Bug 83412 - GCC line directive suppresses warnings
Summary: GCC line directive suppresses warnings
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2017-12-13 17:22 UTC by Martin Sebor
Modified: 2017-12-14 16:17 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 5.4.0, 6.4.0, 7.2.0, 8.0
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2017-12-13 17:22:58 UTC
For some reason the GCC # line directive suppresses warnings.  See bug 83404, comment 2 for the origin of this bug report.

$ cat a.c && gcc -O2 -S -Wall a.c
#include <string.h>

char x[12];

void f (void)
{
  __builtin_strncat (x, "aa", 1);   // warning (good)
}

void g (void)
{
  strncat (x, "aa", 1);   // no warning (bug)
}

a.c: In function ‘f’:
a.c:7:3: warning: ‘__builtin_strncat’ output truncated copying 1 byte from a string of length 2 [-Wstringop-truncation]
   __builtin_strncat (x, "aa", 1);   // warning (good)
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


The problem can be reproduced with another, simpler test case:

$ cat a.ii && gcc -O2 -S -Wall a.ii
char x[12];

void f (void)
{
  x[13] = 0;   // -Warray-bounds (good)
}

int g (void)
{
# 12 "a.c" 3 4
  return x[13];   // no warning (bug)
}
a.ii: In function ‘void f()’:
a.ii:5:7: warning: array subscript 13 is above array bounds of ‘char [12]’ [-Warray-bounds]
   x[13] = 0;   // -Warray-bounds (good)
   ~~~~^
Comment 1 Martin Sebor 2017-12-13 17:23:49 UTC
All releases as far back as 5.4 have this problem.
Comment 2 Andrew Pinski 2017-12-13 18:07:44 UTC
# 12 "a.c" 3 4

This means you are in a system header so -Wsystem is needed IIRC.
Comment 3 Richard Biener 2017-12-14 08:46:48 UTC
Indeed.
Comment 4 Martin Sebor 2017-12-14 16:17:18 UTC
I see.  I (obviously) didn't know that.  It seems like something worth documenting.