Enzyme.jl icon indicating copy to clipboard operation
Enzyme.jl copied to clipboard

Test embedded bitcode path

Open ymardoukhi opened this issue 2 months ago • 4 comments

Test added for capturing Broken function exception and its corresponding stdout message regarding Called function is not the same type as the call! due to automatic inlining of ccall function.

See issue #2664

ymardoukhi avatar Oct 24 '25 22:10 ymardoukhi

Your PR requires formatting changes to meet the project's style guidelines. Please consider running Runic (git runic main) to apply these changes.

Click here to view the suggested changes.
diff --git a/test/embedded_bitcode.jl b/test/embedded_bitcode.jl
index c1dbf0ab..8895ca1f 100644
--- a/test/embedded_bitcode.jl
+++ b/test/embedded_bitcode.jl
@@ -43,7 +43,7 @@ tmp_so_file = joinpath(tmp_dir, "func.so")
 run(
     pipeline(
         `$(clang()) -x ir - -Xclang -no-opaque-pointers -O3 -fPIC -fembed-bitcode -shared -o $(tmp_so_file)`;
-        stdin=IOBuffer(FUNC_LLVM_IR)
+        stdin = IOBuffer(FUNC_LLVM_IR)
     )
 )
 
@@ -54,15 +54,19 @@ const fptr = Libdl.dlsym(lib, :func_wrap)
 function func_ccall(t::Float64, arr::AbstractVector{Float64})
     nitems = length(arr)
     bitsize = Base.elsize(arr)
-    GC.@preserve arr begin
+    return GC.@preserve arr begin
         excinfo = Ptr{Ptr{Cvoid}}(C_NULL)
         base::Ptr{Cdouble} = pointer(arr)
 
-        ccall(fptr, Cdouble,
-            (Ptr{Ptr{Cvoid}}, Cdouble, Ptr{Cvoid}, Ptr{Cvoid},
-                Clong, Clong, Ptr{Cdouble}, Clong, Clong),
+        ccall(
+            fptr, Cdouble,
+            (
+                Ptr{Ptr{Cvoid}}, Cdouble, Ptr{Cvoid}, Ptr{Cvoid},
+                Clong, Clong, Ptr{Cdouble}, Clong, Clong,
+            ),
             excinfo, t, C_NULL, C_NULL, nitems, bitsize,
-            base, nitems, nitems * bitsize)
+            base, nitems, nitems * bitsize
+        )
     end
 end
 
@@ -77,7 +81,7 @@ end
     err_llvmir = nothing
     b = @view a[1:5]
 
-    redirect_stdio(stdout=errstream, stderr=errstream, stdin=devnull) do
+    redirect_stdio(stdout = errstream, stderr = errstream, stdin = devnull) do
         try
             gradient(Reverse, func_ccall, Const(0.0), b)
         catch e

github-actions[bot] avatar Oct 24 '25 22:10 github-actions[bot]

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 72.50%. Comparing base (b02a7b5) to head (0d1f934).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2684      +/-   ##
==========================================
- Coverage   72.58%   72.50%   -0.08%     
==========================================
  Files          58       58              
  Lines       18739    18743       +4     
==========================================
- Hits        13602    13590      -12     
- Misses       5137     5153      +16     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Oct 24 '25 22:10 codecov[bot]

Could we use a small C library instead of using LLVM IR bitcode?

vchuravy avatar Oct 30 '25 15:10 vchuravy

Could we use a small C library instead of using LLVM IR bitcode?

Great point! Will consider this.

ymardoukhi avatar Oct 30 '25 15:10 ymardoukhi