diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-04-15 02:50:59 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-04-15 02:50:59 +0000 |
commit | fe587201feaebc69e6d18858bea85c77926b6ecf (patch) | |
tree | b05fd7a32038f1c0eeb066440f7a2a9cc2564a15 /lib/AST/Expr.cpp | |
parent | 8590d86ea35d0dd04711edd6b8dc57fa9a528305 (diff) |
PR12226: don't generate wrong code if a braced string literal is used to
initialize an array of unsigned char. Outside C++11 mode, this bug was benign,
and just resulted in us emitting a constant which was double the required
length, padded with 0s. In C++11, it resulted in us generating an array whose
first element was something like i8 ptrtoint ([n x i8]* @str to i8).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154756 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Expr.cpp')
-rw-r--r-- | lib/AST/Expr.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 868109e3d5..9556b1acb9 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1590,6 +1590,16 @@ void InitListExpr::setArrayFiller(Expr *filler) { inits[i] = filler; } +bool InitListExpr::isStringLiteralInit() const { + if (getNumInits() != 1) + return false; + const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(getType()); + if (!CAT || !CAT->getElementType()->isIntegerType()) + return false; + const Expr *Init = getInit(0)->IgnoreParenImpCasts(); + return isa<StringLiteral>(Init) || isa<ObjCEncodeExpr>(Init); +} + SourceRange InitListExpr::getSourceRange() const { if (SyntacticForm) return SyntacticForm->getSourceRange(); |