Skip to content

Commit 974b840

Browse files
authored
Fix ffi abs_cstring (#2718)
1 parent a0e9679 commit 974b840

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/absint.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,6 @@ end
862862
end
863863

864864
function abs_cstring(@nospecialize(arg::LLVM.Value))::Tuple{Bool, String}
865-
if isa(arg, ConstantExpr)
866865
ce = arg
867866
while isa(ce, ConstantExpr)
868867
if opcode(ce) == LLVM.API.LLVMAddrSpaceCast || opcode(ce) == LLVM.API.LLVMBitCast || opcode(ce) == LLVM.API.LLVMIntToPtr
@@ -877,13 +876,19 @@ function abs_cstring(@nospecialize(arg::LLVM.Value))::Tuple{Bool, String}
877876
break
878877
end
879878
end
880-
if isa(ce, LLVM.GlobalVariable)
881-
ce = LLVM.initializer(ce)
882-
if (isa(ce, LLVM.ConstantArray) || isa(ce, LLVM.ConstantDataArray)) && eltype(value_type(ce)) == LLVM.IntType(8)
883-
return (true, String(map(Base.Fix1(convert, UInt8), collect(ce)[1:(end - 1)])))
879+
880+
larg = nothing
881+
if LLVM.API.LLVMGetValueKind(ce) == LLVM.API.LLVMGlobalAliasValueKind
882+
larg = LLVM.Value(ccall((:LLVMAliasGetAliasee, LLVM.API.libllvm), LLVM.API.LLVMValueRef, (LLVM.API.LLVMValueRef,), ce))
883+
elseif isa(ce, LLVM.GlobalVariable)
884+
larg = LLVM.initializer(ce)
885+
end
886+
887+
if larg !== nothing
888+
if (isa(larg, LLVM.ConstantArray) || isa(larg, LLVM.ConstantDataArray)) && eltype(value_type(larg)) == LLVM.IntType(8)
889+
return (true, String(map(Base.Fix1(convert, UInt8), collect(larg)[1:(end - 1)])))
884890
end
885891

886892
end
887-
end
888893
return (false, "")
889894
end

0 commit comments

Comments
 (0)