Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions llvm/lib/IR/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,10 @@ void Value::destroyValueName() {
}

bool Value::hasNUses(unsigned N) const {
if (!UseList)
return N == 0;

// TODO: Disallow for ConstantData and remove !UseList check?
return hasNItems(use_begin(), use_end(), N);
}

bool Value::hasNUsesOrMore(unsigned N) const {
// TODO: Disallow for ConstantData and remove !UseList check?
if (!UseList)
return N == 0;

return hasNItemsOrMore(use_begin(), use_end(), N);
}

Expand Down
36 changes: 26 additions & 10 deletions llvm/unittests/IR/ConstantsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,8 @@ TEST(ConstantsTest, UseCounts) {

EXPECT_TRUE(Zero->use_empty());
EXPECT_EQ(Zero->getNumUses(), 0u);
EXPECT_TRUE(Zero->hasNUses(0));
EXPECT_FALSE(Zero->hasOneUse());
EXPECT_FALSE(Zero->hasOneUser());
EXPECT_FALSE(Zero->hasNUses(1));
EXPECT_FALSE(Zero->hasNUsesOrMore(1));
EXPECT_FALSE(Zero->hasNUses(2));
EXPECT_FALSE(Zero->hasNUsesOrMore(2));

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

Expand All @@ -50,15 +45,36 @@ TEST(ConstantsTest, UseCounts) {
// Still looks like use_empty with uses.
EXPECT_TRUE(Zero->use_empty());
EXPECT_EQ(Zero->getNumUses(), 0u);
EXPECT_TRUE(Zero->hasNUses(0));
EXPECT_FALSE(Zero->hasOneUse());
EXPECT_FALSE(Zero->hasOneUser());
EXPECT_FALSE(Zero->hasNUses(1));
EXPECT_FALSE(Zero->hasNUsesOrMore(1));
EXPECT_FALSE(Zero->hasNUses(2));
EXPECT_FALSE(Zero->hasNUsesOrMore(2));
}

#ifdef GTEST_HAS_DEATH_TEST
#ifndef NDEBUG

TEST(ConstantsTest, hasNUsesInvalid) {
LLVMContext Context;
Type *Int32Ty = Type::getInt32Ty(Context);
Constant *Zero = ConstantInt::get(Int32Ty, 0);
std::unique_ptr<Module> M(new Module("MyModule", Context));

// Introduce some uses
new GlobalVariable(*M, Int32Ty, /*isConstant=*/false,
GlobalValue::ExternalLinkage, /*Initializer=*/Zero,
"gv_user0");
new GlobalVariable(*M, Int32Ty, /*isConstant=*/false,
GlobalValue::ExternalLinkage, /*Initializer=*/Zero,
"gv_user1");

for (int I = 0; I != 3; ++I) {
EXPECT_DEATH(Zero->hasNUses(I), "hasUseList\\(\\)");
EXPECT_DEATH(Zero->hasNUsesOrMore(I), "hasUseList\\(\\)");
}
}

#endif
#endif

TEST(ConstantsTest, Integer_i1) {
LLVMContext Context;
IntegerType *Int1 = IntegerType::get(Context, 1);
Expand Down
Loading