public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-5459] libcpp: Use [[likely]] conditionally
@ 2021-11-23 2:44 Marek Polacek
0 siblings, 0 replies; only message in thread
From: Marek Polacek @ 2021-11-23 2:44 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:630686f93f0018fa1ef128aa673fddd302cc83e1
commit r12-5459-g630686f93f0018fa1ef128aa673fddd302cc83e1
Author: Marek Polacek <polacek@redhat.com>
Date: Mon Nov 22 11:29:40 2021 -0500
libcpp: Use [[likely]] conditionally
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.
Diff:
---
libcpp/lex.c | 2 +-
libcpp/system.h | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/libcpp/lex.c b/libcpp/lex.c
index 94c36f0d014..9c27d8b5a08 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -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 ();
diff --git a/libcpp/system.h b/libcpp/system.h
index ee5fbe28889..f6fc583ab80 100644
--- a/libcpp/system.h
+++ b/libcpp/system.h
@@ -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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-11-23 2:44 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-23 2:44 [gcc r12-5459] libcpp: Use [[likely]] conditionally Marek Polacek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).