diff options
author | Chris Lattner <sabre@nondot.org> | 2008-08-04 07:31:14 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-08-04 07:31:14 +0000 |
commit | c63a1f276f7b324fd9a4be82098b1c8f7bf30733 (patch) | |
tree | d20bfdf2549bd5906f9e6347e7576871205f6453 /lib/CodeGen | |
parent | 0998c65aeab7ad319bec8a93931196c170ed74d8 (diff) |
Finally fix PR2189. This makes a fairly invasive but important change to
move getAsArrayType into ASTContext instead of being a method on type.
This is required because getAsArrayType(const AT), where AT is a typedef
for "int[10]" needs to return ArrayType(const int, 10).
Fixing this greatly simplifies getArrayDecayedType, which is a good sign.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54317 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/CGDebugInfo.cpp | 12 | ||||
-rw-r--r-- | lib/CodeGen/CGExpr.cpp | 3 | ||||
-rw-r--r-- | lib/CodeGen/CGExprAgg.cpp | 7 | ||||
-rw-r--r-- | lib/CodeGen/CGExprConstant.cpp | 9 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 3 |
5 files changed, 16 insertions, 18 deletions
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index d232fd9560..0b63463d1f 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -108,10 +108,8 @@ CGDebugInfo::~CGDebugInfo() delete GlobalVariableAnchor; } -void CGDebugInfo::setLocation(SourceLocation loc) -{ - SourceManager &SM = M->getContext().getSourceManager(); - CurLoc = SM.getLogicalLoc(loc); +void CGDebugInfo::setLocation(SourceLocation loc) { + CurLoc = M->getContext().getSourceManager().getLogicalLoc(loc); } /// getCastValueFor - Return a llvm representation for a given debug information @@ -481,20 +479,20 @@ CGDebugInfo::getOrCreateArrayType(QualType type, llvm::CompileUnitDesc *Unit) // Add the dimensions of the array. std::vector<llvm::DebugInfoDesc *> &Elements = ArrayTy->getElements(); do { + const ArrayType *AT = M->getContext().getAsArrayType(type); llvm::SubrangeDesc *Subrange = new llvm::SubrangeDesc(); // push it back on the subrange desc list so that we can free it later. SubrangeDescList.push_back(Subrange); uint64_t Upper = 0; - if (type->getTypeClass() == Type::ConstantArray) { - const ConstantArrayType *ConstArrTy = type->getAsConstantArrayType(); + if (const ConstantArrayType *ConstArrTy = dyn_cast<ConstantArrayType>(AT)) { Upper = ConstArrTy->getSize().getZExtValue() - 1; } Subrange->setLo(0); Subrange->setHi(Upper); Elements.push_back(Subrange); - type = type->getAsArrayType()->getElementType(); + type = AT->getElementType(); } while (type->isArrayType()); ArrayTy->setFromType(getOrCreateType(type, Unit)); diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 1fd616c648..ca52b070dd 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -429,7 +429,8 @@ LValue CodeGenFunction::EmitStringLiteralLValue(const StringLiteral *E) { std::string StringLiteral(StrData, StrData+Len); // Resize the string to the right size - const ConstantArrayType *CAT = E->getType()->getAsConstantArrayType(); + const ConstantArrayType *CAT = + getContext().getAsConstantArrayType(E->getType()); uint64_t RealLen = CAT->getSize().getZExtValue(); StringLiteral.resize(RealLen, '\0'); diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index 815e296e79..df90ee09f5 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -393,11 +393,10 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { } uint64_t NumArrayElements = AType->getNumElements(); - QualType ElementType = E->getType()->getAsArrayType()->getElementType(); + QualType ElementType = CGF.getContext().getCanonicalType(E->getType()); + ElementType =CGF.getContext().getAsArrayType(ElementType)->getElementType(); - unsigned CVRqualifier = - CGF.getContext().getCanonicalType(E->getType())->getAsArrayType() - ->getElementType().getCVRQualifiers(); + unsigned CVRqualifier = ElementType.getCVRQualifiers(); for (uint64_t i = 0; i != NumArrayElements; ++i) { llvm::Value *NextVal = Builder.CreateStructGEP(DestPtr, i, ".array"); diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 681993a5d4..d58d004607 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -85,7 +85,7 @@ public: unsigned NumInitElements = ILE->getNumInits(); // FIXME: Check for wide strings if (NumInitElements > 0 && isa<StringLiteral>(ILE->getInit(0)) && - ILE->getType()->getAsArrayType()->getElementType()->isCharType()) + ILE->getType()->getArrayElementTypeNoTypeQual()->isCharType()) return Visit(ILE->getInit(0)); const llvm::Type *ElemTy = AType->getElementType(); unsigned NumElements = AType->getNumElements(); @@ -332,9 +332,7 @@ public: llvm::Constant *Idx0 = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0); llvm::Constant *Ops[] = {Idx0, Idx0}; C = llvm::ConstantExpr::getGetElementPtr(C, Ops, 2); - - QualType ElemType = SType->getAsArrayType()->getElementType(); - T = CGM.getContext().getPointerType(ElemType); + T = CGM.getContext().getArrayDecayedType(SType); } else if (SType->isFunctionType()) { // Function types decay to a pointer to the function C = EmitLValue(SExpr); @@ -357,7 +355,8 @@ public: // Otherwise this must be a string initializing an array in a static // initializer. Don't emit it as the address of the string, emit the string // data itself as an inline array. - const ConstantArrayType *CAT = E->getType()->getAsConstantArrayType(); + const ConstantArrayType *CAT = + CGM.getContext().getAsConstantArrayType(E->getType()); assert(CAT && "String isn't pointer or array!"); std::string Str(StrData, StrData + Len); diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index b531616b13..5d85b7a70f 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -632,7 +632,8 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) { // FIXME: This is silly; getTypeAlign should just work for incomplete arrays unsigned Align; - if (const IncompleteArrayType* IAT = D->getType()->getAsIncompleteArrayType()) + if (const IncompleteArrayType* IAT = + Context.getAsIncompleteArrayType(D->getType())) Align = Context.getTypeAlign(IAT->getElementType()); else Align = Context.getTypeAlign(D->getType()); |