[clang] 46d4d1f - [AIX] do not emit visibility attribute into IR when there is -mignore-xcoff-visibility
via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 9 07:38:48 PST 2021
Author: diggerlin
Date: 2021-03-09T10:38:00-05:00
New Revision: 46d4d1fea401de1d22fe746077a4ca4dd7e137b4
URL: https://github.com/llvm/llvm-project/commit/46d4d1fea401de1d22fe746077a4ca4dd7e137b4
DIFF: https://github.com/llvm/llvm-project/commit/46d4d1fea401de1d22fe746077a4ca4dd7e137b4.diff
LOG: [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
Added:
clang/test/CodeGen/aix-visibility-inlines-hidden.cpp
Modified:
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/LangOptions.def
clang/lib/AST/Decl.cpp
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/aix-ignore-xcoff-visibility.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def
index a1db1b101620..bbda74044a1c 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -39,7 +39,6 @@ CODEGENOPT(AssumeSaneOperatorNew , 1, 1) ///< implicit __attribute__((malloc)) o
CODEGENOPT(Autolink , 1, 1) ///< -fno-autolink
CODEGENOPT(ObjCAutoRefCountExceptions , 1, 0) ///< Whether ARC should be EH-safe.
CODEGENOPT(Backchain , 1, 0) ///< -mbackchain
-CODEGENOPT(IgnoreXCOFFVisibility , 1, 0) ///< -mignore-xcoff-visibility
CODEGENOPT(ControlFlowGuardNoChecks , 1, 0) ///< -cfguard-no-checks
CODEGENOPT(ControlFlowGuard , 1, 0) ///< -cfguard
CODEGENOPT(EHContGuard , 1, 0) ///< -ehcontguard
diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def
index 346638549719..620b0899507a 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -267,6 +267,7 @@ BENIGN_LANGOPT(DumpRecordLayoutsSimple , 1, 0, "dumping the layout of IRgen'd re
BENIGN_LANGOPT(DumpVTableLayouts , 1, 0, "dumping the layouts of emitted vtables")
LANGOPT(NoConstantCFStrings , 1, 0, "no constant CoreFoundation strings")
BENIGN_LANGOPT(InlineVisibilityHidden , 1, 0, "hidden visibility for inline C++ methods")
+BENIGN_LANGOPT(IgnoreXCOFFVisibility, 1, 0, "All the visibility attributes that are specified in the source code are ignored in aix XCOFF.")
BENIGN_LANGOPT(VisibilityInlinesHiddenStaticLocalVar, 1, 0,
"hidden visibility for static local variables in inline C++ "
"methods when -fvisibility-inlines hidden is enabled")
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 8c986df3e175..cae092ac369d 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -1487,10 +1487,13 @@ LinkageInfo LinkageComputer::getLVForDecl(const NamedDecl *D,
}
LinkageInfo LinkageComputer::getDeclLinkageAndVisibility(const NamedDecl *D) {
- return getLVForDecl(D,
- LVComputationKind(usesTypeVisibility(D)
- ? NamedDecl::VisibilityForType
- : NamedDecl::VisibilityForValue));
+ NamedDecl::ExplicitVisibilityKind EK = usesTypeVisibility(D)
+ ? NamedDecl::VisibilityForType
+ : NamedDecl::VisibilityForValue;
+ LVComputationKind CK(EK);
+ return getLVForDecl(D, D->getASTContext().getLangOpts().IgnoreXCOFFVisibility
+ ? CK.forLinkageOnly()
+ : CK);
}
Module *Decl::getOwningModuleForLinkage(bool IgnoreLinkage) const {
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 36b6588e773f..37f9067e0b2e 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -549,7 +549,7 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
Options.EnableMachineFunctionSplitter = CodeGenOpts.SplitMachineFunctions;
Options.FunctionSections = CodeGenOpts.FunctionSections;
Options.DataSections = CodeGenOpts.DataSections;
- Options.IgnoreXCOFFVisibility = CodeGenOpts.IgnoreXCOFFVisibility;
+ Options.IgnoreXCOFFVisibility = LangOpts.IgnoreXCOFFVisibility;
Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames;
Options.UniqueBasicBlockSectionNames =
CodeGenOpts.UniqueBasicBlockSectionNames;
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 89e485a29384..2606e9f1b185 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1483,9 +1483,6 @@ void CompilerInvocation::GenerateCodeGenArgs(
GenerateArg(Args, Opt, SA);
}
- if (Opts.IgnoreXCOFFVisibility)
- GenerateArg(Args, OPT_mignore_xcoff_visibility, SA);
-
if (Opts.EnableAIXExtendedAltivecABI)
GenerateArg(Args, OPT_mabi_EQ_vec_extabi, SA);
@@ -1831,27 +1828,6 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
}
}
- // This is the reason why '-fvisibility' needs to be always generated:
- // its absence implies '-mignore-xcoff-visibility'.
- //
- // Suppose the original cc1 command line does contain '-fvisibility default':
- // '-mignore-xcoff-visibility' should not be implied.
- // * If '-fvisibility' is not generated (as most options with default values
- // don't), its absence would imply '-mignore-xcoff-visibility'. This changes
- // the command line semantics.
- // * If '-fvisibility' is generated regardless of its presence and value,
- // '-mignore-xcoff-visibility' won't be implied and the command line
- // semantics are kept intact.
- //
- // When the original cc1 command line does **not** contain '-fvisibility',
- // '-mignore-xcoff-visibility' is implied. The generated command line will
- // contain both '-fvisibility default' and '-mignore-xcoff-visibility' and
- // subsequent calls to `CreateFromArgs`/`generateCC1CommandLine` will always
- // produce the same arguments.
- if (T.isOSAIX() && (Args.hasArg(OPT_mignore_xcoff_visibility) ||
- !Args.hasArg(OPT_fvisibility)))
- Opts.IgnoreXCOFFVisibility = 1;
-
if (Arg *A =
Args.getLastArg(OPT_mabi_EQ_vec_default, OPT_mabi_EQ_vec_extabi)) {
if (!T.isOSAIX())
@@ -3342,6 +3318,9 @@ void CompilerInvocation::GenerateLangArgs(const LangOptions &Opts,
Twine(Major) + "." + Twine(Minor) + "." + Twine(Patch), SA);
}
+ if (Opts.IgnoreXCOFFVisibility)
+ GenerateArg(Args, OPT_mignore_xcoff_visibility, SA);
+
if (Opts.SignedOverflowBehavior == LangOptions::SOB_Trapping) {
GenerateArg(Args, OPT_ftrapv, SA);
GenerateArg(Args, OPT_ftrapv_handler, Opts.OverflowHandler, SA);
@@ -3649,6 +3628,30 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.GNUCVersion = Major * 100 * 100 + Minor * 100 + Patch;
}
+ // In AIX OS, the -mignore-xcoff-visibility is enable by default if there is
+ // no -fvisibility=* option.
+ // This is the reason why '-fvisibility' needs to be always generated:
+ // its absence implies '-mignore-xcoff-visibility'.
+ //
+ // Suppose the original cc1 command line does contain '-fvisibility default':
+ // '-mignore-xcoff-visibility' should not be implied.
+ // * If '-fvisibility' is not generated (as most options with default values
+ // don't), its absence would imply '-mignore-xcoff-visibility'. This changes
+ // the command line semantics.
+ // * If '-fvisibility' is generated regardless of its presence and value,
+ // '-mignore-xcoff-visibility' won't be implied and the command line
+ // semantics are kept intact.
+ //
+ // When the original cc1 command line does **not** contain '-fvisibility',
+ // '-mignore-xcoff-visibility' is implied. The generated command line will
+ // contain both '-fvisibility default' and '-mignore-xcoff-visibility' and
+ // subsequent calls to `CreateFromArgs`/`generateCC1CommandLine` will always
+ // produce the same arguments.
+
+ if (T.isOSAIX() && (Args.hasArg(OPT_mignore_xcoff_visibility) ||
+ !Args.hasArg(OPT_fvisibility)))
+ Opts.IgnoreXCOFFVisibility = 1;
+
if (Args.hasArg(OPT_ftrapv)) {
Opts.setSignedOverflowBehavior(LangOptions::SOB_Trapping);
// Set the handler, if one is specified.
diff --git a/clang/test/CodeGen/aix-ignore-xcoff-visibility.cpp b/clang/test/CodeGen/aix-ignore-xcoff-visibility.cpp
index c0341b8c5a70..721a3df1e0e7 100644
--- a/clang/test/CodeGen/aix-ignore-xcoff-visibility.cpp
+++ b/clang/test/CodeGen/aix-ignore-xcoff-visibility.cpp
@@ -1,26 +1,19 @@
-// REQUIRES: powerpc-registered-target
-// RUN: %clang_cc1 -triple powerpc-unknown-aix -o - -x c++ -S %s |\
-// RUN: FileCheck --check-prefix=IGNOREVISIBILITY-ASM %s
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -emit-llvm -o - -x c++ %s | \
+// RUN: FileCheck -check-prefix=NOVISIBILITY-IR %s
-// RUN: %clang_cc1 -triple powerpc-unknown-aix -mignore-xcoff-visibility -o - -x c++ -S %s | \
-// RUN: FileCheck -check-prefix=IGNOREVISIBILITY-ASM %s
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -emit-llvm -round-trip-args -o - -x c++ %s | \
+// RUN: FileCheck -check-prefix=NOVISIBILITY-IR %s
-// RUN: %clang_cc1 -triple powerpc-unknown-aix -mignore-xcoff-visibility -fvisibility default -o - -x c++ -S %s | \
-// RUN: FileCheck -check-prefix=IGNOREVISIBILITY-ASM %s
-
-// RUN: %clang_cc1 -triple powerpc-unknown-aix -fvisibility default -o - -x c++ -S %s | \
-// RUN: FileCheck -check-prefix=VISIBILITY-ASM %s
-
-// RUN: %clang_cc1 -triple powerpc-unknown-aix -mignore-xcoff-visibility -fvisibility default -o - -x c++ -S %s | \
-// RUN: FileCheck -check-prefix=IGNOREVISIBILITY-ASM %s
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -mignore-xcoff-visibility -fvisibility default -emit-llvm -o - -x c++ %s | \
+// RUN: FileCheck -check-prefix=NOVISIBILITY-IR %s
-// RUN: %clang_cc1 -triple powerpc-unknown-aix -fvisibility default -o - -x c++ -S %s | \
-// RUN: FileCheck -check-prefix=VISIBILITY-ASM %s
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -mignore-xcoff-visibility -fvisibility default -emit-llvm -round-trip-args -o - -x c++ %s | \
+// RUN: FileCheck -check-prefix=NOVISIBILITY-IR %s
-// RUN: %clang_cc1 -triple powerpc-unknown-aix -mignore-xcoff-visibility -fvisibility default -emit-llvm -o - -x c++ %s | \
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -fvisibility default -emit-llvm -o - -x c++ %s | \
// RUN: FileCheck -check-prefix=VISIBILITY-IR %s
-// RUN: %clang_cc1 -triple powerpc-unknown-aix -fvisibility default -emit-llvm -o - -x c++ %s | \
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -fvisibility default -round-trip-args -emit-llvm -o - -x c++ %s | \
// RUN: FileCheck -check-prefix=VISIBILITY-IR %s
__attribute__((visibility("hidden"))) void foo_h(int *p) {
@@ -70,28 +63,11 @@ void prambar() {}
// VISIBILITY-IR: define weak_odr protected i32 @_ZN5basicIiE7getdataEv(%class.basic* {{[^,]*}} %this)
// VISIBILITY-IR: define hidden void @_Z7prambarv()
-// VISIBILITY-ASM: .globl _Z5foo_hPi[DS],hidden
-// VISIBILITY-ASM: .globl ._Z5foo_hPi,hidden
-// VISIBILITY-ASM: .globl _Z3barv[DS],protected
-// VISIBILITY-ASM: .globl ._Z3barv,protected
-// VISIBILITY-ASM: .weak _ZNK9TestClass5valueEv[DS],hidden
-// VISIBILITY-ASM: .weak ._ZNK9TestClass5valueEv,hidden
-// VISIBILITY-ASM: .weak _ZN5basicIiE7getdataEv[DS],protected
-// VISIBILITY-ASM: .weak ._ZN5basicIiE7getdataEv,protected
-// VISIBILITY-ASM: .globl _Z7prambarv[DS],hidden
-// VISIBILITY-ASM: .globl ._Z7prambarv,hidden
-// VISIBILITY-ASM: .globl b,protected
-// VISIBILITY-ASM: .globl pramb,hidden
-
-// IGNOREVISIBILITY-ASM: .globl _Z5foo_hPi[DS]
-// IGNOREVISIBILITY-ASM: .globl ._Z5foo_hPi
-// IGNOREVISIBILITY-ASM: .globl _Z3barv[DS]
-// IGNOREVISIBILITY-ASM: .globl ._Z3barv
-// IGNOREVISIBILITY-ASM: .weak _ZNK9TestClass5valueEv[DS]
-// IGNOREVISIBILITY-ASM: .weak ._ZNK9TestClass5valueEv
-// IGNOREVISIBILITY-ASM: .weak _ZN5basicIiE7getdataEv[DS]
-// IGNOREVISIBILITY-ASM: .weak ._ZN5basicIiE7getdataEv
-// IGNOREVISIBILITY-ASM: .globl _Z7prambarv[DS]
-// IGNOREVISIBILITY-ASM: .globl ._Z7prambarv
-// IGNOREVISIBILITY-ASM: .globl b
-// IGNOREVISIBILITY-ASM: .globl pramb
+// NOVISIBILITY-IR: @b = global i32 0
+// NOVISIBILITY-IR: @pramb = global i32 0
+// NOVISIBILITY-IR: define void @_Z5foo_hPi(i32* %p)
+// NOVISIBILITY-IR: declare void @_Z12zoo_extern_hv()
+// NOVISIBILITY-IR: define void @_Z3barv()
+// NOVISIBILITY-IR: define linkonce_odr i32 @_ZNK9TestClass5valueEv(%class.TestClass* {{[^,]*}} %this)
+// NOVISIBILITY-IR: define weak_odr i32 @_ZN5basicIiE7getdataEv(%class.basic* {{[^,]*}} %this)
+// NOVISIBILITY-IR: define void @_Z7prambarv()
diff --git a/clang/test/CodeGen/aix-visibility-inlines-hidden.cpp b/clang/test/CodeGen/aix-visibility-inlines-hidden.cpp
new file mode 100644
index 000000000000..aadca2984300
--- /dev/null
+++ b/clang/test/CodeGen/aix-visibility-inlines-hidden.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -mcmodel=large -emit-llvm -o - -x c++ %s | \
+// RUN: FileCheck -check-prefix=NOVISIBILITY-IR %s
+
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -mcmodel=large \
+// RUN: -fvisibility-inlines-hidden -emit-llvm -o - -x c++ %s | \
+// RUN: FileCheck -check-prefix=NOVISIBILITY-IR %s
+
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -mcmodel=large -fvisibility-inlines-hidden \
+// RUN: -fvisibility default -emit-llvm -o - -x c++ %s | \
+// RUN: FileCheck -check-prefix=VISIBILITY-IR %s
+
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -mcmodel=large -mignore-xcoff-visibility -emit-llvm \
+// RUN: -fvisibility-inlines-hidden -fvisibility default -o - -x c++ %s | \
+// RUN: FileCheck -check-prefix=NOVISIBILITY-IR %s
+
+int x = 66;
+__attribute__((__noinline__)) inline void f() {
+ x = 55;
+}
+
+#pragma GCC visibility push(hidden)
+__attribute__((__noinline__)) inline void foo() {
+ x = 55;
+}
+#pragma GCC visibility pop
+
+int bar() {
+ f();
+ foo();
+ return x;
+}
+
+// VISIBILITY-IR: define linkonce_odr hidden void @_Z1fv()
+// NOVISIBILITY-IR: define linkonce_odr void @_Z1fv()
+
+// VISIBILITY-IR: define linkonce_odr hidden void @_Z3foov()
+// NOVISIBILITY-IR: define linkonce_odr void @_Z3foov()
More information about the cfe-commits
mailing list