This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug preprocessor/77488] Proposal for __FILENAME_ONLY__
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 06 Sep 2016 17:35:53 +0000
- Subject: [Bug preprocessor/77488] Proposal for __FILENAME_ONLY__
- Auto-submitted: auto-generated
- References: <bug-77488-4@http.gcc.gnu.org/bugzilla/>
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.