public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/99420] New: New warning -Warray-parameter
@ 2021-03-05 20:06 raj.khem at gmail dot com
  2021-03-07  0:19 ` [Bug c/99420] " egallager at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: raj.khem at gmail dot com @ 2021-03-05 20:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99420

            Bug ID: 99420
           Summary: New warning -Warray-parameter
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: raj.khem at gmail dot com
  Target Milestone: ---

Following code (reduced from nss ) exhibits new warning with gcc11 on x86_64,
this doe s not happen when both these externs are in one function e.g. foo(),
its an expansion of PR_STATIC_ASSERT from nspr headers 

#define PR_STATIC_ASSERT(condition) \
    extern void pr_static_assert(int arg[(condition) ? 1 : -1])

my gcc version is

gcc version 11.0.1 20210303 (experimental) (GCC) 

a.c
==========================
void foo()
{
    unsigned char bytes[(440 / 8) * 2];
    extern void pr_static_assert(int arg[(sizeof(bytes) >= 32) ? 1 : -1]);
}
void bar()
{
    extern void pr_static_assert(int arg[(((long unsigned int)-1) > (long
unsigned int)1) ? 1 : -1]);
}

===========================

$ x86_64-yoe-linux-musl-gcc -c a.c -Werror=array-parameter=2

a.c: In function 'bar':
a.c:8:38: error: argument 1 of type 'int[1]' with mismatched bound
[-Werror=array-parameter=]
    8 |     extern void pr_static_assert(int arg[(((long unsigned int)-1) >
(long unsigned int)1) ? 1 : -1]);
      |                                 
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.c:4:38: note: previously declared as 'int *'
    4 |     extern void pr_static_assert(int arg[(sizeof(bytes) >= 32) ? 1 :
-1]);
      |                                 
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/99420] New warning -Warray-parameter
  2021-03-05 20:06 [Bug c/99420] New: New warning -Warray-parameter raj.khem at gmail dot com
@ 2021-03-07  0:19 ` egallager at gcc dot gnu.org
  2021-03-08  9:25 ` marxin at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: egallager at gcc dot gnu.org @ 2021-03-07  0:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99420

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |egallager at gcc dot gnu.org,
                   |                            |msebor at gcc dot gnu.org
           Keywords|                            |diagnostic

--- Comment #1 from Eric Gallager <egallager at gcc dot gnu.org> ---
I'm pretty sure Martin Sebor added this warning; cc-ing him...

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/99420] New warning -Warray-parameter
  2021-03-05 20:06 [Bug c/99420] New: New warning -Warray-parameter raj.khem at gmail dot com
  2021-03-07  0:19 ` [Bug c/99420] " egallager at gcc dot gnu.org
@ 2021-03-08  9:25 ` marxin at gcc dot gnu.org
  2021-03-08 17:34 ` msebor at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-03-08  9:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99420

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-03-08
                 CC|                            |marxin at gcc dot gnu.org

--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
Started with r11-3303-g6450f07388f9fe57.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/99420] New warning -Warray-parameter
  2021-03-05 20:06 [Bug c/99420] New: New warning -Warray-parameter raj.khem at gmail dot com
  2021-03-07  0:19 ` [Bug c/99420] " egallager at gcc dot gnu.org
  2021-03-08  9:25 ` marxin at gcc dot gnu.org
@ 2021-03-08 17:34 ` msebor at gcc dot gnu.org
  2021-03-16 11:52 ` [Bug c/99420] [11 Regression] bogus -Warray-parameter on a function redeclaration in function scope rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-03-08 17:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99420

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
The false positive is caused by the local redeclaration of f1() in h() below
not having had the type attributes added to it describing the form of the
array.  This happens because instead of merging the type attributes from the
previous declaration of f1() in g() into those in h() as is done for f0,
pushdecl() sets them to null (on lines 3525-3562 in c/c-decl.c).   The
difference is due to pushdecl() treating redeclarations of entities that are in
scope (like f0) differently than those that aren't (like f1() in h()).

$ cat u.c && gcc -S -Wall u.c
void f0 (int [1]);
void f0 (int [1]);   // okay

void g (void)
{
  void f1 (int [1]);
}

void h (void)
{
  void f1 (int [1]);   // bogus -Warray-parameter
}

u.c: In function ‘h’:
u.c:11:12: warning: argument 1 of type ‘int[1]’ with mismatched bound
[-Warray-parameter=]
   11 |   void f1 (int [1]);   // bogus -Warray-parameter
      |            ^~~~~~~
u.c:6:12: note: previously declared as ‘int *’
    6 |   void f1 (int [1]);
      |            ^~~~~~~

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/99420] [11 Regression] bogus -Warray-parameter on a function redeclaration in function scope
  2021-03-05 20:06 [Bug c/99420] New: New warning -Warray-parameter raj.khem at gmail dot com
                   ` (2 preceding siblings ...)
  2021-03-08 17:34 ` msebor at gcc dot gnu.org
@ 2021-03-16 11:52 ` rguenth at gcc dot gnu.org
  2021-04-08 12:56 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-03-16 11:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99420

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.0

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/99420] [11 Regression] bogus -Warray-parameter on a function redeclaration in function scope
  2021-03-05 20:06 [Bug c/99420] New: New warning -Warray-parameter raj.khem at gmail dot com
                   ` (3 preceding siblings ...)
  2021-03-16 11:52 ` [Bug c/99420] [11 Regression] bogus -Warray-parameter on a function redeclaration in function scope rguenth at gcc dot gnu.org
@ 2021-04-08 12:56 ` rguenth at gcc dot gnu.org
  2021-04-08 16:32 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-04-08 12:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99420

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/99420] [11 Regression] bogus -Warray-parameter on a function redeclaration in function scope
  2021-03-05 20:06 [Bug c/99420] New: New warning -Warray-parameter raj.khem at gmail dot com
                   ` (4 preceding siblings ...)
  2021-04-08 12:56 ` rguenth at gcc dot gnu.org
@ 2021-04-08 16:32 ` jakub at gcc dot gnu.org
  2021-04-08 16:48 ` msebor at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-04-08 16:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99420

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jsm28 at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
If not copying over the attribute is intentional when it isn't builtin, we
could still copy over just the single attribute, like:
--- gcc/c/c-decl.c.jj   2021-03-16 00:21:29.464233163 +0100
+++ gcc/c/c-decl.c      2021-04-08 18:19:24.762093841 +0200
@@ -3268,6 +3268,17 @@ pushdecl (tree x)
            thistype
              = build_type_attribute_variant (thistype,
                                              TYPE_ATTRIBUTES (b->u.type));
+         else if (!lookup_attribute ("access", TYPE_ATTRIBUTES (thistype)))
+           if (tree access = lookup_attribute ("access",
+                                               TYPE_ATTRIBUTES (b->u.type)))
+             {
+               /* Otherwise, copy over the access attribute.  */
+               tree attr = tree_cons (TREE_PURPOSE (access),
+                                      TREE_VALUE (access),
+                                      TYPE_ATTRIBUTES (thistype));
+               thistype
+                 = build_type_attribute_variant (thistype, attr);
+             }
          TREE_TYPE (b->decl) = thistype;
          bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true,
                locus);
Except that the access attribute unfortunately seems to mean a lot of different
things, it is a user attribute with some arguments that is later rewritten into
a different form and that other form is reused also for the array parameters
and the -Warray-parameter stuff using that.
So, if both decls of f1 should have different attributes, then doing the above
is undesirable because it would also result in user's access attributes being
copied over, or that for user access attribute on the second declaration would
result in it not being copied.
Perhaps we can copy the attribute under a different attribute name (something
with space in it so that it isn't user accessible) and use that for
-Warray-parameter purposes in preference over "access"?
Also, I'd argue that the rewritten "access" attribute shouldn't be called
"access" but with some internal name.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/99420] [11 Regression] bogus -Warray-parameter on a function redeclaration in function scope
  2021-03-05 20:06 [Bug c/99420] New: New warning -Warray-parameter raj.khem at gmail dot com
                   ` (5 preceding siblings ...)
  2021-04-08 16:32 ` jakub at gcc dot gnu.org
@ 2021-04-08 16:48 ` msebor at gcc dot gnu.org
  2021-04-08 22:17 ` msebor at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-08 16:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99420

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=99972

--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
The attributes need to be copied/merged across redeclarations of the same
symbol regardless of the scope.  See pr99972 for another example where failing
to do it causes a false positive.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/99420] [11 Regression] bogus -Warray-parameter on a function redeclaration in function scope
  2021-03-05 20:06 [Bug c/99420] New: New warning -Warray-parameter raj.khem at gmail dot com
                   ` (6 preceding siblings ...)
  2021-04-08 16:48 ` msebor at gcc dot gnu.org
@ 2021-04-08 22:17 ` msebor at gcc dot gnu.org
  2021-04-15 21:51 ` cvs-commit at gcc dot gnu.org
  2021-04-15 21:52 ` msebor at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-08 22:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99420

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot gnu.org

--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
Patch: https://gcc.gnu.org/pipermail/gcc-patches/2021-April/567800.html

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/99420] [11 Regression] bogus -Warray-parameter on a function redeclaration in function scope
  2021-03-05 20:06 [Bug c/99420] New: New warning -Warray-parameter raj.khem at gmail dot com
                   ` (7 preceding siblings ...)
  2021-04-08 22:17 ` msebor at gcc dot gnu.org
@ 2021-04-15 21:51 ` cvs-commit at gcc dot gnu.org
  2021-04-15 21:52 ` msebor at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-04-15 21:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99420

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:

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

commit r11-8205-gda879e01ecd35737c18be1da3324f4560aba1961
Author: Martin Sebor <msebor@redhat.com>
Date:   Thu Apr 15 15:49:30 2021 -0600

    Propagate type attribute when merging extern declarations at local scope.

    Resolves:
    PR c/99420 - bogus -Warray-parameter on a function redeclaration in
function scope
    PR c/99972 - missing -Wunused-result on a call to a locally redeclared
warn_unused_result function

    gcc/c/ChangeLog:

            PR c/99420
            PR c/99972
            * c-decl.c (pushdecl): Always propagate type attribute.

    gcc/testsuite/ChangeLog:

            PR c/99420
            PR c/99972
            * gcc.dg/Warray-parameter-9.c: New test.
            * gcc.dg/Wnonnull-6.c: New test.
            * gcc.dg/Wreturn-type3.c: New test.
            * gcc.dg/Wunused-result.c: New test.
            * gcc.dg/attr-noreturn.c: New test.
            * gcc.dg/attr-returns-nonnull.c: New test.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/99420] [11 Regression] bogus -Warray-parameter on a function redeclaration in function scope
  2021-03-05 20:06 [Bug c/99420] New: New warning -Warray-parameter raj.khem at gmail dot com
                   ` (8 preceding siblings ...)
  2021-04-15 21:51 ` cvs-commit at gcc dot gnu.org
@ 2021-04-15 21:52 ` msebor at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-15 21:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99420

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #8 from Martin Sebor <msebor at gcc dot gnu.org> ---
Fix committed in r11-8205.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-04-15 21:52 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-05 20:06 [Bug c/99420] New: New warning -Warray-parameter raj.khem at gmail dot com
2021-03-07  0:19 ` [Bug c/99420] " egallager at gcc dot gnu.org
2021-03-08  9:25 ` marxin at gcc dot gnu.org
2021-03-08 17:34 ` msebor at gcc dot gnu.org
2021-03-16 11:52 ` [Bug c/99420] [11 Regression] bogus -Warray-parameter on a function redeclaration in function scope rguenth at gcc dot gnu.org
2021-04-08 12:56 ` rguenth at gcc dot gnu.org
2021-04-08 16:32 ` jakub at gcc dot gnu.org
2021-04-08 16:48 ` msebor at gcc dot gnu.org
2021-04-08 22:17 ` msebor at gcc dot gnu.org
2021-04-15 21:51 ` cvs-commit at gcc dot gnu.org
2021-04-15 21:52 ` msebor at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).