diff --git a/clang/test/CodeGen/discard_value_names.ll b/clang/test/CodeGen/discard_value_names.ll new file mode 100644 --- /dev/null +++ b/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 } + diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp --- a/llvm/lib/IR/Value.cpp +++ b/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(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())