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


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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to