diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-03-02 23:27:11 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-03-02 23:27:11 +0000 |
commit | a3ca41f0c2bd1c4a752df88b283332f3b757d21e (patch) | |
tree | 8aab234057f7a0c60c5d1bc20ad31ebb07d5977e /lib/CodeGen/CGExprConstant.cpp | |
parent | 067cc40308a9643400fd291fc8678c4a6785e90c (diff) |
Reinstate r151879, r151880, reverted in r151922, along with a bugfix for
scalar emission of DeclRefExprs to const bools: emit scalar bools as i1,
not as i8.
In addition to the extra unit testing, this has successfully bootstrapped.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151955 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprConstant.cpp')
-rw-r--r-- | lib/CodeGen/CGExprConstant.cpp | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 2803640bda..61c10bbe4f 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -511,7 +511,7 @@ void ConstStructBuilder::Build(const APValue &Val, const RecordDecl *RD, const APValue &FieldValue = RD->isUnion() ? Val.getUnionValue() : Val.getStructField(FieldNo); llvm::Constant *EltInit = - CGM.EmitConstantValue(FieldValue, Field->getType(), CGF); + CGM.EmitConstantValueForMemory(FieldValue, Field->getType(), CGF); assert(EltInit && "EmitConstantValue can't fail"); if (!Field->isBitField()) { @@ -1015,7 +1015,7 @@ public: llvm::Constant *CodeGenModule::EmitConstantInit(const VarDecl &D, CodeGenFunction *CGF) { if (const APValue *Value = D.evaluateValue()) - return EmitConstantValue(*Value, D.getType(), CGF); + return EmitConstantValueForMemory(*Value, D.getType(), CGF); // FIXME: Implement C++11 [basic.start.init]p2: if the initializer of a // reference is a constant expression, and the reference binds to a temporary, @@ -1049,10 +1049,12 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E, else Success = E->EvaluateAsRValue(Result, Context); + llvm::Constant *C = 0; if (Success && !Result.HasSideEffects) - return EmitConstantValue(Result.Val, DestType, CGF); + C = EmitConstantValue(Result.Val, DestType, CGF); + else + C = ConstExprEmitter(*this, CGF).Visit(const_cast<Expr*>(E)); - llvm::Constant* C = ConstExprEmitter(*this, CGF).Visit(const_cast<Expr*>(E)); if (C && C->getType()->isIntegerTy(1)) { llvm::Type *BoolTy = getTypes().ConvertTypeForMem(E->getType()); C = llvm::ConstantExpr::getZExt(C, BoolTy); @@ -1110,16 +1112,8 @@ llvm::Constant *CodeGenModule::EmitConstantValue(const APValue &Value, return C; } } - case APValue::Int: { - llvm::Constant *C = llvm::ConstantInt::get(VMContext, - Value.getInt()); - - if (C->getType()->isIntegerTy(1)) { - llvm::Type *BoolTy = getTypes().ConvertTypeForMem(DestType); - C = llvm::ConstantExpr::getZExt(C, BoolTy); - } - return C; - } + case APValue::Int: + return llvm::ConstantInt::get(VMContext, Value.getInt()); case APValue::ComplexInt: { llvm::Constant *Complex[2]; @@ -1199,16 +1193,16 @@ llvm::Constant *CodeGenModule::EmitConstantValue(const APValue &Value, // Emit array filler, if there is one. llvm::Constant *Filler = 0; if (Value.hasArrayFiller()) - Filler = EmitConstantValue(Value.getArrayFiller(), - CAT->getElementType(), CGF); + Filler = EmitConstantValueForMemory(Value.getArrayFiller(), + CAT->getElementType(), CGF); // Emit initializer elements. llvm::Type *CommonElementType = 0; for (unsigned I = 0; I < NumElements; ++I) { llvm::Constant *C = Filler; if (I < NumInitElts) - C = EmitConstantValue(Value.getArrayInitializedElt(I), - CAT->getElementType(), CGF); + C = EmitConstantValueForMemory(Value.getArrayInitializedElt(I), + CAT->getElementType(), CGF); if (I == 0) CommonElementType = C->getType(); else if (C->getType() != CommonElementType) @@ -1237,6 +1231,18 @@ llvm::Constant *CodeGenModule::EmitConstantValue(const APValue &Value, } llvm::Constant * +CodeGenModule::EmitConstantValueForMemory(const APValue &Value, + QualType DestType, + CodeGenFunction *CGF) { + llvm::Constant *C = EmitConstantValue(Value, DestType, CGF); + if (C->getType()->isIntegerTy(1)) { + llvm::Type *BoolTy = getTypes().ConvertTypeForMem(DestType); + C = llvm::ConstantExpr::getZExt(C, BoolTy); + } + return C; +} + +llvm::Constant * CodeGenModule::GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr *E) { assert(E->isFileScope() && "not a file-scope compound literal expr"); return ConstExprEmitter(*this, 0).EmitLValue(E); |