Skip to content

[Clang][Driver] Add new flags to control IR verification #68172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 4, 2023
Merged
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 @@ -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
-------------------------
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 @@ -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]>;
Expand Down
6 changes: 4 additions & 2 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5150,9 +5150,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
const bool IsAssertBuild = true;
#endif

// Disable the verification pass in -asserts builds.
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I might be missing something here, but doesn't this disable the verifier for builds without assertions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I edited the line to append the unless otherwise specified, since now we allow overriding that with the new flag.

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,
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 @@ -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"
Expand Down