Bug 109970 - -Wstringop-overflow should work with parameter forward declarations
Summary: -Wstringop-overflow should work with parameter forward declarations
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 14.0
: P3 normal
Target Milestone: 14.0
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: Wstringop-overflow
  Show dependency treegraph
 
Reported: 2023-05-25 20:01 UTC by Martin Uecker
Modified: 2023-11-03 20:05 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Uecker 2023-05-25 20:01:13 UTC
For bar I get the expected warning but not for foo.

void bar(int x, char buf[x]);
void foo(int x; char buf[x], int x);

int main()
{
    char buf[10];
    bar(11, buf);
    foo(buf, 11);
}

https://godbolt.org/z/zhzr43c55
Comment 1 GCC Commits 2023-05-26 21:31:45 UTC
The master branch has been updated by Martin Uecker <uecker@gcc.gnu.org>:

https://gcc.gnu.org/g:8d6bd830f5f9c939e8565c0341a0c6c588834484

commit r14-1304-g8d6bd830f5f9c939e8565c0341a0c6c588834484
Author: Martin Uecker <uecker@tugraz.at>
Date:   Fri May 26 11:19:01 2023 +0200

    c: -Wstringop-overflow for parameters with forward-declared sizes
    
    Warnings from -Wstringop-overflow do not appear for parameters declared
    as VLAs when the bound refers to a parameter forward declaration. This
    is fixed by splitting the loop that passes through parameters into two,
    first only recording the positions of all possible size expressions
    and then processing the parameters.
    
    PR c/109970
    
    gcc/c-family:
    
            * c-attribs.cc (build_attr_access_from_parms): Split loop to first
            record all parameters.
    
    gcc/testsuite:
    
            * gcc.dg/pr109970.c: New test.
Comment 2 uecker 2023-11-03 20:05:23 UTC
fixed on trunk.