Skip to content

Commit 72ed182

Browse files
committed
Fix lowering and function detection + add test
1 parent 699a949 commit 72ed182

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/llvm-pass-helpers.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ llvm::CallInst *JuliaPassContext::getPGCstack(llvm::Function &F) const
8888
return nullptr;
8989
}
9090

91-
llvm::CallInst *JuliaPassContext::getOrAddPGCstack(llvm::Function &F) const
91+
llvm::CallInst *JuliaPassContext::getOrAddPGCstack(llvm::Function &F)
9292
{
9393
if (pgcstack_getter || adoptthread_func)
9494
for (auto &I : F.getEntryBlock()) {
@@ -101,8 +101,11 @@ llvm::CallInst *JuliaPassContext::getOrAddPGCstack(llvm::Function &F) const
101101
}
102102
}
103103
IRBuilder<> builder(&F.getEntryBlock().front());
104+
if (pgcstack_getter)
105+
return builder.CreateCall(pgcstack_getter);
104106
auto FT = FunctionType::get(PointerType::get(F.getContext(), 0), false);
105107
auto F2 = Function::Create(FT, Function::ExternalLinkage, "julia.get_pgcstack", F.getParent());
108+
pgcstack_getter = F2;
106109
return builder.CreateCall( F2);
107110
}
108111

src/llvm-pass-helpers.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct JuliaPassContext {
9090
// Gets a call to the `julia.get_pgcstack' intrinsic in the entry
9191
// point of the given function, if there exists such a call.
9292
// Otherwise, creates a new call to the intrinsic
93-
llvm::CallInst *getOrAddPGCstack(llvm::Function &F) const;
93+
llvm::CallInst *getOrAddPGCstack(llvm::Function &F);
9494
// Gets the intrinsic or well-known function that conforms to
9595
// the given description if it exists in the module. If not,
9696
// `nullptr` is returned.

test/ccall.jl

+11
Original file line numberDiff line numberDiff line change
@@ -1966,3 +1966,14 @@ let llvm = sprint(code_llvm, world_counter, ())
19661966
# the world age should be -1 in generated functions (or other pure contexts)
19671967
@test (generated_world_counter() == reinterpret(UInt, -1))
19681968
end
1969+
1970+
function gc_safe_ccall()
1971+
@ccall gc_safe=true jl_get_cpu_features()::String
1972+
end
1973+
1974+
let llvm = sprint(code_llvm, gc_safe_ccall, ())
1975+
# check that the call works
1976+
@test gc_safe_ccall() isa String
1977+
# check for the gc_safe store
1978+
@test occursin("store atomic i8 2", llvm)
1979+
end

0 commit comments

Comments
 (0)