public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Longjun Luo <luolongjuna@gmail.com>
To: gcc-patches@gcc.gnu.org
Cc: luolongjuna@gmail.com, sangyan@huawei.com
Subject: [PATCH] libcpp: suppress builtin macro redefined warnings for __LINE__
Date: Thu,  1 Dec 2022 12:31:55 +0800	[thread overview]
Message-ID: <20221201043155.9369-1-luolongjuna@gmail.com> (raw)

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 <luolongjuna@gmail.com>
---
 gcc/testsuite/gcc.dg/builtin-redefine.c | 1 -
 libcpp/init.cc                          | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/builtin-redefine.c b/gcc/testsuite/gcc.dg/builtin-redefine.c
index 882b2210992..9d5b42252ee 100644
--- a/gcc/testsuite/gcc.dg/builtin-redefine.c
+++ b/gcc/testsuite/gcc.dg/builtin-redefine.c
@@ -71,7 +71,6 @@
 /* { 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


             reply	other threads:[~2022-12-01  4:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-01  4:31 Longjun Luo [this message]
2022-12-01 17:01 ` Joseph Myers
2022-12-01 18:23   ` Longjun Luo
2022-12-01 19:07     ` Joseph Myers
2022-12-01 19:51       ` Longjun Luo
2022-12-01 21:10         ` Joseph Myers
2023-01-12 16:02           ` Longjun Luo
2023-04-30 18:30             ` Jeff Law
2023-04-30 23:14               ` Jeff Law
2023-04-30 23:19                 ` Andrew Pinski
2023-01-12 16:05           ` Longjun Luo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221201043155.9369-1-luolongjuna@gmail.com \
    --to=luolongjuna@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=sangyan@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).