Skip to content

Commit a1c3c65

Browse files
authored
[clang][test] Split out staticanalyzer portion of Modules/specializations-lazy-load-parentmap-crash.cpp (#151259)
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 Split out the part of the test that requires the static analyzer so that it does not run when the static analyzer is unavailable.
1 parent 5e3cc00 commit a1c3c65

File tree

2 files changed

+88
-16
lines changed

2 files changed

+88
-16
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// REQUIRES: staticanalyzer
2+
//
3+
// RUN: rm -rf %t
4+
// RUN: mkdir -p %t
5+
// RUN: split-file --leading-lines %s %t
6+
//
7+
// Prepare the BMIs.
8+
// RUN: %clang_cc1 -std=c++20 -emit-module-interface -o %t/mod_a-part1.pcm %t/mod_a-part1.cppm
9+
// RUN: %clang_cc1 -std=c++20 -emit-module-interface -o %t/mod_a-part2.pcm %t/mod_a-part2.cppm
10+
// 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
11+
// 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
12+
13+
// Trigger the construction of the parent map (which is necessary to trigger the bug this regression test is for) using ArrayBoundV2 checker:
14+
// 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
15+
16+
//--- mod_a-part1.cppm
17+
module;
18+
namespace mod_a {
19+
template <int> struct Important;
20+
}
21+
22+
namespace mod_a {
23+
Important<0>& instantiate1();
24+
} // namespace mod_a
25+
export module mod_a:part1;
26+
27+
export namespace mod_a {
28+
using ::mod_a::instantiate1;
29+
}
30+
31+
//--- mod_a-part2.cppm
32+
module;
33+
namespace mod_a {
34+
template <int> struct Important;
35+
}
36+
37+
namespace mod_a {
38+
template <int N> Important<N>& instantiate2();
39+
namespace part2InternalInstantiations {
40+
// During the construction of the parent map, we iterate over ClassTemplateDecl::specializations() for 'Important'.
41+
// After GH119333, the following instantiations get loaded between the call to spec_begin() and spec_end().
42+
// This used to invalidate the begin iterator returned by spec_begin() by the time the end iterator is returned.
43+
// This is a regression test for that.
44+
Important<1> fn1();
45+
Important<2> fn2();
46+
Important<3> fn3();
47+
Important<4> fn4();
48+
Important<5> fn5();
49+
Important<6> fn6();
50+
Important<7> fn7();
51+
Important<8> fn8();
52+
Important<9> fn9();
53+
Important<10> fn10();
54+
Important<11> fn11();
55+
}
56+
} // namespace mod_a
57+
export module mod_a:part2;
58+
59+
export namespace mod_a {
60+
using ::mod_a::instantiate2;
61+
}
62+
63+
//--- mod_a.cppm
64+
export module mod_a;
65+
export import :part1;
66+
export import :part2;
67+
68+
//--- mod_b.cppm
69+
export module mod_b;
70+
import mod_a;
71+
72+
void a() {
73+
mod_a::instantiate1();
74+
mod_a::instantiate2<42>();
75+
}
76+
77+
//--- test-array-bound-v2.cpp
78+
import mod_b;
79+
80+
extern void someFunc(char* first, char* last);
81+
void triggerParentMapContextCreationThroughArrayBoundV2() {
82+
// This code currently causes the ArrayBoundV2 checker to create the ParentMapContext.
83+
// Once it detects an access to buf[100], the checker looks through the parents to find '&' operator.
84+
// (this is needed since taking the address of past-the-end pointer is allowed by the checker)
85+
char buf[100];
86+
someFunc(&buf[0], &buf[100]);
87+
}

clang/test/Modules/specializations-lazy-load-parentmap-crash.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
// 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
99
// 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
1010

11-
// Below are two examples to trigger the construction of the parent map (which is necessary to trigger the bug this regression test is for).
12-
// Using ArrayBoundV2 checker:
13-
// 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
14-
// Using a sanitized build:
11+
// Trigger the construction of the parent map (which is necessary to trigger the bug this regression test is for) using a sanitized build:
1512
// 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
1613

1714
//--- mod_a-part1.cppm
@@ -75,18 +72,6 @@ void a() {
7572
mod_a::instantiate2<42>();
7673
}
7774

78-
//--- test-array-bound-v2.cpp
79-
import mod_b;
80-
81-
extern void someFunc(char* first, char* last);
82-
void triggerParentMapContextCreationThroughArrayBoundV2() {
83-
// This code currently causes the ArrayBoundV2 checker to create the ParentMapContext.
84-
// Once it detects an access to buf[100], the checker looks through the parents to find '&' operator.
85-
// (this is needed since taking the address of past-the-end pointer is allowed by the checker)
86-
char buf[100];
87-
someFunc(&buf[0], &buf[100]);
88-
}
89-
9075
//--- test-sanitized-build.cpp
9176
import mod_b;
9277

0 commit comments

Comments
 (0)