Skip to content

Commit fb627e3

Browse files
authored
[LLVM][IR] Replace unsigned >= ConstantDataFirstVal with static_assert (#140827)
`ConstantDataFirstVal` is 0, so `getValueID() >= ConstantDataFirstVal` leads to a compiler warning that the expression is always true. Replace such comparisons with a static_assert() to verify that `ConstantDataFirstVal` is 0, similar to the existing code in Value.h
1 parent b5e3d8e commit fb627e3

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

llvm/include/llvm/IR/Constants.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ class ConstantData : public Constant {
7474

7575
/// Methods to support type inquiry through isa, cast, and dyn_cast.
7676
static bool classof(const Value *V) {
77-
return V->getValueID() >= ConstantDataFirstVal &&
78-
V->getValueID() <= ConstantDataLastVal;
77+
static_assert(Value::ConstantDataFirstVal == 0,
78+
"V->getValueID() >= Value::ConstantDataFirstVal");
79+
return V->getValueID() <= ConstantDataLastVal;
7980
}
8081
};
8182

llvm/include/llvm/IR/Value.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -987,15 +987,17 @@ template <class Compare> void Value::sortUseList(Compare Cmp) {
987987
//
988988
template <> struct isa_impl<Constant, Value> {
989989
static inline bool doit(const Value &Val) {
990-
static_assert(Value::ConstantFirstVal == 0, "Val.getValueID() >= Value::ConstantFirstVal");
990+
static_assert(Value::ConstantFirstVal == 0,
991+
"Val.getValueID() >= Value::ConstantFirstVal");
991992
return Val.getValueID() <= Value::ConstantLastVal;
992993
}
993994
};
994995

995996
template <> struct isa_impl<ConstantData, Value> {
996997
static inline bool doit(const Value &Val) {
997-
return Val.getValueID() >= Value::ConstantDataFirstVal &&
998-
Val.getValueID() <= Value::ConstantDataLastVal;
998+
static_assert(Value::ConstantDataFirstVal == 0,
999+
"Val.getValueID() >= Value::ConstantDataFirstVal");
1000+
return Val.getValueID() <= Value::ConstantDataLastVal;
9991001
}
10001002
};
10011003

0 commit comments

Comments
 (0)