[PATCH] D80963: [WIP][clang] Allow {u}int_fastN_t to be different to {u}int_leastN_t

Sam Elliott via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 1 17:21:59 PDT 2020


lenary created this revision.
lenary added reviewers: luismarques, asb.
Herald added a project: clang.

This is in order to support psABIs where these two type sizes do not match for
specific values of N. The default implementation matches clang's current
behaviour where `getLeastIntTypeByWidth` is used for `{u}int_fastN_t`.

This patch is a Work-In-Progress. I am seeking guidance as to how to update
clang's `stdint.h` to match this change.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80963

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Frontend/InitPreprocessor.cpp


Index: clang/lib/Frontend/InitPreprocessor.cpp
===================================================================
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -257,7 +257,7 @@
                               const TargetInfo &TI, MacroBuilder &Builder) {
   // stdint.h currently defines the fast int types as equivalent to the least
   // types.
-  TargetInfo::IntType Ty = TI.getLeastIntTypeByWidth(TypeWidth, IsSigned);
+  TargetInfo::IntType Ty = TI.getFastIntTypeByWidth(TypeWidth, IsSigned);
   if (Ty == TargetInfo::NoInt)
     return;
 
Index: clang/include/clang/Basic/TargetInfo.h
===================================================================
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -365,9 +365,21 @@
   virtual IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
 
   /// Return the smallest integer type with at least the specified width.
+  ///
+  /// This will be used for `{u}int_least<BitWidth>_t` in C.
   virtual IntType getLeastIntTypeByWidth(unsigned BitWidth,
                                          bool IsSigned) const;
 
+  /// Return the "fastest" integer type with at least the specified width.
+  ///
+  /// This will be used for `{u}int_fast<BitWidth>_t` in C.
+  ///
+  /// The default implementation will match getLeastIntTypeByWidth.
+  virtual IntType getFastIntTypeByWidth(unsigned BitWidth,
+                                        bool IsSigned) const {
+    return getLeastIntTypeByWidth(BitWidth, IsSigned);
+  }
+
   /// Return floating point type with specified width. On PPC, there are
   /// three possible types for 128-bit floating point: "PPC double-double",
   /// IEEE 754R quad precision, and "long double" (which under the covers


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80963.267764.patch
Type: text/x-patch
Size: 1796 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200602/8b316c82/attachment.bin>


More information about the cfe-commits mailing list