[PATCH] improve detection of incompatible redeclarations (PR 97882)

Martin Sebor msebor@gmail.com
Wed Feb 3 23:21:27 GMT 2021


The test case in the bug report shows that the C front end is
too permissive in accepting invalid redeclarations that involve
an incomplete enum and an otherwise compatible integer type as
return types of a function without a prototype, or as types of
an ordinary variable.  For example, the redeclaration below is
accepted:

   extern enum E { e0 } e;
   extern unsigned e;

In the case of a function the redeclaration can lead to a back
end ICE when one of the declarations is a function definition:

   extern enum F f ();
   extern unsigned f () { }

The attached patch tightens up the front end to reject even these
invalid redeclarations, thus avoiding the ICE.

Tested on x86_64-linux.

The bug is a P2 GCC 7-11 regression but in his comment Joseph
suggests to avoid backporting the fix to release branches due to
the potential to invalidate otherwise presumably benign code that's
accepted there, so I'm looking for approval only for GCC 11.

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-97882.diff
Type: text/x-patch
Size: 26584 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210203/d2babc8b/attachment-0001.bin>


More information about the Gcc-patches mailing list