diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2021-12-06 12:46:54 -0500 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2021-12-06 12:52:01 -0500 |
commit | 6c75ab5f66b403f7ca67e86aeed3a58abe10570b (patch) | |
tree | 08a85a30d4be191d1d0dd512f718b8b3d940a500 /clang/lib/Parse/ParseDecl.cpp | |
parent | a6816b957d28ab7855f2af1277c72a6d65b600b4 (diff) | |
download | llvm-6c75ab5f66b403f7ca67e86aeed3a58abe10570b.zip llvm-6c75ab5f66b403f7ca67e86aeed3a58abe10570b.tar.gz llvm-6c75ab5f66b403f7ca67e86aeed3a58abe10570b.tar.bz2 |
Introduce _BitInt, deprecate _ExtInt
WG14 adopted the _ExtInt feature from Clang for C23, but renamed the
type to be _BitInt. This patch does the vast majority of the work to
rename _ExtInt to _BitInt, which accounts for most of its size. The new
type is exposed in older C modes and all C++ modes as a conforming
extension. However, there are functional changes worth calling out:
* Deprecates _ExtInt with a fix-it to help users migrate to _BitInt.
* Updates the mangling for the type.
* Updates the documentation and adds a release note to warn users what
is going on.
* Adds new diagnostics for use of _BitInt to call out when it's used as
a Clang extension or as a pre-C23 compatibility concern.
* Adds new tests for the new diagnostic behaviors.
I want to call out the ABI break specifically. We do not believe that
this break will cause a significant imposition for early adopters of
the feature, and so this is being done as a full break. If it turns out
there are critical uses where recompilation is not an option for some
reason, we can consider using ABI tags to ease the transition.
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 1bdeccc..0c1f88b 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -2891,7 +2891,8 @@ void Parser::ParseAlignmentSpecifier(ParsedAttributes &Attrs, } ExprResult Parser::ParseExtIntegerArgument() { - assert(Tok.is(tok::kw__ExtInt) && "Not an extended int type"); + assert(Tok.isOneOf(tok::kw__ExtInt, tok::kw__BitInt) && + "Not an extended int type"); ConsumeToken(); BalancedDelimiterTracker T(*this, tok::l_paren); @@ -3882,11 +3883,13 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, isInvalid = DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec, DiagID, Policy); break; - case tok::kw__ExtInt: { + case tok::kw__ExtInt: + case tok::kw__BitInt: { + DiagnoseBitIntUse(Tok); ExprResult ER = ParseExtIntegerArgument(); if (ER.isInvalid()) continue; - isInvalid = DS.SetExtIntType(Loc, ER.get(), PrevSpec, DiagID, Policy); + isInvalid = DS.SetBitIntType(Loc, ER.get(), PrevSpec, DiagID, Policy); ConsumedEnd = PrevTokLocation; break; } @@ -5015,6 +5018,7 @@ bool Parser::isKnownToBeTypeSpecifier(const Token &Tok) const { case tok::kw_char32_t: case tok::kw_int: case tok::kw__ExtInt: + case tok::kw__BitInt: case tok::kw___bf16: case tok::kw_half: case tok::kw_float: @@ -5097,6 +5101,7 @@ bool Parser::isTypeSpecifierQualifier() { case tok::kw_char32_t: case tok::kw_int: case tok::kw__ExtInt: + case tok::kw__BitInt: case tok::kw_half: case tok::kw___bf16: case tok::kw_float: @@ -5268,6 +5273,7 @@ bool Parser::isDeclarationSpecifier(bool DisambiguatingWithExpression) { case tok::kw_int: case tok::kw__ExtInt: + case tok::kw__BitInt: case tok::kw_half: case tok::kw___bf16: case tok::kw_float: @@ -7476,3 +7482,24 @@ bool Parser::TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc, } return false; } + +void Parser::DiagnoseBitIntUse(const Token &Tok) { + // If the token is for _ExtInt, diagnose it as being deprecated. Otherwise, + // the token is about _BitInt and gets (potentially) diagnosed as use of an + // extension. + assert(Tok.isOneOf(tok::kw__ExtInt, tok::kw__BitInt) && + "expected either an _ExtInt or _BitInt token!"); + + SourceLocation Loc = Tok.getLocation(); + if (Tok.is(tok::kw__ExtInt)) { + Diag(Loc, diag::warn_ext_int_deprecated) + << FixItHint::CreateReplacement(Loc, "_BitInt"); + } else { + // In C2x mode, diagnose that the use is not compatible with pre-C2x modes. + // Otherwise, diagnose that the use is a Clang extension. + if (getLangOpts().C2x) + Diag(Loc, diag::warn_c17_compat_bit_int); + else + Diag(Loc, diag::ext_bit_int) << getLangOpts().CPlusPlus; + } +} |