Repository: JuliaLang/julia
File: JuliaLowering/test/function_calls_ir.jl (Julia)

Code before:
########################################
# Error: ccall with too many arguments
ccall(:strlen, Csize_t, (Cstring,), "asdfg", "blah")
#---------------------
LoweringError:
ccall(:strlen, Csize_t, (Cstring,), "asdfg", "blah")
└──────────────────────────────────────────────────┘ ── More arguments than types in ccall

########################################
# Error: ccall varargs with too few args
ccall(:foo, Csize_t, (Cstring...,), "asdfg")
#---------------------
LoweringError:
ccall(:foo, Csize_t, (Cstring...,), "asdfg")
#                     └────────┘ ── C ABI prohibits vararg without one required argument

########################################
# Error: ccall with multiple varargs
ccall(:foo, Csize_t, (Cstring..., Cstring...), "asdfg", "blah")
#---------------------
LoweringError:
ccall(:foo, Csize_t, (Cstring..., Cstring...), "asdfg", "blah")
#                     └────────┘ ── only the trailing ccall argument type should have `...`

########################################
# cglobal special support for (sym, lib) tuple
cglobal((:sym, lib), Int)
#---------------------
1   TestMod.lib
2   (call core.tuple :sym %₁)
3   TestMod.Int
4   (call core.cglobal %₂ %₃)
5   (return %₄)

########################################
# cglobal - non-tuple expressions in first arg are lowered as normal
cglobal(f(), Int)
#---------------------
1   TestMod.f
2   (call %₁)
3   TestMod.Int
4   (call core.cglobal %₂ %₃)
5   (return %₄)

########################################
# Error: cglobal too many arguments
cglobal(:sym, Int, blah)
#---------------------
LoweringError:
cglobal(:sym, Int, blah)
└──────────────────────┘ ── cglobal must have one or two arguments

Review comment (suggestion):
```suggestion
# cglobal special support for (sym, lib) tuple
# unlike flisp we outline the tuple and allow constant propgation to put it back
# before codegen generates code for `cglobal`
```

Code after:
########################################
# Error: ccall with too many arguments
ccall(:strlen, Csize_t, (Cstring,), "asdfg", "blah")
#---------------------
LoweringError:
ccall(:strlen, Csize_t, (Cstring,), "asdfg", "blah")
└──────────────────────────────────────────────────┘ ── More arguments than types in ccall

########################################
# Error: ccall varargs with too few args
ccall(:foo, Csize_t, (Cstring...,), "asdfg")
#---------------------
LoweringError:
ccall(:foo, Csize_t, (Cstring...,), "asdfg")
#                     └────────┘ ── C ABI prohibits vararg without one required argument

########################################
# Error: ccall with multiple varargs
ccall(:foo, Csize_t, (Cstring..., Cstring...), "asdfg", "blah")
#---------------------
LoweringError:
ccall(:foo, Csize_t, (Cstring..., Cstring...), "asdfg", "blah")
#                     └────────┘ ── only the trailing ccall argument type should have `...`

########################################
# cglobal special support for (sym, lib) tuple
# unlike flisp we outline the tuple and allow constant propagation to put it
# back before codegen generates code for `cglobal`
cglobal((:sym, lib), Int)
#---------------------
1   TestMod.lib
2   (call core.tuple :sym %₁)
3   TestMod.Int
4   (call core.cglobal %₂ %₃)
5   (return %₄)

########################################
# cglobal - non-tuple expressions in first arg are lowered as normal
cglobal(f(), Int)
#---------------------
1   TestMod.f
2   (call %₁)
3   TestMod.Int
4   (call core.cglobal %₂ %₃)
5   (return %₄)

########################################
# Error: cglobal too many arguments
cglobal(:sym, Int, blah)
#---------------------
LoweringError: