Skip to content

Commit ffa6cac

Browse files
committed
IR: Remove null UseList checks in hasNUses methods
There do not appear to be any cases where this is used. This does introduce an odd asyemmtry where use_empty is not equivalent to hasNUses(0).
1 parent c528f60 commit ffa6cac

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

llvm/lib/IR/Value.cpp

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

150150
bool Value::hasNUses(unsigned N) const {
151-
if (!UseList)
152-
return N == 0;
153-
154-
// TODO: Disallow for ConstantData and remove !UseList check?
155151
return hasNItems(use_begin(), use_end(), N);
156152
}
157153

158154
bool Value::hasNUsesOrMore(unsigned N) const {
159-
// TODO: Disallow for ConstantData and remove !UseList check?
160-
if (!UseList)
161-
return N == 0;
162-
163155
return hasNItemsOrMore(use_begin(), use_end(), N);
164156
}
165157

llvm/unittests/IR/ConstantsTest.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,8 @@ TEST(ConstantsTest, UseCounts) {
2929

3030
EXPECT_TRUE(Zero->use_empty());
3131
EXPECT_EQ(Zero->getNumUses(), 0u);
32-
EXPECT_TRUE(Zero->hasNUses(0));
3332
EXPECT_FALSE(Zero->hasOneUse());
3433
EXPECT_FALSE(Zero->hasOneUser());
35-
EXPECT_FALSE(Zero->hasNUses(1));
36-
EXPECT_FALSE(Zero->hasNUsesOrMore(1));
37-
EXPECT_FALSE(Zero->hasNUses(2));
38-
EXPECT_FALSE(Zero->hasNUsesOrMore(2));
3934

4035
std::unique_ptr<Module> M(new Module("MyModule", Context));
4136

@@ -50,15 +45,36 @@ TEST(ConstantsTest, UseCounts) {
5045
// Still looks like use_empty with uses.
5146
EXPECT_TRUE(Zero->use_empty());
5247
EXPECT_EQ(Zero->getNumUses(), 0u);
53-
EXPECT_TRUE(Zero->hasNUses(0));
5448
EXPECT_FALSE(Zero->hasOneUse());
5549
EXPECT_FALSE(Zero->hasOneUser());
56-
EXPECT_FALSE(Zero->hasNUses(1));
57-
EXPECT_FALSE(Zero->hasNUsesOrMore(1));
58-
EXPECT_FALSE(Zero->hasNUses(2));
59-
EXPECT_FALSE(Zero->hasNUsesOrMore(2));
6050
}
6151

52+
#ifdef GTEST_HAS_DEATH_TEST
53+
#ifndef NDEBUG
54+
55+
TEST(ConstantsTest, hasNUsesInvalid) {
56+
LLVMContext Context;
57+
Type *Int32Ty = Type::getInt32Ty(Context);
58+
Constant *Zero = ConstantInt::get(Int32Ty, 0);
59+
std::unique_ptr<Module> M(new Module("MyModule", Context));
60+
61+
// Introduce some uses
62+
new GlobalVariable(*M, Int32Ty, /*isConstant=*/false,
63+
GlobalValue::ExternalLinkage, /*Initializer=*/Zero,
64+
"gv_user0");
65+
new GlobalVariable(*M, Int32Ty, /*isConstant=*/false,
66+
GlobalValue::ExternalLinkage, /*Initializer=*/Zero,
67+
"gv_user1");
68+
69+
for (int I = 0; I != 3; ++I) {
70+
EXPECT_DEATH(Zero->hasNUses(I), "hasUseList()");
71+
EXPECT_DEATH(Zero->hasNUsesOrMore(I), "hasUseList()");
72+
}
73+
}
74+
75+
#endif
76+
#endif
77+
6278
TEST(ConstantsTest, Integer_i1) {
6379
LLVMContext Context;
6480
IntegerType *Int1 = IntegerType::get(Context, 1);

0 commit comments

Comments
 (0)