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

via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 3 06:52:44 PDT 2025


https://github.com/overmighty requested changes to this pull request.

This PR currently adds two suffixes: `bf16` and just `b`. Is this intended? GCC seems to only support `bf16`: https://godbolt.org/z/hEfcrGrG1.

It currently also lets Clang accept the following C++ code if the target doesn't have bfloat16 but has float16:

```cpp
auto foo = 1.0bf16;
```

And it lets Clang accept the following C++ code even if the target has neither bfloat16 nor float16:

```cpp
auto foo = 1.0b;
```

It also looks like `foo` ends up being of type `double` either way:

```
TranslationUnitDecl 0x5f0373f42d48 <<invalid sloc>> <invalid sloc>
|-TypedefDecl 0x5f0373f439d0 <<invalid sloc>> <invalid sloc> implicit __int128_t '__int128'
| `-BuiltinType 0x5f0373f43310 '__int128'
|-TypedefDecl 0x5f0373f43a40 <<invalid sloc>> <invalid sloc> implicit __uint128_t 'unsigned __int128'
| `-BuiltinType 0x5f0373f43330 'unsigned __int128'
|-TypedefDecl 0x5f0373f91f70 <<invalid sloc>> <invalid sloc> implicit __NSConstantString '__NSConstantString_tag'
| `-RecordType 0x5f0373f43b30 '__NSConstantString_tag'
|   `-CXXRecord 0x5f0373f43a98 '__NSConstantString_tag'
|-TypedefDecl 0x5f0373f43608 <<invalid sloc>> <invalid sloc> implicit __builtin_ms_va_list 'char *'
| `-PointerType 0x5f0373f435c0 'char *'
|   `-BuiltinType 0x5f0373f42df0 'char'
|-TypedefDecl 0x5f0373f43960 <<invalid sloc>> <invalid sloc> implicit __builtin_va_list '__va_list_tag[1]'
| `-ConstantArrayType 0x5f0373f43910 '__va_list_tag[1]' 1
|   `-RecordType 0x5f0373f436f0 '__va_list_tag'
|     `-CXXRecord 0x5f0373f43660 '__va_list_tag'
`-VarDecl 0x5f0373f92018 <a.cpp:1:1, col:12> col:6 foo 'double' cinit
  `-FloatingLiteral 0x5f0373f920c8 <col:12> 'double' 1.000000e+00
```

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


More information about the cfe-commits mailing list