diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-05-06 00:35:47 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-05-06 00:35:47 +0000 |
commit | 27f9cf3a5a92f70f043b6cfbc5f3f2ac3a38f182 (patch) | |
tree | 5d043ac1270ceb05d21d5041e7d517c418418bf0 /lib/Sema | |
parent | 5528ac9f40ec6cb54e7096908bf2beeed511bce4 (diff) |
Fix assert if __extension__ or _Generic is used when initializing a char array from a string literal.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181174 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/SemaInit.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 08536fbc21..993e68bd67 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -85,12 +85,19 @@ static Expr *IsStringInit(Expr *init, QualType declType, ASTContext &Context) { /// 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, |