[llvm] aed6a1b - Add tests for clang -fno-zero-initialized-in-bss and llc -nozero-initialized-in-bss
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 4 23:27:58 PDT 2020
Author: Fangrui Song
Date: 2020-07-04T23:26:57-07:00
New Revision: aed6a1b137dc17426e3da8b85e1f9966c8229c05
URL: https://github.com/llvm/llvm-project/commit/aed6a1b137dc17426e3da8b85e1f9966c8229c05
DIFF: https://github.com/llvm/llvm-project/commit/aed6a1b137dc17426e3da8b85e1f9966c8229c05.diff
LOG: Add tests for clang -fno-zero-initialized-in-bss and llc -nozero-initialized-in-bss
And rename the CC1 option.
Added:
clang/test/Driver/fzero-initialized-in-bss.c
llvm/test/CodeGen/X86/zero-initialized-in-bss.ll
Modified:
clang/include/clang/Driver/CC1Options.td
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/CC1Options.td b/clang/include/clang/Driver/CC1Options.td
index 8729512454c3..75f8aa610d04 100644
--- a/clang/include/clang/Driver/CC1Options.td
+++ b/clang/include/clang/Driver/CC1Options.td
@@ -307,8 +307,6 @@ def mlimit_float_precision : Separate<["-"], "mlimit-float-precision">,
HelpText<"Limit float precision to the given value">;
def split_stacks : Flag<["-"], "split-stacks">,
HelpText<"Try to use a split stack if possible.">;
-def mno_zero_initialized_in_bss : Flag<["-"], "mno-zero-initialized-in-bss">,
- HelpText<"Do not put zero initialized data in the BSS">;
def mregparm : Separate<["-"], "mregparm">,
HelpText<"Limit the number of registers available for integer arguments">;
def msmall_data_limit : Separate<["-"], "msmall-data-limit">,
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index d030468514c3..e636ee62d202 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1589,7 +1589,6 @@ def fno_unwind_tables : Flag<["-"], "fno-unwind-tables">, Group<f_Group>;
def fno_verbose_asm : Flag<["-"], "fno-verbose-asm">, Group<f_Group>, Flags<[CC1Option]>;
def fno_working_directory : Flag<["-"], "fno-working-directory">, Group<f_Group>;
def fno_wrapv : Flag<["-"], "fno-wrapv">, Group<f_Group>;
-def fno_zero_initialized_in_bss : Flag<["-"], "fno-zero-initialized-in-bss">, Group<f_Group>;
def fobjc_arc : Flag<["-"], "fobjc-arc">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Synthesize retain and release calls for Objective-C pointers">;
def fno_objc_arc : Flag<["-"], "fno-objc-arc">, Group<f_Group>;
@@ -1926,7 +1925,7 @@ def fwrapv : Flag<["-"], "fwrapv">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Treat signed integer overflow as two's complement">;
def fwritable_strings : Flag<["-"], "fwritable-strings">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Store string literals as writable data">;
-def fzero_initialized_in_bss : Flag<["-"], "fzero-initialized-in-bss">, Group<f_Group>;
+defm zero_initialized_in_bss : OptOutFFlag<"zero-initialized-in-bss", "", "Don't place zero initialized data in BSS">;
defm function_sections : OptInFFlag<"function-sections", "Place each function in its own section">;
def fbasic_block_sections_EQ : Joined<["-"], "fbasic-block-sections=">, Group<f_Group>,
Flags<[CC1Option, CC1AsOption]>,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index e6dd6ce0a95e..a0d638e7366d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4556,8 +4556,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back(FPKeepKindStr);
if (!Args.hasFlag(options::OPT_fzero_initialized_in_bss,
- options::OPT_fno_zero_initialized_in_bss))
- CmdArgs.push_back("-mno-zero-initialized-in-bss");
+ options::OPT_fno_zero_initialized_in_bss, true))
+ CmdArgs.push_back("-fno-zero-initialized-in-bss");
bool OFastEnabled = isOptimizationLevelFast(Args);
// If -Ofast is the optimization level, then -fstrict-aliasing should be
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index e12931a5a1b4..821e40c5ea8d 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -942,7 +942,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
Opts.StrictFloatCastOverflow =
!Args.hasArg(OPT_fno_strict_float_cast_overflow);
- Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss);
+ Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_fno_zero_initialized_in_bss);
Opts.NumRegisterParameters = getLastArgIntValue(Args, OPT_mregparm, 0, Diags);
Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack);
Opts.SmallDataLimit =
diff --git a/clang/test/Driver/fzero-initialized-in-bss.c b/clang/test/Driver/fzero-initialized-in-bss.c
new file mode 100644
index 000000000000..34a1dc9788cd
--- /dev/null
+++ b/clang/test/Driver/fzero-initialized-in-bss.c
@@ -0,0 +1,8 @@
+// RUN: %clang -### %s -c -fzero-initialized-in-bss 2>&1 | FileCheck %s --check-prefix=NO
+// RUN: %clang -### %s -c 2>&1 | FileCheck %s --check-prefix=NO
+
+// NO-NOT: -fno-zero-initialized-in-bss
+
+// RUN: %clang -### %s -c -fzero-initialized-in-bss -fno-zero-initialized-in-bss 2>&1 | FileCheck %s
+
+// CHECK: -fno-zero-initialized-in-bss
diff --git a/llvm/test/CodeGen/X86/zero-initialized-in-bss.ll b/llvm/test/CodeGen/X86/zero-initialized-in-bss.ll
new file mode 100644
index 000000000000..2feee54856e2
--- /dev/null
+++ b/llvm/test/CodeGen/X86/zero-initialized-in-bss.ll
@@ -0,0 +1,16 @@
+; RUN: llc < %s -mtriple=x86_64 | FileCheck %s --check-prefix=BSS
+
+; BSS: .bss
+; BSS-NEXT: .globl a
+; BSS: .section .tbss,"awT", at nobits
+; BSS-NEXT: .globl b
+
+; RUN: llc < %s -mtriple=x86_64 -nozero-initialized-in-bss | FileCheck %s --check-prefix=DATA
+
+; DATA: .data
+; DATA-NEXT: .globl a
+; DATA: .section .tdata,"awT", at progbits
+; DATA-NEXT: .globl b
+
+ at a = global i32 0
+ at b = thread_local global i32 0
More information about the llvm-commits
mailing list