This revision was automatically updated to reflect the committed changes.
Closed by commit rGf2639cf3fe46: [randstruct] Move initializer check to be more 
effective (authored by void).

Changed prior to commit:
  https://reviews.llvm.org/D124694?vs=426149&id=426788#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124694/new/

https://reviews.llvm.org/D124694

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/Sema/init-randomized-struct.c


Index: clang/test/Sema/init-randomized-struct.c
===================================================================
--- clang/test/Sema/init-randomized-struct.c
+++ clang/test/Sema/init-randomized-struct.c
@@ -1,6 +1,13 @@
-// RUN: %clang_cc1 -triple=x86_64-unknown-linux 
-frandomize-layout-seed=1234567890abcdef \
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux 
-frandomize-layout-seed=1234567890abcded \
 // RUN:  -verify -fsyntax-only -Werror %s
 
+// NOTE: The current seed (1234567890abcded) is specifically chosen because it
+// uncovered a bug in diagnostics. With it the randomization of "t9" places the
+// "a" element at the end of the record. When that happens, the clang complains
+// about excessive initializers, which is confusing, because there aren't
+// excessive initializers. It should instead complain about using a
+// non-designated initializer on a raqndomized struct.
+
 // Initializing a randomized structure requires a designated initializer,
 // otherwise the element ordering will be off. The only exceptions to this rule
 // are:
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -2170,11 +2170,6 @@
       continue;
     }
 
-    if (Field == FieldEnd) {
-      // We've run out of fields. We're done.
-      break;
-    }
-
     // Check if this is an initializer of forms:
     //
     //   struct foo f = {};
@@ -2204,6 +2199,11 @@
       break;
     }
 
+    if (Field == FieldEnd) {
+      // We've run out of fields. We're done.
+      break;
+    }
+
     // We've already initialized a member of a union. We're done.
     if (InitializedSomething && DeclType->isUnionType())
       break;


Index: clang/test/Sema/init-randomized-struct.c
===================================================================
--- clang/test/Sema/init-randomized-struct.c
+++ clang/test/Sema/init-randomized-struct.c
@@ -1,6 +1,13 @@
-// RUN: %clang_cc1 -triple=x86_64-unknown-linux -frandomize-layout-seed=1234567890abcdef \
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux -frandomize-layout-seed=1234567890abcded \
 // RUN:  -verify -fsyntax-only -Werror %s
 
+// NOTE: The current seed (1234567890abcded) is specifically chosen because it
+// uncovered a bug in diagnostics. With it the randomization of "t9" places the
+// "a" element at the end of the record. When that happens, the clang complains
+// about excessive initializers, which is confusing, because there aren't
+// excessive initializers. It should instead complain about using a
+// non-designated initializer on a raqndomized struct.
+
 // Initializing a randomized structure requires a designated initializer,
 // otherwise the element ordering will be off. The only exceptions to this rule
 // are:
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -2170,11 +2170,6 @@
       continue;
     }
 
-    if (Field == FieldEnd) {
-      // We've run out of fields. We're done.
-      break;
-    }
-
     // Check if this is an initializer of forms:
     //
     //   struct foo f = {};
@@ -2204,6 +2199,11 @@
       break;
     }
 
+    if (Field == FieldEnd) {
+      // We've run out of fields. We're done.
+      break;
+    }
+
     // We've already initialized a member of a union. We're done.
     if (InitializedSomething && DeclType->isUnionType())
       break;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to