]> granicus.if.org Git - clang/commitdiff
CheckStringInit has side effects; make sure we don't run it in VerifyOnly mode, at...
authorEli Friedman <eli.friedman@gmail.com>
Mon, 26 Sep 2011 19:09:09 +0000 (19:09 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Mon, 26 Sep 2011 19:09:09 +0000 (19:09 +0000)
Sebastian, please take a look at this; I'm not entirely sure it is the right thing to do.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140552 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaInit.cpp
test/Sema/init.c

index 9257b81335ec936755177b3db281e53c46b9fe6f..0c518c7bda1c84ea82d2cb432859c8f1a4fd3c7f 100644 (file)
@@ -744,8 +744,10 @@ void InitListChecker::CheckSubElementType(const InitializedEntity &Entity,
     // type here, though.
 
     if (Expr *Str = IsStringInit(expr, arrayType, SemaRef.Context)) {
-      CheckStringInit(Str, ElemType, arrayType, SemaRef);
-      UpdateStructuredListElement(StructuredList, StructuredIndex, Str);
+      if (!VerifyOnly) {
+        CheckStringInit(Str, ElemType, arrayType, SemaRef);
+        UpdateStructuredListElement(StructuredList, StructuredIndex, Str);
+      }
       ++Index;
       return;
     }
@@ -1116,13 +1118,13 @@ void InitListChecker::CheckArrayType(const InitializedEntity &Entity,
   if (Index < IList->getNumInits()) {
     if (Expr *Str = IsStringInit(IList->getInit(Index), arrayType,
                                  SemaRef.Context)) {
-      CheckStringInit(Str, DeclType, arrayType, SemaRef);
       // We place the string literal directly into the resulting
       // initializer list. This is the only place where the structure
       // of the structured initializer list doesn't match exactly,
       // because doing so would involve allocating one character
       // constant for each string.
       if (!VerifyOnly) {
+        CheckStringInit(Str, DeclType, arrayType, SemaRef);
         UpdateStructuredListElement(StructuredList, StructuredIndex, Str);
         StructuredList->resizeInits(SemaRef.Context, StructuredIndex);
       }
index f8110079d0eb47fd44479d714fc83457c04eaaa3..2527e14fcbe9ed85d7f2c26da9f6e0de46567046 100644 (file)
@@ -144,3 +144,7 @@ int PR4386_b = ((void *) PR4386_foo) != 0; // expected-error{{initializer elemen
 int PR4386_c = ((void *) PR4386_zed) != 0;
 int PR4386_zed() __attribute((weak));
 
+// <rdar://problem/10185490> (derived from SPEC vortex benchmark)
+typedef char strty[10];
+struct vortexstruct { strty s; };
+struct vortexstruct vortexvar = { "asdf" };