From patchwork Sun Jul 30 19:25:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 1814689 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=Ft8m/74q; dkim-atps=neutral Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RDWbd0HGNz1yVt for ; Mon, 31 Jul 2023 05:27:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1127C3854148 for ; Sun, 30 Jul 2023 19:27:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1127C3854148 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1690745243; bh=72Fcs2QxOWJyViCpNID0l180KNWHNcPLpANsK4wsUyA=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Ft8m/74qNXlF97YBhfFt/Yrgt+4MCLwfrV2i6rK5eKpq3qn+wNVcqxhBeuuQgA7hI Qq1GLKCPLvYoWJ/lB0SvYMhD772J3XtAadXqKd7x20pLlP9N75P9DoM/Mjkr8UA6DI 0uyVjiXd+vbK5Jpj/rVCZu/U7pQzP5cf0tm56kkw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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 156663858C54 for ; Sun, 30 Jul 2023 19:26:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 156663858C54 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-4fe07f0636bso6047511e87.1 for ; Sun, 30 Jul 2023 12:26:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690745174; x=1691349974; 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=72Fcs2QxOWJyViCpNID0l180KNWHNcPLpANsK4wsUyA=; b=NgK2OdeLYYBSjMnHn+FTI6QbRhfUPAoTUF7zcbUME4DNwQdwLltBBj5SboJ6zQ1WND PX8rgaAayQ2hCxTK2jD2jmLOUOR1uNxO6Bq0sMOe99FF1daS+hSDdrzrC/ToghymN5eo fE+EEFzYzkksYenDeo8NTPF0Xum8fg4dgsnSpJd+/syCfblU/LsOJYaq9CR2hvzE5EBQ k/Khy2sAD607PDk2/LyEUw5KJPtVxi9L52nyy819DhWZuu9bC7OKNrPfaHXykXyFwJ63 3yGTTujhDdBl++dVDrFjV/c3yabWD72mXlwVlpC3S/Z6YIW4QMenvKb1SZY+csGlQSs6 BI3w== X-Gm-Message-State: ABy/qLbxe0OHkzxbzdBRU4YwWpjIKTj7hmDDcpCD7jSeULwrTgLdUYqD UttEaG1OzJacRwAsSrUpnGSg6zaJLqpw5w== X-Google-Smtp-Source: APBJJlHuRAeavU/Uw9/GTPm93CJEiMaA5sKZ9mSnDXSnFWD5rgnUVcVQ2WVm1bjopfiKaKVzPZwcyg== X-Received: by 2002:a19:4f5c:0:b0:4fe:c6c:ac95 with SMTP id a28-20020a194f5c000000b004fe0c6cac95mr3775578lfk.35.1690745174343; Sun, 30 Jul 2023 12:26:14 -0700 (PDT) Received: from localhost.localdomain ([2a02:2168:b344:a600:4435:f106:1598:d2b0]) by smtp.gmail.com with ESMTPSA id y8-20020a197508000000b004fe2f085d5csm532447lfe.299.2023.07.30.12.26.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jul 2023 12:26:13 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Adhemerval Zanella Subject: [PATCH v4 3/6] cdefs.h: Define __glibc_warn_system_headers_{begin, end} Date: Sun, 30 Jul 2023 22:25:58 +0300 Message-ID: <20230730192605.2423480-4-bugaevc@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230730192605.2423480-1-bugaevc@gmail.com> References: <20230730192605.2423480-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" 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 --- misc/sys/cdefs.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h index 90c21e27..15587848 100644 --- a/misc/sys/cdefs.h +++ b/misc/sys/cdefs.h @@ -657,6 +657,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,