Skip to content

Commit 044e0f0

Browse files
authored
Revert "IR: Remove null UseList checks in hasNUses methods (#165929)" (#166500)
This reverts commit 93e860e. hasOneUse still has the null check, and it seems bad to be logically inconsistent across multiple of these predicate functions.
1 parent 849038c commit 044e0f0

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

llvm/lib/IR/Value.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,18 @@ 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?
151155
return hasNItems(use_begin(), use_end(), N);
152156
}
153157

154158
bool Value::hasNUsesOrMore(unsigned N) const {
159+
// TODO: Disallow for ConstantData and remove !UseList check?
160+
if (!UseList)
161+
return N == 0;
162+
155163
return hasNItemsOrMore(use_begin(), use_end(), N);
156164
}
157165

llvm/unittests/IR/ConstantsTest.cpp

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@ 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());
35+
EXPECT_FALSE(Zero->hasNUses(1));
36+
EXPECT_FALSE(Zero->hasNUsesOrMore(1));
37+
EXPECT_FALSE(Zero->hasNUses(2));
38+
EXPECT_FALSE(Zero->hasNUsesOrMore(2));
3439

3540
std::unique_ptr<Module> M(new Module("MyModule", Context));
3641

@@ -45,36 +50,15 @@ TEST(ConstantsTest, UseCounts) {
4550
// Still looks like use_empty with uses.
4651
EXPECT_TRUE(Zero->use_empty());
4752
EXPECT_EQ(Zero->getNumUses(), 0u);
53+
EXPECT_TRUE(Zero->hasNUses(0));
4854
EXPECT_FALSE(Zero->hasOneUse());
4955
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));
5060
}
5161

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-
7862
TEST(ConstantsTest, Integer_i1) {
7963
LLVMContext Context;
8064
IntegerType *Int1 = IntegerType::get(Context, 1);

0 commit comments

Comments
 (0)