From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFCA02EFDA6 for ; Mon, 27 Jul 2026 01:33:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785115986; cv=none; b=RG1wKQi8wodkkFJFaV6c0DKmz5DVJjmLSzbI3aSnUBUuQK9ZM+NfY5eQMeI1RauqFQ0+ApLqEVKrs4OORNsnmWhVjz+DYCX4DijU/Xker61uDI35jxH/Eup/8NscHoscTwsKTepAJawG5RD2FlOnQjm37L28lx/MZk4vfK6HObw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785115986; c=relaxed/simple; bh=JvhlWiHubvipXGwiyYDoGh8n5w2sId5TPv7IkZCZSf4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=sv7959QXdWZHXFwDqB2APZqnDJUV/loxG2gkaHABDc3hJT5Z22peFCoCZy5/uWJ6d6ub5Jk2/9ZLb5GjPvBWucBPgvB5Ev1r5z7VykyWyIsdzo+nY7kTELKENrXuCTPscJ95Q5JYY65/EUZpeHAk5Um/33MEb7NS4vVbhgbNXLI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=openresty.com; spf=pass smtp.mailfrom=openresty.com; dkim=pass (2048-bit key) header.d=openresty.com header.i=@openresty.com header.b=OPInpC6S; arc=none smtp.client-ip=209.85.216.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=openresty.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=openresty.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=openresty.com header.i=@openresty.com header.b="OPInpC6S" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-3811f512167so1988407a91.3 for ; Sun, 26 Jul 2026 18:33:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openresty.com; s=google; t=1785115984; x=1785720784; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=QS8YqykbG3lvtABz9lYv5yB3o6Nx9CfZmlJ/xUd/ZDo=; b=OPInpC6SF8U06+gD1VYAE4r/QyeGlQnM65JGdQQycmup3iyYfolkUD7K91ZelX9FmZ BxJojypUVdVl7embGSj6MtxpG9vUa+jeqdsAL8OVlfr2thOkT2Pqz8JN4EGRLERJBUNU o5GRhwTaGNgS1LLgMzgIlhmebIA8LqiBGNuPpaGJyy+gkfalDY+i+w8jH3ehu7RSvKYN nMLzqi78rruBOUhezUXvJ9WF1UebAst1v6FdYjAr7Zh1g3eBxQ6BhPiaerFXQaVId3zc 1CSZmCVN3kIn8yx+Ui8Os8b0ecRoIWtRgPteHp7DYzGc4lmdycodpZQahfBrkZB5hnbi gnBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785115984; x=1785720784; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=QS8YqykbG3lvtABz9lYv5yB3o6Nx9CfZmlJ/xUd/ZDo=; b=JLLK5KXuxezvcQQnIS254MLewNl9WTIDmH93YlRp4bylHwPQWAaGuHL7icAUgeCAHw gEjucmaaJAb46AjfChuVXZIyPyGFdwmt/mqytwpn2mxXaw5JZcJQ89yYGnm38lP4Xk7c fCLk4TZyjRAUAwMtTsJyL223iVuhbDDlkZMLD7b2lrc3KaT95p9AcaOJg0tqoM7LnqXY 8Eu3PgKbRMY8ND33YgukQGRTse2w8JPd4XvVJa4VFETZ+HOjwm7SbNjkWYowcgMlQv1l ooqjUWDIimoMWc4zXKE0WoctjzYsReuS4ZGJT4KHO7pMVrR/lJey0n/2f8SOiIlfNHNr QMyg== X-Forwarded-Encrypted: i=1; AHgh+RpTWi/3UBleOU1U5PHtVfTnU4C/WQiv3cwmbZ/wpY5sp/YsRRpo81QYWFmTKaKGKLqgAUjB4p6IRzHOBg0=@vger.kernel.org X-Gm-Message-State: AOJu0YzFE4X6ONiSzf0lT3+KzcEp5VIVzGxfMNdQznSRpPw/oGETxwAk azkzNq5nEpx8ldPQRQrtsRMQ5ZCMdK2jnCsxtNxV8ClIjYHkM1hyulGfOamNptDPJH/rHzpH9C8 sOHSdn9EPrw== X-Gm-Gg: AR+sD10nwvggh36qQPE+9Yri030TF2XZ0qjosSaLOF6MOOUOxSsG3/hjI5skabgHecO pAj2JbLT1XnYC+QaCiOlt1W+dS5rwXrafV2CinhfRP6gdsCKSSeGWeNxGgopvDlACgE1S/t6860 uW9VIzqCU0nFC4ffJSfyiYgKMasGg/wTZp0LWTkAgwgOA+NJp6V5SK4idqPcOPlvZI8020urVJ5 nVoC5i1lUEIkHZLV2qRZxKhulhcvQ5tpZzk1p3r82vScJJ9nDwFVrGM+crsIST1NgWojH8Q5I/r 3vKOyUrNbMwTeA/gBBHp/+02o9mcq/iB5++PZrG4S0XTTr7v9OVVWK3N8jxLR96Xp/yTSiBgXYf k6rNePA/qVAs41sj7hhZKl9r0ZHlocEB86ixNzRpXeTrMPnxRvPHauE2R/FL7RsfLFM8bOeEFjH t149kDX+EzeZLm86oUAt2ew3QYPeiBksJde1kiNOAaj4gMBbfet715oJ6d0a3PHSl8umC7Qpo= X-Received: by 2002:a05:6a21:695:b0:3c3:64cc:311a with SMTP id adf61e73a8af0-3c67dd65ec9mr6364557637.22.1785115984125; Sun, 26 Jul 2026 18:33:04 -0700 (PDT) Received: from ?IPV6:2402:8780:1329:2779:943f:461f:3cbe:df62? ([2402:8780:1329:2779:943f:461f:3cbe:df62]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13e53094d65sm18958049c88.13.2026.07.26.18.33.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 26 Jul 2026 18:33:03 -0700 (PDT) Message-ID: <6a5f7481-124f-48ad-ab44-577b12d33592@openresty.com> Date: Mon, 27 Jul 2026 08:32:58 +0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 3/4] selftests/nolibc: add abs() range test To: =?UTF-8?Q?Thomas_Wei=C3=9Fschuh?= Cc: Willy Tarreau , Linux Kernel Mailing List , Linux Kselftest Mailing List , LLVM Mailing List , Yichun Zhang , Alviro Iskandar Setiawan , Shuah Khan , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , gwml@gnuweeb.org References: <20260726101306.3772237-1-ammarfaizi2@openresty.com> <20260726101306.3772237-4-ammarfaizi2@openresty.com> <8bdacaf3-7f93-4095-8875-4c13a273fe3d@t-8ch.de> Content-Language: en-US From: Ammar Faizi In-Reply-To: <8bdacaf3-7f93-4095-8875-4c13a273fe3d@t-8ch.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 7/27/26 3:00 AM, Thomas Weißschuh wrote: >> +/* abs(), labs() and llabs() over the whole range of their argument type */ >> +int test_abs_range(void) >> +{ >> + int i, ri; >> + long l, rl; >> + long long ll, rll; > > Reverse xmas? Fixed for the next revision. >> + >> + /* >> + * Both the inputs and the results have to stay opaque: the compiler >> + * knows abs() and friends never return a negative value and would >> + * otherwise fold the comparisons below at build time, which would also >> + * hide the undefined behavior that is being tested for. >> + */ >> + i = INT_MIN; l = LONG_MIN; ll = LLONG_MIN; >> + __asm__ ("" : "+r" (i), "+r" (l), "+r" (ll)); > > We have _NOLIBC_OPTIMIZER_HIDE_VAR() for this. Oh, I missed it. > Maybe it can be made variadic. Sounds good to me. Does the following patch look good? From: Ammar Faizi Date: Sun, 26 Jul 2026 13:17:14 -0700 Subject: [PATCH] tools/nolibc: make _NOLIBC_OPTIMIZER_HIDE_VAR() variadic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The macro only takes a single variable, so code that needs to hide several at once has to either repeat it or open-code an asm statement with a list of operands. Accept up to four variables and build the operand list from them. Existing single-argument users are unaffected; the code generated for the callers in stdio.h is unchanged on i386 and x86-64. Suggested-by: Thomas Weißschuh Signed-off-by: Ammar Faizi --- tools/include/nolibc/compiler.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/include/nolibc/compiler.h b/tools/include/nolibc/compiler.h index f2d7a81d0d7c..ed69f6d26f56 100644 --- a/tools/include/nolibc/compiler.h +++ b/tools/include/nolibc/compiler.h @@ -77,8 +77,19 @@ # define __nolibc_static_assert(_t) #endif -/* Make the optimizer believe the variable can be manipulated arbitrarily. */ -#define _NOLIBC_OPTIMIZER_HIDE_VAR(var) __asm__ ("" : "+r" (var)) +#define __nolibc_hide1(_1) "+r" (_1) +#define __nolibc_hide2(_1, ...) "+r" (_1), __nolibc_hide1(__VA_ARGS__) +#define __nolibc_hide3(_1, ...) "+r" (_1), __nolibc_hide2(__VA_ARGS__) +#define __nolibc_hide4(_1, ...) "+r" (_1), __nolibc_hide3(__VA_ARGS__) +#define ___nolibc_hide_narg(_1, _2, _3, _4, N, ...) N +#define __nolibc_hide_narg(...) ___nolibc_hide_narg(__VA_ARGS__, 4, 3, 2, 1) +#define __nolibc_hide(N, ...) __nolibc_hide##N(__VA_ARGS__) +#define __nolibc_hide_n(N, ...) __nolibc_hide(N, __VA_ARGS__) + +/* Make the optimizer believe the variables can be manipulated arbitrarily. */ +#define _NOLIBC_OPTIMIZER_HIDE_VAR(...) \ + __asm__ ("" : __nolibc_hide_n(__nolibc_hide_narg(__VA_ARGS__), \ + __VA_ARGS__)) #if __nolibc_has_feature(undefined_behavior_sanitizer) # if defined(__clang__) -- Ammar Faizi