Skip to content

Commit ea1c01d

Browse files
committed
PR51105: look through ConstantExpr when looking for a braced string literal initialization.
1 parent d5f7f35 commit ea1c01d

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

clang/lib/AST/Expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2308,7 +2308,7 @@ bool InitListExpr::isStringLiteralInit() const {
23082308
const Expr *Init = getInit(0);
23092309
if (!Init)
23102310
return false;
2311-
Init = Init->IgnoreParens();
2311+
Init = Init->IgnoreParenImpCasts();
23122312
return isa<StringLiteral>(Init) || isa<ObjCEncodeExpr>(Init);
23132313
}
23142314

clang/lib/AST/ExprConstant.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10473,13 +10473,17 @@ bool ArrayExprEvaluator::VisitInitListExpr(const InitListExpr *E,
1047310473
// C++11 [dcl.init.string]p1: A char array [...] can be initialized by [...]
1047410474
// an appropriately-typed string literal enclosed in braces.
1047510475
if (E->isStringLiteralInit()) {
10476-
auto *SL = dyn_cast<StringLiteral>(E->getInit(0)->IgnoreParens());
10476+
auto *SL = dyn_cast<StringLiteral>(E->getInit(0)->IgnoreParenImpCasts());
1047710477
// FIXME: Support ObjCEncodeExpr here once we support it in
1047810478
// ArrayExprEvaluator generally.
1047910479
if (!SL)
1048010480
return Error(E);
1048110481
return VisitStringLiteral(SL, AllocType);
1048210482
}
10483+
// Any other transparent list init will need proper handling of the
10484+
// AllocType; we can't just recurse to the inner initializer.
10485+
assert(!E->isTransparent() &&
10486+
"transparent array list initialization is not string literal init?");
1048310487

1048410488
bool Success = true;
1048510489

clang/lib/Sema/SemaInit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2899,7 +2899,7 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity,
28992899
// We're modifying a string literal init; we have to decompose the string
29002900
// so we can modify the individual characters.
29012901
ASTContext &Context = SemaRef.Context;
2902-
Expr *SubExpr = StructuredList->getInit(0)->IgnoreParens();
2902+
Expr *SubExpr = StructuredList->getInit(0)->IgnoreParenImpCasts();
29032903

29042904
// Compute the character type
29052905
QualType CharTy = AT->getElementType();

clang/test/CodeGenCXX/const-init.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ int arr[2];
8484
// CHECK: @pastEnd = constant i32* bitcast (i8* getelementptr (i8, i8* bitcast ([2 x i32]* @arr to i8*), i64 8) to i32*)
8585
int &pastEnd = arr[2];
8686

87+
// CHECK: @[[WCHAR_STR:.*]] = internal global [2 x i32] [i32 112, i32 0],
88+
// CHECK: @PR51105_a = global i32* {{.*}} @[[WCHAR_STR]],
89+
wchar_t *PR51105_a = (wchar_t[2]){ (L"p") };
90+
// CHECK: @[[CHAR_STR:.*]] = internal global [5 x i8] c"p\00\00\00\00",
91+
// CHECK: @PR51105_b = global i8* {{.*}} @[[CHAR_STR]],
92+
char *PR51105_b = (char [5]){ ("p") };
93+
8794
struct X {
8895
long n : 8;
8996
};

0 commit comments

Comments
 (0)