llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp:2425:24: warning: Assert statement modifies 'ExpectedID'. [assignmentInAssert]
Source code is
assert(ExpectedID++ == ID && "combine rules are not ordered!");
If asserts are switched off, this code might not work.
Looks like this variable is only used within the assert: https://github.com/llvm/llvm-project/blob/main/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp#L2419-L2428
void GICombinerEmitter::emitTestSimplePredicate(raw_ostream &OS) {
if (!AllCombineRules.empty()) {
OS << "enum {\n";
std::string EnumeratorSeparator = " = GICXXPred_Invalid + 1,\n";
// To avoid emitting a switch, we expect that all those rules are in order.
// That way we can just get the RuleID from the enum by subtracting
// (GICXXPred_Invalid + 1).
unsigned ExpectedID = 0;
(void)ExpectedID;
for (const auto &ID : keys(AllCombineRules)) {
assert(ExpectedID++ == ID && "combine rules are not ordered!");
OS << " " << getIsEnabledPredicateEnumName(ID) << EnumeratorSeparator;
EnumeratorSeparator = ",\n";
}
OS << "};\n\n";
}
OS << "bool " << getClassName()
<< "::testSimplePredicate(unsigned Predicate) const {\n"
<< " return RuleConfig.isRuleEnabled(Predicate - "
"GICXXPred_Invalid - "
"1);\n"
<< "}\n";
}
So I don't think this is a bug.
@Pierre-vh
Can we just pull the increment out of the assert? That would also avoid the need for the void cast to silence unused warning
Can we just pull the increment out of the assert? That would also avoid the need for the void cast to silence unused warning
From what I can see the variable is used only within the assert, so that would add an unnecessary operation to the loop (unless you cover it with something like LLVM_DEBUG() I guess)
From what I can see the variable is used only within the assert, so that would add an unnecessary operation to the loop (unless you cover it with something like
LLVM_DEBUG()I guess)
Luckily we have compiler optimizations that can remove that for you