public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Avoid infinite loop with duplicate anonymous union fields
@ 2018-07-27 10:27 Bogdan Harjoc
  2018-07-27 17:02 ` Joseph Myers
  0 siblings, 1 reply; 9+ messages in thread
From: Bogdan Harjoc @ 2018-07-27 10:27 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 980 bytes --]

(this patch is already uploaded to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86690 )

If a struct contains an anonymous union and both have a field with the
same name, detect_field_duplicates_hash() will replace one of them
with NULL. If compilation doesn't stop immediately, it may later call
lookup_field() on the union, which falsely assumes the union's
LANG_SPECIFIC array is sorted, and may loop indefinitely because of
this.

Reproduced on amd64 since gcc-5, on ubuntu-18.04 and gentoo.

The patch falls back to iterating via DECL_CHAIN if there was an error
earlier during compilation.

I ran the gcc testsuite with the result (the FAIL seems unrelated to the patch):

FAIL: gcc.dg/cpp/_Pragma3.c (test for excess errors)

                === gcc Summary ===

# of expected passes            135094
# of unexpected failures        1
# of expected failures          398
# of unsupported tests          2140
gcc-build/gcc/xgcc  version 8.0.1 20180424 (experimental) (GCC)

[-- Attachment #2: avoid-loop-with-duplicate-union-field.patch --]
[-- Type: text/x-patch, Size: 1031 bytes --]

--- gcc-8.0.1-20180424/gcc/c/c-typeck.c	2018-07-26 20:00:55.475792602 +0300
+++ gcc-8.0.1-20180424/gcc/c/c-typeck.c	2018-07-26 21:39:13.312629356 +0300
@@ -2207,9 +2207,14 @@
   /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
      to the field elements.  Use a binary search on this array to quickly
      find the element.  Otherwise, do a linear search.  TYPE_LANG_SPECIFIC
-     will always be set for structures which have many elements.  */
+     will always be set for structures which have many elements.
+             
+     Duplicate field checking replaces duplicates with NULL_TREE so
+     TYPE_LANG_SPECIFIC arrays are potentially no longer sorted. In that
+     case just iterate using DECL_CHAIN. */
 
-  if (TYPE_LANG_SPECIFIC (type) && TYPE_LANG_SPECIFIC (type)->s)
+  if (TYPE_LANG_SPECIFIC (type) && TYPE_LANG_SPECIFIC (type)->s 
+	  && diagnostic_kind_count(global_dc, DK_ERROR) == 0) 
     {
       int bot, top, half;
       tree *field_array = &TYPE_LANG_SPECIFIC (type)->s->elts[0];

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

end of thread, other threads:[~2018-08-03 15:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-27 10:27 [PATCH] Avoid infinite loop with duplicate anonymous union fields Bogdan Harjoc
2018-07-27 17:02 ` Joseph Myers
2018-07-31  9:56   ` Bogdan Harjoc
2018-07-31 17:45     ` Richard Sandiford
2018-07-31 19:43     ` Joseph Myers
2018-07-31 22:03       ` Bogdan Harjoc
2018-07-31 22:20         ` Joseph Myers
2018-08-01 14:26           ` Bogdan Harjoc
2018-08-03 15:26             ` Joseph Myers

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).