[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 02:16:19 PST 2020


serge-sans-paille updated this revision to Diff 245606.
serge-sans-paille added a comment.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

Other approach to the problem: modify `Value::SetNameImpl`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74871/new/

https://reviews.llvm.org/D74871

Files:
  clang/test/CodeGen/discard_value_names.ll
  llvm/lib/IR/Value.cpp


Index: llvm/lib/IR/Value.cpp
===================================================================
--- llvm/lib/IR/Value.cpp
+++ llvm/lib/IR/Value.cpp
@@ -228,7 +228,10 @@
 void Value::setNameImpl(const Twine &NewName) {
   // Fast-path: LLVMContext can be set to strip out non-GlobalValue names
   if (getContext().shouldDiscardValueNames() && !isa<GlobalValue>(this))
-    return;
+    // Unless the name of the variable was set previously and we're trying to
+    // eras it.
+    if (!(hasName() && NewName.isTriviallyEmpty()))
+      return;
 
   // Fast path for common IRBuilder case of setName("") when there is no name.
   if (NewName.isTriviallyEmpty() && !hasName())
Index: clang/test/CodeGen/discard_value_names.ll
===================================================================
--- /dev/null
+++ clang/test/CodeGen/discard_value_names.ll
@@ -0,0 +1,13 @@
+; Check compatibility between clang parsing IR and discard-value-names
+; RUN: %clang -fdiscard-value-names -S %s -o/dev/null 2>&1
+; RUN: %clang_cc1 -discard-value-names -S %s -o/dev/null
+
+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 }
+


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74871.245606.patch
Type: text/x-patch
Size: 1303 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200220/1c30fd4b/attachment.bin>


More information about the cfe-commits mailing list