[Mlir-commits] [mlir] [mlir][spirv] Truncate Literal String size at max number words (PR #142916)
Jakub Kuderski
llvmlistbot at llvm.org
Thu Jun 5 07:15:19 PDT 2025
================
@@ -68,7 +71,18 @@ void spirv::encodeStringLiteralInto(SmallVectorImpl<uint32_t> &binary,
StringRef literal) {
// We need to encode the literal and the null termination.
auto encodingSize = literal.size() / 4 + 1;
+ auto sizeOfDataToCopy = literal.size();
+ if (encodingSize >= kMaxLiteralWordCount) {
+ // reserve one word for the null termination
+ encodingSize = kMaxLiteralWordCount - 1;
+ // do not override the last word (null termination) when copying
+ sizeOfDataToCopy = (encodingSize - 1) * 4;
+ LLVM_DEBUG(llvm::dbgs() << "Truncating string literal to max size ("
+ << std::to_string(kMaxLiteralWordCount - 1)
----------------
kuhar wrote:
no need to call to_string
https://github.com/llvm/llvm-project/pull/142916
More information about the Mlir-commits
mailing list