diff options
| author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2011-03-13 17:09:40 +0000 |
|---|---|---|
| committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2011-03-13 17:09:40 +0000 |
| commit | 31ad754c96673eefe89baf6994fe2c040f1b3dd7 (patch) | |
| tree | 76ac239f6c78c93339c8b1e1a6de24133ffb82af /clang/lib/AST | |
| parent | 72216105433f8cde20b3314322cd6bb8e3a65ba1 (diff) | |
| download | bcm5719-llvm-31ad754c96673eefe89baf6994fe2c040f1b3dd7.tar.gz bcm5719-llvm-31ad754c96673eefe89baf6994fe2c040f1b3dd7.zip | |
Instead of storing an ASTContext* in FunctionProtoTypes with computed noexcept specifiers, unique FunctionProtoTypes with a ContextualFoldingSet, as suggested by John McCall.
llvm-svn: 127568
Diffstat (limited to 'clang/lib/AST')
| -rw-r--r-- | clang/lib/AST/ASTContext.cpp | 8 | ||||
| -rw-r--r-- | clang/lib/AST/Expr.cpp | 18 | ||||
| -rw-r--r-- | clang/lib/AST/ExprCXX.cpp | 4 | ||||
| -rw-r--r-- | clang/lib/AST/Type.cpp | 18 |
4 files changed, 22 insertions, 26 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index c128ce598bd..0526ebb5cb0 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -195,6 +195,7 @@ ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM, IdentifierTable &idents, SelectorTable &sels, Builtin::Context &builtins, unsigned size_reserve) : + FunctionProtoTypes(this_()), TemplateSpecializationTypes(this_()), DependentTemplateSpecializationTypes(this_()), GlobalNestedNameSpecifier(0), IsInt128Installed(false), @@ -1909,7 +1910,7 @@ ASTContext::getFunctionType(QualType ResultTy, // Unique functions, to guarantee there is only one function of a particular // structure. llvm::FoldingSetNodeID ID; - FunctionProtoType::Profile(ID, ResultTy, ArgArray, NumArgs, EPI, this); + FunctionProtoType::Profile(ID, ResultTy, ArgArray, NumArgs, EPI, *this); void *InsertPos = 0; if (FunctionProtoType *FTP = @@ -1960,13 +1961,12 @@ ASTContext::getFunctionType(QualType ResultTy, if (EPI.ExceptionSpecType == EST_Dynamic) Size += EPI.NumExceptions * sizeof(QualType); else if (EPI.ExceptionSpecType == EST_ComputedNoexcept) { - Size += sizeof(Expr*) + sizeof(ASTContext*); + Size += sizeof(Expr*); } FunctionProtoType *FTP = (FunctionProtoType*) Allocate(Size, TypeAlignment); FunctionProtoType::ExtProtoInfo newEPI = EPI; newEPI.ExtInfo = EPI.ExtInfo.withCallingConv(CallConv); - new (FTP) FunctionProtoType(ResultTy, ArgArray, NumArgs, Canonical, newEPI, - this); + new (FTP) FunctionProtoType(ResultTy, ArgArray, NumArgs, Canonical, newEPI); Types.push_back(FTP); FunctionProtoTypes.InsertNode(FTP, InsertPos); return QualType(FTP, 0); diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 1c7807e6d20..9c4444225ee 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -1629,7 +1629,7 @@ static Expr::CanThrowResult CanSubExprsThrow(ASTContext &C, const Expr *CE) { return R; } -static Expr::CanThrowResult CanCalleeThrow(const Decl *D, +static Expr::CanThrowResult CanCalleeThrow(ASTContext &Ctx, const Decl *D, bool NullThrows = true) { if (!D) return NullThrows ? Expr::CT_Can : Expr::CT_Cannot; @@ -1659,7 +1659,7 @@ static Expr::CanThrowResult CanCalleeThrow(const Decl *D, if (!FT) return Expr::CT_Can; - return FT->isNothrow() ? Expr::CT_Cannot : Expr::CT_Can; + return FT->isNothrow(Ctx) ? Expr::CT_Cannot : Expr::CT_Can; } static Expr::CanThrowResult CanDynamicCastThrow(const CXXDynamicCastExpr *DC) { @@ -1723,7 +1723,7 @@ Expr::CanThrowResult Expr::CanThrow(ASTContext &C) const { case CallExprClass: case CXXOperatorCallExprClass: case CXXMemberCallExprClass: { - CanThrowResult CT = CanCalleeThrow(cast<CallExpr>(this)->getCalleeDecl()); + CanThrowResult CT = CanCalleeThrow(C,cast<CallExpr>(this)->getCalleeDecl()); if (CT == CT_Can) return CT; return MergeCanThrow(CT, CanSubExprsThrow(C, this)); @@ -1731,7 +1731,7 @@ Expr::CanThrowResult Expr::CanThrow(ASTContext &C) const { case CXXConstructExprClass: case CXXTemporaryObjectExprClass: { - CanThrowResult CT = CanCalleeThrow( + CanThrowResult CT = CanCalleeThrow(C, cast<CXXConstructExpr>(this)->getConstructor()); if (CT == CT_Can) return CT; @@ -1740,8 +1740,8 @@ Expr::CanThrowResult Expr::CanThrow(ASTContext &C) const { case CXXNewExprClass: { CanThrowResult CT = MergeCanThrow( - CanCalleeThrow(cast<CXXNewExpr>(this)->getOperatorNew()), - CanCalleeThrow(cast<CXXNewExpr>(this)->getConstructor(), + CanCalleeThrow(C, cast<CXXNewExpr>(this)->getOperatorNew()), + CanCalleeThrow(C, cast<CXXNewExpr>(this)->getConstructor(), /*NullThrows*/false)); if (CT == CT_Can) return CT; @@ -1749,7 +1749,7 @@ Expr::CanThrowResult Expr::CanThrow(ASTContext &C) const { } case CXXDeleteExprClass: { - CanThrowResult CT = CanCalleeThrow( + CanThrowResult CT = CanCalleeThrow(C, cast<CXXDeleteExpr>(this)->getOperatorDelete()); if (CT == CT_Can) return CT; @@ -1759,7 +1759,7 @@ Expr::CanThrowResult Expr::CanThrow(ASTContext &C) const { Arg = Cast->getSubExpr(); if (const PointerType *PT = Arg->getType()->getAs<PointerType>()) { if (const RecordType *RT = PT->getPointeeType()->getAs<RecordType>()) { - CanThrowResult CT2 = CanCalleeThrow( + CanThrowResult CT2 = CanCalleeThrow(C, cast<CXXRecordDecl>(RT->getDecl())->getDestructor()); if (CT2 == CT_Can) return CT2; @@ -1771,7 +1771,7 @@ Expr::CanThrowResult Expr::CanThrow(ASTContext &C) const { case CXXBindTemporaryExprClass: { // The bound temporary has to be destroyed again, which might throw. - CanThrowResult CT = CanCalleeThrow( + CanThrowResult CT = CanCalleeThrow(C, cast<CXXBindTemporaryExpr>(this)->getTemporary()->getDestructor()); if (CT == CT_Can) return CT; diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp index fd94dd108db..35c2d410082 100644 --- a/clang/lib/AST/ExprCXX.cpp +++ b/clang/lib/AST/ExprCXX.cpp @@ -100,9 +100,9 @@ void CXXNewExpr::AllocateArgsArray(ASTContext &C, bool isArray, SubExprs = new (C) Stmt*[TotalSize]; } -bool CXXNewExpr::shouldNullCheckAllocation() const { +bool CXXNewExpr::shouldNullCheckAllocation(ASTContext &Ctx) const { return getOperatorNew()->getType()-> - castAs<FunctionProtoType>()->isNothrow(); + castAs<FunctionProtoType>()->isNothrow(Ctx); } // CXXDeleteExpr diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index eb5254e96e9..1e2a6c48fdd 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -1166,8 +1166,7 @@ llvm::StringRef FunctionType::getNameForCallConv(CallingConv CC) { FunctionProtoType::FunctionProtoType(QualType result, const QualType *args, unsigned numArgs, QualType canonical, - const ExtProtoInfo &epi, - const ASTContext *context) + const ExtProtoInfo &epi) : FunctionType(FunctionProto, result, epi.Variadic, epi.TypeQuals, epi.RefQualifier, canonical, result->isDependentType(), @@ -1205,14 +1204,11 @@ FunctionProtoType::FunctionProtoType(QualType result, const QualType *args, // Store the noexcept expression and context. Expr **noexSlot = reinterpret_cast<Expr**>(argSlot + numArgs); *noexSlot = epi.NoexceptExpr; - const ASTContext **contextSlot = const_cast<const ASTContext**>( - reinterpret_cast<ASTContext**>(noexSlot + 1)); - *contextSlot = context; } } FunctionProtoType::NoexceptResult -FunctionProtoType::getNoexceptSpec() const { +FunctionProtoType::getNoexceptSpec(ASTContext &ctx) const { ExceptionSpecificationType est = getExceptionSpecType(); if (est == EST_BasicNoexcept) return NR_Nothrow; @@ -1227,7 +1223,6 @@ FunctionProtoType::getNoexceptSpec() const { return NR_Dependent; llvm::APSInt value; - ASTContext& ctx = const_cast<ASTContext&>(*getContext()); bool isICE = noexceptExpr->isIntegerConstantExpr(value, ctx, 0, /*evaluated*/false); (void)isICE; @@ -1247,7 +1242,7 @@ bool FunctionProtoType::isTemplateVariadic() const { void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result, const QualType *ArgTys, unsigned NumArgs, const ExtProtoInfo &epi, - const ASTContext *Context) { + const ASTContext &Context) { ID.AddPointer(Result.getAsOpaquePtr()); for (unsigned i = 0; i != NumArgs; ++i) ID.AddPointer(ArgTys[i].getAsOpaquePtr()); @@ -1259,14 +1254,15 @@ void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result, for (unsigned i = 0; i != epi.NumExceptions; ++i) ID.AddPointer(epi.Exceptions[i].getAsOpaquePtr()); } else if (epi.ExceptionSpecType == EST_ComputedNoexcept && epi.NoexceptExpr){ - epi.NoexceptExpr->Profile(ID, *Context, true); + epi.NoexceptExpr->Profile(ID, Context, true); } epi.ExtInfo.Profile(ID); } -void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID) { +void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, + const ASTContext &Ctx) { Profile(ID, getResultType(), arg_type_begin(), NumArgs, getExtProtoInfo(), - getContext()); + Ctx); } QualType TypedefType::desugar() const { |

