From 8c866944dd8066d4cac56df04ea3a88a900af008 Mon Sep 17 00:00:00 2001
From: Pavel Chupin <pavel.v.chupin@intel.com>
Date: Mon, 14 Jul 2014 09:58:10 +0000
Subject: [PATCH] [x32] Add __ILP32__ macro for ILP32 platforms

Summary:
Add __ILP32__ and _ILP32 macro for corresponding platforms.
Cover x86_64-*-*-gnux32 with test.

Test Plan: test added

Reviewers: chandlerc, atanasyan

Subscribers: cfe-commits, dschuff, zinovy.nis

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212931 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Frontend/InitPreprocessor.cpp |   6 ++
 test/Preprocessor/init.c          | 162 ++++++++++++++++++++++++++++++
 2 files changed, 168 insertions(+)

diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp
index 1ce4279df91..e026de21232 100644
--- a/lib/Frontend/InitPreprocessor.cpp
+++ b/lib/Frontend/InitPreprocessor.cpp
@@ -595,6 +595,12 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
     Builder.defineMacro("__LP64__");
   }
 
+  if (TI.getPointerWidth(0) == 32 && TI.getLongWidth() == 32
+      && TI.getIntWidth() == 32) {
+    Builder.defineMacro("_ILP32");
+    Builder.defineMacro("__ILP32__");
+  }
+
   // Define type sizing macros based on the target properties.
   assert(TI.getCharWidth() == 8 && "Only support 8-bit char so far");
   Builder.defineMacro("__CHAR_BIT__", "8");
diff --git a/test/Preprocessor/init.c b/test/Preprocessor/init.c
index 3f15502b807..5d111d31393 100644
--- a/test/Preprocessor/init.c
+++ b/test/Preprocessor/init.c
@@ -5086,6 +5086,7 @@
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=x86_64-none-none < /dev/null | FileCheck -check-prefix X86_64 %s
 //
 // X86_64:#define _LP64 1
+// X86_64-NOT:#define _LP32 1
 // X86_64:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
 // X86_64:#define __CHAR16_TYPE__ unsigned short
 // X86_64:#define __CHAR32_TYPE__ unsigned int
@@ -5168,6 +5169,7 @@
 // X86_64:#define __LONG_LONG_MAX__ 9223372036854775807LL
 // X86_64:#define __LONG_MAX__ 9223372036854775807L
 // X86_64:#define __LP64__ 1
+// X86_64-NOT:#define __ILP32__ 1
 // X86_64:#define __MMX__ 1
 // X86_64:#define __NO_MATH_INLINES 1
 // X86_64:#define __POINTER_WIDTH__ 64
@@ -5241,6 +5243,166 @@
 // X86_64:#define __x86_64 1
 // X86_64:#define __x86_64__ 1
 //
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=x86_64-none-none-gnux32 < /dev/null | FileCheck -check-prefix X32 %s
+//
+// X32:#define _ILP32 1
+// X32-NOT:#define _LP64 1
+// X32:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
+// X32:#define __CHAR16_TYPE__ unsigned short
+// X32:#define __CHAR32_TYPE__ unsigned int
+// X32:#define __CHAR_BIT__ 8
+// X32:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324
+// X32:#define __DBL_DIG__ 15
+// X32:#define __DBL_EPSILON__ 2.2204460492503131e-16
+// X32:#define __DBL_HAS_DENORM__ 1
+// X32:#define __DBL_HAS_INFINITY__ 1
+// X32:#define __DBL_HAS_QUIET_NAN__ 1
+// X32:#define __DBL_MANT_DIG__ 53
+// X32:#define __DBL_MAX_10_EXP__ 308
+// X32:#define __DBL_MAX_EXP__ 1024
+// X32:#define __DBL_MAX__ 1.7976931348623157e+308
+// X32:#define __DBL_MIN_10_EXP__ (-307)
+// X32:#define __DBL_MIN_EXP__ (-1021)
+// X32:#define __DBL_MIN__ 2.2250738585072014e-308
+// X32:#define __DECIMAL_DIG__ 21
+// X32:#define __FLT_DENORM_MIN__ 1.40129846e-45F
+// X32:#define __FLT_DIG__ 6
+// X32:#define __FLT_EPSILON__ 1.19209290e-7F
+// X32:#define __FLT_EVAL_METHOD__ 0
+// X32:#define __FLT_HAS_DENORM__ 1
+// X32:#define __FLT_HAS_INFINITY__ 1
+// X32:#define __FLT_HAS_QUIET_NAN__ 1
+// X32:#define __FLT_MANT_DIG__ 24
+// X32:#define __FLT_MAX_10_EXP__ 38
+// X32:#define __FLT_MAX_EXP__ 128
+// X32:#define __FLT_MAX__ 3.40282347e+38F
+// X32:#define __FLT_MIN_10_EXP__ (-37)
+// X32:#define __FLT_MIN_EXP__ (-125)
+// X32:#define __FLT_MIN__ 1.17549435e-38F
+// X32:#define __FLT_RADIX__ 2
+// X32:#define __ILP32__ 1
+// X32-NOT:#define __LP64__ 1
+// X32:#define __INT16_MAX__ 32767
+// X32:#define __INT16_TYPE__ short
+// X32:#define __INT32_MAX__ 2147483647
+// X32:#define __INT32_TYPE__ int
+// X32:#define __INT64_C_SUFFIX__ L
+// X32:#define __INT64_MAX__ 9223372036854775807L
+// X32:#define __INT64_TYPE__ long long int
+// X32:#define __INT8_MAX__ 127
+// X32:#define __INT8_TYPE__ char
+// X32:#define __INTMAX_MAX__ 9223372036854775807L
+// X32:#define __INTMAX_TYPE__ long long int
+// X32:#define __INTMAX_WIDTH__ 64
+// X32:#define __INTPTR_MAX__ 2147483647
+// X32:#define __INTPTR_TYPE__ int
+// X32:#define __INTPTR_WIDTH__ 32
+// X32:#define __INT_FAST16_MAX__ 32767
+// X32:#define __INT_FAST16_TYPE__ short
+// X32:#define __INT_FAST32_MAX__ 2147483647
+// X32:#define __INT_FAST32_TYPE__ int
+// X32:#define __INT_FAST64_MAX__ 9223372036854775807L
+// X32:#define __INT_FAST64_TYPE__ long long int
+// X32:#define __INT_FAST8_MAX__ 127
+// X32:#define __INT_FAST8_TYPE__ char
+// X32:#define __INT_LEAST16_MAX__ 32767
+// X32:#define __INT_LEAST16_TYPE__ short
+// X32:#define __INT_LEAST32_MAX__ 2147483647
+// X32:#define __INT_LEAST32_TYPE__ int
+// X32:#define __INT_LEAST64_MAX__ 9223372036854775807L
+// X32:#define __INT_LEAST64_TYPE__ long long int
+// X32:#define __INT_LEAST8_MAX__ 127
+// X32:#define __INT_LEAST8_TYPE__ char
+// X32:#define __INT_MAX__ 2147483647
+// X32:#define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L
+// X32:#define __LDBL_DIG__ 18
+// X32:#define __LDBL_EPSILON__ 1.08420217248550443401e-19L
+// X32:#define __LDBL_HAS_DENORM__ 1
+// X32:#define __LDBL_HAS_INFINITY__ 1
+// X32:#define __LDBL_HAS_QUIET_NAN__ 1
+// X32:#define __LDBL_MANT_DIG__ 64
+// X32:#define __LDBL_MAX_10_EXP__ 4932
+// X32:#define __LDBL_MAX_EXP__ 16384
+// X32:#define __LDBL_MAX__ 1.18973149535723176502e+4932L
+// X32:#define __LDBL_MIN_10_EXP__ (-4931)
+// X32:#define __LDBL_MIN_EXP__ (-16381)
+// X32:#define __LDBL_MIN__ 3.36210314311209350626e-4932L
+// X32:#define __LITTLE_ENDIAN__ 1
+// X32:#define __LONG_LONG_MAX__ 9223372036854775807LL
+// X32:#define __LONG_MAX__ 2147483647L
+// X32:#define __MMX__ 1
+// X32:#define __NO_MATH_INLINES 1
+// X32:#define __POINTER_WIDTH__ 32
+// X32:#define __PTRDIFF_TYPE__ int
+// X32:#define __PTRDIFF_WIDTH__ 32
+// X32:#define __REGISTER_PREFIX__ 
+// X32:#define __SCHAR_MAX__ 127
+// X32:#define __SHRT_MAX__ 32767
+// X32:#define __SIG_ATOMIC_WIDTH__ 32
+// X32:#define __SIZEOF_DOUBLE__ 8
+// X32:#define __SIZEOF_FLOAT__ 4
+// X32:#define __SIZEOF_INT__ 4
+// X32:#define __SIZEOF_LONG_DOUBLE__ 16
+// X32:#define __SIZEOF_LONG_LONG__ 8
+// X32:#define __SIZEOF_LONG__ 4
+// X32:#define __SIZEOF_POINTER__ 4
+// X32:#define __SIZEOF_PTRDIFF_T__ 4
+// X32:#define __SIZEOF_SHORT__ 2
+// X32:#define __SIZEOF_SIZE_T__ 4
+// X32:#define __SIZEOF_WCHAR_T__ 4
+// X32:#define __SIZEOF_WINT_T__ 4
+// X32:#define __SIZE_MAX__ 4294967295U
+// X32:#define __SIZE_TYPE__ unsigned int
+// X32:#define __SIZE_WIDTH__ 32
+// X32:#define __SSE2_MATH__ 1
+// X32:#define __SSE2__ 1
+// X32:#define __SSE_MATH__ 1
+// X32:#define __SSE__ 1
+// X32:#define __UINT16_C_SUFFIX__ U
+// X32:#define __UINT16_MAX__ 65535U
+// X32:#define __UINT16_TYPE__ unsigned short
+// X32:#define __UINT32_C_SUFFIX__ U
+// X32:#define __UINT32_MAX__ 4294967295U
+// X32:#define __UINT32_TYPE__ unsigned int
+// X32:#define __UINT64_C_SUFFIX__ UL
+// X32:#define __UINT64_MAX__ 18446744073709551615ULL
+// X32:#define __UINT64_TYPE__ long long unsigned int
+// X32:#define __UINT8_C_SUFFIX__ U
+// X32:#define __UINT8_MAX__ 255U
+// X32:#define __UINT8_TYPE__ unsigned char
+// X32:#define __UINTMAX_MAX__ 18446744073709551615ULL
+// X32:#define __UINTMAX_TYPE__ long long unsigned int
+// X32:#define __UINTMAX_WIDTH__ 64
+// X32:#define __UINTPTR_MAX__ 4294967295U
+// X32:#define __UINTPTR_TYPE__ unsigned int
+// X32:#define __UINTPTR_WIDTH__ 32
+// X32:#define __UINT_FAST16_MAX__ 65535U
+// X32:#define __UINT_FAST16_TYPE__ unsigned short
+// X32:#define __UINT_FAST32_MAX__ 4294967295U
+// X32:#define __UINT_FAST32_TYPE__ unsigned int
+// X32:#define __UINT_FAST64_MAX__ 18446744073709551615ULL
+// X32:#define __UINT_FAST64_TYPE__ long long unsigned int
+// X32:#define __UINT_FAST8_MAX__ 255U
+// X32:#define __UINT_FAST8_TYPE__ unsigned char
+// X32:#define __UINT_LEAST16_MAX__ 65535U
+// X32:#define __UINT_LEAST16_TYPE__ unsigned short
+// X32:#define __UINT_LEAST32_MAX__ 4294967295U
+// X32:#define __UINT_LEAST32_TYPE__ unsigned int
+// X32:#define __UINT_LEAST64_MAX__ 18446744073709551615ULL
+// X32:#define __UINT_LEAST64_TYPE__ long long unsigned int
+// X32:#define __UINT_LEAST8_MAX__ 255U
+// X32:#define __UINT_LEAST8_TYPE__ unsigned char
+// X32:#define __USER_LABEL_PREFIX__ _
+// X32:#define __WCHAR_MAX__ 2147483647
+// X32:#define __WCHAR_TYPE__ int
+// X32:#define __WCHAR_WIDTH__ 32
+// X32:#define __WINT_TYPE__ int
+// X32:#define __WINT_WIDTH__ 32
+// X32:#define __amd64 1
+// X32:#define __amd64__ 1
+// X32:#define __x86_64 1
+// X32:#define __x86_64__ 1
+//
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=x86_64-pc-linux-gnu < /dev/null | FileCheck -check-prefix X86_64-LINUX %s
 //
 // X86_64-LINUX:#define _LP64 1
-- 
GitLab