Skip to content

Commit a61ca99

Browse files
authored
[mlir] fix overflow warning when generating embedded libdevice (llvm#125801)
When building mlir with `-DMLIR_NVVM_EMBED_LIBDEVICE=ON`, there will be a warning ``` build/tools/mlir/lib/Target/LLVM/libdevice_embedded.c:1: warning: overflow in conversion from ‘int’ to ‘char’ changes value from ‘143’ to ‘-113’ [-Woverflow] ``` which is followed by a large number of characters in stdout. Fix this to avoid stdout outputting a large number of characters (3e5).
1 parent ee25a85 commit a61ca99

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

mlir/lib/Target/LLVM/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function(embed_binary_to_src file output_file symbol)
125125
# Convert hex data for C compatibility
126126
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," filedata ${filedata})
127127
# Write data to output file
128-
file(WRITE ${output_file} "const char ${symbol}[] = {${filedata}};\nconst int ${symbol}_size = sizeof(${symbol});\n")
128+
file(WRITE ${output_file} "const unsigned char ${symbol}[] = {${filedata}};\nconst int ${symbol}_size = sizeof(${symbol});\n")
129129
endfunction()
130130

131131
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")

mlir/lib/Target/LLVM/NVVM/Target.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ using namespace mlir::NVVM;
4747
#define __DEFAULT_CUDATOOLKIT_PATH__ ""
4848
#endif
4949

50-
extern "C" const char _mlir_embedded_libdevice[];
50+
extern "C" const unsigned char _mlir_embedded_libdevice[];
5151
extern "C" const unsigned _mlir_embedded_libdevice_size;
5252

5353
namespace {
@@ -160,7 +160,8 @@ LogicalResult SerializeGPUModuleBase::appendStandardLibs() {
160160
// Allocate a resource using one of the UnManagedResourceBlob method to wrap
161161
// the embedded data.
162162
auto unmanagedBlob = UnmanagedAsmResourceBlob::allocateInferAlign(
163-
ArrayRef<char>{_mlir_embedded_libdevice, _mlir_embedded_libdevice_size});
163+
ArrayRef<char>{(const char *)_mlir_embedded_libdevice,
164+
_mlir_embedded_libdevice_size});
164165
librariesToLink.push_back(DenseResourceElementsAttr::get(
165166
type, resourceManager.insert("_mlir_embedded_libdevice",
166167
std::move(unmanagedBlob))));

0 commit comments

Comments
 (0)