<div dir="ltr">Is silently truncating the right thing here, or should this be an error? (otherwise I'm assuming you could have two different names that, when truncated, become one name & produce possibly unintended semantics?)</div><br><div class="gmail_quote"><div dir="ltr">On Fri, Dec 22, 2017 at 6:53 AM serge via Phabricator via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">serge-sans-paille updated this revision to Diff 128024.<br>
<br>
Repository:<br>
  rL LLVM<br>
<br>
<a href="https://reviews.llvm.org/D41296" rel="noreferrer" target="_blank">https://reviews.llvm.org/D41296</a><br>
<br>
Files:<br>
  lib/IR/Value.cpp<br>
  test/Bitcode/value-with-long-name.ll<br>
<br>
<br>
Index: lib/IR/Value.cpp<br>
===================================================================<br>
--- lib/IR/Value.cpp<br>
+++ lib/IR/Value.cpp<br>
@@ -39,6 +39,10 @@<br>
<br>
 using namespace llvm;<br>
<br>
+static cl::opt<unsigned> NonGlobalValueMaxNameSize(<br>
+    "non-global-value-max-name-size", cl::Hidden, cl::init(1024),<br>
+    cl::desc("Maximum size for the name of non-global values."));<br>
+<br>
 //===----------------------------------------------------------------------===//<br>
 //                                Value Class<br>
 //===----------------------------------------------------------------------===//<br>
@@ -244,6 +248,11 @@<br>
   if (getName() == NameRef)<br>
     return;<br>
<br>
+  // Cap the size of non-GlobalValue names.<br>
+  if (NameRef.size() > NonGlobalValueMaxNameSize && !isa<GlobalValue>(this))<br>
+    NameRef =<br>
+        NameRef.substr(0, std::max(1u, (unsigned)NonGlobalValueMaxNameSize));<br>
+<br>
   assert(!getType()->isVoidTy() && "Cannot assign a name to void values!");<br>
<br>
   // Get the symbol table to update for this object.<br>
Index: test/Bitcode/value-with-long-name.ll<br>
===================================================================<br>
--- test/Bitcode/value-with-long-name.ll<br>
+++ test/Bitcode/value-with-long-name.ll<br>
@@ -0,0 +1,16 @@<br>
+; Check we correctly cap the size of newly generated non-global values name<br>
+; Force the size to be small so that the check works on release and debug build<br>
+<br>
+; RUN: opt -S %s -O2 -o - -non-global-value-max-name-size=0 | FileCheck %s<br>
+; RUN: opt -S %s -O2 -o - -non-global-value-max-name-size=1 | FileCheck %s<br>
+<br>
+; CHECK-NOT: %{{[a-z][a-z]+}}<br>
+<br>
+define i32 @f(i32 %a, i32 %b) {<br>
+  %c = add i32 %a, %b<br>
+  %d = add i32 %c, %a<br>
+  %e = add i32 %d, %b<br>
+  ret i32 %e<br>
+}<br>
+<br>
+<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>