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; //