Re: New GCC 7 -Wformat-truncation suppressed by (and only by) -Og?

2017-02-23 Thread Stephan Bergmann

On 02/23/2017 05:02 PM, Martin Sebor wrote:

On 02/23/2017 06:51 AM, Stephan Bergmann wrote:

At least with a recent GCC 7 trunk build ("gcc (GCC) 7.0.1 20170221
(experimental)"), I noticed that -Wformat-truncation warnings happen to
not be emitted if and only if -Og is given:


That's unfortunately a bug.  The warning runs at different stages
depending on whether or not optimization is enabled and it looks
like the global GCC variable it uses to determine this is not set
for -Og.  Can you please open a bug in Bugzilla?


 
"-Wformat-truncation suppressed by (and only by) -Og"


Re: New GCC 7 -Wformat-truncation suppressed by (and only by) -Og?

2017-02-23 Thread Martin Sebor

On 02/23/2017 06:51 AM, Stephan Bergmann wrote:

At least with a recent GCC 7 trunk build ("gcc (GCC) 7.0.1 20170221
(experimental)"), I noticed that -Wformat-truncation warnings happen to
not be emitted if and only if -Og is given:


That's unfortunately a bug.  The warning runs at different stages
depending on whether or not optimization is enabled and it looks
like the global GCC variable it uses to determine this is not set
for -Og.  Can you please open a bug in Bugzilla?

Thanks
Martin




$ cat test.c
#include 
int main() {
char buf[3];
snprintf(buf, sizeof buf, "%s", "foo");
return 0;
}
$ gcc -Wformat-truncation -Og ~/test.c
$ gcc -Wformat-truncation -O ~/test.c
test.c: In function ‘main’:
test.c:4:34: warning: ‘snprintf’ output truncated before the last
format character [-Wformat-truncation=]
 snprintf(buf, sizeof buf, "%s", "foo");
  ^
test.c:4:5: note: ‘snprintf’ output 4 bytes into a destination of size 3
 snprintf(buf, sizeof buf, "%s", "foo");
 ^~


Any other optimization level (-O1..3/s/fast) does emit the warning.  The
documentation makes it clear that the behavior of that warning may be
coupled to the optimization level, but this difference between -Og and
everything else still looks somewhat odd.  Could it be by mistake?




Re: New GCC 7 -Wformat-truncation suppressed by (and only by) -Og?

2017-02-23 Thread Stephan Bergmann

On 02/23/2017 02:51 PM, Stephan Bergmann wrote:

At least with a recent GCC 7 trunk build ("gcc (GCC) 7.0.1 20170221
(experimental)"), I noticed that -Wformat-truncation warnings happen to
not be emitted if and only if -Og is given:


$ cat test.c
#include 
int main() {
char buf[3];
snprintf(buf, sizeof buf, "%s", "foo");
return 0;
}
$ gcc -Wformat-truncation -Og ~/test.c
$ gcc -Wformat-truncation -O ~/test.c
test.c: In function ‘main’:
test.c:4:34: warning: ‘snprintf’ output truncated before the last
format character [-Wformat-truncation=]
 snprintf(buf, sizeof buf, "%s", "foo");
  ^
test.c:4:5: note: ‘snprintf’ output 4 bytes into a destination of size 3
 snprintf(buf, sizeof buf, "%s", "foo");
 ^~


Any other optimization level (-O1..3/s/fast) does emit the warning.  The


-O0..3, even


documentation makes it clear that the behavior of that warning may be
coupled to the optimization level, but this difference between -Og and
everything else still looks somewhat odd.  Could it be by mistake?




New GCC 7 -Wformat-truncation suppressed by (and only by) -Og?

2017-02-23 Thread Stephan Bergmann
At least with a recent GCC 7 trunk build ("gcc (GCC) 7.0.1 20170221 
(experimental)"), I noticed that -Wformat-truncation warnings happen to 
not be emitted if and only if -Og is given:



$ cat test.c
#include 
int main() {
char buf[3];
snprintf(buf, sizeof buf, "%s", "foo");
return 0;
}
$ gcc -Wformat-truncation -Og ~/test.c
$ gcc -Wformat-truncation -O ~/test.c
test.c: In function ‘main’:
test.c:4:34: warning: ‘snprintf’ output truncated before the last format 
character [-Wformat-truncation=]
 snprintf(buf, sizeof buf, "%s", "foo");
  ^
test.c:4:5: note: ‘snprintf’ output 4 bytes into a destination of size 3
 snprintf(buf, sizeof buf, "%s", "foo");
 ^~


Any other optimization level (-O1..3/s/fast) does emit the warning.  The 
documentation makes it clear that the behavior of that warning may be 
coupled to the optimization level, but this difference between -Og and 
everything else still looks somewhat odd.  Could it be by mistake?