diff options
author | Nico Weber <nicolasweber@gmx.de> | 2016-12-14 21:38:18 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2016-12-14 21:38:18 +0000 |
commit | 7849eeb0359e086870633437529c7f8a6a30a952 (patch) | |
tree | f6e8d655f9a1feba6677efeb815d749321625ee1 /clang/lib/CodeGen/CGExprConstant.cpp | |
parent | 65aedad62862a356c49fc5457277fb0c9cd3a75a (diff) | |
download | bcm5719-llvm-7849eeb0359e086870633437529c7f8a6a30a952.tar.gz bcm5719-llvm-7849eeb0359e086870633437529c7f8a6a30a952.zip |
Revert 289252 (and follow-up 289285), it caused PR31374
llvm-svn: 289713
Diffstat (limited to 'clang/lib/CodeGen/CGExprConstant.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGExprConstant.cpp | 62 |
1 files changed, 24 insertions, 38 deletions
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index 752f419f64e..345e0a9216a 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -16,7 +16,6 @@ #include "CGObjCRuntime.h" #include "CGRecordLayout.h" #include "CodeGenModule.h" -#include "TargetInfo.h" #include "clang/AST/APValue.h" #include "clang/AST/ASTContext.h" #include "clang/AST/RecordLayout.h" @@ -1263,10 +1262,6 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E, return C; } -llvm::Constant *CodeGenModule::getNullPointer(llvm::PointerType *T, QualType QT) { - return getTargetCodeGenInfo().getNullPointer(*this, T, QT); -} - llvm::Constant *CodeGenModule::EmitConstantValue(const APValue &Value, QualType DestType, CodeGenFunction *CGF) { @@ -1298,7 +1293,6 @@ llvm::Constant *CodeGenModule::EmitConstantValue(const APValue &Value, llvm::ConstantInt::get(Int64Ty, Value.getLValueOffset().getQuantity()); llvm::Constant *C = nullptr; - if (APValue::LValueBase LVBase = Value.getLValueBase()) { // An array can be represented as an lvalue referring to the base. if (isa<llvm::ArrayType>(DestTy)) { @@ -1329,9 +1323,7 @@ llvm::Constant *CodeGenModule::EmitConstantValue(const APValue &Value, // Convert to the appropriate type; this could be an lvalue for // an integer. - if (auto PT = dyn_cast<llvm::PointerType>(DestTy)) { - if (Value.isNullPointer()) - return getNullPointer(PT, DestType); + if (isa<llvm::PointerType>(DestTy)) { // Convert the integer to a pointer-sized integer before converting it // to a pointer. C = llvm::ConstantExpr::getIntegerCast( @@ -1518,7 +1510,7 @@ static llvm::Constant *EmitNullConstantForBase(CodeGenModule &CGM, const CXXRecordDecl *base); static llvm::Constant *EmitNullConstant(CodeGenModule &CGM, - const RecordDecl *record, + const CXXRecordDecl *record, bool asCompleteObject) { const CGRecordLayout &layout = CGM.getTypes().getCGRecordLayout(record); llvm::StructType *structure = @@ -1528,29 +1520,25 @@ static llvm::Constant *EmitNullConstant(CodeGenModule &CGM, unsigned numElements = structure->getNumElements(); std::vector<llvm::Constant *> elements(numElements); - auto CXXR = dyn_cast<CXXRecordDecl>(record); // Fill in all the bases. - if (CXXR) { - for (const auto &I : CXXR->bases()) { - if (I.isVirtual()) { - // Ignore virtual bases; if we're laying out for a complete - // object, we'll lay these out later. - continue; - } + for (const auto &I : record->bases()) { + if (I.isVirtual()) { + // Ignore virtual bases; if we're laying out for a complete + // object, we'll lay these out later. + continue; + } - const CXXRecordDecl *base = - cast<CXXRecordDecl>(I.getType()->castAs<RecordType>()->getDecl()); + const CXXRecordDecl *base = + cast<CXXRecordDecl>(I.getType()->castAs<RecordType>()->getDecl()); - // Ignore empty bases. - if (base->isEmpty() || - CGM.getContext().getASTRecordLayout(base).getNonVirtualSize() - .isZero()) - continue; - - unsigned fieldIndex = layout.getNonVirtualBaseLLVMFieldNo(base); - llvm::Type *baseType = structure->getElementType(fieldIndex); - elements[fieldIndex] = EmitNullConstantForBase(CGM, baseType, base); - } + // Ignore empty bases. + if (base->isEmpty() || + CGM.getContext().getASTRecordLayout(base).getNonVirtualSize().isZero()) + continue; + + unsigned fieldIndex = layout.getNonVirtualBaseLLVMFieldNo(base); + llvm::Type *baseType = structure->getElementType(fieldIndex); + elements[fieldIndex] = EmitNullConstantForBase(CGM, baseType, base); } // Fill in all the fields. @@ -1574,8 +1562,8 @@ static llvm::Constant *EmitNullConstant(CodeGenModule &CGM, } // Fill in the virtual bases, if we're working with the complete object. - if (CXXR && asCompleteObject) { - for (const auto &I : CXXR->vbases()) { + if (asCompleteObject) { + for (const auto &I : record->vbases()) { const CXXRecordDecl *base = cast<CXXRecordDecl>(I.getType()->castAs<RecordType>()->getDecl()); @@ -1617,10 +1605,6 @@ static llvm::Constant *EmitNullConstantForBase(CodeGenModule &CGM, } llvm::Constant *CodeGenModule::EmitNullConstant(QualType T) { - if (T->getAs<PointerType>()) - return getNullPointer( - cast<llvm::PointerType>(getTypes().ConvertTypeForMem(T)), T); - if (getTypes().isZeroInitializable(T)) return llvm::Constant::getNullValue(getTypes().ConvertTypeForMem(T)); @@ -1636,8 +1620,10 @@ llvm::Constant *CodeGenModule::EmitNullConstant(QualType T) { return llvm::ConstantArray::get(ATy, Array); } - if (const RecordType *RT = T->getAs<RecordType>()) - return ::EmitNullConstant(*this, RT->getDecl(), /*complete object*/ true); + if (const RecordType *RT = T->getAs<RecordType>()) { + const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); + return ::EmitNullConstant(*this, RD, /*complete object*/ true); + } assert(T->isMemberDataPointerType() && "Should only see pointers to data members here!"); |