Skip to content

Commit

Permalink
Guard against use of undefined macros in headers
Browse files Browse the repository at this point in the history
In case users apply the -Wundef flag on their own C code.
  • Loading branch information
MisterDA committed Nov 6, 2023
1 parent 10f1334 commit 3d76183
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
6 changes: 6 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,12 @@ Working version
review by Vincent Laviron, KC Sivaramakrishnan and Xavier Leroy,
report by Vesa Karvonen and Carine Morel)

- #12714: check whether macros are defined before using them to ensure
that the headers can always be used in code which turns on -Wundef
(or equivalent).
(Antonin Décimo, review by Miod Vallat, Gabriel Scherer,
Xavier Leroy, and David Allsopp)

OCaml 5.1.1
-----------

Expand Down
2 changes: 2 additions & 0 deletions runtime/caml/fiber.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ struct stack_info {
#elif defined(TARGET_power)
/* ELF ABI: 4 reserved words at bottom of C stack */
#define Reserved_space_c_stack_link 4 * 8
#else
#define Reserved_space_c_stack_link 0
#endif

/* This structure is used for storing the OCaml return pointer when
Expand Down
12 changes: 7 additions & 5 deletions runtime/caml/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
#define CAMLdeprecated_typedef(name, type) typedef type name
#endif

#if defined(__GNUC__) && __STDC_VERSION__ >= 199901L \
|| defined(_MSC_VER) && _MSC_VER >= 1925
#if defined(__GNUC__) \
&& defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L \
|| defined(_MSC_VER) && _MSC_VER >= 1925

#define CAML_STRINGIFY(x) #x
#ifdef _MSC_VER
Expand Down Expand Up @@ -84,9 +85,10 @@ CAMLdeprecated_typedef(addr, char *);
Note: CAMLnoreturn is a different macro defined in memory.h,
to be used in function bodies rather than as a function attribute.
*/
#if __STDC_VERSION__ >= 202300L || __cplusplus >= 201103L
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202300L \
|| defined(__cplusplus) && __cplusplus >= 201103L
#define CAMLnoret [[noreturn]]
#elif __STDC_VERSION__ >= 201112L
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#define CAMLnoret _Noreturn
#elif defined(__GNUC__)
#define CAMLnoret __attribute__ ((noreturn))
Expand Down Expand Up @@ -561,7 +563,7 @@ CAMLextern int caml_snwprintf(wchar_t * buf,
# define CAMLno_asan __attribute__((no_sanitize("address")))
# endif
#else
# if __SANITIZE_ADDRESS__
# if defined(__SANITIZE_ADDRESS__)
# undef CAMLno_asan
# define CAMLno_asan __attribute__((no_sanitize_address))
# endif
Expand Down
2 changes: 1 addition & 1 deletion runtime/caml/tsan.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# endif
# endif
#else
# if __SANITIZE_THREAD__
# if defined(__SANITIZE_THREAD__)
# undef CAMLreally_no_tsan
# define CAMLreally_no_tsan __attribute__((no_sanitize_thread))
# endif
Expand Down

0 comments on commit 3d76183

Please sign in to comment.