Bug 101585 - [11 Regression] Bad interaction of -fsanitize=undefined and -Wvla-parameters
Summary: [11 Regression] Bad interaction of -fsanitize=undefined and -Wvla-parameters
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 11.1.0
: P3 normal
Target Milestone: 11.3
Assignee: Martin Sebor
URL:
Keywords: diagnostic
Depends on:
Blocks: Wvla-parameter
  Show dependency treegraph
 
Reported: 2021-07-22 22:18 UTC by Thomas Jahns
Modified: 2022-04-07 10:40 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 11.1.0
Last reconfirmed: 2021-07-23 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Jahns 2021-07-22 22:18:23 UTC
The following source causes an incorrect warning with gcc 11.1.0 (sorry did not have 11.1.1 available, it's not yet in spack):

void a(long send_size_asize, int (*)[send_size_asize]);
void a(long send_size_asize, int (*)[send_size_asize]) {}

Compiling it with

gcc-11.1 -c -Wall -Werror -fsanitize=undefined mini.c

results in

mini.c:2:30: error: mismatch in bound 1 of argument 2 declared as 'int (*)[(send_size_asize) - 1]' []8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wvla-parameter-Werror=vla-parameter]8;;]
    2 | void a(long send_size_asize, int (*)[send_size_asize]) {}
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~
mini.c:1:30: note: previously declared as 'int (*)[(send_size_asize) - 1]'
    1 | void a(long send_size_asize, int (*)[send_size_asize]);
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
Comment 1 Martin Sebor 2021-07-23 00:01:41 UTC
Confirmed.  It looks like an oversight in r12-2329.  The following fixes it:

diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index 552a29f9944..7a50baedea9 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -3275,7 +3275,8 @@ warn_parm_ptrarray_mismatch (location_t origloc, tree curparms, tree newparms)
          /* Move on if the bounds look the same.  */
          if (!pcurbndpos && !pnewbndpos
              && curbnd && newbnd
-             && operand_equal_p (curbnd, newbnd, OEP_LEXICOGRAPHIC))
+             && operand_equal_p (curbnd, newbnd, OEP_LEXICOGRAPHIC
+                                 | OEP_DECL_NAME))
            continue;
 
          if ((curbnd && TREE_CODE (curbnd) != INTEGER_CST)
Comment 2 GCC Commits 2021-07-27 19:52:45 UTC
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:

https://gcc.gnu.org/g:a0f9a5dcc3bbe6c7de499e17d201d0f2cb512649

commit r12-2541-ga0f9a5dcc3bbe6c7de499e17d201d0f2cb512649
Author: Martin Sebor <msebor@redhat.com>
Date:   Tue Jul 27 13:51:55 2021 -0600

    Use OEP_DECL_NAME when comparing VLA bounds [PR101585].
    
    Resolves:
    PR c/101585 - Bad interaction of -fsanitize=undefined and -Wvla-parameters
    
    gcc/c-family:
    
            PR c/101585
            * c-warn.c (warn_parm_ptrarray_mismatch): Use OEP_DECL_NAME.
    
    gcc/testsuite:
            PR c/101585
            * gcc.dg/Wvla-parameter-13.c: New test.
Comment 3 Martin Sebor 2021-07-27 20:33:47 UTC
Fixed in GCC 12.  Will backport to GCC 11.
Comment 4 Richard Biener 2021-07-28 07:07:41 UTC
GCC 11.2 is being released, retargeting bugs to GCC 11.3
Comment 5 GCC Commits 2022-04-07 10:40:09 UTC
The releases/gcc-11 branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:5446b933bc1e9449aa408eb66c31b6fcdbe74214

commit r11-9788-g5446b933bc1e9449aa408eb66c31b6fcdbe74214
Author: Martin Sebor <msebor@redhat.com>
Date:   Tue Jul 27 13:51:55 2021 -0600

    Use OEP_DECL_NAME when comparing VLA bounds [PR101585].
    
    Resolves:
    PR c/101585 - Bad interaction of -fsanitize=undefined and -Wvla-parameters
    
    gcc/c-family:
    
            PR c/101585
            * c-warn.c (warn_parm_ptrarray_mismatch): Use OEP_DECL_NAME.
    
    gcc/testsuite:
            PR c/101585
            * gcc.dg/Wvla-parameter-13.c: New test.
    
    (cherry picked from commit a0f9a5dcc3bbe6c7de499e17d201d0f2cb512649)
Comment 6 Richard Biener 2022-04-07 10:40:51 UTC
Fixed.