* [PATCH] Fix -Wshadow=local warnings in dumpfile.h
@ 2019-10-03 15:18 Bernd Edlinger
2019-10-04 12:16 ` Richard Sandiford
0 siblings, 1 reply; 3+ messages in thread
From: Bernd Edlinger @ 2019-10-03 15:18 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 390 bytes --]
Hi,
this fixes a -Wshadow=local warning when using AUTO_DUMP_SCOPE in
nested blocks. Since NAME i a string I cannot use it to create
a unique name for the auto_dump_scope object.
So I used XCONCAT2 from good old symcat.h, to mangle the __LINE__
macro into the scope object name.
Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
Is it OK for trunk?
Thanks
Bernd.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch-wshadow-dumpfile.diff --]
[-- Type: text/x-patch; name="patch-wshadow-dumpfile.diff", Size: 945 bytes --]
2019-10-03 Bernd Edlinger <bernd.edlinger@hotmail.de>
* dumpfile.h (AUTO_DUMP_SCOPE): Use XCONCAT2 and __LINE__
to form a unique name for the scope variable.
Index: gcc/dumpfile.h
===================================================================
--- gcc/dumpfile.h (revision 276484)
+++ gcc/dumpfile.h (working copy)
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. If not see
#ifndef GCC_DUMPFILE_H
#define GCC_DUMPFILE_H 1
+#include "symcat.h" /* XCONCAT2 */
#include "profile-count.h"
/* An attribute for annotating formatting printing functions that use
@@ -634,7 +635,7 @@ class auto_dump_scope
in a nested scope implicitly default to MSG_PRIORITY_INTERNALS. */
#define AUTO_DUMP_SCOPE(NAME, USER_LOC) \
- auto_dump_scope scope (NAME, USER_LOC)
+ auto_dump_scope XCONCAT2 (scope, __LINE__) (NAME, USER_LOC)
extern void dump_function (int phase, tree fn);
extern void print_combine_total_stats (void);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix -Wshadow=local warnings in dumpfile.h
2019-10-03 15:18 [PATCH] Fix -Wshadow=local warnings in dumpfile.h Bernd Edlinger
@ 2019-10-04 12:16 ` Richard Sandiford
2019-10-04 18:00 ` Bernd Edlinger
0 siblings, 1 reply; 3+ messages in thread
From: Richard Sandiford @ 2019-10-04 12:16 UTC (permalink / raw)
To: Bernd Edlinger; +Cc: gcc-patches
Bernd Edlinger <bernd.edlinger@hotmail.de> writes:
> Hi,
>
> this fixes a -Wshadow=local warning when using AUTO_DUMP_SCOPE in
> nested blocks. Since NAME i a string I cannot use it to create
> a unique name for the auto_dump_scope object.
>
> So I used XCONCAT2 from good old symcat.h, to mangle the __LINE__
> macro into the scope object name.
Seems a pity to reintroduce uses of symcat.h again now when it was
originally only a bridge from pre-ISO C. How about just importing
XCONCAT2 into system.h instead? I guess it's a bit of an abuse of
system.h, but not really much worse than CEIL, ROUND_UP, etc., and
that's where symcat.h was originally included.
Thanks,
Richard
> Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
> Is it OK for trunk?
>
>
> Thanks
> Bernd.
>
> 2019-10-03 Bernd Edlinger <bernd.edlinger@hotmail.de>
>
> * dumpfile.h (AUTO_DUMP_SCOPE): Use XCONCAT2 and __LINE__
> to form a unique name for the scope variable.
>
> Index: gcc/dumpfile.h
> ===================================================================
> --- gcc/dumpfile.h (revision 276484)
> +++ gcc/dumpfile.h (working copy)
> @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. If not see
> #ifndef GCC_DUMPFILE_H
> #define GCC_DUMPFILE_H 1
>
> +#include "symcat.h" /* XCONCAT2 */
> #include "profile-count.h"
>
> /* An attribute for annotating formatting printing functions that use
> @@ -634,7 +635,7 @@ class auto_dump_scope
> in a nested scope implicitly default to MSG_PRIORITY_INTERNALS. */
>
> #define AUTO_DUMP_SCOPE(NAME, USER_LOC) \
> - auto_dump_scope scope (NAME, USER_LOC)
> + auto_dump_scope XCONCAT2 (scope, __LINE__) (NAME, USER_LOC)
>
> extern void dump_function (int phase, tree fn);
> extern void print_combine_total_stats (void);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix -Wshadow=local warnings in dumpfile.h
2019-10-04 12:16 ` Richard Sandiford
@ 2019-10-04 18:00 ` Bernd Edlinger
0 siblings, 0 replies; 3+ messages in thread
From: Bernd Edlinger @ 2019-10-04 18:00 UTC (permalink / raw)
To: gcc-patches, richard.sandiford
[-- Attachment #1: Type: text/plain, Size: 802 bytes --]
On 10/4/19 2:16 PM, Richard Sandiford wrote:
> Bernd Edlinger <bernd.edlinger@hotmail.de> writes:
>> Hi,
>>
>> this fixes a -Wshadow=local warning when using AUTO_DUMP_SCOPE in
>> nested blocks. Since NAME i a string I cannot use it to create
>> a unique name for the auto_dump_scope object.
>>
>> So I used XCONCAT2 from good old symcat.h, to mangle the __LINE__
>> macro into the scope object name.
>
> Seems a pity to reintroduce uses of symcat.h again now when it was
> originally only a bridge from pre-ISO C. How about just importing
> XCONCAT2 into system.h instead? I guess it's a bit of an abuse of
> system.h, but not really much worse than CEIL, ROUND_UP, etc., and
> that's where symcat.h was originally included.
>
Done.
Is it OK for trunk?
Thanks
Bernd.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch-wshadow-dumpfile.diff --]
[-- Type: text/x-patch; name="patch-wshadow-dumpfile.diff", Size: 1280 bytes --]
2019-10-04 Bernd Edlinger <bernd.edlinger@hotmail.de>
* system.h (CONCAT2, XCONCAT2): Imported from symcat.h
* dumpfile.h (AUTO_DUMP_SCOPE): Use XCONCAT2 and __LINE__
to form a unique name for the scope variable.
Index: gcc/system.h
===================================================================
--- gcc/system.h (revision 276589)
+++ gcc/system.h (working copy)
@@ -392,6 +392,12 @@ extern int errno;
/* This macro rounds x down to the y boundary. */
#define ROUND_DOWN(x,y) ((x) & ~((y) - 1))
+/* This concatenates two symbols before macro expansion. */
+#define CONCAT2(a,b) a##b
+
+/* This concatenates two symbols after macro expansion. */
+#define XCONCAT2(a,b) CONCAT2(a,b)
+
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
Index: gcc/dumpfile.h
===================================================================
--- gcc/dumpfile.h (revision 276589)
+++ gcc/dumpfile.h (working copy)
@@ -634,7 +634,7 @@ class auto_dump_scope
in a nested scope implicitly default to MSG_PRIORITY_INTERNALS. */
#define AUTO_DUMP_SCOPE(NAME, USER_LOC) \
- auto_dump_scope scope (NAME, USER_LOC)
+ auto_dump_scope XCONCAT2 (scope, __LINE__) (NAME, USER_LOC)
extern void dump_function (int phase, tree fn);
extern void print_combine_total_stats (void);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-10-04 18:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-03 15:18 [PATCH] Fix -Wshadow=local warnings in dumpfile.h Bernd Edlinger
2019-10-04 12:16 ` Richard Sandiford
2019-10-04 18:00 ` Bernd Edlinger
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).