Skip to content

Commit a5414db

Browse files
committed
[Clang][Driver] Add new flags to control IR verification
1 parent 45a334d commit a5414db

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

clang/docs/ReleaseNotes.rst

+7
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ Non-comprehensive list of changes in this release
146146

147147
New Compiler Flags
148148
------------------
149+
* ``-fverify-intermediate-code`` and it's complement ``-fno-verify-intermediate-code``.
150+
Enables or disables verification of the generated LLVM IR.
151+
Users can pass this to turn on extra verification to catch certain types of
152+
compiler bugs at the cost of extra compile time.
153+
Since enabling the verifier adds a non-trivial cost of a few percent impact on
154+
build times, it's disabled by default, unless your LLVM distribution itself is
155+
compiled with runtime checks enabled.
149156

150157
Deprecated Compiler Flags
151158
-------------------------

clang/include/clang/Driver/Options.td

+6
Original file line numberDiff line numberDiff line change
@@ -1909,6 +1909,12 @@ defm safe_buffer_usage_suggestions : BoolFOption<"safe-buffer-usage-suggestions"
19091909
PosFlag<SetTrue, [], [ClangOption, CC1Option],
19101910
"Display suggestions to update code associated with -Wunsafe-buffer-usage warnings">,
19111911
NegFlag<SetFalse>>;
1912+
def fverify_intermediate_code : Flag<["-"], "fverify-intermediate-code">,
1913+
Group<f_clang_Group>, Visibility<[ClangOption, CLOption, DXCOption]>,
1914+
HelpText<"Enable verification of LLVM IR">, Flags<[NoXarchOption]>;
1915+
def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
1916+
Group<f_clang_Group>, Visibility<[ClangOption, CLOption, DXCOption]>,
1917+
HelpText<"Disable verification of LLVM IR">, Flags<[NoXarchOption]>;
19121918
def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">,
19131919
Group<f_clang_Group>, Visibility<[ClangOption, DXCOption]>,
19141920
HelpText<"Discard value names in LLVM IR">, Flags<[NoXarchOption]>;

clang/lib/Driver/ToolChains/Clang.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -5150,9 +5150,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
51505150
const bool IsAssertBuild = true;
51515151
#endif
51525152

5153-
// Disable the verification pass in -asserts builds.
5154-
if (!IsAssertBuild)
5153+
// Disable the verification pass in asserts builds unless otherwise specified.
5154+
if (Args.hasFlag(options::OPT_fno_verify_intermediate_code,
5155+
options::OPT_fverify_intermediate_code, !IsAssertBuild)) {
51555156
CmdArgs.push_back("-disable-llvm-verifier");
5157+
}
51565158

51575159
// Discard value names in assert builds unless otherwise specified.
51585160
if (Args.hasFlag(options::OPT_fdiscard_value_names,

clang/test/Driver/clang_f_opts.c

+5
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,11 @@
520520
// CHECK-COVERAGE-COMPILATION-DIR: "-fcoverage-compilation-dir=."
521521
// CHECK-COVERAGE-COMPILATION-DIR-NOT: "-ffile-compilation-dir=."
522522

523+
// RUN: %clang -### -S -fverify-intermediate-code %s 2>&1 | FileCheck -check-prefix=CHECK-VERIFY-INTERMEDIATE-CODE %s
524+
// RUN: %clang -### -S -fno-verify-intermediate-code %s 2>&1 | FileCheck -check-prefix=CHECK-NO-VERIFY-INTERMEDIATE-CODE %s
525+
// CHECK-VERIFY-INTERMEDIATE-CODE-NOT: "-disable-llvm-verifier"
526+
// CHECK-NO-VERIFY-INTERMEDIATE-CODE: "-disable-llvm-verifier"
527+
523528
// RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-DISCARD-NAMES %s
524529
// RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-NO-DISCARD-NAMES %s
525530
// CHECK-DISCARD-NAMES: "-discard-value-names"

0 commit comments

Comments
 (0)