[clang] 6da382d - [Clang][Driver] Add new flags to control IR verification (#68172)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 4 15:50:36 PDT 2023
Author: Matheus Izvekov
Date: 2023-10-05T00:50:30+02:00
New Revision: 6da382d27bb5c21dfce8ae5239ab5797bc191cab
URL: https://github.com/llvm/llvm-project/commit/6da382d27bb5c21dfce8ae5239ab5797bc191cab
DIFF: https://github.com/llvm/llvm-project/commit/6da382d27bb5c21dfce8ae5239ab5797bc191cab.diff
LOG: [Clang][Driver] Add new flags to control IR verification (#68172)
Enables or disables verification of the generated LLVM IR.
Users can pass this to turn on extra verification to catch certain types of
compiler bugs at the cost of extra compile time.
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/clang_f_opts.c
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6f410c48bd1ffe9..23cc8cfe3b2773c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -146,6 +146,13 @@ Non-comprehensive list of changes in this release
New Compiler Flags
------------------
+* ``-fverify-intermediate-code`` and its complement ``-fno-verify-intermediate-code``.
+ Enables or disables verification of the generated LLVM IR.
+ Users can pass this to turn on extra verification to catch certain types of
+ compiler bugs at the cost of extra compile time.
+ Since enabling the verifier adds a non-trivial cost of a few percent impact on
+ build times, it's disabled by default, unless your LLVM distribution itself is
+ compiled with runtime checks enabled.
Deprecated Compiler Flags
-------------------------
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 74f255624ce2cd6..381126be176ac4f 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1909,6 +1909,12 @@ defm safe_buffer_usage_suggestions : BoolFOption<"safe-buffer-usage-suggestions"
PosFlag<SetTrue, [], [ClangOption, CC1Option],
"Display suggestions to update code associated with -Wunsafe-buffer-usage warnings">,
NegFlag<SetFalse>>;
+def fverify_intermediate_code : Flag<["-"], "fverify-intermediate-code">,
+ Group<f_clang_Group>, Visibility<[ClangOption, CLOption, DXCOption]>,
+ HelpText<"Enable verification of LLVM IR">, Flags<[NoXarchOption]>;
+def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
+ Group<f_clang_Group>, Visibility<[ClangOption, CLOption, DXCOption]>,
+ HelpText<"Disable verification of LLVM IR">, Flags<[NoXarchOption]>;
def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">,
Group<f_clang_Group>, Visibility<[ClangOption, DXCOption]>,
HelpText<"Discard value names in LLVM IR">, Flags<[NoXarchOption]>;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index fc3615245000109..c74f6ff447261dc 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5150,9 +5150,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
const bool IsAssertBuild = true;
#endif
- // Disable the verification pass in -asserts builds.
- if (!IsAssertBuild)
+ // Disable the verification pass in asserts builds unless otherwise specified.
+ if (Args.hasFlag(options::OPT_fno_verify_intermediate_code,
+ options::OPT_fverify_intermediate_code, !IsAssertBuild)) {
CmdArgs.push_back("-disable-llvm-verifier");
+ }
// Discard value names in assert builds unless otherwise specified.
if (Args.hasFlag(options::OPT_fdiscard_value_names,
diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c
index 7a3616a2e9f0a48..ebe8a0520bf0fca 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -520,6 +520,11 @@
// CHECK-COVERAGE-COMPILATION-DIR: "-fcoverage-compilation-dir=."
// CHECK-COVERAGE-COMPILATION-DIR-NOT: "-ffile-compilation-dir=."
+// RUN: %clang -### -S -fverify-intermediate-code %s 2>&1 | FileCheck -check-prefix=CHECK-VERIFY-INTERMEDIATE-CODE %s
+// RUN: %clang -### -S -fno-verify-intermediate-code %s 2>&1 | FileCheck -check-prefix=CHECK-NO-VERIFY-INTERMEDIATE-CODE %s
+// CHECK-VERIFY-INTERMEDIATE-CODE-NOT: "-disable-llvm-verifier"
+// CHECK-NO-VERIFY-INTERMEDIATE-CODE: "-disable-llvm-verifier"
+
// RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-DISCARD-NAMES %s
// RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-NO-DISCARD-NAMES %s
// CHECK-DISCARD-NAMES: "-discard-value-names"
More information about the cfe-commits
mailing list