[Mlir-commits] [mlir] [mlir] fix overflow warning when generating embedded libdevice (PR #125801)

Zichen Lu llvmlistbot at llvm.org
Wed Feb 5 01:11:43 PST 2025


https://github.com/MikaOvO updated https://github.com/llvm/llvm-project/pull/125801

>From 4ce95feadb942bfb9c3975f7a90f36e051b576e7 Mon Sep 17 00:00:00 2001
From: Zichen Lu <mikaovo2000 at gmail.com>
Date: Wed, 5 Feb 2025 12:49:23 +0800
Subject: [PATCH] [mlir] fix overflow warning when generating embedded
 libdevice

---
 mlir/lib/Target/LLVM/CMakeLists.txt  | 2 +-
 mlir/lib/Target/LLVM/NVVM/Target.cpp | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/mlir/lib/Target/LLVM/CMakeLists.txt b/mlir/lib/Target/LLVM/CMakeLists.txt
index 4be147d02d579a..83fbf7a5fe5f32 100644
--- a/mlir/lib/Target/LLVM/CMakeLists.txt
+++ b/mlir/lib/Target/LLVM/CMakeLists.txt
@@ -125,7 +125,7 @@ function(embed_binary_to_src file output_file symbol)
     # Convert hex data for C compatibility
     string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," filedata ${filedata})
     # Write data to output file
-    file(WRITE ${output_file} "const char ${symbol}[] = {${filedata}};\nconst int ${symbol}_size = sizeof(${symbol});\n")
+    file(WRITE ${output_file} "const unsigned char ${symbol}[] = {${filedata}};\nconst int ${symbol}_size = sizeof(${symbol});\n")
 endfunction()
 
 set(MLIR_NVVM_EMBED_LIBDEVICE 0 CACHE BOOL "Embed CUDA libdevice.bc in the binary at build time instead of looking it up at runtime")
diff --git a/mlir/lib/Target/LLVM/NVVM/Target.cpp b/mlir/lib/Target/LLVM/NVVM/Target.cpp
index 86ff848d6c6c2d..7095f37d0c1b1a 100644
--- a/mlir/lib/Target/LLVM/NVVM/Target.cpp
+++ b/mlir/lib/Target/LLVM/NVVM/Target.cpp
@@ -47,7 +47,7 @@ using namespace mlir::NVVM;
 #define __DEFAULT_CUDATOOLKIT_PATH__ ""
 #endif
 
-extern "C" const char _mlir_embedded_libdevice[];
+extern "C" const unsigned char _mlir_embedded_libdevice[];
 extern "C" const unsigned _mlir_embedded_libdevice_size;
 
 namespace {
@@ -159,8 +159,9 @@ LogicalResult SerializeGPUModuleBase::appendStandardLibs() {
 
   // Allocate a resource using one of the UnManagedResourceBlob method to wrap
   // the embedded data.
-  auto unmanagedBlob = UnmanagedAsmResourceBlob::allocateInferAlign(
-      ArrayRef<char>{_mlir_embedded_libdevice, _mlir_embedded_libdevice_size});
+  auto unmanagedBlob =
+      UnmanagedAsmResourceBlob::allocateInferAlign(ArrayRef<char>{
+          (const char *)_mlir_embedded_libdevice, _mlir_embedded_libdevice_size});
   librariesToLink.push_back(DenseResourceElementsAttr::get(
       type, resourceManager.insert("_mlir_embedded_libdevice",
                                    std::move(unmanagedBlob))));



More information about the Mlir-commits mailing list