[cfe-commits] r126056 - in /cfe/trunk: lib/Sema/SemaInit.cpp test/CodeGen/init.c

Chris Lattner sabre at nondot.org
Sat Feb 19 14:28:58 PST 2011


Author: lattner
Date: Sat Feb 19 16:28:58 2011
New Revision: 126056

URL: http://llvm.org/viewvc/llvm-project?rev=126056&view=rev
Log:
implement a tiny amount of codegen support for gnu array range 
designators: allowing codegen when the element initializer is a
constant or something else without a side effect.  This unblocks
enough to let process.c in the linux kernel build, PR9257.


Modified:
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/CodeGen/init.c

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=126056&r1=126055&r2=126056&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Sat Feb 19 16:28:58 2011
@@ -1593,14 +1593,19 @@
   } else {
     assert(D->isArrayRangeDesignator() && "Need array-range designator");
 
-
     DesignatedStartIndex =
       DIE->getArrayRangeStart(*D)->EvaluateAsInt(SemaRef.Context);
     DesignatedEndIndex =
       DIE->getArrayRangeEnd(*D)->EvaluateAsInt(SemaRef.Context);
     IndexExpr = DIE->getArrayRangeEnd(*D);
 
-    if (DesignatedStartIndex.getZExtValue() !=DesignatedEndIndex.getZExtValue())
+    // Codegen can't handle evaluating array range designators that have side
+    // effects, because we replicate the AST value for each initialized element.
+    // As such, set the sawArrayRangeDesignator() bit if we initialize multiple
+    // elements with something that has a side effect, so codegen can emit an
+    // "error unsupported" error instead of miscompiling the app.
+    if (DesignatedStartIndex.getZExtValue()!=DesignatedEndIndex.getZExtValue()&&
+        DIE->getInit()->HasSideEffects(SemaRef.Context))
       FullyStructuredList->sawArrayRangeDesignator();
   }
 

Modified: cfe/trunk/test/CodeGen/init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/init.c?rev=126056&r1=126055&r2=126056&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/init.c (original)
+++ cfe/trunk/test/CodeGen/init.c Sat Feb 19 16:28:58 2011
@@ -100,3 +100,18 @@
   // CHECK-NOT: store i32 0
   // CHECK: call void @bar
 }
+
+
+// PR9257
+struct test11S {
+  int A[10];
+};
+void test11(struct test11S *P) {
+  *P = (struct test11S) { .A = { [0 ... 3] = 4 } };
+  // CHECK: @test11
+  // CHECK: store i32 4
+  // CHECK: store i32 4
+  // CHECK: store i32 4
+  // CHECK: store i32 4
+  // CHECK: ret void
+}





More information about the cfe-commits mailing list