Mesa (staging/21.3): util: Add support for clang::fallthrough.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Nov 9 22:38:05 UTC 2021


Module: Mesa
Branch: staging/21.3
Commit: e243eba108a08d93e928235ca08b826bfffbc031
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=e243eba108a08d93e928235ca08b826bfffbc031

Author: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Date:   Tue Nov  9 11:57:28 2021 +0100

util: Add support for clang::fallthrough.

Looks like the __attribute__ version doesn't work for C++ in the
Android build. Only found now because we don't enable
-Wimplicit-fallthrough by default project wide for C++. Only
ACO enables it.

Reviewed-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13164>
(cherry picked from commit aad80e47d8aab52081a6f10a5b0cd01390e26f10)

---

 .pick_status.json   |  2 +-
 src/util/compiler.h | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/.pick_status.json b/.pick_status.json
index 0e2c14c8acc..b42bfb3b738 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -13,7 +13,7 @@
         "description": "util: Add support for clang::fallthrough.",
         "nominated": false,
         "nomination_type": null,
-        "resolution": 4,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": null
     },
diff --git a/src/util/compiler.h b/src/util/compiler.h
index da602cfa33d..83f8e346a08 100644
--- a/src/util/compiler.h
+++ b/src/util/compiler.h
@@ -76,9 +76,20 @@
 #  define __has_attribute(x) 0
 #endif
 
+#if defined(__has_cpp_attribute) && defined(__clang__)
+/* We do not do the same trick as __has_attribute because parsing
+ * clang::fallthrough in the preprocessor fails in GCC. */
+#  define HAS_CLANG_FALLTHROUGH  __has_cpp_attribute(clang::fallthrough)
+#else
+#  define HAS_CLANG_FALLTHROUGH 0
+#endif
+
 #if __cplusplus >= 201703L || __STDC_VERSION__ > 201710L
 /* Standard C++17/C23 attribute */
 #define FALLTHROUGH [[fallthrough]]
+#elif HAS_CLANG_FALLTHROUGH
+/* Clang++ specific */
+#define FALLTHROUGH [[clang::fallthrough]]
 #elif __has_attribute(fallthrough)
 /* Non-standard but supported by at least gcc and clang */
 #define FALLTHROUGH __attribute__((fallthrough))



More information about the mesa-commit mailing list