[PATCH] D38857: [OpenCL] Improve printing and semantic check related to implicit addr space

2017-10-23 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: include/clang/AST/Type.h:337
+Mask = (Mask & ~ImplicitAddrSpaceMask) |
+   (((uint32_t)Value) << ImplicitAddrSpaceShift);
+  }

This is probably cleaner as:

  Mask = (Value ? (Mask | ImplicitAddrSpaceMask) : (Mask & 
~ImplicitAddrSpaceMask));



Comment at: lib/AST/ASTContext.cpp:2290
+  if (CanT.getAddressSpace() == AddressSpace &&
+  CanT.getQualifiers().isAddressSpaceImplicit() == ImplicitFlag)
 return T;

It looks like your changes here are making implicitness part of the canonical 
type, which is wrong, because implicitly- and explicitly-qualified types are 
not actually different types.

That is fixable, but I'm going to ask you to investigate whether you can solve 
this problem with AttributedType before you introduce this complexity into the 
qualifier system.


https://reviews.llvm.org/D38857



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38857: [OpenCL] Improve printing and semantic check related to implicit addr space

2017-10-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added a comment.

In https://reviews.llvm.org/D38857#896994, @Anastasia wrote:

> LGTM! Thanks!
>
> Can we close https://bugs.llvm.org/show_bug.cgi?id=33418 after this commit?


Will do.




Comment at: test/SemaOpenCL/null_literal.cl:38
 
-#ifdef CL20
-// Accept explicitly pointer to generic address space in OpenCL v2.0.
-global int* ptr5 = (generic void*)0;
-#endif
-
-global int* ptr6 = (local void*)0; // expected-error{{initializing '__global 
int *' with an expression of type '__local void *' changes address space of 
pointer}}
+  global int *g7 = (global void*)(generic void *)0;
+  constant int *c7 = (constant void*)(generic void *)0; 
//expected-error{{casting '__generic void *' to type '__constant void *' 
changes address space of pointer}}

Anastasia wrote:
> Does this extra cast test anything we already miss to test?
Yes. It tests a generic pointer of zero value can be explicitly casted to a 
global pointer. This should be true for any generic pointer, however since 
pointers with zero value have special handling, we want to make sure this still 
works.


https://reviews.llvm.org/D38857



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38857: [OpenCL] Improve printing and semantic check related to implicit addr space

2017-10-13 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks!

Can we close https://bugs.llvm.org/show_bug.cgi?id=33418 after this commit?




Comment at: test/SemaOpenCL/null_literal.cl:38
 
-#ifdef CL20
-// Accept explicitly pointer to generic address space in OpenCL v2.0.
-global int* ptr5 = (generic void*)0;
-#endif
-
-global int* ptr6 = (local void*)0; // expected-error{{initializing '__global 
int *' with an expression of type '__local void *' changes address space of 
pointer}}
+  global int *g7 = (global void*)(generic void *)0;
+  constant int *c7 = (constant void*)(generic void *)0; 
//expected-error{{casting '__generic void *' to type '__constant void *' 
changes address space of pointer}}

Does this extra cast test anything we already miss to test?


https://reviews.llvm.org/D38857



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38857: [OpenCL] Improve printing and semantic check related to implicit addr space

2017-10-12 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.

There are two issues:

1. only (void*)0 should be treated as nullptr

2. only explicit addr space should be printed

This patch introduces a flag in Qualifier to indicating a non-default address 
space qualifier is deduced by context. Only
non-implicit address space qualifier will be print out when printing AST. It is 
also used to identify nullptr.

However this review does not rule out alternative approaches, e.g. using 
AttributedType. We will explore alternative approaches.


https://reviews.llvm.org/D38857

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Type.h
  lib/AST/ASTContext.cpp
  lib/AST/Expr.cpp
  lib/AST/TypePrinter.cpp
  lib/Sema/SemaType.cpp
  test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
  test/SemaOpenCL/address-spaces.cl
  test/SemaOpenCL/atomic-ops.cl
  test/SemaOpenCL/invalid-block.cl
  test/SemaOpenCL/invalid-pipes-cl2.0.cl
  test/SemaOpenCL/null_literal.cl
  test/SemaOpenCL/vector_conv_invalid.cl
  test/SemaTemplate/address_space-dependent.cpp

Index: test/SemaTemplate/address_space-dependent.cpp
===
--- test/SemaTemplate/address_space-dependent.cpp
+++ test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388598)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (4194294)}}
 }
 
 template 
@@ -101,7 +101,7 @@
   car<1, 2, 3>(); // expected-note {{in instantiation of function template specialization 'car<1, 2, 3>' requested here}}
   HasASTemplateFields<1> HASTF;
   neg<-1>(); // expected-note {{in instantiation of function template specialization 'neg<-1>' requested here}}
-  correct<0x76>();
+  correct<0x36>();
   tooBig<8388650>(); // expected-note {{in instantiation of function template specialization 'tooBig<8388650>' requested here}}
 
   __attribute__((address_space(1))) char *x;
Index: test/SemaOpenCL/vector_conv_invalid.cl
===
--- test/SemaOpenCL/vector_conv_invalid.cl
+++ test/SemaOpenCL/vector_conv_invalid.cl
@@ -16,7 +16,7 @@
   e = (constant int4)i;
   e = (private int4)i;
 
-  private int4 *private_ptr = (const private int4 *)const_global_ptr; // expected-error{{casting 'const __global int4 *' to type 'const int4 *' changes address space of pointer}}
+  private int4 *private_ptr = (const private int4 *)const_global_ptr; // expected-error{{casting 'const __global int4 *' to type 'const __private int4 *' changes address space of pointer}}
   global int4 *global_ptr = const_global_ptr; // expected-warning {{initializing '__global int4 *' with an expression of type 'const __global int4 *' discards qualifiers}}
   global_ptr = (global int4 *)const_global_ptr;
 }
Index: test/SemaOpenCL/null_literal.cl
===
--- test/SemaOpenCL/null_literal.cl
+++ test/SemaOpenCL/null_literal.cl
@@ -1,29 +1,68 @@
 // RUN: %clang_cc1 -verify %s
-// RUN: %clang_cc1 -cl-std=CL2.0 -DCL20 -verify %s
+// RUN: %clang_cc1 -cl-std=CL2.0 -verify %s
 
 #define NULL ((void*)0)
 
 void foo(){
+  global int *g1 = NULL;
+  global int *g2 = (global void *)0;
+  global int *g3 = (constant void *)0; // expected-error{{initializing '__global int *' with an expression of type '__constant void *' changes address space of pointer}}
+  global int *g4 = (local void *)0; // expected-error{{initializing '__global int *' with an expression of type '__local void *' changes address space of pointer}}
+  global int *g5 = (private void *)0; // expected-error{{initializing '__global int *' with an expression of type '__private void *' changes address space of pointer}}
 
-global int* ptr1 = NULL;
+  constant int *c1 = NULL;
+  constant int *c2 = (global void *)0; // expected-error{{initializing '__constant int *' with an expression of type '__global void *' changes address space of pointer}}
+  constant int *c3 = (constant void *)0;
+  constant int *c4 = (local void *)0; // expected-error{{initializing '__constant int *' with an expression of type '__local void *' changes address space of pointer}}
+  constant int *c5 = (private void *)0; // expected-error{{initializing '__constant int *' with an expression of type '__private void *' changes address space of pointer}}
 
-global int* ptr2 = (global void*)0;
+  local int *l1 = NULL;
+  local int *l2 = (global void *)0; // expected-error{{initializing '__local int *' with an expression of type '__global void *' changes address space of pointer}}
+  local int *l3 = (constant void *)0; // expected-error{{initializing '__local int *' with an expression of type '__constant void *' changes address space of pointer}}
+  local int *l4 = (local void *)0;
+  local int *l5 = (private void *)0; //