[llvm] [SPIR-V] Fix signed-shift UB when packing UTF-8 string operands (PR #207769)
Juan Manuel Martinez CaamaƱo via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 7 01:00:22 PDT 2026
================
@@ -161,7 +161,7 @@ static uint32_t convertCharsToWord(const StringRef &Str, unsigned i) {
if (StrIndex < Str.size()) { // If it's within the string, get a real char.
CharToAdd = Str[StrIndex];
}
- Word |= (CharToAdd << (WordIndex * 8));
+ Word |= (static_cast<uint32_t>(CharToAdd) << (WordIndex * 8));
}
return Word;
}
----------------
jmmartinez wrote:
Nice catch!
But isn't this just a complicated `memcpy`?
```cpp
static uint32_t convertCharsToWord(StringRef Str, unsigned i) {
uint32_t Word = 0;
unsigned Count = std::min(sizeof(Word), Str.size() - i);
std::memcpy(&Word, &Str[i], Count);
return Word;
}
```
https://github.com/llvm/llvm-project/pull/207769
More information about the llvm-commits
mailing list