41
41
#include " llvm/ADT/DenseMap.h"
42
42
#include " llvm/ADT/ImmutableMap.h"
43
43
#include " llvm/ADT/Optional.h"
44
- #include " llvm/ADT/PointerIntPair.h"
45
44
#include " llvm/ADT/STLExtras.h"
46
45
#include " llvm/ADT/SmallVector.h"
47
46
#include " llvm/ADT/StringRef.h"
@@ -897,41 +896,41 @@ class ScopedLockableFactEntry : public FactEntry {
897
896
UCK_ReleasedExclusive, // /< Exclusive capability that was released.
898
897
};
899
898
900
- using UnderlyingCapability =
901
- llvm::PointerIntPair<const til::SExpr *, 2 , UnderlyingCapabilityKind>;
899
+ struct UnderlyingCapability {
900
+ CapabilityExpr Cap;
901
+ UnderlyingCapabilityKind Kind;
902
+ };
902
903
903
- SmallVector<UnderlyingCapability, 4 > UnderlyingMutexes;
904
+ SmallVector<UnderlyingCapability, 2 > UnderlyingMutexes;
904
905
905
906
public:
906
907
ScopedLockableFactEntry (const CapabilityExpr &CE, SourceLocation Loc)
907
908
: FactEntry(CE, LK_Exclusive, Loc, Acquired) {}
908
909
909
910
void addLock (const CapabilityExpr &M) {
910
- UnderlyingMutexes.emplace_back (M. sexpr () , UCK_Acquired);
911
+ UnderlyingMutexes.push_back (UnderlyingCapability{M , UCK_Acquired} );
911
912
}
912
913
913
914
void addExclusiveUnlock (const CapabilityExpr &M) {
914
- UnderlyingMutexes.emplace_back (M. sexpr () , UCK_ReleasedExclusive);
915
+ UnderlyingMutexes.push_back (UnderlyingCapability{M , UCK_ReleasedExclusive} );
915
916
}
916
917
917
918
void addSharedUnlock (const CapabilityExpr &M) {
918
- UnderlyingMutexes.emplace_back (M. sexpr () , UCK_ReleasedShared);
919
+ UnderlyingMutexes.push_back (UnderlyingCapability{M , UCK_ReleasedShared} );
919
920
}
920
921
921
922
void
922
923
handleRemovalFromIntersection (const FactSet &FSet, FactManager &FactMan,
923
924
SourceLocation JoinLoc, LockErrorKind LEK,
924
925
ThreadSafetyHandler &Handler) const override {
925
926
for (const auto &UnderlyingMutex : UnderlyingMutexes) {
926
- const auto *Entry = FSet.findLock (
927
- FactMan, CapabilityExpr (UnderlyingMutex.getPointer (), false ));
928
- if ((UnderlyingMutex.getInt () == UCK_Acquired && Entry) ||
929
- (UnderlyingMutex.getInt () != UCK_Acquired && !Entry)) {
927
+ const auto *Entry = FSet.findLock (FactMan, UnderlyingMutex.Cap );
928
+ if ((UnderlyingMutex.Kind == UCK_Acquired && Entry) ||
929
+ (UnderlyingMutex.Kind != UCK_Acquired && !Entry)) {
930
930
// If this scoped lock manages another mutex, and if the underlying
931
931
// mutex is still/not held, then warn about the underlying mutex.
932
932
Handler.handleMutexHeldEndOfScope (
933
- " mutex" , sx::toString (UnderlyingMutex.getPointer ()), loc (), JoinLoc,
934
- LEK);
933
+ " mutex" , UnderlyingMutex.Cap .toString (), loc (), JoinLoc, LEK);
935
934
}
936
935
}
937
936
}
@@ -940,13 +939,12 @@ class ScopedLockableFactEntry : public FactEntry {
940
939
ThreadSafetyHandler &Handler,
941
940
StringRef DiagKind) const override {
942
941
for (const auto &UnderlyingMutex : UnderlyingMutexes) {
943
- CapabilityExpr UnderCp (UnderlyingMutex.getPointer (), false );
944
-
945
- if (UnderlyingMutex.getInt () == UCK_Acquired)
946
- lock (FSet, FactMan, UnderCp, entry.kind (), entry.loc (), &Handler,
947
- DiagKind);
942
+ if (UnderlyingMutex.Kind == UCK_Acquired)
943
+ lock (FSet, FactMan, UnderlyingMutex.Cap , entry.kind (), entry.loc (),
944
+ &Handler, DiagKind);
948
945
else
949
- unlock (FSet, FactMan, UnderCp, entry.loc (), &Handler, DiagKind);
946
+ unlock (FSet, FactMan, UnderlyingMutex.Cap , entry.loc (), &Handler,
947
+ DiagKind);
950
948
}
951
949
}
952
950
@@ -956,18 +954,18 @@ class ScopedLockableFactEntry : public FactEntry {
956
954
StringRef DiagKind) const override {
957
955
assert (!Cp.negative () && " Managing object cannot be negative." );
958
956
for (const auto &UnderlyingMutex : UnderlyingMutexes) {
959
- CapabilityExpr UnderCp (UnderlyingMutex.getPointer (), false );
960
-
961
957
// Remove/lock the underlying mutex if it exists/is still unlocked; warn
962
958
// on double unlocking/locking if we're not destroying the scoped object.
963
959
ThreadSafetyHandler *TSHandler = FullyRemove ? nullptr : &Handler;
964
- if (UnderlyingMutex.getInt () == UCK_Acquired) {
965
- unlock (FSet, FactMan, UnderCp, UnlockLoc, TSHandler, DiagKind);
960
+ if (UnderlyingMutex.Kind == UCK_Acquired) {
961
+ unlock (FSet, FactMan, UnderlyingMutex.Cap , UnlockLoc, TSHandler,
962
+ DiagKind);
966
963
} else {
967
- LockKind kind = UnderlyingMutex.getInt () == UCK_ReleasedShared
964
+ LockKind kind = UnderlyingMutex.Kind == UCK_ReleasedShared
968
965
? LK_Shared
969
966
: LK_Exclusive;
970
- lock (FSet, FactMan, UnderCp, kind, UnlockLoc, TSHandler, DiagKind);
967
+ lock (FSet, FactMan, UnderlyingMutex.Cap , kind, UnlockLoc, TSHandler,
968
+ DiagKind);
971
969
}
972
970
}
973
971
if (FullyRemove)
0 commit comments