Skip to content

Commit e8a2dd2

Browse files
committed
Merge pull request #15788 from JuliaLang/yyc/noret
Better doc and codegen for noreturn ccall
2 parents 481a05c + 6e86d8c commit e8a2dd2

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

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

Lines changed: 10 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+
| ``[[noreturn]]`` or ``_Noreturn`` | | | |
405+
+-----------------------------------+-----------------+----------------------+-----------------------------------+
403406
| ``void*`` | | | ``Ptr{Void}`` |
404407
+-----------------------------------+-----------------+----------------------+-----------------------------------+
405408
| ``T*`` (where T represents an | | | ``Ref{T}`` |
@@ -473,6 +476,13 @@ 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
482+
i.e. C++11 ``[[noreturn]]`` or C11 ``_Noreturn`` (e.g. ``jl_throw`` or
483+
``longjmp``). Do not use this for function that returns
484+
no value (``void``) but does return.
485+
476486
.. note::
477487

478488
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)