]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libcpp: Use [[likely]] conditionally
authorMarek Polacek <polacek@redhat.com>
Mon, 22 Nov 2021 16:29:40 +0000 (11:29 -0500)
committerMarek Polacek <polacek@redhat.com>
Tue, 23 Nov 2021 02:43:38 +0000 (21:43 -0500)
Let's hide [[likely]] behind a macro, to suppress warnings if the
compiler doesn't support it.

Co-authored-by: Jonathan Wakely <jwakely@redhat.com>
PR preprocessor/103355

libcpp/ChangeLog:

* lex.c: Use ATTR_LIKELY instead of [[likely]].
* system.h (ATTR_LIKELY): Define.

libcpp/lex.c
libcpp/system.h

index 94c36f0d0148f2ddce48aa0d1398ef7cc97d1bf3..9c27d8b5a085e6ff256514d0aa6bed8023e97ede 100644 (file)
@@ -1286,7 +1286,7 @@ namespace bidi {
       case kind::RTL:
        /* These aren't popped by a PDF/PDI.  */
        break;
-      [[likely]] case kind::NONE:
+      ATTR_LIKELY case kind::NONE:
        break;
       default:
        abort ();
index ee5fbe288892dc502016ecfe51637cc896aa18a7..f6fc583ab806afe8edf93df2bb9d9b2f5c4f2c71 100644 (file)
@@ -422,6 +422,16 @@ extern void fancy_abort (const char *, int, const char *) ATTRIBUTE_NORETURN;
 #define gcc_checking_assert(EXPR) ((void)(0 && (EXPR)))
 #endif
 
+#ifdef __has_cpp_attribute
+# if __has_cpp_attribute(likely)
+#  define ATTR_LIKELY [[likely]]
+# elif __has_cpp_attribute(__likely__)
+#  define ATTR_LIKELY [[__likely__]]
+# else
+#  define ATTR_LIKELY
+# endif
+#endif
+
 /* Poison identifiers we do not want to use.  */
 #if (GCC_VERSION >= 3000)
 #undef calloc