@@ -1015,19 +1015,6 @@ class ThreadSafetyAnalyzer {
1015
1015
1016
1016
BeforeSet *GlobalBeforeSet;
1017
1017
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
-
1031
1018
public:
1032
1019
ThreadSafetyAnalyzer (ThreadSafetyHandler &H, BeforeSet* Bset)
1033
1020
: Arena(&Bpa), SxBuilder(Arena), Handler(H), GlobalBeforeSet(Bset) {}
@@ -1547,15 +1534,16 @@ class BuildLockset : public ConstStmtVisitor<BuildLockset> {
1547
1534
unsigned CtxIndex;
1548
1535
1549
1536
// 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);
1550
1542
1551
1543
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);
1555
1545
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);
1559
1547
1560
1548
void handleCall (const Expr *Exp, const NamedDecl *D,
1561
1549
til::LiteralPtr *Self = nullptr ,
@@ -1583,82 +1571,86 @@ class BuildLockset : public ConstStmtVisitor<BuildLockset> {
1583
1571
1584
1572
// / Warn if the LSet does not contain a lock sufficient to protect access
1585
1573
// / 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) {
1590
1579
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);
1592
1583
if (Cp.isInvalid ()) {
1593
- warnInvalidLock (Handler, MutexExp, D, Exp, Cp.getKind ());
1584
+ warnInvalidLock (Analyzer-> Handler , MutexExp, D, Exp, Cp.getKind ());
1594
1585
return ;
1595
1586
} else if (Cp.shouldIgnore ()) {
1596
1587
return ;
1597
1588
}
1598
1589
1599
1590
if (Cp.negative ()) {
1600
1591
// Negative capabilities act like locks excluded
1601
- const FactEntry *LDat = FSet.findLock (FactMan, !Cp);
1592
+ const FactEntry *LDat = FSet.findLock (Analyzer-> FactMan , !Cp);
1602
1593
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 ;
1606
1597
}
1607
1598
1608
1599
// If this does not refer to a negative capability in the same class,
1609
1600
// then stop here.
1610
- if (!inCurrentScope (Cp))
1611
- return ;
1601
+ if (!Analyzer-> inCurrentScope (Cp))
1602
+ return ;
1612
1603
1613
1604
// Otherwise the negative requirement must be propagated to the caller.
1614
- LDat = FSet.findLock (FactMan, Cp);
1605
+ LDat = FSet.findLock (Analyzer-> FactMan , Cp);
1615
1606
if (!LDat) {
1616
- Handler.handleNegativeNotHeld (D, Cp.toString (), Loc);
1607
+ Analyzer-> Handler .handleNegativeNotHeld (D, Cp.toString (), Loc);
1617
1608
}
1618
1609
return ;
1619
1610
}
1620
1611
1621
- const FactEntry *LDat = FSet.findLockUniv (FactMan, Cp);
1612
+ const FactEntry *LDat = FSet.findLockUniv (Analyzer-> FactMan , Cp);
1622
1613
bool NoError = true ;
1623
1614
if (!LDat) {
1624
1615
// No exact match found. Look for a partial match.
1625
- LDat = FSet.findPartialMatch (FactMan, Cp);
1616
+ LDat = FSet.findPartialMatch (Analyzer-> FactMan , Cp);
1626
1617
if (LDat) {
1627
1618
// Warn that there's no precise match.
1628
1619
std::string PartMatchStr = LDat->toString ();
1629
1620
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);
1632
1623
} else {
1633
1624
// 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);
1635
1627
}
1636
1628
NoError = false ;
1637
1629
}
1638
1630
// Make sure the mutex we found is the right kind.
1639
1631
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);
1641
1634
}
1642
1635
}
1643
1636
1644
1637
// / 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);
1651
1643
if (Cp.isInvalid ()) {
1652
- warnInvalidLock (Handler, MutexExp, D, Exp, Cp.getKind ());
1644
+ warnInvalidLock (Analyzer-> Handler , MutexExp, D, Exp, Cp.getKind ());
1653
1645
return ;
1654
1646
} else if (Cp.shouldIgnore ()) {
1655
1647
return ;
1656
1648
}
1657
1649
1658
- const FactEntry *LDat = FSet.findLock (FactMan, Cp);
1650
+ const FactEntry *LDat = FSet.findLock (Analyzer-> FactMan , Cp);
1659
1651
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);
1662
1654
}
1663
1655
}
1664
1656
@@ -1667,9 +1659,8 @@ void ThreadSafetyAnalyzer::warnIfMutexHeld(const FactSet &FSet,
1667
1659
// / marked with guarded_by, we must ensure the appropriate mutexes are held.
1668
1660
// / Similarly, we check if the access is to an expression that dereferences
1669
1661
// / 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) {
1673
1664
Exp = Exp->IgnoreImplicit ()->IgnoreParenCasts ();
1674
1665
1675
1666
SourceLocation Loc = Exp->getExprLoc ();
@@ -1693,50 +1684,49 @@ void ThreadSafetyAnalyzer::checkAccess(const FactSet &FSet, const Expr *Exp,
1693
1684
if (const auto *UO = dyn_cast<UnaryOperator>(Exp)) {
1694
1685
// For dereferences
1695
1686
if (UO->getOpcode () == UO_Deref)
1696
- checkPtAccess (FSet, UO->getSubExpr (), AK, POK);
1687
+ checkPtAccess (UO->getSubExpr (), AK, POK);
1697
1688
return ;
1698
1689
}
1699
1690
1700
1691
if (const auto *BO = dyn_cast<BinaryOperator>(Exp)) {
1701
1692
switch (BO->getOpcode ()) {
1702
1693
case BO_PtrMemD: // .*
1703
- return checkAccess (FSet, BO->getLHS (), AK, POK);
1694
+ return checkAccess (BO->getLHS (), AK, POK);
1704
1695
case BO_PtrMemI: // ->*
1705
- return checkPtAccess (FSet, BO->getLHS (), AK, POK);
1696
+ return checkPtAccess (BO->getLHS (), AK, POK);
1706
1697
default :
1707
1698
return ;
1708
1699
}
1709
1700
}
1710
1701
1711
1702
if (const auto *AE = dyn_cast<ArraySubscriptExpr>(Exp)) {
1712
- checkPtAccess (FSet, AE->getLHS (), AK, POK);
1703
+ checkPtAccess (AE->getLHS (), AK, POK);
1713
1704
return ;
1714
1705
}
1715
1706
1716
1707
if (const auto *ME = dyn_cast<MemberExpr>(Exp)) {
1717
1708
if (ME->isArrow ())
1718
- checkPtAccess (FSet, ME->getBase (), AK, POK);
1709
+ checkPtAccess (ME->getBase (), AK, POK);
1719
1710
else
1720
- checkAccess (FSet, ME->getBase (), AK, POK);
1711
+ checkAccess (ME->getBase (), AK, POK);
1721
1712
}
1722
1713
1723
1714
const ValueDecl *D = getValueDecl (Exp);
1724
1715
if (!D || !D->hasAttrs ())
1725
1716
return ;
1726
1717
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);
1729
1720
}
1730
1721
1731
1722
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);
1733
1724
}
1734
1725
1735
1726
// / Checks pt_guarded_by and pt_guarded_var attributes.
1736
1727
// / 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) {
1740
1730
while (true ) {
1741
1731
if (const auto *PE = dyn_cast<ParenExpr>(Exp)) {
1742
1732
Exp = PE->getSubExpr ();
@@ -1746,7 +1736,7 @@ void ThreadSafetyAnalyzer::checkPtAccess(const FactSet &FSet, const Expr *Exp,
1746
1736
if (CE->getCastKind () == CK_ArrayToPointerDecay) {
1747
1737
// If it's an actual array, and not a pointer, then it's elements
1748
1738
// are protected by GUARDED_BY, not PT_GUARDED_BY;
1749
- checkAccess (FSet, CE->getSubExpr (), AK, POK);
1739
+ checkAccess (CE->getSubExpr (), AK, POK);
1750
1740
return ;
1751
1741
}
1752
1742
Exp = CE->getSubExpr ();
@@ -1763,11 +1753,11 @@ void ThreadSafetyAnalyzer::checkPtAccess(const FactSet &FSet, const Expr *Exp,
1763
1753
if (!D || !D->hasAttrs ())
1764
1754
return ;
1765
1755
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 ());
1768
1758
1769
1759
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 ,
1771
1761
Exp->getExprLoc ());
1772
1762
}
1773
1763
@@ -1879,9 +1869,8 @@ void BuildLockset::handleCall(const Expr *Exp, const NamedDecl *D,
1879
1869
case attr::RequiresCapability: {
1880
1870
const auto *A = cast<RequiresCapabilityAttr>(At);
1881
1871
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);
1885
1874
// use for adopting a lock
1886
1875
if (!Scp.shouldIgnore ())
1887
1876
Analyzer->getMutexIDs (ScopedReqsAndExcludes, A, Exp, D, Self);
@@ -1892,7 +1881,7 @@ void BuildLockset::handleCall(const Expr *Exp, const NamedDecl *D,
1892
1881
case attr::LocksExcluded: {
1893
1882
const auto *A = cast<LocksExcludedAttr>(At);
1894
1883
for (auto *Arg : A->args ()) {
1895
- Analyzer-> warnIfMutexHeld (FSet, D, Exp, Arg, Self, Loc);
1884
+ warnIfMutexHeld (D, Exp, Arg, Self, Loc);
1896
1885
// use for deferring a lock
1897
1886
if (!Scp.shouldIgnore ())
1898
1887
Analyzer->getMutexIDs (ScopedReqsAndExcludes, A, Exp, D, Self);
0 commit comments