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

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 27 13:58:42 PST 2017


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?)

On Fri, Dec 22, 2017 at 6:53 AM serge via Phabricator via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> serge-sans-paille updated this revision to Diff 128024.
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D41296
>
> Files:
>   lib/IR/Value.cpp
>   test/Bitcode/value-with-long-name.ll
>
>
> Index: lib/IR/Value.cpp
> ===================================================================
> --- lib/IR/Value.cpp
> +++ 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.
> Index: test/Bitcode/value-with-long-name.ll
> ===================================================================
> --- test/Bitcode/value-with-long-name.ll
> +++ test/Bitcode/value-with-long-name.ll
> @@ -0,0 +1,16 @@
> +; 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 %s
> +; RUN: opt -S %s -O2 -o - -non-global-value-max-name-size=1 | FileCheck %s
> +
> +; CHECK-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
> +}
> +
> +
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171227/998a6a50/attachment.html>


More information about the llvm-commits mailing list