[PATCH] D113523: Add toggling for -fnew-infallible/-fno-new-infallible
Di Mo via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 9 21:55:16 PST 2021
modimo updated this revision to Diff 386059.
modimo added a comment.
Add driver test
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D113523/new/
https://reviews.llvm.org/D113523
Files:
clang/docs/ClangCommandLineReference.rst
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CodeGenCXX/new-infallible.cpp
clang/test/Driver/new-infallible.cpp
Index: clang/test/Driver/new-infallible.cpp
===================================================================
--- /dev/null
+++ clang/test/Driver/new-infallible.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang -### -S -fno-new-infallible -fnew-infallible %s 2>&1 | FileCheck --check-prefix=NEW-INFALLIBLE %s
+// NEW-INFALLIBLE: "-fnew-infallible"
+
+// RUN: %clang -### -S -fnew-infallible -fno-new-infallible %s 2>&1 | FileCheck --check-prefix=NO-NEW-INFALLIBLE %s
+// NO-NEW-INFALLIBLE-NOT: "-fnew-infallible"
\ No newline at end of file
Index: clang/test/CodeGenCXX/new-infallible.cpp
===================================================================
--- clang/test/CodeGenCXX/new-infallible.cpp
+++ clang/test/CodeGenCXX/new-infallible.cpp
@@ -1,7 +1,16 @@
// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu -fnew-infallible -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu -fno-new-infallible -fnew-infallible -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu -fno-new-infallible -o - %s | FileCheck %s --check-prefix=NO-NEW-INFALLIBLE
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu -fnew-infallible -fno-new-infallible -o - %s | FileCheck %s --check-prefix=NO-NEW-INFALLIBLE
// CHECK: call noalias nonnull i8* @_Znwm(i64 4)
// CHECK: ; Function Attrs: nobuiltin nounwind allocsize(0)
// CHECK-NEXT: declare nonnull i8* @_Znwm(i64)
+
+// NO-NEW-INFALLIBLE: call noalias nonnull i8* @_Znwm(i64 4)
+
+// NO-NEW-INFALLIBLE: ; Function Attrs: nobuiltin allocsize(0)
+// NO-NEW-INFALLIBLE-NEXT: declare nonnull i8* @_Znwm(i64)
+
int *new_infallible = new int;
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5810,9 +5810,12 @@
Args.AddLastArg(CmdArgs, options::OPT_fvisibility_inlines_hidden_static_local_var,
options::OPT_fno_visibility_inlines_hidden_static_local_var);
Args.AddLastArg(CmdArgs, options::OPT_fvisibility_global_new_delete_hidden);
- Args.AddLastArg(CmdArgs, options::OPT_fnew_infallible);
Args.AddLastArg(CmdArgs, options::OPT_ftlsmodel_EQ);
+ if (Args.hasFlag(options::OPT_fnew_infallible,
+ options::OPT_fno_new_infallible, false))
+ CmdArgs.push_back("-fnew-infallible");
+
if (Args.hasFlag(options::OPT_fno_operator_names,
options::OPT_foperator_names, false))
CmdArgs.push_back("-fno-operator-names");
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2786,10 +2786,11 @@
def fvisibility_global_new_delete_hidden : Flag<["-"], "fvisibility-global-new-delete-hidden">, Group<f_Group>,
HelpText<"Give global C++ operator new and delete declarations hidden visibility">, Flags<[CC1Option]>,
MarshallingInfoFlag<LangOpts<"GlobalAllocationFunctionVisibilityHidden">>;
-def fnew_infallible : Flag<["-"], "fnew-infallible">, Group<f_Group>,
- HelpText<"Treats throwing global C++ operator new as always returning valid memory "
- "(annotates with __attribute__((returns_nonnull)) and throw()). This is detectable in source.">,
- Flags<[CC1Option]>, MarshallingInfoFlag<LangOpts<"NewInfallible">>;
+defm new_infallible : BoolFOption<"new-infallible",
+ LangOpts<"NewInfallible">, DefaultFalse,
+ PosFlag<SetTrue, [], "Enable">, NegFlag<SetFalse, [], "Disable">,
+ BothFlags<[CC1Option], " treating throwing global C++ operator new as always returning valid memory "
+ "(annotates with __attribute__((returns_nonnull)) and throw()). This is detectable in source.">>;
defm whole_program_vtables : BoolFOption<"whole-program-vtables",
CodeGenOpts<"WholeProgramVTables">, DefaultFalse,
PosFlag<SetTrue, [CC1Option], "Enables whole-program vtable optimization. Requires -flto">,
Index: clang/docs/ClangCommandLineReference.rst
===================================================================
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -1941,9 +1941,9 @@
Specifies the largest alignment guaranteed by '::operator new(size\_t)'
-.. option:: -fnew-infallible
+.. option:: -fnew-infallible, -fno-new-infallible
-Treats throwing global C++ operator new as always returning valid memory (annotates with \_\_attribute\_\_((returns\_nonnull)) and throw()). This is detectable in source.
+Enable treating throwing global C++ operator new as always returning valid memory (annotates with \_\_attribute\_\_((returns\_nonnull)) and throw()). This is detectable in source.
.. option:: -fnext-runtime
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113523.386059.patch
Type: text/x-patch
Size: 4749 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211110/76c82317/attachment-0001.bin>
More information about the cfe-commits
mailing list