mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-01-31 02:22:07 +00:00
BUILD: Fix build when using clang without optimizing.
ha_free() uses code that attempts to set a non-existant variable to provoke a link-time error, with the expectation that the compiler will not omit that if the code is unreachable. However, clang will emit it when compiling with no optimization, so only do that if __OPTIMIZE__ is defined.
This commit is contained in:
parent
249f0562cf
commit
7b00e31509
@ -73,13 +73,25 @@
|
||||
#define BUG_ON(cond)
|
||||
#endif
|
||||
|
||||
/* When not optimizing, clang won't remove that code, so only compile it in when optimizing */
|
||||
#ifdef __OPTIMIZE__
|
||||
#define HA_LINK_ERROR(what) \
|
||||
do { \
|
||||
/* provoke a build-time error */ \
|
||||
extern volatile int what; \
|
||||
what = 1; \
|
||||
} while (0)
|
||||
#else
|
||||
#define HA_LINK_ERROR(what) \
|
||||
do { \
|
||||
} while (0)
|
||||
#endif /* __OPTIMIZE__ */
|
||||
|
||||
/* more reliable free() that clears the pointer */
|
||||
#define ha_free(x) do { \
|
||||
typeof(x) __x = (x); \
|
||||
if (__builtin_constant_p((x)) || __builtin_constant_p(*(x))) { \
|
||||
/* provoke a build-time error */ \
|
||||
extern volatile int call_to_ha_free_attempts_to_free_a_constant; \
|
||||
call_to_ha_free_attempts_to_free_a_constant = 1; \
|
||||
HA_LINK_ERROR(call_to_ha_free_attempts_to_free_a_constant); \
|
||||
} \
|
||||
free(*__x); \
|
||||
*__x = NULL; \
|
||||
@ -150,9 +162,7 @@ struct mem_stats {
|
||||
__asm__(".globl __start_mem_stats"); \
|
||||
__asm__(".globl __stop_mem_stats"); \
|
||||
if (__builtin_constant_p((x)) || __builtin_constant_p(*(x))) { \
|
||||
/* provoke a build-time error */ \
|
||||
extern volatile int call_to_ha_free_attempts_to_free_a_constant; \
|
||||
call_to_ha_free_attempts_to_free_a_constant = 1; \
|
||||
HA_LINK_ERROR(call_to_ha_free_attempts_to_free_a_constant); \
|
||||
} \
|
||||
if (*__x) \
|
||||
_HA_ATOMIC_ADD(&_.calls, 1); \
|
||||
|
Loading…
Reference in New Issue
Block a user