public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/107805] New: Spurious warning after redefinition of type
@ 2022-11-22  9:19 fw at gcc dot gnu.org
  2022-11-22  9:27 ` [Bug c/107805] [12/13 Regression] Spurious “type defaults to ‘int’” " rguenth at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: fw at gcc dot gnu.org @ 2022-11-22  9:19 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107805
           Summary: Spurious warning after redefinition of type
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fw at gcc dot gnu.org
  Target Milestone: ---

With gcc-11.3.1-3.fc35.x86_64, this program

typedef int t;
typedef struct { double a; int b; } t;
t x;

produces:

t.c:2:37: error: conflicting types for ‘t’; have ‘struct <anonymous>’
    2 | typedef struct { double a; int b; } t;
      |                                     ^
t.c:1:13: note: previous declaration of ‘t’ with type ‘t’ {aka ‘int’}
    1 | typedef int t;
      |             ^

which is expected.  But with gcc-12.2.1-3.fc38.x86_64, I get this instead:

t.c:2:37: error: conflicting types for ‘t’; have ‘struct <anonymous>’
    2 | typedef struct { double a; int b; } t;
      |                                     ^
t.c:1:13: note: previous declaration of ‘t’ with type ‘t’ {aka ‘int’}
    1 | typedef int t;
      |             ^
t.c:3:3: warning: type defaults to ‘int’ in declaration of ‘x’ [-Wimplicit-int]
    3 | t x;
      |   ^

Note the spurious warning.  This causes problems with attempts to eliminate
implicit int, so it would be nice to fix this.

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

* [Bug c/107805] [12/13 Regression] Spurious “type defaults to ‘int’” warning after redefinition of type
  2022-11-22  9:19 [Bug c/107805] New: Spurious warning after redefinition of type fw at gcc dot gnu.org
@ 2022-11-22  9:27 ` rguenth at gcc dot gnu.org
  2022-11-22  9:40 ` fw at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-11-22  9:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Spurious “type defaults to  |[12/13 Regression] Spurious
                   |‘int’” warning after        |“type defaults to ‘int’”
                   |redefinition of type        |warning after redefinition
                   |                            |of type
   Target Milestone|---                         |12.3

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

* [Bug c/107805] [12/13 Regression] Spurious “type defaults to ‘int’” warning after redefinition of type
  2022-11-22  9:19 [Bug c/107805] New: Spurious warning after redefinition of type fw at gcc dot gnu.org
  2022-11-22  9:27 ` [Bug c/107805] [12/13 Regression] Spurious “type defaults to ‘int’” " rguenth at gcc dot gnu.org
@ 2022-11-22  9:40 ` fw at gcc dot gnu.org
  2022-11-22  9:43 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: fw at gcc dot gnu.org @ 2022-11-22  9:40 UTC (permalink / raw)
  To: gcc-bugs

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

Florian Weimer <fw at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |roger at nextmovesoftware dot com
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=79412

--- Comment #1 from Florian Weimer <fw at gcc dot gnu.org> ---
Started with:

commit 823685221de986afb729910a6f2237f07a377f17
Author: Roger Sayle <roger@nextmovesoftware.com>
Date:   Wed Sep 1 08:38:39 2021 +0100

    C: PR c/79412: Poison decls with error_mark_node after type mismatch

    This patch fixes an ICE during error-recovery regression in the C
front-end.
    The symptom is that the middle-end's sanity checking assertions fail during
    gimplification when being asked to increment an array, which is non-sense.
    The issue is that the C-front end has detected the type mismatch and
    reported an error to the user, but hasn't provided any indication of this
    to the middle-end, simply passing bogus trees that the optimizers recognize
    as invalid.

    This appears to be a frequently reported ICE with 94730, 94731, 101036
    and 101365 all marked as duplicates.

    I believe the correct (polite) fix is to mark the mismatched types as
    problematic/dubious in the front-end, when the error is spotted, so that
    the middle-end has a heads-up and can be a little more forgiving.  This
    patch to c-decl.c's duplicate_decls sets (both) mismatched types to
    error_mark_node if they are significantly different, and we've issued
    an error message.  Alas, this is too punitive for FUNCTION_DECLs where
    we store return types, parameter lists, parameter types and attributes
    in the type, but fortunately the middle-end is already more cautious
    about trusting possibly suspect function types.

    This fix required one minor change to the testsuite, typedef-var-2.c
    where after conflicting type definitions, we now no longer assume that
    the (first or) second definition is the correct one.  This change only
    affects the behaviour after seen_error(), so should be relatively safe.

    2021-09-01  Roger Sayle  <roger@nextmovesoftware.com>
                Joseph Myers  <joseph@codesourcery.com>

    gcc/c/ChangeLog
            PR c/79412
            * c-decl.c (duplicate_decls): On significant mismatches, mark the
            types of both (non-function) decls as error_mark_node, so that the
            middle-end can see the code is malformed.
            (free_attr_access_data): Don't process if the type has been set to
            error_mark_node.

    gcc/testsuite/ChangeLog
            PR c/79412
            * gcc.dg/pr79412.c: New test case.
            * gcc.dg/typedef-var-2.c: Update expeted errors.

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

* [Bug c/107805] [12/13 Regression] Spurious “type defaults to ‘int’” warning after redefinition of type
  2022-11-22  9:19 [Bug c/107805] New: Spurious warning after redefinition of type fw at gcc dot gnu.org
  2022-11-22  9:27 ` [Bug c/107805] [12/13 Regression] Spurious “type defaults to ‘int’” " rguenth at gcc dot gnu.org
  2022-11-22  9:40 ` fw at gcc dot gnu.org
@ 2022-11-22  9:43 ` redi at gcc dot gnu.org
  2022-11-22  9:51 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-22  9:43 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-11-22

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

* [Bug c/107805] [12/13 Regression] Spurious “type defaults to ‘int’” warning after redefinition of type
  2022-11-22  9:19 [Bug c/107805] New: Spurious warning after redefinition of type fw at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2022-11-22  9:43 ` redi at gcc dot gnu.org
@ 2022-11-22  9:51 ` jakub at gcc dot gnu.org
  2022-11-22  9:57 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-11-22  9:51 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
declspecs_add_type does:
      if (TREE_TYPE (type) == error_mark_node)
        ; /* Allow the type to default to int to avoid cascading errors.  */
and so it doesn't set specs->type in any way.
Either we could set it to error_mark_node and deal with it anywhere, or could
add
some new specs bit that type was erroneous and just disable the warning when
the new bit is set.

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

* [Bug c/107805] [12/13 Regression] Spurious “type defaults to ‘int’” warning after redefinition of type
  2022-11-22  9:19 [Bug c/107805] New: Spurious warning after redefinition of type fw at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2022-11-22  9:51 ` jakub at gcc dot gnu.org
@ 2022-11-22  9:57 ` jakub at gcc dot gnu.org
  2022-11-22 12:21 ` fw at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-11-22  9:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
One side-effect of not setting specs->type to error_mark_node is that on:
typedef int t;
typedef struct { double a; int b; } t;
t int x;
we don't diagnose the second bug (two or more types in the x declaration).

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

* [Bug c/107805] [12/13 Regression] Spurious “type defaults to ‘int’” warning after redefinition of type
  2022-11-22  9:19 [Bug c/107805] New: Spurious warning after redefinition of type fw at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2022-11-22  9:57 ` jakub at gcc dot gnu.org
@ 2022-11-22 12:21 ` fw at gcc dot gnu.org
  2022-11-24 10:02 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: fw at gcc dot gnu.org @ 2022-11-22 12:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Florian Weimer <fw at gcc dot gnu.org> ---
Patch posted:

[PATCH] c: Propagate erroneous types to declaration specifiers [PR107805]
<https://gcc.gnu.org/pipermail/gcc-patches/2022-November/606999.html>

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

* [Bug c/107805] [12/13 Regression] Spurious “type defaults to ‘int’” warning after redefinition of type
  2022-11-22  9:19 [Bug c/107805] New: Spurious warning after redefinition of type fw at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2022-11-22 12:21 ` fw at gcc dot gnu.org
@ 2022-11-24 10:02 ` cvs-commit at gcc dot gnu.org
  2022-11-24 10:02 ` fw at gcc dot gnu.org
  2023-05-08 12:26 ` [Bug c/107805] [12 " rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-11-24 10:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Florian Weimer <fw@gcc.gnu.org>:

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

commit r13-4286-ga42e39a7b974645d2820931357e99411fdb0beb6
Author: Florian Weimer <fweimer@redhat.com>
Date:   Thu Nov 24 11:00:54 2022 +0100

    c: Propagate erroneous types to declaration specifiers [PR107805]

    Without this change, finish_declspecs cannot tell that whether there
    was an erroneous type specified, or no type at all.  This may result
    in additional diagnostics for implicit ints, or missing diagnostics
    for multiple types.

            PR c/107805

    gcc/c/
            * c-decl.cc (declspecs_add_type): Propagate error_mark_bode
            from type to specs.

    gcc/testsuite/
            * gcc.dg/pr107805-1.c: New test.
            * gcc.dg/pr107805-2.c: Likewise.

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

* [Bug c/107805] [12/13 Regression] Spurious “type defaults to ‘int’” warning after redefinition of type
  2022-11-22  9:19 [Bug c/107805] New: Spurious warning after redefinition of type fw at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2022-11-24 10:02 ` cvs-commit at gcc dot gnu.org
@ 2022-11-24 10:02 ` fw at gcc dot gnu.org
  2023-05-08 12:26 ` [Bug c/107805] [12 " rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: fw at gcc dot gnu.org @ 2022-11-24 10:02 UTC (permalink / raw)
  To: gcc-bugs

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

Florian Weimer <fw at gcc dot gnu.org> changed:

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

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

* [Bug c/107805] [12 Regression] Spurious “type defaults to ‘int’” warning after redefinition of type
  2022-11-22  9:19 [Bug c/107805] New: Spurious warning after redefinition of type fw at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2022-11-24 10:02 ` fw at gcc dot gnu.org
@ 2023-05-08 12:26 ` rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-05-08 12:26 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|12.3                        |12.4

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 12.3 is being released, retargeting bugs to GCC 12.4.

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

end of thread, other threads:[~2023-05-08 12:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-22  9:19 [Bug c/107805] New: Spurious warning after redefinition of type fw at gcc dot gnu.org
2022-11-22  9:27 ` [Bug c/107805] [12/13 Regression] Spurious “type defaults to ‘int’” " rguenth at gcc dot gnu.org
2022-11-22  9:40 ` fw at gcc dot gnu.org
2022-11-22  9:43 ` redi at gcc dot gnu.org
2022-11-22  9:51 ` jakub at gcc dot gnu.org
2022-11-22  9:57 ` jakub at gcc dot gnu.org
2022-11-22 12:21 ` fw at gcc dot gnu.org
2022-11-24 10:02 ` cvs-commit at gcc dot gnu.org
2022-11-24 10:02 ` fw at gcc dot gnu.org
2023-05-08 12:26 ` [Bug c/107805] [12 " rguenth 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).