r181174 - Fix assert if __extension__ or _Generic is used when initializing a char array from a string literal.

Richard Smith richard-llvm at metafoo.co.uk
Sun May 5 17:35:48 PDT 2013


Author: rsmith
Date: Sun May  5 19:35:47 2013
New Revision: 181174

URL: http://llvm.org/viewvc/llvm-project?rev=181174&view=rev
Log:
Fix assert if __extension__ or _Generic is used when initializing a char array from a string literal.

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

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=181174&r1=181173&r2=181174&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Sun May  5 19:35:47 2013
@@ -85,12 +85,19 @@ static Expr *IsStringInit(Expr *init, Qu
 /// Update the type of a string literal, including any surrounding parentheses,
 /// to match the type of the object which it is initializing.
 static void updateStringLiteralType(Expr *E, QualType Ty) {
-  while (ParenExpr *PE = dyn_cast<ParenExpr>(E)) {
+  while (true) {
     E->setType(Ty);
-    E = PE->getSubExpr();
+    if (isa<StringLiteral>(E) || isa<ObjCEncodeExpr>(E))
+      break;
+    else if (ParenExpr *PE = dyn_cast<ParenExpr>(E))
+      E = PE->getSubExpr();
+    else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(E))
+      E = UO->getSubExpr();
+    else if (GenericSelectionExpr *GSE = dyn_cast<GenericSelectionExpr>(E))
+      E = GSE->getResultExpr();
+    else
+      llvm_unreachable("unexpected expr in string literal init");
   }
-  assert(isa<StringLiteral>(E) || isa<ObjCEncodeExpr>(E));
-  E->setType(Ty);
 }
 
 static void CheckStringInit(Expr *Str, QualType &DeclT, const ArrayType *AT,

Modified: cfe/trunk/test/Sema/array-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/array-init.c?rev=181174&r1=181173&r2=181174&view=diff
==============================================================================
--- cfe/trunk/test/Sema/array-init.c (original)
+++ cfe/trunk/test/Sema/array-init.c Sun May  5 19:35:47 2013
@@ -187,7 +187,7 @@ char r6[sizeof r5 == 15 ? 1 : -1];
 const char r7[] = "zxcv";
 char r8[5] = "5char";
 char r9[5] = "6chars"; //expected-warning{{initializer-string for char array is too long}}
-
+unsigned char r10[] = __extension__ (_Generic(0, int: (__extension__ "foo" )));
 int r11[0] = {}; //expected-warning{{zero size arrays are an extension}} expected-warning{{use of GNU empty initializer extension}}
 
 // Some struct tests





More information about the cfe-commits mailing list