Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ New Compiler Flags
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.
* ``-fverify-machine-code`` and its complement ``-fno-verify-machine-code``.
Enable or disable the verification of the generated machine code.
Users can pass this to turn on extra verification to catch certain types of
compiler bugs at the cost of extra compile time.
This verifier adds a huge overhead to compile time, it's expected that build times
can double, so this is disabled by default.
This flag is currently limited to non-LTO builds.
* ``-fkeep-system-includes`` modifies the behavior of the ``-E`` option,
preserving ``#include`` directives for "system" headers instead of copying
the preprocessed text to the output. This can greatly reduce the size of the
Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -1925,6 +1925,12 @@ def fverify_intermediate_code : Flag<["-"], "fverify-intermediate-code">,
def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
Group<f_clang_Group>, Visibility<[ClangOption, CLOption, DXCOption]>,
HelpText<"Disable verification of LLVM IR">;
def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
Group<f_clang_Group>, Visibility<[ClangOption, CLOption, DXCOption]>,
HelpText<"Enable verification of generated machine code">;
def fno_verify_machine_code : Flag<["-"], "fno-verify-machine-code">,
Group<f_clang_Group>, Visibility<[ClangOption, CLOption, DXCOption]>,
HelpText<"Disable verification of generated machine code">;
def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">,
Group<f_clang_Group>, Visibility<[ClangOption, DXCOption]>,
HelpText<"Discard value names in LLVM IR">;
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5175,6 +5175,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-disable-llvm-verifier");
}

// Enable the machine code verification pass. Note that this is force enabled
// elsewhere with LLVM_ENABLE_EXPENSIVE_CHECKS.
if (Args.hasFlag(options::OPT_fverify_machine_code,
options::OPT_fno_verify_machine_code, false)) {
CmdArgs.push_back("-mllvm");
CmdArgs.push_back("-verify-machineinstrs");
}

// Discard value names in assert builds unless otherwise specified.
if (Args.hasFlag(options::OPT_fdiscard_value_names,
options::OPT_fno_discard_value_names, !IsAssertBuild)) {
Expand Down
5 changes: 5 additions & 0 deletions clang/test/Driver/clang_f_opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,11 @@
// CHECK-VERIFY-INTERMEDIATE-CODE-NOT: "-disable-llvm-verifier"
// CHECK-NO-VERIFY-INTERMEDIATE-CODE: "-disable-llvm-verifier"

// RUN: %clang -### -S -fverify-machine-code %s 2>&1 | FileCheck -check-prefix=CHECK-VERIFY-MACHINE-CODE %s
// RUN: %clang -### -S -fno-verify-machine-code %s 2>&1 | FileCheck -check-prefix=CHECK-NO-VERIFY-MACHINE-CODE %s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to strengthen this RUN line, -fverify-machine-code -fno-verify-machine-code

// CHECK-VERIFY-MACHINE-CODE: "-mllvm" "-verify-machineinstrs"
// CHECK-NO-VERIFY-MACHINE-CODE-NOT: "-mllvm" "-verify-machineinstrs"

// 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"
Expand Down