Skip to content

Commit

Permalink
Fix mangling of booleans and zeros (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne committed Aug 11, 2024
1 parent 43cc242 commit 6927945
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/mangling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,26 @@ function mangle_param(t, substitutions=String[])
end

str
elseif isa(t, Integer)
t > 0 ? "Li$(t)E" : "Lin$(abs(t))E"
elseif isa(t, Union{Bool, Cchar, Cuchar, Cshort, Cushort, Cint, Cuint, Clong, Culong, Clonglong, Culonglong, Int128, UInt128})
ts = t isa Bool ? 'b' : # bool
t isa Cchar ? 'a' : # signed char
t isa Cuchar ? 'h' : # unsigned char
t isa Cshort ? 's' : # short
t isa Cushort ? 't' : # unsigned short
t isa Cint ? 'i' : # int
t isa Cuint ? 'j' : # unsigned int
t isa Clong ? 'l' : # long
t isa Culong ? 'm' : # unsigned long
t isa Clonglong ? 'x' : # long long, __int64
t isa Culonglong ? 'y' : # unsigned long long, __int64
t isa Int128 ? 'n' : # __int128
t isa UInt128 ? 'o' : # unsigned __int128
error("Invalid type")
tn = string(abs(t), base=10)
if t < 0
tn = 'n'*tn
end
"L$(ts)$(tn)E"
else
tn = safe_name(t) # TODO: actually does support digits...
if startswith(tn, r"\d")
Expand Down
10 changes: 10 additions & 0 deletions test/util_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@
@test groups[3] == [:(d=4)]
end

@testset "mangle" begin
struct XX{T} end
# values checked with c++filt / cu++filt
@test GPUCompiler.mangle_sig(Tuple{typeof(sin), XX{false}}) == "_Z3sin2XXILb0EE" # "sin(XX<false>)"
@test GPUCompiler.mangle_sig(Tuple{typeof(sin), XX{true}}) == "_Z3sin2XXILb1EE" # "sin(XX<true>)"
@test GPUCompiler.mangle_sig(Tuple{typeof(sin), XX{Int64(10)}}) == "_Z3sin2XXILl10EE" # "sin(XX<10l>)"
@test GPUCompiler.mangle_sig(Tuple{typeof(sin), XX{Int64(0)}}) == "_Z3sin2XXILl0EE" # "sin(XX<0l>)"
@test GPUCompiler.mangle_sig(Tuple{typeof(sin), XX{Int64(-10)}}) == "_Z3sin2XXILln10EE" # "sin(XX<-10l>)"
end

end

0 comments on commit 6927945

Please sign in to comment.