https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68473

--- Comment #8 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
(In reply to Jay Foad from comment #6)
> FYI here's another test case that seems to trigger the same bug. Your
> candidate patch fixes it.
> 
> $ cat x.c
> #define P(b) b&&4
> int a[]=0;
> int f() { X||P(d); }
> $ ~/gcc/build/gcc/cc1 -quiet -Wall x.c
> [...]
> x.c:3:1: internal compiler error: in contains_point, at
> diagnostic-show-locus.c:335
>  int f() { X||P(d); }
>  ^~~

Thanks.

For this one, it's attempting to issue:
  "suggest parentheses around %<&&%> within %<||%>"

and all three parts of the location are within macro expansions, as it happens,
within the same macro expansion:

(gdb) p /x line_table->location_adhoc_data_map.data[0x1]
$12 = {locus = 0x7ffffffb, src_range = {m_start = 0x7ffffffa, m_finish =
0x7ffffffc}, data = 0x0}

(gdb) call inform (0x7ffffffb, "locus")
pr68473-2.c:2:15: note: locus
 #define P(b) b&&4
               ^

pr68473-2.c:4:14: note: in expansion of macro ‘P’
 int f() { X||P(d); }
              ^

(gdb) call inform (0x7ffffffa, "m_start")
pr68473-2.c:4:16: note: m_start
 int f() { X||P(d); }
                ^

pr68473-2.c:2:14: note: in definition of macro ‘P’
 #define P(b) b&&4
              ^

(gdb) call inform (0x7ffffffc, "m_finish")
pr68473-2.c:2:17: note: m_finish
 #define P(b) b&&4
                 ^

pr68473-2.c:4:14: note: in expansion of macro ‘P’
 int f() { X||P(d); }
              ^

i.e. it's the: "b&&4"

The patch from comment #5 makes it emit:

pr68473-2.c:2:15: warning: suggest parentheses around '&&' within '||'
[-Wparentheses]
 #define P(b) b&&4
               ^

pr68473-2.c:4:14: note: in expansion of macro 'P'
 int f() { X||P(d); }
              ^

Perhaps ideally it should emit:

pr68473-2.c:2:15: warning: suggest parentheses around '&&' within '||'
[-Wparentheses]
 #define P(b) b&&4
              ~^~~

pr68473-2.c:4:14: note: in expansion of macro 'P'
 int f() { X||P(d); }
              ^

given that all parts of the range are within the same expansion (a much more
involved patch, I think)

Reply via email to