Skip to content

Commit 46d4d1f

Browse files
author
diggerlin
committed
[AIX] do not emit visibility attribute into IR when there is -mignore-xcoff-visibility
SUMMARY: n the patch https://reviews.llvm.org/D87451 "add new option -mignore-xcoff-visibility" we did as "The option -mignore-xcoff-visibility has no effect on visibility attribute when compile with -emit-llvm option to generated LLVM IR." in these patch we let -mignore-xcoff-visibility effect on generating IR too. the new feature only work on AIX OS Reviewer: Jason Liu, Differential Revision: https://reviews.llvm.org/D89986
1 parent aaf16b8 commit 46d4d1f

File tree

7 files changed

+91
-72
lines changed

7 files changed

+91
-72
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ CODEGENOPT(AssumeSaneOperatorNew , 1, 1) ///< implicit __attribute__((malloc)) o
3939
CODEGENOPT(Autolink , 1, 1) ///< -fno-autolink
4040
CODEGENOPT(ObjCAutoRefCountExceptions , 1, 0) ///< Whether ARC should be EH-safe.
4141
CODEGENOPT(Backchain , 1, 0) ///< -mbackchain
42-
CODEGENOPT(IgnoreXCOFFVisibility , 1, 0) ///< -mignore-xcoff-visibility
4342
CODEGENOPT(ControlFlowGuardNoChecks , 1, 0) ///< -cfguard-no-checks
4443
CODEGENOPT(ControlFlowGuard , 1, 0) ///< -cfguard
4544
CODEGENOPT(EHContGuard , 1, 0) ///< -ehcontguard

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ BENIGN_LANGOPT(DumpRecordLayoutsSimple , 1, 0, "dumping the layout of IRgen'd re
267267
BENIGN_LANGOPT(DumpVTableLayouts , 1, 0, "dumping the layouts of emitted vtables")
268268
LANGOPT(NoConstantCFStrings , 1, 0, "no constant CoreFoundation strings")
269269
BENIGN_LANGOPT(InlineVisibilityHidden , 1, 0, "hidden visibility for inline C++ methods")
270+
BENIGN_LANGOPT(IgnoreXCOFFVisibility, 1, 0, "All the visibility attributes that are specified in the source code are ignored in aix XCOFF.")
270271
BENIGN_LANGOPT(VisibilityInlinesHiddenStaticLocalVar, 1, 0,
271272
"hidden visibility for static local variables in inline C++ "
272273
"methods when -fvisibility-inlines hidden is enabled")

clang/lib/AST/Decl.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,10 +1487,13 @@ LinkageInfo LinkageComputer::getLVForDecl(const NamedDecl *D,
14871487
}
14881488

14891489
LinkageInfo LinkageComputer::getDeclLinkageAndVisibility(const NamedDecl *D) {
1490-
return getLVForDecl(D,
1491-
LVComputationKind(usesTypeVisibility(D)
1492-
? NamedDecl::VisibilityForType
1493-
: NamedDecl::VisibilityForValue));
1490+
NamedDecl::ExplicitVisibilityKind EK = usesTypeVisibility(D)
1491+
? NamedDecl::VisibilityForType
1492+
: NamedDecl::VisibilityForValue;
1493+
LVComputationKind CK(EK);
1494+
return getLVForDecl(D, D->getASTContext().getLangOpts().IgnoreXCOFFVisibility
1495+
? CK.forLinkageOnly()
1496+
: CK);
14941497
}
14951498

14961499
Module *Decl::getOwningModuleForLinkage(bool IgnoreLinkage) const {

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
549549
Options.EnableMachineFunctionSplitter = CodeGenOpts.SplitMachineFunctions;
550550
Options.FunctionSections = CodeGenOpts.FunctionSections;
551551
Options.DataSections = CodeGenOpts.DataSections;
552-
Options.IgnoreXCOFFVisibility = CodeGenOpts.IgnoreXCOFFVisibility;
552+
Options.IgnoreXCOFFVisibility = LangOpts.IgnoreXCOFFVisibility;
553553
Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames;
554554
Options.UniqueBasicBlockSectionNames =
555555
CodeGenOpts.UniqueBasicBlockSectionNames;

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,9 +1483,6 @@ void CompilerInvocation::GenerateCodeGenArgs(
14831483
GenerateArg(Args, Opt, SA);
14841484
}
14851485

1486-
if (Opts.IgnoreXCOFFVisibility)
1487-
GenerateArg(Args, OPT_mignore_xcoff_visibility, SA);
1488-
14891486
if (Opts.EnableAIXExtendedAltivecABI)
14901487
GenerateArg(Args, OPT_mabi_EQ_vec_extabi, SA);
14911488

@@ -1831,27 +1828,6 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
18311828
}
18321829
}
18331830

1834-
// This is the reason why '-fvisibility' needs to be always generated:
1835-
// its absence implies '-mignore-xcoff-visibility'.
1836-
//
1837-
// Suppose the original cc1 command line does contain '-fvisibility default':
1838-
// '-mignore-xcoff-visibility' should not be implied.
1839-
// * If '-fvisibility' is not generated (as most options with default values
1840-
// don't), its absence would imply '-mignore-xcoff-visibility'. This changes
1841-
// the command line semantics.
1842-
// * If '-fvisibility' is generated regardless of its presence and value,
1843-
// '-mignore-xcoff-visibility' won't be implied and the command line
1844-
// semantics are kept intact.
1845-
//
1846-
// When the original cc1 command line does **not** contain '-fvisibility',
1847-
// '-mignore-xcoff-visibility' is implied. The generated command line will
1848-
// contain both '-fvisibility default' and '-mignore-xcoff-visibility' and
1849-
// subsequent calls to `CreateFromArgs`/`generateCC1CommandLine` will always
1850-
// produce the same arguments.
1851-
if (T.isOSAIX() && (Args.hasArg(OPT_mignore_xcoff_visibility) ||
1852-
!Args.hasArg(OPT_fvisibility)))
1853-
Opts.IgnoreXCOFFVisibility = 1;
1854-
18551831
if (Arg *A =
18561832
Args.getLastArg(OPT_mabi_EQ_vec_default, OPT_mabi_EQ_vec_extabi)) {
18571833
if (!T.isOSAIX())
@@ -3342,6 +3318,9 @@ void CompilerInvocation::GenerateLangArgs(const LangOptions &Opts,
33423318
Twine(Major) + "." + Twine(Minor) + "." + Twine(Patch), SA);
33433319
}
33443320

3321+
if (Opts.IgnoreXCOFFVisibility)
3322+
GenerateArg(Args, OPT_mignore_xcoff_visibility, SA);
3323+
33453324
if (Opts.SignedOverflowBehavior == LangOptions::SOB_Trapping) {
33463325
GenerateArg(Args, OPT_ftrapv, SA);
33473326
GenerateArg(Args, OPT_ftrapv_handler, Opts.OverflowHandler, SA);
@@ -3649,6 +3628,30 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
36493628
Opts.GNUCVersion = Major * 100 * 100 + Minor * 100 + Patch;
36503629
}
36513630

3631+
// In AIX OS, the -mignore-xcoff-visibility is enable by default if there is
3632+
// no -fvisibility=* option.
3633+
// This is the reason why '-fvisibility' needs to be always generated:
3634+
// its absence implies '-mignore-xcoff-visibility'.
3635+
//
3636+
// Suppose the original cc1 command line does contain '-fvisibility default':
3637+
// '-mignore-xcoff-visibility' should not be implied.
3638+
// * If '-fvisibility' is not generated (as most options with default values
3639+
// don't), its absence would imply '-mignore-xcoff-visibility'. This changes
3640+
// the command line semantics.
3641+
// * If '-fvisibility' is generated regardless of its presence and value,
3642+
// '-mignore-xcoff-visibility' won't be implied and the command line
3643+
// semantics are kept intact.
3644+
//
3645+
// When the original cc1 command line does **not** contain '-fvisibility',
3646+
// '-mignore-xcoff-visibility' is implied. The generated command line will
3647+
// contain both '-fvisibility default' and '-mignore-xcoff-visibility' and
3648+
// subsequent calls to `CreateFromArgs`/`generateCC1CommandLine` will always
3649+
// produce the same arguments.
3650+
3651+
if (T.isOSAIX() && (Args.hasArg(OPT_mignore_xcoff_visibility) ||
3652+
!Args.hasArg(OPT_fvisibility)))
3653+
Opts.IgnoreXCOFFVisibility = 1;
3654+
36523655
if (Args.hasArg(OPT_ftrapv)) {
36533656
Opts.setSignedOverflowBehavior(LangOptions::SOB_Trapping);
36543657
// Set the handler, if one is specified.
Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
1-
// REQUIRES: powerpc-registered-target
2-
// RUN: %clang_cc1 -triple powerpc-unknown-aix -o - -x c++ -S %s |\
3-
// RUN: FileCheck --check-prefix=IGNOREVISIBILITY-ASM %s
1+
// RUN: %clang_cc1 -triple powerpc-unknown-aix -emit-llvm -o - -x c++ %s | \
2+
// RUN: FileCheck -check-prefix=NOVISIBILITY-IR %s
43

5-
// RUN: %clang_cc1 -triple powerpc-unknown-aix -mignore-xcoff-visibility -o - -x c++ -S %s | \
6-
// RUN: FileCheck -check-prefix=IGNOREVISIBILITY-ASM %s
4+
// RUN: %clang_cc1 -triple powerpc-unknown-aix -emit-llvm -round-trip-args -o - -x c++ %s | \
5+
// RUN: FileCheck -check-prefix=NOVISIBILITY-IR %s
76

8-
// RUN: %clang_cc1 -triple powerpc-unknown-aix -mignore-xcoff-visibility -fvisibility default -o - -x c++ -S %s | \
9-
// RUN: FileCheck -check-prefix=IGNOREVISIBILITY-ASM %s
10-
11-
// RUN: %clang_cc1 -triple powerpc-unknown-aix -fvisibility default -o - -x c++ -S %s | \
12-
// RUN: FileCheck -check-prefix=VISIBILITY-ASM %s
13-
14-
// RUN: %clang_cc1 -triple powerpc-unknown-aix -mignore-xcoff-visibility -fvisibility default -o - -x c++ -S %s | \
15-
// RUN: FileCheck -check-prefix=IGNOREVISIBILITY-ASM %s
7+
// RUN: %clang_cc1 -triple powerpc-unknown-aix -mignore-xcoff-visibility -fvisibility default -emit-llvm -o - -x c++ %s | \
8+
// RUN: FileCheck -check-prefix=NOVISIBILITY-IR %s
169

17-
// RUN: %clang_cc1 -triple powerpc-unknown-aix -fvisibility default -o - -x c++ -S %s | \
18-
// RUN: FileCheck -check-prefix=VISIBILITY-ASM %s
10+
// RUN: %clang_cc1 -triple powerpc-unknown-aix -mignore-xcoff-visibility -fvisibility default -emit-llvm -round-trip-args -o - -x c++ %s | \
11+
// RUN: FileCheck -check-prefix=NOVISIBILITY-IR %s
1912

20-
// RUN: %clang_cc1 -triple powerpc-unknown-aix -mignore-xcoff-visibility -fvisibility default -emit-llvm -o - -x c++ %s | \
13+
// RUN: %clang_cc1 -triple powerpc-unknown-aix -fvisibility default -emit-llvm -o - -x c++ %s | \
2114
// RUN: FileCheck -check-prefix=VISIBILITY-IR %s
2215

23-
// RUN: %clang_cc1 -triple powerpc-unknown-aix -fvisibility default -emit-llvm -o - -x c++ %s | \
16+
// RUN: %clang_cc1 -triple powerpc-unknown-aix -fvisibility default -round-trip-args -emit-llvm -o - -x c++ %s | \
2417
// RUN: FileCheck -check-prefix=VISIBILITY-IR %s
2518

2619
__attribute__((visibility("hidden"))) void foo_h(int *p) {
@@ -70,28 +63,11 @@ void prambar() {}
7063
// VISIBILITY-IR: define weak_odr protected i32 @_ZN5basicIiE7getdataEv(%class.basic* {{[^,]*}} %this)
7164
// VISIBILITY-IR: define hidden void @_Z7prambarv()
7265

73-
// VISIBILITY-ASM: .globl _Z5foo_hPi[DS],hidden
74-
// VISIBILITY-ASM: .globl ._Z5foo_hPi,hidden
75-
// VISIBILITY-ASM: .globl _Z3barv[DS],protected
76-
// VISIBILITY-ASM: .globl ._Z3barv,protected
77-
// VISIBILITY-ASM: .weak _ZNK9TestClass5valueEv[DS],hidden
78-
// VISIBILITY-ASM: .weak ._ZNK9TestClass5valueEv,hidden
79-
// VISIBILITY-ASM: .weak _ZN5basicIiE7getdataEv[DS],protected
80-
// VISIBILITY-ASM: .weak ._ZN5basicIiE7getdataEv,protected
81-
// VISIBILITY-ASM: .globl _Z7prambarv[DS],hidden
82-
// VISIBILITY-ASM: .globl ._Z7prambarv,hidden
83-
// VISIBILITY-ASM: .globl b,protected
84-
// VISIBILITY-ASM: .globl pramb,hidden
85-
86-
// IGNOREVISIBILITY-ASM: .globl _Z5foo_hPi[DS]
87-
// IGNOREVISIBILITY-ASM: .globl ._Z5foo_hPi
88-
// IGNOREVISIBILITY-ASM: .globl _Z3barv[DS]
89-
// IGNOREVISIBILITY-ASM: .globl ._Z3barv
90-
// IGNOREVISIBILITY-ASM: .weak _ZNK9TestClass5valueEv[DS]
91-
// IGNOREVISIBILITY-ASM: .weak ._ZNK9TestClass5valueEv
92-
// IGNOREVISIBILITY-ASM: .weak _ZN5basicIiE7getdataEv[DS]
93-
// IGNOREVISIBILITY-ASM: .weak ._ZN5basicIiE7getdataEv
94-
// IGNOREVISIBILITY-ASM: .globl _Z7prambarv[DS]
95-
// IGNOREVISIBILITY-ASM: .globl ._Z7prambarv
96-
// IGNOREVISIBILITY-ASM: .globl b
97-
// IGNOREVISIBILITY-ASM: .globl pramb
66+
// NOVISIBILITY-IR: @b = global i32 0
67+
// NOVISIBILITY-IR: @pramb = global i32 0
68+
// NOVISIBILITY-IR: define void @_Z5foo_hPi(i32* %p)
69+
// NOVISIBILITY-IR: declare void @_Z12zoo_extern_hv()
70+
// NOVISIBILITY-IR: define void @_Z3barv()
71+
// NOVISIBILITY-IR: define linkonce_odr i32 @_ZNK9TestClass5valueEv(%class.TestClass* {{[^,]*}} %this)
72+
// NOVISIBILITY-IR: define weak_odr i32 @_ZN5basicIiE7getdataEv(%class.basic* {{[^,]*}} %this)
73+
// NOVISIBILITY-IR: define void @_Z7prambarv()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %clang_cc1 -triple powerpc-unknown-aix -mcmodel=large -emit-llvm -o - -x c++ %s | \
2+
// RUN: FileCheck -check-prefix=NOVISIBILITY-IR %s
3+
4+
// RUN: %clang_cc1 -triple powerpc-unknown-aix -mcmodel=large \
5+
// RUN: -fvisibility-inlines-hidden -emit-llvm -o - -x c++ %s | \
6+
// RUN: FileCheck -check-prefix=NOVISIBILITY-IR %s
7+
8+
// RUN: %clang_cc1 -triple powerpc-unknown-aix -mcmodel=large -fvisibility-inlines-hidden \
9+
// RUN: -fvisibility default -emit-llvm -o - -x c++ %s | \
10+
// RUN: FileCheck -check-prefix=VISIBILITY-IR %s
11+
12+
// RUN: %clang_cc1 -triple powerpc-unknown-aix -mcmodel=large -mignore-xcoff-visibility -emit-llvm \
13+
// RUN: -fvisibility-inlines-hidden -fvisibility default -o - -x c++ %s | \
14+
// RUN: FileCheck -check-prefix=NOVISIBILITY-IR %s
15+
16+
int x = 66;
17+
__attribute__((__noinline__)) inline void f() {
18+
x = 55;
19+
}
20+
21+
#pragma GCC visibility push(hidden)
22+
__attribute__((__noinline__)) inline void foo() {
23+
x = 55;
24+
}
25+
#pragma GCC visibility pop
26+
27+
int bar() {
28+
f();
29+
foo();
30+
return x;
31+
}
32+
33+
// VISIBILITY-IR: define linkonce_odr hidden void @_Z1fv()
34+
// NOVISIBILITY-IR: define linkonce_odr void @_Z1fv()
35+
36+
// VISIBILITY-IR: define linkonce_odr hidden void @_Z3foov()
37+
// NOVISIBILITY-IR: define linkonce_odr void @_Z3foov()

0 commit comments

Comments
 (0)