r239046 - [SPARC] Fix types of size_t, intptr_t, and ptrdiff_t on Linux.

James Y Knight jyknight at google.com
Thu Jun 4 08:36:29 PDT 2015


Author: jyknight
Date: Thu Jun  4 10:36:29 2015
New Revision: 239046

URL: http://llvm.org/viewvc/llvm-project?rev=239046&view=rev
Log:
[SPARC] Fix types of size_t, intptr_t, and ptrdiff_t on Linux.

They should be 'int' instead of 'long int' everywhere else except
NetBSD too, from what I gather in GCC's spec files. So, optimistically
changing it for everyone else, too.

Modified:
    cfe/trunk/lib/Basic/Targets.cpp
    cfe/trunk/test/Preprocessor/init.c

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=239046&r1=239045&r2=239046&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Thu Jun  4 10:36:29 2015
@@ -5501,6 +5501,16 @@ class SparcV8TargetInfo : public SparcTa
 public:
   SparcV8TargetInfo(const llvm::Triple &Triple) : SparcTargetInfo(Triple) {
     DescriptionString = "E-m:e-p:32:32-i64:64-f128:64-n32-S64";
+    // NetBSD uses long (same as llvm default); everyone else uses int.
+    if (getTriple().getOS() == llvm::Triple::NetBSD) {
+      SizeType = UnsignedLong;
+      IntPtrType = SignedLong;
+      PtrDiffType = SignedLong;
+    } else {
+      SizeType = UnsignedInt;
+      IntPtrType = SignedInt;
+      PtrDiffType = SignedInt;
+    }
   }
 
   void getTargetDefines(const LangOptions &Opts,
@@ -5573,15 +5583,6 @@ public:
   }
 };
 
-class SolarisSparcV8TargetInfo : public SolarisTargetInfo<SparcV8TargetInfo> {
-public:
-  SolarisSparcV8TargetInfo(const llvm::Triple &Triple)
-      : SolarisTargetInfo<SparcV8TargetInfo>(Triple) {
-    SizeType = UnsignedInt;
-    PtrDiffType = SignedInt;
-  }
-};
-
 class SystemZTargetInfo : public TargetInfo {
   static const Builtin::Info BuiltinInfo[];
   static const char *const GCCRegNames[];
@@ -7023,7 +7024,7 @@ static TargetInfo *AllocateTarget(const
     case llvm::Triple::Linux:
       return new LinuxTargetInfo<SparcV8TargetInfo>(Triple);
     case llvm::Triple::Solaris:
-      return new SolarisSparcV8TargetInfo(Triple);
+      return new SolarisTargetInfo<SparcV8TargetInfo>(Triple);
     case llvm::Triple::NetBSD:
       return new NetBSDTargetInfo<SparcV8TargetInfo>(Triple);
     case llvm::Triple::OpenBSD:

Modified: cfe/trunk/test/Preprocessor/init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=239046&r1=239045&r2=239046&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/init.c (original)
+++ cfe/trunk/test/Preprocessor/init.c Thu Jun  4 10:36:29 2015
@@ -6851,10 +6851,10 @@
 // SPARC:#define __INTMAX_MAX__ 9223372036854775807LL
 // SPARC:#define __INTMAX_TYPE__ long long int
 // SPARC:#define __INTMAX_WIDTH__ 64
-// SPARC:#define __INTPTR_FMTd__ "ld"
-// SPARC:#define __INTPTR_FMTi__ "li"
-// SPARC:#define __INTPTR_MAX__ 2147483647L
-// SPARC:#define __INTPTR_TYPE__ long int
+// SPARC:#define __INTPTR_FMTd__ "d"
+// SPARC:#define __INTPTR_FMTi__ "i"
+// SPARC:#define __INTPTR_MAX__ 2147483647
+// SPARC:#define __INTPTR_TYPE__ int
 // SPARC:#define __INTPTR_WIDTH__ 32
 // SPARC:#define __INT_FAST16_FMTd__ "hd"
 // SPARC:#define __INT_FAST16_FMTi__ "hi"
@@ -6906,7 +6906,7 @@
 // SPARC:#define __LONG_MAX__ 2147483647L
 // SPARC-NOT:#define __LP64__
 // SPARC:#define __POINTER_WIDTH__ 32
-// SPARC:#define __PTRDIFF_TYPE__ long int
+// SPARC:#define __PTRDIFF_TYPE__ int
 // SPARC:#define __PTRDIFF_WIDTH__ 32
 // SPARC:#define __REGISTER_PREFIX__
 // SPARC:#define __SCHAR_MAX__ 127
@@ -6926,7 +6926,7 @@
 // SPARC:#define __SIZEOF_WCHAR_T__ 4
 // SPARC:#define __SIZEOF_WINT_T__ 4
 // SPARC:#define __SIZE_MAX__ 4294967295U
-// SPARC:#define __SIZE_TYPE__ long unsigned int
+// SPARC:#define __SIZE_TYPE__ unsigned int
 // SPARC:#define __SIZE_WIDTH__ 32
 // SPARC:#define __UINT16_C_SUFFIX__ {{$}}
 // SPARC:#define __UINT16_MAX__ 65535
@@ -6945,7 +6945,7 @@
 // SPARC:#define __UINTMAX_TYPE__ long long unsigned int
 // SPARC:#define __UINTMAX_WIDTH__ 64
 // SPARC:#define __UINTPTR_MAX__ 4294967295U
-// SPARC:#define __UINTPTR_TYPE__ long unsigned int
+// SPARC:#define __UINTPTR_TYPE__ unsigned int
 // SPARC:#define __UINTPTR_WIDTH__ 32
 // SPARC:#define __UINT_FAST16_MAX__ 65535
 // SPARC:#define __UINT_FAST16_TYPE__ unsigned short
@@ -6975,6 +6975,15 @@
 // SPARC:#define __sparcv8 1
 // SPARC:#define sparc 1
 // 
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=sparc-none-netbsd < /dev/null | FileCheck -check-prefix SPARC-NETBSD %s
+// SPARC-NETBSD:#define __INTPTR_FMTd__ "ld"
+// SPARC-NETBSD:#define __INTPTR_FMTi__ "li"
+// SPARC-NETBSD:#define __INTPTR_MAX__ 2147483647L
+// SPARC-NETBSD:#define __INTPTR_TYPE__ long int
+// SPARC-NETBSD:#define __PTRDIFF_TYPE__ long int
+// SPARC-NETBSD:#define __SIZE_TYPE__ long unsigned int
+// SPARC-NETBSD:#define __UINTPTR_TYPE__ long unsigned int
+
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=tce-none-none < /dev/null | FileCheck -check-prefix TCE %s
 //
 // TCE-NOT:#define _LP64





More information about the cfe-commits mailing list