On Wed, Jun 25, 2014 at 02:57:39PM -0700, Matt Arsenault wrote:
> On 06/25/2014 02:10 PM, Tom Stellard wrote:
> > Hi Reid,
> >
> > Here is an updated patch with a Sema test.
> >
> > -Tom
> >
> > On Wed, Jun 25, 2014 at 04:31:52PM -0400, Tom Stellard wrote:
> >> ---
> >>   include/clang/Basic/TargetInfo.h            |  4 +---
> >>   lib/Basic/TargetInfo.cpp                    |  9 +++++++++
> >>   test/CodeGen/record-lowering-non-zero-as.cl | 14 ++++++++++++++
> >>   3 files changed, 24 insertions(+), 3 deletions(-)
> >>   create mode 100644 test/CodeGen/record-lowering-non-zero-as.cl
> >>
> >> diff --git a/include/clang/Basic/TargetInfo.h 
> >> b/include/clang/Basic/TargetInfo.h
> >> index e1d0116..65dc101 100644
> >> --- a/include/clang/Basic/TargetInfo.h
> >> +++ b/include/clang/Basic/TargetInfo.h
> >> @@ -790,9 +790,7 @@ public:
> >>     }
> >>   
> >>   protected:
> >> -  virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
> >> -    return PointerWidth;
> >> -  }
> >> +  virtual uint64_t getPointerWidthV(unsigned AddrSpace) const;
> >>     virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
> >>       return PointerAlign;
> >>     }
> >> diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp
> >> index 71e39dd..d0f6306 100644
> >> --- a/lib/Basic/TargetInfo.cpp
> >> +++ b/lib/Basic/TargetInfo.cpp
> >> @@ -17,6 +17,7 @@
> >>   #include "clang/Basic/LangOptions.h"
> >>   #include "llvm/ADT/APFloat.h"
> >>   #include "llvm/ADT/STLExtras.h"
> >> +#include "llvm/IR/DataLayout.h"
> >>   #include "llvm/Support/ErrorHandling.h"
> >>   #include <cstdlib>
> >>   using namespace clang;
> >> @@ -242,6 +243,14 @@ bool TargetInfo::isTypeSigned(IntType T) {
> >>     };
> >>   }
> >>   
> >> +uint64_t TargetInfo::getPointerWidthV(unsigned AddrSpace) const {
> >> +  if (!DescriptionString)
> >> +    return PointerWidth;
> >> +
> >> +  llvm::DataLayout DL(DescriptionString);
> >> +  return DL.getPointerSizeInBits(AddrSpace);
> >> +}
> 
> Can you do this without reparsing the datalayout string every time this 
> is used?
>

I wasn't able to find a good way to cache the DataLayout, so I just
implemented this for R600.  (See attached patch).  I also drop the
requires from the test.

-Tom

> >> +
> >>   /// setForcedLangOptions - Set forced language options.
> >>   /// Apply changes to the target information with respect to certain
> >>   /// language options which change the target configuration.
> >> diff --git a/test/CodeGen/record-lowering-non-zero-as.cl 
> >> b/test/CodeGen/record-lowering-non-zero-as.cl
> >> new file mode 100644
> >> index 0000000..a96756f
> >> --- /dev/null
> >> +++ b/test/CodeGen/record-lowering-non-zero-as.cl
> >> @@ -0,0 +1,14 @@
> >> +// REQUIRES: r600-registered-target
> >> +// RUN: %clang -target r600 -mcpu=verde -S -emit-llvm -o - %s
> >> +
> >> +// Record lowering was crashing on SI and newer targets, because it
> >> +// was using the wrong size for test::ptr.  Since global memory
> >> +// has 64-bit pointers, sizeof(test::ptr) should be 8.
> >> +
> >> +struct test {
> >> +  global int *ptr;
> >> +};
> >> +
> >> +void func(struct test t, global int *ptr) {
> >> +  *ptr = 0;
> >> +}
> >> -- 
> >> 1.8.1.5
> >>
> >> _______________________________________________
> >> cfe-commits mailing list
> >> [email protected]
> >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> >>
> >>
> >> _______________________________________________
> >> cfe-commits mailing list
> >> [email protected]
> >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> 
>From 78a16a5446a9677d460bc7dd47495dc4108560b1 Mon Sep 17 00:00:00 2001
From: Tom Stellard <[email protected]>
Date: Wed, 25 Jun 2014 16:27:09 -0400
Subject: [PATCH] R600: Implement getPointerWidthV()

This fixes a crash in the OCL_ImgProc/Canny OpenCV test.

NOTE: This is a candidate for the 3.5 branch.
---
 lib/Basic/Targets.cpp                         | 17 +++++++++++++++++
 test/Sema/sizeof-struct-non-zero-as-member.cl | 18 ++++++++++++++++++
 2 files changed, 35 insertions(+)
 create mode 100644 test/Sema/sizeof-struct-non-zero-as-member.cl

diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp
index fe72fe1..0c57542 100644
--- a/lib/Basic/Targets.cpp
+++ b/lib/Basic/Targets.cpp
@@ -1456,6 +1456,9 @@ static const unsigned R600AddrSpaceMap[] = {
   3     // cuda_shared
 };
 
+// If you edit the description strings, make sure you update
+// getPointerWidthV().
+
 static const char *DescriptionStringR600 =
   "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128"
   "-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64";
@@ -1495,6 +1498,20 @@ public:
     UseAddrSpaceMapMangling = true;
   }
 
+  uint64_t getPointerWidthV(unsigned AddrSpace) const override {
+    if (GPU <= GK_CAYMAN)
+      return 32;
+
+    switch(AddrSpace) {
+      default:
+        return 64;
+      case 0:
+      case 3:
+      case 5:
+        return 32;
+    }
+  }
+
   const char * getClobbers() const override {
     return "";
   }
diff --git a/test/Sema/sizeof-struct-non-zero-as-member.cl b/test/Sema/sizeof-struct-non-zero-as-member.cl
new file mode 100644
index 0000000..b64c036
--- /dev/null
+++ b/test/Sema/sizeof-struct-non-zero-as-member.cl
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -triple r600 -target-cpu verde -S -emit-llvm -o - %s
+// expected-no-diagnostics
+
+// Record lowering was crashing on SI and newer targets, because it
+// was using the wrong size for test::ptr.  Since global memory
+// has 64-bit pointers, sizeof(test::ptr) should be 8.
+
+struct test_as0 {int *ptr;};
+constant int as0[sizeof(struct test_as0) == 4 ? 1 : -1] = { 0 };
+
+struct test_as1 {global int *ptr;};
+constant int as1[sizeof(struct test_as1) == 8 ? 1 : -1] = { 0 };
+
+struct test_as2 {constant int *ptr;};
+constant int as2[sizeof(struct test_as2) == 8 ? 1 : -1] = { 0 };
+
+struct test_as3 {local int *ptr;};
+constant int as3[sizeof(struct test_as3) == 4 ? 1 : -1] = { 0 };
-- 
1.8.1.5

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to