[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)
Aaron Puchert via cfe-commits
cfe-commits at lists.llvm.org
Thu May 8 15:48:06 PDT 2025
================
@@ -1011,6 +979,30 @@ void SExprBuilder::exitCFG(const CFGBlock *Last) {
IncompleteArgs.clear();
}
+static CapabilityExpr makeCapabilityExpr(const til::SExpr *E, QualType VDT,
+ bool Neg) {
+ // We need to look at the declaration of the type of the value to determine
+ // which it is. The type should either be a record or a typedef, or a pointer
+ // or reference thereof.
+ if (const auto *RT = VDT->getAs<RecordType>()) {
+ if (const auto *RD = RT->getDecl())
+ if (const auto *CA = RD->getAttr<CapabilityAttr>())
+ return CapabilityExpr(E, CA->getName(), Neg,
+ RD->hasAttr<ReentrantCapabilityAttr>());
+ } else if (const auto *TT = VDT->getAs<TypedefType>()) {
+ if (const auto *TD = TT->getDecl())
+ if (const auto *CA = TD->getAttr<CapabilityAttr>())
+ return CapabilityExpr(E, CA->getName(), Neg,
+ TD->hasAttr<ReentrantCapabilityAttr>());
+ } else if (VDT->isPointerOrReferenceType())
+ return makeCapabilityExpr(E, VDT->getPointeeType(), Neg);
+
+ return CapabilityExpr(E, StringRef("mutex"), Neg, false);
+}
+
+CapabilityExpr::CapabilityExpr(const til::SExpr *E, QualType QT, bool Neg)
+ : CapabilityExpr(makeCapabilityExpr(E, QT, Neg)) {}
----------------
aaronpuchert wrote:
In the header, `CapabilityExpr` seems to come before `SExprBuilder`, so this should probably also come before `SExprBuilder` functions. Or at least before `translateAttrExpr`, so that we can leave the classification in place.
https://github.com/llvm/llvm-project/pull/137133
More information about the cfe-commits
mailing list