how to disable warning from -flto link ?
Martin Sebor
msebor@gmail.com
Sat Feb 3 18:30:00 GMT 2018
On 01/31/2018 02:41 AM, Jay Foad wrote:
> See example below: I'm getting warnings emitted by the -flto link stage.
> I'd like to selectively disable these warnings in my build scripts, but the
> usual -Wno-* option doesn't seem to have any effect. Is it supposed to
> work? Is there another way to do it?
It is supposed to work but it doesn't appear to. I don't see
the warning with your test case where the memset is eliminated
but I can reproduce it when the array is used. There are at
least a couple of bugs in Bugzilla for the interaction between
some warning options and LTO (e.g., 71907 and 79062) but I don't
know of one that points out that the suppression doesn't work.
Please go ahead and open one if you have an account, or otherwise
let me know and I'll open one for you.
As someone already pointed out, in the test case below the warning
is justified. Submitting a test case where the warning is a false
positive, especially one derived from an existing code base, might
increase the bug's priority.
Thanks
Martin
$ (set -x && cat a.c && cat b.c; cc='gcc -O2 -flto -ffat-lto-objects
-Wno-stringop-overflow'; $cc -c a.c b.c && $cc a.o b.o && ./a.out)
+ cat a.c
#include <string.h>
void a(char * x, int n)
{
memset (x, '*', n);
}
+ cat b.c
#include <stdio.h>
void a(char *, int);
int main() {
char x[3];
a(x, 4);
printf ("%.4s\n", x);
}
+ cc='gcc -O2 -flto -ffat-lto-objects -Wno-stringop-overflow'
+ gcc -O2 -flto -ffat-lto-objects -Wno-stringop-overflow -c a.c b.c
+ gcc -O2 -flto -ffat-lto-objects -Wno-stringop-overflow a.o b.o
In function âa.constpropâ,
inlined from âmainâ at b.c:7:3:
a.c:4:3: warning: âmemsetâ writing 4 bytes into a region of size 3
overflows the destination [-Wstringop-overflow=]
memset (x, '*', n);
^
+ ./a.out
****
>
> Thanks,
> Jay.
>
> $ gcc --version
> gcc (Ubuntu 7.2.0-8ubuntu3) 7.2.0
> Copyright (C) 2017 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>
> $ cat a.c
> #include <string.h>
> void a(char * x, int n) {
> memset(x, 0, n);
> }
> $ cat b.c
> void a(char *, int);
> int main() {
> char x[3];
> a(x, 4);
> }
> $ gcc -O3 -flto -c a.c b.c -Wno-stringop-overflow
> $ gcc -O3 -flto a.o b.o -Wno-stringop-overflow
> In function âmemsetâ,
> inlined from âmainâ at a.c:3:2:
> /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:10: warning:
> â__builtin___memset_chkâ writing 4 bytes into a region of size 3 overflows
> the destination [-Wstringop-overflow=]
> return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));
> ^
>
More information about the Gcc-help
mailing list