From 87a29e4d936af7487433ca562688be21bb3a65cb Mon Sep 17 00:00:00 2001 From: naddy Date: Sat, 6 Feb 2021 21:40:59 +0000 Subject: [PATCH] switch clang to -fno-common by default Common variables will be flagged as errors by default. This can be overridden with -fcommon. Cherry-pick this change that will be part of LLVM11. We bring it forward so we can finish fixing the fallout in the ports tree. ok deraadt@ sthen@ mglocker@ --- .../clang/include/clang/Driver/Options.td | 3 ++- .../clang/lib/Driver/ToolChains/Clang.cpp | 22 +++---------------- .../clang/lib/Frontend/CompilerInvocation.cpp | 2 +- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/gnu/llvm/clang/include/clang/Driver/Options.td b/gnu/llvm/clang/include/clang/Driver/Options.td index ff76bcb7ef7..a370a522e84 100644 --- a/gnu/llvm/clang/include/clang/Driver/Options.td +++ b/gnu/llvm/clang/include/clang/Driver/Options.td @@ -840,7 +840,8 @@ def fno_record_command_line : Flag<["-"], "fno-record-command-line">, Group; def : Flag<["-"], "frecord-gcc-switches">, Alias; def : Flag<["-"], "fno-record-gcc-switches">, Alias; -def fcommon : Flag<["-"], "fcommon">, Group; +def fcommon : Flag<["-"], "fcommon">, Group, + Flags<[CoreOption, CC1Option]>, HelpText<"Place uninitialized global variables in a common block">; def fcompile_resource_EQ : Joined<["-"], "fcompile-resource=">, Group; def fcomplete_member_pointers : Flag<["-"], "fcomplete-member-pointers">, Group, Flags<[CoreOption, CC1Option]>, diff --git a/gnu/llvm/clang/lib/Driver/ToolChains/Clang.cpp b/gnu/llvm/clang/lib/Driver/ToolChains/Clang.cpp index 03f637113d1..69900484f61 100644 --- a/gnu/llvm/clang/lib/Driver/ToolChains/Clang.cpp +++ b/gnu/llvm/clang/lib/Driver/ToolChains/Clang.cpp @@ -1404,20 +1404,6 @@ static bool isSignedCharDefault(const llvm::Triple &Triple) { } } -static bool isNoCommonDefault(const llvm::Triple &Triple) { - switch (Triple.getArch()) { - default: - if (Triple.isOSFuchsia()) - return true; - return false; - - case llvm::Triple::xcore: - case llvm::Triple::wasm32: - case llvm::Triple::wasm64: - return true; - } -} - static bool hasMultipleInvocations(const llvm::Triple &Triple, const ArgList &Args) { // Supported only on Darwin where we invoke the compiler multiple times @@ -5638,11 +5624,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (!Args.hasFlag(options::OPT_Qy, options::OPT_Qn, true)) CmdArgs.push_back("-Qn"); - // -fcommon is the default unless compiling kernel code or the target says so - bool NoCommonDefault = KernelOrKext || isNoCommonDefault(RawTriple); - if (!Args.hasFlag(options::OPT_fcommon, options::OPT_fno_common, - !NoCommonDefault)) - CmdArgs.push_back("-fno-common"); + // -fno-common is the default, set -fcommon only when that flag is set. + if (Args.hasFlag(options::OPT_fcommon, options::OPT_fno_common, false)) + CmdArgs.push_back("-fcommon"); // -fsigned-bitfields is default, and clang doesn't yet support // -funsigned-bitfields. diff --git a/gnu/llvm/clang/lib/Frontend/CompilerInvocation.cpp b/gnu/llvm/clang/lib/Frontend/CompilerInvocation.cpp index e33e80f5b37..f47906798a0 100644 --- a/gnu/llvm/clang/lib/Frontend/CompilerInvocation.cpp +++ b/gnu/llvm/clang/lib/Frontend/CompilerInvocation.cpp @@ -808,7 +808,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags); Opts.RecordCommandLine = Args.getLastArgValue(OPT_record_command_line); Opts.MergeAllConstants = Args.hasArg(OPT_fmerge_all_constants); - Opts.NoCommon = Args.hasArg(OPT_fno_common); + Opts.NoCommon = !Args.hasArg(OPT_fcommon); Opts.NoInlineLineTables = Args.hasArg(OPT_gno_inline_line_tables); Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float); Opts.OptimizeSize = getOptimizationLevelSize(Args); -- 2.20.1