From 27c39af73c0d7d0b97e57b3a905040d4cefc9708 Mon Sep 17 00:00:00 2001 From: rdivacky Date: Wed, 10 Mar 2010 17:45:58 +0000 Subject: Update clang to r98164. --- lib/AST/ASTContext.cpp | 113 +++-- lib/AST/ASTDiagnostic.cpp | 6 + lib/AST/ASTImporter.cpp | 14 +- lib/AST/CMakeLists.txt | 3 +- lib/AST/DeclBase.cpp | 21 +- lib/AST/DeclCXX.cpp | 15 +- lib/AST/DeclObjC.cpp | 7 +- lib/AST/DeclTemplate.cpp | 8 +- lib/AST/Expr.cpp | 35 +- lib/AST/NestedNameSpecifier.cpp | 1 - lib/AST/RecordLayout.cpp | 67 +++ lib/AST/RecordLayoutBuilder.cpp | 35 +- lib/AST/Type.cpp | 1 + lib/AST/TypePrinter.cpp | 164 ++++--- lib/Analysis/AnalysisContext.cpp | 26 +- lib/Basic/Targets.cpp | 131 +++++ lib/Checker/BasicStore.cpp | 3 +- lib/Checker/CFRefCount.cpp | 4 +- lib/Checker/GRExprEngine.cpp | 1 - lib/Checker/MallocChecker.cpp | 24 +- lib/Checker/RegionStore.cpp | 793 ++++++++++++++++--------------- lib/Checker/SVals.cpp | 19 + lib/CodeGen/CGDebugInfo.cpp | 253 +++++----- lib/CodeGen/CGDebugInfo.h | 73 +-- lib/CodeGen/CGExprAgg.cpp | 24 +- lib/CodeGen/CGObjC.cpp | 2 +- lib/CodeGen/CGVtable.cpp | 225 ++++++--- lib/CodeGen/CGVtable.h | 18 +- lib/CodeGen/CodeGenModule.cpp | 10 +- lib/CodeGen/CodeGenModule.h | 4 +- lib/CodeGen/Mangle.cpp | 6 - lib/Driver/HostInfo.cpp | 2 +- lib/Driver/Tools.cpp | 4 +- lib/Frontend/CacheTokens.cpp | 4 +- lib/Frontend/CompilerInstance.cpp | 4 +- lib/Frontend/DeclXML.cpp | 26 +- lib/Frontend/DependencyFile.cpp | 3 +- lib/Frontend/FrontendAction.cpp | 2 +- lib/Frontend/InitHeaderSearch.cpp | 2 +- lib/Frontend/PCHReader.cpp | 37 +- lib/Frontend/PCHReaderDecl.cpp | 3 +- lib/Frontend/PCHReaderStmt.cpp | 5 +- lib/Frontend/PCHWriter.cpp | 9 + lib/Frontend/PCHWriterDecl.cpp | 1 + lib/Frontend/PCHWriterStmt.cpp | 5 +- lib/Frontend/PrintPreprocessedOutput.cpp | 8 +- lib/Headers/smmintrin.h | 125 ++++- lib/Headers/stdarg.h | 3 + lib/Headers/stddef.h | 7 + lib/Index/Analyzer.cpp | 4 +- lib/Sema/CodeCompleteConsumer.cpp | 1 - lib/Sema/JumpDiagnostics.cpp | 2 + lib/Sema/SemaCXXCast.cpp | 38 +- lib/Sema/SemaCXXScopeSpec.cpp | 23 +- lib/Sema/SemaDecl.cpp | 65 ++- lib/Sema/SemaDeclCXX.cpp | 81 ++-- lib/Sema/SemaDeclObjC.cpp | 8 +- lib/Sema/SemaExpr.cpp | 3 +- lib/Sema/SemaExprCXX.cpp | 20 +- lib/Sema/SemaExprObjC.cpp | 12 +- lib/Sema/SemaInit.cpp | 30 +- lib/Sema/SemaTemplate.cpp | 26 +- lib/Sema/SemaTemplateDeduction.cpp | 9 + lib/Sema/SemaTemplateInstantiateDecl.cpp | 38 +- lib/Sema/TreeTransform.h | 14 + 65 files changed, 1704 insertions(+), 1026 deletions(-) create mode 100644 lib/AST/RecordLayout.cpp (limited to 'lib') diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index d8c1c84..26b10b5 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -78,21 +78,21 @@ ASTContext::~ASTContext() { // Increment in loop to prevent using deallocated memory. Deallocate(&*I++); } - } - for (llvm::DenseMap::iterator - I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); I != E; ) { - // Increment in loop to prevent using deallocated memory. - ASTRecordLayout *R = const_cast((I++)->second); - delete R; - } + for (llvm::DenseMap::iterator + I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); I != E; ) { + // Increment in loop to prevent using deallocated memory. + if (ASTRecordLayout *R = const_cast((I++)->second)) + R->Destroy(*this); + } - for (llvm::DenseMap::iterator - I = ObjCLayouts.begin(), E = ObjCLayouts.end(); I != E; ) { - // Increment in loop to prevent using deallocated memory. - ASTRecordLayout *R = const_cast((I++)->second); - delete R; + for (llvm::DenseMap::iterator + I = ObjCLayouts.begin(), E = ObjCLayouts.end(); I != E; ) { + // Increment in loop to prevent using deallocated memory. + if (ASTRecordLayout *R = const_cast((I++)->second)) + R->Destroy(*this); + } } // Destroy nested-name-specifiers. @@ -888,6 +888,10 @@ ASTContext::getTypeInfo(const Type *T) { case Type::QualifiedName: return getTypeInfo(cast(T)->getNamedType().getTypePtr()); + case Type::InjectedClassName: + return getTypeInfo(cast(T) + ->getUnderlyingType().getTypePtr()); + case Type::TemplateSpecialization: assert(getCanonicalType(T) != T && "Cannot request the size of a dependent type"); @@ -1918,38 +1922,71 @@ QualType ASTContext::getFunctionType(QualType ResultTy,const QualType *ArgArray, return QualType(FTP, 0); } +#ifndef NDEBUG +static bool NeedsInjectedClassNameType(const RecordDecl *D) { + if (!isa(D)) return false; + const CXXRecordDecl *RD = cast(D); + if (isa(RD)) + return true; + if (RD->getDescribedClassTemplate() && + !isa(RD)) + return true; + return false; +} +#endif + +/// getInjectedClassNameType - Return the unique reference to the +/// injected class name type for the specified templated declaration. +QualType ASTContext::getInjectedClassNameType(CXXRecordDecl *Decl, + QualType TST) { + assert(NeedsInjectedClassNameType(Decl)); + if (Decl->TypeForDecl) { + assert(isa(Decl->TypeForDecl)); + } else if (CXXRecordDecl *PrevDecl + = cast_or_null(Decl->getPreviousDeclaration())) { + assert(PrevDecl->TypeForDecl && "previous declaration has no type"); + Decl->TypeForDecl = PrevDecl->TypeForDecl; + assert(isa(Decl->TypeForDecl)); + } else { + Decl->TypeForDecl = new (*this, TypeAlignment) + InjectedClassNameType(Decl, TST, TST->getCanonicalTypeInternal()); + Types.push_back(Decl->TypeForDecl); + } + return QualType(Decl->TypeForDecl, 0); +} + /// getTypeDeclType - Return the unique reference to the type for the /// specified type declaration. -QualType ASTContext::getTypeDeclType(const TypeDecl *Decl, - const TypeDecl* PrevDecl) { +QualType ASTContext::getTypeDeclTypeSlow(const TypeDecl *Decl) { assert(Decl && "Passed null for Decl param"); - if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); + assert(!Decl->TypeForDecl && "TypeForDecl present in slow case"); if (const TypedefDecl *Typedef = dyn_cast(Decl)) return getTypedefType(Typedef); - else if (isa(Decl)) { - assert(false && "Template type parameter types are always available."); - } else if (const ObjCInterfaceDecl *ObjCInterface + + if (const ObjCInterfaceDecl *ObjCInterface = dyn_cast(Decl)) return getObjCInterfaceType(ObjCInterface); + assert(!isa(Decl) && + "Template type parameter types are always available."); + if (const RecordDecl *Record = dyn_cast(Decl)) { - if (PrevDecl) - Decl->TypeForDecl = PrevDecl->TypeForDecl; - else - Decl->TypeForDecl = new (*this, TypeAlignment) RecordType(Record); + assert(!Record->getPreviousDeclaration() && + "struct/union has previous declaration"); + assert(!NeedsInjectedClassNameType(Record)); + Decl->TypeForDecl = new (*this, TypeAlignment) RecordType(Record); } else if (const EnumDecl *Enum = dyn_cast(Decl)) { - if (PrevDecl) - Decl->TypeForDecl = PrevDecl->TypeForDecl; - else - Decl->TypeForDecl = new (*this, TypeAlignment) EnumType(Enum); + assert(!Enum->getPreviousDeclaration() && + "enum has previous declaration"); + Decl->TypeForDecl = new (*this, TypeAlignment) EnumType(Enum); } else if (const UnresolvedUsingTypenameDecl *Using = dyn_cast(Decl)) { Decl->TypeForDecl = new (*this, TypeAlignment) UnresolvedUsingType(Using); } else - assert(false && "TypeDecl without a type?"); + llvm_unreachable("TypeDecl without a type?"); - if (!PrevDecl) Types.push_back(Decl->TypeForDecl); + Types.push_back(Decl->TypeForDecl); return QualType(Decl->TypeForDecl, 0); } @@ -2022,6 +2059,24 @@ QualType ASTContext::getTemplateTypeParmType(unsigned Depth, unsigned Index, return QualType(TypeParm, 0); } +TypeSourceInfo * +ASTContext::getTemplateSpecializationTypeInfo(TemplateName Name, + SourceLocation NameLoc, + const TemplateArgumentListInfo &Args, + QualType CanonType) { + QualType TST = getTemplateSpecializationType(Name, Args, CanonType); + + TypeSourceInfo *DI = CreateTypeSourceInfo(TST); + TemplateSpecializationTypeLoc TL + = cast(DI->getTypeLoc()); + TL.setTemplateNameLoc(NameLoc); + TL.setLAngleLoc(Args.getLAngleLoc()); + TL.setRAngleLoc(Args.getRAngleLoc()); + for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) + TL.setArgLocInfo(i, Args[i].getLocInfo()); + return DI; +} + QualType ASTContext::getTemplateSpecializationType(TemplateName Template, const TemplateArgumentListInfo &Args, diff --git a/lib/AST/ASTDiagnostic.cpp b/lib/AST/ASTDiagnostic.cpp index 7402b7d..866b7f7 100644 --- a/lib/AST/ASTDiagnostic.cpp +++ b/lib/AST/ASTDiagnostic.cpp @@ -56,6 +56,12 @@ static bool ShouldAKA(ASTContext &Context, QualType QT, QT = cast(Ty)->desugar(); continue; } + + // ...or an injected class name... + if (isa(Ty)) { + QT = cast(Ty)->desugar(); + continue; + } // ...or a substituted template type parameter. if (isa(Ty)) { diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index 2bcf07e..d9c0d7b 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -610,6 +610,16 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, break; } + case Type::InjectedClassName: { + const InjectedClassNameType *Inj1 = cast(T1); + const InjectedClassNameType *Inj2 = cast(T2); + if (!IsStructurallyEquivalent(Context, + Inj1->getUnderlyingType(), + Inj2->getUnderlyingType())) + return false; + break; + } + case Type::Typename: { const TypenameType *Typename1 = cast(T1); const TypenameType *Typename2 = cast(T2); @@ -2244,12 +2254,14 @@ Decl *ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { if (ResultTy.isNull()) return 0; + TypeSourceInfo *ResultTInfo = Importer.Import(D->getResultTypeSourceInfo()); + ObjCMethodDecl *ToMethod = ObjCMethodDecl::Create(Importer.getToContext(), Loc, Importer.Import(D->getLocEnd()), Name.getObjCSelector(), - ResultTy, DC, + ResultTy, ResultTInfo, DC, D->isInstanceMethod(), D->isVariadic(), D->isSynthesized(), diff --git a/lib/AST/CMakeLists.txt b/lib/AST/CMakeLists.txt index e5bd9b7..2f1a6af 100644 --- a/lib/AST/CMakeLists.txt +++ b/lib/AST/CMakeLists.txt @@ -4,8 +4,8 @@ add_clang_library(clangAST APValue.cpp ASTConsumer.cpp ASTContext.cpp - ASTImporter.cpp ASTDiagnostic.cpp + ASTImporter.cpp AttrImpl.cpp CXXInheritance.cpp Decl.cpp @@ -23,6 +23,7 @@ add_clang_library(clangAST InheritViz.cpp NestedNameSpecifier.cpp ParentMap.cpp + RecordLayout.cpp RecordLayoutBuilder.cpp Stmt.cpp StmtDumper.cpp diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index 9db6ae1..a949534 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -574,11 +574,22 @@ DeclContext *DeclContext::getPrimaryContext() { if (DeclKind >= Decl::TagFirst && DeclKind <= Decl::TagLast) { // If this is a tag type that has a definition or is currently // being defined, that definition is our primary context. - if (const TagType *TagT =cast(this)->TypeForDecl->getAs()) - if (TagT->isBeingDefined() || - (TagT->getDecl() && TagT->getDecl()->isDefinition())) - return TagT->getDecl(); - return this; + TagDecl *Tag = cast(this); + assert(isa(Tag->TypeForDecl) || + isa(Tag->TypeForDecl)); + + if (TagDecl *Def = Tag->getDefinition()) + return Def; + + if (!isa(Tag->TypeForDecl)) { + const TagType *TagTy = cast(Tag->TypeForDecl); + if (TagTy->isBeingDefined()) + // FIXME: is it necessarily being defined in the decl + // that owns the type? + return TagTy->getDecl(); + } + + return Tag; } assert(DeclKind >= Decl::FunctionFirst && DeclKind <= Decl::FunctionLast && diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index 9b693af..7f4ad34 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -636,11 +636,16 @@ QualType CXXMethodDecl::getThisType(ASTContext &C) const { assert(isInstance() && "No 'this' for static methods!"); - QualType ClassTy; - if (ClassTemplateDecl *TD = getParent()->getDescribedClassTemplate()) - ClassTy = TD->getInjectedClassNameType(C); - else - ClassTy = C.getTagDeclType(getParent()); + QualType ClassTy = C.getTypeDeclType(getParent()); + + // Aesthetically we prefer not to synthesize a type as the + // InjectedClassNameType of a template pattern: injected class names + // are printed without template arguments, which might + // surprise/confuse/distract our poor users if they didn't + // explicitly write one. + if (isa(ClassTy)) + ClassTy = cast(ClassTy)->getUnderlyingType(); + ClassTy = C.getQualifiedType(ClassTy, Qualifiers::fromCVRMask(getTypeQualifiers())); return C.getPointerType(ClassTy); diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 8decafa..67b71a0 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -304,15 +304,16 @@ ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc, Selector SelInfo, QualType T, + TypeSourceInfo *ResultTInfo, DeclContext *contextDecl, bool isInstance, bool isVariadic, bool isSynthesized, ImplementationControl impControl) { return new (C) ObjCMethodDecl(beginLoc, endLoc, - SelInfo, T, contextDecl, - isInstance, - isVariadic, isSynthesized, impControl); + SelInfo, T, ResultTInfo, contextDecl, + isInstance, + isVariadic, isSynthesized, impControl); } void ObjCMethodDecl::Destroy(ASTContext &C) { diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp index d80db45..b449398 100644 --- a/lib/AST/DeclTemplate.cpp +++ b/lib/AST/DeclTemplate.cpp @@ -193,7 +193,8 @@ ClassTemplateDecl::findPartialSpecialization(QualType T) { return 0; } -QualType ClassTemplateDecl::getInjectedClassNameType(ASTContext &Context) { +QualType +ClassTemplateDecl::getInjectedClassNameSpecialization(ASTContext &Context) { if (!CommonPtr->InjectedClassNameType.isNull()) return CommonPtr->InjectedClassNameType; @@ -393,6 +394,7 @@ ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, SpecializedTemplate->getIdentifier(), PrevDecl), SpecializedTemplate(SpecializedTemplate), + TypeAsWritten(0), TemplateArgs(Context, Builder, /*TakeArgs=*/true), SpecializationKind(TSK_Undeclared) { } @@ -453,6 +455,7 @@ Create(ASTContext &Context, DeclContext *DC, SourceLocation L, ClassTemplateDecl *SpecializedTemplate, TemplateArgumentListBuilder &Builder, const TemplateArgumentListInfo &ArgInfos, + QualType CanonInjectedType, ClassTemplatePartialSpecializationDecl *PrevDecl) { unsigned N = ArgInfos.size(); TemplateArgumentLoc *ClonedArgs = new (Context) TemplateArgumentLoc[N]; @@ -467,7 +470,8 @@ Create(ASTContext &Context, DeclContext *DC, SourceLocation L, ClonedArgs, N, PrevDecl); Result->setSpecializationKind(TSK_ExplicitSpecialization); - Context.getTypeDeclType(Result, PrevDecl); + + Context.getInjectedClassNameType(Result, CanonInjectedType); return Result; } diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index a2914bc..efd0fd1 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -181,7 +181,6 @@ std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { } PrintingPolicy Policy(Context.getLangOptions()); - Policy.SuppressTagKind = true; std::string Proto = FD->getQualifiedNameAsString(Policy); @@ -2115,12 +2114,12 @@ ObjCMessageExpr::ObjCMessageExpr(ASTContext &C, Expr *receiver, // constructor for class messages. // FIXME: clsName should be typed to ObjCInterfaceType ObjCMessageExpr::ObjCMessageExpr(ASTContext &C, IdentifierInfo *clsName, - Selector selInfo, QualType retType, - ObjCMethodDecl *mproto, + SourceLocation clsNameLoc, Selector selInfo, + QualType retType, ObjCMethodDecl *mproto, SourceLocation LBrac, SourceLocation RBrac, Expr **ArgExprs, unsigned nargs) - : Expr(ObjCMessageExprClass, retType, false, false), SelName(selInfo), - MethodProto(mproto) { + : Expr(ObjCMessageExprClass, retType, false, false), ClassNameLoc(clsNameLoc), + SelName(selInfo), MethodProto(mproto) { NumArgs = nargs; SubExprs = new (C) Stmt*[NumArgs+1]; SubExprs[RECEIVER] = (Expr*) ((uintptr_t) clsName | IsClsMethDeclUnknown); @@ -2134,12 +2133,14 @@ ObjCMessageExpr::ObjCMessageExpr(ASTContext &C, IdentifierInfo *clsName, // constructor for class messages. ObjCMessageExpr::ObjCMessageExpr(ASTContext &C, ObjCInterfaceDecl *cls, - Selector selInfo, QualType retType, + SourceLocation clsNameLoc, Selector selInfo, + QualType retType, ObjCMethodDecl *mproto, SourceLocation LBrac, SourceLocation RBrac, Expr **ArgExprs, unsigned nargs) -: Expr(ObjCMessageExprClass, retType, false, false), SelName(selInfo), -MethodProto(mproto) { + : Expr(ObjCMessageExprClass, retType, false, false), ClassNameLoc(clsNameLoc), + SelName(selInfo), MethodProto(mproto) +{ NumArgs = nargs; SubExprs = new (C) Stmt*[NumArgs+1]; SubExprs[RECEIVER] = (Expr*) ((uintptr_t) cls | IsClsMethDeclKnown); @@ -2157,23 +2158,27 @@ ObjCMessageExpr::ClassInfo ObjCMessageExpr::getClassInfo() const { default: assert(false && "Invalid ObjCMessageExpr."); case IsInstMeth: - return ClassInfo(0, 0); + return ClassInfo(0, 0, SourceLocation()); case IsClsMethDeclUnknown: - return ClassInfo(0, (IdentifierInfo*) (x & ~Flags)); + return ClassInfo(0, (IdentifierInfo*) (x & ~Flags), ClassNameLoc); case IsClsMethDeclKnown: { ObjCInterfaceDecl* D = (ObjCInterfaceDecl*) (x & ~Flags); - return ClassInfo(D, D->getIdentifier()); + return ClassInfo(D, D->getIdentifier(), ClassNameLoc); } } } void ObjCMessageExpr::setClassInfo(const ObjCMessageExpr::ClassInfo &CI) { - if (CI.first == 0 && CI.second == 0) + if (CI.Decl == 0 && CI.Name == 0) { SubExprs[RECEIVER] = (Expr*)((uintptr_t)0 | IsInstMeth); - else if (CI.first == 0) - SubExprs[RECEIVER] = (Expr*)((uintptr_t)CI.second | IsClsMethDeclUnknown); + return; + } + + if (CI.Decl == 0) + SubExprs[RECEIVER] = (Expr*)((uintptr_t)CI.Name | IsClsMethDeclUnknown); else - SubExprs[RECEIVER] = (Expr*)((uintptr_t)CI.first | IsClsMethDeclKnown); + SubExprs[RECEIVER] = (Expr*)((uintptr_t)CI.Decl | IsClsMethDeclKnown); + ClassNameLoc = CI.Loc; } void ObjCMessageExpr::DoDestroy(ASTContext &C) { diff --git a/lib/AST/NestedNameSpecifier.cpp b/lib/AST/NestedNameSpecifier.cpp index e26c0bb..45518e9 100644 --- a/lib/AST/NestedNameSpecifier.cpp +++ b/lib/AST/NestedNameSpecifier.cpp @@ -142,7 +142,6 @@ NestedNameSpecifier::print(llvm::raw_ostream &OS, Type *T = getAsType(); PrintingPolicy InnerPolicy(Policy); - InnerPolicy.SuppressTagKind = true; InnerPolicy.SuppressScope = true; // Nested-name-specifiers are intended to contain minimally-qualified diff --git a/lib/AST/RecordLayout.cpp b/lib/AST/RecordLayout.cpp new file mode 100644 index 0000000..838753a --- /dev/null +++ b/lib/AST/RecordLayout.cpp @@ -0,0 +1,67 @@ +//===-- RecordLayout.cpp - Layout information for a struct/union -*- C++ -*-==// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the RecordLayout interface. +// +//===----------------------------------------------------------------------===// + +#include "clang/AST/ASTContext.h" +#include "clang/AST/RecordLayout.h" + +using namespace clang; + +void ASTRecordLayout::Destroy(ASTContext &Ctx) { + if (FieldOffsets) + Ctx.Deallocate(FieldOffsets); + if (CXXInfo) + Ctx.Deallocate(CXXInfo); + this->~ASTRecordLayout(); + Ctx.Deallocate(this); +} + +ASTRecordLayout::ASTRecordLayout(ASTContext &Ctx, uint64_t size, unsigned alignment, + unsigned datasize, const uint64_t *fieldoffsets, + unsigned fieldcount) + : Size(size), DataSize(datasize), FieldOffsets(0), Alignment(alignment), + FieldCount(fieldcount), CXXInfo(0) { + if (FieldCount > 0) { + FieldOffsets = new (Ctx) uint64_t[FieldCount]; + memcpy(FieldOffsets, fieldoffsets, FieldCount * sizeof(*FieldOffsets)); + } +} + +// Constructor for C++ records. +ASTRecordLayout::ASTRecordLayout(ASTContext &Ctx, + uint64_t size, unsigned alignment, + uint64_t datasize, + const uint64_t *fieldoffsets, + unsigned fieldcount, + uint64_t nonvirtualsize, + unsigned nonvirtualalign, + const PrimaryBaseInfo &PrimaryBase, + const std::pair *bases, + unsigned numbases, + const std::pair *vbases, + unsigned numvbases) + : Size(size), DataSize(datasize), FieldOffsets(0), Alignment(alignment), + FieldCount(fieldcount), CXXInfo(new (Ctx) CXXRecordLayoutInfo) +{ + if (FieldCount > 0) { + FieldOffsets = new (Ctx) uint64_t[FieldCount]; + memcpy(FieldOffsets, fieldoffsets, FieldCount * sizeof(*FieldOffsets)); + } + + CXXInfo->PrimaryBase = PrimaryBase; + CXXInfo->NonVirtualSize = nonvirtualsize; + CXXInfo->NonVirtualAlign = nonvirtualalign; + for (unsigned i = 0; i != numbases; ++i) + CXXInfo->BaseOffsets[bases[i].first] = bases[i].second; + for (unsigned i = 0; i != numvbases; ++i) + CXXInfo->VBaseOffsets[vbases[i].first] = vbases[i].second; +} diff --git a/lib/AST/RecordLayoutBuilder.cpp b/lib/AST/RecordLayoutBuilder.cpp index 10c5089..22285ca 100644 --- a/lib/AST/RecordLayoutBuilder.cpp +++ b/lib/AST/RecordLayoutBuilder.cpp @@ -675,9 +675,10 @@ ASTRecordLayoutBuilder::ComputeLayout(ASTContext &Ctx, Builder.Layout(D); if (!isa(D)) - return new ASTRecordLayout(Builder.Size, Builder.Alignment, Builder.Size, - Builder.FieldOffsets.data(), - Builder.FieldOffsets.size()); + return new (Ctx) ASTRecordLayout(Ctx, Builder.Size, Builder.Alignment, + Builder.Size, + Builder.FieldOffsets.data(), + Builder.FieldOffsets.size()); // FIXME: This is not always correct. See the part about bitfields at // http://www.codesourcery.com/public/cxx-abi/abi.html#POD for more info. @@ -690,16 +691,16 @@ ASTRecordLayoutBuilder::ComputeLayout(ASTContext &Ctx, uint64_t NonVirtualSize = IsPODForThePurposeOfLayout ? DataSize : Builder.NonVirtualSize; - return new ASTRecordLayout(Builder.Size, Builder.Alignment, DataSize, - Builder.FieldOffsets.data(), - Builder.FieldOffsets.size(), - NonVirtualSize, - Builder.NonVirtualAlignment, - Builder.PrimaryBase, - Builder.Bases.data(), - Builder.Bases.size(), - Builder.VBases.data(), - Builder.VBases.size()); + return new (Ctx) ASTRecordLayout(Ctx, Builder.Size, Builder.Alignment, + DataSize, Builder.FieldOffsets.data(), + Builder.FieldOffsets.size(), + NonVirtualSize, + Builder.NonVirtualAlignment, + Builder.PrimaryBase, + Builder.Bases.data(), + Builder.Bases.size(), + Builder.VBases.data(), + Builder.VBases.size()); } const ASTRecordLayout * @@ -710,10 +711,10 @@ ASTRecordLayoutBuilder::ComputeLayout(ASTContext &Ctx, Builder.Layout(D, Impl); - return new ASTRecordLayout(Builder.Size, Builder.Alignment, - Builder.DataSize, - Builder.FieldOffsets.data(), - Builder.FieldOffsets.size()); + return new (Ctx) ASTRecordLayout(Ctx, Builder.Size, Builder.Alignment, + Builder.DataSize, + Builder.FieldOffsets.data(), + Builder.FieldOffsets.size()); } const CXXMethodDecl * diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 76cc382..8a64f8e 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -650,6 +650,7 @@ bool Type::isPODType() const { case Vector: case ExtVector: case ObjCObjectPointer: + case BlockPointer: return true; case Enum: diff --git a/lib/AST/TypePrinter.cpp b/lib/AST/TypePrinter.cpp index 5b621cf..037bc14 100644 --- a/lib/AST/TypePrinter.cpp +++ b/lib/AST/TypePrinter.cpp @@ -30,7 +30,8 @@ namespace { explicit TypePrinter(const PrintingPolicy &Policy) : Policy(Policy) { } void Print(QualType T, std::string &S); - void PrintTag(const TagType *T, std::string &S); + void AppendScope(DeclContext *DC, std::string &S); + void PrintTag(TagDecl *T, std::string &S); #define ABSTRACT_TYPE(CLASS, PARENT) #define TYPE(CLASS, PARENT) \ void Print##CLASS(const CLASS##Type *T, std::string &S); @@ -330,19 +331,21 @@ void TypePrinter::PrintFunctionNoProto(const FunctionNoProtoType *T, Print(T->getResultType(), S); } -void TypePrinter::PrintUnresolvedUsing(const UnresolvedUsingType *T, - std::string &S) { - IdentifierInfo *II = T->getDecl()->getIdentifier(); +static void PrintTypeSpec(const NamedDecl *D, std::string &S) { + IdentifierInfo *II = D->getIdentifier(); if (S.empty()) S = II->getName().str(); else S = II->getName().str() + ' ' + S; } +void TypePrinter::PrintUnresolvedUsing(const UnresolvedUsingType *T, + std::string &S) { + PrintTypeSpec(T->getDecl(), S); +} + void TypePrinter::PrintTypedef(const TypedefType *T, std::string &S) { - if (!S.empty()) // Prefix the basic type, e.g. 'typedefname X'. - S = ' ' + S; - S = T->getDecl()->getIdentifier()->getName().str() + S; + PrintTypeSpec(T->getDecl(), S); } void TypePrinter::PrintTypeOfExpr(const TypeOfExprType *T, std::string &S) { @@ -371,89 +374,106 @@ void TypePrinter::PrintDecltype(const DecltypeType *T, std::string &S) { S = "decltype(" + s.str() + ")" + S; } -void TypePrinter::PrintTag(const TagType *T, std::string &InnerString) { +/// Appends the given scope to the end of a string. +void TypePrinter::AppendScope(DeclContext *DC, std::string &Buffer) { + if (DC->isTranslationUnit()) return; + AppendScope(DC->getParent(), Buffer); + + unsigned OldSize = Buffer.size(); + + if (NamespaceDecl *NS = dyn_cast(DC)) { + if (NS->getIdentifier()) + Buffer += NS->getNameAsString(); + else + Buffer += ""; + } else if (ClassTemplateSpecializationDecl *Spec + = dyn_cast(DC)) { + const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); + std::string TemplateArgsStr + = TemplateSpecializationType::PrintTemplateArgumentList( + TemplateArgs.getFlatArgumentList(), + TemplateArgs.flat_size(), + Policy); + Buffer += Spec->getIdentifier()->getName(); + Buffer += TemplateArgsStr; + } else if (TagDecl *Tag = dyn_cast(DC)) { + if (TypedefDecl *Typedef = Tag->getTypedefForAnonDecl()) + Buffer += Typedef->getIdentifier()->getName(); + else if (Tag->getIdentifier()) + Buffer += Tag->getIdentifier()->getName(); + } + + if (Buffer.size() != OldSize) + Buffer += "::"; +} + +void TypePrinter::PrintTag(TagDecl *D, std::string &InnerString) { if (Policy.SuppressTag) return; - - if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. - InnerString = ' ' + InnerString; - - const char *Kind = Policy.SuppressTagKind? 0 : T->getDecl()->getKindName(); + + std::string Buffer; + + // We don't print tags unless this is an elaborated type. + // In C, we just assume every RecordType is an elaborated type. + if (!Policy.LangOpts.CPlusPlus && !D->getTypedefForAnonDecl()) { + Buffer += D->getKindName(); + Buffer += ' '; + } + + if (!Policy.SuppressScope) + // Compute the full nested-name-specifier for this type. In C, + // this will always be empty. + AppendScope(D->getDeclContext(), Buffer); + const char *ID; - if (const IdentifierInfo *II = T->getDecl()->getIdentifier()) + if (const IdentifierInfo *II = D->getIdentifier()) ID = II->getNameStart(); - else if (TypedefDecl *Typedef = T->getDecl()->getTypedefForAnonDecl()) { - Kind = 0; + else if (TypedefDecl *Typedef = D->getTypedefForAnonDecl()) { assert(Typedef->getIdentifier() && "Typedef without identifier?"); ID = Typedef->getIdentifier()->getNameStart(); } else ID = ""; - + Buffer += ID; + // If this is a class template specialization, print the template // arguments. if (ClassTemplateSpecializationDecl *Spec - = dyn_cast(T->getDecl())) { - const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); - std::string TemplateArgsStr - = TemplateSpecializationType::PrintTemplateArgumentList( - TemplateArgs.getFlatArgumentList(), - TemplateArgs.flat_size(), - Policy); - InnerString = TemplateArgsStr + InnerString; - } - - if (!Policy.SuppressScope) { - // Compute the full nested-name-specifier for this type. In C, - // this will always be empty. - std::string ContextStr; - for (DeclContext *DC = T->getDecl()->getDeclContext(); - !DC->isTranslationUnit(); DC = DC->getParent()) { - std::string MyPart; - if (NamespaceDecl *NS = dyn_cast(DC)) { - if (NS->getIdentifier()) - MyPart = NS->getNameAsString(); - } else if (ClassTemplateSpecializationDecl *Spec - = dyn_cast(DC)) { - const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); - std::string TemplateArgsStr - = TemplateSpecializationType::PrintTemplateArgumentList( - TemplateArgs.getFlatArgumentList(), - TemplateArgs.flat_size(), - Policy); - MyPart = Spec->getIdentifier()->getName().str() + TemplateArgsStr; - } else if (TagDecl *Tag = dyn_cast(DC)) { - if (TypedefDecl *Typedef = Tag->getTypedefForAnonDecl()) - MyPart = Typedef->getIdentifier()->getName(); - else if (Tag->getIdentifier()) - MyPart = Tag->getIdentifier()->getName(); - } - - if (!MyPart.empty()) - ContextStr = MyPart + "::" + ContextStr; + = dyn_cast(D)) { + const TemplateArgument *Args; + unsigned NumArgs; + if (TypeSourceInfo *TAW = Spec->getTypeAsWritten()) { + const TemplateSpecializationType *TST = + cast(TAW->getType()); + Args = TST->getArgs(); + NumArgs = TST->getNumArgs(); + } else { + const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); + Args = TemplateArgs.getFlatArgumentList(); + NumArgs = TemplateArgs.flat_size(); } - - if (Kind) - InnerString = std::string(Kind) + ' ' + ContextStr + ID + InnerString; - else - InnerString = ContextStr + ID + InnerString; - } else - InnerString = ID + InnerString; + Buffer += TemplateSpecializationType::PrintTemplateArgumentList(Args, + NumArgs, + Policy); + } + + if (!InnerString.empty()) { + Buffer += ' '; + Buffer += InnerString; + } + + std::swap(Buffer, InnerString); } void TypePrinter::PrintRecord(const RecordType *T, std::string &S) { - PrintTag(T, S); + PrintTag(T->getDecl(), S); } void TypePrinter::PrintEnum(const EnumType *T, std::string &S) { - PrintTag(T, S); + PrintTag(T->getDecl(), S); } void TypePrinter::PrintElaborated(const ElaboratedType *T, std::string &S) { - std::string TypeStr; - PrintingPolicy InnerPolicy(Policy); - InnerPolicy.SuppressTagKind = true; - TypePrinter(InnerPolicy).Print(T->getUnderlyingType(), S); - + Print(T->getUnderlyingType(), S); S = std::string(T->getNameForTagKind(T->getTagKind())) + ' ' + S; } @@ -494,6 +514,11 @@ void TypePrinter::PrintTemplateSpecialization( S = SpecString + ' ' + S; } +void TypePrinter::PrintInjectedClassName(const InjectedClassNameType *T, + std::string &S) { + PrintTemplateSpecialization(T->getUnderlyingTST(), S); +} + void TypePrinter::PrintQualifiedName(const QualifiedNameType *T, std::string &S) { std::string MyString; @@ -505,7 +530,6 @@ void TypePrinter::PrintQualifiedName(const QualifiedNameType *T, std::string TypeStr; PrintingPolicy InnerPolicy(Policy); - InnerPolicy.SuppressTagKind = true; InnerPolicy.SuppressScope = true; TypePrinter(InnerPolicy).Print(T->getNamedType(), TypeStr); diff --git a/lib/Analysis/AnalysisContext.cpp b/lib/Analysis/AnalysisContext.cpp index d9933e8..5640c4a 100644 --- a/lib/Analysis/AnalysisContext.cpp +++ b/lib/Analysis/AnalysisContext.cpp @@ -12,15 +12,16 @@ // //===----------------------------------------------------------------------===// -#include "clang/Analysis/CFG.h" -#include "clang/Analysis/AnalysisContext.h" -#include "clang/Analysis/Analyses/LiveVariables.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/ParentMap.h" #include "clang/AST/StmtVisitor.h" +#include "clang/Analysis/Analyses/LiveVariables.h" +#include "clang/Analysis/AnalysisContext.h" +#include "clang/Analysis/CFG.h" #include "clang/Analysis/Support/BumpVector.h" +#include "llvm/ADT/SmallSet.h" #include "llvm/Support/ErrorHandling.h" using namespace clang; @@ -207,11 +208,17 @@ class FindBlockDeclRefExprsVals : public StmtVisitor{ BumpVector &BEVals; BumpVectorContext &BC; llvm::DenseMap Visited; + llvm::SmallSet IgnoredContexts; public: FindBlockDeclRefExprsVals(BumpVector &bevals, BumpVectorContext &bc) : BEVals(bevals), BC(bc) {} - + + bool IsTrackedDecl(const VarDecl *VD) { + const DeclContext *DC = VD->getDeclContext(); + return IgnoredContexts.count(DC) == 0; + } + void VisitStmt(Stmt *S) { for (Stmt::child_iterator I = S->child_begin(), E = S->child_end();I!=E;++I) if (Stmt *child = *I) @@ -229,16 +236,23 @@ public: } } } - + void VisitBlockDeclRefExpr(BlockDeclRefExpr *DR) { if (const VarDecl *VD = dyn_cast(DR->getDecl())) { unsigned &flag = Visited[VD]; if (!flag) { flag = 1; - BEVals.push_back(VD, BC); + if (IsTrackedDecl(VD)) + BEVals.push_back(VD, BC); } } } + + void VisitBlockExpr(BlockExpr *BR) { + // Blocks containing blocks can transitively capture more variables. + IgnoredContexts.insert(BR->getBlockDecl()); + Visit(BR->getBlockDecl()->getBody()); + } }; } // end anonymous namespace diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index ae6d5df..3b226d0 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -598,6 +598,134 @@ public: } // end anonymous namespace. namespace { +// MBlaze abstract base class +class MBlazeTargetInfo : public TargetInfo { + static const char * const GCCRegNames[]; + static const TargetInfo::GCCRegAlias GCCRegAliases[]; + +public: + MBlazeTargetInfo(const std::string& triple) : TargetInfo(triple) { + DescriptionString = "E-p:32:32-i8:8:8-i16:16:16-i64:32:32-f64:32:32-" + "v64:32:32-v128:32:32-n32"; + } + + virtual void getTargetBuiltins(const Builtin::Info *&Records, + unsigned &NumRecords) const { + // FIXME: Implement. + Records = 0; + NumRecords = 0; + } + + virtual void getTargetDefines(const LangOptions &Opts, + MacroBuilder &Builder) const; + + virtual const char *getVAListDeclaration() const { + return "typedef char* __builtin_va_list;"; + } + virtual const char *getTargetPrefix() const { + return "mblaze"; + } + virtual void getGCCRegNames(const char * const *&Names, + unsigned &NumNames) const; + virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, + unsigned &NumAliases) const; + virtual bool validateAsmConstraint(const char *&Name, + TargetInfo::ConstraintInfo &Info) const { + switch (*Name) { + default: return false; + case 'O': // Zero + return true; + case 'b': // Base register + case 'f': // Floating point register + Info.setAllowsRegister(); + return true; + } + } + virtual const char *getClobbers() const { + return ""; + } +}; + +/// MBlazeTargetInfo::getTargetDefines - Return a set of the MBlaze-specific +/// #defines that are not tied to a specific subtarget. +void MBlazeTargetInfo::getTargetDefines(const LangOptions &Opts, + MacroBuilder &Builder) const { + // Target identification. + Builder.defineMacro("__microblaze__"); + Builder.defineMacro("_ARCH_MICROBLAZE"); + Builder.defineMacro("__MICROBLAZE__"); + + // Target properties. + Builder.defineMacro("_BIG_ENDIAN"); + Builder.defineMacro("__BIG_ENDIAN__"); + + // Subtarget options. + Builder.defineMacro("__REGISTER_PREFIX__", ""); +} + + +const char * const MBlazeTargetInfo::GCCRegNames[] = { + "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", + "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", + "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", + "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", + "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7", + "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15", + "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23", + "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31", + "hi", "lo", "accum","rmsr", "$fcc1","$fcc2","$fcc3","$fcc4", + "$fcc5","$fcc6","$fcc7","$ap", "$rap", "$frp" +}; + +void MBlazeTargetInfo::getGCCRegNames(const char * const *&Names, + unsigned &NumNames) const { + Names = GCCRegNames; + NumNames = llvm::array_lengthof(GCCRegNames); +} + +const TargetInfo::GCCRegAlias MBlazeTargetInfo::GCCRegAliases[] = { + { {"f0"}, "r0" }, + { {"f1"}, "r1" }, + { {"f2"}, "r2" }, + { {"f3"}, "r3" }, + { {"f4"}, "r4" }, + { {"f5"}, "r5" }, + { {"f6"}, "r6" }, + { {"f7"}, "r7" }, + { {"f8"}, "r8" }, + { {"f9"}, "r9" }, + { {"f10"}, "r10" }, + { {"f11"}, "r11" }, + { {"f12"}, "r12" }, + { {"f13"}, "r13" }, + { {"f14"}, "r14" }, + { {"f15"}, "r15" }, + { {"f16"}, "r16" }, + { {"f17"}, "r17" }, + { {"f18"}, "r18" }, + { {"f19"}, "r19" }, + { {"f20"}, "r20" }, + { {"f21"}, "r21" }, + { {"f22"}, "r22" }, + { {"f23"}, "r23" }, + { {"f24"}, "r24" }, + { {"f25"}, "r25" }, + { {"f26"}, "r26" }, + { {"f27"}, "r27" }, + { {"f28"}, "r28" }, + { {"f29"}, "r29" }, + { {"f30"}, "r30" }, + { {"f31"}, "r31" }, +}; + +void MBlazeTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, + unsigned &NumAliases) const { + Aliases = GCCRegAliases; + NumAliases = llvm::array_lengthof(GCCRegAliases); +} +} // end anonymous namespace. + +namespace { // Namespace for x86 abstract base class const Builtin::Info BuiltinInfo[] = { #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false }, @@ -2159,6 +2287,9 @@ static TargetInfo *AllocateTarget(const std::string &T) { return new FreeBSDTargetInfo(T); return new PPC64TargetInfo(T); + case llvm::Triple::mblaze: + return new MBlazeTargetInfo(T); + case llvm::Triple::sparc: if (os == llvm::Triple::AuroraUX) return new AuroraUXSparcV8TargetInfo(T); diff --git a/lib/Checker/BasicStore.cpp b/lib/Checker/BasicStore.cpp index d93a665..10136f3 100644 --- a/lib/Checker/BasicStore.cpp +++ b/lib/Checker/BasicStore.cpp @@ -142,7 +142,8 @@ SVal BasicStoreManager::LazyRetrieve(Store store, const TypedRegion *R) { // Globals and parameters start with symbolic values. // Local variables initially are undefined. - if (VR->hasGlobalsOrParametersStorage()) + if (VR->hasGlobalsOrParametersStorage() || + isa(VR->getMemorySpace())) return ValMgr.getRegionValueSymbolVal(R); return UndefinedVal(); } diff --git a/lib/Checker/CFRefCount.cpp b/lib/Checker/CFRefCount.cpp index ecb98a0..9a76f6a 100644 --- a/lib/Checker/CFRefCount.cpp +++ b/lib/Checker/CFRefCount.cpp @@ -853,7 +853,7 @@ public: RetainSummary *getClassMethodSummary(const ObjCMessageExpr *ME) { return getClassMethodSummary(ME->getSelector(), ME->getClassName(), - ME->getClassInfo().first, + ME->getClassInfo().Decl, ME->getMethodDecl(), ME->getType()); } @@ -2511,7 +2511,7 @@ static QualType GetReturnType(const Expr* RetE, ASTContext& Ctx) { // id, id<...>, or Class. If we have an ObjCInterfaceDecl, we know this // is a call to a class method whose type we can resolve. In such // cases, promote the return type to XXX* (where XXX is the class). - const ObjCInterfaceDecl *D = ME->getClassInfo().first; + const ObjCInterfaceDecl *D = ME->getClassInfo().Decl; return !D ? RetTy : Ctx.getPointerType(Ctx.getObjCInterfaceType(D)); } diff --git a/lib/Checker/GRExprEngine.cpp b/lib/Checker/GRExprEngine.cpp index 2ea689e..130d805 100644 --- a/lib/Checker/GRExprEngine.cpp +++ b/lib/Checker/GRExprEngine.cpp @@ -25,7 +25,6 @@ #include "clang/Basic/PrettyStackTrace.h" #include "llvm/Support/raw_ostream.h" #include "llvm/ADT/ImmutableList.h" -#include "llvm/ADT/StringSwitch.h" #ifndef NDEBUG #include "llvm/Support/GraphWriter.h" diff --git a/lib/Checker/MallocChecker.cpp b/lib/Checker/MallocChecker.cpp index 4ff9864..a08afc4 100644 --- a/lib/Checker/MallocChecker.cpp +++ b/lib/Checker/MallocChecker.cpp @@ -57,17 +57,20 @@ class RegionState {}; class MallocChecker : public CheckerVisitor { BuiltinBug *BT_DoubleFree; BuiltinBug *BT_Leak; + BuiltinBug *BT_UseFree; IdentifierInfo *II_malloc, *II_free, *II_realloc; public: MallocChecker() - : BT_DoubleFree(0), BT_Leak(0), II_malloc(0), II_free(0), II_realloc(0) {} + : BT_DoubleFree(0), BT_Leak(0), BT_UseFree(0), + II_malloc(0), II_free(0), II_realloc(0) {} static void *getTag(); bool EvalCallExpr(CheckerContext &C, const CallExpr *CE); void EvalDeadSymbols(CheckerContext &C,const Stmt *S,SymbolReaper &SymReaper); void EvalEndPath(GREndPathNodeBuilder &B, void *tag, GRExprEngine &Eng); void PreVisitReturnStmt(CheckerContext &C, const ReturnStmt *S); const GRState *EvalAssume(const GRState *state, SVal Cond, bool Assumption); + void VisitLocation(CheckerContext &C, const Stmt *S, SVal l); private: void MallocMem(CheckerContext &C, const CallExpr *CE); @@ -339,3 +342,22 @@ const GRState *MallocChecker::EvalAssume(const GRState *state, SVal Cond, return state; } + +// Check if the location is a freed symbolic region. +void MallocChecker::VisitLocation(CheckerContext &C, const Stmt *S, SVal l) { + SymbolRef Sym = l.getLocSymbolInBase(); + if (Sym) { + const RefState *RS = C.getState()->get(Sym); + if (RS) + if (RS->isReleased()) { + ExplodedNode *N = C.GenerateSink(); + if (!BT_UseFree) + BT_UseFree = new BuiltinBug("Use dynamically allocated memory after" + " it is freed."); + + BugReport *R = new BugReport(*BT_UseFree, BT_UseFree->getDescription(), + N); + C.EmitReport(R); + } + } +} diff --git a/lib/Checker/RegionStore.cpp b/lib/Checker/RegionStore.cpp index fd48f72..91c3a15 100644 --- a/lib/Checker/RegionStore.cpp +++ b/lib/Checker/RegionStore.cpp @@ -41,25 +41,25 @@ public: enum Kind { Direct = 0x0, Default = 0x1 }; private: llvm ::PointerIntPair P; - uint64_t Offset; - + uint64_t Offset; + explicit BindingKey(const MemRegion *r, uint64_t offset, Kind k) : P(r, (unsigned) k), Offset(offset) { assert(r); } public: - + bool isDefault() const { return P.getInt() == Default; } bool isDirect() const { return P.getInt() == Direct; } - + const MemRegion *getRegion() const { return P.getPointer(); } uint64_t getOffset() const { return Offset; } - + void Profile(llvm::FoldingSetNodeID& ID) const { ID.AddPointer(P.getOpaqueValue()); ID.AddInteger(Offset); } - + static BindingKey Make(const MemRegion *R, Kind k); - + bool operator<(const BindingKey &X) const { if (P.getOpaqueValue() < X.P.getOpaqueValue()) return true; @@ -67,16 +67,16 @@ public: return false; return Offset < X.Offset; } - + bool operator==(const BindingKey &X) const { return P.getOpaqueValue() == X.P.getOpaqueValue() && Offset == X.Offset; } -}; +}; } // end anonymous namespace namespace llvm { - static inline + static inline llvm::raw_ostream& operator<<(llvm::raw_ostream& os, BindingKey K) { os << '(' << K.getRegion() << ',' << K.getOffset() << ',' << (K.isDirect() ? "direct" : "default") @@ -174,7 +174,7 @@ public: void process(llvm::SmallVectorImpl &WL, const SubRegion *R); ~RegionStoreSubRegionMap() {} - + const Set *getSubRegions(const MemRegion *Parent) const { Map::const_iterator I = M.find(Parent); return I == M.end() ? NULL : &I->second; @@ -196,13 +196,10 @@ public: } }; - + class RegionStoreManager : public StoreManager { const RegionStoreFeatures Features; RegionBindings::Factory RBFactory; - - typedef llvm::DenseMap SMCache; - SMCache SC; public: RegionStoreManager(GRStateManager& mgr, const RegionStoreFeatures &f) @@ -210,11 +207,6 @@ public: Features(f), RBFactory(mgr.getAllocator()) {} - virtual ~RegionStoreManager() { - for (SMCache::iterator I = SC.begin(), E = SC.end(); I != E; ++I) - delete (*I).second; - } - SubRegionMap *getSubRegionMap(Store store) { return getRegionStoreSubRegionMap(store); } @@ -226,10 +218,10 @@ public: /// getDefaultBinding - Returns an SVal* representing an optional default /// binding associated with a region and its subregions. Optional getDefaultBinding(RegionBindings B, const MemRegion *R); - + /// setImplicitDefaultValue - Set the default binding for the provided /// MemRegion to the value implicitly defined for compound literals when - /// the value is not specified. + /// the value is not specified. Store setImplicitDefaultValue(Store store, const MemRegion *R, QualType T); /// ArrayToPointer - Emulates the "decay" of an array to a pointer @@ -250,11 +242,11 @@ public: // Binding values to regions. //===-------------------------------------------------------------------===// - Store InvalidateRegion(Store store, const MemRegion *R, const Expr *E, + Store InvalidateRegion(Store store, const MemRegion *R, const Expr *E, unsigned Count, InvalidatedSymbols *IS) { return RegionStoreManager::InvalidateRegions(store, &R, &R+1, E, Count, IS); } - + Store InvalidateRegions(Store store, const MemRegion * const *Begin, const MemRegion * const *End, @@ -262,7 +254,7 @@ public: InvalidatedSymbols *IS); public: // Made public for helper classes. - + void RemoveSubRegionBindings(RegionBindings &B, const MemRegion *R, RegionStoreSubRegionMap &M); @@ -270,17 +262,17 @@ public: // Made public for helper classes. RegionBindings Add(RegionBindings B, const MemRegion *R, BindingKey::Kind k, SVal V); - + const SVal *Lookup(RegionBindings B, BindingKey K); const SVal *Lookup(RegionBindings B, const MemRegion *R, BindingKey::Kind k); RegionBindings Remove(RegionBindings B, BindingKey K); RegionBindings Remove(RegionBindings B, const MemRegion *R, BindingKey::Kind k); - + RegionBindings Remove(RegionBindings B, const MemRegion *R) { return Remove(Remove(B, R, BindingKey::Direct), R, BindingKey::Default); - } + } Store Remove(Store store, BindingKey K); @@ -306,7 +298,7 @@ public: // Part of public interface to class. Store KillStruct(Store store, const TypedRegion* R); Store Remove(Store store, Loc LV); - + //===------------------------------------------------------------------===// // Loading values from regions. @@ -373,7 +365,7 @@ public: // Part of public interface to class. //===------------------------------------------------------------------===// const GRState *setExtent(const GRState *state,const MemRegion* R,SVal Extent); - DefinedOrUnknownSVal getSizeInElements(const GRState *state, + DefinedOrUnknownSVal getSizeInElements(const GRState *state, const MemRegion* R, QualType EleTy); //===------------------------------------------------------------------===// @@ -449,85 +441,148 @@ RegionStoreManager::getRegionStoreSubRegionMap(Store store) { } //===----------------------------------------------------------------------===// -// Binding invalidation. +// Region Cluster analysis. //===----------------------------------------------------------------------===// -void RegionStoreManager::RemoveSubRegionBindings(RegionBindings &B, - const MemRegion *R, - RegionStoreSubRegionMap &M) { - - if (const RegionStoreSubRegionMap::Set *S = M.getSubRegions(R)) - for (RegionStoreSubRegionMap::Set::iterator I = S->begin(), E = S->end(); - I != E; ++I) - RemoveSubRegionBindings(B, *I, M); - - B = Remove(B, R); -} - namespace { -class InvalidateRegionsWorker { +template +class ClusterAnalysis { +protected: typedef BumpVector RegionCluster; typedef llvm::DenseMap ClusterMap; - typedef llvm::SmallVector, 10> - WorkList; + llvm::DenseMap Visited; + typedef llvm::SmallVector, 10> + WorkList; BumpVectorContext BVC; ClusterMap ClusterM; WorkList WL; - + RegionStoreManager &RM; - StoreManager::InvalidatedSymbols *IS; ASTContext &Ctx; ValueManager &ValMgr; - + + RegionBindings B; + public: - InvalidateRegionsWorker(RegionStoreManager &rm, - StoreManager::InvalidatedSymbols *is, - ASTContext &ctx, ValueManager &valMgr) - : RM(rm), IS(is), Ctx(ctx), ValMgr(valMgr) {} - - Store InvalidateRegions(Store store, const MemRegion * const *I, - const MemRegion * const *E, - const Expr *Ex, unsigned Count); - -private: - void AddToWorkList(BindingKey K); - void AddToWorkList(const MemRegion *R); - void AddToCluster(BindingKey K); - RegionCluster **getCluster(const MemRegion *R); - void VisitBinding(SVal V); -}; -} + ClusterAnalysis(RegionStoreManager &rm, GRStateManager &StateMgr, + RegionBindings b) + : RM(rm), Ctx(StateMgr.getContext()), ValMgr(StateMgr.getValueManager()), + B(b) {} + + RegionBindings getRegionBindings() const { return B; } + + void AddToCluster(BindingKey K) { + const MemRegion *R = K.getRegion(); + const MemRegion *baseR = R->getBaseRegion(); + RegionCluster &C = getCluster(baseR); + C.push_back(K, BVC); + static_cast(this)->VisitAddedToCluster(baseR, C); + } -void InvalidateRegionsWorker::AddToCluster(BindingKey K) { - const MemRegion *R = K.getRegion(); - const MemRegion *baseR = R->getBaseRegion(); - RegionCluster **CPtr = getCluster(baseR); - assert(*CPtr); - (*CPtr)->push_back(K, BVC); -} + bool isVisited(const MemRegion *R) { + return (bool) Visited[&getCluster(R->getBaseRegion())]; + } -void InvalidateRegionsWorker::AddToWorkList(BindingKey K) { - AddToWorkList(K.getRegion()); -} + RegionCluster& getCluster(const MemRegion *R) { + RegionCluster *&CRef = ClusterM[R]; + if (!CRef) { + void *Mem = BVC.getAllocator().template Allocate(); + CRef = new (Mem) RegionCluster(BVC, 10); + } + return *CRef; + } -void InvalidateRegionsWorker::AddToWorkList(const MemRegion *R) { - const MemRegion *baseR = R->getBaseRegion(); - RegionCluster **CPtr = getCluster(baseR); - if (RegionCluster *C = *CPtr) { - WL.push_back(std::make_pair(baseR, C)); - *CPtr = NULL; + void GenerateClusters() { + // Scan the entire set of bindings and make the region clusters. + for (RegionBindings::iterator RI = B.begin(), RE = B.end(); RI != RE; ++RI){ + AddToCluster(RI.getKey()); + if (const MemRegion *R = RI.getData().getAsRegion()) { + // Generate a cluster, but don't add the region to the cluster + // if there aren't any bindings. + getCluster(R->getBaseRegion()); + } + } + } + + bool AddToWorkList(const MemRegion *R, RegionCluster &C) { + if (unsigned &visited = Visited[&C]) + return false; + else + visited = 1; + + WL.push_back(std::make_pair(R, &C)); + return true; + } + + bool AddToWorkList(BindingKey K) { + return AddToWorkList(K.getRegion()); } -} -InvalidateRegionsWorker::RegionCluster ** -InvalidateRegionsWorker::getCluster(const MemRegion *R) { - RegionCluster *&CRef = ClusterM[R]; - if (!CRef) { - void *Mem = BVC.getAllocator().Allocate(); - CRef = new (Mem) RegionCluster(BVC, 10); + bool AddToWorkList(const MemRegion *R) { + const MemRegion *baseR = R->getBaseRegion(); + return AddToWorkList(baseR, getCluster(baseR)); + } + + void RunWorkList() { + while (!WL.empty()) { + const MemRegion *baseR; + RegionCluster *C; + llvm::tie(baseR, C) = WL.back(); + WL.pop_back(); + + // First visit the cluster. + static_cast(this)->VisitCluster(baseR, C->begin(), C->end()); + + // Next, visit the region. + static_cast(this)->VisitRegion(baseR); + } } - return &CRef; + +public: + void VisitAddedToCluster(const MemRegion *baseR, RegionCluster &C) {} + void VisitCluster(const MemRegion *baseR, BindingKey *I, BindingKey *E) {} + void VisitRegion(const MemRegion *baseR) {} +}; +} + +//===----------------------------------------------------------------------===// +// Binding invalidation. +//===----------------------------------------------------------------------===// + +void RegionStoreManager::RemoveSubRegionBindings(RegionBindings &B, + const MemRegion *R, + RegionStoreSubRegionMap &M) { + + if (const RegionStoreSubRegionMap::Set *S = M.getSubRegions(R)) + for (RegionStoreSubRegionMap::Set::iterator I = S->begin(), E = S->end(); + I != E; ++I) + RemoveSubRegionBindings(B, *I, M); + + B = Remove(B, R); +} + +namespace { +class InvalidateRegionsWorker : public ClusterAnalysis +{ + const Expr *Ex; + unsigned Count; + StoreManager::InvalidatedSymbols *IS; +public: + InvalidateRegionsWorker(RegionStoreManager &rm, + GRStateManager &stateMgr, + RegionBindings b, + const Expr *ex, unsigned count, + StoreManager::InvalidatedSymbols *is) + : ClusterAnalysis(rm, stateMgr, b), + Ex(ex), Count(count), IS(is) {} + + void VisitCluster(const MemRegion *baseR, BindingKey *I, BindingKey *E); + void VisitRegion(const MemRegion *baseR); + +private: + void VisitBinding(SVal V); +}; } void InvalidateRegionsWorker::VisitBinding(SVal V) { @@ -535,7 +590,7 @@ void InvalidateRegionsWorker::VisitBinding(SVal V) { if (IS) if (SymbolRef Sym = V.getAsSymbol()) IS->insert(Sym); - + if (const MemRegion *R = V.getAsRegion()) { AddToWorkList(R); return; @@ -558,112 +613,82 @@ void InvalidateRegionsWorker::VisitBinding(SVal V) { } } -Store InvalidateRegionsWorker::InvalidateRegions(Store store, - const MemRegion * const *I, - const MemRegion * const *E, - const Expr *Ex, unsigned Count) -{ - RegionBindings B = RegionStoreManager::GetRegionBindings(store); - - // Scan the entire store and make the region clusters. - for (RegionBindings::iterator RI = B.begin(), RE = B.end(); RI != RE; ++RI) { - AddToCluster(RI.getKey()); - if (const MemRegion *R = RI.getData().getAsRegion()) { - // Generate a cluster, but don't add the region to the cluster - // if there aren't any bindings. - getCluster(R->getBaseRegion()); - } +void InvalidateRegionsWorker::VisitCluster(const MemRegion *baseR, + BindingKey *I, BindingKey *E) { + for ( ; I != E; ++I) { + // Get the old binding. Is it a region? If so, add it to the worklist. + const BindingKey &K = *I; + if (const SVal *V = RM.Lookup(B, K)) + VisitBinding(*V); + + B = RM.Remove(B, K); } - - // Add the cluster for I .. E to a worklist. - for ( ; I != E; ++I) - AddToWorkList(*I); +} - while (!WL.empty()) { - const MemRegion *baseR; - RegionCluster *C; - llvm::tie(baseR, C) = WL.back(); - WL.pop_back(); - - for (RegionCluster::iterator I = C->begin(), E = C->end(); I != E; ++I) { - BindingKey K = *I; - - // Get the old binding. Is it a region? If so, add it to the worklist. - if (const SVal *V = RM.Lookup(B, K)) - VisitBinding(*V); - - B = RM.Remove(B, K); - } - - // Now inspect the base region. +void InvalidateRegionsWorker::VisitRegion(const MemRegion *baseR) { + if (IS) { + // Symbolic region? Mark that symbol touched by the invalidation. + if (const SymbolicRegion *SR = dyn_cast(baseR)) + IS->insert(SR->getSymbol()); + } - if (IS) { - // Symbolic region? Mark that symbol touched by the invalidation. - if (const SymbolicRegion *SR = dyn_cast(baseR)) - IS->insert(SR->getSymbol()); + // BlockDataRegion? If so, invalidate captured variables that are passed + // by reference. + if (const BlockDataRegion *BR = dyn_cast(baseR)) { + for (BlockDataRegion::referenced_vars_iterator + BI = BR->referenced_vars_begin(), BE = BR->referenced_vars_end() ; + BI != BE; ++BI) { + const VarRegion *VR = *BI; + const VarDecl *VD = VR->getDecl(); + if (VD->getAttr() || !VD->hasLocalStorage()) + AddToWorkList(VR); } - - // BlockDataRegion? If so, invalidate captured variables that are passed - // by reference. - if (const BlockDataRegion *BR = dyn_cast(baseR)) { - for (BlockDataRegion::referenced_vars_iterator - BI = BR->referenced_vars_begin(), BE = BR->referenced_vars_end() ; - BI != BE; ++BI) { - const VarRegion *VR = *BI; - const VarDecl *VD = VR->getDecl(); - if (VD->getAttr() || !VD->hasLocalStorage()) - AddToWorkList(VR); - } - continue; - } - - if (isa(baseR) || isa(baseR)) { - // Invalidate the region by setting its default value to - // conjured symbol. The type of the symbol is irrelavant. - DefinedOrUnknownSVal V = ValMgr.getConjuredSymbolVal(baseR, Ex, Ctx.IntTy, - Count); - B = RM.Add(B, baseR, BindingKey::Default, V); - continue; - } - - if (!baseR->isBoundable()) - continue; - - const TypedRegion *TR = cast(baseR); - QualType T = TR->getValueType(Ctx); - - // Invalidate the binding. - if (const RecordType *RT = T->getAsStructureType()) { - const RecordDecl *RD = RT->getDecl()->getDefinition(); + return; + } + + if (isa(baseR) || isa(baseR)) { + // Invalidate the region by setting its default value to + // conjured symbol. The type of the symbol is irrelavant. + DefinedOrUnknownSVal V = ValMgr.getConjuredSymbolVal(baseR, Ex, Ctx.IntTy, + Count); + B = RM.Add(B, baseR, BindingKey::Default, V); + return; + } + + if (!baseR->isBoundable()) + return; + + const TypedRegion *TR = cast(baseR); + QualType T = TR->getValueType(Ctx); + + // Invalidate the binding. + if (const RecordType *RT = T->getAsStructureType()) { + const RecordDecl *RD = RT->getDecl()->getDefinition(); // No record definition. There is nothing we can do. - if (!RD) { - B = RM.Remove(B, baseR); - continue; - } - + if (!RD) { + B = RM.Remove(B, baseR); + return; + } + // Invalidate the region by setting its default value to // conjured symbol. The type of the symbol is irrelavant. - DefinedOrUnknownSVal V = ValMgr.getConjuredSymbolVal(baseR, Ex, Ctx.IntTy, - Count); - B = RM.Add(B, baseR, BindingKey::Default, V); - continue; - } + DefinedOrUnknownSVal V = ValMgr.getConjuredSymbolVal(baseR, Ex, Ctx.IntTy, + Count); + B = RM.Add(B, baseR, BindingKey::Default, V); + return; + } - if (const ArrayType *AT = Ctx.getAsArrayType(T)) { + if (const ArrayType *AT = Ctx.getAsArrayType(T)) { // Set the default value of the array to conjured symbol. - DefinedOrUnknownSVal V = - ValMgr.getConjuredSymbolVal(baseR, Ex, AT->getElementType(), Count); - B = RM.Add(B, baseR, BindingKey::Default, V); - continue; - } - - DefinedOrUnknownSVal V = ValMgr.getConjuredSymbolVal(baseR, Ex, T, Count); - assert(SymbolManager::canSymbolicate(T) || V.isUnknown()); - B = RM.Add(B, baseR, BindingKey::Direct, V); + DefinedOrUnknownSVal V = + ValMgr.getConjuredSymbolVal(baseR, Ex, AT->getElementType(), Count); + B = RM.Add(B, baseR, BindingKey::Default, V); + return; } - // Create a new state with the updated bindings. - return B.getRoot(); + DefinedOrUnknownSVal V = ValMgr.getConjuredSymbolVal(baseR, Ex, T, Count); + assert(SymbolManager::canSymbolicate(T) || V.isUnknown()); + B = RM.Add(B, baseR, BindingKey::Direct, V); } Store RegionStoreManager::InvalidateRegions(Store store, @@ -671,11 +696,23 @@ Store RegionStoreManager::InvalidateRegions(Store store, const MemRegion * const *E, const Expr *Ex, unsigned Count, InvalidatedSymbols *IS) { - InvalidateRegionsWorker W(*this, IS, getContext(), - StateMgr.getValueManager()); - return W.InvalidateRegions(store, I, E, Ex, Count); + InvalidateRegionsWorker W(*this, StateMgr, + RegionStoreManager::GetRegionBindings(store), + Ex, Count, IS); + + // Scan the bindings and generate the clusters. + W.GenerateClusters(); + + // Add I .. E to the worklist. + for ( ; I != E; ++I) + W.AddToWorkList(*I); + + W.RunWorkList(); + + // Return the new bindings. + return W.getRegionBindings().getRoot(); } - + //===----------------------------------------------------------------------===// // Extents for regions. //===----------------------------------------------------------------------===// @@ -686,7 +723,7 @@ DefinedOrUnknownSVal RegionStoreManager::getSizeInElements(const GRState *state, switch (R->getKind()) { case MemRegion::CXXThisRegionKind: - assert(0 && "Cannot get size of 'this' region"); + assert(0 && "Cannot get size of 'this' region"); case MemRegion::GenericMemSpaceRegionKind: case MemRegion::StackLocalsSpaceRegionKind: case MemRegion::StackArgumentsSpaceRegionKind: @@ -719,7 +756,7 @@ DefinedOrUnknownSVal RegionStoreManager::getSizeInElements(const GRState *state, if (!CI) return UnknownVal(); - CharUnits RegionSize = + CharUnits RegionSize = CharUnits::fromQuantity(CI->getValue().getSExtValue()); CharUnits EleSize = getContext().getTypeSizeInChars(EleTy); assert(RegionSize % EleSize == 0); @@ -840,7 +877,7 @@ SVal RegionStoreManager::EvalBinOp(BinaryOperator::Opcode Op, Loc L, NonLoc R, // Not yet handled. case MemRegion::VarRegionKind: case MemRegion::StringRegionKind: { - + } // Fall-through. case MemRegion::CompoundLiteralRegionKind: @@ -884,13 +921,13 @@ SVal RegionStoreManager::EvalBinOp(BinaryOperator::Opcode Op, Loc L, NonLoc R, MRMgr.getElementRegion(ER->getElementType(), NewIdx, ER->getSuperRegion(), getContext()); return ValMgr.makeLoc(NewER); - } + } if (0 == Base->getValue()) { const MemRegion* NewER = MRMgr.getElementRegion(ER->getElementType(), R, ER->getSuperRegion(), getContext()); - return ValMgr.makeLoc(NewER); - } + return ValMgr.makeLoc(NewER); + } } return UnknownVal(); @@ -900,10 +937,10 @@ SVal RegionStoreManager::EvalBinOp(BinaryOperator::Opcode Op, Loc L, NonLoc R, // Loading values from regions. //===----------------------------------------------------------------------===// -Optional RegionStoreManager::getDirectBinding(RegionBindings B, +Optional RegionStoreManager::getDirectBinding(RegionBindings B, const MemRegion *R) { if (const SVal *V = Lookup(B, R, BindingKey::Direct)) - return *V; + return *V; return Optional(); } @@ -923,10 +960,10 @@ Optional RegionStoreManager::getDefaultBinding(RegionBindings B, Optional RegionStoreManager::getBinding(RegionBindings B, const MemRegion *R) { - + if (Optional V = getDirectBinding(B, R)) return V; - + return getDefaultBinding(B, R); } @@ -964,12 +1001,12 @@ RegionStoreManager::GetElementZeroRegion(const MemRegion *R, QualType T) { SVal RegionStoreManager::Retrieve(Store store, Loc L, QualType T) { assert(!isa(L) && "location unknown"); assert(!isa(L) && "location undefined"); - + // FIXME: Is this even possible? Shouldn't this be treated as a null // dereference at a higher level? if (isa(L)) return UndefinedVal(); - + const MemRegion *MR = cast(L).getRegion(); if (isa(MR) || isa(MR)) @@ -1029,7 +1066,7 @@ SVal RegionStoreManager::Retrieve(Store store, Loc L, QualType T) { // bound regions (e.g., several bound bytes), or could be a subset of // a larger value. return CastRetrievedVal(RetrieveElement(store, ER), ER, T, false); - } + } if (const ObjCIvarRegion *IVR = dyn_cast(R)) { // FIXME: Here we actually perform an implicit conversion from the loaded @@ -1047,7 +1084,7 @@ SVal RegionStoreManager::Retrieve(Store store, Loc L, QualType T) { // that blow past the extent of the variable. If the address of the // variable is reinterpretted, it is possible we stored a different value // that could fit within the variable. Either we need to cast these when - // storing them or reinterpret them lazily (as we do here). + // storing them or reinterpret them lazily (as we do here). return CastRetrievedVal(RetrieveVar(store, VR), VR, T, false); } @@ -1096,7 +1133,7 @@ RegionStoreManager::GetLazyBinding(RegionBindings B, const MemRegion *R) { return std::make_pair(X.first, MRMgr.getFieldRegionWithSuper(FR, X.second)); } - // The NULL MemRegion indicates an non-existent lazy binding. A NULL Store is + // The NULL MemRegion indicates an non-existent lazy binding. A NULL Store is // possible for a valid lazy binding. return std::make_pair((Store) 0, (const MemRegion *) 0); } @@ -1112,13 +1149,13 @@ SVal RegionStoreManager::RetrieveElement(Store store, // Check if the region is an element region of a string literal. if (const StringRegion *StrR=dyn_cast(superR)) { - // FIXME: Handle loads from strings where the literal is treated as + // FIXME: Handle loads from strings where the literal is treated as // an integer, e.g., *((unsigned int*)"hello") ASTContext &Ctx = getContext(); QualType T = Ctx.getAsArrayType(StrR->getValueType(Ctx))->getElementType(); if (T != Ctx.getCanonicalType(R->getElementType())) return UnknownVal(); - + const StringLiteral *Str = StrR->getStringLiteral(); SVal Idx = R->getIndex(); if (nonloc::ConcreteInt *CI = dyn_cast(&Idx)) { @@ -1155,7 +1192,7 @@ SVal RegionStoreManager::RetrieveElement(Store store, // Other cases: give up. return UnknownVal(); } - + return RetrieveFieldOrElementCommon(store, R, R->getElementType(), superR); } @@ -1268,8 +1305,8 @@ SVal RegionStoreManager::RetrieveVar(Store store, const VarRegion *R) { const VarDecl *VD = R->getDecl(); QualType T = VD->getType(); const MemSpaceRegion *MS = R->getMemorySpace(); - - if (isa(MS) || + + if (isa(MS) || isa(MS)) return ValMgr.getRegionValueSymbolVal(R); @@ -1282,9 +1319,9 @@ SVal RegionStoreManager::RetrieveVar(Store store, const VarRegion *R) { if (T->isPointerType()) return ValMgr.makeNull(); - return UnknownVal(); + return UnknownVal(); } - + return UndefinedVal(); } @@ -1402,7 +1439,7 @@ Store RegionStoreManager::Bind(Store store, Loc L, SVal V) { // Binding directly to a symbolic region should be treated as binding // to element 0. QualType T = SR->getSymbol()->getType(getContext()); - + // FIXME: Is this the right way to handle symbols that are references? if (const PointerType *PT = T->getAs()) T = PT->getPointeeType(); @@ -1417,7 +1454,7 @@ Store RegionStoreManager::Bind(Store store, Loc L, SVal V) { return Add(B, R, BindingKey::Direct, V).getRoot(); } -Store RegionStoreManager::BindDecl(Store store, const VarRegion *VR, +Store RegionStoreManager::BindDecl(Store store, const VarRegion *VR, SVal InitVal) { QualType T = VR->getDecl()->getType(); @@ -1460,19 +1497,19 @@ Store RegionStoreManager::setImplicitDefaultValue(Store store, return Add(B, R, BindingKey::Default, V).getRoot(); } - -Store RegionStoreManager::BindArray(Store store, const TypedRegion* R, + +Store RegionStoreManager::BindArray(Store store, const TypedRegion* R, SVal Init) { - + ASTContext &Ctx = getContext(); const ArrayType *AT = cast(Ctx.getCanonicalType(R->getValueType(Ctx))); - QualType ElementTy = AT->getElementType(); + QualType ElementTy = AT->getElementType(); Optional Size; - + if (const ConstantArrayType* CAT = dyn_cast(AT)) Size = CAT->getSize().getZExtValue(); - + // Check if the init expr is a StringLiteral. if (isa(Init)) { const MemRegion* InitR = cast(Init).getRegion(); @@ -1484,11 +1521,11 @@ Store RegionStoreManager::BindArray(Store store, const TypedRegion* R, // Copy bytes from the string literal into the target array. Trailing bytes // in the array that are not covered by the string literal are initialized // to zero. - + // We assume that string constants are bound to // constant arrays. uint64_t size = Size.getValue(); - + for (uint64_t i = 0; i < size; ++i, ++j) { if (j >= len) break; @@ -1509,10 +1546,10 @@ Store RegionStoreManager::BindArray(Store store, const TypedRegion* R, return CopyLazyBindings(*LCV, store, R); // Remaining case: explicit compound values. - + if (Init.isUnknown()) - return setImplicitDefaultValue(store, R, ElementTy); - + return setImplicitDefaultValue(store, R, ElementTy); + nonloc::CompoundVal& CV = cast(Init); nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end(); uint64_t i = 0; @@ -1628,14 +1665,14 @@ Store RegionStoreManager::CopyLazyBindings(nonloc::LazyCompoundVal V, BindingKey BindingKey::Make(const MemRegion *R, Kind k) { if (const ElementRegion *ER = dyn_cast(R)) { const RegionRawOffset &O = ER->getAsRawOffset(); - + if (O.getRegion()) return BindingKey(O.getRegion(), O.getByteOffset(), k); - + // FIXME: There are some ElementRegions for which we cannot compute // raw offsets yet, including regions with symbolic offsets. } - + return BindingKey(R, 0, k); } @@ -1675,194 +1712,163 @@ Store RegionStoreManager::Remove(Store store, BindingKey K) { //===----------------------------------------------------------------------===// // State pruning. //===----------------------------------------------------------------------===// - -Store RegionStoreManager::RemoveDeadBindings(Store store, Stmt* Loc, - SymbolReaper& SymReaper, - llvm::SmallVectorImpl& RegionRoots) -{ - typedef std::pair RBDNode; - RegionBindings B = GetRegionBindings(store); +namespace { +class RemoveDeadBindingsWorker : + public ClusterAnalysis { + llvm::SmallVector Postponed; + SymbolReaper &SymReaper; + Stmt *Loc; +public: + RemoveDeadBindingsWorker(RegionStoreManager &rm, GRStateManager &stateMgr, + RegionBindings b, SymbolReaper &symReaper, + Stmt *loc) + : ClusterAnalysis(rm, stateMgr, b), + SymReaper(symReaper), Loc(loc) {} + + // Called by ClusterAnalysis. + void VisitAddedToCluster(const MemRegion *baseR, RegionCluster &C); + void VisitCluster(const MemRegion *baseR, BindingKey *I, BindingKey *E); + void VisitRegion(const MemRegion *baseR); + + bool UpdatePostponed(); + void VisitBinding(SVal V); +}; +} - // The backmap from regions to subregions. - llvm::OwningPtr - SubRegions(getRegionStoreSubRegionMap(store)); - - // Do a pass over the regions in the store. For VarRegions we check if - // the variable is still live and if so add it to the list of live roots. - // For other regions we populate our region backmap. - llvm::SmallVector IntermediateRoots; - - // Scan the direct bindings for "intermediate" roots. - for (RegionBindings::iterator I = B.begin(), E = B.end(); I != E; ++I) { - const MemRegion *R = I.getKey().getRegion(); - IntermediateRoots.push_back(R); - } - - // Process the "intermediate" roots to find if they are referenced by - // real roots. - llvm::SmallVector WorkList; - llvm::SmallVector Postponed; - - llvm::DenseSet IntermediateVisited; - - while (!IntermediateRoots.empty()) { - const MemRegion* R = IntermediateRoots.back(); - IntermediateRoots.pop_back(); - - if (IntermediateVisited.count(R)) - continue; - IntermediateVisited.insert(R); - - if (const VarRegion* VR = dyn_cast(R)) { - if (SymReaper.isLive(Loc, VR)) - WorkList.push_back(std::make_pair(store, VR)); - continue; - } - - if (const SymbolicRegion* SR = dyn_cast(R)) { - llvm::SmallVectorImpl &Q = - SymReaper.isLive(SR->getSymbol()) ? WorkList : Postponed; - - Q.push_back(std::make_pair(store, SR)); +void RemoveDeadBindingsWorker::VisitAddedToCluster(const MemRegion *baseR, + RegionCluster &C) { - continue; - } - - // Add the super region for R to the worklist if it is a subregion. - if (const SubRegion* superR = - dyn_cast(cast(R)->getSuperRegion())) - IntermediateRoots.push_back(superR); + if (const VarRegion *VR = dyn_cast(baseR)) { + if (SymReaper.isLive(Loc, VR)) + AddToWorkList(baseR, C); + + return; } - // Enqueue the RegionRoots onto WorkList. - for (llvm::SmallVectorImpl::iterator I=RegionRoots.begin(), - E=RegionRoots.end(); I!=E; ++I) { - WorkList.push_back(std::make_pair(store, *I)); - } - RegionRoots.clear(); - - llvm::DenseSet Visited; - -tryAgain: - while (!WorkList.empty()) { - RBDNode N = WorkList.back(); - WorkList.pop_back(); - - // Have we visited this node before? - if (Visited.count(N)) - continue; - Visited.insert(N); - - const MemRegion *R = N.second; - Store store_N = N.first; - - // Enqueue subregions. - RegionStoreSubRegionMap *M; - - if (store == store_N) - M = SubRegions.get(); - else { - RegionStoreSubRegionMap *& SM = SC[store_N]; - if (!SM) - SM = getRegionStoreSubRegionMap(store_N); - M = SM; - } + if (const SymbolicRegion *SR = dyn_cast(baseR)) { + if (SymReaper.isLive(SR->getSymbol())) + AddToWorkList(SR, C); + else + Postponed.push_back(SR); - if (const RegionStoreSubRegionMap::Set *S = M->getSubRegions(R)) - for (RegionStoreSubRegionMap::Set::iterator I = S->begin(), E = S->end(); - I != E; ++I) - WorkList.push_back(std::make_pair(store_N, *I)); - - // Enqueue the super region. - if (const SubRegion *SR = dyn_cast(R)) { - const MemRegion *superR = SR->getSuperRegion(); - if (!isa(superR)) { - // If 'R' is a field or an element, we want to keep the bindings - // for the other fields and elements around. The reason is that - // pointer arithmetic can get us to the other fields or elements. - assert(isa(R) || isa(R) - || isa(R)); - WorkList.push_back(std::make_pair(store_N, superR)); - } - } + return; + } +} - // Mark the symbol for any live SymbolicRegion as "live". This means we - // should continue to track that symbol. - if (const SymbolicRegion *SymR = dyn_cast(R)) - SymReaper.markLive(SymR->getSymbol()); - - // For BlockDataRegions, enqueue the VarRegions for variables marked - // with __block (passed-by-reference). - // via BlockDeclRefExprs. - if (const BlockDataRegion *BD = dyn_cast(R)) { - for (BlockDataRegion::referenced_vars_iterator - RI = BD->referenced_vars_begin(), RE = BD->referenced_vars_end(); - RI != RE; ++RI) { - if ((*RI)->getDecl()->getAttr()) - WorkList.push_back(std::make_pair(store_N, *RI)); - } - // No possible data bindings on a BlockDataRegion. Continue to the - // next region in the worklist. - continue; +void RemoveDeadBindingsWorker::VisitCluster(const MemRegion *baseR, + BindingKey *I, BindingKey *E) { + for ( ; I != E; ++I) { + const MemRegion *R = I->getRegion(); + if (R != baseR) + VisitRegion(R); + } +} + +void RemoveDeadBindingsWorker::VisitBinding(SVal V) { + // Is it a LazyCompoundVal? All referenced regions are live as well. + if (const nonloc::LazyCompoundVal *LCS = + dyn_cast(&V)) { + + const MemRegion *LazyR = LCS->getRegion(); + RegionBindings B = RegionStoreManager::GetRegionBindings(LCS->getStore()); + for (RegionBindings::iterator RI = B.begin(), RE = B.end(); RI != RE; ++RI){ + const MemRegion *baseR = RI.getKey().getRegion(); + if (cast(baseR)->isSubRegionOf(LazyR)) + VisitBinding(RI.getData()); } + return; + } - RegionBindings B_N = GetRegionBindings(store_N); - - // Get the data binding for R (if any). - Optional V = getBinding(B_N, R); - - if (V) { - // Check for lazy bindings. - if (const nonloc::LazyCompoundVal *LCV = - dyn_cast(V.getPointer())) { - - const LazyCompoundValData *D = LCV->getCVData(); - WorkList.push_back(std::make_pair(D->getStore(), D->getRegion())); - } - else { - // Update the set of live symbols. - for (SVal::symbol_iterator SI=V->symbol_begin(), SE=V->symbol_end(); - SI!=SE;++SI) - SymReaper.markLive(*SI); - - // If V is a region, then add it to the worklist. - if (const MemRegion *RX = V->getAsRegion()) - WorkList.push_back(std::make_pair(store_N, RX)); - } + // If V is a region, then add it to the worklist. + if (const MemRegion *R = V.getAsRegion()) + AddToWorkList(R); + + // Update the set of live symbols. + for (SVal::symbol_iterator SI=V.symbol_begin(), SE=V.symbol_end(); + SI!=SE;++SI) + SymReaper.markLive(*SI); +} + +void RemoveDeadBindingsWorker::VisitRegion(const MemRegion *R) { + // Mark this region "live" by adding it to the worklist. This will cause + // use to visit all regions in the cluster (if we haven't visited them + // already). + AddToWorkList(R); + + // Mark the symbol for any live SymbolicRegion as "live". This means we + // should continue to track that symbol. + if (const SymbolicRegion *SymR = dyn_cast(R)) + SymReaper.markLive(SymR->getSymbol()); + + // For BlockDataRegions, enqueue the VarRegions for variables marked + // with __block (passed-by-reference). + // via BlockDeclRefExprs. + if (const BlockDataRegion *BD = dyn_cast(R)) { + for (BlockDataRegion::referenced_vars_iterator + RI = BD->referenced_vars_begin(), RE = BD->referenced_vars_end(); + RI != RE; ++RI) { + if ((*RI)->getDecl()->getAttr()) + AddToWorkList(*RI); } + + // No possible data bindings on a BlockDataRegion. + return; } - + + // Get the data binding for R (if any). + if (Optional V = RM.getBinding(B, R)) + VisitBinding(*V); +} + +bool RemoveDeadBindingsWorker::UpdatePostponed() { // See if any postponed SymbolicRegions are actually live now, after // having done a scan. - for (llvm::SmallVectorImpl::iterator I = Postponed.begin(), - E = Postponed.end() ; I != E ; ++I) { - if (const SymbolicRegion *SR = cast_or_null(I->second)) { + bool changed = false; + + for (llvm::SmallVectorImpl::iterator + I = Postponed.begin(), E = Postponed.end() ; I != E ; ++I) { + if (const SymbolicRegion *SR = cast_or_null(*I)) { if (SymReaper.isLive(SR->getSymbol())) { - WorkList.push_back(*I); - I->second = NULL; + changed |= AddToWorkList(SR); + *I = NULL; } } } - - if (!WorkList.empty()) - goto tryAgain; - + + return changed; +} + +Store RegionStoreManager::RemoveDeadBindings(Store store, Stmt* Loc, + SymbolReaper& SymReaper, + llvm::SmallVectorImpl& RegionRoots) +{ + RegionBindings B = GetRegionBindings(store); + RemoveDeadBindingsWorker W(*this, StateMgr, B, SymReaper, Loc); + W.GenerateClusters(); + + // Enqueue the region roots onto the worklist. + for (llvm::SmallVectorImpl::iterator I=RegionRoots.begin(), + E=RegionRoots.end(); I!=E; ++I) + W.AddToWorkList(*I); + + do W.RunWorkList(); while (W.UpdatePostponed()); + // We have now scanned the store, marking reachable regions and symbols // as live. We now remove all the regions that are dead from the store // as well as update DSymbols with the set symbols that are now dead. - Store new_store = store; for (RegionBindings::iterator I = B.begin(), E = B.end(); I != E; ++I) { - const MemRegion* R = I.getKey().getRegion(); - // If this region live? Is so, none of its symbols are dead. - if (Visited.count(std::make_pair(store, R))) + const BindingKey &K = I.getKey(); + + // If the cluster has been visited, we know the region has been marked. + if (W.isVisited(K.getRegion())) continue; - // Remove this dead region from the store. - new_store = Remove(new_store, I.getKey()); + // Remove the dead entry. + B = Remove(B, K); - // Mark all non-live symbols that this region references as dead. - if (const SymbolicRegion* SymR = dyn_cast(R)) + // Mark all non-live symbols that this binding references as dead. + if (const SymbolicRegion* SymR = dyn_cast(K.getRegion())) SymReaper.maybeDead(SymR->getSymbol()); SVal X = I.getData(); @@ -1871,9 +1877,10 @@ tryAgain: SymReaper.maybeDead(*SI); } - return new_store; + return B.getRoot(); } + GRState const *RegionStoreManager::EnterStackFrame(GRState const *state, StackFrameContext const *frame) { FunctionDecl const *FD = cast(frame->getDecl()); diff --git a/lib/Checker/SVals.cpp b/lib/Checker/SVals.cpp index 28b3fce..4bfa2cd 100644 --- a/lib/Checker/SVals.cpp +++ b/lib/Checker/SVals.cpp @@ -70,6 +70,25 @@ SymbolRef SVal::getAsLocSymbol() const { return NULL; } +/// Get the symbol in the SVal or its base region. +SymbolRef SVal::getLocSymbolInBase() const { + const loc::MemRegionVal *X = dyn_cast(this); + + if (!X) + return 0; + + const MemRegion *R = X->getRegion(); + + while (const SubRegion *SR = dyn_cast(R)) { + if (const SymbolicRegion *SymR = dyn_cast(SR)) + return SymR->getSymbol(); + else + R = SR->getSuperRegion(); + } + + return 0; +} + /// getAsSymbol - If this Sval wraps a symbol return that SymbolRef. /// Otherwise return 0. // FIXME: should we consider SymbolRef wrapped in CodeTextRegion? diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 0f3502e..c3302e6 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -36,8 +36,9 @@ using namespace clang; using namespace clang::CodeGen; CGDebugInfo::CGDebugInfo(CodeGenModule &CGM) - : CGM(CGM), isMainCompileUnitCreated(false), DebugFactory(CGM.getModule()), - BlockLiteralGenericSet(false) { + : CGM(CGM), DebugFactory(CGM.getModule()), + FwdDeclCount(0), BlockLiteralGenericSet(false) { + CreateCompileUnit(); } CGDebugInfo::~CGDebugInfo() { @@ -85,45 +86,29 @@ llvm::StringRef CGDebugInfo::getFunctionName(const FunctionDecl *FD) { return llvm::StringRef(StrPtr, NS.length()); } -/// getOrCreateCompileUnit - Get the compile unit from the cache or create a new -/// one if necessary. This returns null for invalid source locations. -llvm::DICompileUnit CGDebugInfo::getOrCreateCompileUnit(SourceLocation Loc) { - // Get source file information. - const char *FileName = ""; +/// getOrCreateFile - Get the file debug info descriptor for the input location. +llvm::DIFile CGDebugInfo::getOrCreateFile(SourceLocation Loc) { + if (!Loc.isValid()) + // If Location is not valid then use main input file. + return DebugFactory.CreateFile(TheCU.getFilename(), TheCU.getDirectory(), + TheCU); SourceManager &SM = CGM.getContext().getSourceManager(); - if (Loc.isValid()) { - PresumedLoc PLoc = SM.getPresumedLoc(Loc); - FileName = PLoc.getFilename(); - unsigned FID = PLoc.getIncludeLoc().getRawEncoding(); - - // See if this compile unit has been used before for this valid location. - llvm::DICompileUnit &Unit = CompileUnitCache[FID]; - if (!Unit.isNull()) return Unit; - } + PresumedLoc PLoc = SM.getPresumedLoc(Loc); + llvm::sys::Path AbsFileName(PLoc.getFilename()); + AbsFileName.makeAbsolute(); + + return DebugFactory.CreateFile(AbsFileName.getLast(), + AbsFileName.getDirname(), TheCU); +} +/// CreateCompileUnit - Create new compile unit. +void CGDebugInfo::CreateCompileUnit() { // Get absolute path name. - llvm::sys::Path AbsFileName(FileName); + llvm::sys::Path AbsFileName(CGM.getCodeGenOpts().MainFileName); AbsFileName.makeAbsolute(); - // See if thie compile unit is representing main source file. Each source - // file has corresponding compile unit. There is only one main source - // file at a time. - bool isMain = false; - const LangOptions &LO = CGM.getLangOptions(); - const CodeGenOptions &CGO = CGM.getCodeGenOpts(); - if (isMainCompileUnitCreated == false) { - if (!CGO.MainFileName.empty()) { - if (AbsFileName.getLast() == CGO.MainFileName) - isMain = true; - } else { - if (Loc.isValid() && SM.isFromMainFile(Loc)) - isMain = true; - } - if (isMain) - isMainCompileUnitCreated = true; - } - unsigned LangTag; + const LangOptions &LO = CGM.getLangOptions(); if (LO.CPlusPlus) { if (LO.ObjC1) LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus; @@ -149,22 +134,15 @@ llvm::DICompileUnit CGDebugInfo::getOrCreateCompileUnit(SourceLocation Loc) { RuntimeVers = LO.ObjCNonFragileABI ? 2 : 1; // Create new compile unit. - llvm::DICompileUnit Unit = DebugFactory.CreateCompileUnit( - LangTag, AbsFileName.getLast(), AbsFileName.getDirname(), Producer, isMain, + TheCU = DebugFactory.CreateCompileUnit( + LangTag, AbsFileName.getLast(), AbsFileName.getDirname(), Producer, true, LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers); - - if (Loc.isValid()) { - PresumedLoc PLoc = SM.getPresumedLoc(Loc); - unsigned FID = PLoc.getIncludeLoc().getRawEncoding(); - CompileUnitCache[FID] = Unit; - } - return Unit; } /// CreateType - Get the Basic type from the cache or create a new /// one if necessary. llvm::DIType CGDebugInfo::CreateType(const BuiltinType *BT, - llvm::DICompileUnit Unit) { + llvm::DIFile Unit) { unsigned Encoding = 0; switch (BT->getKind()) { default: @@ -201,7 +179,7 @@ llvm::DIType CGDebugInfo::CreateType(const BuiltinType *BT, } llvm::DIType CGDebugInfo::CreateType(const ComplexType *Ty, - llvm::DICompileUnit Unit) { + llvm::DIFile Unit) { // Bit size, align and offset of the type. unsigned Encoding = llvm::dwarf::DW_ATE_complex_float; if (Ty->isComplexIntegerType()) @@ -220,7 +198,7 @@ llvm::DIType CGDebugInfo::CreateType(const ComplexType *Ty, /// CreateCVRType - Get the qualified type from the cache or create /// a new one if necessary. -llvm::DIType CGDebugInfo::CreateQualifiedType(QualType Ty, llvm::DICompileUnit Unit) { +llvm::DIType CGDebugInfo::CreateQualifiedType(QualType Ty, llvm::DIFile Unit) { QualifierCollector Qc; const Type *T = Qc.strip(Ty); @@ -250,13 +228,13 @@ llvm::DIType CGDebugInfo::CreateQualifiedType(QualType Ty, llvm::DICompileUnit U // No need to fill in the Name, Line, Size, Alignment, Offset in case of // CVR derived types. llvm::DIType DbgTy = - DebugFactory.CreateDerivedType(Tag, Unit, "", llvm::DICompileUnit(), + DebugFactory.CreateDerivedType(Tag, Unit, "", Unit, 0, 0, 0, 0, 0, FromTy); return DbgTy; } llvm::DIType CGDebugInfo::CreateType(const ObjCObjectPointerType *Ty, - llvm::DICompileUnit Unit) { + llvm::DIFile Unit) { llvm::DIType DbgTy = CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty, Ty->getPointeeType(), Unit); @@ -264,7 +242,7 @@ llvm::DIType CGDebugInfo::CreateType(const ObjCObjectPointerType *Ty, } llvm::DIType CGDebugInfo::CreateType(const PointerType *Ty, - llvm::DICompileUnit Unit) { + llvm::DIFile Unit) { return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty, Ty->getPointeeType(), Unit); } @@ -272,7 +250,7 @@ llvm::DIType CGDebugInfo::CreateType(const PointerType *Ty, llvm::DIType CGDebugInfo::CreatePointerLikeType(unsigned Tag, const Type *Ty, QualType PointeeTy, - llvm::DICompileUnit Unit) { + llvm::DIFile Unit) { llvm::DIType EltTy = getOrCreateType(PointeeTy, Unit); // Bit size, align and offset of the type. @@ -284,17 +262,16 @@ llvm::DIType CGDebugInfo::CreatePointerLikeType(unsigned Tag, uint64_t Align = CGM.getContext().getTypeAlign(Ty); return - DebugFactory.CreateDerivedType(Tag, Unit, "", llvm::DICompileUnit(), + DebugFactory.CreateDerivedType(Tag, Unit, "", Unit, 0, Size, Align, 0, 0, EltTy); } llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty, - llvm::DICompileUnit Unit) { + llvm::DIFile Unit) { if (BlockLiteralGenericSet) return BlockLiteralGeneric; - llvm::DICompileUnit DefUnit; unsigned Tag = llvm::dwarf::DW_TAG_structure_type; llvm::SmallVector EltTys; @@ -314,7 +291,7 @@ llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty, FieldSize = CGM.getContext().getTypeSize(FType); FieldAlign = CGM.getContext().getTypeAlign(FType); FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, - "reserved", DefUnit, + "reserved", Unit, 0, FieldSize, FieldAlign, FieldOffset, 0, FieldTy); EltTys.push_back(FieldTy); @@ -325,7 +302,7 @@ llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty, FieldSize = CGM.getContext().getTypeSize(FType); FieldAlign = CGM.getContext().getTypeAlign(FType); FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, - "Size", DefUnit, + "Size", Unit, 0, FieldSize, FieldAlign, FieldOffset, 0, FieldTy); EltTys.push_back(FieldTy); @@ -337,7 +314,7 @@ llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty, unsigned Flags = llvm::DIType::FlagAppleBlock; EltTy = DebugFactory.CreateCompositeType(Tag, Unit, "__block_descriptor", - DefUnit, 0, FieldOffset, 0, 0, Flags, + Unit, 0, FieldOffset, 0, 0, Flags, llvm::DIType(), Elements); // Bit size, align and offset of the type. @@ -345,7 +322,7 @@ llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty, uint64_t Align = CGM.getContext().getTypeAlign(Ty); DescTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, - Unit, "", llvm::DICompileUnit(), + Unit, "", Unit, 0, Size, Align, 0, 0, EltTy); FieldOffset = 0; @@ -354,7 +331,7 @@ llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty, FieldSize = CGM.getContext().getTypeSize(FType); FieldAlign = CGM.getContext().getTypeAlign(FType); FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, - "__isa", DefUnit, + "__isa", Unit, 0, FieldSize, FieldAlign, FieldOffset, 0, FieldTy); EltTys.push_back(FieldTy); @@ -365,7 +342,7 @@ llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty, FieldSize = CGM.getContext().getTypeSize(FType); FieldAlign = CGM.getContext().getTypeAlign(FType); FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, - "__flags", DefUnit, + "__flags", Unit, 0, FieldSize, FieldAlign, FieldOffset, 0, FieldTy); EltTys.push_back(FieldTy); @@ -376,7 +353,7 @@ llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty, FieldSize = CGM.getContext().getTypeSize(FType); FieldAlign = CGM.getContext().getTypeAlign(FType); FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, - "__reserved", DefUnit, + "__reserved", Unit, 0, FieldSize, FieldAlign, FieldOffset, 0, FieldTy); EltTys.push_back(FieldTy); @@ -387,7 +364,7 @@ llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty, FieldSize = CGM.getContext().getTypeSize(FType); FieldAlign = CGM.getContext().getTypeAlign(FType); FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, - "__FuncPtr", DefUnit, + "__FuncPtr", Unit, 0, FieldSize, FieldAlign, FieldOffset, 0, FieldTy); EltTys.push_back(FieldTy); @@ -398,7 +375,7 @@ llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty, FieldSize = CGM.getContext().getTypeSize(Ty); FieldAlign = CGM.getContext().getTypeAlign(Ty); FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, - "__descriptor", DefUnit, + "__descriptor", Unit, 0, FieldSize, FieldAlign, FieldOffset, 0, FieldTy); EltTys.push_back(FieldTy); @@ -407,19 +384,19 @@ llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty, Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); EltTy = DebugFactory.CreateCompositeType(Tag, Unit, "__block_literal_generic", - DefUnit, 0, FieldOffset, 0, 0, Flags, + Unit, 0, FieldOffset, 0, 0, Flags, llvm::DIType(), Elements); BlockLiteralGenericSet = true; BlockLiteralGeneric = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, Unit, - "", llvm::DICompileUnit(), + "", Unit, 0, Size, Align, 0, 0, EltTy); return BlockLiteralGeneric; } llvm::DIType CGDebugInfo::CreateType(const TypedefType *Ty, - llvm::DICompileUnit Unit) { + llvm::DIFile Unit) { // Typedefs are derived from some other type. If we have a typedef of a // typedef, make sure to emit the whole chain. llvm::DIType Src = getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit); @@ -442,7 +419,7 @@ llvm::DIType CGDebugInfo::CreateType(const TypedefType *Ty, } llvm::DIType CGDebugInfo::CreateType(const FunctionType *Ty, - llvm::DICompileUnit Unit) { + llvm::DIFile Unit) { llvm::SmallVector EltTys; // Add the result type at least. @@ -462,7 +439,7 @@ llvm::DIType CGDebugInfo::CreateType(const FunctionType *Ty, llvm::DIType DbgTy = DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type, - Unit, "", llvm::DICompileUnit(), + Unit, "", Unit, 0, 0, 0, 0, 0, llvm::DIType(), EltTypeArray); return DbgTy; @@ -471,7 +448,7 @@ llvm::DIType CGDebugInfo::CreateType(const FunctionType *Ty, /// CollectRecordFields - A helper function to collect debug info for /// record fields. This is used while creating debug info entry for a Record. void CGDebugInfo:: -CollectRecordFields(const RecordDecl *RD, llvm::DICompileUnit Unit, +CollectRecordFields(const RecordDecl *RD, llvm::DIFile Unit, llvm::SmallVectorImpl &EltTys) { unsigned FieldNo = 0; SourceManager &SM = CGM.getContext().getSourceManager(); @@ -491,11 +468,11 @@ CollectRecordFields(const RecordDecl *RD, llvm::DICompileUnit Unit, // Get the location for the field. SourceLocation FieldDefLoc = Field->getLocation(); PresumedLoc PLoc = SM.getPresumedLoc(FieldDefLoc); - llvm::DICompileUnit FieldDefUnit; + llvm::DIFile FieldDefUnit; unsigned FieldLine = 0; if (!PLoc.isInvalid()) { - FieldDefUnit = getOrCreateCompileUnit(FieldDefLoc); + FieldDefUnit = getOrCreateFile(FieldDefLoc); FieldLine = PLoc.getLine(); } @@ -531,7 +508,7 @@ CollectRecordFields(const RecordDecl *RD, llvm::DICompileUnit Unit, /// routine to get a method type which includes "this" pointer. llvm::DIType CGDebugInfo::getOrCreateMethodType(const CXXMethodDecl *Method, - llvm::DICompileUnit Unit) { + llvm::DIFile Unit) { llvm::DIType FnTy = getOrCreateType(Method->getType(), Unit); // Static methods do not need "this" pointer argument. @@ -566,7 +543,7 @@ CGDebugInfo::getOrCreateMethodType(const CXXMethodDecl *Method, return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type, - Unit, "", llvm::DICompileUnit(), + Unit, "", Unit, 0, 0, 0, 0, 0, llvm::DIType(), EltTypeArray); } @@ -575,7 +552,7 @@ CGDebugInfo::getOrCreateMethodType(const CXXMethodDecl *Method, /// a single member function GlobalDecl. llvm::DISubprogram CGDebugInfo::CreateCXXMemberFunction(const CXXMethodDecl *Method, - llvm::DICompileUnit Unit, + llvm::DIFile Unit, llvm::DICompositeType &RecordTy) { bool IsCtorOrDtor = isa(Method) || isa(Method); @@ -594,11 +571,11 @@ CGDebugInfo::CreateCXXMemberFunction(const CXXMethodDecl *Method, // Get the location for the method. SourceLocation MethodDefLoc = Method->getLocation(); PresumedLoc PLoc = SM.getPresumedLoc(MethodDefLoc); - llvm::DICompileUnit MethodDefUnit; + llvm::DIFile MethodDefUnit; unsigned MethodLine = 0; if (!PLoc.isInvalid()) { - MethodDefUnit = getOrCreateCompileUnit(MethodDefLoc); + MethodDefUnit = getOrCreateFile(MethodDefLoc); MethodLine = PLoc.getLine(); } @@ -640,7 +617,7 @@ CGDebugInfo::CreateCXXMemberFunction(const CXXMethodDecl *Method, /// C++ member functions.This is used while creating debug info entry for /// a Record. void CGDebugInfo:: -CollectCXXMemberFunctions(const CXXRecordDecl *RD, llvm::DICompileUnit Unit, +CollectCXXMemberFunctions(const CXXRecordDecl *RD, llvm::DIFile Unit, llvm::SmallVectorImpl &EltTys, llvm::DICompositeType &RecordTy) { for(CXXRecordDecl::method_iterator I = RD->method_begin(), @@ -658,7 +635,7 @@ CollectCXXMemberFunctions(const CXXRecordDecl *RD, llvm::DICompileUnit Unit, /// C++ base classes. This is used while creating debug info entry for /// a Record. void CGDebugInfo:: -CollectCXXBases(const CXXRecordDecl *RD, llvm::DICompileUnit Unit, +CollectCXXBases(const CXXRecordDecl *RD, llvm::DIFile Unit, llvm::SmallVectorImpl &EltTys, llvm::DICompositeType &RecordTy) { @@ -688,7 +665,7 @@ CollectCXXBases(const CXXRecordDecl *RD, llvm::DICompileUnit Unit, llvm::DIType DTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_inheritance, RecordTy, llvm::StringRef(), - llvm::DICompileUnit(), 0, 0, 0, + Unit, 0, 0, 0, BaseOffset, BFlags, getOrCreateType(BI->getType(), Unit)); @@ -697,8 +674,8 @@ CollectCXXBases(const CXXRecordDecl *RD, llvm::DICompileUnit Unit, } /// getOrCreateVTablePtrType - Return debug info descriptor for vtable. -llvm::DIType CGDebugInfo::getOrCreateVTablePtrType(llvm::DICompileUnit Unit) { - if (!VTablePtrType.isNull()) +llvm::DIType CGDebugInfo::getOrCreateVTablePtrType(llvm::DIFile Unit) { + if (VTablePtrType.isValid()) return VTablePtrType; ASTContext &Context = CGM.getContext(); @@ -710,18 +687,19 @@ llvm::DIType CGDebugInfo::getOrCreateVTablePtrType(llvm::DICompileUnit Unit) { DebugFactory.GetOrCreateArray(STys.data(), STys.size()); llvm::DIType SubTy = DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type, - Unit, "", llvm::DICompileUnit(), + Unit, "", Unit, 0, 0, 0, 0, 0, llvm::DIType(), SElements); unsigned Size = Context.getTypeSize(Context.VoidPtrTy); llvm::DIType vtbl_ptr_type = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, - Unit, "__vtbl_ptr_type", llvm::DICompileUnit(), + Unit, "__vtbl_ptr_type", Unit, 0, Size, 0, 0, 0, SubTy); - VTablePtrType = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, - Unit, "", llvm::DICompileUnit(), - 0, Size, 0, 0, 0, vtbl_ptr_type); + VTablePtrType = + DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, + Unit, "", Unit, + 0, Size, 0, 0, 0, vtbl_ptr_type); return VTablePtrType; } @@ -740,7 +718,7 @@ llvm::StringRef CGDebugInfo::getVtableName(const CXXRecordDecl *RD) { /// CollectVtableInfo - If the C++ class has vtable info then insert appropriate /// debug info entry in EltTys vector. void CGDebugInfo:: -CollectVtableInfo(const CXXRecordDecl *RD, llvm::DICompileUnit Unit, +CollectVtableInfo(const CXXRecordDecl *RD, llvm::DIFile Unit, llvm::SmallVectorImpl &EltTys) { const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); @@ -755,7 +733,7 @@ CollectVtableInfo(const CXXRecordDecl *RD, llvm::DICompileUnit Unit, unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy); llvm::DIType VPTR = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, - getVtableName(RD), llvm::DICompileUnit(), + getVtableName(RD), Unit, 0, Size, 0, 0, 0, getOrCreateVTablePtrType(Unit)); EltTys.push_back(VPTR); @@ -763,7 +741,7 @@ CollectVtableInfo(const CXXRecordDecl *RD, llvm::DICompileUnit Unit, /// CreateType - get structure or union type. llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty, - llvm::DICompileUnit Unit) { + llvm::DIFile Unit) { RecordDecl *RD = Ty->getDecl(); unsigned Tag; @@ -780,10 +758,10 @@ llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty, // Get overall information about the record type for the debug info. PresumedLoc PLoc = SM.getPresumedLoc(RD->getLocation()); - llvm::DICompileUnit DefUnit; + llvm::DIFile DefUnit; unsigned Line = 0; if (!PLoc.isInvalid()) { - DefUnit = getOrCreateCompileUnit(RD->getLocation()); + DefUnit = getOrCreateFile(RD->getLocation()); Line = PLoc.getLine(); } @@ -796,12 +774,13 @@ llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty, // A RD->getName() is not unique. However, the debug info descriptors // are uniqued so use type name to ensure uniquness. - std::string STy = QualType(Ty, 0).getAsString(); + llvm::SmallString<256> FwdDeclName; + FwdDeclName.resize(256); + sprintf(&FwdDeclName[0], "fwd.type.%d", FwdDeclCount++); llvm::DIDescriptor FDContext = getContextDescriptor(dyn_cast(RD->getDeclContext()), Unit); llvm::DICompositeType FwdDecl = - DebugFactory.CreateCompositeType(Tag, FDContext, - STy.c_str(), + DebugFactory.CreateCompositeType(Tag, FDContext, FwdDeclName, DefUnit, Line, 0, 0, 0, 0, llvm::DIType(), llvm::DIArray()); @@ -861,19 +840,19 @@ llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty, /// CreateType - get objective-c interface type. llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty, - llvm::DICompileUnit Unit) { + llvm::DIFile Unit) { ObjCInterfaceDecl *ID = Ty->getDecl(); unsigned Tag = llvm::dwarf::DW_TAG_structure_type; SourceManager &SM = CGM.getContext().getSourceManager(); // Get overall information about the record type for the debug info. - llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(ID->getLocation()); + llvm::DIFile DefUnit = getOrCreateFile(ID->getLocation()); PresumedLoc PLoc = SM.getPresumedLoc(ID->getLocation()); unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine(); - unsigned RuntimeLang = DefUnit.getLanguage(); + unsigned RuntimeLang = TheCU.getLanguage(); // To handle recursive interface, we // first generate a debug descriptor for the struct as a forward declaration. @@ -905,7 +884,7 @@ llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty, getOrCreateType(CGM.getContext().getObjCInterfaceType(SClass), Unit); llvm::DIType InhTag = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_inheritance, - Unit, "", llvm::DICompileUnit(), 0, 0, 0, + Unit, "", Unit, 0, 0, 0, 0 /* offset */, 0, SClassTy); EltTys.push_back(InhTag); } @@ -926,7 +905,7 @@ llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty, // Get the location for the field. SourceLocation FieldDefLoc = Field->getLocation(); - llvm::DICompileUnit FieldDefUnit = getOrCreateCompileUnit(FieldDefLoc); + llvm::DIFile FieldDefUnit = getOrCreateFile(FieldDefLoc); PresumedLoc PLoc = SM.getPresumedLoc(FieldDefLoc); unsigned FieldLine = PLoc.isInvalid() ? 0 : PLoc.getLine(); @@ -984,7 +963,7 @@ llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty, } llvm::DIType CGDebugInfo::CreateType(const EnumType *Ty, - llvm::DICompileUnit Unit) { + llvm::DIFile Unit) { EnumDecl *ED = Ty->getDecl(); llvm::SmallVector Enumerators; @@ -1002,7 +981,7 @@ llvm::DIType CGDebugInfo::CreateType(const EnumType *Ty, DebugFactory.GetOrCreateArray(Enumerators.data(), Enumerators.size()); SourceLocation DefLoc = ED->getLocation(); - llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(DefLoc); + llvm::DIFile DefUnit = getOrCreateFile(DefLoc); SourceManager &SM = CGM.getContext().getSourceManager(); PresumedLoc PLoc = SM.getPresumedLoc(DefLoc); unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine(); @@ -1025,7 +1004,7 @@ llvm::DIType CGDebugInfo::CreateType(const EnumType *Ty, } llvm::DIType CGDebugInfo::CreateType(const TagType *Ty, - llvm::DICompileUnit Unit) { + llvm::DIFile Unit) { if (const RecordType *RT = dyn_cast(Ty)) return CreateType(RT, Unit); else if (const EnumType *ET = dyn_cast(Ty)) @@ -1035,7 +1014,7 @@ llvm::DIType CGDebugInfo::CreateType(const TagType *Ty, } llvm::DIType CGDebugInfo::CreateType(const VectorType *Ty, - llvm::DICompileUnit Unit) { + llvm::DIFile Unit) { llvm::DIType ElementTy = getOrCreateType(Ty->getElementType(), Unit); uint64_t NumElems = Ty->getNumElements(); if (NumElems > 0) @@ -1051,13 +1030,13 @@ llvm::DIType CGDebugInfo::CreateType(const VectorType *Ty, return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_vector_type, - Unit, "", llvm::DICompileUnit(), + Unit, "", Unit, 0, Size, Align, 0, 0, ElementTy, SubscriptArray); } llvm::DIType CGDebugInfo::CreateType(const ArrayType *Ty, - llvm::DICompileUnit Unit) { + llvm::DIFile Unit) { uint64_t Size; uint64_t Align; @@ -1096,7 +1075,7 @@ llvm::DIType CGDebugInfo::CreateType(const ArrayType *Ty, llvm::DIType DbgTy = DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_array_type, - Unit, "", llvm::DICompileUnit(), + Unit, "", Unit, 0, Size, Align, 0, 0, getOrCreateType(EltTy, Unit), SubscriptArray); @@ -1104,13 +1083,13 @@ llvm::DIType CGDebugInfo::CreateType(const ArrayType *Ty, } llvm::DIType CGDebugInfo::CreateType(const LValueReferenceType *Ty, - llvm::DICompileUnit Unit) { + llvm::DIFile Unit) { return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type, Ty, Ty->getPointeeType(), Unit); } llvm::DIType CGDebugInfo::CreateType(const MemberPointerType *Ty, - llvm::DICompileUnit U) { + llvm::DIFile U) { QualType PointerDiffTy = CGM.getContext().getPointerDiffType(); llvm::DIType PointerDiffDITy = getOrCreateType(PointerDiffTy, U); @@ -1129,14 +1108,14 @@ llvm::DIType CGDebugInfo::CreateType(const MemberPointerType *Ty, // FIXME: This should probably be a function type instead. ElementTypes[0] = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, U, - "ptr", llvm::DICompileUnit(), 0, + "ptr", U, 0, Info.first, Info.second, FieldOffset, 0, PointerDiffDITy); FieldOffset += Info.first; ElementTypes[1] = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, U, - "ptr", llvm::DICompileUnit(), 0, + "ptr", U, 0, Info.first, Info.second, FieldOffset, 0, PointerDiffDITy); @@ -1146,7 +1125,7 @@ llvm::DIType CGDebugInfo::CreateType(const MemberPointerType *Ty, return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_structure_type, U, llvm::StringRef("test"), - llvm::DICompileUnit(), 0, FieldOffset, + U, 0, FieldOffset, 0, 0, 0, llvm::DIType(), Elements); } @@ -1192,7 +1171,7 @@ static QualType UnwrapTypeForDebugInfo(QualType T) { /// getOrCreateType - Get the type from the cache or create a new /// one if necessary. llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty, - llvm::DICompileUnit Unit) { + llvm::DIFile Unit) { if (Ty.isNull()) return llvm::DIType(); @@ -1218,7 +1197,7 @@ llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty, /// CreateTypeNode - Create a new debug type node. llvm::DIType CGDebugInfo::CreateTypeNode(QualType Ty, - llvm::DICompileUnit Unit) { + llvm::DIFile Unit) { // Handle qualifiers, which recursively handles what they refer to. if (Ty.hasLocalQualifiers()) return CreateQualifiedType(Ty, Unit); @@ -1267,6 +1246,7 @@ llvm::DIType CGDebugInfo::CreateTypeNode(QualType Ty, case Type::MemberPointer: return CreateType(cast(Ty), Unit); + case Type::InjectedClassName: case Type::TemplateSpecialization: case Type::Elaborated: case Type::QualifiedName: @@ -1306,8 +1286,8 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType, llvm::DenseMap::iterator FI = SPCache.find(FD); if (FI != SPCache.end()) { - llvm::DISubprogram SP(dyn_cast_or_null(FI->second)); - if (!SP.isNull() && SP.isSubprogram() && SP.isDefinition()) { + llvm::DIDescriptor SP(dyn_cast_or_null(FI->second)); + if (SP.isSubprogram() && llvm::DISubprogram(SP.getNode()).isDefinition()) { RegionStack.push_back(SP.getNode()); RegionMap[D] = llvm::WeakVH(SP.getNode()); return; @@ -1329,7 +1309,7 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType, // It is expected that CurLoc is set before using EmitFunctionStart. // Usually, CurLoc points to the left bracket location of compound // statement representing function body. - llvm::DICompileUnit Unit = getOrCreateCompileUnit(CurLoc); + llvm::DIFile Unit = getOrCreateFile(CurLoc); SourceManager &SM = CGM.getContext().getSourceManager(); unsigned LineNo = SM.getPresumedLoc(CurLoc).getLine(); @@ -1359,7 +1339,7 @@ void CGDebugInfo::EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder) { PrevLoc = CurLoc; // Get the appropriate compile unit. - llvm::DICompileUnit Unit = getOrCreateCompileUnit(CurLoc); + llvm::DIFile Unit = getOrCreateFile(CurLoc); PresumedLoc PLoc = SM.getPresumedLoc(CurLoc); llvm::DIDescriptor DR(RegionStack.back()); @@ -1406,7 +1386,7 @@ llvm::DIType CGDebugInfo::EmitTypeForVarWithBlocksAttr(const ValueDecl *VD, uint64_t FieldSize, FieldOffset; unsigned FieldAlign; - llvm::DICompileUnit Unit = getOrCreateCompileUnit(VD->getLocation()); + llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); QualType Type = VD->getType(); FieldOffset = 0; @@ -1415,7 +1395,7 @@ llvm::DIType CGDebugInfo::EmitTypeForVarWithBlocksAttr(const ValueDecl *VD, FieldSize = CGM.getContext().getTypeSize(FType); FieldAlign = CGM.getContext().getTypeAlign(FType); FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, - "__isa", llvm::DICompileUnit(), + "__isa", Unit, 0, FieldSize, FieldAlign, FieldOffset, 0, FieldTy); EltTys.push_back(FieldTy); @@ -1426,7 +1406,7 @@ llvm::DIType CGDebugInfo::EmitTypeForVarWithBlocksAttr(const ValueDecl *VD, FieldSize = CGM.getContext().getTypeSize(FType); FieldAlign = CGM.getContext().getTypeAlign(FType); FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, - "__forwarding", llvm::DICompileUnit(), + "__forwarding", Unit, 0, FieldSize, FieldAlign, FieldOffset, 0, FieldTy); EltTys.push_back(FieldTy); @@ -1437,7 +1417,7 @@ llvm::DIType CGDebugInfo::EmitTypeForVarWithBlocksAttr(const ValueDecl *VD, FieldSize = CGM.getContext().getTypeSize(FType); FieldAlign = CGM.getContext().getTypeAlign(FType); FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, - "__flags", llvm::DICompileUnit(), + "__flags", Unit, 0, FieldSize, FieldAlign, FieldOffset, 0, FieldTy); EltTys.push_back(FieldTy); @@ -1448,7 +1428,7 @@ llvm::DIType CGDebugInfo::EmitTypeForVarWithBlocksAttr(const ValueDecl *VD, FieldSize = CGM.getContext().getTypeSize(FType); FieldAlign = CGM.getContext().getTypeAlign(FType); FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, - "__size", llvm::DICompileUnit(), + "__size", Unit, 0, FieldSize, FieldAlign, FieldOffset, 0, FieldTy); EltTys.push_back(FieldTy); @@ -1461,8 +1441,7 @@ llvm::DIType CGDebugInfo::EmitTypeForVarWithBlocksAttr(const ValueDecl *VD, FieldSize = CGM.getContext().getTypeSize(FType); FieldAlign = CGM.getContext().getTypeAlign(FType); FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, - "__copy_helper", - llvm::DICompileUnit(), + "__copy_helper", Unit, 0, FieldSize, FieldAlign, FieldOffset, 0, FieldTy); EltTys.push_back(FieldTy); @@ -1473,8 +1452,7 @@ llvm::DIType CGDebugInfo::EmitTypeForVarWithBlocksAttr(const ValueDecl *VD, FieldSize = CGM.getContext().getTypeSize(FType); FieldAlign = CGM.getContext().getTypeAlign(FType); FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, - "__destroy_helper", - llvm::DICompileUnit(), + "__destroy_helper", Unit, 0, FieldSize, FieldAlign, FieldOffset, 0, FieldTy); EltTys.push_back(FieldTy); @@ -1497,7 +1475,7 @@ llvm::DIType CGDebugInfo::EmitTypeForVarWithBlocksAttr(const ValueDecl *VD, FieldSize = CGM.getContext().getTypeSize(FType); FieldAlign = CGM.getContext().getTypeAlign(FType); FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, - Unit, "", llvm::DICompileUnit(), + Unit, "", Unit, 0, FieldSize, FieldAlign, FieldOffset, 0, FieldTy); EltTys.push_back(FieldTy); @@ -1512,7 +1490,7 @@ llvm::DIType CGDebugInfo::EmitTypeForVarWithBlocksAttr(const ValueDecl *VD, *XOffset = FieldOffset; FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, - VD->getName(), llvm::DICompileUnit(), + VD->getName(), Unit, 0, FieldSize, FieldAlign, FieldOffset, 0, FieldTy); EltTys.push_back(FieldTy); @@ -1524,8 +1502,7 @@ llvm::DIType CGDebugInfo::EmitTypeForVarWithBlocksAttr(const ValueDecl *VD, unsigned Flags = llvm::DIType::FlagBlockByrefStruct; return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_structure_type, - Unit, "", - llvm::DICompileUnit(), + Unit, "", Unit, 0, FieldOffset, 0, 0, Flags, llvm::DIType(), Elements); @@ -1542,7 +1519,7 @@ void CGDebugInfo::EmitDeclare(const VarDecl *VD, unsigned Tag, if (CGO.OptimizationLevel) return; - llvm::DICompileUnit Unit = getOrCreateCompileUnit(VD->getLocation()); + llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); llvm::DIType Ty; uint64_t XOffset = 0; if (VD->hasAttr()) @@ -1560,9 +1537,9 @@ void CGDebugInfo::EmitDeclare(const VarDecl *VD, unsigned Tag, if (PLoc.isValid()) { Line = PLoc.getLine(); Column = PLoc.getColumn(); - Unit = getOrCreateCompileUnit(CurLoc); + Unit = getOrCreateFile(CurLoc); } else { - Unit = llvm::DICompileUnit(); + Unit = llvm::DIFile(); } // Create the descriptor for the variable. @@ -1596,7 +1573,7 @@ void CGDebugInfo::EmitDeclare(const BlockDeclRefExpr *BDRE, unsigned Tag, return; uint64_t XOffset = 0; - llvm::DICompileUnit Unit = getOrCreateCompileUnit(VD->getLocation()); + llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); llvm::DIType Ty; if (VD->hasAttr()) Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset); @@ -1610,7 +1587,7 @@ void CGDebugInfo::EmitDeclare(const BlockDeclRefExpr *BDRE, unsigned Tag, if (!PLoc.isInvalid()) Line = PLoc.getLine(); else - Unit = llvm::DICompileUnit(); + Unit = llvm::DIFile(); CharUnits offset = CGF->BlockDecls[VD]; llvm::SmallVector addr; @@ -1675,7 +1652,7 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, const VarDecl *D) { // Create global variable debug descriptor. - llvm::DICompileUnit Unit = getOrCreateCompileUnit(D->getLocation()); + llvm::DIFile Unit = getOrCreateFile(D->getLocation()); SourceManager &SM = CGM.getContext().getSourceManager(); PresumedLoc PLoc = SM.getPresumedLoc(D->getLocation()); unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine(); @@ -1706,7 +1683,7 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, ObjCInterfaceDecl *ID) { // Create global variable debug descriptor. - llvm::DICompileUnit Unit = getOrCreateCompileUnit(ID->getLocation()); + llvm::DIFile Unit = getOrCreateFile(ID->getLocation()); SourceManager &SM = CGM.getContext().getSourceManager(); PresumedLoc PLoc = SM.getPresumedLoc(ID->getLocation()); unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine(); @@ -1750,7 +1727,7 @@ CGDebugInfo::getOrCreateNameSpace(const NamespaceDecl *NSDecl, getContextDescriptor(dyn_cast(NSDecl->getDeclContext()), Unit); llvm::DINameSpace NS = DebugFactory.CreateNameSpace(Context, NSDecl->getName(), - llvm::DICompileUnit(Unit.getNode()), LineNo); + llvm::DIFile(Unit.getNode()), LineNo); NameSpaceCache[NSDecl] = llvm::WeakVH(NS.getNode()); return NS; } diff --git a/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h index 50f5759..47a4620 100644 --- a/lib/CodeGen/CGDebugInfo.h +++ b/lib/CodeGen/CGDebugInfo.h @@ -43,16 +43,14 @@ namespace CodeGen { /// the backend. class CGDebugInfo { CodeGenModule &CGM; - bool isMainCompileUnitCreated; llvm::DIFactory DebugFactory; - + llvm::DICompileUnit TheCU; SourceLocation CurLoc, PrevLoc; - llvm::DIType VTablePtrType; - - /// CompileUnitCache - Cache of previously constructed CompileUnits. - llvm::DenseMap CompileUnitCache; - + /// FwdDeclCount - This counter is used to ensure unique names for forward + /// record decls. + unsigned FwdDeclCount; + /// TypeCache - Cache of previously constructed Types. // FIXME: Eliminate this map. Be careful of iterator invalidation. std::map TypeCache; @@ -71,52 +69,52 @@ class CGDebugInfo { llvm::DenseMap NameSpaceCache; /// Helper functions for getOrCreateType. - llvm::DIType CreateType(const BuiltinType *Ty, llvm::DICompileUnit U); - llvm::DIType CreateType(const ComplexType *Ty, llvm::DICompileUnit U); - llvm::DIType CreateQualifiedType(QualType Ty, llvm::DICompileUnit U); - llvm::DIType CreateType(const TypedefType *Ty, llvm::DICompileUnit U); + llvm::DIType CreateType(const BuiltinType *Ty, llvm::DIFile F); + llvm::DIType CreateType(const ComplexType *Ty, llvm::DIFile F); + llvm::DIType CreateQualifiedType(QualType Ty, llvm::DIFile F); + llvm::DIType CreateType(const TypedefType *Ty, llvm::DIFile F); llvm::DIType CreateType(const ObjCObjectPointerType *Ty, - llvm::DICompileUnit Unit); - llvm::DIType CreateType(const PointerType *Ty, llvm::DICompileUnit U); - llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DICompileUnit U); - llvm::DIType CreateType(const FunctionType *Ty, llvm::DICompileUnit U); - llvm::DIType CreateType(const TagType *Ty, llvm::DICompileUnit U); - llvm::DIType CreateType(const RecordType *Ty, llvm::DICompileUnit U); - llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DICompileUnit U); - llvm::DIType CreateType(const EnumType *Ty, llvm::DICompileUnit U); - llvm::DIType CreateType(const VectorType *Ty, llvm::DICompileUnit Unit); - llvm::DIType CreateType(const ArrayType *Ty, llvm::DICompileUnit U); - llvm::DIType CreateType(const LValueReferenceType *Ty, llvm::DICompileUnit U); - llvm::DIType CreateType(const MemberPointerType *Ty, llvm::DICompileUnit U); + llvm::DIFile F); + llvm::DIType CreateType(const PointerType *Ty, llvm::DIFile F); + llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DIFile F); + llvm::DIType CreateType(const FunctionType *Ty, llvm::DIFile F); + llvm::DIType CreateType(const TagType *Ty, llvm::DIFile F); + llvm::DIType CreateType(const RecordType *Ty, llvm::DIFile F); + llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DIFile F); + llvm::DIType CreateType(const EnumType *Ty, llvm::DIFile F); + llvm::DIType CreateType(const VectorType *Ty, llvm::DIFile F); + llvm::DIType CreateType(const ArrayType *Ty, llvm::DIFile F); + llvm::DIType CreateType(const LValueReferenceType *Ty, llvm::DIFile F); + llvm::DIType CreateType(const MemberPointerType *Ty, llvm::DIFile F); llvm::DIType getOrCreateMethodType(const CXXMethodDecl *Method, - llvm::DICompileUnit Unit); - llvm::DIType getOrCreateVTablePtrType(llvm::DICompileUnit Unit); + llvm::DIFile F); + llvm::DIType getOrCreateVTablePtrType(llvm::DIFile F); llvm::DINameSpace getOrCreateNameSpace(const NamespaceDecl *N, llvm::DIDescriptor Unit); llvm::DIType CreatePointerLikeType(unsigned Tag, const Type *Ty, QualType PointeeTy, - llvm::DICompileUnit U); + llvm::DIFile F); llvm::DISubprogram CreateCXXMemberFunction(const CXXMethodDecl *Method, - llvm::DICompileUnit Unit, + llvm::DIFile F, llvm::DICompositeType &RecordTy); void CollectCXXMemberFunctions(const CXXRecordDecl *Decl, - llvm::DICompileUnit U, + llvm::DIFile F, llvm::SmallVectorImpl &E, llvm::DICompositeType &T); void CollectCXXBases(const CXXRecordDecl *Decl, - llvm::DICompileUnit Unit, + llvm::DIFile F, llvm::SmallVectorImpl &EltTys, llvm::DICompositeType &RecordTy); - void CollectRecordFields(const RecordDecl *Decl, llvm::DICompileUnit U, + void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile F, llvm::SmallVectorImpl &E); void CollectVtableInfo(const CXXRecordDecl *Decl, - llvm::DICompileUnit Unit, + llvm::DIFile F, llvm::SmallVectorImpl &EltTys); public: @@ -185,16 +183,19 @@ private: llvm::DIDescriptor getContextDescriptor(const Decl *Decl, llvm::DIDescriptor &CU); - /// getOrCreateCompileUnit - Get the compile unit from the cache or create a - /// new one if necessary. - llvm::DICompileUnit getOrCreateCompileUnit(SourceLocation Loc); + /// CreateCompileUnit - Create new compile unit. + void CreateCompileUnit(); + + /// getOrCreateFile - Get the file debug info descriptor for the input + /// location. + llvm::DIFile getOrCreateFile(SourceLocation Loc); /// getOrCreateType - Get the type from the cache or create a new type if /// necessary. - llvm::DIType getOrCreateType(QualType Ty, llvm::DICompileUnit Unit); + llvm::DIType getOrCreateType(QualType Ty, llvm::DIFile F); /// CreateTypeNode - Create type metadata for a source language type. - llvm::DIType CreateTypeNode(QualType Ty, llvm::DICompileUnit Unit); + llvm::DIType CreateTypeNode(QualType Ty, llvm::DIFile F); /// getFunctionName - Get function name for the given FunctionDecl. If the /// name is constructred on demand (e.g. C++ destructor) then the name diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index ac189a0..4847ca3 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -178,6 +178,11 @@ void AggExprEmitter::EmitFinalDestCopy(const Expr *E, LValue Src, bool Ignore) { //===----------------------------------------------------------------------===// void AggExprEmitter::VisitCastExpr(CastExpr *E) { + if (!DestPtr) { + Visit(E->getSubExpr()); + return; + } + switch (E->getCastKind()) { default: assert(0 && "Unhandled cast kind!"); @@ -205,6 +210,11 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) { break; case CastExpr::CK_NullToMemberPointer: { + // If the subexpression's type is the C++0x nullptr_t, emit the + // subexpression, which may have side effects. + if (E->getSubExpr()->getType()->isNullPtrType()) + Visit(E->getSubExpr()); + const llvm::Type *PtrDiffTy = CGF.ConvertType(CGF.getContext().getPointerDiffType()); @@ -652,6 +662,16 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { return; } + + // If we're initializing the whole aggregate, just do it in place. + // FIXME: This is a hack around an AST bug (PR6537). + if (NumInitElements == 1 && E->getType() == E->getInit(0)->getType()) { + EmitInitializationToLValue(E->getInit(0), + LValue::MakeAddr(DestPtr, Qualifiers()), + E->getType()); + return; + } + // Here we iterate over the fields; this makes it simpler to both // default-initialize fields and skip over unnamed fields. @@ -670,8 +690,8 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { // We never generate write-barries for initialized fields. LValue::SetObjCNonGC(FieldLoc, true); if (CurInitVal < NumInitElements) { - // Store the initializer into the field - EmitInitializationToLValue(E->getInit(CurInitVal++), FieldLoc, + // Store the initializer into the field. + EmitInitializationToLValue(E->getInit(CurInitVal++), FieldLoc, Field->getType()); } else { // We're out of initalizers; default-initialize to null diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp index b62e6ed..3ff77f0 100644 --- a/lib/CodeGen/CGObjC.cpp +++ b/lib/CodeGen/CGObjC.cpp @@ -59,7 +59,7 @@ RValue CodeGenFunction::EmitObjCMessageExpr(const ObjCMessageExpr *E) { // Find the receiver llvm::Value *Receiver; if (!ReceiverExpr) { - const ObjCInterfaceDecl *OID = E->getClassInfo().first; + const ObjCInterfaceDecl *OID = E->getClassInfo().Decl; // Very special case, super send in class method. The receiver is // self (the class object) and the send uses super semantics. diff --git a/lib/CodeGen/CGVtable.cpp b/lib/CodeGen/CGVtable.cpp index 932bd07..4500ec0 100644 --- a/lib/CodeGen/CGVtable.cpp +++ b/lib/CodeGen/CGVtable.cpp @@ -60,10 +60,13 @@ public: /// Method - The method decl of the overrider. const CXXMethodDecl *Method; - /// Offset - the base offset of the overrider relative to the layout class. - int64_t Offset; + /// Offset - the base offset of the overrider in the layout class. + uint64_t Offset; - OverriderInfo() : Method(0), Offset(0) { } + /// OldOffset - FIXME: Remove this. + int64_t OldOffset; + + OverriderInfo() : Method(0), Offset(0), OldOffset(0) { } }; private: @@ -71,6 +74,16 @@ private: /// are stored. const CXXRecordDecl *MostDerivedClass; + /// MostDerivedClassOffset - If we're building final overriders for a + /// construction vtable, this holds the offset from the layout class to the + /// most derived class. + const uint64_t MostDerivedClassOffset; + + /// LayoutClass - The class we're using for layout information. Will be + /// different than the most derived class if the final overriders are for a + /// construction vtable. + const CXXRecordDecl *LayoutClass; + ASTContext &Context; /// MostDerivedClassLayout - the AST record layout of the most derived class. @@ -122,11 +135,13 @@ private: /// subobject (and all its direct and indirect bases). void ComputeFinalOverriders(BaseSubobject Base, bool BaseSubobjectIsVisitedVBase, + uint64_t OffsetInLayoutClass, SubobjectOffsetsMapTy &Offsets); /// AddOverriders - Add the final overriders for this base subobject to the /// map of final overriders. - void AddOverriders(BaseSubobject Base, SubobjectOffsetsMapTy &Offsets); + void AddOverriders(BaseSubobject Base,uint64_t OffsetInLayoutClass, + SubobjectOffsetsMapTy &Offsets); /// PropagateOverrider - Propagate the NewMD overrider to all the functions /// that OldMD overrides. For example, if we have: @@ -139,6 +154,7 @@ private: /// C::f. void PropagateOverrider(const CXXMethodDecl *OldMD, BaseSubobject NewBase, + uint64_t OverriderOffsetInLayoutClass, const CXXMethodDecl *NewMD, SubobjectOffsetsMapTy &Offsets); @@ -146,7 +162,9 @@ private: SubobjectOffsetsMapTy &Offsets); public: - explicit FinalOverriders(const CXXRecordDecl *MostDerivedClass); + FinalOverriders(const CXXRecordDecl *MostDerivedClass, + uint64_t MostDerivedClassOffset, + const CXXRecordDecl *LayoutClass); /// getOverrider - Get the final overrider for the given method declaration in /// the given base subobject. @@ -181,15 +199,19 @@ public: #define DUMP_OVERRIDERS 0 -FinalOverriders::FinalOverriders(const CXXRecordDecl *MostDerivedClass) +FinalOverriders::FinalOverriders(const CXXRecordDecl *MostDerivedClass, + uint64_t MostDerivedClassOffset, + const CXXRecordDecl *LayoutClass) : MostDerivedClass(MostDerivedClass), + MostDerivedClassOffset(MostDerivedClassOffset), LayoutClass(LayoutClass), Context(MostDerivedClass->getASTContext()), MostDerivedClassLayout(Context.getASTRecordLayout(MostDerivedClass)) { // Compute the final overriders. SubobjectOffsetsMapTy Offsets; ComputeFinalOverriders(BaseSubobject(MostDerivedClass, 0), - /*BaseSubobjectIsVisitedVBase=*/false, Offsets); + /*BaseSubobjectIsVisitedVBase=*/false, + MostDerivedClassOffset, Offsets); VisitedVirtualBases.clear(); #if DUMP_OVERRIDERS @@ -199,18 +221,19 @@ FinalOverriders::FinalOverriders(const CXXRecordDecl *MostDerivedClass) // Also dump the base offsets (for now). for (SubobjectOffsetsMapTy::const_iterator I = Offsets.begin(), E = Offsets.end(); I != E; ++I) { - const OffsetVectorTy& OffsetVector = I->second; + const OffsetSetVectorTy& OffsetSetVector = I->second; llvm::errs() << "Base offsets for "; llvm::errs() << I->first->getQualifiedNameAsString() << '\n'; - for (unsigned I = 0, E = OffsetVector.size(); I != E; ++I) - llvm::errs() << " " << I << " - " << OffsetVector[I] << '\n'; + for (unsigned I = 0, E = OffsetSetVector.size(); I != E; ++I) + llvm::errs() << " " << I << " - " << OffsetSetVector[I] / 8 << '\n'; } #endif } void FinalOverriders::AddOverriders(BaseSubobject Base, + uint64_t OffsetInLayoutClass, SubobjectOffsetsMapTy &Offsets) { const CXXRecordDecl *RD = Base.getBase(); @@ -222,13 +245,14 @@ void FinalOverriders::AddOverriders(BaseSubobject Base, continue; // First, propagate the overrider. - PropagateOverrider(MD, Base, MD, Offsets); + PropagateOverrider(MD, Base, OffsetInLayoutClass, MD, Offsets); // Add the overrider as the final overrider of itself. OverriderInfo& Overrider = OverridersMap[std::make_pair(Base, MD)]; assert(!Overrider.Method && "Overrider should not exist yet!"); - Overrider.Offset = Base.getBaseOffset(); + Overrider.OldOffset = Base.getBaseOffset(); + Overrider.Offset = OffsetInLayoutClass; Overrider.Method = MD; } } @@ -346,6 +370,7 @@ ComputeReturnAdjustmentBaseOffset(ASTContext &Context, void FinalOverriders::PropagateOverrider(const CXXMethodDecl *OldMD, BaseSubobject NewBase, + uint64_t OverriderOffsetInLayoutClass, const CXXMethodDecl *NewMD, SubobjectOffsetsMapTy &Offsets) { for (CXXMethodDecl::method_iterator I = OldMD->begin_overridden_methods(), @@ -389,11 +414,13 @@ void FinalOverriders::PropagateOverrider(const CXXMethodDecl *OldMD, } // Set the new overrider. - Overrider.Offset = NewBase.getBaseOffset(); + Overrider.Offset = OverriderOffsetInLayoutClass; + Overrider.OldOffset = NewBase.getBaseOffset(); Overrider.Method = NewMD; // And propagate it further. - PropagateOverrider(OverriddenMD, NewBase, NewMD, Offsets); + PropagateOverrider(OverriddenMD, NewBase, OverriderOffsetInLayoutClass, + NewMD, Offsets); } } } @@ -416,6 +443,7 @@ FinalOverriders::MergeSubobjectOffsets(const SubobjectOffsetsMapTy &NewOffsets, void FinalOverriders::ComputeFinalOverriders(BaseSubobject Base, bool BaseSubobjectIsVisitedVBase, + uint64_t OffsetInLayoutClass, SubobjectOffsetsMapTy &Offsets) { const CXXRecordDecl *RD = Base.getBase(); const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); @@ -433,12 +461,20 @@ void FinalOverriders::ComputeFinalOverriders(BaseSubobject Base, bool IsVisitedVirtualBase = BaseSubobjectIsVisitedVBase; uint64_t BaseOffset; + uint64_t BaseOffsetInLayoutClass; if (I->isVirtual()) { if (!VisitedVirtualBases.insert(BaseDecl)) IsVisitedVirtualBase = true; BaseOffset = MostDerivedClassLayout.getVBaseClassOffset(BaseDecl); + + const ASTRecordLayout &LayoutClassLayout = + Context.getASTRecordLayout(LayoutClass); + BaseOffsetInLayoutClass = + LayoutClassLayout.getVBaseClassOffset(BaseDecl); } else { BaseOffset = Layout.getBaseClassOffset(BaseDecl) + Base.getBaseOffset(); + BaseOffsetInLayoutClass = Layout.getBaseClassOffset(BaseDecl) + + OffsetInLayoutClass; } // Compute the final overriders for this base. @@ -463,13 +499,14 @@ void FinalOverriders::ComputeFinalOverriders(BaseSubobject Base, // Here, we still want to compute the overriders for A as a base of C, // because otherwise we'll miss that C::g overrides A::f. ComputeFinalOverriders(BaseSubobject(BaseDecl, BaseOffset), - IsVisitedVirtualBase, NewOffsets); + IsVisitedVirtualBase, BaseOffsetInLayoutClass, + NewOffsets); } /// Now add the overriders for this particular subobject. /// (We don't want to do this more than once for a virtual base). if (!BaseSubobjectIsVisitedVBase) - AddOverriders(Base, NewOffsets); + AddOverriders(Base, OffsetInLayoutClass, NewOffsets); // And merge the newly discovered subobject offsets. MergeSubobjectOffsets(NewOffsets, Offsets); @@ -508,7 +545,7 @@ void FinalOverriders::dump(llvm::raw_ostream &Out, BaseSubobject Base) { } Out << "Final overriders for (" << RD->getQualifiedNameAsString() << ", "; - Out << Base.getBaseOffset() << ")\n"; + Out << Base.getBaseOffset() / 8 << ")\n"; // Now dump the overriders for this base subobject. for (CXXRecordDecl::method_iterator I = RD->method_begin(), @@ -522,7 +559,7 @@ void FinalOverriders::dump(llvm::raw_ostream &Out, BaseSubobject Base) { Out << " " << MD->getQualifiedNameAsString() << " - ("; Out << Overrider.Method->getQualifiedNameAsString(); - Out << ", " << Overrider.Offset << ')'; + Out << ", " << Overrider.OldOffset / 8 << ", " << Overrider.Offset / 8 << ')'; AdjustmentOffsetsMapTy::const_iterator AI = ReturnAdjustments.find(std::make_pair(Base, MD)); @@ -1173,15 +1210,17 @@ private: /// thunk. Since we require that a call to C::f() first convert to A*, /// C-in-D's copy of A's vtable is never referenced, so this is not /// necessary. - bool IsOverriderUsed(BaseSubobject Base, - BaseSubobject FirstBaseInPrimaryBaseChain, - uint64_t OffsetInLayoutClass, - FinalOverriders::OverriderInfo Overrider) const; + bool IsOverriderUsed(const CXXMethodDecl *Overrider, + uint64_t BaseOffsetInLayoutClass, + const CXXRecordDecl *FirstBaseInPrimaryBaseChain, + uint64_t FirstBaseOffsetInLayoutClass) const; + /// AddMethods - Add the methods of this base subobject and all its /// primary bases to the vtable components vector. - void AddMethods(BaseSubobject Base, BaseSubobject FirstBaseInPrimaryBaseChain, - uint64_t OffsetInLayoutClass, + void AddMethods(BaseSubobject Base, uint64_t BaseOffsetInLayoutClass, + const CXXRecordDecl *FirstBaseInPrimaryBaseChain, + uint64_t FirstBaseOffsetInLayoutClass, PrimaryBasesSetVectorTy &PrimaryBases); // LayoutVtable - Layout the vtable for the given base class, including its @@ -1201,6 +1240,7 @@ private: /// DeterminePrimaryVirtualBases - Determine the primary virtual bases in this /// class hierarchy. void DeterminePrimaryVirtualBases(const CXXRecordDecl *RD, + uint64_t OffsetInLayoutClass, VisitedVirtualBasesSetTy &VBases); /// LayoutVtablesForVirtualBases - Layout vtables for all virtual bases of the @@ -1222,7 +1262,7 @@ public: MostDerivedClassOffset(MostDerivedClassOffset), MostDerivedClassIsVirtual(MostDerivedClassIsVirtual), LayoutClass(LayoutClass), Context(MostDerivedClass->getASTContext()), - Overriders(MostDerivedClass) { + Overriders(MostDerivedClass, MostDerivedClassOffset, LayoutClass) { LayoutVtable(); } @@ -1269,7 +1309,7 @@ void VtableBuilder::ComputeThisAdjustments() { Overriders.getOverrider(OverriddenBaseSubobject, MD); // Check if we need an adjustment. - if (Overrider.Offset == (int64_t)MethodInfo.BaseOffset) + if (Overrider.OldOffset == (int64_t)MethodInfo.BaseOffset) continue; uint64_t VtableIndex = MethodInfo.VtableIndex; @@ -1284,7 +1324,7 @@ void VtableBuilder::ComputeThisAdjustments() { continue; BaseSubobject OverriderBaseSubobject(Overrider.Method->getParent(), - Overrider.Offset); + Overrider.OldOffset); // Compute the adjustment offset. BaseOffset ThisAdjustmentOffset = @@ -1473,13 +1513,13 @@ OverridesIndirectMethodInBases(const CXXMethodDecl *MD, } bool -VtableBuilder::IsOverriderUsed(BaseSubobject Base, - BaseSubobject FirstBaseInPrimaryBaseChain, - uint64_t OffsetInLayoutClass, - FinalOverriders::OverriderInfo Overrider) const { +VtableBuilder::IsOverriderUsed(const CXXMethodDecl *Overrider, + uint64_t BaseOffsetInLayoutClass, + const CXXRecordDecl *FirstBaseInPrimaryBaseChain, + uint64_t FirstBaseOffsetInLayoutClass) const { // If the base and the first base in the primary base chain have the same // offsets, then this overrider will be used. - if (Base.getBaseOffset() == OffsetInLayoutClass) + if (BaseOffsetInLayoutClass == FirstBaseOffsetInLayoutClass) return true; // We know now that Base (or a direct or indirect base of it) is a primary @@ -1488,12 +1528,12 @@ VtableBuilder::IsOverriderUsed(BaseSubobject Base, // If the overrider is the first base in the primary base chain, we know // that the overrider will be used. - if (Overrider.Method->getParent() == FirstBaseInPrimaryBaseChain.getBase()) + if (Overrider->getParent() == FirstBaseInPrimaryBaseChain) return true; VtableBuilder::PrimaryBasesSetVectorTy PrimaryBases; - const CXXRecordDecl *RD = FirstBaseInPrimaryBaseChain.getBase(); + const CXXRecordDecl *RD = FirstBaseInPrimaryBaseChain; PrimaryBases.insert(RD); // Now traverse the base chain, starting with the first base, until we find @@ -1515,7 +1555,7 @@ VtableBuilder::IsOverriderUsed(BaseSubobject Base, // Now check if this is the primary base that is not a primary base in the // most derived class. if (LayoutClassLayout.getVBaseClassOffset(PrimaryBase) != - OffsetInLayoutClass) { + FirstBaseOffsetInLayoutClass) { // We found it, stop walking the chain. break; } @@ -1532,7 +1572,7 @@ VtableBuilder::IsOverriderUsed(BaseSubobject Base, // If the final overrider is an override of one of the primary bases, // then we know that it will be used. - return OverridesIndirectMethodInBases(Overrider.Method, PrimaryBases); + return OverridesIndirectMethodInBases(Overrider, PrimaryBases); } /// FindNearestOverriddenMethod - Given a method, returns the overridden method @@ -1557,17 +1597,17 @@ FindNearestOverriddenMethod(const CXXMethodDecl *MD, return 0; } -void -VtableBuilder::AddMethods(BaseSubobject Base, - BaseSubobject FirstBaseInPrimaryBaseChain, - uint64_t OffsetInLayoutClass, +void +VtableBuilder::AddMethods(BaseSubobject Base, uint64_t BaseOffsetInLayoutClass, + const CXXRecordDecl *FirstBaseInPrimaryBaseChain, + uint64_t FirstBaseOffsetInLayoutClass, PrimaryBasesSetVectorTy &PrimaryBases) { const CXXRecordDecl *RD = Base.getBase(); - const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); if (const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase()) { - uint64_t BaseOffset; + uint64_t PrimaryBaseOffset; + uint64_t PrimaryBaseOffsetInLayoutClass; if (Layout.getPrimaryBaseWasVirtual()) { assert(Layout.getVBaseClassOffset(PrimaryBase) == 0 && "Primary vbase should have a zero offset!"); @@ -1575,17 +1615,25 @@ VtableBuilder::AddMethods(BaseSubobject Base, const ASTRecordLayout &MostDerivedClassLayout = Context.getASTRecordLayout(MostDerivedClass); - BaseOffset = MostDerivedClassLayout.getVBaseClassOffset(PrimaryBase); + PrimaryBaseOffset = + MostDerivedClassLayout.getVBaseClassOffset(PrimaryBase); + + const ASTRecordLayout &LayoutClassLayout = + Context.getASTRecordLayout(LayoutClass); + + PrimaryBaseOffsetInLayoutClass = + LayoutClassLayout.getVBaseClassOffset(PrimaryBase); } else { assert(Layout.getBaseClassOffset(PrimaryBase) == 0 && "Primary base should have a zero offset!"); - BaseOffset = Base.getBaseOffset(); + PrimaryBaseOffset = Base.getBaseOffset(); + PrimaryBaseOffsetInLayoutClass = BaseOffsetInLayoutClass; } - // FIXME: OffsetInLayoutClass is not right here. - AddMethods(BaseSubobject(PrimaryBase, BaseOffset), - FirstBaseInPrimaryBaseChain, OffsetInLayoutClass, PrimaryBases); + AddMethods(BaseSubobject(PrimaryBase, PrimaryBaseOffset), + PrimaryBaseOffsetInLayoutClass, FirstBaseInPrimaryBaseChain, + FirstBaseOffsetInLayoutClass, PrimaryBases); if (!PrimaryBases.insert(PrimaryBase)) assert(false && "Found a duplicate primary base!"); @@ -1636,9 +1684,10 @@ VtableBuilder::AddMethods(BaseSubobject Base, MethodInfoMap.insert(std::make_pair(MD, MethodInfo)); // Check if this overrider is going to be used. - if (!IsOverriderUsed(Base, FirstBaseInPrimaryBaseChain, OffsetInLayoutClass, - Overrider)) { - const CXXMethodDecl *OverriderMD = Overrider.Method; + const CXXMethodDecl *OverriderMD = Overrider.Method; + if (!IsOverriderUsed(OverriderMD, BaseOffsetInLayoutClass, + FirstBaseInPrimaryBaseChain, + FirstBaseOffsetInLayoutClass)) { Components.push_back(VtableComponent::MakeUnusedFunction(OverriderMD)); continue; } @@ -1662,7 +1711,8 @@ void VtableBuilder::LayoutVtable() { VisitedVirtualBasesSetTy VBases; // Determine the primary virtual bases. - DeterminePrimaryVirtualBases(MostDerivedClass, VBases); + DeterminePrimaryVirtualBases(MostDerivedClass, MostDerivedClassOffset, + VBases); VBases.clear(); LayoutVtablesForVirtualBases(MostDerivedClass, VBases); @@ -1700,7 +1750,8 @@ VtableBuilder::LayoutPrimaryAndSecondaryVtables(BaseSubobject Base, // Now go through all virtual member functions and add them. PrimaryBasesSetVectorTy PrimaryBases; - AddMethods(Base, Base, OffsetInLayoutClass, PrimaryBases); + AddMethods(Base, OffsetInLayoutClass, Base.getBase(), OffsetInLayoutClass, + PrimaryBases); // Compute 'this' pointer adjustments. ComputeThisAdjustments(); @@ -1771,7 +1822,8 @@ void VtableBuilder::LayoutSecondaryVtables(BaseSubobject Base, } void -VtableBuilder::DeterminePrimaryVirtualBases(const CXXRecordDecl *RD, +VtableBuilder::DeterminePrimaryVirtualBases(const CXXRecordDecl *RD, + uint64_t OffsetInLayoutClass, VisitedVirtualBasesSetTy &VBases) { const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); @@ -1785,8 +1837,15 @@ VtableBuilder::DeterminePrimaryVirtualBases(const CXXRecordDecl *RD, if (isBuildingConstructorVtable()) { // Check if the base is actually a primary base in the class we use for // layout. - // FIXME: Is this check enough? - if (MostDerivedClassOffset != 0) + const ASTRecordLayout &LayoutClassLayout = + Context.getASTRecordLayout(LayoutClass); + + uint64_t PrimaryBaseOffsetInLayoutClass = + LayoutClassLayout.getVBaseClassOffset(PrimaryBase); + + // We know that the base is not a primary base in the layout class if + // the base offsets are different. + if (PrimaryBaseOffsetInLayoutClass != OffsetInLayoutClass) IsPrimaryVirtualBase = false; } @@ -1801,10 +1860,22 @@ VtableBuilder::DeterminePrimaryVirtualBases(const CXXRecordDecl *RD, const CXXRecordDecl *BaseDecl = cast(I->getType()->getAs()->getDecl()); - if (I->isVirtual() && !VBases.insert(BaseDecl)) - continue; + uint64_t BaseOffsetInLayoutClass; + + if (I->isVirtual()) { + if (!VBases.insert(BaseDecl)) + continue; + + const ASTRecordLayout &LayoutClassLayout = + Context.getASTRecordLayout(LayoutClass); - DeterminePrimaryVirtualBases(BaseDecl, VBases); + BaseOffsetInLayoutClass = LayoutClassLayout.getVBaseClassOffset(BaseDecl); + } else { + BaseOffsetInLayoutClass = + OffsetInLayoutClass + Layout.getBaseClassOffset(BaseDecl); + } + + DeterminePrimaryVirtualBases(BaseDecl, BaseOffsetInLayoutClass, VBases); } } @@ -3405,7 +3476,22 @@ void CGVtableInfo::GenerateClassData(llvm::GlobalVariable::LinkageTypes Linkage, Vtable = GenerateVtable(Linkage, /*GenerateDefinition=*/true, RD, RD, 0, /*IsVirtual=*/false, AddressPoints); - GenerateVTT(Linkage, /*GenerateDefinition=*/true, RD); + GenerateVTT(Linkage, /*GenerateDefinition=*/true, RD); + + for (CXXRecordDecl::method_iterator i = RD->method_begin(), + e = RD->method_end(); i != e; ++i) { + if (!(*i)->isVirtual()) + continue; + if(!(*i)->hasInlineBody() && !(*i)->isImplicit()) + continue; + + if (const CXXDestructorDecl *DD = dyn_cast(*i)) { + CGM.BuildThunksForVirtual(GlobalDecl(DD, Dtor_Complete)); + CGM.BuildThunksForVirtual(GlobalDecl(DD, Dtor_Deleting)); + } else { + CGM.BuildThunksForVirtual(GlobalDecl(*i)); + } + } } llvm::GlobalVariable *CGVtableInfo::getVtable(const CXXRecordDecl *RD) { @@ -3438,19 +3524,12 @@ void CGVtableInfo::MaybeEmitVtable(GlobalDecl GD) { return; } - // Emit the data. - GenerateClassData(CGM.getVtableLinkage(RD), RD); + if (Vtables.count(RD)) + return; - for (CXXRecordDecl::method_iterator i = RD->method_begin(), - e = RD->method_end(); i != e; ++i) { - if ((*i)->isVirtual() && ((*i)->hasInlineBody() || (*i)->isImplicit())) { - if (const CXXDestructorDecl *DD = dyn_cast(*i)) { - CGM.BuildThunksForVirtual(GlobalDecl(DD, Dtor_Complete)); - CGM.BuildThunksForVirtual(GlobalDecl(DD, Dtor_Deleting)); - } else { - CGM.BuildThunksForVirtual(GlobalDecl(*i)); - } - } - } + TemplateSpecializationKind kind = RD->getTemplateSpecializationKind(); + if (kind == TSK_ImplicitInstantiation) + CGM.DeferredVtables.push_back(RD); + else + GenerateClassData(CGM.getVtableLinkage(RD), RD); } - diff --git a/lib/CodeGen/CGVtable.h b/lib/CodeGen/CGVtable.h index 6ccb011..57220d9 100644 --- a/lib/CodeGen/CGVtable.h +++ b/lib/CodeGen/CGVtable.h @@ -173,15 +173,7 @@ private: uint64_t getNumVirtualFunctionPointers(const CXXRecordDecl *RD); void ComputeMethodVtableIndices(const CXXRecordDecl *RD); - - /// GenerateClassData - Generate all the class data requires to be generated - /// upon definition of a KeyFunction. This includes the vtable, the - /// rtti data structure and the VTT. - /// - /// \param Linkage - The desired linkage of the vtable, the RTTI and the VTT. - void GenerateClassData(llvm::GlobalVariable::LinkageTypes Linkage, - const CXXRecordDecl *RD); - + llvm::GlobalVariable * GenerateVtable(llvm::GlobalVariable::LinkageTypes Linkage, bool GenerateDefinition, const CXXRecordDecl *LayoutClass, @@ -245,6 +237,14 @@ public: llvm::GlobalVariable *getVTT(const CXXRecordDecl *RD); void MaybeEmitVtable(GlobalDecl GD); + + /// GenerateClassData - Generate all the class data requires to be generated + /// upon definition of a KeyFunction. This includes the vtable, the + /// rtti data structure and the VTT. + /// + /// \param Linkage - The desired linkage of the vtable, the RTTI and the VTT. + void GenerateClassData(llvm::GlobalVariable::LinkageTypes Linkage, + const CXXRecordDecl *RD); }; } // end namespace CodeGen diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index d6a56da..c67948d 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -488,7 +488,15 @@ void CodeGenModule::EmitDeferred() { // Emit code for any potentially referenced deferred decls. Since a // previously unused static decl may become used during the generation of code // for a static function, iterate until no changes are made. - while (!DeferredDeclsToEmit.empty()) { + + while (!DeferredDeclsToEmit.empty() || !DeferredVtables.empty()) { + if (!DeferredVtables.empty()) { + const CXXRecordDecl *RD = DeferredVtables.back(); + DeferredVtables.pop_back(); + getVtableInfo().GenerateClassData(getVtableLinkage(RD), RD); + continue; + } + GlobalDecl D = DeferredDeclsToEmit.back(); DeferredDeclsToEmit.pop_back(); diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index c86f8b4..40dc563 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -451,7 +451,9 @@ public: /// GetTargetTypeStoreSize - Return the store size, in character units, of /// the given LLVM type. CharUnits GetTargetTypeStoreSize(const llvm::Type *Ty) const; - + + std::vector DeferredVtables; + private: /// UniqueMangledName - Unique a name by (if necessary) inserting it into the /// MangledNames string map. diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp index 20d54b3..2e0580f 100644 --- a/lib/CodeGen/Mangle.cpp +++ b/lib/CodeGen/Mangle.cpp @@ -214,12 +214,6 @@ bool MangleContext::shouldMangleDeclName(const NamedDecl *D) { if (!getASTContext().getLangOptions().CPlusPlus) return false; - // No mangling in an "implicit extern C" header. - if (D->getLocation().isValid() && - getASTContext().getSourceManager(). - isInExternCSystemHeader(D->getLocation())) - return false; - // Variables at global scope with non-internal linkage are not mangled if (!FD) { const DeclContext *DC = D->getDeclContext(); diff --git a/lib/Driver/HostInfo.cpp b/lib/Driver/HostInfo.cpp index 98b64f1..d8e086d 100644 --- a/lib/Driver/HostInfo.cpp +++ b/lib/Driver/HostInfo.cpp @@ -164,7 +164,7 @@ class TCEHostInfo : public HostInfo { public: TCEHostInfo(const Driver &D, const llvm::Triple &Triple); - ~TCEHostInfo() {}; + ~TCEHostInfo() {} virtual bool useDriverDriver() const; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index de9bdcc..bc52100 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -929,7 +929,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // Special case debug options to only pass -g to clang. This is // wrong. - if (Args.hasArg(options::OPT_g_Group)) + Args.ClaimAllArgs(options::OPT_g_Group); + Arg *Garg = Args.getLastArg(options::OPT_g_Group); + if (Garg && Garg != Args.getLastArg(options::OPT_g0)) CmdArgs.push_back("-g"); Args.AddLastArg(CmdArgs, options::OPT_nostdinc); diff --git a/lib/Frontend/CacheTokens.cpp b/lib/Frontend/CacheTokens.cpp index 702c1d0..c845d56 100644 --- a/lib/Frontend/CacheTokens.cpp +++ b/lib/Frontend/CacheTokens.cpp @@ -64,7 +64,7 @@ public: PTHEntryKeyVariant(struct stat* statbuf, const char* path) : Path(path), Kind(IsDE), StatBuf(new struct stat(*statbuf)) {} - PTHEntryKeyVariant(const char* path) + explicit PTHEntryKeyVariant(const char* path) : Path(path), Kind(IsNoExist), StatBuf(0) {} bool isFile() const { return Kind == IsFE; } @@ -513,7 +513,7 @@ public: int result = StatSysCallCache::stat(path, buf); if (result != 0) // Failed 'stat'. - PM.insert(path, PTHEntry()); + PM.insert(PTHEntryKeyVariant(path), PTHEntry()); else if (S_ISDIR(buf->st_mode)) { // Only cache directories with absolute paths. if (!llvm::sys::Path(path).isAbsolute()) diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 1831ca5..25b804a 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -94,7 +94,7 @@ namespace { public: explicit BinaryDiagnosticSerializer(llvm::raw_ostream &OS) : OS(OS), SourceMgr(0) { } - + virtual void HandleDiagnostic(Diagnostic::Level DiagLevel, const DiagnosticInfo &Info); }; @@ -341,7 +341,7 @@ void CompilerInstance::addOutputFile(llvm::StringRef Path, OutputFiles.push_back(std::make_pair(Path, OS)); } -void CompilerInstance::ClearOutputFiles(bool EraseFiles) { +void CompilerInstance::clearOutputFiles(bool EraseFiles) { for (std::list< std::pair >::iterator it = OutputFiles.begin(), ie = OutputFiles.end(); it != ie; ++it) { delete it->second; diff --git a/lib/Frontend/DeclXML.cpp b/lib/Frontend/DeclXML.cpp index d7470d9..8750b1e 100644 --- a/lib/Frontend/DeclXML.cpp +++ b/lib/Frontend/DeclXML.cpp @@ -29,6 +29,14 @@ class DocumentXML::DeclPrinter : public DeclVisitor { } } + void addFunctionBody(FunctionDecl* FD) { + if (FD->isThisDeclarationADefinition()) { + Doc.addSubNode("Body"); + Doc.PrintStmt(FD->getBody()); + Doc.toParent(); + } + } + void addSubNodes(RecordDecl* RD) { for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); i != e; ++i) { @@ -37,6 +45,15 @@ class DocumentXML::DeclPrinter : public DeclVisitor { } } + void addSubNodes(CXXRecordDecl* RD) { + addSubNodes(cast(RD)); + for (CXXRecordDecl::method_iterator i = RD->method_begin(), + e = RD->method_end(); i != e; ++i) { + Visit(*i); + Doc.toParent(); + } + } + void addSubNodes(EnumDecl* ED) { for (EnumDecl::enumerator_iterator i = ED->enumerator_begin(), e = ED->enumerator_end(); i != e; ++i) { @@ -115,6 +132,8 @@ public: #define SUB_NODE_SEQUENCE_XML( CLASS ) addSubNodes(T); #define SUB_NODE_OPT_XML( CLASS ) addSubNodes(T); +#define SUB_NODE_FN_BODY_XML addFunctionBody(T); + #include "clang/Frontend/DeclXML.def" }; @@ -122,13 +141,6 @@ public: //--------------------------------------------------------- void DocumentXML::writeDeclToXML(Decl *D) { DeclPrinter(*this).Visit(D); - if (FunctionDecl *FD = dyn_cast(D)) { - if (Stmt *Body = FD->getBody()) { - addSubNode("Body"); - PrintStmt(Body); - toParent(); - } - } toParent(); } diff --git a/lib/Frontend/DependencyFile.cpp b/lib/Frontend/DependencyFile.cpp index 478c339..de2b056 100644 --- a/lib/Frontend/DependencyFile.cpp +++ b/lib/Frontend/DependencyFile.cpp @@ -74,8 +74,7 @@ void clang::AttachDependencyFileGen(Preprocessor &PP, return; } - assert(!PP.getPPCallbacks() && "Preprocessor callbacks already registered!"); - PP.setPPCallbacks(new DependencyFileCallback(&PP, OS, Opts)); + PP.addPPCallbacks(new DependencyFileCallback(&PP, OS, Opts)); } /// FileMatchesDepCriteria - Determine whether the given Filename should be diff --git a/lib/Frontend/FrontendAction.cpp b/lib/Frontend/FrontendAction.cpp index 96a68c9..66df7a6 100644 --- a/lib/Frontend/FrontendAction.cpp +++ b/lib/Frontend/FrontendAction.cpp @@ -180,7 +180,7 @@ void FrontendAction::EndSourceFile() { // Cleanup the output streams, and erase the output files if we encountered // an error. - CI.ClearOutputFiles(/*EraseFiles=*/CI.getDiagnostics().getNumErrors()); + CI.clearOutputFiles(/*EraseFiles=*/CI.getDiagnostics().getNumErrors()); // Inform the diagnostic client we are done with this source file. CI.getDiagnosticClient().EndSourceFile(); diff --git a/lib/Frontend/InitHeaderSearch.cpp b/lib/Frontend/InitHeaderSearch.cpp index 4f972f0..cd749d2 100644 --- a/lib/Frontend/InitHeaderSearch.cpp +++ b/lib/Frontend/InitHeaderSearch.cpp @@ -436,7 +436,7 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple) { break; } - AddPath("/usr/local/include", System, false, false, false); + AddPath("/usr/local/include", System, true, false, false); AddPath("/usr/include", System, false, false, false); } diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index a878df7..267f4c1 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -120,7 +120,7 @@ PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) { PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl); PARSE_LANGOPT_BENIGN(CatchUndefined); PARSE_LANGOPT_IMPORTANT(ElideConstructors, diag::warn_pch_elide_constructors); -#undef PARSE_LANGOPT_IRRELEVANT +#undef PARSE_LANGOPT_IMPORTANT #undef PARSE_LANGOPT_BENIGN return false; @@ -1089,13 +1089,13 @@ void PCHReader::ReadDefinedMacros() { // If there was no preprocessor block, do nothing. if (!MacroCursor.getBitStreamReader()) return; - + llvm::BitstreamCursor Cursor = MacroCursor; if (Cursor.EnterSubBlock(pch::PREPROCESSOR_BLOCK_ID)) { Error("malformed preprocessor block record in PCH file"); return; } - + RecordData Record; while (true) { unsigned Code = Cursor.ReadCode(); @@ -1104,7 +1104,7 @@ void PCHReader::ReadDefinedMacros() { Error("error at end of preprocessor block in PCH file"); return; } - + if (Code == llvm::bitc::ENTER_SUBBLOCK) { // No known subblocks, always skip them. Cursor.ReadSubBlockID(); @@ -1114,12 +1114,12 @@ void PCHReader::ReadDefinedMacros() { } continue; } - + if (Code == llvm::bitc::DEFINE_ABBREV) { Cursor.ReadAbbrevRecord(); continue; } - + // Read a record. const char *BlobStart; unsigned BlobLen; @@ -1127,7 +1127,7 @@ void PCHReader::ReadDefinedMacros() { switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { default: // Default behavior: ignore. break; - + case pch::PP_MACRO_OBJECT_LIKE: case pch::PP_MACRO_FUNCTION_LIKE: DecodeIdentifierInfo(Record[0]); @@ -1339,7 +1339,7 @@ PCHReader::ReadPCHBlock() { } UnusedStaticFuncs.swap(Record); break; - + case pch::LOCALLY_SCOPED_EXTERNAL_DECLS: if (!LocallyScopedExternalDecls.empty()) { Error("duplicate LOCALLY_SCOPED_EXTERNAL_DECLS record in PCH file"); @@ -1385,7 +1385,7 @@ PCHReader::ReadPCHBlock() { break; case pch::STAT_CACHE: { - PCHStatCache *MyStatCache = + PCHStatCache *MyStatCache = new PCHStatCache((const unsigned char *)BlobStart + Record[0], (const unsigned char *)BlobStart, NumStatHits, NumStatMisses); @@ -1393,7 +1393,7 @@ PCHReader::ReadPCHBlock() { StatCache = MyStatCache; break; } - + case pch::EXT_VECTOR_DECLS: if (!ExtVectorDecls.empty()) { Error("duplicate EXT_VECTOR_DECLS record in PCH file"); @@ -1412,7 +1412,7 @@ PCHReader::ReadPCHBlock() { Comments = (SourceRange *)BlobStart; NumComments = BlobLen / sizeof(SourceRange); break; - + case pch::VERSION_CONTROL_BRANCH_REVISION: { const std::string &CurBranch = getClangFullRepositoryVersion(); llvm::StringRef PCHBranch(BlobStart, BlobLen); @@ -1561,7 +1561,7 @@ void PCHReader::InitializeContext(ASTContext &Ctx) { PP->getIdentifierTable().setExternalIdentifierLookup(this); PP->getHeaderSearchInfo().SetExternalLookup(this); PP->setExternalSource(this); - + // Load the translation unit declaration ReadDeclRecord(DeclOffsets[0], 0); @@ -2018,6 +2018,12 @@ QualType PCHReader::ReadTypeRecord(uint64_t Offset) { Context->getSubstTemplateTypeParmType(cast(Parm), Replacement); } + + case pch::TYPE_INJECTED_CLASS_NAME: { + CXXRecordDecl *D = cast(GetDecl(Record[0])); + QualType TST = GetType(Record[1]); // probably derivable + return Context->getInjectedClassNameType(D, TST); + } } // Suppress a GCC warning return QualType(); @@ -2172,6 +2178,9 @@ void TypeLocReader::VisitTemplateSpecializationTypeLoc( void TypeLocReader::VisitQualifiedNameTypeLoc(QualifiedNameTypeLoc TL) { TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); } +void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { + TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); +} void TypeLocReader::VisitTypenameTypeLoc(TypenameTypeLoc TL) { TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); } @@ -2271,7 +2280,7 @@ PCHReader::GetTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, case TemplateArgument::Type: return GetTypeSourceInfo(Record, Index); case TemplateArgument::Template: { - SourceLocation + SourceLocation QualStart = SourceLocation::getFromRawEncoding(Record[Index++]), QualEnd = SourceLocation::getFromRawEncoding(Record[Index++]), TemplateNameLoc = SourceLocation::getFromRawEncoding(Record[Index++]); @@ -2487,7 +2496,7 @@ void PCHReader::InitializeSema(Sema &S) { VarDecl *Var = cast(GetDecl(TentativeDefinitions[I])); SemaObj->TentativeDefinitions.push_back(Var); } - + // If there were any unused static functions, deserialize them and add to // Sema's list of unused static functions. for (unsigned I = 0, N = UnusedStaticFuncs.size(); I != N; ++I) { diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp index 356bd07..a3f5eac 100644 --- a/lib/Frontend/PCHReaderDecl.cpp +++ b/lib/Frontend/PCHReaderDecl.cpp @@ -211,6 +211,7 @@ void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]); MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]); MD->setResultType(Reader.GetType(Record[Idx++])); + MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx)); MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); unsigned NumParams = Record[Idx++]; llvm::SmallVector Params; @@ -690,7 +691,7 @@ Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) { break; case pch::DECL_OBJC_METHOD: D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(), - Selector(), QualType(), 0); + Selector(), QualType(), 0, 0); break; case pch::DECL_OBJC_INTERFACE: D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0); diff --git a/lib/Frontend/PCHReaderStmt.cpp b/lib/Frontend/PCHReaderStmt.cpp index d123694..7b94805 100644 --- a/lib/Frontend/PCHReaderStmt.cpp +++ b/lib/Frontend/PCHReaderStmt.cpp @@ -792,8 +792,9 @@ unsigned PCHStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) { cast_or_null(StmtStack[StmtStack.size() - E->getNumArgs() - 1])); if (!E->getReceiver()) { ObjCMessageExpr::ClassInfo CI; - CI.first = cast_or_null(Reader.GetDecl(Record[Idx++])); - CI.second = Reader.GetIdentifierInfo(Record, Idx); + CI.Decl = cast_or_null(Reader.GetDecl(Record[Idx++])); + CI.Name = Reader.GetIdentifierInfo(Record, Idx); + CI.Loc = SourceLocation::getFromRawEncoding(Record[Idx++]); E->setClassInfo(CI); } diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp index 93af754..eed3cc1 100644 --- a/lib/Frontend/PCHWriter.cpp +++ b/lib/Frontend/PCHWriter.cpp @@ -235,6 +235,12 @@ void PCHTypeWriter::VisitQualifiedNameType(const QualifiedNameType *T) { assert(false && "Cannot serialize qualified name types"); } +void PCHTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { + Writer.AddDeclRef(T->getDecl(), Record); + Writer.AddTypeRef(T->getUnderlyingType(), Record); + Code = pch::TYPE_INJECTED_CLASS_NAME; +} + void PCHTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { Writer.AddDeclRef(T->getDecl(), Record); Record.push_back(T->getNumProtocols()); @@ -394,6 +400,9 @@ void TypeLocWriter::VisitTemplateSpecializationTypeLoc( void TypeLocWriter::VisitQualifiedNameTypeLoc(QualifiedNameTypeLoc TL) { Writer.AddSourceLocation(TL.getNameLoc(), Record); } +void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { + Writer.AddSourceLocation(TL.getNameLoc(), Record); +} void TypeLocWriter::VisitTypenameTypeLoc(TypenameTypeLoc TL) { Writer.AddSourceLocation(TL.getNameLoc(), Record); } diff --git a/lib/Frontend/PCHWriterDecl.cpp b/lib/Frontend/PCHWriterDecl.cpp index e776d32..0774797 100644 --- a/lib/Frontend/PCHWriterDecl.cpp +++ b/lib/Frontend/PCHWriterDecl.cpp @@ -210,6 +210,7 @@ void PCHDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) { // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway Record.push_back(D->getObjCDeclQualifier()); Writer.AddTypeRef(D->getResultType(), Record); + Writer.AddTypeSourceInfo(D->getResultTypeSourceInfo(), Record); Writer.AddSourceLocation(D->getLocEnd(), Record); Record.push_back(D->param_size()); for (ObjCMethodDecl::param_iterator P = D->param_begin(), diff --git a/lib/Frontend/PCHWriterStmt.cpp b/lib/Frontend/PCHWriterStmt.cpp index a8cc9d6..9a5417c 100644 --- a/lib/Frontend/PCHWriterStmt.cpp +++ b/lib/Frontend/PCHWriterStmt.cpp @@ -720,8 +720,9 @@ void PCHStmtWriter::VisitObjCMessageExpr(ObjCMessageExpr *E) { if (!E->getReceiver()) { ObjCMessageExpr::ClassInfo CI = E->getClassInfo(); - Writer.AddDeclRef(CI.first, Record); - Writer.AddIdentifierRef(CI.second, Record); + Writer.AddDeclRef(CI.Decl, Record); + Writer.AddIdentifierRef(CI.Name, Record); + Writer.AddSourceLocation(CI.Loc, Record); } for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end(); diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp index 774372c..be5bb0d 100644 --- a/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/lib/Frontend/PrintPreprocessedOutput.cpp @@ -52,7 +52,7 @@ static void PrintMacroDefinition(const IdentifierInfo &II, const MacroInfo &MI, if (MI.isGNUVarargs()) OS << "..."; // #define foo(x...) - + OS << ')'; } @@ -102,7 +102,7 @@ public: EmittedMacroOnThisLine = false; FileType = SrcMgr::C_User; Initialized = false; - + // If we're in microsoft mode, use normal #line instead of line markers. UseLineDirective = PP.getLangOptions().Microsoft; } @@ -150,7 +150,7 @@ void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo, OS << '#' << ' ' << LineNo << ' ' << '"'; OS.write(&CurFilename[0], CurFilename.size()); OS << '"'; - + if (ExtraLen) OS.write(Extra, ExtraLen); @@ -492,7 +492,7 @@ void clang::DoPrintPreprocessedInput(Preprocessor &PP, llvm::raw_ostream *OS, PP.AddPragmaHandler("GCC", new UnknownPragmaHandler("#pragma GCC", Callbacks)); - PP.setPPCallbacks(Callbacks); + PP.addPPCallbacks(Callbacks); // After we have configured the preprocessor, enter the main file. PP.EnterMainSourceFile(); diff --git a/lib/Headers/smmintrin.h b/lib/Headers/smmintrin.h index d91ed1d..b3bdac6 100644 --- a/lib/Headers/smmintrin.h +++ b/lib/Headers/smmintrin.h @@ -32,6 +32,7 @@ /* Type defines. */ typedef double __v2df __attribute__ ((__vector_size__ (16))); +typedef long long __v2di __attribute__ ((__vector_size__ (16))); /* SSE4 Rounding macros. */ #define _MM_FROUND_TO_NEAREST_INT 0x00 @@ -48,7 +49,7 @@ typedef double __v2df __attribute__ ((__vector_size__ (16))); #define _MM_FROUND_CEIL (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_POS_INF) #define _MM_FROUND_TRUNC (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_ZERO) #define _MM_FROUND_RINT (_MM_FROUND_RAISE_EXC | _MM_FROUND_CUR_DIRECTION) -#define _MM_FROUND_NEARBYINT (_MM_FROUND_RAISE_EXC | _MM_FROUND_CUR_DIRECTION) +#define _MM_FROUND_NEARBYINT (_MM_FROUND_NO_EXC | _MM_FROUND_CUR_DIRECTION) #define _mm_ceil_ps(X) _mm_round_ps((X), _MM_FROUND_CEIL) #define _mm_ceil_pd(X) _mm_round_pd((X), _MM_FROUND_CEIL) @@ -60,30 +61,10 @@ typedef double __v2df __attribute__ ((__vector_size__ (16))); #define _mm_floor_ss(X, Y) _mm_round_ss((X), (Y), _MM_FROUND_FLOOR) #define _mm_floor_sd(X, Y) _mm_round_sd((X), (Y), _MM_FROUND_FLOOR) -/* SSE4 Rounding Intrinsics. */ -static inline __m128 __attribute__((__always_inline__, __nodebug__)) -_mm_round_ps (__m128 __V, const int __M) -{ - return (__m128) __builtin_ia32_roundps ((__v4sf)__V, __M); -} - -static inline __m128 __attribute__((__always_inline__, __nodebug__)) -_mm_round_ss (__m128 __V1, __m128 __V2, const int __M) -{ - return (__m128) __builtin_ia32_roundss ((__v4sf)__V1, (__v4sf)__V2, __M); -} - -static inline __m128d __attribute__((__always_inline__, __nodebug__)) -_mm_round_pd (__m128d __V, const int __M) -{ - return (__m128d) __builtin_ia32_roundpd ((__v2df)__V, __M); -} - -static inline __m128d __attribute__((__always_inline__, __nodebug__)) -_mm_round_sd(__m128d __V1, __m128d __V2, const int __M) -{ - return (__m128d) __builtin_ia32_roundsd ((__v2df)__V1, (__v2df)__V2, __M); -} +#define _mm_round_ps(X, Y) __builtin_ia32_roundps((X), (Y)) +#define _mm_round_ss(X, Y, M) __builtin_ia32_roundss((X), (Y), (M)) +#define _mm_round_pd(X, M) __builtin_ia32_roundpd((X), (M)) +#define _mm_round_sd(X, Y, M) __builtin_ia32_roundsd((X), (Y), (M)) /* SSE4 Packed Blending Intrinsics. */ static inline __m128d __attribute__((__always_inline__, __nodebug__)) @@ -125,6 +106,100 @@ _mm_blend_epi16 (__m128i __V1, __m128i __V2, const int __M) return (__m128i) __builtin_ia32_pblendw128 ((__v8hi)__V1, (__v8hi)__V2, __M); } +/* SSE4 Dword Multiply Instructions. */ +static inline __m128i __attribute__((__always_inline__, __nodebug__)) +_mm_mullo_epi32 (__m128i __V1, __m128i __V2) +{ + return (__m128i) __builtin_ia32_pmulld128((__v4si)__V1, (__v4si)__V2); +} + +static inline __m128i __attribute__((__always_inline__, __nodebug__)) +_mm_mul_epi32 (__m128i __V1, __m128i __V2) +{ + return (__m128i) __builtin_ia32_pmuldq128 ((__v4si)__V1, (__v4si)__V2); +} + +/* SSE4 Floating Point Dot Product Instructions. */ +#define _mm_dp_ps(X, Y, M) __builtin_ia32_dpps ((X), (Y), (M)) +#define _mm_dp_pd(X, Y, M) __builtin_ia32_dppd ((X), (Y), (M)) + +/* SSE4 Streaming Load Hint Instruction. */ +static inline __m128i __attribute__((__always_inline__, __nodebug__)) +_mm_stream_load_si128 (__m128i *__V) +{ + return (__m128i) __builtin_ia32_movntdqa ((__v2di *) __V); +} + +/* SSE4 Packed Integer Min/Max Instructions. */ +static inline __m128i __attribute__((__always_inline__, __nodebug__)) +_mm_min_epi8 (__m128i __V1, __m128i __V2) +{ + return (__m128i) __builtin_ia32_pminsb128 ((__v16qi) __V1, (__v16qi) __V2); +} + +static inline __m128i __attribute__((__always_inline__, __nodebug__)) +_mm_max_epi8 (__m128i __V1, __m128i __V2) +{ + return (__m128i) __builtin_ia32_pmaxsb128 ((__v16qi) __V1, (__v16qi) __V2); +} + +static inline __m128i __attribute__((__always_inline__, __nodebug__)) +_mm_min_epu16 (__m128i __V1, __m128i __V2) +{ + return (__m128i) __builtin_ia32_pminuw128 ((__v8hi) __V1, (__v8hi) __V2); +} + +static inline __m128i __attribute__((__always_inline__, __nodebug__)) +_mm_max_epu16 (__m128i __V1, __m128i __V2) +{ + return (__m128i) __builtin_ia32_pmaxuw128 ((__v8hi) __V1, (__v8hi) __V2); +} + +static inline __m128i __attribute__((__always_inline__, __nodebug__)) +_mm_min_epi32 (__m128i __V1, __m128i __V2) +{ + return (__m128i) __builtin_ia32_pminsd128 ((__v4si) __V1, (__v4si) __V2); +} + +static inline __m128i __attribute__((__always_inline__, __nodebug__)) +_mm_max_epi32 (__m128i __V1, __m128i __V2) +{ + return (__m128i) __builtin_ia32_pmaxsd128 ((__v4si) __V1, (__v4si) __V2); +} + +static inline __m128i __attribute__((__always_inline__, __nodebug__)) +_mm_min_epu32 (__m128i __V1, __m128i __V2) +{ + return (__m128i) __builtin_ia32_pminud128((__v4si) __V1, (__v4si) __V2); +} + +static inline __m128i __attribute__((__always_inline__, __nodebug__)) +_mm_max_epu32 (__m128i __V1, __m128i __V2) +{ + return (__m128i) __builtin_ia32_pmaxud128((__v4si) __V1, (__v4si) __V2); +} + +/* SSE4 Insertion and Extraction from XMM Register Instructions. */ +#define _mm_insert_ps(X, Y, N) __builtin_ia32_insertps128((X), (Y), (N)) +#define _mm_extract_ps(X, N) (__extension__ \ + ({ union { int i; float f; } __t; \ + __v4sf __a = (__v4sf)X; \ + __t.f = __a[N]; \ + __t.i;})) + +/* Miscellaneous insert and extract macros. */ +/* Extract a single-precision float from X at index N into D. */ +#define _MM_EXTRACT_FLOAT(D, X, N) (__extension__ ({ __v4sf __a = (__v4sf)X; \ + (D) = __a[N]; })) + +/* Or together 2 sets of indexes (X and Y) with the zeroing bits (Z) to create + an index suitable for _mm_insert_ps. */ +#define _MM_MK_INSERTPS_NDX(X, Y, Z) (((X) << 6) | ((Y) << 4) | (Z)) + +/* Extract a float from X at index N into the first index of the return. */ +#define _MM_PICK_OUT_PS(X, N) _mm_insert_ps (_mm_setzero_ps(), (X), \ + _MM_MK_INSERTPS_NDX((N), 0, 0x0e)) + #endif /* __SSE4_1__ */ #endif /* _SMMINTRIN_H */ diff --git a/lib/Headers/stdarg.h b/lib/Headers/stdarg.h index bbbaff9..c36ab12 100644 --- a/lib/Headers/stdarg.h +++ b/lib/Headers/stdarg.h @@ -26,7 +26,10 @@ #ifndef __STDARG_H #define __STDARG_H +#ifndef _VA_LIST typedef __builtin_va_list va_list; +#define _VA_LIST +#endif #define va_start(ap, param) __builtin_va_start(ap, param) #define va_end(ap) __builtin_va_end(ap) #define va_arg(ap, type) __builtin_va_arg(ap, type) diff --git a/lib/Headers/stddef.h b/lib/Headers/stddef.h index 2c84b4b..6868ad3 100644 --- a/lib/Headers/stddef.h +++ b/lib/Headers/stddef.h @@ -27,11 +27,18 @@ #define __STDDEF_H typedef __typeof__(((int*)0)-((int*)0)) ptrdiff_t; +#ifndef _SIZE_T +#define _SIZE_T typedef __typeof__(sizeof(int)) size_t; +#endif #ifndef __cplusplus +#ifndef _WCHAR_T +#define _WCHAR_T typedef __typeof__(*L"") wchar_t; #endif +#endif +#undef NULL #ifdef __cplusplus #define NULL __null #else diff --git a/lib/Index/Analyzer.cpp b/lib/Index/Analyzer.cpp index fb3529d..7b414f2 100644 --- a/lib/Index/Analyzer.cpp +++ b/lib/Index/Analyzer.cpp @@ -177,7 +177,7 @@ public: if (IsInstanceMethod) return false; - MsgD = Msg->getClassInfo().first; + MsgD = Msg->getClassInfo().Decl; // FIXME: Case when we only have an identifier. assert(MsgD && "Identifier only"); } @@ -250,7 +250,7 @@ public: while (true) { if (Msg->getReceiver() == 0) { CanBeClassMethod = true; - MsgD = Msg->getClassInfo().first; + MsgD = Msg->getClassInfo().Decl; // FIXME: Case when we only have an identifier. assert(MsgD && "Identifier only"); break; diff --git a/lib/Sema/CodeCompleteConsumer.cpp b/lib/Sema/CodeCompleteConsumer.cpp index 8c4caaf..299e84e 100644 --- a/lib/Sema/CodeCompleteConsumer.cpp +++ b/lib/Sema/CodeCompleteConsumer.cpp @@ -17,7 +17,6 @@ #include "clang-c/Index.h" #include "Sema.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/StringSwitch.h" #include "llvm/Support/raw_ostream.h" #include #include diff --git a/lib/Sema/JumpDiagnostics.cpp b/lib/Sema/JumpDiagnostics.cpp index 7cf207f..1c761b9 100644 --- a/lib/Sema/JumpDiagnostics.cpp +++ b/lib/Sema/JumpDiagnostics.cpp @@ -85,6 +85,8 @@ static unsigned GetDiagForGotoScopeDecl(const Decl *D, bool isCPlusPlus) { return diag::note_protected_by_cleanup; if (VD->hasAttr()) return diag::note_protected_by___block; + // FIXME: In C++0x, we have to check more conditions than "did we + // just give it an initializer?". See 6.7p3. if (isCPlusPlus && VD->hasLocalStorage() && VD->hasInit()) return diag::note_protected_by_variable_init; diff --git a/lib/Sema/SemaCXXCast.cpp b/lib/Sema/SemaCXXCast.cpp index 0097cd3..e04abd2 100644 --- a/lib/Sema/SemaCXXCast.cpp +++ b/lib/Sema/SemaCXXCast.cpp @@ -84,7 +84,8 @@ static TryCastResult TryStaticDowncast(Sema &Self, CanQualType SrcType, QualType OrigSrcType, QualType OrigDestType, unsigned &msg, CastExpr::CastKind &Kind); -static TryCastResult TryStaticMemberPointerUpcast(Sema &Self, QualType SrcType, +static TryCastResult TryStaticMemberPointerUpcast(Sema &Self, Expr *&SrcExpr, + QualType SrcType, QualType DestType,bool CStyle, const SourceRange &OpRange, unsigned &msg, @@ -554,7 +555,7 @@ static TryCastResult TryStaticCast(Sema &Self, Expr *&SrcExpr, // Reverse member pointer conversion. C++ 4.11 specifies member pointer // conversion. C++ 5.2.9p9 has additional information. // DR54's access restrictions apply here also. - tcr = TryStaticMemberPointerUpcast(Self, SrcType, DestType, CStyle, + tcr = TryStaticMemberPointerUpcast(Self, SrcExpr, SrcType, DestType, CStyle, OpRange, msg, Kind); if (tcr != TC_NotApplicable) return tcr; @@ -798,12 +799,23 @@ TryStaticDowncast(Sema &Self, CanQualType SrcType, CanQualType DestType, /// where B is a base class of D [...]. /// TryCastResult -TryStaticMemberPointerUpcast(Sema &Self, QualType SrcType, QualType DestType, - bool CStyle, const SourceRange &OpRange, +TryStaticMemberPointerUpcast(Sema &Self, Expr *&SrcExpr, QualType SrcType, + QualType DestType, bool CStyle, + const SourceRange &OpRange, unsigned &msg, CastExpr::CastKind &Kind) { const MemberPointerType *DestMemPtr = DestType->getAs(); if (!DestMemPtr) return TC_NotApplicable; + + bool WasOverloadedFunction = false; + if (FunctionDecl *Fn + = Self.ResolveAddressOfOverloadedFunction(SrcExpr, DestType, false)) { + CXXMethodDecl *M = cast(Fn); + SrcType = Self.Context.getMemberPointerType(Fn->getType(), + Self.Context.getTypeDeclType(M->getParent()).getTypePtr()); + WasOverloadedFunction = true; + } + const MemberPointerType *SrcMemPtr = SrcType->getAs(); if (!SrcMemPtr) { msg = diag::err_bad_static_cast_member_pointer_nonmp; @@ -853,6 +865,24 @@ TryStaticMemberPointerUpcast(Sema &Self, QualType SrcType, QualType DestType, return TC_Failed; } + if (WasOverloadedFunction) { + // Resolve the address of the overloaded function again, this time + // allowing complaints if something goes wrong. + FunctionDecl *Fn = Self.ResolveAddressOfOverloadedFunction(SrcExpr, + DestType, + true); + if (!Fn) { + msg = 0; + return TC_Failed; + } + + SrcExpr = Self.FixOverloadedFunctionReference(SrcExpr, Fn); + if (!SrcExpr) { + msg = 0; + return TC_Failed; + } + } + Kind = CastExpr::CK_DerivedToBaseMemberPointer; return TC_Success; } diff --git a/lib/Sema/SemaCXXScopeSpec.cpp b/lib/Sema/SemaCXXScopeSpec.cpp index 971b78c..95b79ab 100644 --- a/lib/Sema/SemaCXXScopeSpec.cpp +++ b/lib/Sema/SemaCXXScopeSpec.cpp @@ -76,14 +76,6 @@ getCurrentInstantiationOf(ASTContext &Context, DeclContext *CurContext, // our context. if (Context.getCanonicalType(Context.getTypeDeclType(Record)) == T) return Record; - - if (ClassTemplateDecl *Template = Record->getDescribedClassTemplate()) { - QualType InjectedClassName - = Template->getInjectedClassNameType(Context); - if (T == Context.getCanonicalType(InjectedClassName)) - return Template->getTemplatedDecl(); - } - // FIXME: check for class template partial specializations } return 0; @@ -130,8 +122,11 @@ DeclContext *Sema::computeDeclContext(const CXXScopeSpec &SS, return Record; if (EnteringContext) { - if (const TemplateSpecializationType *SpecType - = dyn_cast_or_null(NNS->getAsType())) { + const Type *NNSType = NNS->getAsType(); + if (!NNSType) { + // do nothing, fall out + } else if (const TemplateSpecializationType *SpecType + = NNSType->getAs()) { // We are entering the context of the nested name specifier, so try to // match the nested name specifier to either a primary class template // or a class template partial specialization. @@ -144,7 +139,8 @@ DeclContext *Sema::computeDeclContext(const CXXScopeSpec &SS, // If the type of the nested name specifier is the same as the // injected class name of the named class template, we're entering // into that class template definition. - QualType Injected = ClassTemplate->getInjectedClassNameType(Context); + QualType Injected + = ClassTemplate->getInjectedClassNameSpecialization(Context); if (Context.hasSameType(Injected, ContextType)) return ClassTemplate->getTemplatedDecl(); @@ -156,8 +152,7 @@ DeclContext *Sema::computeDeclContext(const CXXScopeSpec &SS, = ClassTemplate->findPartialSpecialization(ContextType)) return PartialSpec; } - } else if (const RecordType *RecordT - = dyn_cast_or_null(NNS->getAsType())) { + } else if (const RecordType *RecordT = NNSType->getAs()) { // The nested name specifier refers to a member of a class template. return RecordT->getDecl(); } @@ -248,7 +243,7 @@ bool Sema::RequireCompleteDeclContext(const CXXScopeSpec &SS) { // If we're currently defining this type, then lookup into the // type is okay: don't complain that it isn't complete yet. const TagType *TagT = Context.getTypeDeclType(Tag)->getAs(); - if (TagT->isBeingDefined()) + if (TagT && TagT->isBeingDefined()) return false; // The type must be complete. diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index ec1939e..94fcfc6 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -188,18 +188,6 @@ Sema::TypeTy *Sema::getTypeName(IdentifierInfo &II, SourceLocation NameLoc, if (TypeDecl *TD = dyn_cast(IIDecl)) { DiagnoseUseOfDecl(IIDecl, NameLoc); - // C++ [temp.local]p2: - // Within the scope of a class template specialization or - // partial specialization, when the injected-class-name is - // not followed by a <, it is equivalent to the - // injected-class-name followed by the template-argument s - // of the class template specialization or partial - // specialization enclosed in <>. - if (CXXRecordDecl *RD = dyn_cast(TD)) - if (RD->isInjectedClassName()) - if (ClassTemplateDecl *Template = RD->getDescribedClassTemplate()) - T = Template->getInjectedClassNameType(Context); - if (T.isNull()) T = Context.getTypeDeclType(TD); @@ -1773,12 +1761,7 @@ DeclarationName Sema::GetNameFromUnqualifiedId(const UnqualifiedId &Name) { return DeclarationName(); // Determine the type of the class being constructed. - QualType CurClassType; - if (ClassTemplateDecl *ClassTemplate - = CurClass->getDescribedClassTemplate()) - CurClassType = ClassTemplate->getInjectedClassNameType(Context); - else - CurClassType = Context.getTypeDeclType(CurClass); + QualType CurClassType = Context.getTypeDeclType(CurClass); // FIXME: Check two things: that the template-id names the same type as // CurClassType, and that the template-id does not occur when the name @@ -3809,24 +3792,38 @@ void Sema::ActOnUninitializedDecl(DeclPtrTy dcl, return; } - InitializedEntity Entity = InitializedEntity::InitializeVariable(Var); - InitializationKind Kind - = InitializationKind::CreateDefault(Var->getLocation()); + const RecordType *Record + = Context.getBaseElementType(Type)->getAs(); + if (Record && getLangOptions().CPlusPlus && !getLangOptions().CPlusPlus0x && + cast(Record->getDecl())->isPOD()) { + // C++03 [dcl.init]p9: + // If no initializer is specified for an object, and the + // object is of (possibly cv-qualified) non-POD class type (or + // array thereof), the object shall be default-initialized; if + // the object is of const-qualified type, the underlying class + // type shall have a user-declared default + // constructor. Otherwise, if no initializer is specified for + // a non- static object, the object and its subobjects, if + // any, have an indeterminate initial value); if the object + // or any of its subobjects are of const-qualified type, the + // program is ill-formed. + // FIXME: DPG thinks it is very fishy that C++0x disables this. + } else { + InitializedEntity Entity = InitializedEntity::InitializeVariable(Var); + InitializationKind Kind + = InitializationKind::CreateDefault(Var->getLocation()); - InitializationSequence InitSeq(*this, Entity, Kind, 0, 0); - OwningExprResult Init = InitSeq.Perform(*this, Entity, Kind, - MultiExprArg(*this, 0, 0)); - if (Init.isInvalid()) - Var->setInvalidDecl(); - else { - if (Init.get()) + InitializationSequence InitSeq(*this, Entity, Kind, 0, 0); + OwningExprResult Init = InitSeq.Perform(*this, Entity, Kind, + MultiExprArg(*this, 0, 0)); + if (Init.isInvalid()) + Var->setInvalidDecl(); + else if (Init.get()) Var->setInit(MaybeCreateCXXExprWithTemporaries(Init.takeAs())); - - if (getLangOptions().CPlusPlus) - if (const RecordType *Record - = Context.getBaseElementType(Type)->getAs()) - FinalizeVarWithDestructor(Var, Record); } + + if (!Var->isInvalidDecl() && getLangOptions().CPlusPlus && Record) + FinalizeVarWithDestructor(Var, Record); } } @@ -5030,7 +5027,7 @@ void Sema::ActOnTagFinishDefinition(Scope *S, DeclPtrTy TagD, // Exit this scope of this tag's definition. PopDeclContext(); - if (isa(Tag) && !Tag->getDeclContext()->isRecord()) + if (isa(Tag) && !Tag->getLexicalDeclContext()->isRecord()) RecordDynamicClassesWithNoKeyFunction(*this, cast(Tag), RBraceLoc); diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 0708d41..e694cb4 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -665,22 +665,29 @@ void Sema::ActOnBaseSpecifiers(DeclPtrTy ClassDecl, BaseTy **Bases, (CXXBaseSpecifier**)(Bases), NumBases); } +static CXXRecordDecl *GetClassForType(QualType T) { + if (const RecordType *RT = T->getAs()) + return cast(RT->getDecl()); + else if (const InjectedClassNameType *ICT = T->getAs()) + return ICT->getDecl(); + else + return 0; +} + /// \brief Determine whether the type \p Derived is a C++ class that is /// derived from the type \p Base. bool Sema::IsDerivedFrom(QualType Derived, QualType Base) { if (!getLangOptions().CPlusPlus) return false; - - const RecordType *DerivedRT = Derived->getAs(); - if (!DerivedRT) + + CXXRecordDecl *DerivedRD = GetClassForType(Derived); + if (!DerivedRD) return false; - const RecordType *BaseRT = Base->getAs(); - if (!BaseRT) + CXXRecordDecl *BaseRD = GetClassForType(Base); + if (!BaseRD) return false; - CXXRecordDecl *DerivedRD = cast(DerivedRT->getDecl()); - CXXRecordDecl *BaseRD = cast(BaseRT->getDecl()); // FIXME: instantiate DerivedRD if necessary. We need a PoI for this. return DerivedRD->hasDefinition() && DerivedRD->isDerivedFrom(BaseRD); } @@ -691,16 +698,14 @@ bool Sema::IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths) { if (!getLangOptions().CPlusPlus) return false; - const RecordType *DerivedRT = Derived->getAs(); - if (!DerivedRT) + CXXRecordDecl *DerivedRD = GetClassForType(Derived); + if (!DerivedRD) return false; - const RecordType *BaseRT = Base->getAs(); - if (!BaseRT) + CXXRecordDecl *BaseRD = GetClassForType(Base); + if (!BaseRD) return false; - CXXRecordDecl *DerivedRD = cast(DerivedRT->getDecl()); - CXXRecordDecl *BaseRD = cast(BaseRT->getDecl()); return DerivedRD->isDerivedFrom(BaseRD, Paths); } @@ -1083,6 +1088,9 @@ Sema::ActOnMemInitializer(DeclPtrTy ConstructorD, // specialization, we take it as a type name. BaseType = CheckTypenameType((NestedNameSpecifier *)SS.getScopeRep(), *MemberOrBase, SS.getRange()); + if (BaseType.isNull()) + return true; + R.clear(); } } @@ -4526,20 +4534,23 @@ Sema::CheckReferenceInit(Expr *&Init, QualType DeclType, OverloadCandidateSet::iterator Best; switch (BestViableFunction(CandidateSet, DeclLoc, Best)) { case OR_Success: + // C++ [over.ics.ref]p1: + // + // [...] If the parameter binds directly to the result of + // applying a conversion function to the argument + // expression, the implicit conversion sequence is a + // user-defined conversion sequence (13.3.3.1.2), with the + // second standard conversion sequence either an identity + // conversion or, if the conversion function returns an + // entity of a type that is a derived class of the parameter + // type, a derived-to-base Conversion. + if (!Best->FinalConversion.DirectBinding) + break; + // This is a direct binding. BindsDirectly = true; if (ICS) { - // C++ [over.ics.ref]p1: - // - // [...] If the parameter binds directly to the result of - // applying a conversion function to the argument - // expression, the implicit conversion sequence is a - // user-defined conversion sequence (13.3.3.1.2), with the - // second standard conversion sequence either an identity - // conversion or, if the conversion function returns an - // entity of a type that is a derived class of the parameter - // type, a derived-to-base Conversion. ICS->setUserDefined(); ICS->UserDefined.Before = Best->Conversions[0].Standard; ICS->UserDefined.After = Best->FinalConversion; @@ -5189,21 +5200,28 @@ VarDecl *Sema::BuildExceptionDeclaration(Scope *S, QualType ExDeclType, Invalid = true; } + // GCC allows catching pointers and references to incomplete types + // as an extension; so do we, but we warn by default. + QualType BaseType = ExDeclType; int Mode = 0; // 0 for direct type, 1 for pointer, 2 for reference unsigned DK = diag::err_catch_incomplete; + bool IncompleteCatchIsInvalid = true; if (const PointerType *Ptr = BaseType->getAs()) { BaseType = Ptr->getPointeeType(); Mode = 1; - DK = diag::err_catch_incomplete_ptr; + DK = diag::ext_catch_incomplete_ptr; + IncompleteCatchIsInvalid = false; } else if (const ReferenceType *Ref = BaseType->getAs()) { // For the purpose of error recovery, we treat rvalue refs like lvalue refs. BaseType = Ref->getPointeeType(); Mode = 2; - DK = diag::err_catch_incomplete_ref; + DK = diag::ext_catch_incomplete_ref; + IncompleteCatchIsInvalid = false; } if (!Invalid && (Mode == 0 || !BaseType->isVoidType()) && - !BaseType->isDependentType() && RequireCompleteType(Loc, BaseType, DK)) + !BaseType->isDependentType() && RequireCompleteType(Loc, BaseType, DK) && + IncompleteCatchIsInvalid) Invalid = true; if (!Invalid && !ExDeclType->isDependentType() && @@ -5889,10 +5907,13 @@ void Sema::MaybeMarkVirtualMembersReferenced(SourceLocation Loc, // We will need to mark all of the virtual members as referenced to build the // vtable. - // We actually call MarkVirtualMembersReferenced instead of adding to - // ClassesWithUnmarkedVirtualMembers because this marking is needed by - // codegen that will happend before we finish parsing the file. - if (needsVtable(MD, Context)) + if (!needsVtable(MD, Context)) + return; + + TemplateSpecializationKind kind = RD->getTemplateSpecializationKind(); + if (kind == TSK_ImplicitInstantiation) + ClassesWithUnmarkedVirtualMembers.push_back(std::make_pair(RD, Loc)); + else MarkVirtualMembersReferenced(Loc, RD); } diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 149fe15..762ef38 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -1681,7 +1681,7 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property, // for this class. GetterMethod = ObjCMethodDecl::Create(Context, property->getLocation(), property->getLocation(), property->getGetterName(), - property->getType(), CD, true, false, true, + property->getType(), 0, CD, true, false, true, (property->getPropertyImplementation() == ObjCPropertyDecl::Optional) ? ObjCMethodDecl::Optional : @@ -1703,7 +1703,7 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property, SetterMethod = ObjCMethodDecl::Create(Context, property->getLocation(), property->getLocation(), property->getSetterName(), - Context.VoidTy, CD, true, false, true, + Context.VoidTy, 0, CD, true, false, true, (property->getPropertyImplementation() == ObjCPropertyDecl::Optional) ? ObjCMethodDecl::Optional : @@ -1992,8 +1992,9 @@ Sema::DeclPtrTy Sema::ActOnMethodDeclaration( } QualType resultDeclType; + TypeSourceInfo *ResultTInfo = 0; if (ReturnType) { - resultDeclType = GetTypeFromParser(ReturnType); + resultDeclType = GetTypeFromParser(ReturnType, &ResultTInfo); // Methods cannot return interface types. All ObjC objects are // passed by reference. @@ -2007,6 +2008,7 @@ Sema::DeclPtrTy Sema::ActOnMethodDeclaration( ObjCMethodDecl* ObjCMethod = ObjCMethodDecl::Create(Context, MethodLoc, EndLoc, Sel, resultDeclType, + ResultTInfo, cast(ClassDecl), MethodType == tok::minus, isVariadic, false, diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 10001c3..2249579 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -6593,7 +6593,8 @@ Sema::ActOnStmtExpr(SourceLocation LPLoc, StmtArg substmt, assert(SubStmt && isa(SubStmt) && "Invalid action invocation!"); CompoundStmt *Compound = cast(SubStmt); - bool isFileScope = getCurFunctionOrMethodDecl() == 0; + bool isFileScope + = (getCurFunctionOrMethodDecl() == 0) && (getCurBlock() == 0); if (isFileScope) return ExprError(Diag(LPLoc, diag::err_stmtexpr_file_scope)); diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 309da29..b9c8afa 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -172,14 +172,6 @@ Action::TypeTy *Sema::getDestructorName(SourceLocation TildeLoc, if (TypeDecl *Type = Found.getAsSingle()) { QualType T = Context.getTypeDeclType(Type); - // If we found the injected-class-name of a class template, retrieve the - // type of that template. - // FIXME: We really shouldn't need to do this. - if (CXXRecordDecl *Record = dyn_cast(Type)) - if (Record->isInjectedClassName()) - if (Record->getDescribedClassTemplate()) - T = Record->getDescribedClassTemplate() - ->getInjectedClassNameType(Context); if (SearchType.isNull() || SearchType->isDependentType() || Context.hasSameUnqualifiedType(T, SearchType)) { @@ -200,16 +192,8 @@ Action::TypeTy *Sema::getDestructorName(SourceLocation TildeLoc, if (SS.isSet()) { if (DeclContext *Ctx = computeDeclContext(SS, EnteringContext)) { // Figure out the type of the context, if it has one. - if (ClassTemplateSpecializationDecl *Spec - = dyn_cast(Ctx)) - MemberOfType = Context.getTypeDeclType(Spec); - else if (CXXRecordDecl *Record = dyn_cast(Ctx)) { - if (Record->getDescribedClassTemplate()) - MemberOfType = Record->getDescribedClassTemplate() - ->getInjectedClassNameType(Context); - else - MemberOfType = Context.getTypeDeclType(Record); - } + if (CXXRecordDecl *Record = dyn_cast(Ctx)) + MemberOfType = Context.getTypeDeclType(Record); } } if (MemberOfType.isNull()) diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 3a05241..c60455d 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -470,13 +470,13 @@ Sema::ExprResult Sema::ActOnClassMessage( // now, we simply pass the "super" identifier through (which isn't consistent // with instance methods. if (isSuper) - return new (Context) ObjCMessageExpr(Context, receiverName, Sel, returnType, - Method, lbrac, rbrac, ArgExprs, - NumArgs); + return new (Context) ObjCMessageExpr(Context, receiverName, receiverLoc, + Sel, returnType, Method, lbrac, rbrac, + ArgExprs, NumArgs); else - return new (Context) ObjCMessageExpr(Context, ClassDecl, Sel, returnType, - Method, lbrac, rbrac, ArgExprs, - NumArgs); + return new (Context) ObjCMessageExpr(Context, ClassDecl, receiverLoc, + Sel, returnType, Method, lbrac, rbrac, + ArgExprs, NumArgs); } // ActOnInstanceMessage - used for both unary and keyword messages. diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index bf9f73c..3540cd0 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -18,6 +18,7 @@ #include "SemaInit.h" #include "Lookup.h" #include "Sema.h" +#include "clang/Lex/Preprocessor.h" #include "clang/Parse/Designator.h" #include "clang/AST/ASTContext.h" #include "clang/AST/ExprCXX.h" @@ -497,6 +498,20 @@ void InitListChecker::CheckImplicitInitList(const InitializedEntity &Entity, = ParentIList->getInit(EndIndex)->getSourceRange().getEnd(); StructuredSubobjectInitList->setRBraceLoc(EndLoc); } + + // Warn about missing braces. + if (T->isArrayType() || T->isRecordType()) { + SemaRef.Diag(StructuredSubobjectInitList->getLocStart(), + diag::warn_missing_braces) + << StructuredSubobjectInitList->getSourceRange() + << CodeModificationHint::CreateInsertion( + StructuredSubobjectInitList->getLocStart(), + "{") + << CodeModificationHint::CreateInsertion( + SemaRef.PP.getLocForEndOfToken( + StructuredSubobjectInitList->getLocEnd()), + "}"); + } } void InitListChecker::CheckExplicitInitList(const InitializedEntity &Entity, @@ -2258,10 +2273,17 @@ static OverloadingResult TryRefInitWithConversionFunction(Sema &S, Sema::ReferenceCompareResult NewRefRelationship = S.CompareReferenceRelationship(DeclLoc, T1, T2.getNonReferenceType(), NewDerivedToBase); - assert(NewRefRelationship != Sema::Ref_Incompatible && - "Overload resolution picked a bad conversion function"); - (void)NewRefRelationship; - if (NewDerivedToBase) + if (NewRefRelationship == Sema::Ref_Incompatible) { + // If the type we've converted to is not reference-related to the + // type we're looking for, then there is another conversion step + // we need to perform to produce a temporary of the right type + // that we'll be binding to. + ImplicitConversionSequence ICS; + ICS.setStandard(); + ICS.Standard = Best->FinalConversion; + T2 = ICS.Standard.getToType(2); + Sequence.AddConversionSequenceStep(ICS, T2); + } else if (NewDerivedToBase) Sequence.AddDerivedToBaseCastStep( S.Context.getQualifiedType(T1, T2.getNonReferenceType().getQualifiers()), diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 0321958..7c4cab1 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -871,10 +871,8 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, NewClass->setDescribedClassTemplate(NewTemplate); // Build the type for the class template declaration now. - QualType T = - Context.getTypeDeclType(NewClass, - PrevClassTemplate? - PrevClassTemplate->getTemplatedDecl() : 0); + QualType T = NewTemplate->getInjectedClassNameSpecialization(Context); + T = Context.getInjectedClassNameType(NewClass, T); assert(T->isDependentType() && "Class template type is not dependent?"); (void)T; @@ -1306,7 +1304,7 @@ Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, TemplateParameterList *ExpectedTemplateParams = 0; // Is this template-id naming the primary template? if (Context.hasSameType(TemplateId, - ClassTemplate->getInjectedClassNameType(Context))) + ClassTemplate->getInjectedClassNameSpecialization(Context))) ExpectedTemplateParams = ClassTemplate->getTemplateParameters(); // ... or a partial specialization? else if (ClassTemplatePartialSpecializationDecl *PartialSpec @@ -1431,6 +1429,8 @@ QualType Sema::CheckTemplateIdType(TemplateName Name, } CanonType = Context.getTypeDeclType(Decl); + assert(isa(CanonType) && + "type of non-dependent specialization is not a RecordType"); } // Build the fully-sugared type for this class template @@ -3488,6 +3488,7 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, ClassTemplate, Converted, TemplateArgs, + CanonType, PrevPartial); if (PrevPartial) { @@ -3609,8 +3610,9 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, // actually wrote the specialization, rather than formatting the // name based on the "canonical" representation used to store the // template arguments in the specialization. - QualType WrittenTy - = Context.getTemplateSpecializationType(Name, TemplateArgs, CanonType); + TypeSourceInfo *WrittenTy + = Context.getTemplateSpecializationTypeInfo(Name, TemplateNameLoc, + TemplateArgs, CanonType); if (TUK != TUK_Friend) Specialization->setTypeAsWritten(WrittenTy); TemplateArgsIn.release(); @@ -3632,7 +3634,7 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, if (TUK == TUK_Friend) { FriendDecl *Friend = FriendDecl::Create(Context, CurContext, TemplateNameLoc, - WrittenTy.getTypePtr(), + WrittenTy->getType().getTypePtr(), /*FIXME:*/KWLoc); Friend->setAccess(AS_public); CurContext->addDecl(Friend); @@ -4344,8 +4346,9 @@ Sema::ActOnExplicitInstantiation(Scope *S, // the explicit instantiation, rather than formatting the name based // on the "canonical" representation used to store the template // arguments in the specialization. - QualType WrittenTy - = Context.getTemplateSpecializationType(Name, TemplateArgs, + TypeSourceInfo *WrittenTy + = Context.getTemplateSpecializationTypeInfo(Name, TemplateNameLoc, + TemplateArgs, Context.getTypeDeclType(Specialization)); Specialization->setTypeAsWritten(WrittenTy); TemplateArgsIn.release(); @@ -4992,6 +4995,9 @@ CurrentInstantiationRebuilder::TransformTypenameType(TypeLocBuilder &TLB, Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SourceRange(TL.getNameLoc())); + if (Result.isNull()) + return QualType(); + TypenameTypeLoc NewTL = TLB.push(Result); NewTL.setNameLoc(TL.getNameLoc()); return Result; diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index 7f16400..326519d 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -625,6 +625,15 @@ DeduceTemplateArguments(Sema &S, return Sema::TDK_Success; } + case Type::InjectedClassName: { + // Treat a template's injected-class-name as if the template + // specialization type had been used. + Param = cast(Param)->getUnderlyingType(); + assert(isa(Param) && + "injected class name is not a template specialization type"); + // fall through + } + // template-name (where template-name refers to a class template) // template-name // TT diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 3a6b4cb..cf8d38c 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -621,7 +621,8 @@ Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) { Inst->setInstantiatedFromMemberTemplate(D); // Trigger creation of the type for the instantiation. - SemaRef.Context.getTypeDeclType(RecordInst); + SemaRef.Context.getInjectedClassNameType(RecordInst, + Inst->getInjectedClassNameSpecialization(SemaRef.Context)); // Finish handling of friends. if (Inst->getFriendObjectKind()) { @@ -1462,8 +1463,10 @@ TemplateDeclInstantiator::InstantiateClassTemplatePartialSpecialization( // actually wrote the specialization, rather than formatting the // name based on the "canonical" representation used to store the // template arguments in the specialization. - QualType WrittenTy - = SemaRef.Context.getTemplateSpecializationType(TemplateName(ClassTemplate), + TypeSourceInfo *WrittenTy + = SemaRef.Context.getTemplateSpecializationTypeInfo( + TemplateName(ClassTemplate), + PartialSpec->getLocation(), InstTemplateArgs, CanonType); @@ -1499,6 +1502,7 @@ TemplateDeclInstantiator::InstantiateClassTemplatePartialSpecialization( ClassTemplate, Converted, InstTemplateArgs, + CanonType, 0); InstPartialSpec->setInstantiatedFromMember(PartialSpec); InstPartialSpec->setTypeAsWritten(WrittenTy); @@ -2236,12 +2240,18 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, ClassTemplateDecl *ClassTemplate = Record->getDescribedClassTemplate(); if (ClassTemplate) { - T = ClassTemplate->getInjectedClassNameType(Context); + T = ClassTemplate->getInjectedClassNameSpecialization(Context); } else if (ClassTemplatePartialSpecializationDecl *PartialSpec = dyn_cast(Record)) { - T = Context.getTypeDeclType(Record); ClassTemplate = PartialSpec->getSpecializedTemplate(); - } + + // If we call SubstType with an InjectedClassNameType here we + // can end up in an infinite loop. + T = Context.getTypeDeclType(Record); + assert(isa(T) && + "type of partial specialization is not an InjectedClassNameType"); + T = cast(T)->getUnderlyingType(); + } if (!T.isNull()) { // Substitute into the injected-class-name to get the type @@ -2308,16 +2318,16 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, // so now we need to look into the instantiated parent context to // find the instantiation of the declaration D. - // If our context is a class template specialization, we may need - // to instantiate it before performing lookup into that context. - if (ClassTemplateSpecializationDecl *Spec - = dyn_cast(ParentDC)) { + // If our context used to be dependent, we may need to instantiate + // it before performing lookup into that context. + if (CXXRecordDecl *Spec = dyn_cast(ParentDC)) { if (!Spec->isDependentContext()) { QualType T = Context.getTypeDeclType(Spec); - if (const TagType *Tag = T->getAs()) - if (!Tag->isBeingDefined() && - RequireCompleteType(Loc, T, diag::err_incomplete_type)) - return 0; + const RecordType *Tag = T->getAs(); + assert(Tag && "type of non-dependent record is not a RecordType"); + if (!Tag->isBeingDefined() && + RequireCompleteType(Loc, T, diag::err_incomplete_type)) + return 0; } } diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 24ea62c..17f9419 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -2823,6 +2823,20 @@ QualType TreeTransform::TransformElaboratedType(TypeLocBuilder &TLB, return Result; } +template +QualType TreeTransform::TransformInjectedClassNameType( + TypeLocBuilder &TLB, + InjectedClassNameTypeLoc TL, + QualType ObjectType) { + Decl *D = getDerived().TransformDecl(TL.getNameLoc(), + TL.getTypePtr()->getDecl()); + if (!D) return QualType(); + + QualType T = SemaRef.Context.getTypeDeclType(cast(D)); + TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); + return T; +} + template QualType TreeTransform::TransformTemplateTypeParmType( -- cgit v1.1