From patchwork Sun May 28 17:20:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 70195 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1D6153856DD4 for ; Sun, 28 May 2023 17:20:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D6153856DD4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685294449; bh=HusZAiEp2p1vo5ZcgzUzBcrU53SPu3W6E+fWb708c7Y=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=AJXfDxu/Cw5YNZ8D1UHjSHTNUNmqW+E1GX7lr25Mzi8QM+hnZQJ1/7nTmqc2ubB87 w6cdeovLiEK4vHhjy+A2jvFf4fGFiyFMq+kC70T15NjPJA+HSC9MHcZlZqlYPBOhIy RF/4NvGGcZBhmG8aMK/MxxFTy6OlPu8/I2hda/4A= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by sourceware.org (Postfix) with ESMTPS id 228FC3858C74 for ; Sun, 28 May 2023 17:20:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 228FC3858C74 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-4f4f3ac389eso1279233e87.1 for ; Sun, 28 May 2023 10:20:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685294417; x=1687886417; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HusZAiEp2p1vo5ZcgzUzBcrU53SPu3W6E+fWb708c7Y=; b=b7Xbx6PY8n3OHnRCM7vjsi42CpXC72jeM9d34BAneZbNZ8x5W8y0lrIWk+BO4hMzWr IieoSDb0KgF2pTZLpXZKdxyCaG5Ols5Qx6UeSDH3eG0MTdlTDyjqXGlc40mfb/LYSkDa 42VtQM6Bim612k5HC0wya4EAXqfmGH+VN3KrK3Fc9y/RELA1WxCoNyr3m3kFWroEBI5S p06nADI1wZbOj/ELe/O6dKSN4A7gt+cMJp++afuw3ggLGFoohecs83E415i1P+R7+XKn /NYQXivebmWJLuWYwnLKz5JXOjwdO3ssHMtlHhYbOOSzTTuGf97aOLHS8L8S3k9UG6t9 uOQA== X-Gm-Message-State: AC+VfDy15eNIP9O3psg51ViOsIAbVlSC3I8pt0HOLyoTWpqyAQYcLxq/ sCnWF6/H0kWsEoGDrkP0Hwf38Xy5snM= X-Google-Smtp-Source: ACHHUZ7vZDSsylJzIhEdV5mEBDyMwHiRLVTep0Fq7ePKrEkaFNp2eBR55lmxFmP72bWWZyDAxLbCbg== X-Received: by 2002:ac2:5ec7:0:b0:4f3:822e:f025 with SMTP id d7-20020ac25ec7000000b004f3822ef025mr2667557lfq.49.1685294417207; Sun, 28 May 2023 10:20:17 -0700 (PDT) Received: from surface-pro-6.. ([2a00:1370:818c:4a57:5e3d:a067:bc18:2967]) by smtp.gmail.com with ESMTPSA id v26-20020a19741a000000b004f4d5003e8dsm1662596lfe.7.2023.05.28.10.20.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 May 2023 10:20:16 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 2/3] cdefs.h: Define __glibc_warn_system_headers_{begin, end} Date: Sun, 28 May 2023 20:20:12 +0300 Message-Id: <20230528172013.73111-3-bugaevc@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528172013.73111-1-bugaevc@gmail.com> References: <20230528172013.73111-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 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+patchwork=sourceware.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. Signed-off-by: Sergey Bugaev Reviewed-by: Adhemerval Zanella --- 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. 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,