1RUN: rm -rf %t 2REQUIRES: x86-registered-target 3 4RUN: %clang_cc1 -triple=x86_64-linux-gnu -fmodules-codegen -x c++ -fmodules -emit-module -fmodule-name=foo %S/Inputs/codegen-opt/foo.modulemap -o %t/foo.pcm 5RUN: %clang_cc1 -triple=x86_64-linux-gnu -fmodules-codegen -x c++ -fmodules -emit-module -fmodule-name=bar %S/Inputs/codegen-opt/bar.modulemap -o %t/bar.pcm -fmodule-file=%t/foo.pcm 6 7RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %t/foo.pcm | FileCheck --check-prefix=FOO %s 8RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %t/bar.pcm -fmodule-file=%t/foo.pcm | FileCheck --check-prefix=BAR-CMN --check-prefix=BAR %s 9RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - -fmodules -fmodule-file=%t/foo.pcm -fmodule-file=%t/bar.pcm %S/Inputs/codegen-opt/use.cpp | FileCheck --check-prefix=USE-CMN --check-prefix=USE %s 10 11RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - -O2 -disable-llvm-passes %t/foo.pcm | FileCheck --check-prefix=FOO %s 12RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - -O2 -disable-llvm-passes %t/bar.pcm -fmodule-file=%t/foo.pcm | FileCheck --check-prefix=BAR-CMN --check-prefix=BAR-OPT %s 13RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - -O2 -disable-llvm-passes -fmodules -fmodule-file=%t/foo.pcm -fmodule-file=%t/bar.pcm %S/Inputs/codegen-opt/use.cpp | FileCheck --check-prefix=USE-CMN --check-prefix=USE-OPT %s 14 15FOO-NOT: comdat 16FOO: $_Z3foov = comdat any 17FOO: $_Z4foo2v = comdat any 18FOO: $_ZZ3foovE1i = comdat any 19FOO: @_ZZ3foovE1i = linkonce_odr global i32 0, comdat 20FOO-NOT: {{comdat|define|declare}} 21FOO: define void @_Z7foo_extv() 22FOO-NOT: {{define|declare}} 23FOO: define weak_odr void @_Z3foov() #{{[0-9]+}} comdat 24FOO-NOT: {{define|declare}} 25FOO: declare void @_Z2f1Ri(i32* 26FOO-NOT: {{define|declare}} 27 28Internal functions are not modularly code generated - they are 29internal wherever they're used. This might not be ideal, but 30continues to workaround/support some oddities that backwards 31compatible modules have seen and supported in the wild. To remove 32the duplication here, the internal functions would need to be 33promoted to weak_odr, placed in comdat and given a new mangling - 34this would be needed for the C++ Modules TS anyway. 35FOO: define internal void @_ZL2f2v() #{{[0-9]+}} 36FOO-NOT: {{define|declare}} 37 38FOO: define weak_odr void @_Z4foo2v() #{{[0-9]+}} comdat 39FOO-NOT: {{define|declare}} 40 41 42BAR-CMN-NOT: comdat 43BAR-CMN: $_Z3barv = comdat any 44BAR-OPT: @_ZZ3foovE1i = linkonce_odr global i32 0, comdat 45BAR-CMN-NOT: {{comdat|define|declare}} 46BAR-CMN: define weak_odr void @_Z3barv() #{{[0-9]+}} comdat 47BAR-CMN-NOT: {{define|declare}} 48BAR: declare void @_Z3foov() 49Include all the available_externally definitions required for bar (foo -> f2) 50BAR-OPT: define available_externally void @_Z3foov() 51BAR-CMN-NOT: {{define|declare}} 52BAR-OPT: declare void @_Z2f1Ri(i32* 53BAR-OPT-NOT: {{define|declare}} 54BAR-OPT: define internal void @_ZL2f2v() 55BAR-OPT-NOT: {{define|declare}} 56 57 58USE-OPT: @_ZZ3foovE1i = linkonce_odr global i32 0, comdat 59USE-CMN-NOT: {{comdat|define|declare}} 60USE-CMN: define i32 @main() 61USE-CMN-NOT: {{define|declare}} 62USE: declare void @_Z3barv() 63Include all the available_externally definitions required for main (bar -> foo -> f2) 64USE-OPT: define available_externally void @_Z3barv() 65USE-CMN-NOT: {{define|declare}} 66USE-OPT: define available_externally void @_Z3foov() 67USE-OPT-NOT: {{define|declare}} 68USE-OPT: declare void @_Z2f1Ri(i32* 69USE-OPT-NOT: {{define|declare}} 70USE-OPT: define internal void @_ZL2f2v() 71USE-OPT-NOT: {{define|declare}} 72