xref: /llvm-project/clang/test/Modules/visibility.cpp (revision d3b75c4750673b6d0d8a224f02b2c0885209a49a)
1 // Test that modules with different visibility mode can be shared.
2 // REQUIRES: aarch64-registered-target
3 
4 // RUN: rm -rf %t && mkdir %t
5 // RUN: split-file %s %t
6 
7 // RUN: %clang_cc1 -triple arm64e-apple-macos -x c++ -fvisibility=default -fmodules -emit-module -fmodule-name=foo %t/foo.modulemap -o %t/foo.default.pcm
8 // RUN: %clang_cc1 -triple arm64e-apple-macos -x c++ -fvisibility=hidden  -fmodules -emit-module -fmodule-name=foo %t/foo.modulemap -o %t/foo.hidden.pcm
9 
10 // RUN: %clang_cc1 -triple arm64e-apple-macos -x c++ -fvisibility=default -fmodules -fmodule-file=%t/foo.default.pcm -I%t -emit-llvm %t/test.cpp -o - | FileCheck %s --check-prefixes=DEFAULT,BOTH
11 // RUN: %clang_cc1 -triple arm64e-apple-macos -x c++ -fvisibility=default -fmodules -fmodule-file=%t/foo.hidden.pcm  -I%t -emit-llvm %t/test.cpp -o - | FileCheck %s --check-prefixes=DEFAULT,BOTH
12 
13 // RUN: %clang_cc1 -triple arm64e-apple-macos -x c++ -fvisibility=hidden -fmodules -fmodule-file=%t/foo.default.pcm -I%t -emit-llvm %t/test.cpp -o - | FileCheck %s --check-prefixes=HIDDEN,BOTH
14 // RUN: %clang_cc1 -triple arm64e-apple-macos -x c++ -fvisibility=hidden -fmodules -fmodule-file=%t/foo.hidden.pcm  -I%t -emit-llvm %t/test.cpp -o - | FileCheck %s --check-prefixes=HIDDEN,BOTH
15 
16 // DEFAULT: define void @_Z2f4v()
17 // HIDDEN: define hidden void @_Z2f4v()
18 // DEFAULT: define void @_Z4testv()
19 // HIDDEN: define hidden void @_Z4testv()
20 // BOTH: declare void @_Z2f1v()
21 // BOTH: define internal void @_ZL2f2v()
22 // DEFAULT: define linkonce_odr void @_Z2f3v()
23 // HIDDEN: define linkonce_odr hidden void @_Z2f3v()
24 
25 
26 //--- foo.h
27 void f1();
f2()28 static void f2() {}
f3()29 inline void f3() {}
f4()30 void f4() {}
31 
32 //--- test.cpp
33 #include "foo.h"
34 
test()35 void test() {
36   f1();
37   f2();
38   f3();
39   f4();
40 }
41 
42 //--- foo.modulemap
43 module foo { header "foo.h" }
44 
45