From 6e86d8cfb48cf3a56d96b1acb464300759d6c43f Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Thu, 7 Apr 2016 10:23:04 -0400 Subject: [PATCH] Better doc and codegen for noreturn ccall Closes #14685 --- doc/manual/calling-c-and-fortran-code.rst | 10 ++++++++++ src/ccall.cpp | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/doc/manual/calling-c-and-fortran-code.rst b/doc/manual/calling-c-and-fortran-code.rst index ddb85f17a5076..49affe6d61e0c 100644 --- a/doc/manual/calling-c-and-fortran-code.rst +++ b/doc/manual/calling-c-and-fortran-code.rst @@ -400,6 +400,9 @@ Julia type with the same name, prefixed by C. This can help for writing portable +-----------------------------------+-----------------+----------------------+-----------------------------------+ | ``void`` | | | ``Void`` | +-----------------------------------+-----------------+----------------------+-----------------------------------+ +| ``void`` and | | | ``Union{}`` | +| ``[[noreturn]]`` or ``_Noreturn`` | | | | ++-----------------------------------+-----------------+----------------------+-----------------------------------+ | ``void*`` | | | ``Ptr{Void}`` | +-----------------------------------+-----------------+----------------------+-----------------------------------+ | ``T*`` (where T represents an | | | ``Ref{T}`` | @@ -473,6 +476,13 @@ C name Standard Julia Alias Julia Base Type Julia's ``Char`` type is 32 bits, which is not the same as the wide character type (``wchar_t`` or ``wint_t``) on all platforms. +.. warning:: + + A return type of ``Union{}`` means the function will not return + i.e. C++11 ``[[noreturn]]`` or C11 ``_Noreturn`` (e.g. ``jl_throw`` or + ``longjmp``). Do not use this for function that returns + no value (``void``) but does return. + .. note:: For ``wchar_t*`` arguments, the Julia type should be ``Cwstring`` (if the C diff --git a/src/ccall.cpp b/src/ccall.cpp index 43f3dc28d635f..753141b00f544 100644 --- a/src/ccall.cpp +++ b/src/ccall.cpp @@ -1013,6 +1013,10 @@ static std::string generate_func_sig( AttributeSet::get(jl_LLVMContext, i + 1, paramattrs[i])); } } + if (rt == jl_bottom_type) + attributes = attributes.addAttribute(jl_LLVMContext, + AttributeSet::FunctionIndex, + Attribute::NoReturn); return ""; }