Bug 1948567

Summary: #pragma does not take an effect with -flto
Product: [Fedora] Fedora Reporter: Kamil Dudka <kdudka>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: NEW --- QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 38CC: aoliva, dmalcolm, fweimer, jakub, jwakely, kdudka, law, mpolacek, msebor, nickc, sipoyare
Target Milestone: ---Keywords: Reproducer
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Kamil Dudka 2021-04-12 13:09:25 UTC
Description of problem:
#pragma successfully suppresses a warning at compile time but the same warning then appears again at link time.


Version-Release number of selected component (if applicable):
gcc-11.0.1-0.4.fc35.x86_64


How reproducible:
100%


Steps to Reproduce:
1. prepare two source files:

$ cat main.c    
void foo(char x[2]);

int main() {
    char x[2];
#pragma GCC diagnostic ignored "-Wstringop-overflow"
    foo(x + 1);
}

$ cat foo.c     
void foo(char x[2])
{
    foo(x + 1);
}


2. compile/link without LTO:
$ gcc main.c foo.c


3. compile/link with LTO:
$ gcc -flto main.c foo.c


Actual results:
The warning is not suppressed if LTO is enabled:
main.c: In function ‘main’:
main.c:6:5: warning: ‘foo’ accessing 2 bytes in a region of size 1 [-Wstringop-overflow=]
    6 |     foo(x + 1);
      |     ^
main.c:6:5: note: referencing argument 1 of type ‘char *’
foo.c:1:6: note: in a call to function ‘foo’
    1 | void foo(char x[2])
      |      ^


Expected results:
The warning should be suppressed even when LTO is enabled.


Additional info:
Originally reported by Dmitry Belyavskiy (internal bug #1938797).

Comment 1 Ben Cotton 2021-08-10 12:58:40 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 35 development cycle.
Changing version to 35.

Comment 2 Ben Cotton 2022-11-29 16:55:17 UTC
This message is a reminder that Fedora Linux 35 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora Linux 35 on 2022-12-13.
It is Fedora's policy to close all bug reports from releases that are no longer
maintained. At that time this bug will be closed as EOL if it remains open with a
'version' of '35'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, change the 'version' 
to a later Fedora Linux version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora Linux 35 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora Linux, you are encouraged to change the 'version' to a later version
prior to this bug being closed.

Comment 3 Kamil Dudka 2022-11-30 13:44:40 UTC
This bug affects gcc-12.2.1-4.fc38.x86_64 as well.  The reproducer in comment #0 still works out of the box.

Comment 4 Ben Cotton 2023-02-07 14:51:57 UTC
This bug appears to have been reported against 'rawhide' during the Fedora Linux 38 development cycle.
Changing version to 38.