]> granicus.if.org Git - clang/commitdiff
[WebAssembly] Use "long long" for int_fast64_t and int_least64_t on wasm64
authorDan Gohman <dan433584@gmail.com>
Mon, 14 Sep 2015 21:49:41 +0000 (21:49 +0000)
committerDan Gohman <dan433584@gmail.com>
Mon, 14 Sep 2015 21:49:41 +0000 (21:49 +0000)
This makes int_fast64_t and int_least64_t the same type as int64_t, and
eliminates a difference between wasm32 and wasm64.

Differential Revision: http://reviews.llvm.org/D12861

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@247622 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/TargetInfo.h
lib/Basic/Targets.cpp
test/Preprocessor/init.c

index bdae270aa846a8d0f0df8c59fbb77f7ad17b1104..4683ede63dfdff53ba25b1b4b5765f9ebb6ad6e5 100644 (file)
@@ -255,10 +255,11 @@ public:
   unsigned getTypeWidth(IntType T) const;
 
   /// \brief Return integer type with specified width.
-  IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
+  virtual IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
 
   /// \brief Return the smallest integer type with at least the specified width.
-  IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
+  virtual IntType getLeastIntTypeByWidth(unsigned BitWidth,
+                                         bool IsSigned) const;
 
   /// \brief Return floating point type with specified width.
   RealType getRealTypeByWidth(unsigned BitWidth) const;
index 16593b9b224bbd75124ebfb196dd0b7f89da7341..2007f01c2ad0f7d1742e49c9b085fa6898c68d19 100644 (file)
@@ -7069,6 +7069,19 @@ private:
   const char *getClobbers() const final { return ""; }
   bool isCLZForZeroUndef() const final { return false; }
   bool hasInt128Type() const final { return true; }
+  IntType getIntTypeByWidth(unsigned BitWidth,
+                            bool IsSigned) const final {
+    // WebAssembly prefers long long for explicitly 64-bit integers.
+    return BitWidth == 64 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
+                          : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
+  }
+  IntType getLeastIntTypeByWidth(unsigned BitWidth,
+                                 bool IsSigned) const final {
+    // WebAssembly uses long long for int_least64_t and int_fast64_t.
+    return BitWidth == 64
+               ? (IsSigned ? SignedLongLong : UnsignedLongLong)
+               : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
+  }
 };
 
 const Builtin::Info WebAssemblyTargetInfo::BuiltinInfo[] = {
index dcc2ef004703fc778d02bb00d9504aa0dd96ba70..615dd1ca957f7d5d2ea8bb670aef51531fb320ca 100644 (file)
 // WEBASSEMBLY64-NEXT:#define __INT_FAST32_FMTi__ "i"{{$}}
 // WEBASSEMBLY64-NEXT:#define __INT_FAST32_MAX__ 2147483647{{$}}
 // WEBASSEMBLY64-NEXT:#define __INT_FAST32_TYPE__ int{{$}}
-// WEBASSEMBLY64-NEXT:#define __INT_FAST64_FMTd__ "ld"{{$}}
-// WEBASSEMBLY64-NEXT:#define __INT_FAST64_FMTi__ "li"{{$}}
-// WEBASSEMBLY64-NEXT:#define __INT_FAST64_MAX__ 9223372036854775807L{{$}}
-// WEBASSEMBLY64-NEXT:#define __INT_FAST64_TYPE__ long int{{$}}
+// WEBASSEMBLY64-NEXT:#define __INT_FAST64_FMTd__ "lld"{{$}}
+// WEBASSEMBLY64-NEXT:#define __INT_FAST64_FMTi__ "lli"{{$}}
+// WEBASSEMBLY64-NEXT:#define __INT_FAST64_MAX__ 9223372036854775807LL{{$}}
+// WEBASSEMBLY64-NEXT:#define __INT_FAST64_TYPE__ long long int{{$}}
 // WEBASSEMBLY64-NEXT:#define __INT_FAST8_FMTd__ "hhd"{{$}}
 // WEBASSEMBLY64-NEXT:#define __INT_FAST8_FMTi__ "hhi"{{$}}
 // WEBASSEMBLY64-NEXT:#define __INT_FAST8_MAX__ 127{{$}}
 // WEBASSEMBLY64-NEXT:#define __INT_LEAST32_FMTi__ "i"{{$}}
 // WEBASSEMBLY64-NEXT:#define __INT_LEAST32_MAX__ 2147483647{{$}}
 // WEBASSEMBLY64-NEXT:#define __INT_LEAST32_TYPE__ int{{$}}
-// WEBASSEMBLY64-NEXT:#define __INT_LEAST64_FMTd__ "ld"{{$}}
-// WEBASSEMBLY64-NEXT:#define __INT_LEAST64_FMTi__ "li"{{$}}
-// WEBASSEMBLY64-NEXT:#define __INT_LEAST64_MAX__ 9223372036854775807L{{$}}
-// WEBASSEMBLY64-NEXT:#define __INT_LEAST64_TYPE__ long int{{$}}
+// WEBASSEMBLY64-NEXT:#define __INT_LEAST64_FMTd__ "lld"{{$}}
+// WEBASSEMBLY64-NEXT:#define __INT_LEAST64_FMTi__ "lli"{{$}}
+// WEBASSEMBLY64-NEXT:#define __INT_LEAST64_MAX__ 9223372036854775807LL{{$}}
+// WEBASSEMBLY64-NEXT:#define __INT_LEAST64_TYPE__ long long int{{$}}
 // WEBASSEMBLY64-NEXT:#define __INT_LEAST8_FMTd__ "hhd"{{$}}
 // WEBASSEMBLY64-NEXT:#define __INT_LEAST8_FMTi__ "hhi"{{$}}
 // WEBASSEMBLY64-NEXT:#define __INT_LEAST8_MAX__ 127{{$}}
 // WEBASSEMBLY64-NEXT:#define __UINT_FAST32_FMTx__ "x"{{$}}
 // WEBASSEMBLY64-NEXT:#define __UINT_FAST32_MAX__ 4294967295U{{$}}
 // WEBASSEMBLY64-NEXT:#define __UINT_FAST32_TYPE__ unsigned int{{$}}
-// WEBASSEMBLY64-NEXT:#define __UINT_FAST64_FMTX__ "lX"{{$}}
-// WEBASSEMBLY64-NEXT:#define __UINT_FAST64_FMTo__ "lo"{{$}}
-// WEBASSEMBLY64-NEXT:#define __UINT_FAST64_FMTu__ "lu"{{$}}
-// WEBASSEMBLY64-NEXT:#define __UINT_FAST64_FMTx__ "lx"{{$}}
-// WEBASSEMBLY64-NEXT:#define __UINT_FAST64_MAX__ 18446744073709551615UL{{$}}
-// WEBASSEMBLY64-NEXT:#define __UINT_FAST64_TYPE__ long unsigned int{{$}}
+// WEBASSEMBLY64-NEXT:#define __UINT_FAST64_FMTX__ "llX"{{$}}
+// WEBASSEMBLY64-NEXT:#define __UINT_FAST64_FMTo__ "llo"{{$}}
+// WEBASSEMBLY64-NEXT:#define __UINT_FAST64_FMTu__ "llu"{{$}}
+// WEBASSEMBLY64-NEXT:#define __UINT_FAST64_FMTx__ "llx"{{$}}
+// WEBASSEMBLY64-NEXT:#define __UINT_FAST64_MAX__ 18446744073709551615ULL{{$}}
+// WEBASSEMBLY64-NEXT:#define __UINT_FAST64_TYPE__ long long unsigned int{{$}}
 // WEBASSEMBLY64-NEXT:#define __UINT_FAST8_FMTX__ "hhX"{{$}}
 // WEBASSEMBLY64-NEXT:#define __UINT_FAST8_FMTo__ "hho"{{$}}
 // WEBASSEMBLY64-NEXT:#define __UINT_FAST8_FMTu__ "hhu"{{$}}
 // WEBASSEMBLY64-NEXT:#define __UINT_LEAST32_FMTx__ "x"{{$}}
 // WEBASSEMBLY64-NEXT:#define __UINT_LEAST32_MAX__ 4294967295U{{$}}
 // WEBASSEMBLY64-NEXT:#define __UINT_LEAST32_TYPE__ unsigned int{{$}}
-// WEBASSEMBLY64-NEXT:#define __UINT_LEAST64_FMTX__ "lX"{{$}}
-// WEBASSEMBLY64-NEXT:#define __UINT_LEAST64_FMTo__ "lo"{{$}}
-// WEBASSEMBLY64-NEXT:#define __UINT_LEAST64_FMTu__ "lu"{{$}}
-// WEBASSEMBLY64-NEXT:#define __UINT_LEAST64_FMTx__ "lx"{{$}}
-// WEBASSEMBLY64-NEXT:#define __UINT_LEAST64_MAX__ 18446744073709551615UL{{$}}
-// WEBASSEMBLY64-NEXT:#define __UINT_LEAST64_TYPE__ long unsigned int{{$}}
+// WEBASSEMBLY64-NEXT:#define __UINT_LEAST64_FMTX__ "llX"{{$}}
+// WEBASSEMBLY64-NEXT:#define __UINT_LEAST64_FMTo__ "llo"{{$}}
+// WEBASSEMBLY64-NEXT:#define __UINT_LEAST64_FMTu__ "llu"{{$}}
+// WEBASSEMBLY64-NEXT:#define __UINT_LEAST64_FMTx__ "llx"{{$}}
+// WEBASSEMBLY64-NEXT:#define __UINT_LEAST64_MAX__ 18446744073709551615ULL{{$}}
+// WEBASSEMBLY64-NEXT:#define __UINT_LEAST64_TYPE__ long long unsigned int{{$}}
 // WEBASSEMBLY64-NEXT:#define __UINT_LEAST8_FMTX__ "hhX"{{$}}
 // WEBASSEMBLY64-NEXT:#define __UINT_LEAST8_FMTo__ "hho"{{$}}
 // WEBASSEMBLY64-NEXT:#define __UINT_LEAST8_FMTu__ "hhu"{{$}}