[llvm-branch-commits] [clang] ff5f42e - [clang][cli] Port visibility LangOptions to marshalling system
Jan Svoboda via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Jan 22 00:36:41 PST 2021
Author: Jan Svoboda
Date: 2021-01-22T09:32:01+01:00
New Revision: ff5f42e413386b1b3730879abf7b35756891e1c3
URL: https://github.com/llvm/llvm-project/commit/ff5f42e413386b1b3730879abf7b35756891e1c3
DIFF: https://github.com/llvm/llvm-project/commit/ff5f42e413386b1b3730879abf7b35756891e1c3.diff
LOG: [clang][cli] Port visibility LangOptions to marshalling system
This patch introduces Clang-specific MarshallingInfoVisibility TableGen class.
Reviewed By: dexonsmith
Differential Revision: https://reviews.llvm.org/D95147
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 a2800381be0e..3bb545f84132 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -510,6 +510,14 @@ multiclass BoolGOption<string flag_base, KeyPathAndMacro kpm,
Group<g_Group>;
}
+// FIXME: Diagnose if target does not support protected visibility.
+class MarshallingInfoVisibility<KeyPathAndMacro kpm, code default>
+ : MarshallingInfoString<kpm, default>,
+ Values<"default,hidden,internal,protected">,
+ NormalizedValues<["DefaultVisibility", "HiddenVisibility",
+ "HiddenVisibility", "ProtectedVisibility"]>,
+ AutoNormalizeEnum {}
+
// Key paths that are constant during parsing of options with the same key path prefix.
defvar open_cl = LangOpts<"OpenCL">;
@@ -2482,15 +2490,26 @@ def fno_var_tracking : Flag<["-"], "fno-var-tracking">, Group<clang_ignored_f_Gr
def fverbose_asm : Flag<["-"], "fverbose-asm">, Group<f_Group>,
HelpText<"Generate verbose assembly output">;
def dA : Flag<["-"], "dA">, Alias<fverbose_asm>;
-defm visibility_from_dllstorageclass : OptInFFlag<"visibility-from-dllstorageclass", "Set the visiblity of symbols in the generated code from their DLL storage class">;
+defm visibility_from_dllstorageclass : BoolFOption<"visibility-from-dllstorageclass",
+ LangOpts<"VisibilityFromDLLStorageClass">, DefaultsToFalse,
+ ChangedBy<PosFlag, [], "Set the visiblity of symbols in the generated code from their DLL storage class">,
+ ResetBy<NegFlag>>;
def fvisibility_dllexport_EQ : Joined<["-"], "fvisibility-dllexport=">, Group<f_Group>, Flags<[CC1Option]>,
- HelpText<"The visibility for dllexport defintions [-fvisibility-from-dllstorageclass]">, Values<"hidden,protected,default">;
+ HelpText<"The visibility for dllexport defintions [-fvisibility-from-dllstorageclass]">,
+ MarshallingInfoVisibility<LangOpts<"DLLExportVisibility">, "DefaultVisibility">,
+ ShouldParseIf<fvisibility_from_dllstorageclass.KeyPath>;
def fvisibility_nodllstorageclass_EQ : Joined<["-"], "fvisibility-nodllstorageclass=">, Group<f_Group>, Flags<[CC1Option]>,
- HelpText<"The visibility for defintiions without an explicit DLL export class [-fvisibility-from-dllstorageclass]">, Values<"hidden,protected,default">;
+ HelpText<"The visibility for defintiions without an explicit DLL export class [-fvisibility-from-dllstorageclass]">,
+ MarshallingInfoVisibility<LangOpts<"NoDLLStorageClassVisibility">, "HiddenVisibility">,
+ ShouldParseIf<fvisibility_from_dllstorageclass.KeyPath>;
def fvisibility_externs_dllimport_EQ : Joined<["-"], "fvisibility-externs-dllimport=">, Group<f_Group>, Flags<[CC1Option]>,
- HelpText<"The visibility for dllimport external declarations [-fvisibility-from-dllstorageclass]">, Values<"hidden,protected,default">;
+ HelpText<"The visibility for dllimport external declarations [-fvisibility-from-dllstorageclass]">,
+ MarshallingInfoVisibility<LangOpts<"ExternDeclDLLImportVisibility">, "DefaultVisibility">,
+ ShouldParseIf<fvisibility_from_dllstorageclass.KeyPath>;
def fvisibility_externs_nodllstorageclass_EQ : Joined<["-"], "fvisibility-externs-nodllstorageclass=">, Group<f_Group>, Flags<[CC1Option]>,
- HelpText<"The visibility for external declarations without an explicit DLL dllstorageclass [-fvisibility-from-dllstorageclass]">, Values<"hidden,protected,default">;
+ HelpText<"The visibility for external declarations without an explicit DLL dllstorageclass [-fvisibility-from-dllstorageclass]">,
+ MarshallingInfoVisibility<LangOpts<"ExternDeclNoDLLStorageClassVisibility">, "HiddenVisibility">,
+ ShouldParseIf<fvisibility_from_dllstorageclass.KeyPath>;
def fvisibility_EQ : Joined<["-"], "fvisibility=">, Group<f_Group>,
HelpText<"Set the default symbol visibility for all global declarations">, Values<"hidden,default">;
def fvisibility_inlines_hidden : Flag<["-"], "fvisibility-inlines-hidden">, Group<f_Group>,
@@ -5148,14 +5167,12 @@ def stack_protector : Separate<["-"], "stack-protector">,
def stack_protector_buffer_size : Separate<["-"], "stack-protector-buffer-size">,
HelpText<"Lower bound for a buffer to be considered for stack protection">,
MarshallingInfoStringInt<CodeGenOpts<"SSPBufferSize">, "8">;
-// FIXME: diagnose if target does not support protected visibility
-// Good place for this is CompilerInvocation::fixupInvocation. Do the same for parseVisibility.
def fvisibility : Separate<["-"], "fvisibility">,
- HelpText<"Default type and symbol visibility">, Values<"default,hidden,internal,protected">,
- NormalizedValues<["DefaultVisibility", "HiddenVisibility", "HiddenVisibility", "ProtectedVisibility"]>,
- MarshallingInfoString<LangOpts<"ValueVisibilityMode">, "DefaultVisibility">, AutoNormalizeEnum;
+ HelpText<"Default type and symbol visibility">,
+ MarshallingInfoVisibility<LangOpts<"ValueVisibilityMode">, "DefaultVisibility">;
def ftype_visibility : Separate<["-"], "ftype-visibility">,
- HelpText<"Default type visibility">;
+ HelpText<"Default type visibility">,
+ MarshallingInfoVisibility<LangOpts<"TypeVisibilityMode">, fvisibility.KeyPath>;
def fapply_global_visibility_to_externs : Flag<["-"], "fapply-global-visibility-to-externs">,
HelpText<"Apply global symbol visibility to external declarations without an explicit visibility">,
MarshallingInfoFlag<LangOpts<"SetVisibilityForExternDecls">>;
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 24b8fd19dd50..d18e6b9f9320 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2061,24 +2061,6 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
Opts.DoubleSquareBracketAttributes = Opts.CPlusPlus11 || Opts.C2x;
}
-/// Attempt to parse a visibility value out of the given argument.
-static Visibility parseVisibility(Arg *arg, ArgList &args,
- DiagnosticsEngine &diags) {
- StringRef value = arg->getValue();
- if (value == "default") {
- return DefaultVisibility;
- } else if (value == "hidden" || value == "internal") {
- return HiddenVisibility;
- } else if (value == "protected") {
- // FIXME: diagnose if target does not support protected visibility
- return ProtectedVisibility;
- }
-
- diags.Report(diag::err_drv_invalid_value)
- << arg->getAsString(args) << value;
- return DefaultVisibility;
-}
-
/// Check if input file kind and language standard are compatible.
static bool IsInputCompatibleWithStandard(InputKind IK,
const LangStandard &S) {
@@ -2366,45 +2348,6 @@ void CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.GNUInline = 1;
}
- // The type-visibility mode defaults to the value-visibility mode.
- if (Arg *typeVisOpt = Args.getLastArg(OPT_ftype_visibility)) {
- Opts.setTypeVisibilityMode(parseVisibility(typeVisOpt, Args, Diags));
- } else {
- Opts.setTypeVisibilityMode(Opts.getValueVisibilityMode());
- }
-
- if (Args.hasArg(OPT_fvisibility_from_dllstorageclass)) {
- Opts.VisibilityFromDLLStorageClass = 1;
-
- // Translate dllexport defintions to default visibility, by default.
- if (Arg *O = Args.getLastArg(OPT_fvisibility_dllexport_EQ))
- Opts.setDLLExportVisibility(parseVisibility(O, Args, Diags));
- else
- Opts.setDLLExportVisibility(DefaultVisibility);
-
- // Translate defintions without an explict DLL storage class to hidden
- // visibility, by default.
- if (Arg *O = Args.getLastArg(OPT_fvisibility_nodllstorageclass_EQ))
- Opts.setNoDLLStorageClassVisibility(parseVisibility(O, Args, Diags));
- else
- Opts.setNoDLLStorageClassVisibility(HiddenVisibility);
-
- // Translate dllimport external declarations to default visibility, by
- // default.
- if (Arg *O = Args.getLastArg(OPT_fvisibility_externs_dllimport_EQ))
- Opts.setExternDeclDLLImportVisibility(parseVisibility(O, Args, Diags));
- else
- Opts.setExternDeclDLLImportVisibility(DefaultVisibility);
-
- // Translate external declarations without an explicit DLL storage class
- // to hidden visibility, by default.
- if (Arg *O = Args.getLastArg(OPT_fvisibility_externs_nodllstorageclass_EQ))
- Opts.setExternDeclNoDLLStorageClassVisibility(
- parseVisibility(O, Args, Diags));
- else
- Opts.setExternDeclNoDLLStorageClassVisibility(HiddenVisibility);
- }
-
if (Args.hasArg(OPT_ftrapv)) {
Opts.setSignedOverflowBehavior(LangOptions::SOB_Trapping);
// Set the handler, if one is specified.
More information about the llvm-branch-commits
mailing list