From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server-vie001.gnuweeb.org X-Spam-Level: * X-Spam-Status: No, score=1.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,NO_DNS_FOR_FROM,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 Authentication-Results: server-vie001.gnuweeb.org; dkim=pass (2048-bit key; unprotected) header.d=openresty.com header.i=@openresty.com header.a=rsa-sha256 header.s=google header.b=keVbGisV; dkim-atps=neutral Received: by server-vie001.gnuweeb.org (Postfix, from userid 1000) id 4F5702E51F21; Mon, 27 Jul 2026 01:33:27 +0000 (UTC) Authentication-Results: server-vie001.gnuweeb.org; dmarc=none (p=none dis=none) header.from=openresty.com Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2607:f8b0:4864:20::52f; helo=mail-pg1-x52f.google.com; envelope-from=ammarfaizi2@openresty.com; receiver= Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by server-vie001.gnuweeb.org (Postfix) with ESMTPS id 6A4792E51EF2 for ; Mon, 27 Jul 2026 01:33:12 +0000 (UTC) Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-ca913a601fbso1583064a12.3 for ; Sun, 26 Jul 2026 18:33:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openresty.com; s=google; t=1785115984; x=1785720784; darn=gnuweeb.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=keVbGisV8kw7kInfmnLc/d0uaaphQRPVzNKw8VWr1KNmE3vf+zFHHpC7/FthPOS4aV ha5W7Ze19enrBRBOXqDPgf6FBI+1pdOx9nOv5c2j5VWzXyHbumuFAlRZY9cl5CFWqq9l AYRdd3kn9sLPeTEcYaWgLRVL5Sho5wlXpFIW2gr4nCQ/sgY1f2a3h+7pHJEC6Gch+HN3 CxGGFNfDw4L0Sm4eOqgTvF7XwJRQ0KFnc9bHnB3Yd/JAZEmD/HiC1KChsa6T8c8mqc2W 0d4DQskYJrsei10ABzvvHP982JfPm4nVyhr+0yLQHePKCA+16f2m913I8ezgzkiz15pn Pg+w== 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=WTddE04CzArn2JYLlLqyKxe1BHXMQT5wev3ndqWd1O3Qgm7kb3r04vTmUNZS540Uui VRjVehcRMdx0pVOHNM55jqAaJ6g7+KRD1heaikvkzbvqiDguHsTjlOUz0v5/I5QTyCqz vehg88FcYvXiY9mwRu17f1JdnjqnZ/eX+WPV0mvGPjto4yH6Ig4T/ZrS7Ds5Vz+uzjyH yDrwMrn6Lce9CNXmC8WjqxGX2bp3M3ao3Vda2zkC2HwvlppX/8iaB5VgYnJ4a0DmNUCv giGFo7EOmtQVYC/oelDbddCLB0xjIM07jUFWjOqDfOPld7nDGToSnmCF0cjdP32T6kOq XXig== X-Forwarded-Encrypted: i=1; AHgh+RrGlW4eEokm95ClsNK2F/q2bbOB5X3RCsd1VkI08o/a2DTd29jvIrPrvT94GGz7UWNyXKZJ@gnuweeb.org X-Gm-Message-State: AOJu0YzP+87u6ax5wZRjRanMjcKYpUDQyZV2p0HpW4LUpmi+ndXmm9o4 1wNrI3Y9Z/zUoTx8nYq2XEbA/EZE3+8wNa4epDc0wTCZSy2cQ8P6Xp+h6optW4mExXQ= X-Gm-Gg: AR+sD111NtWKziu5fU4vWB7KV2KeqLO1k215Vah24ddiVubruGZPXNEdmjsjBxDw4qa i1vpKZqGjXH6mBGXI14+0umAGYXxFok3Z1WzV4ZfiTSZDaFPp+gIL9qGRUWq+xTTN66JQMAxyEg 38ore/3Ghu8BBudMMFMS1Om3qHwWp/z4Qrj18m0D5MF+2I2n3WOFy/ywCtAh/4M7H8XCrm2r55w WWcNN2RpljCN82bMH4MQq6ZCx7kD1/qQ4n67GA7OrwiF8i5m0WSgYLSAi2i3ME/Goe1Xmid+Z6K H1r4grNF/+j8wzkb7qvnP5yP4fwPqvYzvSueAflL/dOylyirH8rur8p/ettU8wcRe1EbQKCjMTm 9ID3Rhdlk++zmjaT376GxL5hK/L+nE2/S6aorXV8abPABcAOAjf3pFTD5e+2r0pRgHjnJagsVgs 7MigpSLCJua45/xGDvNFeTiMJ7PPBniHXCixZg7Dkx6lwJyvBWlcCvYTFRfSCVYlAwnMi9H60= 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 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 List-Id: 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