Community
Participate
Working Groups
Build Identifier: Build id: 20111215-0110 For code like this (observed in real code as well, of course): int f(void) { assert(false); } One solution would be to special-case assert(), but here I think it would be better to correctly parse the glibc assert macro and the __noreturn__ attributed functions that it resolves to: /* This prints an "Assertion failed" message and aborts. */ extern void __assert_fail (__const char *__assertion, __const char *__file, unsigned int __line, __const char *__function) __THROW __attribute__ ((__noreturn__)); /* Likewise, but prints the error text for ERRNUM. */ extern void __assert_perror_fail (int __errnum, __const char *__file, unsigned int __line, __const char *__function) __THROW __attribute__ ((__noreturn__)); /* The following is not at all used here but needed for standard compliance. */ extern void __assert (const char *__assertion, const char *__file, int __line) __THROW __attribute__ ((__noreturn__)); __END_DECLS #endif /* Not _ASSERT_H_DECLS */ # define assert(expr) \ ((expr) \ ? __ASSERT_VOID_CAST (0) \ : __assert_fail (__STRING(expr), __FILE__, __LINE__, __ASSERT_FUNCTION)) This is technically a duplicate of #346557, as far as the root cause, but a different symptom. Reproducible: Always
That is not that easy - we cannot just assume that assert not returns, we also have to do constant folding propagation and static evaluation to evaluate ?: expression. I think fixing this code to return 0 is a lot easier.
The code I presented is a reduced testcase, of course. In context, they are trying to halt the system if the end of a function is reached. Due to the nature of the custom embedded operating system, they have chosen to do it with assert(false). Thankfully, they didn't use a macro with inline asm -- the macro resolves to real functions that have attributes to help. I hear what you are saying about static evaluation, which would likely be very useful for other circumstances as well. Is this bug an appropriate way to track that feature for a future release?