Add "-fretain-subst-template-type-parm-type-ast-nodes" in necessary locations in Nullability code.
Clang commit https://github.com/llvm/llvm-project/commit/7f78f99fe5af82361d37adcbd2daa4d04afba13d broke crucial functionality in the nullability infrastructure. Consequently, the flag `-fretain-subst-template-type-parm-type-ast-nodes` was added in https://github.com/llvm/llvm-project/commit/661dda9df13c65ce021407bb726b558c7a414731 to reinstate that feature.
This CL adds that flag to the various places needed for the code to work properly and reinstates all tests that were broken (and consequently disabled) by the original commit.
PiperOrigin-RevId: 665420846
Change-Id: I0628e950e760393ef68312fff0ba62aa748e8dff
diff --git a/nullability/BUILD b/nullability/BUILD
index b22aa04..79bdb80 100644
--- a/nullability/BUILD
+++ b/nullability/BUILD
@@ -198,11 +198,6 @@
cc_test(
name = "type_nullability_test",
srcs = ["type_nullability_test.cc"],
- # TODO(b/357760487): re-enable it.
- tags = [
- "manual",
- "notap",
- ],
deps = [
":pragma",
":type_nullability",
diff --git a/nullability/inference/BUILD b/nullability/inference/BUILD
index eff7ddc..80175f8 100644
--- a/nullability/inference/BUILD
+++ b/nullability/inference/BUILD
@@ -155,11 +155,6 @@
cc_test(
name = "eligible_ranges_test",
srcs = ["eligible_ranges_test.cc"],
- # TODO(b/357760487): re-enable it.
- tags = [
- "manual",
- "notap",
- ],
deps = [
":augmented_test_inputs",
":eligible_ranges",
diff --git a/nullability/inference/augmented_test_inputs.cc b/nullability/inference/augmented_test_inputs.cc
index 1bbac3e..709bc10 100644
--- a/nullability/inference/augmented_test_inputs.cc
+++ b/nullability/inference/augmented_test_inputs.cc
@@ -29,6 +29,10 @@
for (const auto& Entry : llvm::ArrayRef(ctn_replacement_macros_create(),
ctn_replacement_macros_size()))
Inputs.ExtraFiles.try_emplace(Entry.name, Entry.data);
+ // TODO: b/357760487 -- use the flag until the issue is resolved or we find a
+ // workaround.
+ Inputs.ExtraArgs.push_back(
+ "-fretain-subst-template-type-parm-type-ast-nodes");
Inputs.ExtraArgs.push_back("-I.");
Inputs.ExtraArgs.push_back("-include");
Inputs.ExtraArgs.push_back("nullability_annotations.h");
diff --git a/nullability/inference/infer_tu_main.cc b/nullability/inference/infer_tu_main.cc
index bbc9619..f2b3cd8 100644
--- a/nullability/inference/infer_tu_main.cc
+++ b/nullability/inference/infer_tu_main.cc
@@ -312,7 +312,10 @@
"-w",
// Include the file containing macro replacements that enable
// additional inference.
- "-include", std::string(ReplacementMacrosHeaderFileName)},
+ "-include", std::string(ReplacementMacrosHeaderFileName),
+ // TODO: b/357760487 -- use the flag until the issue is resolved or
+ // we find a workaround.
+ "-Xclang", "-fretain-subst-template-type-parm-type-ast-nodes"},
ArgumentInsertPosition::BEGIN));
QCHECK(!Err) << toString(std::move(Err));
}
diff --git a/nullability/test/BUILD b/nullability/test/BUILD
index 43b7904..9585290 100644
--- a/nullability/test/BUILD
+++ b/nullability/test/BUILD
@@ -74,11 +74,6 @@
srcs = ["nullability_test_test.sh"],
args = ["$(location :nullability_test)"],
data = [":nullability_test"],
- # TODO(b/357760487): re-enable it.
- tags = [
- "manual",
- "notap",
- ],
)
cc_test(
@@ -314,11 +309,10 @@
],
)
-# TODO(b/357760487): re-enable it.
-# nullability_test(
-# name = "symbolic_nullability",
-# srcs = ["symbolic_nullability.cc"],
-# )
+nullability_test(
+ name = "symbolic_nullability",
+ srcs = ["symbolic_nullability.cc"],
+)
cc_test(
name = "templates",
diff --git a/nullability/test/nullability_test.cc b/nullability/test/nullability_test.cc
index ef74d79..14ce835 100644
--- a/nullability/test/nullability_test.cc
+++ b/nullability/test/nullability_test.cc
@@ -649,10 +649,14 @@
// Run in C++17 and C++20 mode to cover differences in the AST between modes
// (e.g. C++20 can contain `CXXRewrittenBinaryOperator`).
for (const char *CxxMode : {"-std=c++17", "-std=c++20"})
- require(Executor.execute(clang::tooling::newFrontendActionFactory(&F, &F),
- clang::tooling::getInsertArgumentAdjuster(
- // Ensure test_headers are on the include path.
- {"-isystem.", CxxMode},
- clang::tooling::ArgumentInsertPosition::END)));
+ require(Executor.execute(
+ clang::tooling::newFrontendActionFactory(&F, &F),
+ clang::tooling::getInsertArgumentAdjuster(
+ // Ensure test_headers are on the include path.
+ {"-isystem.", CxxMode,
+ // TODO: b/357760487 -- use the flag until the issue is resolved or
+ // we find a workaround.
+ "-Xclang", "-fretain-subst-template-type-parm-type-ast-nodes"},
+ clang::tooling::ArgumentInsertPosition::END)));
return F.Output.hadErrors() ? 1 : 0;
}
diff --git a/nullability/type_nullability_test.cc b/nullability/type_nullability_test.cc
index 07c7acb..23af767 100644
--- a/nullability/type_nullability_test.cc
+++ b/nullability/type_nullability_test.cc
@@ -393,6 +393,10 @@
Inputs.ExtraArgs.push_back("nullability.h");
Inputs.ExtraArgs.push_back("-include");
Inputs.ExtraArgs.push_back("header.h");
+ // TODO: b/357760487 -- use the flag until the issue is resolved or we find
+ // a workaround.
+ Inputs.ExtraArgs.push_back(
+ "-fretain-subst-template-type-parm-type-ast-nodes");
Inputs.ExtraFiles["nullability.h"] = R"cpp(
template <class X>
using Nullable [[clang::annotate("Nullable")]] = X;
@@ -765,6 +769,10 @@
TestInputs Inputs(AnnotatedInput.code());
Inputs.MakeAction = makeRegisterPragmasAction(Pragmas);
Inputs.Language = TestLanguage::Lang_CXX17;
+ // TODO: b/357760487 -- use the flag until the issue is resolved or we find a
+ // workaround.
+ Inputs.ExtraArgs.push_back(
+ "-fretain-subst-template-type-parm-type-ast-nodes");
if (!HeaderWithAttributes.empty()) {
Inputs.ExtraFiles["header.h"] = HeaderWithAttributes;
Inputs.ExtraArgs.push_back("-include");
@@ -1245,14 +1253,13 @@
}
TEST_F(GetTypeNullabilityLocsTest, AliasTemplateWithDefaultArg) {
- // TODO(b/281474380): The NullabilityKind should be Nullable and the range
- // should only enclose the `int *`, but we don't yet handle default argument
- // sugar correctly.
+ // TODO(b/281474380): The range should only enclose the `int *`, but we don't
+ // yet handle default argument sugar correctly.
Snippet = R"(
template <typename T1, typename T2 = T1>
using AliasTemplate = T2;
- using Target =$0[[AliasTemplate<int * _Nullable>]];
+ using Target = $0(Nullable)[[AliasTemplate<int * _Nullable>]];
)";
EXPECT_THAT(getComparableNullabilityLocs(Snippet), matchesRanges());
}