[PATCH] D56318: [HIP] Fix size_t for MSVC environment

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 4 06:50:43 PST 2019


yaxunl created this revision.
yaxunl added reviewers: tra, rjmccall.
Herald added subscribers: tpr, nhaehnle, jvesely.

In 64 bit MSVC environment size_t is defined as unsigned long long. Fix AMDGPU target info to match it in MSVC environment.


https://reviews.llvm.org/D56318

Files:
  lib/Basic/Targets/AMDGPU.cpp
  lib/Driver/Driver.cpp
  test/SemaCUDA/amdgpu-size_t.cu


Index: test/SemaCUDA/amdgpu-size_t.cu
===================================================================
--- /dev/null
+++ test/SemaCUDA/amdgpu-size_t.cu
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa-msvc -fms-compatibility -fcuda-is-device -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+typedef unsigned __int64 size_t;
+typedef __int64 intptr_t;
+typedef unsigned __int64 uintptr_t;
+
Index: lib/Driver/Driver.cpp
===================================================================
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -614,7 +614,11 @@
     StringRef DeviceTripleStr;
     auto OFK = Action::OFK_HIP;
     DeviceTripleStr = "amdgcn-amd-amdhsa";
-    llvm::Triple HIPTriple(DeviceTripleStr);
+    StringRef Env;
+    if (HostTriple.getEnvironment() == llvm::Triple::MSVC)
+      Env = HostTriple.getEnvironmentName();
+    llvm::Triple HIPTriple(Env.empty() ? Twine(DeviceTripleStr) :
+        DeviceTripleStr + "-" + Env);
     // Use the HIP and host triples as the key into the ToolChains map,
     // because the device toolchain we create depends on both.
     auto &HIPTC = ToolChains[HIPTriple.str() + "/" + HostTriple.str()];
Index: lib/Basic/Targets/AMDGPU.cpp
===================================================================
--- lib/Basic/Targets/AMDGPU.cpp
+++ lib/Basic/Targets/AMDGPU.cpp
@@ -254,9 +254,15 @@
   PointerWidth = PointerAlign = DataLayout->getPointerSizeInBits();
   if (getMaxPointerWidth() == 64) {
     LongWidth = LongAlign = 64;
-    SizeType = UnsignedLong;
-    PtrDiffType = SignedLong;
-    IntPtrType = SignedLong;
+    if (Triple.getEnvironment() == llvm::Triple::MSVC) {
+      SizeType = UnsignedLongLong;
+      PtrDiffType = SignedLongLong;
+      IntPtrType = SignedLongLong;
+    } else {
+      SizeType = UnsignedLong;
+      PtrDiffType = SignedLong;
+      IntPtrType = SignedLong;
+    }
   }
 
   MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56318.180241.patch
Type: text/x-patch
Size: 1947 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190104/0fc11a28/attachment.bin>


More information about the cfe-commits mailing list