From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id 48C0B3858D39 for ; Sat, 17 Jun 2023 22:22:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 48C0B3858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-4f6170b1486so2548825e87.0 for ; Sat, 17 Jun 2023 15:22:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687040543; x=1689632543; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/Lclhxgm24KnDj9DmjKd8uL9F54LjmvtbvSfs5ONcv8=; b=hV8gaFk+/U2z8ZsnRgXlxDBflXE98PuOyghMdCez5KsVtzI4Tbpnle/T7v4bvtQ8hW xnBJDsR5qIl7muPwpop6TpTlsnlQa106mWNtqRAdSCuC9oSn/KwIbPLCz0iwTZz7qFOk qqOYeCcRmqb0kmPk7D9l0Fw1EMcYoC3f8EIKr+WToFzMzPAMkEsMn3BU2jIwmIhB0zdx uo/FSULh1xbrrp8zdLuAq7uSDpVYusttb3YFwcD62GyAOeh1X/fcSphdkhrJPmnROSbP 7Q24cSlCWAGrjSN4U1iV8bHVOXXR3Cs8GQ0tYToJYCE3uCt8fUx2kj/cKfi9EOU6eb9U VR1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687040543; x=1689632543; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/Lclhxgm24KnDj9DmjKd8uL9F54LjmvtbvSfs5ONcv8=; b=c1RBgGtj8F3c3vaL+2YQPBELuZMwEtTL6f8gDJJ84VbXTy6787Y3cDVnCNUDJ7cWH1 vrxjEz7rxBpQhG+6a87xaujot44dN94rmQehfpQFbStl2Cc26/YbG8MYmJpYl7VAE1OO cEG6ht5bf4wDMchuwO2pEFz4ZnBYCDqObRjR3AaIUv3tw+w82Qy069n8k/nV+5mAuFCl Sp0fBr5kk+OJWV2NPDLgf50upplrxAM6tis1cqF6QfqkmSjXhP4L2erUcRQt+HxLUYFt faUXnsHLCV4gO8i/hqKAYSWpviT6zQDUkU6wtEubNa2/kTwXkey+wcyW4hdCPt8DdXhF Ho1Q== X-Gm-Message-State: AC+VfDzw2mzRgIYyTq4lzZWTWkKPbt0yUBt4IFOkRS7o15b36tiO+VMi i59R7QDKk+oqBVpdY2QIxQnf3T8RQH0= X-Google-Smtp-Source: ACHHUZ5UdWsys0+mWVVXwnon/0TBtDn2Qc7a5VEqCn/E2c6lVw+yOOiv7mkLMG+Zggs4YPi0HxCq/A== X-Received: by 2002:a19:4f12:0:b0:4f8:6253:540 with SMTP id d18-20020a194f12000000b004f862530540mr805868lfb.19.1687040543243; Sat, 17 Jun 2023 15:22:23 -0700 (PDT) Received: from surface-pro-6.. ([2a00:1370:818c:173b:cc34:4e0d:9ea6:c16c]) by smtp.gmail.com with ESMTPSA id j28-20020ac253bc000000b004f76a88dbcbsm1567091lfh.176.2023.06.17.15.22.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Jun 2023 15:22:22 -0700 (PDT) From: Sergey Bugaev To: libc-alpha@sourceware.org Cc: Adhemerval Zanella Subject: [PATCH v3 2/5] cdefs.h: Define __glibc_warn_system_headers_{begin,end} Date: Sun, 18 Jun 2023 01:22:15 +0300 Message-ID: <20230617222218.642125-3-bugaevc@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230617222218.642125-1-bugaevc@gmail.com> References: <20230617222218.642125-1-bugaevc@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,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: 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. Clang does not seem to support turning -Wsystem-headers on and off with a pragma, but does not seem to suppress warnings from system-defined macros either. Hence, the macros added by this patch expand to nothing under Clang. Reviewed-by: Adhemerval Zanella Signed-off-by: Sergey Bugaev --- diff to v2: no longer expands to anything on Clang misc/sys/cdefs.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h index 393d9091..6ca8ca31 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) +# 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, -- 2.41.0