diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2022-01-28 15:00:20 -0500 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2022-01-28 15:04:29 -0500 |
commit | 86797fdb6f51d32f285e48b6d3e0fc5b8b852734 (patch) | |
tree | 2fc62491019b2f2dc2bafdad397ba932c9c19f12 /clang/lib/Frontend/InitPreprocessor.cpp | |
parent | 944dca758f1c25706b0150ea238f46c8707b95af (diff) | |
download | llvm-86797fdb6f51d32f285e48b6d3e0fc5b8b852734.zip llvm-86797fdb6f51d32f285e48b6d3e0fc5b8b852734.tar.gz llvm-86797fdb6f51d32f285e48b6d3e0fc5b8b852734.tar.bz2 |
Add BITINT_MAXWIDTH support
Part of the _BitInt feature in C2x
(http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2763.pdf) is a new
macro in limits.h named BITINT_MAXWIDTH that can be used to determine
the maximum width of a bit-precise integer type. This macro must expand
to a value that is at least as large as ULLONG_WIDTH.
This adds an implementation-defined macro named __BITINT_MAXWIDTH__ to
specify that value, which is used by limits.h for the standard macro.
This also limits the maximum bit width to 128 bits because backends do
not currently support all mathematical operations (such as division) on
wider types yet. This maximum is expected to be increased in the future.
Diffstat (limited to 'clang/lib/Frontend/InitPreprocessor.cpp')
-rw-r--r-- | clang/lib/Frontend/InitPreprocessor.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index a9023a7..e259ab4 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -25,6 +25,7 @@ #include "clang/Serialization/ASTReader.h" #include "llvm/ADT/APFloat.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/DerivedTypes.h" using namespace clang; static bool MacroBodyEndsInBackslash(StringRef MacroBody) { @@ -914,6 +915,13 @@ static void InitializePredefinedMacros(const TargetInfo &TI, Builder.defineMacro("__LONG_WIDTH__", Twine(TI.getLongWidth())); Builder.defineMacro("__LLONG_WIDTH__", Twine(TI.getLongLongWidth())); + size_t BitIntMaxWidth = TI.getMaxBitIntWidth(); + assert(BitIntMaxWidth <= llvm::IntegerType::MAX_INT_BITS && + "Target defined a max bit width larger than LLVM can support!"); + assert(BitIntMaxWidth >= TI.getLongLongWidth() && + "Target defined a max bit width smaller than the C standard allows!"); + Builder.defineMacro("__BITINT_MAXWIDTH__", Twine(BitIntMaxWidth)); + DefineTypeSize("__SCHAR_MAX__", TargetInfo::SignedChar, TI, Builder); DefineTypeSize("__SHRT_MAX__", TargetInfo::SignedShort, TI, Builder); DefineTypeSize("__INT_MAX__", TargetInfo::SignedInt, TI, Builder); |