From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by sourceware.org (Postfix) with ESMTPS id 90A2E3858D35 for ; Thu, 12 Jan 2023 16:02:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 90A2E3858D35 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-ej1-x636.google.com with SMTP id fy8so45769624ejc.13 for ; Thu, 12 Jan 2023 08:02:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=CNYlq43YwSHjz/gaudhBqWcS0m5a/ahCydEfTQDQx64=; b=OH9xiwQN5xAeZFTgAlx2QDsqXu8UmakJO6b7MqMLYuK7EChkJkXjh0H8OyjglESdWU IbNLRPHVYDPdg0kzU3uuzzFrbCpGvtd5S6LHdhQIjthyIlUHM785LxBCy1W1/qiEo1XR 2p7HwqN7ZFE6HHzu4DCX8KZae5HdI+/gnh7GOcJFSnQbU7AZJV5PMsOMRZuTZ8eGy1K/ roNfx2bWOikPcVphLE6gQ9RekDr77OMU/ZQR+vVtYy6ivfLDuYHqQ0OxLsceoXiI3WML vxAHDP1Z3wisoOB/MEK4N7ksMUTkXyOE5YEtPPwofkHCdB6N7v9W9CqDIcciU1BTAMUM 7UKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=CNYlq43YwSHjz/gaudhBqWcS0m5a/ahCydEfTQDQx64=; b=7T6UPqUAjhFbfAaMQRf86BIIZ86jdt5pUOrnyv6NGnltOPgUHfX8GHcWY3DZeqaBY3 AJ14RaV0rym2bn8msa4MsNK3a9OmL77ou88yeNWlFv4C3adtX/PmLier2RCl1eqwq9ob UE6n3muw0iFlwc3zifbElU/wgN5CQr+6+v+PtVDnpEWMFtvfb3xFMSia2wkgwkRaCwBN iodA5JM4ckePqGB0JKaXOFdjLBwNkZTzuinJq0BW8GcG0bnKzadyHGYxaKrshT/VtTWw emkBdGScufgpaVnrxwN7daOjRIRaV04h0wnkt3+awFNehOPaEzA2IRFTBAR1UFHSYFMn Z20w== X-Gm-Message-State: AFqh2kp53OH/Ubadk9Vz0xvGD7HeCNBfd9uX173vUN/8jYLEj1cbAxVG AmaKATPXuMP2n7gxH7Hc5kc= X-Google-Smtp-Source: AMrXdXuwa5z5ATjx+7l5HfhnMtOeSuS8Vj80PwubReVNkWJu0JwE8BpgrlSxFg5BcmpSfsacS9fhRg== X-Received: by 2002:a17:906:3ad7:b0:7c1:6e53:dd02 with SMTP id z23-20020a1709063ad700b007c16e53dd02mr71002946ejd.64.1673539342206; Thu, 12 Jan 2023 08:02:22 -0800 (PST) Received: from [0.0.0.0] ([2a05:f480:2400:16fb:5400:4ff:fe3c:2a4f]) by smtp.gmail.com with ESMTPSA id lb19-20020a170907785300b0084d1efe9af6sm7562480ejc.58.2023.01.12.08.02.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Jan 2023 08:02:21 -0800 (PST) Message-ID: <86625ca4-6ef5-4010-e452-aa2e1149215f@gmail.com> Date: Fri, 13 Jan 2023 00:02:17 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH] libcpp: suppress builtin macro redefined warnings for __LINE__ To: Joseph Myers Cc: gcc-patches@gcc.gnu.org, sangyan@huawei.com References: <20221201043155.9369-1-luolongjuna@gmail.com> <8767c6bc-5b37-ca10-1176-e341081c555f@gmail.com> <587de9c9-e46f-b69e-84d8-7356a19db74@codesourcery.com> <6ac6c8e6-d18a-8aae-2ae3-ecdfed291755@codesourcery.com> From: Longjun Luo In-Reply-To: <6ac6c8e6-d18a-8aae-2ae3-ecdfed291755@codesourcery.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP 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: From 0821df518b264e754d698d399f98be1a62945e32 Mon Sep 17 00:00:00 2001 From: Longjun Luo Date: Thu, 12 Jan 2023 23:59:54 +0800 Subject: [PATCH] libcpp: suppress builtin macro redefined warnings for __LINE__ As implied in gcc.gnu.org/legacy-ml/gcc-patches/2008-09/msg00076.html, gcc provides -Wno-builtin-macro-redefined to suppress warning when redefining builtin macro. However, at that time, there was no scenario for __LINE__ macro. But, when we try to build a live-patch, we compare sections by using -ffunction-sections. Some same functions are considered changed because of __LINE__ macro. At present, to detect such a changed caused by __LINE__ macro, we have to analyse code and maintain a function list. For example, in kpatch, check this commit github.com/dynup/kpatch/commit/0e1b95edeafa36edb7bcf11da6d1c00f76d7e03d. So, in this scenario, when we try to compared sections, it would be better to support suppress builtin macro redefined warnings for __LINE__ macro. Signed-off-by: Longjun Luo --- gcc/testsuite/gcc.dg/builtin-redefine-1.c | 49 +++++++++++++++++++++++ gcc/testsuite/gcc.dg/builtin-redefine.c | 24 +++++++++-- libcpp/init.cc | 2 +- 3 files changed, 70 insertions(+), 5 deletions(-) create mode 100755 gcc/testsuite/gcc.dg/builtin-redefine-1.c diff --git a/gcc/testsuite/gcc.dg/builtin-redefine-1.c b/gcc/testsuite/gcc.dg/builtin-redefine-1.c new file mode 100755 index 00000000000..c1e05b4fc7c --- /dev/null +++ b/gcc/testsuite/gcc.dg/builtin-redefine-1.c @@ -0,0 +1,49 @@ +/* Test default warnings for redefining builtin macros. */ + +/* { dg-do compile } */ +/* { dg-options "-D__TIMESTAMP__=x -D__TIME__=x -D__DATE__=x -D__FILE__=x -D__FILE_NAME__=x -D__BASE_FILE__=x -D__LINE__=0" } */ + +/* Check default behavior for builtin macros redefinition. */ + +/* { dg-message "\"__TIMESTAMP__\" redefined" "" {target "*-*-*"} 0 } */ +#ifndef __TIMESTAMP__ +#error "__TIMESTAMP__ builtin is not defined" +/* { dg-bogus "Expected built-in is not defined" "" { target *-*-* } .-1 } */ +#endif + +/* { dg-message "\"__TIME__\" redefined" "" {target "*-*-*"} 0 } */ +#ifndef __TIME__ +#error "__TIME__ builtin is not defined" +/* { dg-bogus "Expected built-in is not defined" "" { target *-*-* } .-1 } */ +#endif + +/* { dg-message "\"__DATE__\" redefined" "" {target "*-*-*"} 0 } */ +#ifndef __DATE__ +#error "__DATE__ builtin is not defined" +/* { dg-bogus "Expected built-in is not defined" "" { target *-*-* } .-1 } */ +#endif + +/* { dg-message "\"__FILE__\" redefined" "" {target "*-*-*"} 0 } */ +#ifndef __FILE__ +#error "__FILE__ builtin is not defined" +/* { dg-bogus "Expected built-in is not defined" "" { target *-*-* } .-1 } */ +#endif + +/* { dg-message "\"__FILE_NAME__\" redefined" "" {target "*-*-*"} 0 } */ +#ifndef __FILE_NAME__ +#error "__FILE_NAME__ builtin is not defined" +/* { dg-bogus "Expected built-in is not defined" "" { target *-*-* } .-1 } */ +#endif + +/* { dg-message "\"__BASE_FILE__\" redefined" "" {target "*-*-*"} 0 } */ +#ifndef __BASE_FILE__ +#error "__BASE_FILE__ builtin is not defined" +/* { dg-bogus "Expected built-in is not defined" "" { target *-*-* } .-1 } */ +#endif + +/* { dg-message "\"__LINE__\" redefined" "" {target "*-*-*"} 0 } */ +#ifndef __LINE__ +#error "__LINE__ builtin is not defined" +/* { dg-bogus "Expected built-in is not defined" "" { target *-*-* } .-1 } */ +#endif + diff --git a/gcc/testsuite/gcc.dg/builtin-redefine.c b/gcc/testsuite/gcc.dg/builtin-redefine.c index 882b2210992..fa27ee9aefc 100644 --- a/gcc/testsuite/gcc.dg/builtin-redefine.c +++ b/gcc/testsuite/gcc.dg/builtin-redefine.c @@ -1,9 +1,9 @@ /* Test -Wno-builtin-macro-redefined warnings. */ /* { dg-do compile } */ -/* { dg-options "-Wno-builtin-macro-redefined -U__DATE__ -D__TIME__=X" } */ +/* { dg-options "-Wno-builtin-macro-redefined -U__DATE__ -D__TIME__=X -D__LINE__=0" } */ -/* Check date, time, and datestamp built-ins warnings may be suppressed. */ +/* Check date, time, datestamp and line built-ins warnings may be suppressed. */ #if defined(__DATE__) #error "__DATE__ is defined, but should not be (-U command line error)" @@ -15,6 +15,11 @@ /* { dg-bogus "__TIME__ is not defined" "" { target *-*-* } .-1 } */ #endif +#if __LINE__ != 0 +#error "__LINE__ is not defined as expected (-D command line error)" +/* { dg-bogus "__LINE__ is not defined" "" { target *-*-* } .-1 } */ +#endif + #if !defined(__TIMESTAMP__) #error "__TIMESTAMP__ is not defined (built-in macro expectation error)" /* { dg-bogus "__TIMESTAMP__ is not defined" "" { target *-*-* } .-1 } */ @@ -53,6 +58,18 @@ #undef __TIMESTAMP__ /* Undefine while defined. */ +#undef __LINE__ /* Undefine while defined. */ +#undef __LINE__ /* Undefine while already undefined. */ + +#define __LINE__ "1" /* Define while undefined. */ +#define __LINE__ "1" /* Re-define while defined. */ /* { dg-line line_prev } */ + +#define __LINE__ "2" /* { dg-warning "-:\"__LINE__\" redefined" } */ +/* { dg-message "-:previous definition" "" { target *-*-* } line_prev } */ + +#undef __LINE__ /* Undefine while defined. */ + + /* Check other built-ins with warnings that may be suppressed. */ #if !defined(__FILE__) || !defined(__BASE_FILE__) @@ -66,12 +83,11 @@ /* Check selected built-ins not affected by warning suppression. */ -#if !defined(__LINE__) || !defined(__INCLUDE_LEVEL__) || !defined(__COUNTER__) +#if !defined(__INCLUDE_LEVEL__) || !defined(__COUNTER__) #error "Expected built-in is not defined (built-in macro expectation error)" /* { dg-bogus "Expected built-in is not defined" "" { target *-*-* } .-1 } */ #endif -#define __LINE__ 0 /* { dg-warning "-:\"__LINE__\" redef" } */ #define __INCLUDE_LEVEL__ 0 /* { dg-warning "-:\"__INCLUDE_LEVEL__\" redef" } */ #define __COUNTER__ 0 /* { dg-warning "-:\"__COUNTER__\" redef" } */ diff --git a/libcpp/init.cc b/libcpp/init.cc index 5f34e3515d2..2765b9838b7 100644 --- a/libcpp/init.cc +++ b/libcpp/init.cc @@ -421,7 +421,7 @@ static const struct builtin_macro builtin_array[] = B("__FILE__", BT_FILE, false), B("__FILE_NAME__", BT_FILE_NAME, false), B("__BASE_FILE__", BT_BASE_FILE, false), - B("__LINE__", BT_SPECLINE, true), + B("__LINE__", BT_SPECLINE, false), B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL, true), B("__COUNTER__", BT_COUNTER, true), /* Make sure to update the list of built-in -- 2.38.1