[nullability] Smart pointers: Use feature flag where it wasn't used before.
The transfer functions `transferValue_SharedPtrCastCall()` and
`transferValue_WeakPtrLockCall()` were erroneously being run unconditionally
because they are specific to individual smart pointer types, hence they don't
use `isSupportedSmartPointerType()` and thus weren't subject to the feature
flag.
We now gate these functions expliclty on the feature flag.
PiperOrigin-RevId: 591797488
Change-Id: I7b4b123d7044152b0b9298c9cf564b19ee39f400
diff --git a/bazel/llvm.bzl b/bazel/llvm.bzl
index 4b96d31..017a3dc 100644
--- a/bazel/llvm.bzl
+++ b/bazel/llvm.bzl
@@ -53,7 +53,7 @@
executable = False,
)
-LLVM_COMMIT_SHA = "b2cdf3cc4c08729d0ff582d55e40793a20bbcdcc"
+LLVM_COMMIT_SHA = "b3e353d263f9d6ef061f4e6d89619c72a3553002"
def llvm_loader_repository_dependencies():
# This *declares* the dependency, but it won't actually be *downloaded* unless it's used.
diff --git a/nullability/pointer_nullability_analysis.cc b/nullability/pointer_nullability_analysis.cc
index 6689166..0349dcd 100644
--- a/nullability/pointer_nullability_analysis.cc
+++ b/nullability/pointer_nullability_analysis.cc
@@ -574,6 +574,8 @@
void transferValue_SharedPtrCastCall(
const CallExpr *CE, const MatchFinder::MatchResult &Result,
TransferState<PointerNullabilityLattice> &State) {
+ if (!smartPointersEnabled()) return;
+
Environment &Env = State.Env;
DataflowAnalysisContext &Ctx = Env.getDataflowAnalysisContext();
Arena &A = Env.arena();
@@ -647,6 +649,8 @@
void transferValue_WeakPtrLockCall(
const CXXMemberCallExpr *MCE, const MatchFinder::MatchResult &Result,
TransferState<PointerNullabilityLattice> &State) {
+ if (!smartPointersEnabled()) return;
+
RecordStorageLocation &Loc = State.Env.getResultObjectLocation(*MCE);
// Create a `RecordValue`, associate it with the `Loc` and the expression.
State.Env.setValue(*MCE, refreshRecordValue(Loc, State.Env));
@@ -1326,10 +1330,8 @@
transferValue_SmartPointerComparisonOpCall)
.CaseOfCFGStmt<CallExpr>(isSharedPtrCastCall(),
transferValue_SharedPtrCastCall)
- // TODO(b/316410576): Disabled because causing a crash in production
- // pipeline.
- // .CaseOfCFGStmt<CXXMemberCallExpr>(isWeakPtrLockCall(),
- // transferValue_WeakPtrLockCall)
+ .CaseOfCFGStmt<CXXMemberCallExpr>(isWeakPtrLockCall(),
+ transferValue_WeakPtrLockCall)
.CaseOfCFGStmt<CXXMemberCallExpr>(isSupportedPointerAccessorCall(),
transferValue_AccessorCall)
.CaseOfCFGStmt<CXXMemberCallExpr>(isZeroParamConstMemberCall(),
diff --git a/nullability/test/smart_pointers.cc b/nullability/test/smart_pointers.cc
index 5a57bac..adf3f3e 100644
--- a/nullability/test/smart_pointers.cc
+++ b/nullability/test/smart_pointers.cc
@@ -482,8 +482,7 @@
provable(nullptr != p1);
}
-// TODO(b/316410576): re-enable after bug fix.
-// TEST void weakPtrLocReturnsNullable(std::shared_ptr<int> shared) {
-// std::weak_ptr<int> weak(shared);
-// nullable(weak.lock());
-// }
+TEST void weakPtrLocReturnsNullable(std::shared_ptr<int> shared) {
+ std::weak_ptr<int> weak(shared);
+ nullable(weak.lock());
+}
diff --git a/nullability/type_nullability.cc b/nullability/type_nullability.cc
index 132ddc7..be228c4 100644
--- a/nullability/type_nullability.cc
+++ b/nullability/type_nullability.cc
@@ -37,6 +37,8 @@
} // namespace test
+bool smartPointersEnabled() { return SmartPointersEnabled; }
+
bool isSupportedPointerType(QualType T) {
return isSupportedRawPointerType(T) || isSupportedSmartPointerType(T);
}
diff --git a/nullability/type_nullability.h b/nullability/type_nullability.h
index b22bd61..fc2f01a 100644
--- a/nullability/type_nullability.h
+++ b/nullability/type_nullability.h
@@ -57,6 +57,9 @@
} // namespace test
+/// Returns whether support for smart pointers has been turned on.
+bool smartPointersEnabled();
+
/// Is this exactly a pointer type that we track outer nullability for?
/// This unwraps sugar, i.e. it looks at the canonical type.
///