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 | 9ec1e48b59db3708b861e96058c73a6a8a51f488 (patch) | |
| tree | d11ab73b68cb8f7c936107dec50155aa5a08093b /clang/lib/CodeGen | |
| parent | d07ba6208fed3cfc69b04a5e0caa7f185f10b995 (diff) | |
| download | bcm5719-llvm-9ec1e48b59db3708b861e96058c73a6a8a51f488.tar.gz bcm5719-llvm-9ec1e48b59db3708b861e96058c73a6a8a51f488.zip | |
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).
llvm-svn: 154756
Diffstat (limited to 'clang/lib/CodeGen')
| -rw-r--r-- | clang/lib/CodeGen/CGExprAgg.cpp | 10 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CGExprConstant.cpp | 8 |
2 files changed, 4 insertions, 14 deletions
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index b6efc1cafaa..975f572c0df 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -916,14 +916,8 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { // Handle initialization of an array. if (E->getType()->isArrayType()) { - if (E->getNumInits() > 0) { - QualType T1 = E->getType(); - QualType T2 = E->getInit(0)->getType(); - if (CGF.getContext().hasSameUnqualifiedType(T1, T2)) { - EmitAggLoadOfLValue(E->getInit(0)); - return; - } - } + if (E->isStringLiteralInit()) + return Visit(E->getInit(0)); QualType elementType = CGF.getContext().getAsArrayType(E->getType())->getElementType(); diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index d528e0c4b72..bc9f9ef07b2 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -758,17 +758,13 @@ public: } llvm::Constant *EmitArrayInitialization(InitListExpr *ILE) { - unsigned NumInitElements = ILE->getNumInits(); - if (NumInitElements == 1 && - CGM.getContext().hasSameUnqualifiedType(ILE->getType(), - ILE->getInit(0)->getType()) && - (isa<StringLiteral>(ILE->getInit(0)) || - isa<ObjCEncodeExpr>(ILE->getInit(0)))) + if (ILE->isStringLiteralInit()) return Visit(ILE->getInit(0)); llvm::ArrayType *AType = cast<llvm::ArrayType>(ConvertType(ILE->getType())); llvm::Type *ElemTy = AType->getElementType(); + unsigned NumInitElements = ILE->getNumInits(); unsigned NumElements = AType->getNumElements(); // Initialising an array requires us to automatically |

