Skip to content

Commit d3b75c4

Browse files
authored
[clang] Make -fvisibility={} and -ftype-visibility={} benign options. (#71985)
Both options do not affect the AST content that is serialized into the PCM. This commit includes the following changes: 1.) Mark `-fvisibility={}` and `-ftype-visibility={}` as benign options.That means they are no longer considered part of the module hash, which can reduce the number of module variants. 2.) Add a test to verify the generated LLVM IR is not affected by the default visibiliy mode in the module. 3.) Add a test to clang-scan-deps to ensure only one module is build, even if the above mentioned options are used. This fixes rdar://118246054.
1 parent be9fa9d commit d3b75c4

File tree

4 files changed

+145
-2
lines changed

4 files changed

+145
-2
lines changed

clang/include/clang/Basic/LangOptions.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,9 @@ LANGOPT(
349349
"type's inheritance model would be determined under the Microsoft ABI")
350350

351351
ENUM_LANGOPT(GC, GCMode, 2, NonGC, "Objective-C Garbage Collection mode")
352-
ENUM_LANGOPT(ValueVisibilityMode, Visibility, 3, DefaultVisibility,
352+
BENIGN_ENUM_LANGOPT(ValueVisibilityMode, Visibility, 3, DefaultVisibility,
353353
"default visibility for functions and variables [-fvisibility]")
354-
ENUM_LANGOPT(TypeVisibilityMode, Visibility, 3, DefaultVisibility,
354+
BENIGN_ENUM_LANGOPT(TypeVisibilityMode, Visibility, 3, DefaultVisibility,
355355
"default visibility for types [-ftype-visibility]")
356356
LANGOPT(SetVisibilityForExternDecls, 1, 0,
357357
"apply global symbol visibility to external declarations without an explicit visibility")
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
4+
5+
// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full -mode preprocess-dependency-directives > %t/result.txt
6+
7+
// RUN: FileCheck %s -input-file %t/result.txt
8+
9+
// Verify that there's a single version of module A.
10+
11+
// CHECK: "modules": [
12+
// CHECK-NEXT: {
13+
// CHECK: "command-line": [
14+
// CHECK-NOT: "-fvisibility="
15+
// CHECK-NOT: "-ftype-visibility="
16+
// CHECK: ]
17+
// CHECK: "name": "A"
18+
// CHECK: }
19+
// CHECK-NOT: "name": "A"
20+
// CHECK: "translation-units"
21+
22+
//--- cdb.json.template
23+
[
24+
{
25+
"directory": "DIR",
26+
"command": "clang -Imodules/A -fmodules -fmodules-cache-path=DIR/module-cache -fimplicit-modules -fimplicit-module-maps -fsyntax-only DIR/t1.c",
27+
"file": "DIR/t1.c"
28+
},
29+
{
30+
"directory": "DIR",
31+
"command": "clang -Imodules/A -fmodules -fmodules-cache-path=DIR/module-cache -fimplicit-modules -fimplicit-module-maps -fvisibility=hidden -fsyntax-only DIR/t2.c",
32+
"file": "DIR/t2.c"
33+
},
34+
{
35+
"directory": "DIR",
36+
"command": "clang -Imodules/A -fmodules -fmodules-cache-path=DIR/module-cache -fimplicit-modules -fimplicit-module-maps -fvisibility=hidden -fvisibility-ms-compat -fsyntax-only DIR/t3.c",
37+
"file": "DIR/t3.c"
38+
}
39+
]
40+
41+
//--- modules/A/module.modulemap
42+
43+
module A {
44+
umbrella header "A.h"
45+
}
46+
47+
//--- modules/A/A.h
48+
49+
typedef int A_t;
50+
extern int a(void);
51+
52+
//--- t1.c
53+
#include "A.h"
54+
55+
//--- t2.c
56+
#include "A.h"
57+
58+
//--- t3.c
59+
#include "A.h"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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-codegen -fmodules -emit-module -fmodule-name=foo %t/foo.modulemap -o %t/foo.pcm
8+
9+
// RUN: %clang_cc1 -emit-llvm %t/foo.pcm -o - | FileCheck %s --check-prefix=DEF
10+
// RUN: %clang_cc1 -triple arm64e-apple-macos -x c++ -fvisibility=hidden -fmodules -fmodule-file=%t/foo.pcm -I%t -emit-llvm %t/test.cpp -o - | FileCheck %s --check-prefixes=USE
11+
12+
// DEF: define void @_Z2f4v()
13+
// DEF: define weak_odr void @_Z2f3v()
14+
15+
// USE: define hidden void @_Z4testv()
16+
// USE: declare void @_Z2f1v()
17+
// USE: define internal void @_ZL2f2v()
18+
// USE: declare void @_Z2f3v()
19+
// USE: declare void @_Z2f4v()
20+
21+
22+
//--- foo.h
23+
void f1();
24+
static void f2() {}
25+
inline void f3() {}
26+
void f4() {}
27+
28+
//--- test.cpp
29+
#include "foo.h"
30+
31+
void test() {
32+
f1();
33+
f2();
34+
f3();
35+
f4();
36+
}
37+
38+
//--- foo.modulemap
39+
module foo { header "foo.h" }
40+

clang/test/Modules/visibility.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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();
28+
static void f2() {}
29+
inline void f3() {}
30+
void f4() {}
31+
32+
//--- test.cpp
33+
#include "foo.h"
34+
35+
void test() {
36+
f1();
37+
f2();
38+
f3();
39+
f4();
40+
}
41+
42+
//--- foo.modulemap
43+
module foo { header "foo.h" }
44+

0 commit comments

Comments
 (0)