https://github.com/nathanchance updated https://github.com/llvm/llvm-project/pull/151259
>From 53b66607e46965a6fff0bd3dc825236bca1e4447 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor <nat...@kernel.org> Date: Tue, 29 Jul 2025 17:03:41 -0700 Subject: [PATCH 1/5] [clang][test] Require staticanalyzer for Modules/specializations-lazy-load-parentmap-crash.cpp When the static analyzer is disabled with -DCLANG_ENABLE_STATIC_ANALYZER=OFF, the newly added specializations-lazy-load-parentmap-crash.cpp test fails with: error: action RunAnalysis not compiled in -- ******************** ******************** Failed Tests (1): Clang :: Modules/specializations-lazy-load-parentmap-crash.cpp Add a 'REQUIRES: staticanalyzer' line to the test so that it does not run when the static analyzer is unavailable. --- .../test/Modules/specializations-lazy-load-parentmap-crash.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/test/Modules/specializations-lazy-load-parentmap-crash.cpp b/clang/test/Modules/specializations-lazy-load-parentmap-crash.cpp index bd07ada631355..19f9d14102903 100644 --- a/clang/test/Modules/specializations-lazy-load-parentmap-crash.cpp +++ b/clang/test/Modules/specializations-lazy-load-parentmap-crash.cpp @@ -1,3 +1,5 @@ +// REQUIRES: staticanalyzer +// // RUN: rm -rf %t // RUN: mkdir -p %t // RUN: split-file --leading-lines %s %t >From 418eb2f0faa2b8500a2193a79d567a9bab5cf0cd Mon Sep 17 00:00:00 2001 From: Nathan Chancellor <nat...@kernel.org> Date: Thu, 31 Jul 2025 19:13:36 -0700 Subject: [PATCH 2/5] fixup! [clang][test] Require staticanalyzer for Modules/specializations-lazy-load-parentmap-crash.cpp Signed-off-by: Nathan Chancellor <nat...@kernel.org> --- ...ons-lazy-load-parentmap-crash-analyzer.cpp | 98 +++++++++++++++++++ ...cializations-lazy-load-parentmap-crash.cpp | 5 +- 2 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 clang/test/Modules/specializations-lazy-load-parentmap-crash-analyzer.cpp diff --git a/clang/test/Modules/specializations-lazy-load-parentmap-crash-analyzer.cpp b/clang/test/Modules/specializations-lazy-load-parentmap-crash-analyzer.cpp new file mode 100644 index 0000000000000..52b86b1ec27da --- /dev/null +++ b/clang/test/Modules/specializations-lazy-load-parentmap-crash-analyzer.cpp @@ -0,0 +1,98 @@ +// REQUIRES: staticanalyzer +// +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file --leading-lines %s %t +// +// Prepare the BMIs. +// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-module-interface -o %t/mod_a-part1.pcm %t/mod_a-part1.cppm +// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-module-interface -o %t/mod_a-part2.pcm %t/mod_a-part2.cppm +// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-module-interface -o %t/mod_a.pcm %t/mod_a.cppm -fmodule-file=mod_a:part2=%t/mod_a-part2.pcm -fmodule-file=mod_a:part1=%t/mod_a-part1.pcm +// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-module-interface -o %t/mod_b.pcm %t/mod_b.cppm -fmodule-file=mod_a:part2=%t/mod_a-part2.pcm -fmodule-file=mod_a=%t/mod_a.pcm -fmodule-file=mod_a:part1=%t/mod_a-part1.pcm + +// Trigger the construction of the parent map (which is necessary to trigger the bug this regression test is for) using ArrayBoundV2 checker: +// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -analyze -analyzer-checker=security,alpha.security -analyzer-output=text %t/test-array-bound-v2.cpp -fmodule-file=mod_a:part2=%t/mod_a-part2.pcm -fmodule-file=mod_a=%t/mod_a.pcm -fmodule-file=mod_a:part1=%t/mod_a-part1.pcm -fmodule-file=mod_b=%t/mod_b.pcm + +//--- mod_a-part1.cppm +module; +namespace mod_a { +template <int> struct Important; +} + +namespace mod_a { +Important<0>& instantiate1(); +} // namespace mod_a +export module mod_a:part1; + +export namespace mod_a { +using ::mod_a::instantiate1; +} + +//--- mod_a-part2.cppm +module; +namespace mod_a { +template <int> struct Important; +} + +namespace mod_a { +template <int N> Important<N>& instantiate2(); +namespace part2InternalInstantiations { +// During the construction of the parent map, we iterate over ClassTemplateDecl::specializations() for 'Important'. +// After GH119333, the following instantiations get loaded between the call to spec_begin() and spec_end(). +// This used to invalidate the begin iterator returned by spec_begin() by the time the end iterator is returned. +// This is a regression test for that. +Important<1> fn1(); +Important<2> fn2(); +Important<3> fn3(); +Important<4> fn4(); +Important<5> fn5(); +Important<6> fn6(); +Important<7> fn7(); +Important<8> fn8(); +Important<9> fn9(); +Important<10> fn10(); +Important<11> fn11(); +} +} // namespace mod_a +export module mod_a:part2; + +export namespace mod_a { +using ::mod_a::instantiate2; +} + +//--- mod_a.cppm +export module mod_a; +export import :part1; +export import :part2; + +//--- mod_b.cppm +export module mod_b; +import mod_a; + +void a() { + mod_a::instantiate1(); + mod_a::instantiate2<42>(); +} + +//--- test-array-bound-v2.cpp +import mod_b; + +extern void someFunc(char* first, char* last); +void triggerParentMapContextCreationThroughArrayBoundV2() { + // This code currently causes the ArrayBoundV2 checker to create the ParentMapContext. + // Once it detects an access to buf[100], the checker looks through the parents to find '&' operator. + // (this is needed since taking the address of past-the-end pointer is allowed by the checker) + char buf[100]; + someFunc(&buf[0], &buf[100]); +} + +//--- test-sanitized-build.cpp +import mod_b; + +extern void some(); +void triggerParentMapContextCreationThroughSanitizedBuild(unsigned i) { + // This code currently causes UBSan to create the ParentMapContext. + // UBSan currently excludes the pattern below to avoid noise, and it relies on ParentMapContext to detect it. + while (i--) + some(); +} diff --git a/clang/test/Modules/specializations-lazy-load-parentmap-crash.cpp b/clang/test/Modules/specializations-lazy-load-parentmap-crash.cpp index 19f9d14102903..6a70b07227274 100644 --- a/clang/test/Modules/specializations-lazy-load-parentmap-crash.cpp +++ b/clang/test/Modules/specializations-lazy-load-parentmap-crash.cpp @@ -10,10 +10,7 @@ // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-module-interface -o %t/mod_a.pcm %t/mod_a.cppm -fmodule-file=mod_a:part2=%t/mod_a-part2.pcm -fmodule-file=mod_a:part1=%t/mod_a-part1.pcm // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-module-interface -o %t/mod_b.pcm %t/mod_b.cppm -fmodule-file=mod_a:part2=%t/mod_a-part2.pcm -fmodule-file=mod_a=%t/mod_a.pcm -fmodule-file=mod_a:part1=%t/mod_a-part1.pcm -// Below are two examples to trigger the construction of the parent map (which is necessary to trigger the bug this regression test is for). -// Using ArrayBoundV2 checker: -// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -analyze -analyzer-checker=security,alpha.security -analyzer-output=text %t/test-array-bound-v2.cpp -fmodule-file=mod_a:part2=%t/mod_a-part2.pcm -fmodule-file=mod_a=%t/mod_a.pcm -fmodule-file=mod_a:part1=%t/mod_a-part1.pcm -fmodule-file=mod_b=%t/mod_b.pcm -// Using a sanitized build: +// Trigger the construction of the parent map (which is necessary to trigger the bug this regression test is for) using ArrayBoundV2 checker using a sanitized build: // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fsanitize=unsigned-integer-overflow -fsanitize-undefined-ignore-overflow-pattern=all -emit-llvm -o %t/ignored %t/test-sanitized-build.cpp -fmodule-file=mod_a:part2=%t/mod_a-part2.pcm -fmodule-file=mod_a=%t/mod_a.pcm -fmodule-file=mod_a:part1=%t/mod_a-part1.pcm -fmodule-file=mod_b=%t/mod_b.pcm //--- mod_a-part1.cppm >From 94c0649d426aaa03e9eeaacc60bbc740dccb218f Mon Sep 17 00:00:00 2001 From: Nathan Chancellor <nat...@kernel.org> Date: Fri, 1 Aug 2025 11:13:16 -0700 Subject: [PATCH 3/5] fixup! [clang][test] Require staticanalyzer for Modules/specializations-lazy-load-parentmap-crash.cpp --- .../test/Modules/specializations-lazy-load-parentmap-crash.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Modules/specializations-lazy-load-parentmap-crash.cpp b/clang/test/Modules/specializations-lazy-load-parentmap-crash.cpp index 6a70b07227274..378ceb5ce0807 100644 --- a/clang/test/Modules/specializations-lazy-load-parentmap-crash.cpp +++ b/clang/test/Modules/specializations-lazy-load-parentmap-crash.cpp @@ -10,7 +10,7 @@ // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-module-interface -o %t/mod_a.pcm %t/mod_a.cppm -fmodule-file=mod_a:part2=%t/mod_a-part2.pcm -fmodule-file=mod_a:part1=%t/mod_a-part1.pcm // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-module-interface -o %t/mod_b.pcm %t/mod_b.cppm -fmodule-file=mod_a:part2=%t/mod_a-part2.pcm -fmodule-file=mod_a=%t/mod_a.pcm -fmodule-file=mod_a:part1=%t/mod_a-part1.pcm -// Trigger the construction of the parent map (which is necessary to trigger the bug this regression test is for) using ArrayBoundV2 checker using a sanitized build: +// Trigger the construction of the parent map (which is necessary to trigger the bug this regression test is for) using a sanitized build: // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fsanitize=unsigned-integer-overflow -fsanitize-undefined-ignore-overflow-pattern=all -emit-llvm -o %t/ignored %t/test-sanitized-build.cpp -fmodule-file=mod_a:part2=%t/mod_a-part2.pcm -fmodule-file=mod_a=%t/mod_a.pcm -fmodule-file=mod_a:part1=%t/mod_a-part1.pcm -fmodule-file=mod_b=%t/mod_b.pcm //--- mod_a-part1.cppm >From 22186191ae74d9cbaef9d63583dc75e4dbf164f8 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor <nat...@kernel.org> Date: Fri, 1 Aug 2025 11:15:50 -0700 Subject: [PATCH 4/5] fixup! [clang][test] Require staticanalyzer for Modules/specializations-lazy-load-parentmap-crash.cpp Signed-off-by: Nathan Chancellor <nat...@kernel.org> --- ...alizations-lazy-load-parentmap-crash-analyzer.cpp | 11 ----------- .../specializations-lazy-load-parentmap-crash.cpp | 12 ------------ 2 files changed, 23 deletions(-) diff --git a/clang/test/Modules/specializations-lazy-load-parentmap-crash-analyzer.cpp b/clang/test/Modules/specializations-lazy-load-parentmap-crash-analyzer.cpp index 52b86b1ec27da..d710dbb2427a4 100644 --- a/clang/test/Modules/specializations-lazy-load-parentmap-crash-analyzer.cpp +++ b/clang/test/Modules/specializations-lazy-load-parentmap-crash-analyzer.cpp @@ -85,14 +85,3 @@ void triggerParentMapContextCreationThroughArrayBoundV2() { char buf[100]; someFunc(&buf[0], &buf[100]); } - -//--- test-sanitized-build.cpp -import mod_b; - -extern void some(); -void triggerParentMapContextCreationThroughSanitizedBuild(unsigned i) { - // This code currently causes UBSan to create the ParentMapContext. - // UBSan currently excludes the pattern below to avoid noise, and it relies on ParentMapContext to detect it. - while (i--) - some(); -} diff --git a/clang/test/Modules/specializations-lazy-load-parentmap-crash.cpp b/clang/test/Modules/specializations-lazy-load-parentmap-crash.cpp index 378ceb5ce0807..43edaf548482a 100644 --- a/clang/test/Modules/specializations-lazy-load-parentmap-crash.cpp +++ b/clang/test/Modules/specializations-lazy-load-parentmap-crash.cpp @@ -74,18 +74,6 @@ void a() { mod_a::instantiate2<42>(); } -//--- test-array-bound-v2.cpp -import mod_b; - -extern void someFunc(char* first, char* last); -void triggerParentMapContextCreationThroughArrayBoundV2() { - // This code currently causes the ArrayBoundV2 checker to create the ParentMapContext. - // Once it detects an access to buf[100], the checker looks through the parents to find '&' operator. - // (this is needed since taking the address of past-the-end pointer is allowed by the checker) - char buf[100]; - someFunc(&buf[0], &buf[100]); -} - //--- test-sanitized-build.cpp import mod_b; >From 5e298005a0fae191f8f6d9c9d2aafbdeb9866b76 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor <nat...@kernel.org> Date: Fri, 1 Aug 2025 11:17:10 -0700 Subject: [PATCH 5/5] fixup! [clang][test] Require staticanalyzer for Modules/specializations-lazy-load-parentmap-crash.cpp Signed-off-by: Nathan Chancellor <nat...@kernel.org> --- ...cializations-lazy-load-parentmap-crash-analyzer.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clang/test/Modules/specializations-lazy-load-parentmap-crash-analyzer.cpp b/clang/test/Modules/specializations-lazy-load-parentmap-crash-analyzer.cpp index d710dbb2427a4..d1e603fcd874a 100644 --- a/clang/test/Modules/specializations-lazy-load-parentmap-crash-analyzer.cpp +++ b/clang/test/Modules/specializations-lazy-load-parentmap-crash-analyzer.cpp @@ -5,13 +5,13 @@ // RUN: split-file --leading-lines %s %t // // Prepare the BMIs. -// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-module-interface -o %t/mod_a-part1.pcm %t/mod_a-part1.cppm -// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-module-interface -o %t/mod_a-part2.pcm %t/mod_a-part2.cppm -// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-module-interface -o %t/mod_a.pcm %t/mod_a.cppm -fmodule-file=mod_a:part2=%t/mod_a-part2.pcm -fmodule-file=mod_a:part1=%t/mod_a-part1.pcm -// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-module-interface -o %t/mod_b.pcm %t/mod_b.cppm -fmodule-file=mod_a:part2=%t/mod_a-part2.pcm -fmodule-file=mod_a=%t/mod_a.pcm -fmodule-file=mod_a:part1=%t/mod_a-part1.pcm +// RUN: %clang_cc1 -std=c++20 -emit-module-interface -o %t/mod_a-part1.pcm %t/mod_a-part1.cppm +// RUN: %clang_cc1 -std=c++20 -emit-module-interface -o %t/mod_a-part2.pcm %t/mod_a-part2.cppm +// RUN: %clang_cc1 -std=c++20 -emit-module-interface -o %t/mod_a.pcm %t/mod_a.cppm -fmodule-file=mod_a:part2=%t/mod_a-part2.pcm -fmodule-file=mod_a:part1=%t/mod_a-part1.pcm +// RUN: %clang_cc1 -std=c++20 -emit-module-interface -o %t/mod_b.pcm %t/mod_b.cppm -fmodule-file=mod_a:part2=%t/mod_a-part2.pcm -fmodule-file=mod_a=%t/mod_a.pcm -fmodule-file=mod_a:part1=%t/mod_a-part1.pcm // Trigger the construction of the parent map (which is necessary to trigger the bug this regression test is for) using ArrayBoundV2 checker: -// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -analyze -analyzer-checker=security,alpha.security -analyzer-output=text %t/test-array-bound-v2.cpp -fmodule-file=mod_a:part2=%t/mod_a-part2.pcm -fmodule-file=mod_a=%t/mod_a.pcm -fmodule-file=mod_a:part1=%t/mod_a-part1.pcm -fmodule-file=mod_b=%t/mod_b.pcm +// RUN: %clang_cc1 -std=c++20 -analyze -analyzer-checker=security,alpha.security -analyzer-output=text %t/test-array-bound-v2.cpp -fmodule-file=mod_a:part2=%t/mod_a-part2.pcm -fmodule-file=mod_a=%t/mod_a.pcm -fmodule-file=mod_a:part1=%t/mod_a-part1.pcm -fmodule-file=mod_b=%t/mod_b.pcm //--- mod_a-part1.cppm module; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits