[PATCH] D120770: [C2x] Implement literal suffixes for _BitInt

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 1 14:02:09 PST 2022


aaron.ballman created this revision.
aaron.ballman added reviewers: erichkeane, jyknight, rjmccall, rsmith.
Herald added subscribers: dexonsmith, hiraditya.
Herald added a project: All.
aaron.ballman requested review of this revision.
Herald added projects: clang, LLVM.
Herald added a subscriber: llvm-commits.

WG14 adopted N2775 (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2775.pdf) at our Feb 2022 meeting. This paper adds a literal suffix for bit-precise types that automatically sizes the bit-precise type to be the smallest possible legal `_BitInt` type that can represent the literal value. The suffix chosen is `wb` (for a signed bit-precise type) which can be combined with the `u` suffix (for an unsigned bit-precise type).

The preprocessor continues to operate as-if all integer types were `intmax_t`/`uintmax_t`, including bit-precise integer types. It is a constraint violation if the bit-precise literal is too large to fit within that type in the context of the preprocessor (when still using a pp-number preprocessing token), but it is not a constraint violation in other circumstances. This allows you to make bit-precise integer literals that are wider than what the preprocessor currently supports in order to initialize variables, etc.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120770

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Lex/LiteralSupport.h
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/lib/Lex/PPExpressions.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/bitint-suffix.c
  clang/test/Lexer/bitint-constants-compat.c
  clang/test/Lexer/bitint-constants.c
  llvm/include/llvm/ADT/APInt.h
  llvm/lib/Support/APInt.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120770.412240.patch
Type: text/x-patch
Size: 22475 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220301/431041aa/attachment-0001.bin>


More information about the cfe-commits mailing list