[clang] [CLang][Driver] Add new flags to control IR verification (PR #68172)
Matheus Izvekov via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 3 19:42:47 PDT 2023
https://github.com/mizvekov created https://github.com/llvm/llvm-project/pull/68172
None
>From 4aec8113bc23d361164f1e164c8e4e36a9eb0ad0 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov <mizvekov at gmail.com>
Date: Wed, 4 Oct 2023 04:39:11 +0200
Subject: [PATCH] [CLang][Driver] Add new flags to control IR verification
---
clang/docs/ReleaseNotes.rst | 6 ++++++
clang/include/clang/Driver/Options.td | 6 ++++++
clang/lib/Driver/ToolChains/Clang.cpp | 6 ++++--
clang/test/Driver/clang_f_opts.c | 5 +++++
4 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3dce7f6a8f9d56e..1e1433589ddd7c9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -146,6 +146,12 @@ Non-comprehensive list of changes in this release
New Compiler Flags
------------------
+* ``-fdisable-llvm-verifier`` and it's complement ``-fno-disable-llvm-verifier``.
+ It's strongly encouraged to enable this verification, as it can catch hard to
+ find code generation bugs.
+ 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 61e0729974c24d1..6911acb7420ec60 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1905,6 +1905,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 fdisable_llvm_verifier : Flag<["-"], "fdisable-llvm-verifier">,
+ Group<f_clang_Group>, Visibility<[ClangOption, CLOption, DXCOption]>,
+ HelpText<"Disable verification of LLVM IR">, Flags<[NoXarchOption]>;
+def fno_disable_llvm_verifier : Flag<["-"], "fno-disable-llvm-verifier">,
+ Group<f_clang_Group>, Visibility<[ClangOption, CLOption, DXCOption]>,
+ HelpText<"Do not 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 129adfb9fcc74d1..1f1afee57ba4259 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_fdisable_llvm_verifier,
+ options::OPT_fno_disable_llvm_verifier, !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..f9882c2604cbb18 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 -fdisable-llvm-verifier %s 2>&1 | FileCheck -check-prefix=CHECK-DISABLE-LLVM-VERIFIER %s
+// RUN: %clang -### -S -fno-disable-llvm-verifier %s 2>&1 | FileCheck -check-prefix=CHECK-NO-DISABLE-LLVM-VERIFIER %s
+// CHECK-DISABLE-LLVM-VERIFIER: "-disable-llvm-verifier"
+// CHECK-NO-DISABLE-LLVM-VERIFIER-NOT: "-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