public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/102887] New: wrong warning location with macro expansion
@ 2021-10-21 20:45 msebor at gcc dot gnu.org
2021-10-21 20:45 ` [Bug middle-end/102887] " msebor at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-10-21 20:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102887
Bug ID: 102887
Summary: wrong warning location with macro expansion
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
As noted here:
https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582316.html
in a -Wuninitialized warning for the use of a variable in the expansion of a
macro the warning points to the macro definition and not to the point of its
expansion as in other warnings such as -Warray-bounds. The test case below
shows the difference. Pointing also to the point of the macro's expansion is
important in large functions.
$ cat t.C && gcc -O2 -S -Wall -Wextra t.C
#define X(x) x ? x + 1 : 2 // warning here (not helpful)
int f (int i, int j)
{
int x; // note here (good)
if (i < 0)
x = i + 1;
if (j < 0)
return X (x);
return -1;
}
#define A(i) a[i] // note here (good)
extern int a[4]; // note here (good)
int g (int i)
{
if (i < 0)
return A (7); // warning here (helpful)
return -1;
}
t.C: In function ‘int f(int, int)’:
t.C:1:16: warning: ‘x’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
1 | #define X(x) x ? x + 1 : 2 // warning here (not helpful)
| ^
t.C:5:7: note: ‘x’ was declared here
5 | int x; // note here (good)
| ^
t.C: In function ‘int g(int)’:
t.C:13:17: warning: array subscript 7 is above array bounds of ‘int [4]’
[-Warray-bounds]
13 | #define A(i) a[i] // note here (good)
| ~~~^
t.C:19:12: note: in expansion of macro ‘A’
19 | return A (7); // warning here (helpful)
| ^
t.C:14:12: note: while referencing ‘a’
14 | extern int a[4]; // note here (good)
| ^
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug middle-end/102887] wrong warning location with macro expansion
2021-10-21 20:45 [Bug middle-end/102887] New: wrong warning location with macro expansion msebor at gcc dot gnu.org
@ 2021-10-21 20:45 ` msebor at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-10-21 20:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102887
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
Last reconfirmed| |2021-10-21
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Blocks| |24639
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24639
[Bug 24639] [meta-bug] bug to track all Wuninitialized issues
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-10-21 20:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-21 20:45 [Bug middle-end/102887] New: wrong warning location with macro expansion msebor at gcc dot gnu.org
2021-10-21 20:45 ` [Bug middle-end/102887] " msebor at gcc dot gnu.org
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).