Handle never type in return position consistently.

Fixes #779
This commit is contained in:
Emilio Cobos Álvarez
2022-08-30 14:08:16 +02:00
parent f43ccfc047
commit 47b1d1de1e
13 changed files with 198 additions and 54 deletions
@@ -0,0 +1,20 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#ifndef NO_RETURN_ATTR
#ifdef __GNUC__
#define NO_RETURN_ATTR __attribute__ ((noreturn))
#else // __GNUC__
#define NO_RETURN_ATTR
#endif // __GNUC__
#endif // NO_RETURN_ATTR
typedef struct Example {
void (*f)(uintptr_t, uintptr_t) NO_RETURN_ATTR;
} Example;
void loop_forever(void) NO_RETURN_ATTR;
uint8_t normal_return(struct Example arg, void (*other)(uint8_t) NO_RETURN_ATTR);
@@ -0,0 +1,28 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#ifndef NO_RETURN_ATTR
#ifdef __GNUC__
#define NO_RETURN_ATTR __attribute__ ((noreturn))
#else // __GNUC__
#define NO_RETURN_ATTR
#endif // __GNUC__
#endif // NO_RETURN_ATTR
typedef struct Example {
void (*f)(uintptr_t, uintptr_t) NO_RETURN_ATTR;
} Example;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
void loop_forever(void) NO_RETURN_ATTR;
uint8_t normal_return(struct Example arg, void (*other)(uint8_t) NO_RETURN_ATTR);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
+5 -1
View File
@@ -11,6 +11,10 @@
#endif // NO_RETURN_ATTR
typedef struct {
void (*f)(uintptr_t, uintptr_t) NO_RETURN_ATTR;
} Example;
void loop_forever(void) NO_RETURN_ATTR;
uint8_t normal_return(void);
uint8_t normal_return(Example arg, void (*other)(uint8_t) NO_RETURN_ATTR);
@@ -11,13 +11,17 @@
#endif // NO_RETURN_ATTR
typedef struct {
void (*f)(uintptr_t, uintptr_t) NO_RETURN_ATTR;
} Example;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
void loop_forever(void) NO_RETURN_ATTR;
uint8_t normal_return(void);
uint8_t normal_return(Example arg, void (*other)(uint8_t) NO_RETURN_ATTR);
#ifdef __cplusplus
} // extern "C"
+5 -1
View File
@@ -12,10 +12,14 @@
#endif // NO_RETURN_ATTR
struct Example {
void (*f)(uintptr_t, uintptr_t) NO_RETURN_ATTR;
};
extern "C" {
void loop_forever() NO_RETURN_ATTR;
uint8_t normal_return();
uint8_t normal_return(Example arg, void (*other)(uint8_t) NO_RETURN_ATTR);
} // extern "C"
+4 -1
View File
@@ -14,6 +14,9 @@ cdef extern from *:
cdef extern from *:
ctypedef struct Example:
void (*f)(uintptr_t, uintptr_t);
void loop_forever();
uint8_t normal_return();
uint8_t normal_return(Example arg, void (*other)(uint8_t));
@@ -0,0 +1,20 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#ifndef NO_RETURN_ATTR
#ifdef __GNUC__
#define NO_RETURN_ATTR __attribute__ ((noreturn))
#else // __GNUC__
#define NO_RETURN_ATTR
#endif // __GNUC__
#endif // NO_RETURN_ATTR
struct Example {
void (*f)(uintptr_t, uintptr_t) NO_RETURN_ATTR;
};
void loop_forever(void) NO_RETURN_ATTR;
uint8_t normal_return(struct Example arg, void (*other)(uint8_t) NO_RETURN_ATTR);
@@ -0,0 +1,28 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#ifndef NO_RETURN_ATTR
#ifdef __GNUC__
#define NO_RETURN_ATTR __attribute__ ((noreturn))
#else // __GNUC__
#define NO_RETURN_ATTR
#endif // __GNUC__
#endif // NO_RETURN_ATTR
struct Example {
void (*f)(uintptr_t, uintptr_t) NO_RETURN_ATTR;
};
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
void loop_forever(void) NO_RETURN_ATTR;
uint8_t normal_return(struct Example arg, void (*other)(uint8_t) NO_RETURN_ATTR);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
@@ -0,0 +1,22 @@
from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t
cdef extern from *:
ctypedef bint bool
ctypedef struct va_list
#ifndef NO_RETURN_ATTR
#ifdef __GNUC__
#define NO_RETURN_ATTR __attribute__ ((noreturn))
#else // __GNUC__
#define NO_RETURN_ATTR
#endif // __GNUC__
#endif // NO_RETURN_ATTR
cdef extern from *:
cdef struct Example:
void (*f)(uintptr_t, uintptr_t);
void loop_forever();
uint8_t normal_return(Example arg, void (*other)(uint8_t));
+7 -2
View File
@@ -1,9 +1,14 @@
#[no_mangle]
pub extern fn loop_forever() -> ! {
pub extern "C" fn loop_forever() -> ! {
loop {}
}
#[no_mangle]
pub extern fn normal_return() -> u8 {
pub extern "C" fn normal_return(arg: Example, other: extern "C" fn(u8) -> !) -> u8 {
0
}
#[repr(C)]
pub struct Example {
pub f: extern "C" fn(usize, usize) -> !,
}