From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 3D1E73858C00 for ; Mon, 29 May 2023 14:51:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3D1E73858C00 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-6af86627460so2559369a34.1 for ; Mon, 29 May 2023 07:51:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1685371862; x=1687963862; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=lndrxJerWWbgcECvN4PyRKlYZsoKOdseE4bl1WjCsfw=; b=zFPd/2hTftFpp7g6EImkxV7DG8TtF80Y1yYcg8PqDZb4nMah8vygiIDkt/va4P8DFY 4WP7lnCBzb9emFeJRj3ALhiCog9Rnbl8jYrs9+2F7hyy1xEdRMTfjV1OaQ6i5pgnCPA7 OCEjnDdHu5CDHFZ4lBtHmHYE+8YXIi2+nYloX/5+TA+sLuAu5QJlvePQ9hEK1ub+8Qe6 Mg+NhoFVMncJ2MGiT5Uw8lbjGWKaSQ3yemwqZfli2jgzYGEOjmyvKOt7SRMkiF4KKKUU W9Pb61b4nkRtruCHk4lsQQdXG+TqTH2gU+in08QPAqsC+VwC9/msq6TpE6aO6/psMXTI e7zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685371862; x=1687963862; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lndrxJerWWbgcECvN4PyRKlYZsoKOdseE4bl1WjCsfw=; b=WX1ORd0FGO0S8/Q0TtYkF3TDre9A/iPN7m/JbJD23fQXcZG9UbjngXK/DkxVu6oEMy XXL4HUe+G1DVaLMuHWF+WumKBZGdf93ut2X+UaJS7psVophgybpgFpeWdAsETH6VXTuc ILC6/WMo8EqVLLm+z8pQH1hbDcFKbqZPllNt9mdGHvk1ZGIBPifktNmFwqf3HeDdGO9Y Fni2X6jGs/NNZyGNZMKQeyBfimlp3vF6MRUAzYHESD1rD+ReJaba2XWrxRxQIKHLT/m4 g03dGR3SNmkwdHVmQve0gqXrzFdmeth0N9+QsDGRdQ0H2XjnS3w8wsZaKq41d9YFWMnY ltyA== X-Gm-Message-State: AC+VfDy0bj5Bs82me7r6l2dC2/hpC8/FMTJXHkr4XOpi1M1Nh/lNtjH9 nZsDHjA+wvg43n+W3f0DX8mVN40gqxlDEo61D+lRDw== X-Google-Smtp-Source: ACHHUZ6D9NrQHSi/6k2SrEGvzZuolp/FmjbJ4suolPvKtiLX3txNtnNcLpVjnBgBaTRCVZAnTjmbag== X-Received: by 2002:a05:6808:2391:b0:398:3f05:227a with SMTP id bp17-20020a056808239100b003983f05227amr5285319oib.43.1685371861889; Mon, 29 May 2023 07:51:01 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c1:4dd5:7120:a40d:fc97:d6db? ([2804:1b3:a7c1:4dd5:7120:a40d:fc97:d6db]) by smtp.gmail.com with ESMTPSA id o201-20020a4a2cd2000000b005526983ebdcsm4648644ooo.4.2023.05.29.07.50.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 May 2023 07:51:00 -0700 (PDT) Message-ID: <1e0168d1-6175-aec2-bf35-f23aaf14e216@linaro.org> Date: Mon, 29 May 2023 11:50:58 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.11.1 Subject: Re: [PATCH v2 2/3] cdefs.h: Define __glibc_warn_system_headers_{begin, end} Content-Language: en-US To: Sergey Bugaev , libc-alpha@sourceware.org References: <20230528172013.73111-1-bugaevc@gmail.com> <20230528172013.73111-3-bugaevc@gmail.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <20230528172013.73111-3-bugaevc@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 28/05/23 14:20, Sergey Bugaev via Libc-alpha wrote: > By default, GCC supresses warnings inside "system headers". Moreover, it > also supresses warnings resulting from expansion of macros defined in > system headers, even in the expansion itself happens in user code. This > may be desirable most of the time because the user cannot do anything > about the mistakes of the system headers, but sometimes causing a > warning is an intentional effect that a macro has, in which case this > GCC feature gets in a way. > > GCC allows turning off the warning suspension feature by passing > -Wsystem-headers; however, that turns it off globally. But by using > "#pragma GCC diagnostic" it can be made to only apply to the relevant > macro definition, in which case GCC only does not supress warnings > resulting from expansion of that one macro. > > To that end, introduce __glibc_warn_system_headers_begin and > __glibc_warn_system_headers_end macros that can be used to surround a > macro definition and ensure that warnings inside the macro are not > supressed: > > __glibc_warn_system_headers_begin > #define foo(x) bar_warn (x) > __glibc_warn_system_headers_end > > This will be used in a following patch which turns fcntl and fcntl64 > into macros that cause warnings on argument type mismatch. > > Note that "#pragma GCC diagnostic warning" normally overrides any > diagnostic options specified on the command line, and so can even > downgrade severity of a diagnostic from an error to a warning (if, for > instance, -Werror is in effect). But this is not a concern here, since > the actual warning that gets emitted is not "-Wsystem-headers", but some > other specific warning; "-Wsystem-headers" is only used to disable its > supression. So passing -Werror still causes the specific warning to be > treated as an error, and to fail the compilation. > > Signed-off-by: Sergey Bugaev > --- > > I'm not very sure about the prereq check. I stole it from the > __glibc_macro_warning above (which also uses _Pragma), and according to > the online docs GCC 4 has already supported -Wsystem-headers. I think it should be OK to limit to GCC 4.8 and clang 3.5 (both support -Wsystem-headers). The patch look good to me, thanks. Reviewed-by: Adhemerval Zanella > > misc/sys/cdefs.h | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > > diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h > index 393d9091..d832d5c3 100644 > --- a/misc/sys/cdefs.h > +++ b/misc/sys/cdefs.h > @@ -649,6 +649,21 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf > # define __glibc_macro_warning(msg) > #endif > > +/* __glibc_warn_system_headers_begin starts a block of code where warnings > + produced by expanding macros defined in system headers will *not* be > + supressed. __glibc_warn_system_headers_end ends such a block. */ > +#if __GNUC_PREREQ (4,8) || __glibc_clang_prereq (3,5) > +# define __glibc_warn_system_headers1(message) _Pragma (#message) > +# define __glibc_warn_system_headers_begin \ > + __glibc_warn_system_headers1 (GCC diagnostic push) \ > + __glibc_warn_system_headers1 (GCC diagnostic warning "-Wsystem-headers") > +# define __glibc_warn_system_headers_end \ > + __glibc_warn_system_headers1 (GCC diagnostic pop) > +#else > +# define __glibc_warn_system_headers_begin > +# define __glibc_warn_system_headers_end > +#endif > + > /* Generic selection (ISO C11) is a C-only feature, available in GCC > since version 4.9. Previous versions do not provide generic > selection, even though they might set __STDC_VERSION__ to 201112L,