[PATCH] D74871: Fix interaction between -fdiscard-value-names and LLVM Bitcode
serge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 20 00:30:26 PST 2020
serge-sans-paille updated this revision to Diff 245594.
serge-sans-paille added a comment.
Finally, the test case :-)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D74871/new/
https://reviews.llvm.org/D74871
Files:
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/discard_value_names.ll
Index: clang/test/CodeGen/discard_value_names.ll
===================================================================
--- /dev/null
+++ clang/test/CodeGen/discard_value_names.ll
@@ -0,0 +1,15 @@
+; Check compatibility between clang parsing IR and discard-value-names
+; RUN: %clang -fdiscard-value-names -S %s -o/dev/null 2>&1 | FileCheck %s
+; RUN: %clang_cc1 -discard-value-names -S %s -o/dev/null
+
+; CHECK: ignoring -fdiscard-value-names for LLVM Bitcode
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64--linux-gnu"
+
+define linkonce_odr float @sin_f32(float %x) #0 {
+ ret float 0.
+}
+
+attributes #0 = { alwaysinline }
+
Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3603,6 +3603,11 @@
LangOpts.PIE = Args.hasArg(OPT_pic_is_pie);
parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
Diags, LangOpts.Sanitize);
+ // Cannot discard value names when processing llvm-ir, because IR loading
+ // is conservative wrt. names.
+ if (Res.getCodeGenOpts().DiscardValueNames) {
+ Res.getCodeGenOpts().DiscardValueNames = false;
+ }
} else {
// Other LangOpts are only initialized when the input is not AST or LLVM IR.
// FIXME: Should we really be calling this for an Language::Asm input?
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4332,8 +4332,15 @@
// Discard value names in assert builds unless otherwise specified.
if (Args.hasFlag(options::OPT_fdiscard_value_names,
- options::OPT_fno_discard_value_names, !IsAssertBuild))
+ options::OPT_fno_discard_value_names, !IsAssertBuild)) {
+ if (std::any_of(Inputs.begin(), Inputs.end(),
+ [](const clang::driver::InputInfo &II) {
+ return types::isLLVMIR(II.getType());
+ })) {
+ D.Diag(diag::warn_ignoring_fdiscard_for_bitcode);
+ }
CmdArgs.push_back("-discard-value-names");
+ }
// Set the main file name, so that debug info works even with
// -save-temps.
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -271,6 +271,9 @@
InGroup<UnsupportedTargetOpt>;
def warn_c_kext : Warning<
"ignoring -fapple-kext which is valid for C++ and Objective-C++ only">;
+def warn_ignoring_fdiscard_for_bitcode : Warning<
+ "ignoring -fdiscard-value-names for LLVM Bitcode">,
+ InGroup<UnusedCommandLineArgument>;
def warn_drv_input_file_unused : Warning<
"%0: '%1' input unused%select{ when '%3' is present|}2">,
InGroup<UnusedCommandLineArgument>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74871.245594.patch
Type: text/x-patch
Size: 3098 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200220/ee1a91c8/attachment.bin>
More information about the cfe-commits
mailing list