85 lines · cpp
1// RUN: rm -rf %t2// RUN: mkdir -p %t3// RUN: split-file --leading-lines %s %t4//5// Prepare the BMIs.6// 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.cppm7// 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.cppm8// 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.pcm9// 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.pcm10 11// Trigger the construction of the parent map (which is necessary to trigger the bug this regression test is for) using a sanitized build:12// 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.pcm13 14//--- mod_a-part1.cppm15module;16namespace mod_a {17template <int> struct Important;18}19 20namespace mod_a {21Important<0>& instantiate1();22} // namespace mod_a23export module mod_a:part1;24 25export namespace mod_a {26using ::mod_a::instantiate1;27}28 29//--- mod_a-part2.cppm30module;31namespace mod_a {32template <int> struct Important;33}34 35namespace mod_a {36template <int N> Important<N>& instantiate2();37namespace part2InternalInstantiations {38// During the construction of the parent map, we iterate over ClassTemplateDecl::specializations() for 'Important'.39// After GH119333, the following instantiations get loaded between the call to spec_begin() and spec_end().40// This used to invalidate the begin iterator returned by spec_begin() by the time the end iterator is returned.41// This is a regression test for that.42Important<1> fn1();43Important<2> fn2();44Important<3> fn3();45Important<4> fn4();46Important<5> fn5();47Important<6> fn6();48Important<7> fn7();49Important<8> fn8();50Important<9> fn9();51Important<10> fn10();52Important<11> fn11();53}54} // namespace mod_a55export module mod_a:part2;56 57export namespace mod_a {58using ::mod_a::instantiate2;59}60 61//--- mod_a.cppm62export module mod_a;63export import :part1;64export import :part2;65 66//--- mod_b.cppm67export module mod_b;68import mod_a;69 70void a() {71 mod_a::instantiate1();72 mod_a::instantiate2<42>();73}74 75//--- test-sanitized-build.cpp76import mod_b;77 78extern void some();79void triggerParentMapContextCreationThroughSanitizedBuild(unsigned i) {80 // This code currently causes UBSan to create the ParentMapContext.81 // UBSan currently excludes the pattern below to avoid noise, and it relies on ParentMapContext to detect it.82 while (i--)83 some();84}85