[llvm] 8a337c8 - Revert "[SPIR-V] Simplify and fix sign-extension bug in convertCharsToWord (#207769)" (#209162)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 13 05:34:11 PDT 2026
Author: Nikita Popov
Date: 2026-07-13T14:34:07+02:00
New Revision: 8a337c88d64e8d3fe918ae9fdc740fadbba2368c
URL: https://github.com/llvm/llvm-project/commit/8a337c88d64e8d3fe918ae9fdc740fadbba2368c
DIFF: https://github.com/llvm/llvm-project/commit/8a337c88d64e8d3fe918ae9fdc740fadbba2368c.diff
LOG: Revert "[SPIR-V] Simplify and fix sign-extension bug in convertCharsToWord (#207769)" (#209162)
This reverts commit 503f0ca19cfcc9c0c88d6918939a2c0038ad0498.
This is obviously incorrect on big endian architectures.
Added:
Modified:
llvm/lib/Target/SPIRV/SPIRVUtils.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
index 748783490ef64..c6f53609a2b3d 100644
--- a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
@@ -27,7 +27,6 @@
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/IntrinsicsSPIRV.h"
#include "llvm/Support/MathExtras.h"
-#include <cstring>
#include <queue>
#include <vector>
@@ -147,9 +146,15 @@ StringRef getOriginalAsmConstraints(const CallBase &CB) {
// when making string comparisons in compiler passes.
// SPIR-V requires null-terminated UTF-8 strings padded to 32-bit alignment.
static uint32_t convertCharsToWord(StringRef Str, unsigned i) {
- uint32_t Word = 0u; // Padding/null bytes are zero-initialized.
- unsigned Count = std::min(static_cast<size_t>(4), Str.size() - i);
- std::memcpy(&Word, Str.data() + i, Count);
+ uint32_t Word = 0u; // Build up this 32-bit word from 4 8-bit chars.
+ for (unsigned WordIndex = 0; WordIndex < 4; ++WordIndex) {
+ unsigned StrIndex = i + WordIndex;
+ uint8_t CharToAdd = 0; // Initilize char as padding/null.
+ if (StrIndex < Str.size()) { // If it's within the string, get a real char.
+ CharToAdd = Str[StrIndex];
+ }
+ Word |= (CharToAdd << (WordIndex * 8));
+ }
return Word;
}
More information about the llvm-commits
mailing list