diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2023-02-11 12:38:04 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-02-11 12:38:11 +0000 |
commit | e3b557809604d036af6e00c60f012c2025b59a5e (patch) | |
tree | 8a11ba2269a3b669601e2fd41145b174008f4da8 /clang/lib/Analysis/ThreadSafetyCommon.cpp | |
parent | 08e8dd7b9db7bb4a9de26d44c1cbfd24e869c014 (diff) |
Diffstat (limited to 'clang/lib/Analysis/ThreadSafetyCommon.cpp')
-rw-r--r-- | clang/lib/Analysis/ThreadSafetyCommon.cpp | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/clang/lib/Analysis/ThreadSafetyCommon.cpp b/clang/lib/Analysis/ThreadSafetyCommon.cpp index 66413f84907a..a771149f1591 100644 --- a/clang/lib/Analysis/ThreadSafetyCommon.cpp +++ b/clang/lib/Analysis/ThreadSafetyCommon.cpp @@ -115,19 +115,22 @@ static StringRef ClassifyDiagnostic(QualType VDT) { /// \param D The declaration to which the attribute is attached. /// \param DeclExp An expression involving the Decl to which the attribute /// is attached. E.g. the call to a function. +/// \param Self S-expression to substitute for a \ref CXXThisExpr. CapabilityExpr SExprBuilder::translateAttrExpr(const Expr *AttrExp, const NamedDecl *D, const Expr *DeclExp, - VarDecl *SelfDecl) { + til::SExpr *Self) { // If we are processing a raw attribute expression, with no substitutions. - if (!DeclExp) + if (!DeclExp && !Self) return translateAttrExpr(AttrExp, nullptr); CallingContext Ctx(nullptr, D); // Examine DeclExp to find SelfArg and FunArgs, which are used to substitute // for formal parameters when we call buildMutexID later. - if (const auto *ME = dyn_cast<MemberExpr>(DeclExp)) { + if (!DeclExp) + /* We'll use Self. */; + else if (const auto *ME = dyn_cast<MemberExpr>(DeclExp)) { Ctx.SelfArg = ME->getBase(); Ctx.SelfArrow = ME->isArrow(); } else if (const auto *CE = dyn_cast<CXXMemberCallExpr>(DeclExp)) { @@ -142,29 +145,24 @@ CapabilityExpr SExprBuilder::translateAttrExpr(const Expr *AttrExp, Ctx.SelfArg = nullptr; // Will be set below Ctx.NumArgs = CE->getNumArgs(); Ctx.FunArgs = CE->getArgs(); - } else if (D && isa<CXXDestructorDecl>(D)) { - // There's no such thing as a "destructor call" in the AST. - Ctx.SelfArg = DeclExp; } - // Hack to handle constructors, where self cannot be recovered from - // the expression. - if (SelfDecl && !Ctx.SelfArg) { - DeclRefExpr SelfDRE(SelfDecl->getASTContext(), SelfDecl, false, - SelfDecl->getType(), VK_LValue, - SelfDecl->getLocation()); - Ctx.SelfArg = &SelfDRE; + if (Self) { + assert(!Ctx.SelfArg && "Ambiguous self argument"); + Ctx.SelfArg = Self; // If the attribute has no arguments, then assume the argument is "this". if (!AttrExp) - return translateAttrExpr(Ctx.SelfArg, nullptr); + return CapabilityExpr( + Self, ClassifyDiagnostic(cast<CXXMethodDecl>(D)->getThisObjectType()), + false); else // For most attributes. return translateAttrExpr(AttrExp, &Ctx); } // If the attribute has no arguments, then assume the argument is "this". if (!AttrExp) - return translateAttrExpr(Ctx.SelfArg, nullptr); + return translateAttrExpr(cast<const Expr *>(Ctx.SelfArg), nullptr); else // For most attributes. return translateAttrExpr(AttrExp, &Ctx); } @@ -218,6 +216,16 @@ CapabilityExpr SExprBuilder::translateAttrExpr(const Expr *AttrExp, return CapabilityExpr(E, Kind, Neg); } +til::LiteralPtr *SExprBuilder::createVariable(const VarDecl *VD) { + return new (Arena) til::LiteralPtr(VD); +} + +std::pair<til::LiteralPtr *, StringRef> +SExprBuilder::createThisPlaceholder(const Expr *Exp) { + return {new (Arena) til::LiteralPtr(nullptr), + ClassifyDiagnostic(Exp->getType())}; +} + // Translate a clang statement or expression to a TIL expression. // Also performs substitution of variables; Ctx provides the context. // Dispatches on the type of S. @@ -327,8 +335,12 @@ til::SExpr *SExprBuilder::translateDeclRefExpr(const DeclRefExpr *DRE, til::SExpr *SExprBuilder::translateCXXThisExpr(const CXXThisExpr *TE, CallingContext *Ctx) { // Substitute for 'this' - if (Ctx && Ctx->SelfArg) - return translate(Ctx->SelfArg, Ctx->Prev); + if (Ctx && Ctx->SelfArg) { + if (const auto *SelfArg = dyn_cast<const Expr *>(Ctx->SelfArg)) + return translate(SelfArg, Ctx->Prev); + else + return cast<til::SExpr *>(Ctx->SelfArg); + } assert(SelfVar && "We have no variable for 'this'!"); return SelfVar; } @@ -637,7 +649,7 @@ SExprBuilder::translateAbstractConditionalOperator( til::SExpr * SExprBuilder::translateDeclStmt(const DeclStmt *S, CallingContext *Ctx) { DeclGroupRef DGrp = S->getDeclGroup(); - for (auto I : DGrp) { + for (auto *I : DGrp) { if (auto *VD = dyn_cast_or_null<VarDecl>(I)) { Expr *E = VD->getInit(); til::SExpr* SE = translate(E, Ctx); |