]> granicus.if.org Git - clang/commitdiff
Fix InitListExpr::isStringLiteralInit so it handles various edge cases correctly...
authorEli Friedman <eli.friedman@gmail.com>
Mon, 20 Aug 2012 20:55:45 +0000 (20:55 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Mon, 20 Aug 2012 20:55:45 +0000 (20:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162226 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Expr.cpp
test/CodeGen/const-init.c

index 24361efafa6c42a89fdcdd7c5da5c86504217a01..7e82382942d189f0a21d225c46aab9b7039a0016 100644 (file)
@@ -1723,10 +1723,10 @@ void InitListExpr::setArrayFiller(Expr *filler) {
 bool InitListExpr::isStringLiteralInit() const {
   if (getNumInits() != 1)
     return false;
-  const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(getType());
-  if (!CAT || !CAT->getElementType()->isIntegerType())
+  const ArrayType *AT = getType()->getAsArrayTypeUnsafe();
+  if (!AT || !AT->getElementType()->isIntegerType())
     return false;
-  const Expr *Init = getInit(0)->IgnoreParenImpCasts();
+  const Expr *Init = getInit(0)->IgnoreParens();
   return isa<StringLiteral>(Init) || isa<ObjCEncodeExpr>(Init);
 }
 
index 4f3f7ab5533088a87c77962dd8f162cfcea8a6ce..5f729b8df42858d57023997da5badc4d9d9d24e7 100644 (file)
@@ -144,3 +144,18 @@ void g28() {
   static v12i16 b = (v2f80){1,2};
   static v2f80 c = (v12i16){0,0,0,-32768,16383,0,0,0,0,-32768,16384,0};
 }
+
+// PR13643
+void g29() {
+  typedef char DCC_PASSWD[2];
+  typedef struct
+  {
+      DCC_PASSWD passwd;
+  } DCC_SRVR_NM;
+  // CHECK: @g29.a = internal global %struct.DCC_SRVR_NM { [2 x i8] c"@\00" }, align 1
+  // CHECK: @g29.b = internal global [1 x i32] [i32 ptrtoint ([5 x i8]* @.str to i32)], align 4
+  // CHECK: @g29.c = internal global [1 x i32] [i32 97], align 4
+  static DCC_SRVR_NM a = { {"@"} };
+  static int b[1] = { "asdf" };
+  static int c[1] = { L"a" };
+}