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
URL:
Keywords: diagnostic, lto
Depends on:
Blocks:
 
Reported: 2017-05-30 22:10 UTC by Thiago Macieira
Modified: 2017-06-16 06:28 UTC (History)
3 users (show)

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


Attachments

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)
{
    __builtin_free(ptr);
}

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

static char c;
int main()
{
    myfree(&c);
}

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]
     __builtin_free(ptr);
                   ^
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.