Skip to content

Commit d3d48b2

Browse files
committed
Better doc and codegen for noreturn ccall
Closes #14685
1 parent a51c6fb commit d3d48b2

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

doc/manual/calling-c-and-fortran-code.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,9 @@ Julia type with the same name, prefixed by C. This can help for writing portable
400400
+-----------------------------------+-----------------+----------------------+-----------------------------------+
401401
| ``void`` | | | ``Void`` |
402402
+-----------------------------------+-----------------+----------------------+-----------------------------------+
403+
| ``void`` and | | | ``Union{}`` |
404+
| ``__attribute__((noreturn))`` | | | |
405+
+-----------------------------------+-----------------+----------------------+-----------------------------------+
403406
| ``void*`` | | | ``Ptr{Void}`` |
404407
+-----------------------------------+-----------------+----------------------+-----------------------------------+
405408
| ``T*`` (where T represents an | | | ``Ref{T}`` |
@@ -473,6 +476,12 @@ C name Standard Julia Alias Julia Base Type
473476
Julia's ``Char`` type is 32 bits, which is not the same as the wide character
474477
type (``wchar_t`` or ``wint_t``) on all platforms.
475478

479+
.. warning::
480+
481+
A return type of ``Union{}`` means the function will not return (e.g.
482+
``jl_throw`` or ``longjmp``). Do not use this for functions that return
483+
no value (``void``) but does return.
484+
476485
.. note::
477486

478487
For ``wchar_t*`` arguments, the Julia type should be ``Cwstring`` (if the C

src/ccall.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,10 @@ static std::string generate_func_sig(
10131013
AttributeSet::get(jl_LLVMContext, i + 1, paramattrs[i]));
10141014
}
10151015
}
1016+
if (rt == jl_bottom_type)
1017+
attributes = attributes.addAttribute(jl_LLVMContext,
1018+
AttributeSet::FunctionIndex,
1019+
Attribute::NoReturn);
10161020
return "";
10171021
}
10181022

0 commit comments

Comments
 (0)