[Mlir-commits] [mlir] [mlir] avoid comparing char with `~0x00` literal. (PR #186441)
Chenguang Wang
llvmlistbot at llvm.org
Fri Mar 13 10:25:02 PDT 2026
================
@@ -180,7 +181,7 @@ readDenseTypedElementsAttr(DialectBytecodeReader &reader, ShapedType type,
size_t packedSize = llvm::divideCeil(numElements, 8);
// Unpack splats to single element 0x01 to match unpacked splat format.
- if (blob.size() == 1 && blob[0] == ~0x00) {
+ if (blob.size() == 1 && blob[0] == static_cast<char>(~0x00)) {
----------------
wecing wrote:
> should we reinterpret cast that to unsigned char in bytecode
@GleasonK Sorry -- I don't have the full context here, e.g. I actually don't understand why the splat is represented as `0x01`, so I couldn't really comment on that.
But at least I am certain comparing `char` with `~0x00` is incorrect, at least in C89; `==` triggers arithmetic conversion, which causes both the LHS (`char`) and RHS (`int`) to be converted to `int` first. Here the result of promoting the LHS depends on whether `char` is signed or not, so the comparison does not always do what you would expect.
Let me close this thread and submit this PR.
https://github.com/llvm/llvm-project/pull/186441
More information about the Mlir-commits
mailing list