Skip to content

Commit 6f0de17

Browse files
committed
make hasNUses(0) equivalent to use_empty for constants
1 parent ee561ee commit 6f0de17

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

llvm/lib/IR/Value.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,19 @@ void Value::destroyValueName() {
148148
}
149149

150150
bool Value::hasNUses(unsigned N) const {
151+
if (!UseList)
152+
return N == 0;
153+
151154
// TODO: Disallow for ConstantData and remove !UseList check?
152-
return UseList && hasNItems(use_begin(), use_end(), N);
155+
return hasNItems(use_begin(), use_end(), N);
153156
}
154157

155158
bool Value::hasNUsesOrMore(unsigned N) const {
156159
// TODO: Disallow for ConstantData and remove !UseList check?
157-
return UseList && hasNItemsOrMore(use_begin(), use_end(), N);
160+
if (!UseList)
161+
return N == 0;
162+
163+
return hasNItemsOrMore(use_begin(), use_end(), N);
158164
}
159165

160166
bool Value::hasOneUser() const {

llvm/unittests/IR/ConstantsTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ TEST(ConstantsTest, UseCounts) {
2929

3030
EXPECT_TRUE(Zero->use_empty());
3131
EXPECT_EQ(Zero->getNumUses(), 0u);
32+
EXPECT_TRUE(Zero->hasNUses(0));
3233
EXPECT_FALSE(Zero->hasOneUse());
3334
EXPECT_FALSE(Zero->hasOneUser());
3435
EXPECT_FALSE(Zero->hasNUses(1));
@@ -49,6 +50,7 @@ TEST(ConstantsTest, UseCounts) {
4950
// Still looks like use_empty with uses.
5051
EXPECT_TRUE(Zero->use_empty());
5152
EXPECT_EQ(Zero->getNumUses(), 0u);
53+
EXPECT_TRUE(Zero->hasNUses(0));
5254
EXPECT_FALSE(Zero->hasOneUse());
5355
EXPECT_FALSE(Zero->hasOneUser());
5456
EXPECT_FALSE(Zero->hasNUses(1));

0 commit comments

Comments
 (0)