[clang] fcf75ae - [clang][cli] Fix generation of '-fvisibility' with regards to '-mignore-xcoff-visibility'
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 5 01:57:30 PST 2021
Author: Jan Svoboda
Date: 2021-03-05T10:57:06+01:00
New Revision: fcf75ae6ce20e3575b1464ce724619f38c43edd2
URL: https://github.com/llvm/llvm-project/commit/fcf75ae6ce20e3575b1464ce724619f38c43edd2
DIFF: https://github.com/llvm/llvm-project/commit/fcf75ae6ce20e3575b1464ce724619f38c43edd2.diff
LOG: [clang][cli] Fix generation of '-fvisibility' with regards to '-mignore-xcoff-visibility'
This patch fixes failure of the `CodeGen/aix-ignore-xcoff-visibility.cpp` test with command line round-trip.
The absence of '-fvisibility' implies '-mignore-xcoff-visibility'.
The problem is that when '-fvisibility default' is passed to -cc1, it isn't being generated. (This adheres to the principle that generation doesn't produce arguments with default values.)
However, that caused '-mignore-xcoff-visibility' to be implied in the generated command line (without '-fvisibility'), while it wasn't implied in the original command line (with '-fvisibility').
This patch fixes that by always generating '-fvisibility' and explains the situation in comment.
(The '-mginore-xcoff-visibility' option was added in D87451).
Reviewed By: Bigcheese
Differential Revision: https://reviews.llvm.org/D97552
Added:
Modified:
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index d4d48deb649f..299d4619c7e1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5321,7 +5321,9 @@ def stack_protector_buffer_size : Separate<["-"], "stack-protector-buffer-size">
MarshallingInfoInt<CodeGenOpts<"SSPBufferSize">, "8">;
def fvisibility : Separate<["-"], "fvisibility">,
HelpText<"Default type and symbol visibility">,
- MarshallingInfoVisibility<LangOpts<"ValueVisibilityMode">, "DefaultVisibility">;
+ MarshallingInfoVisibility<LangOpts<"ValueVisibilityMode">, "DefaultVisibility">,
+ // Always emitting because of the relation to `-mignore-xcoff-visibility`.
+ AlwaysEmit;
def ftype_visibility : Separate<["-"], "ftype-visibility">,
HelpText<"Default type visibility">,
MarshallingInfoVisibility<LangOpts<"TypeVisibilityMode">, fvisibility.KeyPath>;
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index b0654f9d706e..89e485a29384 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1831,6 +1831,23 @@ 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;
More information about the cfe-commits
mailing list