1// Test that a change related to an ADL can be propagated correctly. 2// 3// RUN: rm -rf %t 4// RUN: split-file %s %t 5// 6// RUN: %clang_cc1 -std=c++20 %t/Common.cppm -emit-reduced-module-interface -o %t/Common.pcm 7// 8// RUN: %clang_cc1 -std=c++20 %t/m-partA.cppm -emit-reduced-module-interface -o %t/m-partA.pcm \ 9// RUN: -fmodule-file=Common=%t/Common.pcm 10// RUN: %clang_cc1 -std=c++20 %t/m-partA.v1.cppm -emit-reduced-module-interface -o \ 11// RUN: %t/m-partA.v1.pcm -fmodule-file=Common=%t/Common.pcm 12// RUN: %clang_cc1 -std=c++20 %t/m-partB.cppm -emit-reduced-module-interface -o %t/m-partB.pcm 13// RUN: %clang_cc1 -std=c++20 %t/m.cppm -emit-reduced-module-interface -o %t/m.pcm \ 14// RUN: -fmodule-file=m:partA=%t/m-partA.pcm -fmodule-file=m:partB=%t/m-partB.pcm \ 15// RUN: -fmodule-file=Common=%t/Common.pcm 16// RUN: %clang_cc1 -std=c++20 %t/m.cppm -emit-reduced-module-interface -o %t/m.v1.pcm \ 17// RUN: -fmodule-file=m:partA=%t/m-partA.v1.pcm -fmodule-file=m:partB=%t/m-partB.pcm \ 18// RUN: -fmodule-file=Common=%t/Common.pcm 19// 20// Produce B.pcm and B.v1.pcm 21// RUN: %clang_cc1 -std=c++20 %t/B.cppm -emit-reduced-module-interface -o %t/B.pcm \ 22// RUN: -fmodule-file=m=%t/m.pcm -fmodule-file=m:partA=%t/m-partA.pcm \ 23// RUN: -fmodule-file=m:partB=%t/m-partB.pcm -fmodule-file=Common=%t/Common.pcm 24// RUN: %clang_cc1 -std=c++20 %t/B.cppm -emit-reduced-module-interface -o %t/B.v1.pcm \ 25// RUN: -fmodule-file=m=%t/m.v1.pcm -fmodule-file=m:partA=%t/m-partA.v1.pcm \ 26// RUN: -fmodule-file=m:partB=%t/m-partB.pcm -fmodule-file=Common=%t/Common.pcm 27// 28// Verify that both B.pcm and B.v1.pcm can work as expected. 29// RUN: %clang_cc1 -std=c++20 %t/use.cpp -fsyntax-only -verify -fmodule-file=m=%t/m.pcm \ 30// RUN: -fmodule-file=m:partA=%t/m-partA.pcm -fmodule-file=m:partB=%t/m-partB.pcm \ 31// RUN: -fmodule-file=B=%t/B.pcm -fmodule-file=Common=%t/Common.pcm \ 32// RUN: -DEXPECTED_VALUE=false 33// RUN: %clang_cc1 -std=c++20 %t/use.cpp -fsyntax-only -verify -fmodule-file=m=%t/m.v1.pcm \ 34// RUN: -fmodule-file=m:partA=%t/m-partA.v1.pcm -fmodule-file=m:partB=%t/m-partB.pcm \ 35// RUN: -fmodule-file=B=%t/B.v1.pcm -fmodule-file=Common=%t/Common.pcm \ 36// RUN: -DEXPECTED_VALUE=true 37// 38// Since we add new ADL function in m-partA.v1.cppm, B.v1.pcm is expected to not be the same with 39// B.pcm. 40// RUN: not diff %t/B.pcm %t/B.v1.pcm &> /dev/null 41 42// Test that BMI won't differ if it doesn't refer adl. 43// RUN: %clang_cc1 -std=c++20 %t/C.cppm -emit-reduced-module-interface -o %t/C.pcm \ 44// RUN: -fmodule-file=m=%t/m.pcm -fmodule-file=m:partA=%t/m-partA.pcm \ 45// RUN: -fmodule-file=m:partB=%t/m-partB.pcm -fmodule-file=Common=%t/Common.pcm 46// RUN: %clang_cc1 -std=c++20 %t/C.cppm -emit-reduced-module-interface -o %t/C.v1.pcm \ 47// RUN: -fmodule-file=m=%t/m.v1.pcm -fmodule-file=m:partA=%t/m-partA.v1.pcm \ 48// RUN: -fmodule-file=m:partB=%t/m-partB.pcm -fmodule-file=Common=%t/Common.pcm 49// RUN: diff %t/C.pcm %t/C.v1.pcm &> /dev/null 50 51//--- Common.cppm 52export module Common; 53 54export namespace N { 55 struct A { 56 constexpr operator int() { 57 return 43; 58 } 59 }; 60} 61 62//--- m-partA.cppm 63export module m:partA; 64import Common; 65 66export namespace N {} 67 68//--- m-partA.v1.cppm 69export module m:partA; 70import Common; 71 72export namespace N { 73constexpr bool adl(A) { return true; } 74} 75 76//--- m-partB.cppm 77export module m:partB; 78 79export constexpr bool adl(int) { return false; } 80 81//--- m.cppm 82export module m; 83export import :partA; 84export import :partB; 85 86//--- B.cppm 87export module B; 88import m; 89 90export template <class C> 91constexpr bool test_adl(C c) { 92 return adl(c); 93} 94 95//--- use.cpp 96// expected-no-diagnostics 97import B; 98import Common; 99 100void test() { 101 N::A a; 102 static_assert(test_adl(a) == EXPECTED_VALUE); 103} 104 105//--- C.cppm 106export module B; 107import m; 108 109export template <class C> 110constexpr bool not_test_adl(C c) { 111 return false; 112} 113