Bug 80922 - #pragma diagnostic ignored not honoured with -flto
Summary: #pragma diagnostic ignored not honoured with -flto
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 7.0.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: diagnostic, lto
Depends on:
Reported: 2017-05-30 22:10 UTC by Thiago Macieira
Modified: 2017-06-16 06:28 UTC (History)
3 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2017-05-31 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description Thiago Macieira 2017-05-30 22:10:46 UTC
$ cat f1.cpp
#pragma GCC diagnostic ignored "-Wfree-nonheap-object"
void myfree(void *ptr)

$ cat f2.cpp
void myfree(void *);

static char c;
int main()

This code is intentionally bogus just to trigger the warning. The situation that caused this was correct code, with a false positive warning I was trying to suppress.

$ gcc -O2 -include f1.cpp f2.cpp
[no warning, as expected]

$ gcc -O2 -flto f1.cpp f2.cpp   
In function ‘myfree.constprop’,
    inlined from ‘main’ at f2.cpp:6:11:
f1.cpp:4:19: warning: attempt to free a non-heap object ‘c’ [-Wfree-nonheap-object]
Comment 1 Richard Biener 2017-05-31 07:21:18 UTC
Confirmed.  We do not track warning options (and thus optimize pragmas / attributes) across LTO because they are not saved in the function specific
optimization flag section.