Implement literal suffixes for _BitInt
authorAaron Ballman <aaron@aaronballman.com>
Mon, 14 Mar 2022 13:22:37 +0000 (09:22 -0400)
committerAaron Ballman <aaron@aaronballman.com>
Mon, 14 Mar 2022 13:24:19 +0000 (09:24 -0400)
commit8cba72177dcd8de5d37177dbaf2347e5c1f0f1e8
tree2456735e4473af6bf031f6a9076dba3988bf8129
parentdc152659b4527cc2e5f75cc33f36df67c7d5db26
Implement literal suffixes for _BitInt

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.
12 files changed:
clang/docs/ReleaseNotes.rst
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 [new file with mode: 0644]
clang/test/Lexer/bitint-constants-compat.c [new file with mode: 0644]
clang/test/Lexer/bitint-constants.c [new file with mode: 0644]
llvm/include/llvm/ADT/APInt.h
llvm/lib/Support/APInt.cpp