Skip to content

Commit f703774

Browse files
authored
Revert "[clang analysis][NFCI] Preparatory work for D153131. (llvm#67420)" (llvm#67523)
There was a misunderstanding as to whether we wanted those base NFC changes or not. This reverts commit 166074e.
1 parent a904bb4 commit f703774

File tree

1 file changed

+61
-72
lines changed

1 file changed

+61
-72
lines changed

clang/lib/Analysis/ThreadSafety.cpp

Lines changed: 61 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,19 +1015,6 @@ class ThreadSafetyAnalyzer {
10151015

10161016
BeforeSet *GlobalBeforeSet;
10171017

1018-
void warnIfMutexNotHeld(const FactSet &FSet, const NamedDecl *D,
1019-
const Expr *Exp, AccessKind AK, Expr *MutexExp,
1020-
ProtectedOperationKind POK, til::LiteralPtr *Self,
1021-
SourceLocation Loc);
1022-
void warnIfMutexHeld(const FactSet &FSet, const NamedDecl *D, const Expr *Exp,
1023-
Expr *MutexExp, til::LiteralPtr *Self,
1024-
SourceLocation Loc);
1025-
1026-
void checkAccess(const FactSet &FSet, const Expr *Exp, AccessKind AK,
1027-
ProtectedOperationKind POK);
1028-
void checkPtAccess(const FactSet &FSet, const Expr *Exp, AccessKind AK,
1029-
ProtectedOperationKind POK);
1030-
10311018
public:
10321019
ThreadSafetyAnalyzer(ThreadSafetyHandler &H, BeforeSet* Bset)
10331020
: Arena(&Bpa), SxBuilder(Arena), Handler(H), GlobalBeforeSet(Bset) {}
@@ -1547,15 +1534,16 @@ class BuildLockset : public ConstStmtVisitor<BuildLockset> {
15471534
unsigned CtxIndex;
15481535

15491536
// helper functions
1537+
void warnIfMutexNotHeld(const NamedDecl *D, const Expr *Exp, AccessKind AK,
1538+
Expr *MutexExp, ProtectedOperationKind POK,
1539+
til::LiteralPtr *Self, SourceLocation Loc);
1540+
void warnIfMutexHeld(const NamedDecl *D, const Expr *Exp, Expr *MutexExp,
1541+
til::LiteralPtr *Self, SourceLocation Loc);
15501542

15511543
void checkAccess(const Expr *Exp, AccessKind AK,
1552-
ProtectedOperationKind POK = POK_VarAccess) {
1553-
Analyzer->checkAccess(FSet, Exp, AK, POK);
1554-
}
1544+
ProtectedOperationKind POK = POK_VarAccess);
15551545
void checkPtAccess(const Expr *Exp, AccessKind AK,
1556-
ProtectedOperationKind POK = POK_VarAccess) {
1557-
Analyzer->checkPtAccess(FSet, Exp, AK, POK);
1558-
}
1546+
ProtectedOperationKind POK = POK_VarAccess);
15591547

15601548
void handleCall(const Expr *Exp, const NamedDecl *D,
15611549
til::LiteralPtr *Self = nullptr,
@@ -1583,82 +1571,86 @@ class BuildLockset : public ConstStmtVisitor<BuildLockset> {
15831571

15841572
/// Warn if the LSet does not contain a lock sufficient to protect access
15851573
/// of at least the passed in AccessKind.
1586-
void ThreadSafetyAnalyzer::warnIfMutexNotHeld(
1587-
const FactSet &FSet, const NamedDecl *D, const Expr *Exp, AccessKind AK,
1588-
Expr *MutexExp, ProtectedOperationKind POK, til::LiteralPtr *Self,
1589-
SourceLocation Loc) {
1574+
void BuildLockset::warnIfMutexNotHeld(const NamedDecl *D, const Expr *Exp,
1575+
AccessKind AK, Expr *MutexExp,
1576+
ProtectedOperationKind POK,
1577+
til::LiteralPtr *Self,
1578+
SourceLocation Loc) {
15901579
LockKind LK = getLockKindFromAccessKind(AK);
1591-
CapabilityExpr Cp = SxBuilder.translateAttrExpr(MutexExp, D, Exp, Self);
1580+
1581+
CapabilityExpr Cp =
1582+
Analyzer->SxBuilder.translateAttrExpr(MutexExp, D, Exp, Self);
15921583
if (Cp.isInvalid()) {
1593-
warnInvalidLock(Handler, MutexExp, D, Exp, Cp.getKind());
1584+
warnInvalidLock(Analyzer->Handler, MutexExp, D, Exp, Cp.getKind());
15941585
return;
15951586
} else if (Cp.shouldIgnore()) {
15961587
return;
15971588
}
15981589

15991590
if (Cp.negative()) {
16001591
// Negative capabilities act like locks excluded
1601-
const FactEntry *LDat = FSet.findLock(FactMan, !Cp);
1592+
const FactEntry *LDat = FSet.findLock(Analyzer->FactMan, !Cp);
16021593
if (LDat) {
1603-
Handler.handleFunExcludesLock(Cp.getKind(), D->getNameAsString(),
1604-
(!Cp).toString(), Loc);
1605-
return;
1594+
Analyzer->Handler.handleFunExcludesLock(
1595+
Cp.getKind(), D->getNameAsString(), (!Cp).toString(), Loc);
1596+
return;
16061597
}
16071598

16081599
// If this does not refer to a negative capability in the same class,
16091600
// then stop here.
1610-
if (!inCurrentScope(Cp))
1611-
return;
1601+
if (!Analyzer->inCurrentScope(Cp))
1602+
return;
16121603

16131604
// Otherwise the negative requirement must be propagated to the caller.
1614-
LDat = FSet.findLock(FactMan, Cp);
1605+
LDat = FSet.findLock(Analyzer->FactMan, Cp);
16151606
if (!LDat) {
1616-
Handler.handleNegativeNotHeld(D, Cp.toString(), Loc);
1607+
Analyzer->Handler.handleNegativeNotHeld(D, Cp.toString(), Loc);
16171608
}
16181609
return;
16191610
}
16201611

1621-
const FactEntry *LDat = FSet.findLockUniv(FactMan, Cp);
1612+
const FactEntry *LDat = FSet.findLockUniv(Analyzer->FactMan, Cp);
16221613
bool NoError = true;
16231614
if (!LDat) {
16241615
// No exact match found. Look for a partial match.
1625-
LDat = FSet.findPartialMatch(FactMan, Cp);
1616+
LDat = FSet.findPartialMatch(Analyzer->FactMan, Cp);
16261617
if (LDat) {
16271618
// Warn that there's no precise match.
16281619
std::string PartMatchStr = LDat->toString();
16291620
StringRef PartMatchName(PartMatchStr);
1630-
Handler.handleMutexNotHeld(Cp.getKind(), D, POK, Cp.toString(), LK, Loc,
1631-
&PartMatchName);
1621+
Analyzer->Handler.handleMutexNotHeld(Cp.getKind(), D, POK, Cp.toString(),
1622+
LK, Loc, &PartMatchName);
16321623
} else {
16331624
// Warn that there's no match at all.
1634-
Handler.handleMutexNotHeld(Cp.getKind(), D, POK, Cp.toString(), LK, Loc);
1625+
Analyzer->Handler.handleMutexNotHeld(Cp.getKind(), D, POK, Cp.toString(),
1626+
LK, Loc);
16351627
}
16361628
NoError = false;
16371629
}
16381630
// Make sure the mutex we found is the right kind.
16391631
if (NoError && LDat && !LDat->isAtLeast(LK)) {
1640-
Handler.handleMutexNotHeld(Cp.getKind(), D, POK, Cp.toString(), LK, Loc);
1632+
Analyzer->Handler.handleMutexNotHeld(Cp.getKind(), D, POK, Cp.toString(),
1633+
LK, Loc);
16411634
}
16421635
}
16431636

16441637
/// Warn if the LSet contains the given lock.
1645-
void ThreadSafetyAnalyzer::warnIfMutexHeld(const FactSet &FSet,
1646-
const NamedDecl *D, const Expr *Exp,
1647-
Expr *MutexExp,
1648-
til::LiteralPtr *Self,
1649-
SourceLocation Loc) {
1650-
CapabilityExpr Cp = SxBuilder.translateAttrExpr(MutexExp, D, Exp, Self);
1638+
void BuildLockset::warnIfMutexHeld(const NamedDecl *D, const Expr *Exp,
1639+
Expr *MutexExp, til::LiteralPtr *Self,
1640+
SourceLocation Loc) {
1641+
CapabilityExpr Cp =
1642+
Analyzer->SxBuilder.translateAttrExpr(MutexExp, D, Exp, Self);
16511643
if (Cp.isInvalid()) {
1652-
warnInvalidLock(Handler, MutexExp, D, Exp, Cp.getKind());
1644+
warnInvalidLock(Analyzer->Handler, MutexExp, D, Exp, Cp.getKind());
16531645
return;
16541646
} else if (Cp.shouldIgnore()) {
16551647
return;
16561648
}
16571649

1658-
const FactEntry *LDat = FSet.findLock(FactMan, Cp);
1650+
const FactEntry *LDat = FSet.findLock(Analyzer->FactMan, Cp);
16591651
if (LDat) {
1660-
Handler.handleFunExcludesLock(Cp.getKind(), D->getNameAsString(),
1661-
Cp.toString(), Loc);
1652+
Analyzer->Handler.handleFunExcludesLock(Cp.getKind(), D->getNameAsString(),
1653+
Cp.toString(), Loc);
16621654
}
16631655
}
16641656

@@ -1667,9 +1659,8 @@ void ThreadSafetyAnalyzer::warnIfMutexHeld(const FactSet &FSet,
16671659
/// marked with guarded_by, we must ensure the appropriate mutexes are held.
16681660
/// Similarly, we check if the access is to an expression that dereferences
16691661
/// a pointer marked with pt_guarded_by.
1670-
void ThreadSafetyAnalyzer::checkAccess(const FactSet &FSet, const Expr *Exp,
1671-
AccessKind AK,
1672-
ProtectedOperationKind POK) {
1662+
void BuildLockset::checkAccess(const Expr *Exp, AccessKind AK,
1663+
ProtectedOperationKind POK) {
16731664
Exp = Exp->IgnoreImplicit()->IgnoreParenCasts();
16741665

16751666
SourceLocation Loc = Exp->getExprLoc();
@@ -1693,50 +1684,49 @@ void ThreadSafetyAnalyzer::checkAccess(const FactSet &FSet, const Expr *Exp,
16931684
if (const auto *UO = dyn_cast<UnaryOperator>(Exp)) {
16941685
// For dereferences
16951686
if (UO->getOpcode() == UO_Deref)
1696-
checkPtAccess(FSet, UO->getSubExpr(), AK, POK);
1687+
checkPtAccess(UO->getSubExpr(), AK, POK);
16971688
return;
16981689
}
16991690

17001691
if (const auto *BO = dyn_cast<BinaryOperator>(Exp)) {
17011692
switch (BO->getOpcode()) {
17021693
case BO_PtrMemD: // .*
1703-
return checkAccess(FSet, BO->getLHS(), AK, POK);
1694+
return checkAccess(BO->getLHS(), AK, POK);
17041695
case BO_PtrMemI: // ->*
1705-
return checkPtAccess(FSet, BO->getLHS(), AK, POK);
1696+
return checkPtAccess(BO->getLHS(), AK, POK);
17061697
default:
17071698
return;
17081699
}
17091700
}
17101701

17111702
if (const auto *AE = dyn_cast<ArraySubscriptExpr>(Exp)) {
1712-
checkPtAccess(FSet, AE->getLHS(), AK, POK);
1703+
checkPtAccess(AE->getLHS(), AK, POK);
17131704
return;
17141705
}
17151706

17161707
if (const auto *ME = dyn_cast<MemberExpr>(Exp)) {
17171708
if (ME->isArrow())
1718-
checkPtAccess(FSet, ME->getBase(), AK, POK);
1709+
checkPtAccess(ME->getBase(), AK, POK);
17191710
else
1720-
checkAccess(FSet, ME->getBase(), AK, POK);
1711+
checkAccess(ME->getBase(), AK, POK);
17211712
}
17221713

17231714
const ValueDecl *D = getValueDecl(Exp);
17241715
if (!D || !D->hasAttrs())
17251716
return;
17261717

1727-
if (D->hasAttr<GuardedVarAttr>() && FSet.isEmpty(FactMan)) {
1728-
Handler.handleNoMutexHeld(D, POK, AK, Loc);
1718+
if (D->hasAttr<GuardedVarAttr>() && FSet.isEmpty(Analyzer->FactMan)) {
1719+
Analyzer->Handler.handleNoMutexHeld(D, POK, AK, Loc);
17291720
}
17301721

17311722
for (const auto *I : D->specific_attrs<GuardedByAttr>())
1732-
warnIfMutexNotHeld(FSet, D, Exp, AK, I->getArg(), POK, nullptr, Loc);
1723+
warnIfMutexNotHeld(D, Exp, AK, I->getArg(), POK, nullptr, Loc);
17331724
}
17341725

17351726
/// Checks pt_guarded_by and pt_guarded_var attributes.
17361727
/// POK is the same operationKind that was passed to checkAccess.
1737-
void ThreadSafetyAnalyzer::checkPtAccess(const FactSet &FSet, const Expr *Exp,
1738-
AccessKind AK,
1739-
ProtectedOperationKind POK) {
1728+
void BuildLockset::checkPtAccess(const Expr *Exp, AccessKind AK,
1729+
ProtectedOperationKind POK) {
17401730
while (true) {
17411731
if (const auto *PE = dyn_cast<ParenExpr>(Exp)) {
17421732
Exp = PE->getSubExpr();
@@ -1746,7 +1736,7 @@ void ThreadSafetyAnalyzer::checkPtAccess(const FactSet &FSet, const Expr *Exp,
17461736
if (CE->getCastKind() == CK_ArrayToPointerDecay) {
17471737
// If it's an actual array, and not a pointer, then it's elements
17481738
// are protected by GUARDED_BY, not PT_GUARDED_BY;
1749-
checkAccess(FSet, CE->getSubExpr(), AK, POK);
1739+
checkAccess(CE->getSubExpr(), AK, POK);
17501740
return;
17511741
}
17521742
Exp = CE->getSubExpr();
@@ -1763,11 +1753,11 @@ void ThreadSafetyAnalyzer::checkPtAccess(const FactSet &FSet, const Expr *Exp,
17631753
if (!D || !D->hasAttrs())
17641754
return;
17651755

1766-
if (D->hasAttr<PtGuardedVarAttr>() && FSet.isEmpty(FactMan))
1767-
Handler.handleNoMutexHeld(D, PtPOK, AK, Exp->getExprLoc());
1756+
if (D->hasAttr<PtGuardedVarAttr>() && FSet.isEmpty(Analyzer->FactMan))
1757+
Analyzer->Handler.handleNoMutexHeld(D, PtPOK, AK, Exp->getExprLoc());
17681758

17691759
for (auto const *I : D->specific_attrs<PtGuardedByAttr>())
1770-
warnIfMutexNotHeld(FSet, D, Exp, AK, I->getArg(), PtPOK, nullptr,
1760+
warnIfMutexNotHeld(D, Exp, AK, I->getArg(), PtPOK, nullptr,
17711761
Exp->getExprLoc());
17721762
}
17731763

@@ -1879,9 +1869,8 @@ void BuildLockset::handleCall(const Expr *Exp, const NamedDecl *D,
18791869
case attr::RequiresCapability: {
18801870
const auto *A = cast<RequiresCapabilityAttr>(At);
18811871
for (auto *Arg : A->args()) {
1882-
Analyzer->warnIfMutexNotHeld(FSet, D, Exp,
1883-
A->isShared() ? AK_Read : AK_Written,
1884-
Arg, POK_FunctionCall, Self, Loc);
1872+
warnIfMutexNotHeld(D, Exp, A->isShared() ? AK_Read : AK_Written, Arg,
1873+
POK_FunctionCall, Self, Loc);
18851874
// use for adopting a lock
18861875
if (!Scp.shouldIgnore())
18871876
Analyzer->getMutexIDs(ScopedReqsAndExcludes, A, Exp, D, Self);
@@ -1892,7 +1881,7 @@ void BuildLockset::handleCall(const Expr *Exp, const NamedDecl *D,
18921881
case attr::LocksExcluded: {
18931882
const auto *A = cast<LocksExcludedAttr>(At);
18941883
for (auto *Arg : A->args()) {
1895-
Analyzer->warnIfMutexHeld(FSet, D, Exp, Arg, Self, Loc);
1884+
warnIfMutexHeld(D, Exp, Arg, Self, Loc);
18961885
// use for deferring a lock
18971886
if (!Scp.shouldIgnore())
18981887
Analyzer->getMutexIDs(ScopedReqsAndExcludes, A, Exp, D, Self);

0 commit comments

Comments
 (0)