Skip to content

Commit b2006f4

Browse files
committed
[Clang][Driver] Add new flags to control machine instruction verification
1 parent fa18827 commit b2006f4

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,13 @@ New Compiler Flags
206206
Since enabling the verifier adds a non-trivial cost of a few percent impact on
207207
build times, it's disabled by default, unless your LLVM distribution itself is
208208
compiled with runtime checks enabled.
209+
* ``-fverify-machine-code`` and its complement ``-fno-verify-machine-code``.
210+
Enable or disable the verification of the generated machine code.
211+
Users can pass this to turn on extra verification to catch certain types of
212+
compiler bugs at the cost of extra compile time.
213+
This verifier adds a huge overhead to compile time, it's expected that build times
214+
can double, so this is disabled by default.
215+
This flag is currently limited to non-LTO builds.
209216
* ``-fkeep-system-includes`` modifies the behavior of the ``-E`` option,
210217
preserving ``#include`` directives for "system" headers instead of copying
211218
the preprocessed text to the output. This can greatly reduce the size of the

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,12 @@ def fverify_intermediate_code : Flag<["-"], "fverify-intermediate-code">,
19251925
def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
19261926
Group<f_clang_Group>, Visibility<[ClangOption, CLOption, DXCOption]>,
19271927
HelpText<"Disable verification of LLVM IR">;
1928+
def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
1929+
Group<f_clang_Group>, Visibility<[ClangOption, CLOption, DXCOption]>,
1930+
HelpText<"Enable verification of generated machine code">;
1931+
def fno_verify_machine_code : Flag<["-"], "fno-verify-machine-code">,
1932+
Group<f_clang_Group>, Visibility<[ClangOption, CLOption, DXCOption]>,
1933+
HelpText<"Disable verification of generated machine code">;
19281934
def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">,
19291935
Group<f_clang_Group>, Visibility<[ClangOption, DXCOption]>,
19301936
HelpText<"Discard value names in LLVM IR">;

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5175,6 +5175,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
51755175
CmdArgs.push_back("-disable-llvm-verifier");
51765176
}
51775177

5178+
// Enable the machine code verification pass. Note that this is force enabled
5179+
// elsewhere with LLVM_ENABLE_EXPENSIVE_CHECKS.
5180+
if (Args.hasFlag(options::OPT_fverify_machine_code,
5181+
options::OPT_fno_verify_machine_code, false)) {
5182+
CmdArgs.push_back("-mllvm");
5183+
CmdArgs.push_back("-verify-machineinstrs");
5184+
}
5185+
51785186
// Discard value names in assert builds unless otherwise specified.
51795187
if (Args.hasFlag(options::OPT_fdiscard_value_names,
51805188
options::OPT_fno_discard_value_names, !IsAssertBuild)) {

clang/test/Driver/clang_f_opts.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,11 @@
525525
// CHECK-VERIFY-INTERMEDIATE-CODE-NOT: "-disable-llvm-verifier"
526526
// CHECK-NO-VERIFY-INTERMEDIATE-CODE: "-disable-llvm-verifier"
527527

528+
// RUN: %clang -### -S -fverify-machine-code %s 2>&1 | FileCheck -check-prefix=CHECK-VERIFY-MACHINE-CODE %s
529+
// RUN: %clang -### -S -fno-verify-machine-code %s 2>&1 | FileCheck -check-prefix=CHECK-NO-VERIFY-MACHINE-CODE %s
530+
// CHECK-VERIFY-MACHINE-CODE: "-mllvm" "-verify-machineinstrs"
531+
// CHECK-NO-VERIFY-MACHINE-CODE-NOT: "-mllvm" "-verify-machineinstrs"
532+
528533
// RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-DISCARD-NAMES %s
529534
// RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-NO-DISCARD-NAMES %s
530535
// CHECK-DISCARD-NAMES: "-discard-value-names"

0 commit comments

Comments
 (0)