diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -510,6 +510,14 @@ Group; } +// FIXME: Diagnose if target does not support protected visibility. +class MarshallingInfoVisibility + : MarshallingInfoString, + 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 fverbose_asm : Flag<["-"], "fverbose-asm">, Group, HelpText<"Generate verbose assembly output">; def dA : Flag<["-"], "dA">, Alias; -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, + ResetBy>; def fvisibility_dllexport_EQ : Joined<["-"], "fvisibility-dllexport=">, 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, "DefaultVisibility">, + ShouldParseIf; def fvisibility_nodllstorageclass_EQ : Joined<["-"], "fvisibility-nodllstorageclass=">, 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, "HiddenVisibility">, + ShouldParseIf; def fvisibility_externs_dllimport_EQ : Joined<["-"], "fvisibility-externs-dllimport=">, 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, "DefaultVisibility">, + ShouldParseIf; def fvisibility_externs_nodllstorageclass_EQ : Joined<["-"], "fvisibility-externs-nodllstorageclass=">, 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, "HiddenVisibility">, + ShouldParseIf; def fvisibility_EQ : Joined<["-"], "fvisibility=">, Group, HelpText<"Set the default symbol visibility for all global declarations">, Values<"hidden,default">; def fvisibility_inlines_hidden : Flag<["-"], "fvisibility-inlines-hidden">, Group, @@ -5147,14 +5166,12 @@ def stack_protector_buffer_size : Separate<["-"], "stack-protector-buffer-size">, HelpText<"Lower bound for a buffer to be considered for stack protection">, MarshallingInfoStringInt, "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, "DefaultVisibility">, AutoNormalizeEnum; + HelpText<"Default type and symbol visibility">, + MarshallingInfoVisibility, "DefaultVisibility">; def ftype_visibility : Separate<["-"], "ftype-visibility">, - HelpText<"Default type visibility">; + HelpText<"Default type visibility">, + MarshallingInfoVisibility, 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>; diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -2061,24 +2061,6 @@ 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 @@ 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.