[clang] [clang] Add `__bf16` Type Support Macros With Literal Suffix Support (PR #134214)

via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 7 03:11:48 PDT 2025


================
@@ -978,6 +979,24 @@ NumericLiteralParser::NumericLiteralParser(StringRef TokSpelling,
   // we break out of the loop.
   for (; s != ThisTokEnd; ++s) {
     switch (*s) {
+    case 'b': // FP Suffix for "__bf16"
+    case 'B':
+      if (!Target.hasBFloat16Type())
+        break;
+      if (!isFPConstant)
+        break; // Error for integer constant.
+      if (HasSize)
+        break;
+      HasSize = true;
+
+      if (s + 3 < ThisTokEnd &&
+          ((s[0] == 'b' && s[1] == 'f') || (s[0] == 'B' && s[1] == 'F')) &&
+          s[2] == '1' && s[3] == '6') {
+        s += 3; // success, eat up 3 characters.
+        isBFloat16 = true;
+        continue;
+      }
+      break;
----------------
cor3ntin wrote:

This is true for C++23. Do we want extension warnings in other language modes @AaronBallman?

As an aside, did anyone benchmark that the pattern we use in this function is actually faster than string_view
comparisons?

https://github.com/llvm/llvm-project/pull/134214


More information about the cfe-commits mailing list