[clang] 8420a53 - [Debugify] Expose original debug info preservation check as CC1 option
Djordje Todorovic via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 25 05:31:10 PDT 2021
Author: Djordje Todorovic
Date: 2021-03-25T05:29:42-07:00
New Revision: 8420a5332486c682c1aaddbcb58a571869d19832
URL: https://github.com/llvm/llvm-project/commit/8420a5332486c682c1aaddbcb58a571869d19832
DIFF: https://github.com/llvm/llvm-project/commit/8420a5332486c682c1aaddbcb58a571869d19832.diff
LOG: [Debugify] Expose original debug info preservation check as CC1 option
In order to test the preservation of the original Debug Info metadata
in your projects, a front end option could be very useful, since users
usually report that a concrete entity (e.g. variable x, or function fn2())
is missing debug info. The [0] is an example of running the utility
on GDB Project.
This depends on: D82546 and D82545.
Differential Revision: https://reviews.llvm.org/D82547
Added:
clang/test/Driver/verify-debug-info-preservation.c
Modified:
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Frontend/CompilerInvocation.cpp
llvm/docs/HowToUpdateDebugInfo.rst
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def
index bbda74044a1c..4c354734dff8 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -70,6 +70,10 @@ CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug information for the new
CODEGENOPT(DisableRedZone , 1, 0) ///< Set when -mno-red-zone is enabled.
CODEGENOPT(EmitCallSiteInfo, 1, 0) ///< Emit call site info only in the case of
///< '-g' + 'O>0' level.
+CODEGENOPT(EnableDIPreservationVerify, 1, 0) ///< Enable di preservation verify
+ ///< each (it means check
+ ///< the original debug info
+ ///< metadata preservation).
CODEGENOPT(IndirectTlsSegRefs, 1, 0) ///< Set when -mno-tls-direct-seg-refs
///< is specified.
CODEGENOPT(DisableTailCalls , 1, 0) ///< Do not emit tail calls.
diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h
index b38df2da97de..778340b34272 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -190,6 +190,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
/// The ABI to use for passing floating point arguments.
std::string FloatABI;
+ /// The file to use for dumping bug report by `Debugify` for original
+ /// debug info.
+ std::string DIBugsReportFilePath;
+
/// The floating-point denormal mode to use.
llvm::DenormalMode FPDenormalMode = llvm::DenormalMode::getIEEE();
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 6f50774d8f1c..5e580cc4fbb7 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -342,6 +342,10 @@ def warn_drv_disabling_vptr_no_rtti_default : Warning<
def warn_drv_object_size_disabled_O0 : Warning<
"the object size sanitizer has no effect at -O0, but is explicitly enabled: %0">,
InGroup<InvalidCommandLineArgument>, DefaultWarnNoWerror;
+def warn_ignoring_verify_debuginfo_preserve_export : Warning<
+ "ignoring -fverify-debuginfo-preserve-export=%0 because "
+ "-fverify-debuginfo-preserve wasn't enabled">,
+ InGroup<UnusedCommandLineArgument>;
def err_invalid_branch_protection: Error <
"invalid branch protection option '%0' in '%1'">;
def err_invalid_sls_hardening : Error<
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index a48b922e884a..f4af1a4b10f1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4877,6 +4877,18 @@ def fexperimental_debug_variable_locations : Flag<["-"],
"fexperimental-debug-variable-locations">,
HelpText<"Use experimental new value-tracking variable locations">,
MarshallingInfoFlag<CodeGenOpts<"ValueTrackingVariableLocations">>;
+def fverify_debuginfo_preserve
+ : Flag<["-"], "fverify-debuginfo-preserve">,
+ HelpText<"Enable Debug Info Metadata preservation testing in "
+ "optimizations.">,
+ MarshallingInfoFlag<CodeGenOpts<"EnableDIPreservationVerify">>;
+def fverify_debuginfo_preserve_export
+ : Joined<["-"], "fverify-debuginfo-preserve-export=">,
+ MetaVarName<"<file>">,
+ HelpText<"Export debug info (by testing original Debug Info) failures "
+ "into specified (JSON) file (should be abs path as we use "
+ "append mode to insert new JSON objects).">,
+ MarshallingInfoString<CodeGenOpts<"DIBugsReportFilePath">>;
// The driver option takes the key as a parameter to the -msign-return-address=
// and -mbranch-protection= options, but CC1 has a separate option so we
// don't have to parse the parameter twice.
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 37f9067e0b2e..6de482ea74f5 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -81,6 +81,7 @@
#include "llvm/Transforms/Scalar/LowerMatrixIntrinsics.h"
#include "llvm/Transforms/Utils.h"
#include "llvm/Transforms/Utils/CanonicalizeAliases.h"
+#include "llvm/Transforms/Utils/Debugify.h"
#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
#include "llvm/Transforms/Utils/NameAnonGlobals.h"
#include "llvm/Transforms/Utils/SymbolRewriter.h"
@@ -945,7 +946,16 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
if (TM)
TheModule->setDataLayout(TM->createDataLayout());
- legacy::PassManager PerModulePasses;
+ DebugifyCustomPassManager PerModulePasses;
+ DebugInfoPerPassMap DIPreservationMap;
+ if (CodeGenOpts.EnableDIPreservationVerify) {
+ PerModulePasses.setDebugifyMode(DebugifyMode::OriginalDebugInfo);
+ PerModulePasses.setDIPreservationMap(DIPreservationMap);
+
+ if (!CodeGenOpts.DIBugsReportFilePath.empty())
+ PerModulePasses.setOrigDIVerifyBugsReportFilePath(
+ CodeGenOpts.DIBugsReportFilePath);
+ }
PerModulePasses.add(
createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 56aa4b41d58d..490672bf93ab 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1648,6 +1648,12 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
llvm::is_contained(DebugEntryValueArchs, T.getArch()))
Opts.EmitCallSiteInfo = true;
+ if (!Opts.EnableDIPreservationVerify && Opts.DIBugsReportFilePath.size()) {
+ Diags.Report(diag::warn_ignoring_verify_debuginfo_preserve_export)
+ << Opts.DIBugsReportFilePath;
+ Opts.DIBugsReportFilePath = "";
+ }
+
Opts.NewStructPathTBAA = !Args.hasArg(OPT_no_struct_path_tbaa) &&
Args.hasArg(OPT_new_struct_path_tbaa);
Opts.OptimizeSize = getOptimizationLevelSize(Args);
diff --git a/clang/test/Driver/verify-debug-info-preservation.c b/clang/test/Driver/verify-debug-info-preservation.c
new file mode 100644
index 000000000000..b81d12686f38
--- /dev/null
+++ b/clang/test/Driver/verify-debug-info-preservation.c
@@ -0,0 +1,19 @@
+// We support the CC1 options for testing whether each LLVM pass preserves
+// original debug info.
+
+// RUN: %clang -g -Xclang -fverify-debuginfo-preserve -### %s 2>&1 \
+// RUN: | FileCheck --check-prefix=VERIFYDIPRESERVE %s
+
+// VERIFYDIPRESERVE: "-fverify-debuginfo-preserve"
+
+// RUN: %clang -g -Xclang -fverify-debuginfo-preserve \
+// RUN: -Xclang -fverify-debuginfo-preserve-export=%t.json -### %s 2>&1 \
+// RUN: | FileCheck --check-prefix=VERIFYDIPRESERVE-JSON-EXPORT %s
+
+// VERIFYDIPRESERVE-JSON-EXPORT: "-fverify-debuginfo-preserve"
+// VERIFYDIPRESERVE-JSON-EXPORT: "-fverify-debuginfo-preserve-export={{.*}}"
+
+// RUN: %clang -g -Xclang -fverify-debuginfo-preserve-export=%t.json %s -S 2>&1 \
+// RUN: | FileCheck --check-prefix=WARN %s
+
+// WARN: warning: ignoring -fverify-debuginfo-preserve-export
diff --git a/llvm/docs/HowToUpdateDebugInfo.rst b/llvm/docs/HowToUpdateDebugInfo.rst
index b9bdc485b487..58bdc111a90c 100644
--- a/llvm/docs/HowToUpdateDebugInfo.rst
+++ b/llvm/docs/HowToUpdateDebugInfo.rst
@@ -376,6 +376,17 @@ as follows:
$ llvm-original-di-preservation.py sample.json sample.html
+Testing of original debug info preservation can be invoked from front-end level
+as follows:
+
+.. code-block:: bash
+
+ # Test each pass.
+ $ clang -Xclang -fverify-debuginfo-preserve -g -O2 sample.c
+
+ # Test each pass and export the issues report into the JSON file.
+ $ clang -Xclang -fverify-debuginfo-preserve -Xclang -fverify-debuginfo-preserve-export=sample.json -g -O2 sample.c
+
Mutation testing for MIR-level transformations
----------------------------------------------
More information about the cfe-commits
mailing list