[libc++] Use __builtin_FILE and __builtin_LINE in _LIBCPP_ASSERT
authorLouis Dionne <ldionne.2@gmail.com>
Tue, 7 Feb 2023 00:11:14 +0000 (16:11 -0800)
committerLouis Dionne <ldionne.2@gmail.com>
Tue, 7 Feb 2023 15:35:33 +0000 (07:35 -0800)
This avoids theoretical potential ODR violations since __LINE__ and
__FILE__ expand to different things depending on where they are.

Differential Revision: https://reviews.llvm.org/D143443

libcxx/include/__assert

index 3f4e933..d94a657 100644 (file)
@@ -41,7 +41,8 @@
 #  define _LIBCPP_ASSERT(expression, message)                                                                          \
     (__builtin_expect(static_cast<bool>(expression), 1)                                                                \
          ? (void)0                                                                                                     \
-         : _LIBCPP_VERBOSE_ABORT("%s:%d: assertion %s failed: %s", __FILE__, __LINE__, #expression, message))
+         : _LIBCPP_VERBOSE_ABORT(                                                                                      \
+               "%s:%d: assertion %s failed: %s", __builtin_FILE(), __builtin_LINE(), #expression, message))
 #elif !defined(_LIBCPP_ASSERTIONS_DISABLE_ASSUME) && __has_builtin(__builtin_assume)
 #  define _LIBCPP_ASSERT(expression, message)                                                                          \
     (_LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wassume")                                              \