Skip to content

Commit 6950db3

Browse files
committed
The wrong placement of add pass with optimizations led to -funique-internal-linkage-names being disabled.
Fixed the placement of the MPM.addpass for UniqueInternalLinkageNames to make it work correctly with -O2 and new pass manager. Updated the tests to explicitly check O0 and O2. Previously, the addPass was placed before BackendUtil.cpp#L1373 which is wrong as MPM gets assigned at this point and any additions to the pass vector before this is wrong. This change just moves it after MPM is assigned and places it at a point where O0 and O0+ can share it. Differential Revision: https://reviews.llvm.org/D87921
1 parent 46075e0 commit 6950db3

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,12 +1262,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
12621262
if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds))
12631263
MPM.addPass(createModuleToFunctionPassAdaptor(BoundsCheckingPass()));
12641264

1265-
// Add UniqueInternalLinkageNames Pass which renames internal linkage
1266-
// symbols with unique names.
1267-
if (CodeGenOpts.UniqueInternalLinkageNames) {
1268-
MPM.addPass(UniqueInternalLinkageNamesPass());
1269-
}
1270-
12711265
// Lastly, add semantically necessary passes for LTO.
12721266
if (IsLTO || IsThinLTO) {
12731267
MPM.addPass(CanonicalizeAliasesPass());
@@ -1363,12 +1357,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
13631357
MPM.addPass(InstrProfiling(*Options, false));
13641358
});
13651359

1366-
// Add UniqueInternalLinkageNames Pass which renames internal linkage
1367-
// symbols with unique names.
1368-
if (CodeGenOpts.UniqueInternalLinkageNames) {
1369-
MPM.addPass(UniqueInternalLinkageNamesPass());
1370-
}
1371-
13721360
if (IsThinLTO) {
13731361
MPM = PB.buildThinLTOPreLinkDefaultPipeline(
13741362
Level, CodeGenOpts.DebugPassManager);
@@ -1385,6 +1373,11 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
13851373
}
13861374
}
13871375

1376+
// Add UniqueInternalLinkageNames Pass which renames internal linkage
1377+
// symbols with unique names.
1378+
if (CodeGenOpts.UniqueInternalLinkageNames)
1379+
MPM.addPass(UniqueInternalLinkageNamesPass());
1380+
13881381
if (CodeGenOpts.MemProf) {
13891382
MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
13901383
MPM.addPass(ModuleMemProfilerPass());

clang/test/CodeGen/unique-internal-linkage-names.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// This test checks if internal linkage symbols get unique names with
22
// -funique-internal-linkage-names option.
33
// RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm -o - < %s | FileCheck %s --check-prefix=PLAIN
4-
// RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm -funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
5-
// RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm -fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
4+
// RUN: %clang_cc1 -triple x86_64 -x c++ -O0 -S -emit-llvm -funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
5+
// RUN: %clang_cc1 -triple x86_64 -x c++ -O1 -S -emit-llvm -funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUEO1
6+
// RUN: %clang_cc1 -triple x86_64 -x c++ -O0 -S -emit-llvm -fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
7+
// RUN: %clang_cc1 -triple x86_64 -x c++ -O1 -S -emit-llvm -fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUEO1
68

79
static int glob;
810
static int foo() {
@@ -59,3 +61,7 @@ int mver_call() {
5961
// UNIQUE: define weak_odr i32 ()* @_ZL4mverv.resolver()
6062
// UNIQUE: define internal i32 @_ZL4mverv.{{[0-9a-f]+}}()
6163
// UNIQUE: define internal i32 @_ZL4mverv.sse4.2.{{[0-9a-f]+}}
64+
// UNIQUEO1: define internal i32 @_ZL3foov.{{[0-9a-f]+}}()
65+
// UNIQUEO1: define weak_odr i32 ()* @_ZL4mverv.resolver()
66+
// UNIQUEO1: define internal i32 @_ZL4mverv.{{[0-9a-f]+}}()
67+
// UNIQUEO1: define internal i32 @_ZL4mverv.sse4.2.{{[0-9a-f]+}}

0 commit comments

Comments
 (0)