[PATCH] D41296: Limit size of non-GlobalValue name

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 5 11:42:37 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL321886: Limit size of non-GlobalValue name (authored by serge_sans_paille, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41296?vs=128750&id=128778#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41296

Files:
  llvm/trunk/lib/IR/Value.cpp
  llvm/trunk/test/Bitcode/value-with-long-name.ll


Index: llvm/trunk/test/Bitcode/value-with-long-name.ll
===================================================================
--- llvm/trunk/test/Bitcode/value-with-long-name.ll
+++ llvm/trunk/test/Bitcode/value-with-long-name.ll
@@ -0,0 +1,18 @@
+; Check the size of generated variable when no option is set
+; RUN: opt -S %s -O2 -o - | FileCheck -check-prefix=CHECK-LONG %s
+; CHECK-LONG: %{{[a-z]{4}[a-z]+}}
+
+; Then check we correctly cap the size of newly generated non-global values name
+; Force the size to be small so that the check works on release and debug build
+; RUN: opt -S %s -O2 -o - -non-global-value-max-name-size=0 | FileCheck -check-prefix=CHECK-SHORT %s
+; RUN: opt -S %s -O2 -o - -non-global-value-max-name-size=1 | FileCheck -check-prefix=CHECK-SHORT %s
+; CHECK-SHORT-NOT: %{{[a-z][a-z]+}}
+
+define i32 @f(i32 %a, i32 %b) {
+  %c = add i32 %a, %b
+  %d = add i32 %c, %a
+  %e = add i32 %d, %b
+  ret i32 %e
+}
+
+
Index: llvm/trunk/lib/IR/Value.cpp
===================================================================
--- llvm/trunk/lib/IR/Value.cpp
+++ llvm/trunk/lib/IR/Value.cpp
@@ -39,6 +39,10 @@
 
 using namespace llvm;
 
+static cl::opt<unsigned> NonGlobalValueMaxNameSize(
+    "non-global-value-max-name-size", cl::Hidden, cl::init(1024),
+    cl::desc("Maximum size for the name of non-global values."));
+
 //===----------------------------------------------------------------------===//
 //                                Value Class
 //===----------------------------------------------------------------------===//
@@ -244,6 +248,11 @@
   if (getName() == NameRef)
     return;
 
+  // Cap the size of non-GlobalValue names.
+  if (NameRef.size() > NonGlobalValueMaxNameSize && !isa<GlobalValue>(this))
+    NameRef =
+        NameRef.substr(0, std::max(1u, (unsigned)NonGlobalValueMaxNameSize));
+
   assert(!getType()->isVoidTy() && "Cannot assign a name to void values!");
 
   // Get the symbol table to update for this object.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41296.128778.patch
Type: text/x-patch
Size: 1969 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180105/7f0272d7/attachment.bin>


More information about the llvm-commits mailing list