[llvm] c30d8f7 - [IR] Set name when inserting 'llvm::Value*'
Brian Gesiak via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 18 05:22:14 PST 2020
Author: Brian Gesiak
Date: 2020-02-18T08:22:03-05:00
New Revision: c30d8f7c910d9ddcaf8cab1ebea4b202bc88fcf9
URL: https://github.com/llvm/llvm-project/commit/c30d8f7c910d9ddcaf8cab1ebea4b202bc88fcf9
DIFF: https://github.com/llvm/llvm-project/commit/c30d8f7c910d9ddcaf8cab1ebea4b202bc88fcf9.diff
LOG: [IR] Set name when inserting 'llvm::Value*'
Summary:
I noticed a small regression in a toy project of mine after applying
D73835, in which instruction names weren't being set properly. In the
example test case included with this patch,
`llvm::IRBuilderBase::CreateAdd` returns an `llvm::Value *` that is then
passed as an argument to `llvm::IRBuilderBase::Insert`. The overloaded
function that is selected for that call then ignores the `Name`
parameter that is given. This patch addresses that issue.
Reviewers: nikic, Meinersbur, nhaehnle, fhahn, thakis, teemperor
Reviewed By: nikic, fhahn
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74754
Added:
Modified:
llvm/include/llvm/IR/IRBuilder.h
llvm/unittests/IR/IRBuilderTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 825a2426b742..24db7dcb2067 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -134,9 +134,9 @@ class IRBuilderBase {
return C;
}
- Value *Insert(Value *V, const Twine& = "") const {
+ Value *Insert(Value *V, const Twine &Name = "") const {
if (Instruction *I = dyn_cast<Instruction>(V))
- return Insert(I);
+ return Insert(I, Name);
assert(isa<Constant>(V));
return V;
}
diff --git a/llvm/unittests/IR/IRBuilderTest.cpp b/llvm/unittests/IR/IRBuilderTest.cpp
index 4ceff2d69b88..ab9cec33bac7 100644
--- a/llvm/unittests/IR/IRBuilderTest.cpp
+++ b/llvm/unittests/IR/IRBuilderTest.cpp
@@ -929,4 +929,11 @@ TEST_F(IRBuilderTest, DIBuilderMacro) {
EXPECT_EQ(MN2, MF2->getRawElements());
EXPECT_TRUE(verifyModule(*M));
}
+
+TEST_F(IRBuilderTest, NoFolderNames) {
+ IRBuilder<NoFolder> Builder(BB);
+ auto *Add =
+ Builder.CreateAdd(Builder.getInt32(1), Builder.getInt32(2), "add");
+ EXPECT_EQ(Add->getName(), "add");
+}
}
More information about the llvm-commits
mailing list