[Bug preprocessor/77488] Proposal for __FILENAME_ONLY__

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Sep 6 17:36:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77488

--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
> How would that help here?  You obviously pass the address of the string
> literal to the __assert_func or how is the assertion passed, thus it escapes.

With the optimization in place the assert macro could be defined similarly to
the one below.  __builtin_printf is known not to escape string arguments of its
%s directives (or form pointers prior to their beginning).

#define FILE  (__builtin_strrchr (__FILE__, '/') ? __builtin_strrchr (__FILE__,
'/') + 1 : __FILE__)

#define assert(e) ((e) ? (void)0 : (void)(__builtin_printf ("%s:%i: assertion
%s failed\n", FILE, __LINE__, #e), __builtin_abort ()))

To make the optimization more generally applicable (so that it could work with
arbitrary functions including __assert_func) a new attribute might need to be
introduced to tell GCC about the same guarantee.


More information about the Gcc-bugs mailing list