Skip to content

Commit 6927945

Browse files
authored
Fix mangling of booleans and zeros (#614)
1 parent 43cc242 commit 6927945

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/mangling.jl

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,26 @@ function mangle_param(t, substitutions=String[])
8383
end
8484

8585
str
86-
elseif isa(t, Integer)
87-
t > 0 ? "Li$(t)E" : "Lin$(abs(t))E"
86+
elseif isa(t, Union{Bool, Cchar, Cuchar, Cshort, Cushort, Cint, Cuint, Clong, Culong, Clonglong, Culonglong, Int128, UInt128})
87+
ts = t isa Bool ? 'b' : # bool
88+
t isa Cchar ? 'a' : # signed char
89+
t isa Cuchar ? 'h' : # unsigned char
90+
t isa Cshort ? 's' : # short
91+
t isa Cushort ? 't' : # unsigned short
92+
t isa Cint ? 'i' : # int
93+
t isa Cuint ? 'j' : # unsigned int
94+
t isa Clong ? 'l' : # long
95+
t isa Culong ? 'm' : # unsigned long
96+
t isa Clonglong ? 'x' : # long long, __int64
97+
t isa Culonglong ? 'y' : # unsigned long long, __int64
98+
t isa Int128 ? 'n' : # __int128
99+
t isa UInt128 ? 'o' : # unsigned __int128
100+
error("Invalid type")
101+
tn = string(abs(t), base=10)
102+
if t < 0
103+
tn = 'n'*tn
104+
end
105+
"L$(ts)$(tn)E"
88106
else
89107
tn = safe_name(t) # TODO: actually does support digits...
90108
if startswith(tn, r"\d")

test/util_tests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,14 @@
99
@test groups[3] == [:(d=4)]
1010
end
1111

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

0 commit comments

Comments
 (0)