[PATCH] D39321: ARM: centralise SizeType, PtrDiffType, and IntPtrType

Saleem Abdulrasool via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 25 22:56:26 PDT 2017


compnerd created this revision.
compnerd added a project: clang.
Herald added subscribers: kristof.beyls, javed.absar, aemerson.

Centralise the definitions of these compiler vended types to aid
inspection to ensure that they are defined similarly.  The one case that
stands out is the Darwin case where the types do not match up.  This
fixes the API conformance for APCS-GNU as well.


Repository:
  rL LLVM

https://reviews.llvm.org/D39321

Files:
  lib/Basic/Targets/ARM.cpp
  test/Preprocessor/init.c


Index: test/Preprocessor/init.c
===================================================================
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -1791,6 +1791,11 @@
 // ARM:#define __arm 1
 // ARM:#define __arm__ 1

+// RUN: %clang_cc1 -dM -ffreestanding -triple arm-none-none -target-abi apcs-gnu -E /dev/null -o - | FileCheck -match-full-lines -check-prefix ARM-APCS-GNU %s
+// ARM-APCS-GNU: #define __INTPTR_TYPE__ int
+// ARM-APCS-GNU: #define __PTRDIFF_TYPE__ int
+// ARM-APCS-GNU: #define __SIZE_TYPE__ unsigned int
+
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=armeb-none-none < /dev/null | FileCheck -match-full-lines -check-prefix ARM-BE %s
 //
 // ARM-BE-NOT:#define _LP64
Index: lib/Basic/Targets/ARM.cpp
===================================================================
--- lib/Basic/Targets/ARM.cpp
+++ lib/Basic/Targets/ARM.cpp
@@ -28,14 +28,6 @@
   DoubleAlign = LongLongAlign = LongDoubleAlign = SuitableAlign = 64;
   const llvm::Triple &T = getTriple();

-  // size_t is unsigned long on MachO-derived environments, NetBSD, and
-  // OpenBSD.
-  if (T.isOSBinFormatMachO() || T.getOS() == llvm::Triple::NetBSD ||
-      T.getOS() == llvm::Triple::OpenBSD)
-    SizeType = UnsignedLong;
-  else
-    SizeType = UnsignedInt;
-
   bool IsNetBSD = T.getOS() == llvm::Triple::NetBSD;
   bool IsOpenBSD = T.getOS() == llvm::Triple::OpenBSD;
   if (!T.isOSWindows() && !IsNetBSD && !IsOpenBSD)
@@ -83,12 +75,6 @@
   else
     DoubleAlign = LongLongAlign = LongDoubleAlign = SuitableAlign = 32;

-  // size_t is unsigned int on FreeBSD.
-  if (T.getOS() == llvm::Triple::FreeBSD)
-    SizeType = UnsignedInt;
-  else
-    SizeType = UnsignedLong;
-
   WCharType = SignedInt;

   // Do not respect the alignment of bit-field types when laying out
@@ -225,22 +211,23 @@
                              const TargetOptions &Opts)
     : TargetInfo(Triple), FPMath(FP_Default), IsAAPCS(true), LDREX(0),
       HW_FP(0) {
-
-  switch (getTriple().getOS()) {
-  case llvm::Triple::NetBSD:
-  case llvm::Triple::OpenBSD:
-    PtrDiffType = SignedLong;
-    break;
-  default:
-    PtrDiffType = SignedInt;
-    break;
-  }
-
   bool IsOpenBSD = Triple.getOS() == llvm::Triple::OpenBSD;
   bool IsNetBSD = Triple.getOS() == llvm::Triple::NetBSD;
-  IntPtrType =
+
+  PtrDiffType = IntPtrType =
       (Triple.isOSDarwin() || IsOpenBSD || IsNetBSD) ? SignedLong : SignedInt;

+  // FIXME: the isOSBinFormatMachO is a workaround for identifying a Darwin-like
+  // environment where size_t is `unsigned long` rather than `unsigned int`
+  SizeType = (Triple.isOSDarwin() || Triple.isOSBinFormatMachO() || IsOpenBSD ||
+              IsNetBSD)
+                 ? UnsignedLong
+                 : UnsignedInt;
+
+  // ptrdiff_t is inconsistent on Darwin
+  if (Triple.isOSDarwin())
+    PtrDiffType = SignedInt;
+
   // Cache arch related info.
   setArchInfo();



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39321.120364.patch
Type: text/x-patch
Size: 2885 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171026/8310999c/attachment.bin>


More information about the cfe-commits mailing list