Re: r314872 - We allow implicit function declarations as an extension in all C dialects. Remove OpenCL special case.

2018-08-21 Thread Anastasia Stulova via cfe-commits
If there are no objections I would like to revert this old commit that coverts 
error about implicit function declaration into a warning.


We have decided to generate an error for this https://reviews.llvm.org/D31745 
because for OpenCL variadic prototypes are disallowed (section 6.9.e, 
https://www.khronos.org/registry/OpenCL/specs/opencl-2.0-openclc.pdf) and the 
implicit prototype requires variadic support. As most vendors that support 
OpenCL don't support variadic functions it was decided to restrict this 
explicitly in the spec (section s6.9.u). There is a little bit of more history 
in https://reviews.llvm.org/D17438.


Currently the code that can't run correctly on most OpenCL targets compiles 
successfully. The problem can't be easily seen by the OpenCL developers since 
it's not very common to retrieve the compilation warning log during online 
compilation. Also generated IR doesn't seem to be correct if I compare with the 
similar code in C.

Example:
 1 typedef long long16 __attribute__((ext_vector_type(16)));
 2 void test_somefunc( __global int *d, __global void *s )
 3 {
 4   int i = get_global_id(0);
 5   d[i] = somefunc((( __global long16 *)s)[i]);
 6 }

Is generated to:

%call1 = call i32 (<16 x i64>*, ...) bitcast (i32 ()* @somefunc to i32 (<16 x 
i64>*, ...)*)(<16 x i64>* byval nonnull align 128 %indirect-arg-temp) #2
...

declare i32 @somefunc() local_unnamed_addr #1

Equivalent C code at least generates variadic function prototype correctly:

%call1 = call i32 (<16 x i64>*, ...) bitcast (i32 (...)* @somefunc to i32 (<16 
x i64>*, ...)*)(<16 x i64>* byval align 128 %indirect-arg-temp)
...
declare i32 @somefunc(...)

Anastasia

From: cfe-commits  on behalf of Richard 
Smith via cfe-commits 
Sent: 04 October 2017 02:58
To: cfe-commits@lists.llvm.org
Subject: r314872 - We allow implicit function declarations as an extension in 
all C dialects. Remove OpenCL special case.

Author: rsmith
Date: Tue Oct  3 18:58:22 2017
New Revision: 314872

URL: http://llvm.org/viewvc/llvm-project?rev=314872&view=rev
Log:
We allow implicit function declarations as an extension in all C dialects. 
Remove OpenCL special case.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaOpenCL/clang-builtin-version.cl
cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=314872&r1=314871&r2=314872&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Oct  3 18:58:22 
2017
@@ -355,7 +355,7 @@ def warn_implicit_function_decl : Warnin
   "implicit declaration of function %0">,
   InGroup, DefaultIgnore;
 def ext_implicit_function_decl : ExtWarn<
-  "implicit declaration of function %0 is invalid in C99">,
+  "implicit declaration of function %0 is invalid in %select{C99|OpenCL}1">,
   InGroup;
 def note_function_suggestion : Note<"did you mean %0?">;

@@ -8449,8 +8449,6 @@ def err_opencl_scalar_type_rank_greater_
 "element. (%0 and %1)">;
 def err_bad_kernel_param_type : Error<
   "%0 cannot be used as the type of a kernel parameter">;
-def err_opencl_implicit_function_decl : Error<
-  "implicit declaration of function %0 is invalid in OpenCL">;
 def err_record_with_pointers_kernel_param : Error<
   "%select{struct|union}0 kernel parameters may not contain pointers">;
 def note_within_field_of_type : Note<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=314872&r1=314871&r2=314872&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Oct  3 18:58:22 2017
@@ -12642,17 +12642,15 @@ NamedDecl *Sema::ImplicitlyDefineFunctio
   }

   // Extension in C99.  Legal in C90, but warn about it.
+  // OpenCL v2.0 s6.9.u - Implicit function declaration is not supported.
   unsigned diag_id;
   if (II.getName().startswith("__builtin_"))
 diag_id = diag::warn_builtin_unknown;
-  // OpenCL v2.0 s6.9.u - Implicit function declaration is not supported.
-  else if (getLangOpts().OpenCL)
-diag_id = diag::err_opencl_implicit_function_decl;
-  else if (getLangOpts().C99)
+  else if (getLangOpts().C99 || getLangOpts().OpenCL)
 diag_id = diag::ext_implicit_function_decl;
   else
 diag_id = diag::warn_implicit_function_decl;
-  Diag(Loc, diag_id) << &II;
+  Diag(Loc, diag_id) << &II << getLangOpts().OpenCL;

   // If we found a prior declaration of this function, don't bother building
   // another one. We've already pushed that one into scope, so there's nothing

Modified: cfe/trunk/test/SemaOpenCL/clang-builtin-ver

Re: r314872 - We allow implicit function declarations as an extension in all C dialects. Remove OpenCL special case.

2018-08-21 Thread Anastasia Stulova via cfe-commits
Hi Alexey,


I understand that avoiding adding extra diagnostics is desirable, but I am not 
sure it's a good idea to accept and generate code that is not going to work. 
Variadic functions are currently not expected to be supported by all OpenCL 
targets hence we disallow this in the spec explicitly.


I would be inclined to explicitly reject the code by default, unless there is a 
valid way to handle the generated bitcast of variadic prototype to non-variadic 
one? Then we could look at updating the spec and explain that this is the 
difference in implicit function prototypes for OpenCL.


One compromise could be to try to set "-Werror=implicit-function-declaration" 
by default in the OpenCL mode? Not sure if it's easier/better than an extra 
diagnostic though.


Cheers,

Anastasia



From: aleksey.ba...@gmail.com 
Sent: 21 August 2018 16:11
To: Anastasia Stulova
Cc: Richard Smith; cfe-commits; nd
Subject: Re: r314872 - We allow implicit function declarations as an extension 
in all C dialects. Remove OpenCL special case.

Hi Anastasia,

Richard and I discussed the way to enforce the error w/o customizing
the diagnostic for OpenCL off-list and Richard proposed to use
"-Werror=implicit-function-declaration" command line option if error
is required. Will it work for you?

Thanks,
Alexey
On Tue, Aug 21, 2018 at 5:41 PM Anastasia Stulova via cfe-commits
 wrote:
>
> If there are no objections I would like to revert this old commit that 
> coverts error about implicit function declaration into a warning.
>
>
> We have decided to generate an error for this https://reviews.llvm.org/D31745 
> because for OpenCL variadic prototypes are disallowed (section 6.9.e, 
> https://www.khronos.org/registry/OpenCL/specs/opencl-2.0-openclc.pdf) and the 
> implicit prototype requires variadic support. As most vendors that support 
> OpenCL don't support variadic functions it was decided to restrict this 
> explicitly in the spec (section s6.9.u). There is a little bit of more 
> history in https://reviews.llvm.org/D17438.
>
> Currently the code that can't run correctly on most OpenCL targets compiles 
> successfully. The problem can't be easily seen by the OpenCL developers since 
> it's not very common to retrieve the compilation warning log during online 
> compilation. Also generated IR doesn't seem to be correct if I compare with 
> the similar code in C.
>
> Example:
>  1 typedef long long16 __attribute__((ext_vector_type(16)));
>  2 void test_somefunc( __global int *d, __global void *s )
>  3 {
>  4   int i = get_global_id(0);
>  5   d[i] = somefunc((( __global long16 *)s)[i]);
>  6 }
>
> Is generated to:
>
> %call1 = call i32 (<16 x i64>*, ...) bitcast (i32 ()* @somefunc to i32 (<16 x 
> i64>*, ...)*)(<16 x i64>* byval nonnull align 128 %indirect-arg-temp) #2
> ...
>
> declare i32 @somefunc() local_unnamed_addr #1
>
> Equivalent C code at least generates variadic function prototype correctly:
>
> %call1 = call i32 (<16 x i64>*, ...) bitcast (i32 (...)* @somefunc to i32 
> (<16 x i64>*, ...)*)(<16 x i64>* byval align 128 %indirect-arg-temp)
> ...
> declare i32 @somefunc(...)
>
> Anastasia
> 
> From: cfe-commits  on behalf of Richard 
> Smith via cfe-commits 
> Sent: 04 October 2017 02:58
> To: cfe-commits@lists.llvm.org
> Subject: r314872 - We allow implicit function declarations as an extension in 
> all C dialects. Remove OpenCL special case.
>
> Author: rsmith
> Date: Tue Oct  3 18:58:22 2017
> New Revision: 314872
>
> URL: http://llvm.org/viewvc/llvm-project?rev=314872&view=rev
> Log:
> We allow implicit function declarations as an extension in all C dialects. 
> Remove OpenCL special case.
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/test/SemaOpenCL/clang-builtin-version.cl
> cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=314872&r1=314871&r2=314872&view=diff
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Oct  3 18:58:22 
> 2017
> @@ -355,7 +355,7 @@ def warn_implicit_function_decl : Warnin
>"implicit declaration of function %0">,
>InGroup, DefaultIgnore;
>  def ext_implicit_function_decl : ExtWarn<
> -  "implicit declaration of function %0 is invalid in C99&quo

Re: r314872 - We allow implicit function declarations as an extension in all C dialects. Remove OpenCL special case.

2018-08-22 Thread Anastasia Stulova via cfe-commits
Hi Richard,

> This is incorrect. Implicit function declarations declare unprototyped 
> functions, which are *not* variadic, and are in fact supported by Clang's 
> OpenCL language mode.

We have removed the support for the unprototyped functions from the OpenCL as 
well. See commit: https://reviews.llvm.org/D33681. This is the reason why in 
the OpenCL mode we now generated empty parameter list instead of unprototyped 
function like for C in the examples I provided before (that is not governed now 
by any standard or any compiler extension).

> I would have sympathy for your position if we did not produce an extension 
> warning on this construct by default. But we do, and it says the construct is 
> invalid in OpenCL; moreover, in our strict conformance mode 
> (-pedantic-errors), we reject the code.

I understand the motivation for C to maintain the compatibility with the 
previous standards and other compilers (like gcc) to be able to support the 
legacy code. However, for OpenCL we don't have this requirement wrt older C 
standards. And therefore it is desirable to take advantage of this and remove 
problematic features that are generally confusing for developers or that can't 
be efficiently supported by the targets (especially if there is a little cost 
to that).
 

From: Richard Smith 
Sent: 21 August 2018 22:09:35
To: Anastasia Stulova
Cc: cfe-commits; nd
Subject: Re: r314872 - We allow implicit function declarations as an extension 
in all C dialects. Remove OpenCL special case.

On Tue, 21 Aug 2018 at 07:41, Anastasia Stulova via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:

If there are no objections I would like to revert this old commit that coverts 
error about implicit function declaration into a warning.


We have decided to generate an error for this https://reviews.llvm.org/D31745 
because for OpenCL variadic prototypes are disallowed (section 6.9.e, 
https://www.khronos.org/registry/OpenCL/specs/opencl-2.0-openclc.pdf) and the 
implicit prototype requires variadic support.

This is incorrect. Implicit function declarations declare unprototyped 
functions, which are *not* variadic, and are in fact supported by Clang's 
OpenCL language mode.

See C90 6.5.4.3 Semantics, last paragraph, and 6.3.2.2 Semantics, second 
paragraph.

So that argument does not appear to apply. The reason we accept 
implicitly-declared functions outside of our C89 mode is because this is an 
explicit, supported Clang extension. Generally, Clang intends to support using 
all of its extensions together, unless there is some fundamental reason why 
they cannot be combined. So, just as it doesn't make sense for our OpenCL 
language mode to conflict with, say, AltiVec vector extensions, it doesn't make 
sense for the OpenCL language mode to conflict with our implicitly-declared 
functions extension.

I would have sympathy for your position if we did not produce an extension 
warning on this construct by default. But we do, and it says the construct is 
invalid in OpenCL; moreover, in our strict conformance mode (-pedantic-errors), 
we reject the code.

As most vendors that support OpenCL don't support variadic functions it was 
decided to restrict this explicitly in the spec (section s6.9.u). There is a 
little bit of more history in https://reviews.llvm.org/D17438.


Currently the code that can't run correctly on most OpenCL targets compiles 
successfully. The problem can't be easily seen by the OpenCL developers since 
it's not very common to retrieve the compilation warning log during online 
compilation. Also generated IR doesn't seem to be correct if I compare with the 
similar code in C.

Example:
 1 typedef long long16 __attribute__((ext_vector_type(16)));
 2 void test_somefunc( __global int *d, __global void *s )
 3 {
 4   int i = get_global_id(0);
 5   d[i] = somefunc((( __global long16 *)s)[i]);
 6 }

Is generated to:

%call1 = call i32 (<16 x i64>*, ...) bitcast (i32 ()* @somefunc to i32 (<16 x 
i64>*, ...)*)(<16 x i64>* byval nonnull align 128 %indirect-arg-temp) #2
...

declare i32 @somefunc() local_unnamed_addr #1

Equivalent C code at least generates variadic function prototype correctly:

%call1 = call i32 (<16 x i64>*, ...) bitcast (i32 (...)* @somefunc to i32 (<16 
x i64>*, ...)*)(<16 x i64>* byval align 128 %indirect-arg-temp)
...
declare i32 @somefunc(...)

Anastasia

From: cfe-commits 
mailto:cfe-commits-boun...@lists.llvm.org>> 
on behalf of Richard Smith via cfe-commits 
mailto:cfe-commits@lists.llvm.org>>
Sent: 04 October 2017 02:58
To: cfe-commits@lists.llvm.org<mailto:cfe-commits@lists.llvm.org>
Subject: r314872 - We allow implicit function declarations as an extension in 
all C dialects. Remove OpenCL special case.

Author: rsmith
Date: Tue Oct  3 18:58:22 2017
New Revision: 31

Re: r314872 - We allow implicit function declarations as an extension in all C dialects. Remove OpenCL special case.

2018-08-23 Thread Anastasia Stulova via cfe-commits
Hi Richard,


There was a change in the spec to disallow unprototyped functions, which was 
made this year. Unfortunately it seems it didn't make into the Khronos registry 
yet to appear publicly. I will chase it up with Khronos.


I would like to highlight that OpenCL C was based on C99 originally and 
therefore in contrast to C doesn't have backwards compatibility with the old C 
standards. I don't think it's common to either write or port old C code to 
OpenCL simply because it's not practical to run regular C code on OpenCL 
targets efficiently but also in many cases it won't even compile due to many 
restrictions.


Anastasia



From: Richard Smith 
Sent: 22 August 2018 21:16
To: Anastasia Stulova
Cc: nd; cfe-commits
Subject: Re: r314872 - We allow implicit function declarations as an extension 
in all C dialects. Remove OpenCL special case.

On Wed, 22 Aug 2018 at 06:55, Anastasia Stulova via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:
Hi Richard,

> This is incorrect. Implicit function declarations declare unprototyped 
> functions, which are *not* variadic, and are in fact supported by Clang's 
> OpenCL language mode.

We have removed the support for the unprototyped functions from the OpenCL as 
well. See commit: https://reviews.llvm.org/D33681. This is the reason why in 
the OpenCL mode we now generated empty parameter list instead of unprototyped 
function like for C in the examples I provided before (that is not governed now 
by any standard or any compiler extension).

That's interesting. Do I understand from that review thread that we're 
diverging from the OpenCL specification in treating () as (void) rather than as 
an unprototyped function declaration? If so, that seems like a surprising and 
concerning decision, unless we're confident that the OpenCL language really did 
mean to change this aspect of the C semantics and omitted the wording change by 
oversight. (And I've checked, and can find nothing in the OpenCL specification 
that justifies this: it looks like a Clang bug that we reject

  int f();
  void g() { f(1, 2, 3); }
  int f(int a, int b, int c) { return 0; }

... for example, unless Khronos really did mean to use the C++ rule.)

If it is indeed the intent of the OpenCL specification to treat () as (void) 
like in C++ and not have unprototyped functions, then I think it does make 
sense to also disable our implicitly declared functions extension in OpenCL. 
But, conversely, if the OpenCL specification instead intends to follow C here 
and allow unprototyped functions, then it is a bug in our OpenCL support that 
we don't follow that intent, and when that bug is fixed it makes sense to 
continue to accept implicit function declarations as an extension.

> I would have sympathy for your position if we did not produce an extension 
> warning on this construct by default. But we do, and it says the construct is 
> invalid in OpenCL; moreover, in our strict conformance mode 
> (-pedantic-errors), we reject the code.

I understand the motivation for C to maintain the compatibility with the 
previous standards and other compilers (like gcc) to be able to support the 
legacy code. However, for OpenCL we don't have this requirement wrt older C 
standards. And therefore it is desirable to take advantage of this and remove 
problematic features that are generally confusing for developers or that can't 
be efficiently supported by the targets (especially if there is a little cost 
to that).

For this "can't be efficiently supported by the target" claim, I think you're 
conflating the target and the language mode. If some target can't reasonably 
support variadic functions, we should disable variadic functions for that 
target. That has *nothing* to do with the language mode; targets and language 
modes can be combined arbitrarily. [If I want to use Clang to compile OpenCL 
code for my PDP-11, then I should be allowed to do that (assuming I have a 
suitable LLVM backend), and that target presumably would support variadic 
functions just fine.] Likewise, if the target doesn't support variadic 
functions, we should not be generating variadic function types when producing 
IR (particularly in calls to non-variadic functions like in your example 
elsewhere in this thread). This is true regardless of whether the source 
language is OpenCL or C89 or C++ or anything else.

It is a goal of Clang to allow its various features to be used together, 
including combining them in ways that we didn't think of. The particular case 
of implicit function declarations is not especially important in and of itself, 
but the underlying principle is: the OpenCL language mode of Clang should not 
disable other Clang extensions unless there's some fundamental reason why they 
are incompatible.

Consider this: we allow implicit fun

r331877 - [OpenCL] Add constant address space to __func__ in AST.

2018-05-09 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Wed May  9 06:23:26 2018
New Revision: 331877

URL: http://llvm.org/viewvc/llvm-project?rev=331877&view=rev
Log:
[OpenCL] Add constant address space to __func__ in AST.

Added string literal helper function to obtain the type
attributed by a constant address space.

Also fixed predefind __func__ expr to use the helper
to constract the string literal correctly.

Differential Revision: https://reviews.llvm.org/D46049


Added:
cfe/trunk/test/SemaOpenCL/predefined-expr.cl
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/CodeGenOpenCL/str_literals.cl

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=331877&r1=331876&r2=331877&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Wed May  9 06:23:26 2018
@@ -1348,6 +1348,8 @@ public:
 return getFunctionTypeInternal(ResultTy, Args, EPI, false);
   }
 
+  QualType adjustStringLiteralBaseType(QualType StrLTy) const;
+
 private:
   /// Return a normal function type with a typed argument list.
   QualType getFunctionTypeInternal(QualType ResultTy, ArrayRef Args,

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=331877&r1=331876&r2=331877&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed May  9 06:23:26 2018
@@ -3621,6 +3621,12 @@ QualType ASTContext::getPipeType(QualTyp
   return QualType(New, 0);
 }
 
+QualType ASTContext::adjustStringLiteralBaseType(QualType Ty) const {
+  // OpenCL v1.1 s6.5.3: a string literal is in the constant address space.
+  return LangOpts.OpenCL ? getAddrSpaceQualType(Ty, LangAS::opencl_constant)
+ : Ty;
+}
+
 QualType ASTContext::getReadPipeType(QualType T) const {
   return getPipeType(T, true);
 }

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=331877&r1=331876&r2=331877&view=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Wed May  9 06:23:26 2018
@@ -881,7 +881,8 @@ StringLiteral *StringLiteral::CreateEmpt
   void *Mem =
   C.Allocate(sizeof(StringLiteral) + sizeof(SourceLocation) * (NumStrs - 
1),
  alignof(StringLiteral));
-  StringLiteral *SL = new (Mem) StringLiteral(QualType());
+  StringLiteral *SL =
+  new (Mem) StringLiteral(C.adjustStringLiteralBaseType(QualType()));
   SL->CharByteWidth = 0;
   SL->Length = 0;
   SL->NumConcatenated = NumStrs;

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=331877&r1=331876&r2=331877&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed May  9 06:23:26 2018
@@ -1554,17 +1554,14 @@ Sema::ActOnStringLiteral(ArrayRef
   if (getLangOpts().CPlusPlus || getLangOpts().ConstStrings)
 CharTyConst.addConst();
 
+  CharTyConst = Context.adjustStringLiteralBaseType(CharTyConst);
+
   // Get an array type for the string, according to C99 6.4.5.  This includes
   // the nul terminator character as well as the string length for pascal
   // strings.
-  QualType StrTy = Context.getConstantArrayType(CharTyConst,
- llvm::APInt(32, 
Literal.GetNumStringChars()+1),
- ArrayType::Normal, 0);
-
-  // OpenCL v1.1 s6.5.3: a string literal is in the constant address space.
-  if (getLangOpts().OpenCL) {
-StrTy = Context.getAddrSpaceQualType(StrTy, LangAS::opencl_constant);
-  }
+  QualType StrTy = Context.getConstantArrayType(
+  CharTyConst, llvm::APInt(32, Literal.GetNumStringChars() + 1),
+  ArrayType::Normal, 0);
 
   // Pass &StringTokLocs[0], StringTokLocs.size() to factory!
   StringLiteral *Lit = StringLiteral::Create(Context, Literal.GetString(),
@@ -3046,7 +3043,8 @@ ExprResult Sema::BuildPredefinedExpr(Sou
 
 llvm::APInt LengthI(32, Length + 1);
 if (IT == PredefinedExpr::LFunction) {
-  ResTy = Context.WideCharTy.withConst();
+  ResTy =
+  Context.adjustStringLiteralBaseType(Context.WideCharTy.withConst());
   SmallString<32> RawChars;
   ConvertUTF8ToWideString(Context.getTypeSizeInChars(ResTy).getQuantity(),
   Str, RawChars);
@@ -3055,7 +3053,7 @@ ExprResult Sema::BuildPredefinedExpr(Sou
   SL = StringLiteral::Create(Context, RawChars, StringLiteral::Wide,
 

r314304 - [OpenCL] Handle address space conversion while setting type alignment.

2017-09-27 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Wed Sep 27 07:37:00 2017
New Revision: 314304

URL: http://llvm.org/viewvc/llvm-project?rev=314304&view=rev
Log:
[OpenCL] Handle address space conversion while setting type alignment.

Added missing addrspacecast case in alignment computation
logic of pointer type emission in IR generation.

Differential Revision: https://reviews.llvm.org/D37804


Modified:
cfe/trunk/lib/CodeGen/CGBuilder.h
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/test/CodeGenOpenCL/vectorLoadStore.cl

Modified: cfe/trunk/lib/CodeGen/CGBuilder.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuilder.h?rev=314304&r1=314303&r2=314304&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuilder.h (original)
+++ cfe/trunk/lib/CodeGen/CGBuilder.h Wed Sep 27 07:37:00 2017
@@ -145,6 +145,13 @@ public:
Addr.getAlignment());
   }
 
+  using CGBuilderBaseTy::CreateAddrSpaceCast;
+  Address CreateAddrSpaceCast(Address Addr, llvm::Type *Ty,
+  const llvm::Twine &Name = "") {
+return Address(CreateAddrSpaceCast(Addr.getPointer(), Ty, Name),
+   Addr.getAlignment());
+  }
+
   /// Cast the element type of the given address to a different type,
   /// preserving information like the alignment and address space.
   Address CreateElementBitCast(Address Addr, llvm::Type *Ty,

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=314304&r1=314303&r2=314304&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Sep 27 07:37:00 2017
@@ -925,6 +925,7 @@ Address CodeGenFunction::EmitPointerWith
 // Non-converting casts (but not C's implicit conversion from void*).
 case CK_BitCast:
 case CK_NoOp:
+case CK_AddressSpaceConversion:
   if (auto PtrTy = CE->getSubExpr()->getType()->getAs()) {
 if (PtrTy->getPointeeType()->isVoidType())
   break;
@@ -953,8 +954,10 @@ Address CodeGenFunction::EmitPointerWith
   CodeGenFunction::CFITCK_UnrelatedCast,
   CE->getLocStart());
 }
-
-return Builder.CreateBitCast(Addr, ConvertType(E->getType()));
+return CE->getCastKind() != CK_AddressSpaceConversion
+   ? Builder.CreateBitCast(Addr, ConvertType(E->getType()))
+   : Builder.CreateAddrSpaceCast(Addr,
+ ConvertType(E->getType()));
   }
   break;
 

Modified: cfe/trunk/test/CodeGenOpenCL/vectorLoadStore.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/vectorLoadStore.cl?rev=314304&r1=314303&r2=314304&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/vectorLoadStore.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/vectorLoadStore.cl Wed Sep 27 07:37:00 2017
@@ -1,9 +1,22 @@
-// RUN: %clang_cc1 %s -emit-llvm -O0 -o - | FileCheck %s
+// RUN: %clang_cc1 -triple "spir-unknown-unknown" %s -emit-llvm -O0 -o - | 
FileCheck %s
 
-typedef char char3 __attribute((ext_vector_type(3)));;
+typedef char char2 __attribute((ext_vector_type(2)));
+typedef char char3 __attribute((ext_vector_type(3)));
+typedef char char8 __attribute((ext_vector_type(8)));
+typedef float float4 __attribute((ext_vector_type(4)));
 
 // Check for optimized vec3 load/store which treats vec3 as vec4.
 void foo(char3 *P, char3 *Q) {
   *P = *Q;
   // CHECK: %{{.*}} = shufflevector <4 x i8> %{{.*}}, <4 x i8> undef, <3 x 
i32> 
 }
+
+// CHECK: define spir_func void @alignment()
+void alignment() {
+  __private char2 data_generic[100];
+  __private char8 data_private[100];
+
+  // CHECK: %{{.*}} = load <4 x float>, <4 x float> addrspace(4)* %{{.*}}, 
align 2
+  // CHECK: store <4 x float> %{{.*}}, <4 x float>* %{{.*}}, align 8
+  ((private float4 *)data_private)[1] = ((float4 *)data_generic)[2];
+}


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


r314317 - [OpenCL] Fixed CL version in failing test.

2017-09-27 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Wed Sep 27 10:03:35 2017
New Revision: 314317

URL: http://llvm.org/viewvc/llvm-project?rev=314317&view=rev
Log:
[OpenCL] Fixed CL version in failing test.


Modified:
cfe/trunk/test/CodeGenOpenCL/vectorLoadStore.cl

Modified: cfe/trunk/test/CodeGenOpenCL/vectorLoadStore.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/vectorLoadStore.cl?rev=314317&r1=314316&r2=314317&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/vectorLoadStore.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/vectorLoadStore.cl Wed Sep 27 10:03:35 2017
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple "spir-unknown-unknown" %s -emit-llvm -O0 -o - | 
FileCheck %s
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple "spir-unknown-unknown" %s -emit-llvm 
-O0 -o - | FileCheck %s
 
 typedef char char2 __attribute((ext_vector_type(2)));
 typedef char char3 __attribute((ext_vector_type(3)));


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


Re: r298369 - [OpenCL] Added diagnostic for checking length of vector

2017-10-12 Thread Anastasia Stulova via cfe-commits

I think this bit is a bit confusing to us. Some of our original OpenCL checks 
were removed in some places because in some cases OpenCL semantic was adopted 
elsewhere. But I think this should indeed go under OpenCL check.

Thanks,
Anastasia


From: Bruno Cardoso Lopes 
Sent: 11 October 2017 00:27
To: Egor Churaev
Cc: cfe-commits; Anastasia Stulova
Subject: Re: r298369 - [OpenCL] Added diagnostic for checking length of vector

Hi Egor,

On Tue, Mar 21, 2017 at 6:20 AM, Egor Churaev via cfe-commits
 wrote:
> Author: echuraev
> Date: Tue Mar 21 08:20:57 2017
> New Revision: 298369
>
> URL: http://llvm.org/viewvc/llvm-project?rev=298369&view=rev
> Log:
> [OpenCL] Added diagnostic for checking length of vector
>
> Reviewers: Anastasia, cfe-commits
>
> Reviewed By: Anastasia
>
> Subscribers: bader, yaxunl
>
> Differential Revision: https://reviews.llvm.org/D30937
>
> Added:
> cfe/trunk/test/SemaOpenCL/vector_swizzle_length.cl
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaExprMember.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=298369&r1=298368&r2=298369&view=diff
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Mar 21 08:20:57 
> 2017
> @@ -8236,6 +8236,8 @@ def err_opencl_ptrptr_kernel_param : Err
>  def err_kernel_arg_address_space : Error<
>"pointer arguments to kernel functions must reside in '__global', "
>"'__constant' or '__local' address space">;
> +def err_opencl_ext_vector_component_invalid_length : Error<
> +  "vector component access has invalid length %0.  Supported: 
> 1,2,3,4,8,16.">;
>  def err_opencl_function_variable : Error<
>"%select{non-kernel function|function scope}0 variable cannot be declared 
> in %1 address space">;
>  def err_static_function_scope : Error<
>
> Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=298369&r1=298368&r2=298369&view=diff
> ==
> --- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprMember.cpp Tue Mar 21 08:20:57 2017
> @@ -284,6 +284,14 @@ IsRGBA(char c) {
>}
>  }
>
> +// OpenCL v1.1, s6.1.7
> +// The component swizzle length must be in accordance with the acceptable
> +// vector sizes.
> +static bool IsValidOpenCLComponentSwizzleLength(unsigned len)
> +{
> +  return (len >= 1 && len <= 4) || len == 8 || len == 16;
> +}
> +
>  /// Check an ext-vector component access expression.
>  ///
>  /// VK should be set in advance to the value kind of the base
> @@ -376,6 +384,19 @@ CheckExtVectorComponent(Sema &S, QualTyp
>  }
>}
>
> +  if (!HalvingSwizzle) {
> +unsigned SwizzleLength = CompName->getLength();
> +
> +if (HexSwizzle)
> +  SwizzleLength--;
> +
> +if (IsValidOpenCLComponentSwizzleLength(SwizzleLength) == false) {
> +  S.Diag(OpLoc, diag::err_opencl_ext_vector_component_invalid_length)
> +<< SwizzleLength << SourceRange(CompLoc);
> +  return QualType();
> +}
> +  }
> +
>// The component accessor looks fine - now we need to compute the actual 
> type.
>// The vector type is implied by the component accessor. For example,
>// vec4.b is a float, vec4.xy is a vec2, vec4.rgb is a vec3, etc.
>
> Added: cfe/trunk/test/SemaOpenCL/vector_swizzle_length.cl
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/vector_swizzle_length.cl?rev=298369&view=auto
> ==
> --- cfe/trunk/test/SemaOpenCL/vector_swizzle_length.cl (added)
> +++ cfe/trunk/test/SemaOpenCL/vector_swizzle_length.cl Tue Mar 21 08:20:57 
> 2017
> @@ -0,0 +1,10 @@
> +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
> +
> +typedef float float8 __attribute__((ext_vector_type(8)));
> +
> +void foo() {
> +float8 f2 = (float8)(0, 0, 0, 0, 0, 0, 0, 0);
> +
> +f2.s01234; // expected-error {{vector component access has invalid 
> length 5.  Supported: 1,2,3,4,8,16}}
> +f2.xyzxy; // expected-error {{vector component access has invalid length 
> 5.  Supported: 1,2,3,4,8,16}}
> +}

Sorry for the necromancy here, but I wonder if we should only make
this if LangOpts.OpenCL in on. Is there an initial intent for not to?

The rationale is that we have given users support for ext_vector_type
without OpenCL mode with arbitrary vectors lengths not defined in
"6.1.2 Built-In Vector Data Types", that said it makes sense to
support the component notation for those. I'm happy to fix it, I just
need to know if this covers some background I'm not aware of.

Thanks,

--
Bruno Cardoso Lo

Re: r314872 - We allow implicit function declarations as an extension in all C dialects. Remove OpenCL special case.

2018-08-24 Thread Anastasia Stulova via cfe-commits
Thanks! Will do!



From: Richard Smith 
Sent: 23 August 2018 21:15
To: Anastasia Stulova
Cc: nd; cfe-commits
Subject: Re: r314872 - We allow implicit function declarations as an extension 
in all C dialects. Remove OpenCL special case.

On Thu, 23 Aug 2018 at 02:52, Anastasia Stulova via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:

Hi Richard,


There was a change in the spec to disallow unprototyped functions, which was 
made this year. Unfortunately it seems it didn't make into the Khronos registry 
yet to appear publicly. I will chase it up with Khronos.

Thanks!

Reiterating what I said below, I think it is reasonable and appropriate to 
disallow implicit function declarations in languages that don't have 
unprototyped functions -- implicitly declaring something that could not be 
declared explicitly doesn't seem appropriate. So feel free to revert r314872, 
but please update the comment to explain that we don't allow this as an 
extension in OpenCL because OpenCL does not permit unprototyped functions. 
Apologies for the round-trip time here.


I would like to highlight that OpenCL C was based on C99 originally and 
therefore in contrast to C doesn't have backwards compatibility with the old C 
standards. I don't think it's common to either write or port old C code to 
OpenCL simply because it's not practical to run regular C code on OpenCL 
targets efficiently but also in many cases it won't even compile due to many 
restrictions.


Anastasia



From: Richard Smith mailto:rich...@metafoo.co.uk>>
Sent: 22 August 2018 21:16
To: Anastasia Stulova
Cc: nd; cfe-commits
Subject: Re: r314872 - We allow implicit function declarations as an extension 
in all C dialects. Remove OpenCL special case.

On Wed, 22 Aug 2018 at 06:55, Anastasia Stulova via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:
Hi Richard,

> This is incorrect. Implicit function declarations declare unprototyped 
> functions, which are *not* variadic, and are in fact supported by Clang's 
> OpenCL language mode.

We have removed the support for the unprototyped functions from the OpenCL as 
well. See commit: https://reviews.llvm.org/D33681. This is the reason why in 
the OpenCL mode we now generated empty parameter list instead of unprototyped 
function like for C in the examples I provided before (that is not governed now 
by any standard or any compiler extension).

That's interesting. Do I understand from that review thread that we're 
diverging from the OpenCL specification in treating () as (void) rather than as 
an unprototyped function declaration? If so, that seems like a surprising and 
concerning decision, unless we're confident that the OpenCL language really did 
mean to change this aspect of the C semantics and omitted the wording change by 
oversight. (And I've checked, and can find nothing in the OpenCL specification 
that justifies this: it looks like a Clang bug that we reject

  int f();
  void g() { f(1, 2, 3); }
  int f(int a, int b, int c) { return 0; }

... for example, unless Khronos really did mean to use the C++ rule.)

If it is indeed the intent of the OpenCL specification to treat () as (void) 
like in C++ and not have unprototyped functions, then I think it does make 
sense to also disable our implicitly declared functions extension in OpenCL. 
But, conversely, if the OpenCL specification instead intends to follow C here 
and allow unprototyped functions, then it is a bug in our OpenCL support that 
we don't follow that intent, and when that bug is fixed it makes sense to 
continue to accept implicit function declarations as an extension.

> I would have sympathy for your position if we did not produce an extension 
> warning on this construct by default. But we do, and it says the construct is 
> invalid in OpenCL; moreover, in our strict conformance mode 
> (-pedantic-errors), we reject the code.

I understand the motivation for C to maintain the compatibility with the 
previous standards and other compilers (like gcc) to be able to support the 
legacy code. However, for OpenCL we don't have this requirement wrt older C 
standards. And therefore it is desirable to take advantage of this and remove 
problematic features that are generally confusing for developers or that can't 
be efficiently supported by the targets (especially if there is a little cost 
to that).

For this "can't be efficiently supported by the target" claim, I think you're 
conflating the target and the language mode. If some target can't reasonably 
support variadic functions, we should disable variadic functions for that 
target. That has *nothing* to do with the language mode; targets and language 
modes can be combined arbitrarily. [If I want to use Clang to compile OpenCL 
code for my PDP-11, then I shoul

r304708 - [OpenCL] Fix pipe size in TypeInfo.

2017-06-05 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Mon Jun  5 06:27:03 2017
New Revision: 304708

URL: http://llvm.org/viewvc/llvm-project?rev=304708&view=rev
Log:
[OpenCL] Fix pipe size in TypeInfo.

Pipes are now the size of pointers rather than the size
of the type that they contain.

Patch by Simon Perretta!

Differential Revision: https://reviews.llvm.org/D33597


Added:
cfe/trunk/test/Index/pipe-size.cl
Modified:
cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=304708&r1=304707&r2=304708&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Jun  5 06:27:03 2017
@@ -1939,9 +1939,8 @@ TypeInfo ASTContext::getTypeInfoImpl(con
   break;
 
   case Type::Pipe: {
-TypeInfo Info = getTypeInfo(cast(T)->getElementType());
-Width = Info.Width;
-Align = Info.Align;
+Width = 
Target->getPointerWidth(getTargetAddressSpace(LangAS::opencl_global));
+Align = 
Target->getPointerAlign(getTargetAddressSpace(LangAS::opencl_global));
   }
 
   }

Added: cfe/trunk/test/Index/pipe-size.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/pipe-size.cl?rev=304708&view=auto
==
--- cfe/trunk/test/Index/pipe-size.cl (added)
+++ cfe/trunk/test/Index/pipe-size.cl Mon Jun  5 06:27:03 2017
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -x cl -O0 -cl-std=CL2.0 -emit-llvm -triple 
x86_64-unknown-linux-gnu %s -o - | FileCheck %s --check-prefix=X86
+// RUN: %clang_cc1 -x cl -O0 -cl-std=CL2.0 -emit-llvm -triple 
spir-unknown-unknown %s -o - | FileCheck %s --check-prefix=SPIR
+// RUN: %clang_cc1 -x cl -O0 -cl-std=CL2.0 -emit-llvm -triple 
spir64-unknown-unknown %s -o - | FileCheck %s --check-prefix=SPIR64
+// RUN: %clang_cc1 -x cl -O0 -cl-std=CL2.0 -emit-llvm -triple 
amdgcn-amd-amdhsa-amdgizcl %s -o - | FileCheck %s --check-prefix=AMD
+__kernel void testPipe( pipe int test )
+{
+int s = sizeof(test);
+// X86: store %opencl.pipe_t* %test, %opencl.pipe_t** %test.addr, align 8
+// X86: store i32 8, i32* %s, align 4
+// SPIR: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t 
addrspace(1)** %test.addr, align 4
+// SPIR: store i32 4, i32* %s, align 4
+// SPIR64: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t 
addrspace(1)** %test.addr, align 8
+// SPIR64: store i32 8, i32* %s, align 4
+// AMD: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t 
addrspace(1)* addrspace(5)* %test.addr, align 4
+// AMD: store i32 8, i32 addrspace(5)* %s, align 4
+}


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


r305798 - [OpenCL] Diagnose scoped address-space qualified variables

2017-06-20 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Tue Jun 20 09:50:45 2017
New Revision: 305798

URL: http://llvm.org/viewvc/llvm-project?rev=305798&view=rev
Log:
[OpenCL] Diagnose scoped address-space qualified variables

Produce an error if variables qualified with a local or
a constant address space are not declared in the outermost
scope of a kernel.

Patch by Simon Perretta.

Differential Revision: https://reviews.llvm.org/D34024


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaOpenCL/storageclass.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=305798&r1=305797&r2=305798&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jun 20 09:50:45 
2017
@@ -8311,6 +8311,9 @@ def err_opencl_ext_vector_component_inva
   "vector component access has invalid length %0.  Supported: 1,2,3,4,8,16.">;
 def err_opencl_function_variable : Error<
   "%select{non-kernel function|function scope}0 variable cannot be declared in 
%1 address space">;
+def err_opencl_addrspace_scope : Error<
+  "variables in the %0 address space can only be declared in the outermost "
+  "scope of a kernel function">;
 def err_static_function_scope : Error<
   "variables in function scope cannot be declared static">;
 def err_opencl_bitfields : Error<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=305798&r1=305797&r2=305798&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jun 20 09:50:45 2017
@@ -7260,11 +7260,11 @@ void Sema::CheckVariableDeclarationType(
 NewVD->setInvalidDecl();
 return;
   }
-  // OpenCL v1.1 s6.5.2 and s6.5.3 no local or constant variables
-  // in functions.
   if (T.getAddressSpace() == LangAS::opencl_constant ||
   T.getAddressSpace() == LangAS::opencl_local) {
 FunctionDecl *FD = getCurFunctionDecl();
+// OpenCL v1.1 s6.5.2 and s6.5.3: no local or constant variables
+// in functions.
 if (FD && !FD->hasAttr()) {
   if (T.getAddressSpace() == LangAS::opencl_constant)
 Diag(NewVD->getLocation(), diag::err_opencl_function_variable)
@@ -7275,6 +7275,20 @@ void Sema::CheckVariableDeclarationType(
   NewVD->setInvalidDecl();
   return;
 }
+// OpenCL v2.0 s6.5.2 and s6.5.3: local and constant variables must be
+// in the outermost scope of a kernel function.
+if (FD && FD->hasAttr()) {
+  if (!getCurScope()->isFunctionScope()) {
+if (T.getAddressSpace() == LangAS::opencl_constant)
+  Diag(NewVD->getLocation(), diag::err_opencl_addrspace_scope)
+  << "constant";
+else
+  Diag(NewVD->getLocation(), diag::err_opencl_addrspace_scope)
+  << "local";
+NewVD->setInvalidDecl();
+return;
+  }
+}
   } else if (T.getAddressSpace() != LangAS::Default) {
 // Do not allow other address spaces on automatic variable.
 Diag(NewVD->getLocation(), diag::err_as_qualified_auto_decl) << 1;

Modified: cfe/trunk/test/SemaOpenCL/storageclass.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/storageclass.cl?rev=305798&r1=305797&r2=305798&view=diff
==
--- cfe/trunk/test/SemaOpenCL/storageclass.cl (original)
+++ cfe/trunk/test/SemaOpenCL/storageclass.cl Tue Jun 20 09:50:45 2017
@@ -13,6 +13,11 @@ void kernel foo(int x) {
   constant int L1 = 0;
   local int L2;
 
+  if (true) {
+local int L1; // expected-error {{variables in the local address space can 
only be declared in the outermost scope of a kernel function}}
+constant int L1 = 42; // expected-error {{variables in the constant 
address space can only be declared in the outermost scope of a kernel function}}
+  }
+
   auto int L3 = 7;// expected-error{{OpenCL 
version 1.2 does not support the 'auto' storage class specifier}}
   global int L4;  // expected-error{{function 
scope variable cannot be declared in global address space}}
   __attribute__((address_space(100))) int L5; // expected-error{{automatic 
variable qualified with an invalid address space}}


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


r335358 - [Sema] Updated note for address spaces to print the type.

2018-06-22 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Fri Jun 22 08:45:08 2018
New Revision: 335358

URL: http://llvm.org/viewvc/llvm-project?rev=335358&view=rev
Log:
[Sema] Updated note for address spaces to print the type.

This allows to reuse the same diagnostic for OpenCL or CUDA.


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/SemaCXX/address-space-references.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=335358&r1=335357&r2=335358&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jun 22 08:45:08 
2018
@@ -3683,8 +3683,8 @@ def note_ovl_candidate_bad_lvalue : Note
 "%select{%ordinal4 argument|object argument}3">;
 def note_ovl_candidate_bad_addrspace : Note<
 "candidate %sub{select_ovl_candidate_kind}0,1,2 not viable: "
-"%select{%ordinal7|'this'}6 argument (%3) is in "
-"address space %4, but parameter must be in address space %5">;
+"address space mismatch in %select{%ordinal6|'this'}5 argument (%3), "
+"parameter type must be %4">;
 def note_ovl_candidate_bad_gc : Note<
 "candidate %sub{select_ovl_candidate_kind}0,1,2 not viable: "
 "%select{%ordinal7|'this'}6 argument (%3) has %select{no|__weak|__strong}4 
"

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=335358&r1=335357&r2=335358&view=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri Jun 22 08:45:08 2018
@@ -9591,9 +9591,7 @@ static void DiagnoseBadConversion(Sema &
   S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_addrspace)
   << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << 
FnDesc
   << (FromExpr ? FromExpr->getSourceRange() : SourceRange()) << FromTy
-  << FromQs.getAddressSpaceAttributePrintValue()
-  << ToQs.getAddressSpaceAttributePrintValue()
-  << (unsigned)isObjectArgument << I + 1;
+  << ToTy << (unsigned)isObjectArgument << I + 1;
   MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
   return;
 }

Modified: cfe/trunk/test/SemaCXX/address-space-references.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/address-space-references.cpp?rev=335358&r1=335357&r2=335358&view=diff
==
--- cfe/trunk/test/SemaCXX/address-space-references.cpp (original)
+++ cfe/trunk/test/SemaCXX/address-space-references.cpp Fri Jun 22 08:45:08 2018
@@ -3,10 +3,10 @@
 typedef int __attribute__((address_space(1))) int_1;
 typedef int __attribute__((address_space(2))) int_2;
 
-void f0(int_1 &); // expected-note{{candidate function not viable: 1st 
argument ('int') is in address space 0, but parameter must be in address space 
1}} \
-// expected-note{{candidate function not viable: 1st argument ('int_2' (aka 
'__attribute__((address_space(2))) int')) is in address space 2, but parameter 
must be in address space 1}}
-void f0(const int_1 &); // expected-note{{candidate function not viable: 1st 
argument ('int') is in address space 0, but parameter must be in address space 
1}} \
-// expected-note{{candidate function not viable: 1st argument ('int_2' (aka 
'__attribute__((address_space(2))) int')) is in address space 2, but parameter 
must be in address space 1}}
+void f0(int_1 &); // expected-note{{candidate function not viable: address 
space mismatch in 1st argument ('int'), parameter type must be 'int_1 &' (aka 
'__attribute__((address_space(1))) int &')}} \
+// expected-note{{candidate function not viable: address space mismatch in 1st 
argument ('int_2' (aka '__attribute__((address_space(2))) int')), parameter 
type must be 'int_1 &' (aka '__attribute__((address_space(1))) int &')}}
+void f0(const int_1 &); // expected-note{{candidate function not viable: 
address space mismatch in 1st argument ('int'), parameter type must be 'const 
int_1 &' (aka 'const __attribute__((address_space(1))) int &')}} \
+// expected-note{{candidate function not viable: address space mismatch in 1st 
argument ('int_2' (aka '__attribute__((address_space(2))) int')), parameter 
type must be 'const int_1 &' (aka 'const __attribute__((address_space(1))) int 
&')}}
 
 void test_f0() {
   int i;


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


r335362 - [OpenCL] Fixed parsing of address spaces for C++.

2018-06-22 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Fri Jun 22 09:20:21 2018
New Revision: 335362

URL: http://llvm.org/viewvc/llvm-project?rev=335362&view=rev
Log:
[OpenCL] Fixed parsing of address spaces for C++.

Added address space tokens to C++ parsing code to be able
to parse declarations that start from an address space keyword.


Modified:
cfe/trunk/lib/Parse/ParseTentative.cpp
cfe/trunk/test/SemaOpenCL/address-spaces.cl

Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=335362&r1=335361&r2=335362&view=diff
==
--- cfe/trunk/lib/Parse/ParseTentative.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTentative.cpp Fri Jun 22 09:20:21 2018
@@ -1357,6 +1357,11 @@ Parser::isCXXDeclarationSpecifier(Parser
 // cv-qualifier
   case tok::kw_const:
   case tok::kw_volatile:
+  case tok::kw___private:
+  case tok::kw___local:
+  case tok::kw___global:
+  case tok::kw___constant:
+  case tok::kw___generic:
 
 // GNU
   case tok::kw_restrict:

Modified: cfe/trunk/test/SemaOpenCL/address-spaces.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/address-spaces.cl?rev=335362&r1=335361&r2=335362&view=diff
==
--- cfe/trunk/test/SemaOpenCL/address-spaces.cl (original)
+++ cfe/trunk/test/SemaOpenCL/address-spaces.cl Fri Jun 22 09:20:21 2018
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -cl-std=c++ -verify -pedantic -fsyntax-only
 
 __constant int ci = 1;
 
@@ -8,6 +9,8 @@ __kernel void foo(__global int *gip) {
   __local int lj = 2; // expected-error {{'__local' variable cannot have an 
initializer}}
 
   int *ip;
+// FIXME: Temporarily disable part of the test that doesn't work for C++ yet.
+#if !__OPENCL_CPP_VERSION__
 #if __OPENCL_C_VERSION__ < 200
   ip = gip; // expected-error {{assigning '__global int *' to 'int *' changes 
address space of pointer}}
   ip = &li; // expected-error {{assigning '__local int *' to 'int *' changes 
address space of pointer}}
@@ -64,4 +67,5 @@ void func_multiple_addr(void) {
   __local private_int_t *var4;  // expected-error {{multiple address spaces 
specified for type}}
   __private private_int_t var5; // expected-warning {{multiple identical 
address spaces specified for type}}
   __private private_int_t *var6;// expected-warning {{multiple identical 
address spaces specified for type}}
+#endif // !__OPENCL_CXX_VERSION__
 }


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


r344148 - [OpenCL] Fixed address space cast in C style cast of C++ parsing

2018-10-10 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Wed Oct 10 09:05:22 2018
New Revision: 344148

URL: http://llvm.org/viewvc/llvm-project?rev=344148&view=rev
Log:
[OpenCL] Fixed address space cast in C style cast of C++ parsing

C style cast in OpenCL C++ was ignoring the address space
conversions from OpenCL C and as a result accepting incorrect
code to compile. This commit adds special function for checking 
correctness of address spaces that is shared between C and C++
casts.
 

Modified:
cfe/trunk/lib/Sema/SemaCast.cpp
cfe/trunk/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
cfe/trunk/test/SemaOpenCL/address-spaces.cl

Modified: cfe/trunk/lib/Sema/SemaCast.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=344148&r1=344147&r2=344148&view=diff
==
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCast.cpp Wed Oct 10 09:05:22 2018
@@ -131,6 +131,9 @@ namespace {
   return PlaceholderKind == K;
 }
 
+// Language specific cast restrictions for address spaces.
+void checkAddressSpaceCast(QualType SrcType, QualType DestType);
+
 void checkCastAlign() {
   Self.CheckCastAlign(SrcExpr.get(), DestType, OpRange);
 }
@@ -2276,6 +2279,27 @@ static TryCastResult TryReinterpretCast(
   return SuccessResult;
 }
 
+void CastOperation::checkAddressSpaceCast(QualType SrcType, QualType DestType) 
{
+  // In OpenCL only conversions between pointers to objects in overlapping
+  // addr spaces are allowed. v2.0 s6.5.5 - Generic addr space overlaps
+  // with any named one, except for constant.
+  if (Self.getLangOpts().OpenCL) {
+auto SrcPtrType = SrcType->getAs();
+if (!SrcPtrType)
+  return;
+auto DestPtrType = DestType->getAs();
+if (!DestPtrType)
+  return;
+if (!DestPtrType->isAddressSpaceOverlapping(*SrcPtrType)) {
+  Self.Diag(OpRange.getBegin(),
+diag::err_typecheck_incompatible_address_space)
+  << SrcType << DestType << Sema::AA_Casting
+  << SrcExpr.get()->getSourceRange();
+  SrcExpr = ExprError();
+}
+  }
+}
+
 void CastOperation::CheckCXXCStyleCast(bool FunctionalStyle,
bool ListInitialization) {
   assert(Self.getLangOpts().CPlusPlus);
@@ -2403,6 +2427,8 @@ void CastOperation::CheckCXXCStyleCast(b
 }
   }
 
+  checkAddressSpaceCast(SrcExpr.get()->getType(), DestType);
+
   if (isValidCast(tcr)) {
 if (Kind == CK_BitCast)
   checkCastAlign();
@@ -2489,20 +2515,9 @@ void CastOperation::CheckCStyleCast() {
 
   assert(!SrcType->isPlaceholderType());
 
-  // OpenCL v1 s6.5: Casting a pointer to address space A to a pointer to
-  // address space B is illegal.
-  if (Self.getLangOpts().OpenCL && DestType->isPointerType() &&
-  SrcType->isPointerType()) {
-const PointerType *DestPtr = DestType->getAs();
-if (!DestPtr->isAddressSpaceOverlapping(*SrcType->getAs())) {
-  Self.Diag(OpRange.getBegin(),
-diag::err_typecheck_incompatible_address_space)
-  << SrcType << DestType << Sema::AA_Casting
-  << SrcExpr.get()->getSourceRange();
-  SrcExpr = ExprError();
-  return;
-}
-  }
+  checkAddressSpaceCast(SrcType, DestType);
+  if (SrcExpr.isInvalid())
+return;
 
   if (Self.RequireCompleteType(OpRange.getBegin(), DestType,
diag::err_typecheck_cast_to_incomplete)) {

Modified: cfe/trunk/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl?rev=344148&r1=344147&r2=344148&view=diff
==
--- cfe/trunk/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl (original)
+++ cfe/trunk/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl Wed Oct 10 
09:05:22 2018
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only 
-DCONSTANT -cl-std=CL2.0
 // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only 
-DGLOBAL -cl-std=CL2.0
 // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only 
-DGENERIC -cl-std=CL2.0
+// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only 
-DCONSTANT -cl-std=c++
+// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only 
-DGLOBAL -cl-std=c++
+// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only 
-DGENERIC -cl-std=c++
 
 /* OpenCLC v2.0 adds a set of restrictions for conversions between pointers to
 *  different address spaces, mainly described in Sections 6.5.5 and 6.5.6.
@@ -17,71 +20,111 @@
 */
 
 #ifdef GENERIC
-#define AS generic
-#define AS_COMP local
-#define AS_INCOMP constant
+#define AS __generic
+#define AS_COMP __local
+#define AS_INCOMP __constant
 #endif
 
 #ifdef GLOBAL
-#define AS global
-#define AS_COMP global
-#d

Re: r343653 - OpenCL: Mark printf format string argument

2018-10-29 Thread Anastasia Stulova via cfe-commits
It seems like it caused a bug:

https://bugs.llvm.org/show_bug.cgi?id=39486



From: cfe-commits  on behalf of Matt 
Arsenault via cfe-commits 
Sent: 03 October 2018 03:01
To: cfe-commits@lists.llvm.org
Subject: r343653 - OpenCL: Mark printf format string argument

Author: arsenm
Date: Tue Oct  2 19:01:19 2018
New Revision: 343653

URL: http://llvm.org/viewvc/llvm-project?rev=343653&view=rev
Log:
OpenCL: Mark printf format string argument

Fixes not warning on format string errors.

Added:
cfe/trunk/test/SemaOpenCL/printf-format-string-warnings.cl
Modified:
cfe/trunk/lib/Headers/opencl-c.h

Modified: cfe/trunk/lib/Headers/opencl-c.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/opencl-c.h?rev=343653&r1=343652&r2=343653&view=diff
==
--- cfe/trunk/lib/Headers/opencl-c.h (original)
+++ cfe/trunk/lib/Headers/opencl-c.h Tue Oct  2 19:01:19 2018
@@ -14462,7 +14462,7 @@ half16 __ovld __cnfn shuffle2(half16 x,
 #if __OPENCL_C_VERSION__ >= CL_VERSION_1_2
 // OpenCL v1.2 s6.12.13, v2.0 s6.13.13 - printf

-int printf(__constant const char* st, ...);
+int printf(__constant const char* st, ...) __attribute__((format(printf, 1, 
2)));
 #endif

 // OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14 - Image Read and Write 
Functions

Added: cfe/trunk/test/SemaOpenCL/printf-format-string-warnings.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/printf-format-string-warnings.cl?rev=343653&view=auto
==
--- cfe/trunk/test/SemaOpenCL/printf-format-string-warnings.cl (added)
+++ cfe/trunk/test/SemaOpenCL/printf-format-string-warnings.cl Tue Oct  2 
19:01:19 2018
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0 
-finclude-default-header
+
+// Make sure warnings are produced based on printf format strings.
+
+
+kernel void format_string_warnings(__constant char* arg) {
+
+  printf("%d", arg); // expected-warning {{format specifies type 'int' but the 
argument has type '__constant char *'}}
+
+  printf("not enough arguments %d %d", 4); // expected-warning {{more '%' 
conversions than data arguments}}
+
+  printf("too many arguments", 4); // expected-warning {{data argument not 
used by format string}}
+}


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


r351053 - [OpenCL] Set generic addr space of 'this' in special class members.

2019-01-14 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Mon Jan 14 03:44:22 2019
New Revision: 351053

URL: http://llvm.org/viewvc/llvm-project?rev=351053&view=rev
Log:
[OpenCL] Set generic addr space of 'this' in special class members.

Set address spaces of 'this' param correctly for implicit special
class members.

This also changes initialization conversion sequence to separate
address space conversion from other qualifiers in case of binding
reference to a temporary. In this case address space conversion  
should happen after the binding (unlike for other quals). This is
needed to materialize it correctly in the alloca address space.

Initial patch by Mikael Nilssoni!

Differential Revision: https://reviews.llvm.org/D56066


Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl
cfe/trunk/test/SemaOpenCLCXX/address-space-templates.cl

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=351053&r1=351052&r2=351053&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Jan 14 03:44:22 2019
@@ -307,6 +307,10 @@ class Sema {
   }
   bool shouldLinkPossiblyHiddenDecl(LookupResult &Old, const NamedDecl *New);
 
+  void setupImplicitSpecialMemberType(CXXMethodDecl *SpecialMem,
+  QualType ResultTy,
+  ArrayRef Args);
+
 public:
   typedef OpaquePtr DeclGroupPtrTy;
   typedef OpaquePtr TemplateTy;

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=351053&r1=351052&r2=351053&view=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Mon Jan 14 03:44:22 2019
@@ -1677,10 +1677,10 @@ bool CastExpr::CastConsistency() const {
 auto Ty = getType();
 auto SETy = getSubExpr()->getType();
 assert(getValueKindForType(Ty) == Expr::getValueKindForType(SETy));
-if (!isGLValue())
+if (isRValue()) {
   Ty = Ty->getPointeeType();
-if (!isGLValue())
   SETy = SETy->getPointeeType();
+}
 assert(!Ty.isNull() && !SETy.isNull() &&
Ty.getAddressSpace() != SETy.getAddressSpace());
 goto CheckNoBasePath;

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=351053&r1=351052&r2=351053&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Jan 14 03:44:22 2019
@@ -74,7 +74,7 @@ static CanQualType GetThisType(ASTContex
const CXXMethodDecl *MD) {
   QualType RecTy = Context.getTagDeclType(RD)->getCanonicalTypeInternal();
   if (MD)
-RecTy = Context.getAddrSpaceQualType(RecTy, 
MD->getType().getAddressSpace());
+RecTy = Context.getAddrSpaceQualType(RecTy, 
MD->getTypeQualifiers().getAddressSpace());
   return Context.getPointerType(CanQualType::CreateUnsafe(RecTy));
 }
 

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=351053&r1=351052&r2=351053&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jan 14 03:44:22 2019
@@ -3192,12 +3192,7 @@ bool Sema::MergeFunctionDecl(FunctionDec
   if (RequiresAdjustment) {
 const FunctionType *AdjustedType = New->getType()->getAs();
 AdjustedType = Context.adjustFunctionType(AdjustedType, NewTypeInfo);
-
-QualType AdjustedQT = QualType(AdjustedType, 0);
-LangAS AS = Old->getType().getAddressSpace();
-AdjustedQT = Context.getAddrSpaceQualType(AdjustedQT, AS);
-
-New->setType(AdjustedQT);
+New->setType(QualType(AdjustedType, 0));
 NewQType = Context.getCanonicalType(New->getType());
 NewType = cast(NewQType);
   }

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=351053&r1=351052&r2=351053&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Jan 14 03:44:22 2019
@@ -6551,8 +6551,11 @@ void Sema::CheckExplicitlyDefaultedSpeci
   if (CSM == CXXCopyAssignment || CSM == CXXMoveAssignment) {
 // Check for return type matching.
 ReturnType = Type->getReturnType();
-QualType ExpectedReturnType =
-Context.getLValueRefe

r351546 - [OpenCL] Fix overloading ranking rules for addrspace conversions.

2019-01-18 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Fri Jan 18 03:38:16 2019
New Revision: 351546

URL: http://llvm.org/viewvc/llvm-project?rev=351546&view=rev
Log:
[OpenCL] Fix overloading ranking rules for addrspace conversions.

Extend ranking to work with address spaces correctly when
resolving overloads.

Differential Revision: https://reviews.llvm.org/D56735


Added:
cfe/trunk/test/SemaOpenCLCXX/address_space_overloading.cl
Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=351546&r1=351545&r2=351546&view=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri Jan 18 03:38:16 2019
@@ -4019,9 +4019,12 @@ CompareQualificationConversions(Sema &S,
 // to unwrap. This essentially mimics what
 // IsQualificationConversion does, but here we're checking for a
 // strict subset of qualifiers.
-if (T1.getCVRQualifiers() == T2.getCVRQualifiers())
+if (T1.getQualifiers().withoutObjCLifetime() ==
+T2.getQualifiers().withoutObjCLifetime())
   // The qualifiers are the same, so this doesn't tell us anything
   // about how the sequences rank.
+  // ObjC ownership quals are omitted above as they interfere with
+  // the ARC overload rule.
   ;
 else if (T2.isMoreQualifiedThan(T1)) {
   // T1 has fewer qualifiers, so it could be the better sequence.

Added: cfe/trunk/test/SemaOpenCLCXX/address_space_overloading.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCLCXX/address_space_overloading.cl?rev=351546&view=auto
==
--- cfe/trunk/test/SemaOpenCLCXX/address_space_overloading.cl (added)
+++ cfe/trunk/test/SemaOpenCLCXX/address_space_overloading.cl Fri Jan 18 
03:38:16 2019
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=c++
+
+// expected-no-diagnostics
+
+struct RetGlob {
+  int dummy;
+};
+
+struct RetGen {
+  char dummy;
+};
+
+RetGlob foo(const __global int *);
+RetGen foo(const __generic int *);
+
+void kernel k() {
+  __global int *ArgGlob;
+  __generic int *ArgGen;
+  __local int *ArgLoc;
+  RetGlob TestGlob = foo(ArgGlob);
+  RetGen TestGen = foo(ArgGen);
+  TestGen = foo(ArgLoc);
+}


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


r351747 - [OpenCL] Allow address spaces as method qualifiers.

2019-01-21 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Mon Jan 21 08:01:38 2019
New Revision: 351747

URL: http://llvm.org/viewvc/llvm-project?rev=351747&view=rev
Log:
[OpenCL] Allow address spaces as method qualifiers.

Methods can now be qualified with address spaces to prevent
undesirable conversions to generic or to provide custom 
implementation to be used if the object is located in certain
memory segments.

This commit extends parsing and standard C++ overloading to
work for an address space of a method (i.e. implicit 'this'
parameter).

Differential Revision: https://reviews.llvm.org/D55850


Added:
cfe/trunk/test/CodeGenOpenCLCXX/method-overload-address-space.cl
cfe/trunk/test/SemaOpenCLCXX/address-space-of-this-class-scope.cl
cfe/trunk/test/SemaOpenCLCXX/method-overload-address-space.cl
Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/Sema/ParsedAttr.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaOpenCLCXX/address_space_overloading.cl

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=351747&r1=351746&r2=351747&view=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Jan 21 08:01:38 2019
@@ -1982,7 +1982,7 @@ public:
   bool isObjCQualifiedClassType() const;// Class
   bool isObjCObjectOrInterfaceType() const;
   bool isObjCIdType() const;// id
-
+  bool isDecltypeType() const;
   /// Was this type written with the special inert-in-ARC __unsafe_unretained
   /// qualifier?
   ///
@@ -6440,6 +6440,10 @@ inline bool Type::isObjCBuiltinType() co
   return isObjCIdType() || isObjCClassType() || isObjCSelType();
 }
 
+inline bool Type::isDecltypeType() const {
+  return isa(this);
+}
+
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
   inline bool Type::is##Id##Type() const { \
 return isSpecificBuiltinType(BuiltinType::Id); \

Modified: cfe/trunk/include/clang/Sema/ParsedAttr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ParsedAttr.h?rev=351747&r1=351746&r2=351747&view=diff
==
--- cfe/trunk/include/clang/Sema/ParsedAttr.h (original)
+++ cfe/trunk/include/clang/Sema/ParsedAttr.h Mon Jan 21 08:01:38 2019
@@ -567,6 +567,25 @@ public:
   /// parsed attribute does not have a semantic equivalent, or would not have
   /// a Spelling enumeration, the value UINT_MAX is returned.
   unsigned getSemanticSpelling() const;
+
+  /// If this is an OpenCL addr space attribute returns its representation
+  /// in LangAS, otherwise returns default addr space.
+  LangAS asOpenCLLangAS() const {
+switch (getKind()) {
+case ParsedAttr::AT_OpenCLConstantAddressSpace:
+  return LangAS::opencl_constant;
+case ParsedAttr::AT_OpenCLGlobalAddressSpace:
+  return LangAS::opencl_global;
+case ParsedAttr::AT_OpenCLLocalAddressSpace:
+  return LangAS::opencl_local;
+case ParsedAttr::AT_OpenCLPrivateAddressSpace:
+  return LangAS::opencl_private;
+case ParsedAttr::AT_OpenCLGenericAddressSpace:
+  return LangAS::opencl_generic;
+default:
+  return LangAS::Default;
+}
+  }
 };
 
 class AttributePool;

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=351747&r1=351746&r2=351747&view=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Jan 21 08:01:38 2019
@@ -6177,6 +6177,20 @@ void Parser::ParseFunctionDeclarator(Dec
   Qualifiers Q = Qualifiers::fromCVRUMask(DS.getTypeQualifiers());
   if (D.getDeclSpec().isConstexprSpecified() && !getLangOpts().CPlusPlus14)
 Q.addConst();
+  // FIXME: Collect C++ address spaces.
+  // If there are multiple different address spaces, the source is invalid.
+  // Carry on using the first addr space for the qualifiers of 'this'.
+  // The diagnostic will be given later while creating the function
+  // prototype for the method.
+  if (getLangOpts().OpenCLCPlusPlus) {
+for (ParsedAttr &attr : DS.getAttributes()) {
+  LangAS ASIdx = attr.asOpenCLLangAS();
+  if (ASIdx != LangAS::Default) {
+Q.addAddressSpace(ASIdx);
+break;
+  }
+}
+  }
 
   Sema::CXXThisScopeRAII ThisScope(
   Actions, dyn_cast(Actions.CurContext), Q,

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=351747&r1=351746&r2=351747&view=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cp

r352349 - Rename getTypeQualifiers to getMethodQualifiers.

2019-01-28 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Mon Jan 28 03:37:49 2019
New Revision: 352349

URL: http://llvm.org/viewvc/llvm-project?rev=352349&view=rev
Log:
Rename getTypeQualifiers to getMethodQualifiers.

Use more descriptive name for the method qualifiers getter.

Differential Revision: https://reviews.llvm.org/D56792


Modified:
cfe/trunk/include/clang/AST/CanonicalType.h
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/lib/AST/TypePrinter.cpp
cfe/trunk/lib/AST/VTableBuilder.cpp
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/Index/USRGeneration.cpp
cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/include/clang/AST/CanonicalType.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CanonicalType.h?rev=352349&r1=352348&r2=352349&view=diff
==
--- cfe/trunk/include/clang/AST/CanonicalType.h (original)
+++ cfe/trunk/include/clang/AST/CanonicalType.h Mon Jan 28 03:37:49 2019
@@ -509,7 +509,7 @@ struct CanProxyAdaptor;

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=352349&r1=352348&r2=352349&view=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Mon Jan 28 03:37:49 2019
@@ -2184,8 +2184,8 @@ public:
   static QualType getThisType(const FunctionProtoType *FPT,
   const CXXRecordDecl *Decl);
 
-  Qualifiers getTypeQualifiers() const {
-return getType()->getAs()->getTypeQuals();
+  Qualifiers getMethodQualifiers() const {
+return getType()->getAs()->getMethodQuals();
   }
 
   /// Retrieve the ref-qualifier associated with this method.

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=352349&r1=352348&r2=352349&view=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Jan 28 03:37:49 2019
@@ -3901,7 +3901,7 @@ public:
 EPI.Variadic = isVariadic();
 EPI.HasTrailingReturn = hasTrailingReturn();
 EPI.ExceptionSpec.Type = getExceptionSpecType();
-EPI.TypeQuals = getTypeQuals();
+EPI.TypeQuals = getMethodQuals();
 EPI.RefQualifier = getRefQualifier();
 if (EPI.ExceptionSpec.Type == EST_Dynamic) {
   EPI.ExceptionSpec.Exceptions = exceptions();
@@ -4011,7 +4011,7 @@ public:
   /// Whether this function prototype has a trailing return type.
   bool hasTrailingReturn() const { return FunctionTypeBits.HasTrailingReturn; }
 
-  Qualifiers getTypeQuals() const {
+  Qualifiers getMethodQuals() const {
 if (hasExtQualifiers())
   return *getTrailingObjects();
 else

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=352349&r1=352348&r2=352349&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Jan 28 03:37:49 2019
@@ -8580,7 +8580,7 @@ QualType ASTContext::mergeFunctionTypes(
 if (lproto->isVariadic() != rproto->isVariadic())
   return {};
 
-if (lproto->getTypeQuals() != rproto->getTypeQuals())
+if (lproto->getMethodQuals() != rproto->getMethodQuals())
   return {};
 
 SmallVector newParamInfos;

Modified: cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp?rev=352349&r1=352348&r2=352349&view=diff
==
--- cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp (original)
+++ cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp Mon Jan 28 03:37:49 2019
@@ -528,7 +528,7 @@ static bool IsStructurallyEquivalent(Str
 if (Proto1->isVariadic() != Proto2->isVariadic())
   return false;
 
-if (Proto1->getTypeQuals() != Proto2->getTypeQuals())
+if (Proto1->getMethodQuals() != Proto2->getMethodQuals())
   return false;
 
 // Check exceptions, this information is lost in canonical type.

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: 
http

r352617 - [OpenCL] Add generic addr space to the return of implicit assignment.

2019-01-30 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Wed Jan 30 03:18:08 2019
New Revision: 352617

URL: http://llvm.org/viewvc/llvm-project?rev=352617&view=rev
Log:
[OpenCL] Add generic addr space to the return of implicit assignment.

When creating the prototype of implicit assignment operators the
returned reference to the class should be qualified with the same
addr space as 'this' (i.e. __generic in OpenCL).

Differential Revision: https://reviews.llvm.org/D57101


Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl
cfe/trunk/test/SemaOpenCLCXX/address_space_overloading.cl

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=352617&r1=352616&r2=352617&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Jan 30 03:18:08 2019
@@ -11813,14 +11813,13 @@ CXXMethodDecl *Sema::DeclareImplicitCopy
 return nullptr;
 
   QualType ArgType = Context.getTypeDeclType(ClassDecl);
+  if (Context.getLangOpts().OpenCLCPlusPlus)
+ArgType = Context.getAddrSpaceQualType(ArgType, LangAS::opencl_generic);
   QualType RetType = Context.getLValueReferenceType(ArgType);
   bool Const = ClassDecl->implicitCopyAssignmentHasConstParam();
   if (Const)
 ArgType = ArgType.withConst();
 
-  if (Context.getLangOpts().OpenCLCPlusPlus)
-ArgType = Context.getAddrSpaceQualType(ArgType, LangAS::opencl_generic);
-
   ArgType = Context.getLValueReferenceType(ArgType);
 
   bool Constexpr = defaultedSpecialMemberIsConstexpr(*this, ClassDecl,
@@ -12138,6 +12137,8 @@ CXXMethodDecl *Sema::DeclareImplicitMove
   // constructor rules.
 
   QualType ArgType = Context.getTypeDeclType(ClassDecl);
+  if (Context.getLangOpts().OpenCLCPlusPlus)
+ArgType = Context.getAddrSpaceQualType(ArgType, LangAS::opencl_generic);
   QualType RetType = Context.getLValueReferenceType(ArgType);
   ArgType = Context.getRValueReferenceType(ArgType);
 

Modified: cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl?rev=352617&r1=352616&r2=352617&view=diff
==
--- cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl (original)
+++ cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl Wed Jan 30 03:18:08 
2019
@@ -1,25 +1,26 @@
-// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -emit-llvm 
-pedantic -verify -O0 -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -emit-llvm 
-pedantic -verify -O0 -o - -DDECL | FileCheck %s --check-prefixes="COMMON,EXPL"
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -emit-llvm 
-pedantic -verify -O0 -o - -DDECL -DUSE_DEFLT | FileCheck %s 
--check-prefixes="COMMON,IMPL"
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -emit-llvm 
-pedantic -verify -O0 -o - | FileCheck %s --check-prefixes="COMMON,IMPL"
 // expected-no-diagnostics
 
 // Test that the 'this' pointer is in the __generic address space.
 
-// FIXME: Add support for __constant address space.
+#ifdef USE_DEFLT
+#define DEFAULT =default
+#else
+#define DEFAULT
+#endif
 
 class C {
 public:
   int v;
-  C() { v = 2; }
-  C(C &&c) { v = c.v; }
-  C(const C &c) { v = c.v; }
-  C &operator=(const C &c) {
-v = c.v;
-return *this;
-  }
-  C &operator=(C &&c) & {
-v = c.v;
-return *this;
-  }
-
+#ifdef DECL
+  C() DEFAULT;
+  C(C &&c) DEFAULT;
+  C(const C &c) DEFAULT;
+  C &operator=(const C &c) DEFAULT;
+  C &operator=(C &&c) & DEFAULT;
+#endif
   C operator+(const C& c) {
 v += c.v;
 return *this;
@@ -30,6 +31,24 @@ public:
   int outside();
 };
 
+#if defined(DECL) && !defined(USE_DEFLT)
+C::C() { v = 2; };
+
+C::C(C &&c) { v = c.v; }
+
+C::C(const C &c) { v = c.v; }
+
+C &C::operator=(const C &c) {
+  v = c.v;
+  return *this;
+}
+
+C &C::operator=(C &&c) & {
+  v = c.v;
+  return *this;
+}
+#endif
+
 int C::outside() {
   return v;
 }
@@ -49,58 +68,76 @@ __kernel void test__global() {
   C c5 = foo();
 }
 
-// CHECK-LABEL: @__cxx_global_var_init()
-// CHECK: call void @_ZNU3AS41CC1Ev(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(1)* @c to %class.C addrspace(4)*))
+// Test that the address space is __generic for all members
+// EXPL: @_ZNU3AS41CC2Ev(%class.C addrspace(4)* %this)
+// EXPL: @_ZNU3AS41CC1Ev(%class.C addrspace(4)* %this)
+// EXPL: @_ZNU3AS41CC2EOU3AS4S_(%class.C addrspace(4)* %this
+// EXPL: @_ZNU3AS41CC1EOU3AS4S_(%class.C addrspace(4)* %this
+// EXPL: @_ZNU3AS41CC2ERU3AS4KS_(%class.C addrspace(4)* %this
+// EXPL: @_ZNU3AS41CC1ERU3AS4KS_(%class.C addrspace(4)* %this
+// EXPL: @_ZNU3AS41CaSERU3AS4KS_(%class.C addrspace(4)* %this
+// EXPL: @_ZNU3AS4R1CaSEOU3AS4S_(%class.C addrspace(4)* %this
+// COMMON: @_ZNU3AS41C7outsideEv(%class.C addrspace(4)* %this

r352760 - [OpenCL] Fixed addr space manging test.

2019-01-31 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu Jan 31 07:23:48 2019
New Revision: 352760

URL: http://llvm.org/viewvc/llvm-project?rev=352760&view=rev
Log:
[OpenCL] Fixed addr space manging test.

Fixed typo in the Filecheck directive and changed the
test to verify output correctly.

Fixes PR40029!


Modified:
cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl

Modified: cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl?rev=352760&r1=352759&r2=352760&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl Thu Jan 31 07:23:48 
2019
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 %s -ffake-address-space-map 
-faddress-space-map-mangling=yes -triple %itanium_abi_triple -emit-llvm -o - | 
FileCheck -check-prefixes=ASMANG,ASMAN10 %s
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map 
-faddress-space-map-mangling=yes -triple %itanium_abi_triple -emit-llvm -o - | 
FileCheck -check-prefixes=ASMANG,ASMAN20 %s
-// RUN: %clang_cc1 %s -ffake-address-space-map -faddress-space-map-mangling=no 
-triple %itanium_abi_triple -emit-llvm -o - | FileCheck 
-check-prefixes=NOASMANG,NOASMAN10 %s
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map 
-faddress-space-map-mangling=no -triple %itanium_abi_triple -emit-llvm -o - | 
FileCheck -check-prefixes=NOASMANG,NOASMAN20 %s
+// RUN: %clang_cc1 %s -ffake-address-space-map 
-faddress-space-map-mangling=yes -triple %itanium_abi_triple -emit-llvm -o - | 
FileCheck -check-prefixes="ASMANG,ASMANG10" %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map 
-faddress-space-map-mangling=yes -triple %itanium_abi_triple -emit-llvm -o - | 
FileCheck -check-prefixes="ASMANG,ASMANG20" %s
+// RUN: %clang_cc1 %s -ffake-address-space-map -faddress-space-map-mangling=no 
-triple %itanium_abi_triple -emit-llvm -o - | FileCheck 
-check-prefixes="NOASMANG,NOASMANG10" %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map 
-faddress-space-map-mangling=no -triple %itanium_abi_triple -emit-llvm -o - | 
FileCheck -check-prefixes="NOASMANG,NOASMANG20" %s
 
 // We check that the address spaces are mangled the same in both version of 
OpenCL
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=CL2.0 -emit-llvm -o 
- | FileCheck -check-prefix=OCL-20 %s
@@ -14,7 +14,7 @@ __attribute__((overloadable))
 void ff(int *arg) { }
 // ASMANG10: @_Z2ffPi
 // ASMANG20: @_Z2ffPU3AS4i
-// NOASMANG10: @_Z2ffPi
+// NOASMANG10: @_Z2ffPU9CLprivatei
 // NOASMANG20: @_Z2ffPU9CLgenerici
 // OCL-20-DAG: @_Z2ffPU3AS4i
 // OCL-12-DAG: @_Z2ffPi


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


r347059 - [OpenCL] Enable address spaces for references in C++

2018-11-16 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Fri Nov 16 08:22:56 2018
New Revision: 347059

URL: http://llvm.org/viewvc/llvm-project?rev=347059&view=rev
Log:
[OpenCL] Enable address spaces for references in C++

Added references to the addr spaces deduction and enabled
CL2.0 features (program scope variables and storage class
qualifiers) to work in C++ mode too.

Fixed several address space conversion issues in CodeGen 
for references.

Differential Revision: https://reviews.llvm.org/D53764


Added:
cfe/trunk/test/CodeGenOpenCLCXX/
cfe/trunk/test/CodeGenOpenCLCXX/address-space-deduction.cl
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/Sema/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=347059&r1=347058&r2=347059&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Nov 16 08:22:56 2018
@@ -9631,6 +9631,10 @@ public:
AssignmentAction Action,
CheckedConversionKind CCK);
 
+  ExprResult PerformQualificationConversion(
+  Expr *E, QualType Ty, ExprValueKind VK = VK_RValue,
+  CheckedConversionKind CCK = CCK_ImplicitConversion);
+
   /// the following "Check" methods will return a valid/converted QualType
   /// or a null QualType (indicating an error diagnostic was issued).
 

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=347059&r1=347058&r2=347059&view=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Fri Nov 16 08:22:56 2018
@@ -1634,13 +1634,18 @@ bool CastExpr::CastConsistency() const {
 assert(getSubExpr()->getType()->isFunctionType());
 goto CheckNoBasePath;
 
-  case CK_AddressSpaceConversion:
-assert(getType()->isPointerType() || getType()->isBlockPointerType());
-assert(getSubExpr()->getType()->isPointerType() ||
-   getSubExpr()->getType()->isBlockPointerType());
-assert(getType()->getPointeeType().getAddressSpace() !=
-   getSubExpr()->getType()->getPointeeType().getAddressSpace());
-LLVM_FALLTHROUGH;
+  case CK_AddressSpaceConversion: {
+auto Ty = getType();
+auto SETy = getSubExpr()->getType();
+assert(getValueKindForType(Ty) == Expr::getValueKindForType(SETy));
+if (!isGLValue())
+  Ty = Ty->getPointeeType();
+if (!isGLValue())
+  SETy = SETy->getPointeeType();
+assert(!Ty.isNull() && !SETy.isNull() &&
+   Ty.getAddressSpace() != SETy.getAddressSpace());
+goto CheckNoBasePath;
+  }
   // These should not have an inheritance path.
   case CK_Dynamic:
   case CK_ToUnion:

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=347059&r1=347058&r2=347059&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Nov 16 08:22:56 2018
@@ -4163,7 +4163,6 @@ LValue CodeGenFunction::EmitCastLValue(c
   case CK_ARCReclaimReturnedObject:
   case CK_ARCExtendBlockObject:
   case CK_CopyAndAutoreleaseBlockObject:
-  case CK_AddressSpaceConversion:
   case CK_IntToOCLSampler:
   case CK_FixedPointCast:
   case CK_FixedPointToBoolean:
@@ -4260,6 +4259,14 @@ LValue CodeGenFunction::EmitCastLValue(c
 return MakeAddrLValue(V, E->getType(), LV.getBaseInfo(),
   CGM.getTBAAInfoForSubobject(LV, E->getType()));
   }
+  case CK_AddressSpaceConversion: {
+LValue LV = EmitLValue(E->getSubExpr());
+QualType DestTy = getContext().getPointerType(E->getType());
+llvm::Value *V = getTargetHooks().performAddrSpaceCast(
+*this, LV.getPointer(), E->getSubExpr()->getType().getAddressSpace(),
+DestTy.getAddressSpace(), ConvertType(DestTy));
+return MakeNaturalAlignPointeeAddrLValue(V, DestTy);
+  }
   case CK_ObjCObjectLValueCast: {
 LValue LV = EmitLValue(E->getSubExpr());
 Address V = Builder.CreateElementBitCast(LV.getAddress(),

Modified: cfe/trunk/lib/Sema/DeclSpec.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/DeclSpec.cpp?rev=347059&r1=347058&r2=347059&view=diff
==
--- cfe/trunk/lib/Sema/DeclSpec.cpp (original)
+++ cfe/trunk/lib/Sema/DeclSpec.cpp Fri Nov 16 08:22:56 2018
@@ -566,14 +566,16 @@ bool DeclSpec::SetStorageClassSpec(Sema
   // these storage-class specifiers.
   // OpenCL v1.2 s6.8 changes this to 

r347189 - [OpenCL] Fix address space deduction in template args.

2018-11-19 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Mon Nov 19 03:00:14 2018
New Revision: 347189

URL: http://llvm.org/viewvc/llvm-project?rev=347189&view=rev
Log:
[OpenCL] Fix address space deduction in template args.

Don't deduce address spaces for non-pointer-like types
in template args.

Fixes PR38603!

Differential Revision: https://reviews.llvm.org/D54634


Added:
cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl
Modified:
cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=347189&r1=347188&r2=347189&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Nov 19 03:00:14 2018
@@ -7227,7 +7227,9 @@ static void deduceOpenCLImplicitAddrSpac
 if (IsPointee) {
   ImpAddr = LangAS::opencl_generic;
 } else {
-  if (D.getContext() == DeclaratorContext::FileContext) {
+  if (D.getContext() == DeclaratorContext::TemplateArgContext) {
+// Do not deduce address space for non-pointee type in template args
+  } else if (D.getContext() == DeclaratorContext::FileContext) {
 ImpAddr = LangAS::opencl_global;
   } else {
 if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||

Added: cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl?rev=347189&view=auto
==
--- cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl (added)
+++ cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl Mon Nov 19 
03:00:14 2018
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -cl-std=c++ %s -emit-llvm -o - -O0 -triple 
spir-unknown-unknown | FileCheck %s
+
+template 
+struct S{
+  T a;
+  T foo();
+};
+
+template
+T S::foo() { return a;}
+
+//CHECK: %struct.S = type { i32 }
+//CHECK: %struct.S.0 = type { i32 addrspace(4)* }
+//CHECK: %struct.S.1 = type { i32 addrspace(1)* }
+
+//CHECK: i32 @_ZN1SIiE3fooEv(%struct.S* %this)
+//CHECK: i32 addrspace(4)* @_ZN1SIPU3AS4iE3fooEv(%struct.S.0* %this)
+//CHECK: i32 addrspace(1)* @_ZN1SIPU3AS1iE3fooEv(%struct.S.1* %this)
+
+void bar(){
+  S sint;
+  S sintptr;
+  S<__global int*> sintptrgl;
+  // FIXME: Preserve AS in TreeTransform
+  //S<__global int> sintgl;
+
+  sint.foo();
+  sintptr.foo();
+  sintptrgl.foo();
+  //sintgl.foo();
+}


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


Re: r347189 - [OpenCL] Fix address space deduction in template args.

2018-11-19 Thread Anastasia Stulova via cfe-commits
Hi Benjamin,


Thanks for reporting the issues, I think this should fix it:


diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index 1fe553000b..9ff631401f 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -7201,7 +7201,7 @@ static void 
deduceOpenCLImplicitAddrSpace(TypeProcessingState &State,
   (T->isVoidType() && !IsPointee))
 return;

-  LangAS ImpAddr;
+  LangAS ImpAddr = LangAS::Default;
   // Put OpenCL automatic variable in private address space.
   // OpenCL v1.2 s6.5:
   // The default address space name for arguments to a function in a

I am trying to reproduce and test the problem now to commit the fix.

Cheers,
Anastasia



From: Benjamin Kramer 
Sent: 19 November 2018 11:08
To: Anastasia Stulova
Cc: cfe-commits
Subject: Re: r347189 - [OpenCL] Fix address space deduction in template args.

clang gives me this:

llvm/tools/clang/lib/Sema/SemaType.cpp:7230:11: error: variable 'ImpAddr' is 
used uninitialized whenever 'if' condition is true 
[-Werror,-Wsometimes-uninitialized]
  if (D.getContext() == DeclaratorContext::TemplateArgContext) {
  ^~~
llvm/tools/clang/lib/Sema/SemaType.cpp:7244:55: note: uninitialized use occurs 
here
  T = State.getSema().Context.getAddrSpaceQualType(T, ImpAddr);
  ^~~
llvm/tools/clang/lib/Sema/SemaType.cpp:7230:7: note: remove the 'if' if its 
condition is always false
  if (D.getContext() == DeclaratorContext::TemplateArgContext) {
  ^~
llvm/tools/clang/lib/Sema/SemaType.cpp:7208:3: note: variable 'ImpAddr' is 
declared here
  LangAS ImpAddr;

On Mon, Nov 19, 2018 at 12:02 PM Anastasia Stulova via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:
Author: stulova
Date: Mon Nov 19 03:00:14 2018
New Revision: 347189

URL: http://llvm.org/viewvc/llvm-project?rev=347189&view=rev
Log:
[OpenCL] Fix address space deduction in template args.

Don't deduce address spaces for non-pointer-like types
in template args.

Fixes PR38603!

Differential Revision: https://reviews.llvm.org/D54634


Added:

cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl<http://template-address-spaces.cl>
Modified:
cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=347189&r1=347188&r2=347189&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Nov 19 03:00:14 2018
@@ -7227,7 +7227,9 @@ static void deduceOpenCLImplicitAddrSpac
 if (IsPointee) {
   ImpAddr = LangAS::opencl_generic;
 } else {
-  if (D.getContext() == DeclaratorContext::FileContext) {
+  if (D.getContext() == DeclaratorContext::TemplateArgContext) {
+// Do not deduce address space for non-pointee type in template args
+  } else if (D.getContext() == DeclaratorContext::FileContext) {
 ImpAddr = LangAS::opencl_global;
   } else {
 if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||

Added: 
cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl<http://template-address-spaces.cl>
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl?rev=347189&view=auto
==
--- 
cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl<http://template-address-spaces.cl>
 (added)
+++ 
cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl<http://template-address-spaces.cl>
 Mon Nov 19 03:00:14 2018
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -cl-std=c++ %s -emit-llvm -o - -O0 -triple 
spir-unknown-unknown | FileCheck %s
+
+template 
+struct S{
+  T a;
+  T foo();
+};
+
+template
+T S::foo() { return a;}
+
+//CHECK: %struct.S = type { i32 }
+//CHECK: %struct.S.0 = type { i32 addrspace(4)* }
+//CHECK: %struct.S.1 = type { i32 addrspace(1)* }
+
+//CHECK: i32 @_ZN1SIiE3fooEv(%struct.S* %this)
+//CHECK: i32 addrspace(4)* @_ZN1SIPU3AS4iE3fooEv(%struct.S.0* %this)
+//CHECK: i32 addrspace(1)* @_ZN1SIPU3AS1iE3fooEv(%struct.S.1* %this)
+
+void bar(){
+  S sint;
+  S sintptr;
+  S<__global int*> sintptrgl;
+  // FIXME: Preserve AS in TreeTransform
+  //S<__global int> sintgl;
+
+  sint.foo();
+  sintptr.foo();
+  sintptrgl.foo();
+  //sintgl.foo();
+}


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


r347196 - Fixed uninitialized variable issue.

2018-11-19 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Mon Nov 19 04:43:39 2018
New Revision: 347196

URL: http://llvm.org/viewvc/llvm-project?rev=347196&view=rev
Log:
Fixed uninitialized variable issue.

This commit should fix failing bots.


Modified:
cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=347196&r1=347195&r2=347196&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Nov 19 04:43:39 2018
@@ -7205,7 +7205,7 @@ static void deduceOpenCLImplicitAddrSpac
   (T->isVoidType() && !IsPointee))
 return;
 
-  LangAS ImpAddr;
+  LangAS ImpAddr = LangAS::Default;
   // Put OpenCL automatic variable in private address space.
   // OpenCL v1.2 s6.5:
   // The default address space name for arguments to a function in a


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


r347865 - [OpenCL] Improve diags for addr spaces in templates

2018-11-29 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu Nov 29 06:11:15 2018
New Revision: 347865

URL: http://llvm.org/viewvc/llvm-project?rev=347865&view=rev
Log:
[OpenCL] Improve diags for addr spaces in templates

Fix ICEs on template instantiations that were leading to
the creation of invalid code patterns with address spaces.

Incorrect cases are now diagnosed properly.

Differential Revision: https://reviews.llvm.org/D54858


Added:
cfe/trunk/test/SemaOpenCLCXX/address-space-templates.cl
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=347865&r1=347864&r2=347865&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Nov 29 06:11:15 2018
@@ -15148,22 +15148,6 @@ FieldDecl *Sema::HandleField(Scope *S, R
 }
   }
 
-  // TR 18037 does not allow fields to be declared with address spaces.
-  if (T.getQualifiers().hasAddressSpace() ||
-  T->isDependentAddressSpaceType() ||
-  T->getBaseElementTypeUnsafe()->isDependentAddressSpaceType()) {
-Diag(Loc, diag::err_field_with_address_space);
-D.setInvalidType();
-  }
-
-  // OpenCL v1.2 s6.9b,r & OpenCL v2.0 s6.12.5 - The following types cannot be
-  // used as structure or union field: image, sampler, event or block types.
-  if (LangOpts.OpenCL && (T->isEventT() || T->isImageType() ||
-  T->isSamplerT() || T->isBlockPointerType())) {
-Diag(Loc, diag::err_opencl_type_struct_or_union_field) << T;
-D.setInvalidType();
-  }
-
   DiagnoseFunctionSpecifiers(D.getDeclSpec());
 
   if (D.getDeclSpec().isInlineSpecified())
@@ -15275,12 +15259,30 @@ FieldDecl *Sema::CheckFieldDecl(Declarat
 }
   }
 
-  // OpenCL v1.2 s6.9.c: bitfields are not supported.
-  if (BitWidth && getLangOpts().OpenCL) {
-Diag(Loc, diag::err_opencl_bitfields);
+  // TR 18037 does not allow fields to be declared with address space
+  if (T.getQualifiers().hasAddressSpace() || T->isDependentAddressSpaceType() 
||
+  T->getBaseElementTypeUnsafe()->isDependentAddressSpaceType()) {
+Diag(Loc, diag::err_field_with_address_space);
+Record->setInvalidDecl();
 InvalidDecl = true;
   }
 
+  if (LangOpts.OpenCL) {
+// OpenCL v1.2 s6.9b,r & OpenCL v2.0 s6.12.5 - The following types cannot 
be
+// used as structure or union field: image, sampler, event or block types.
+if (T->isEventT() || T->isImageType() || T->isSamplerT() ||
+T->isBlockPointerType()) {
+  Diag(Loc, diag::err_opencl_type_struct_or_union_field) << T;
+  Record->setInvalidDecl();
+  InvalidDecl = true;
+}
+// OpenCL v1.2 s6.9.c: bitfields are not supported.
+if (BitWidth) {
+  Diag(Loc, diag::err_opencl_bitfields);
+  InvalidDecl = true;
+}
+  }
+
   // Anonymous bit-fields cannot be cv-qualified (CWG 2229).
   if (!InvalidDecl && getLangOpts().CPlusPlus && !II && BitWidth &&
   T.hasQualifiers()) {

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=347865&r1=347864&r2=347865&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Nov 29 06:11:15 2018
@@ -7226,8 +7226,9 @@ static void deduceOpenCLImplicitAddrSpac
 if (IsPointee) {
   ImpAddr = LangAS::opencl_generic;
 } else {
-  if (D.getContext() == DeclaratorContext::TemplateArgContext) {
-// Do not deduce address space for non-pointee type in template args
+  if (D.getContext() == DeclaratorContext::TemplateArgContext ||
+  T->isDependentType()) {
+// Do not deduce address space for non-pointee type in templates.
   } else if (D.getContext() == DeclaratorContext::FileContext) {
 ImpAddr = LangAS::opencl_global;
   } else {

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=347865&r1=347864&r2=347865&view=diff
==
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Thu Nov 29 06:11:15 2018
@@ -5284,6 +5284,13 @@ QualType TreeTransform::Transfo
 if (ResultType.isNull())
   return QualType();
 
+// Return type can not be qualified with an address space.
+if (ResultType.getAddressSpace() != LangAS::Default) {
+  SemaRef.Diag(TL.getReturnLoc().getBeginLoc(),
+   diag::err_attribute_address_function_type);
+  return QualType();
+}
+
 if (getDerived().TransformFunctionTypeParams(
 TL.getBeginLoc(), TL.getParams(),
 T

r348382 - [OpenCL] Diagnose conflicting address spaces in templates.

2018-12-05 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Wed Dec  5 09:02:22 2018
New Revision: 348382

URL: http://llvm.org/viewvc/llvm-project?rev=348382&view=rev
Log:
[OpenCL] Diagnose conflicting address spaces in templates.

Added new diagnostic when templates are instantiated with
different address space from the one provided in its definition.

This also prevents deducing generic address space in pointer
type of templates to allow giving them concrete address space
during instantiation.

Differential Revision: https://reviews.llvm.org/D55127


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/SemaOpenCLCXX/address-space-templates.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=348382&r1=348381&r2=348382&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Dec  5 09:02:22 
2018
@@ -2634,6 +2634,8 @@ def err_field_with_address_space : Error
   "field may not be qualified with an address space">;
 def err_compound_literal_with_address_space : Error<
   "compound literal in function scope may not be qualified with an address 
space">;
+def err_address_space_mismatch_templ_inst : Error<
+  "conflicting address space qualifiers are provided between types %0 and %1">;
 def err_attr_objc_ownership_redundant : Error<
   "the type %0 is already explicitly ownership-qualified">;
 def err_invalid_nsnumber_type : Error<

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=348382&r1=348381&r2=348382&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Dec  5 09:02:22 2018
@@ -7201,7 +7201,10 @@ static void deduceOpenCLImplicitAddrSpac
!IsPointee) ||
   // Do not deduce addr space of the void type, e.g. in f(void), otherwise
   // it will fail some sema check.
-  (T->isVoidType() && !IsPointee))
+  (T->isVoidType() && !IsPointee) ||
+  // Do not deduce address spaces for dependent types because they might 
end
+  // up instantiating to a type with an explicit address space qualifier.
+  T->isDependentType())
 return;
 
   LangAS ImpAddr = LangAS::Default;
@@ -7226,9 +7229,8 @@ static void deduceOpenCLImplicitAddrSpac
 if (IsPointee) {
   ImpAddr = LangAS::opencl_generic;
 } else {
-  if (D.getContext() == DeclaratorContext::TemplateArgContext ||
-  T->isDependentType()) {
-// Do not deduce address space for non-pointee type in templates.
+  if (D.getContext() == DeclaratorContext::TemplateArgContext) {
+// Do not deduce address space for non-pointee type in template arg.
   } else if (D.getContext() == DeclaratorContext::FileContext) {
 ImpAddr = LangAS::opencl_global;
   } else {

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=348382&r1=348381&r2=348382&view=diff
==
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Wed Dec  5 09:02:22 2018
@@ -684,15 +684,13 @@ public:
   OMPClause *Transform ## Class(Class *S);
 #include "clang/Basic/OpenMPKinds.def"
 
-  /// Build a new qualified type given its unqualified type and type
-  /// qualifiers.
+  /// Build a new qualified type given its unqualified type and type location.
   ///
   /// By default, this routine adds type qualifiers only to types that can
   /// have qualifiers, and silently suppresses those qualifiers that are not
   /// permitted. Subclasses may override this routine to provide different
   /// behavior.
-  QualType RebuildQualifiedType(QualType T, SourceLocation Loc,
-Qualifiers Quals);
+  QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL);
 
   /// Build a new pointer type given its pointee type.
   ///
@@ -4228,8 +4226,9 @@ TreeTransform::TransformTypeWit
 return nullptr;
 
   if (QTL) {
-Result = getDerived().RebuildQualifiedType(
-Result, QTL.getBeginLoc(), QTL.getType().getLocalQualifiers());
+Result = getDerived().RebuildQualifiedType(Result, QTL);
+if (Result.isNull())
+  return nullptr;
 TLB.TypeWasModifiedSafely(Result);
   }
 
@@ -4240,13 +4239,14 @@ template
 QualType
 TreeTransform::TransformQualifiedType(TypeLocBuilder &TLB,
QualifiedTypeLoc T) {
-  Qualifiers Quals = T.getType().getLocalQualifiers();
-
   QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
   if (

r355499 - [PR40778] Add addr space conversion when binding reference to a temporary.

2019-03-06 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Wed Mar  6 05:02:41 2019
New Revision: 355499

URL: http://llvm.org/viewvc/llvm-project?rev=355499&view=rev
Log:
[PR40778] Add addr space conversion when binding reference to a temporary.

This change fixes temporary materialization to happen in the right
(default) address space when binding to it a reference of different type.

It adds address space conversion afterwards to match the addr space
of a reference.

Differential Revision: https://reviews.llvm.org/D58634


Added:
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-references.cl
Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/Sema/SemaInit.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=355499&r1=355498&r2=355499&view=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Wed Mar  6 05:02:41 2019
@@ -317,6 +317,11 @@ public:
 qs.removeObjCLifetime();
 return qs;
   }
+  Qualifiers withoutAddressSpace() const {
+Qualifiers qs = *this;
+qs.removeAddressSpace();
+return qs;
+  }
 
   bool hasObjCLifetime() const { return Mask & LifetimeMask; }
   ObjCLifetime getObjCLifetime() const {

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=355499&r1=355498&r2=355499&view=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Mar  6 05:02:41 2019
@@ -4760,7 +4760,15 @@ static void TryReferenceInitializationCo
   //copy-initialization (8.5). The reference is then bound to the
   //temporary. [...]
 
-  InitializedEntity TempEntity = InitializedEntity::InitializeTemporary(cv1T1);
+  // Ignore address space of reference type at this point and perform address
+  // space conversion after the reference binding step.
+  QualType cv1T1IgnoreAS =
+  T1Quals.hasAddressSpace()
+  ? S.Context.getQualifiedType(T1, T1Quals.withoutAddressSpace())
+  : cv1T1;
+
+  InitializedEntity TempEntity =
+  InitializedEntity::InitializeTemporary(cv1T1IgnoreAS);
 
   // FIXME: Why do we use an implicit conversion here rather than trying
   // copy-initialization?
@@ -4795,8 +4803,9 @@ static void TryReferenceInitializationCo
   //than, cv2; otherwise, the program is ill-formed.
   unsigned T1CVRQuals = T1Quals.getCVRQualifiers();
   unsigned T2CVRQuals = T2Quals.getCVRQualifiers();
-  if (RefRelationship == Sema::Ref_Related &&
-  (T1CVRQuals | T2CVRQuals) != T1CVRQuals) {
+  if ((RefRelationship == Sema::Ref_Related &&
+   (T1CVRQuals | T2CVRQuals) != T1CVRQuals) ||
+  !T1Quals.isAddressSpaceSupersetOf(T2Quals)) {
 
Sequence.SetFailed(InitializationSequence::FK_ReferenceInitDropsQualifiers);
 return;
   }
@@ -4810,7 +4819,11 @@ static void TryReferenceInitializationCo
 return;
   }
 
-  Sequence.AddReferenceBindingStep(cv1T1, /*bindingTemporary=*/true);
+  Sequence.AddReferenceBindingStep(cv1T1IgnoreAS, /*bindingTemporary=*/true);
+
+  if (T1Quals.hasAddressSpace())
+Sequence.AddQualificationConversionStep(cv1T1, isLValueRef ? VK_LValue
+   : VK_XValue);
 }
 
 /// Attempt character array initialization from a string literal

Added: cfe/trunk/test/CodeGenOpenCLCXX/addrspace-references.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/addrspace-references.cl?rev=355499&view=auto
==
--- cfe/trunk/test/CodeGenOpenCLCXX/addrspace-references.cl (added)
+++ cfe/trunk/test/CodeGenOpenCLCXX/addrspace-references.cl Wed Mar  6 05:02:41 
2019
@@ -0,0 +1,14 @@
+//RUN: %clang_cc1 %s -cl-std=c++ -triple spir -emit-llvm -o - | FileCheck %s
+
+int bar(const unsigned int &i);
+// CHECK-LABEL: define spir_func void @_Z3foov() 
+void foo() {
+  // The generic addr space reference parameter object will be bound
+  // to a temporary value allocated in private addr space. We need an
+  // addrspacecast before passing the value to the function.
+  // CHECK: [[REF:%.*]] = alloca i32
+  // CHECK: store i32 1, i32* [[REF]]
+  // CHECK: [[REG:%[0-9]+]] = addrspacecast i32* [[REF]] to i32 addrspace(4)*
+  // CHECK: call spir_func i32 @_Z3barRU3AS4Kj(i32 addrspace(4)* nonnull 
dereferenceable(4) [[REG]])
+  bar(1);
+}


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


r355606 - [PR40778] Preserve addr space in Derived to Base cast.

2019-03-07 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu Mar  7 08:23:15 2019
New Revision: 355606

URL: http://llvm.org/viewvc/llvm-project?rev=355606&view=rev
Log:
[PR40778] Preserve addr space in Derived to Base cast.

The address space for the Base class pointer when up-casting
from Derived should be taken from the Derived class pointer.

Differential Revision: https://reviews.llvm.org/D53818


Added:
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
Modified:
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=355606&r1=355605&r2=355606&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Thu Mar  7 08:23:15 2019
@@ -302,7 +302,8 @@ Address CodeGenFunction::GetAddressOfBas
 
   // Get the base pointer type.
   llvm::Type *BasePtrTy =
-ConvertType((PathEnd[-1])->getType())->getPointerTo();
+  ConvertType((PathEnd[-1])->getType())
+  ->getPointerTo(Value.getType()->getPointerAddressSpace());
 
   QualType DerivedTy = getContext().getRecordType(Derived);
   CharUnits DerivedAlign = CGM.getClassPointerAlignment(Derived);

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=355606&r1=355605&r2=355606&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Mar  7 08:23:15 2019
@@ -2660,10 +2660,15 @@ Sema::PerformObjectMemberConversion(Expr
   bool PointerConversions = false;
   if (isa(Member)) {
 DestRecordType = Context.getCanonicalType(Context.getTypeDeclType(RD));
+auto FromPtrType = FromType->getAs();
+DestRecordType = Context.getAddrSpaceQualType(
+DestRecordType, FromPtrType
+? FromType->getPointeeType().getAddressSpace()
+: FromType.getAddressSpace());
 
-if (FromType->getAs()) {
+if (FromPtrType) {
   DestType = Context.getPointerType(DestRecordType);
-  FromRecordType = FromType->getPointeeType();
+  FromRecordType = FromPtrType->getPointeeType();
   PointerConversions = true;
 } else {
   DestType = DestRecordType;

Added: cfe/trunk/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/addrspace-derived-base.cl?rev=355606&view=auto
==
--- cfe/trunk/test/CodeGenOpenCLCXX/addrspace-derived-base.cl (added)
+++ cfe/trunk/test/CodeGenOpenCLCXX/addrspace-derived-base.cl Thu Mar  7 
08:23:15 2019
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 %s -triple spir -cl-std=c++ -emit-llvm -O0 -o - | FileCheck 
%s
+
+struct B {
+  int mb;
+};
+
+class D : public B {
+public:
+  int getmb() { return mb; }
+};
+
+void foo() {
+  D d;
+  //CHECK: addrspacecast %class.D* %d to %class.D addrspace(4)*
+  //CHECK: call i32 @_ZNU3AS41D5getmbEv(%class.D addrspace(4)*
+  d.getmb();
+}
+
+//Derived and Base are in the same address space.
+
+//CHECK: define linkonce_odr i32 @_ZNU3AS41D5getmbEv(%class.D addrspace(4)* 
%this)
+//CHECK: bitcast %class.D addrspace(4)* %this1 to %struct.B addrspace(4)*


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


r355608 - [PR40778][Sema] Adjust addr space of operands in builtin operators.

2019-03-07 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu Mar  7 08:43:41 2019
New Revision: 355608

URL: http://llvm.org/viewvc/llvm-project?rev=355608&view=rev
Log:
[PR40778][Sema] Adjust addr space of operands in builtin operators.

Adjust address space for references and pointer operands of builtin operators.

Currently this change only fixes addr space in assignment (= and |=) operator,
that is needed for the test case reported in the bug. Wider support for all
other operations will follow.

Differential Revision: https://reviews.llvm.org/D58719


Added:
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-operators.cl
Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=355608&r1=355607&r2=355608&view=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Mar  7 08:43:41 2019
@@ -7659,6 +7659,12 @@ BuiltinCandidateTypeSet::AddTypesConvert
 }
   }
 }
+/// Helper function for adjusting address spaces for the pointer or reference
+/// operands of builtin operators depending on the argument.
+static QualType AdjustAddressSpaceForBuiltinOperandType(Sema &S, QualType T,
+Expr *Arg) {
+  return S.Context.getAddrSpaceQualType(T, Arg->getType().getAddressSpace());
+}
 
 /// Helper function for AddBuiltinOperatorCandidates() that adds
 /// the volatile- and non-volatile-qualified assignment operators for the
@@ -7670,15 +7676,17 @@ static void AddBuiltinAssignmentOperator
   QualType ParamTypes[2];
 
   // T& operator=(T&, T)
-  ParamTypes[0] = S.Context.getLValueReferenceType(T);
+  ParamTypes[0] = S.Context.getLValueReferenceType(
+  AdjustAddressSpaceForBuiltinOperandType(S, T, Args[0]));
   ParamTypes[1] = T;
   S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet,
 /*IsAssignmentOperator=*/true);
 
   if (!S.Context.getCanonicalType(T).isVolatileQualified()) {
 // volatile T& operator=(volatile T&, T)
-ParamTypes[0]
-  = S.Context.getLValueReferenceType(S.Context.getVolatileType(T));
+ParamTypes[0] = S.Context.getLValueReferenceType(
+AdjustAddressSpaceForBuiltinOperandType(S, 
S.Context.getVolatileType(T),
+Args[0]));
 ParamTypes[1] = T;
 S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet,
   /*IsAssignmentOperator=*/true);
@@ -8573,8 +8581,9 @@ public:
 ParamTypes[1] = ArithmeticTypes[Right];
 
 // Add this built-in operator as a candidate (VQ is empty).
-ParamTypes[0] =
-  S.Context.getLValueReferenceType(ArithmeticTypes[Left]);
+ParamTypes[0] = S.Context.getLValueReferenceType(
+AdjustAddressSpaceForBuiltinOperandType(S, ArithmeticTypes[Left],
+Args[0]));
 S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet);
 if (VisibleTypeConversionsQuals.hasVolatile()) {
   // Add this built-in operator as a candidate (VQ is 'volatile').

Added: cfe/trunk/test/CodeGenOpenCLCXX/addrspace-operators.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/addrspace-operators.cl?rev=355608&view=auto
==
--- cfe/trunk/test/CodeGenOpenCLCXX/addrspace-operators.cl (added)
+++ cfe/trunk/test/CodeGenOpenCLCXX/addrspace-operators.cl Thu Mar  7 08:43:41 
2019
@@ -0,0 +1,46 @@
+//RUN: %clang_cc1 %s -triple spir -cl-std=c++ -emit-llvm -O0 -o - | FileCheck 
%s
+
+enum E {
+  a,
+  b,
+};
+
+class C {
+public:
+  void Assign(E e) { me = e; }
+  void OrAssign(E e) { mi |= e; }
+  E me;
+  int mi;
+};
+
+__global E globE;
+//CHECK-LABEL: define spir_func void @_Z3barv()
+void bar() {
+  C c;
+  //CHECK: addrspacecast %class.C* %c to %class.C addrspace(4)*
+  //CHECK: call void @_ZNU3AS41C6AssignE1E(%class.C addrspace(4)* %{{[0-9]+}}, 
i32 0)
+  c.Assign(a);
+  //CHECK: addrspacecast %class.C* %c to %class.C addrspace(4)*
+  //CHECK: call void @_ZNU3AS41C8OrAssignE1E(%class.C addrspace(4)* 
%{{[0-9]+}}, i32 0)
+  c.OrAssign(a);
+
+  E e;
+  // CHECK: store i32 1, i32* %e
+  e = b;
+  // CHECK: store i32 0, i32 addrspace(1)* @globE
+  globE = a;
+  // FIXME: Sema fails here because it thinks the types are incompatible.
+  //e = b;
+  //globE = a;
+}
+
+//CHECK: define linkonce_odr void @_ZNU3AS41C6AssignE1E(%class.C addrspace(4)* 
%this, i32 %e)
+//CHECK: [[E:%[0-9]+]] = load i32, i32* %e.addr
+//CHECK: %me = getelementptr inbounds %class.C, %class.C addrspace(4)* %this1, 
i32 0, i32 0
+//CHECK: store i32 [[E]], i32 addrspace(4)* %me
+
+//CHECK define linkonce_odr void @_ZNU3AS41C8OrAssignE1E(%class.C 
addrspace(4)* %this, i32 %e)
+//CHECK: [[E:%[0-9]+]] = load i32, i32* %e.addr
+//CHECK: %mi = getelementptr inbound

r355609 - [Sema] Change addr space diagnostics in casts to follow C++ style.

2019-03-07 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu Mar  7 09:06:30 2019
New Revision: 355609

URL: http://llvm.org/viewvc/llvm-project?rev=355609&view=rev
Log:
[Sema] Change addr space diagnostics in casts to follow C++ style.

This change adds a new diagnostic for mismatching address spaces
to be used for C++ casts (only enabled in C style cast for now,
the rest will follow!).

The change extends C-style cast rules to account for address spaces.
It also adds a separate function for address space cast checking that
can be used to map from a separate address space cast operator
addrspace_cast (to be added as a follow up patch).

Note, that after this change clang will no longer allows arbitrary
address space conversions in reinterpret_casts because they can lead
to accidental errors. The implicit safe conversions would still be
allowed.

Differential Revision: https://reviews.llvm.org/D58346


Added:
cfe/trunk/test/CodeGenOpenCLCXX/address-space-castoperators.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaCast.cpp
cfe/trunk/test/SemaCXX/address-space-conversion.cpp
cfe/trunk/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
cfe/trunk/test/SemaOpenCL/address-spaces.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=355609&r1=355608&r2=355609&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Mar  7 09:06:30 
2019
@@ -6271,6 +6271,10 @@ def err_bad_cxx_cast_bitfield : Error<
 def err_bad_cxx_cast_qualifiers_away : Error<
   "%select{const_cast|static_cast|reinterpret_cast|dynamic_cast|C-style cast|"
   "functional-style cast}0 from %1 to %2 casts away qualifiers">;
+def err_bad_cxx_cast_addr_space_mismatch : Error<
+  "%select{const_cast|static_cast|reinterpret_cast|dynamic_cast|C-style cast|"
+  "functional-style cast}0 from %1 to %2 converts between mismatching address"
+  " spaces">;
 def ext_bad_cxx_cast_qualifiers_away_incoherent : ExtWarn<
   "ISO C++ does not allow "
   "%select{const_cast|static_cast|reinterpret_cast|dynamic_cast|C-style cast|"

Modified: cfe/trunk/lib/Sema/SemaCast.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=355609&r1=355608&r2=355609&view=diff
==
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCast.cpp Thu Mar  7 09:06:30 2019
@@ -2212,7 +2212,15 @@ static TryCastResult TryReinterpretCast(
  /*CheckObjCLifetime=*/CStyle))
 SuccessResult = getCastAwayConstnessCastKind(CACK, msg);
 
-  if (IsLValueCast) {
+  if (IsAddressSpaceConversion(SrcType, DestType)) {
+Kind = CK_AddressSpaceConversion;
+assert(SrcType->isPointerType() && DestType->isPointerType());
+if (!CStyle &&
+!DestType->getPointeeType().getQualifiers().isAddressSpaceSupersetOf(
+SrcType->getPointeeType().getQualifiers())) {
+  SuccessResult = TC_Failed;
+}
+  } else if (IsLValueCast) {
 Kind = CK_LValueBitCast;
   } else if (DestType->isObjCObjectPointerType()) {
 Kind = Self.PrepareCastToObjCObjectPointer(SrcExpr);
@@ -,8 +2230,6 @@ static TryCastResult TryReinterpretCast(
 } else {
   Kind = CK_BitCast;
 }
-  } else if (IsAddressSpaceConversion(SrcType, DestType)) {
-Kind = CK_AddressSpaceConversion;
   } else {
 Kind = CK_BitCast;
   }
@@ -2278,6 +2284,41 @@ static TryCastResult TryReinterpretCast(
   return SuccessResult;
 }
 
+static TryCastResult TryAddressSpaceCast(Sema &Self, ExprResult &SrcExpr,
+ QualType DestType, bool CStyle,
+ unsigned &msg) {
+  if (!Self.getLangOpts().OpenCL)
+// FIXME: As compiler doesn't have any information about overlapping addr
+// spaces at the moment we have to be permissive here.
+return TC_NotApplicable;
+  // Even though the logic below is general enough and can be applied to
+  // non-OpenCL mode too, we fast-path above because no other languages
+  // define overlapping address spaces currently.
+  auto SrcType = SrcExpr.get()->getType();
+  auto SrcPtrType = SrcType->getAs();
+  if (!SrcPtrType)
+return TC_NotApplicable;
+  auto DestPtrType = DestType->getAs();
+  if (!DestPtrType)
+return TC_NotApplicable;
+  auto SrcPointeeType = SrcPtrType->getPointeeType();
+  auto DestPointeeType = DestPtrType->getPointeeType();
+  if (SrcPointeeType.getAddressSpace() == DestPointeeType.getAddressSpace())
+return TC_NotApplicable;
+  if (!DestPtrType->isAddressSpaceOverlapping(*SrcPtrType)) {
+msg = diag::err_bad_cxx_cast_addr_space_mismatch;
+return TC_Failed;
+  }
+  auto SrcPointeeTypeWithoutAS =
+  Self.Context.r

r355915 - [PR41007][OpenCL] Allow printf in C++ mode.

2019-03-12 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Tue Mar 12 05:46:56 2019
New Revision: 355915

URL: http://llvm.org/viewvc/llvm-project?rev=355915&view=rev
Log:
[PR41007][OpenCL] Allow printf in C++ mode.

As for OpenCL C, we need to allow using printf and toolchain variadic
functions (prefixed by "__") in C++ mode.

Differential Revision: https://reviews.llvm.org/D59219


Modified:
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaOpenCL/extensions.cl

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=355915&r1=355914&r2=355915&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Tue Mar 12 05:46:56 2019
@@ -4585,7 +4585,7 @@ static TypeSourceInfo *GetFullTypeForDec
 if (FTI.isVariadic &&
 !(D.getIdentifier() &&
   ((D.getIdentifier()->getName() == "printf" &&
-LangOpts.OpenCLVersion >= 120) ||
+(LangOpts.OpenCLCPlusPlus || LangOpts.OpenCLVersion >= 120)) ||
D.getIdentifier()->getName().startswith("__" {
   S.Diag(D.getIdentifierLoc(), diag::err_opencl_variadic_function);
   D.setInvalidType(true);

Modified: cfe/trunk/test/SemaOpenCL/extensions.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/extensions.cl?rev=355915&r1=355914&r2=355915&view=diff
==
--- cfe/trunk/test/SemaOpenCL/extensions.cl (original)
+++ cfe/trunk/test/SemaOpenCL/extensions.cl Tue Mar 12 05:46:56 2019
@@ -28,7 +28,7 @@
 // enabled by default with -cl-std=CL2.0).
 //
 // RUN: %clang_cc1 %s -triple amdgcn-unknown-unknown -verify -pedantic 
-fsyntax-only -cl-std=CL2.0 -finclude-default-header
-// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic 
-fsyntax-only -cl-std=c++
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic 
-fsyntax-only -cl-std=c++ -finclude-default-header
 
 #ifdef _OPENCL_H_
 // expected-no-diagnostics


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


r356450 - [OpenCL] Improved testing of default header.

2019-03-19 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Tue Mar 19 06:04:17 2019
New Revision: 356450

URL: http://llvm.org/viewvc/llvm-project?rev=356450&view=rev
Log:
[OpenCL] Improved testing of default header.

Improved some checks and moved testing of the default header
in C++ mode into the Headers folder.

Differential Revision: https://reviews.llvm.org/D59486


Modified:
cfe/trunk/test/Driver/include-default-header.cl
cfe/trunk/test/Headers/opencl-c-header.cl
cfe/trunk/test/SemaOpenCL/builtin.cl
cfe/trunk/test/SemaOpenCL/extensions.cl

Modified: cfe/trunk/test/Driver/include-default-header.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/include-default-header.cl?rev=356450&r1=356449&r2=356450&view=diff
==
--- cfe/trunk/test/Driver/include-default-header.cl (original)
+++ cfe/trunk/test/Driver/include-default-header.cl Tue Mar 19 06:04:17 2019
@@ -1,5 +1,6 @@
-// RUN: %clang -save-temps -x cl -Xclang -cl-std=CL2.0 -Xclang 
-finclude-default-header -emit-llvm -S -### %s
-// CHECK-NOT: finclude-default-header
+// RUN: %clang -save-temps -x cl -Xclang -cl-std=CL2.0 -Xclang 
-finclude-default-header -emit-llvm -S -### %s 2>&1 | FileCheck %s
+
+// CHECK-LABEL: finclude-default-header
 // Make sure we don't pass -finclude-default-header to any commands other than 
the driver.
 
 void test() {}

Modified: cfe/trunk/test/Headers/opencl-c-header.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/opencl-c-header.cl?rev=356450&r1=356449&r2=356450&view=diff
==
--- cfe/trunk/test/Headers/opencl-c-header.cl (original)
+++ cfe/trunk/test/Headers/opencl-c-header.cl Tue Mar 19 06:04:17 2019
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify | FileCheck %s
-// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.1| 
FileCheck %s
-// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.2| 
FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.1 
| FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.2 
| FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=c++ | 
FileCheck %s --check-prefix=CHECK20
 
 // Test including the default header as a module.
 // The module should be compiled only once and loaded from cache afterwards.
@@ -54,7 +55,7 @@
 // CHECK20: _Z3ctzc
 // CHECK20-NOT: _Z16convert_char_rtec
 char f(char x) {
-#if __OPENCL_C_VERSION__ != CL_VERSION_2_0
+#if !defined(__OPENCL_CPP_VERSION__) && (__OPENCL_C_VERSION__ != 
CL_VERSION_2_0)
   return convert_char_rte(x);
 
 #else //__OPENCL_C_VERSION__
@@ -67,7 +68,7 @@ char f(char x) {
 // from OpenCL 2.0 onwards.
 
 // CHECK20: _Z12write_imagef14ocl_image3d_wo
-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
 void test_image3dwo(write_only image3d_t img) {
   write_imagef(img, (0), (0.0f));
 }
@@ -75,7 +76,7 @@ void test_image3dwo(write_only image3d_t
 
 // Verify that non-builtin cl_intel_planar_yuv extension is defined from
 // OpenCL 1.2 onwards.
-#if (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
+#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
 // expected-no-diagnostics
 #ifndef cl_intel_planar_yuv
 #error "Missing cl_intel_planar_yuv define"

Modified: cfe/trunk/test/SemaOpenCL/builtin.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/builtin.cl?rev=356450&r1=356449&r2=356450&view=diff
==
--- cfe/trunk/test/SemaOpenCL/builtin.cl (original)
+++ cfe/trunk/test/SemaOpenCL/builtin.cl Tue Mar 19 06:04:17 2019
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=c++
 
 // expected-no-diagnostics
 

Modified: cfe/trunk/test/SemaOpenCL/extensions.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/extensions.cl?rev=356450&r1=356449&r2=356450&view=diff
==
--- cfe/trunk/test/SemaOpenCL/extensions.cl (original)
+++ cfe/trunk/test/SemaOpenCL/extensions.cl Tue Mar 19 06:04:17 2019
@@ -28,7 +28,7 @@
 // enabled by default with -cl-std=CL2.0).
 //
 // RUN: %clang_cc1 %s -triple amdgcn-unknown-unknown -verify -pedantic 
-fsynt

r356475 - [Sema] Adjust addr space of reference operand in compound assignment

2019-03-19 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Tue Mar 19 09:50:21 2019
New Revision: 356475

URL: http://llvm.org/viewvc/llvm-project?rev=356475&view=rev
Log:
[Sema] Adjust addr space of reference operand in compound assignment

When we create overloads for the builtin compound assignment operators
we need to preserve address space for the reference operand taking it
from the argument that is passed in.

Differential Revision: https://reviews.llvm.org/D59367


Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-operators.cl

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=356475&r1=356474&r2=356475&view=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Mar 19 09:50:21 2019
@@ -8513,17 +8513,16 @@ public:
Right < LastPromotedArithmeticType; ++Right) {
 QualType ParamTypes[2];
 ParamTypes[1] = ArithmeticTypes[Right];
-
+auto LeftBaseTy = AdjustAddressSpaceForBuiltinOperandType(
+S, ArithmeticTypes[Left], Args[0]);
 // Add this built-in operator as a candidate (VQ is empty).
-ParamTypes[0] =
-  S.Context.getLValueReferenceType(ArithmeticTypes[Left]);
+ParamTypes[0] = S.Context.getLValueReferenceType(LeftBaseTy);
 S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet,
   /*IsAssigmentOperator=*/isEqualOp);
 
 // Add this built-in operator as a candidate (VQ is 'volatile').
 if (VisibleTypeConversionsQuals.hasVolatile()) {
-  ParamTypes[0] =
-S.Context.getVolatileType(ArithmeticTypes[Left]);
+  ParamTypes[0] = S.Context.getVolatileType(LeftBaseTy);
   ParamTypes[0] = S.Context.getLValueReferenceType(ParamTypes[0]);
   S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet,
 /*IsAssigmentOperator=*/isEqualOp);
@@ -8579,15 +8578,14 @@ public:
Right < LastPromotedIntegralType; ++Right) {
 QualType ParamTypes[2];
 ParamTypes[1] = ArithmeticTypes[Right];
-
+auto LeftBaseTy = AdjustAddressSpaceForBuiltinOperandType(
+S, ArithmeticTypes[Left], Args[0]);
 // Add this built-in operator as a candidate (VQ is empty).
-ParamTypes[0] = S.Context.getLValueReferenceType(
-AdjustAddressSpaceForBuiltinOperandType(S, ArithmeticTypes[Left],
-Args[0]));
+ParamTypes[0] = S.Context.getLValueReferenceType(LeftBaseTy);
 S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet);
 if (VisibleTypeConversionsQuals.hasVolatile()) {
   // Add this built-in operator as a candidate (VQ is 'volatile').
-  ParamTypes[0] = ArithmeticTypes[Left];
+  ParamTypes[0] = LeftBaseTy;
   ParamTypes[0] = S.Context.getVolatileType(ParamTypes[0]);
   ParamTypes[0] = S.Context.getLValueReferenceType(ParamTypes[0]);
   S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet);

Modified: cfe/trunk/test/CodeGenOpenCLCXX/addrspace-operators.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/addrspace-operators.cl?rev=356475&r1=356474&r2=356475&view=diff
==
--- cfe/trunk/test/CodeGenOpenCLCXX/addrspace-operators.cl (original)
+++ cfe/trunk/test/CodeGenOpenCLCXX/addrspace-operators.cl Tue Mar 19 09:50:21 
2019
@@ -14,6 +14,8 @@ public:
 };
 
 __global E globE;
+volatile __global int globVI;
+__global int globI;
 //CHECK-LABEL: define spir_func void @_Z3barv()
 void bar() {
   C c;
@@ -25,13 +27,18 @@ void bar() {
   c.OrAssign(a);
 
   E e;
-  // CHECK: store i32 1, i32* %e
+  //CHECK: store i32 1, i32* %e
   e = b;
-  // CHECK: store i32 0, i32 addrspace(1)* @globE
+  //CHECK: store i32 0, i32 addrspace(1)* @globE
   globE = a;
-  // FIXME: Sema fails here because it thinks the types are incompatible.
-  //e = b;
-  //globE = a;
+  //CHECK: store i32 %or, i32 addrspace(1)* @globI
+  globI |= b;
+  //CHECK: store i32 %add, i32 addrspace(1)* @globI
+  globI += a;
+  //CHECK: store volatile i32 %and, i32 addrspace(1)* @globVI
+  globVI &= b;
+  //CHECK: store volatile i32 %sub, i32 addrspace(1)* @globVI
+  globVI -= a;
 }
 
 //CHECK: define linkonce_odr void @_ZNU3AS41C6AssignE1E(%class.C addrspace(4)* 
%this, i32 %e)


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


r356479 - [OpenCL] Minor improvements in default header testing

2019-03-19 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Tue Mar 19 10:09:06 2019
New Revision: 356479

URL: http://llvm.org/viewvc/llvm-project?rev=356479&view=rev
Log:
[OpenCL] Minor improvements in default header testing

Differential Revision: https://reviews.llvm.org/D59544


Modified:
cfe/trunk/test/Headers/opencl-c-header.cl

Modified: cfe/trunk/test/Headers/opencl-c-header.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/opencl-c-header.cl?rev=356479&r1=356478&r2=356479&view=diff
==
--- cfe/trunk/test/Headers/opencl-c-header.cl (original)
+++ cfe/trunk/test/Headers/opencl-c-header.cl Tue Mar 19 10:09:06 2019
@@ -53,15 +53,14 @@
 // CHECK: _Z16convert_char_rtec
 // CHECK-NOT: _Z3ctzc
 // CHECK20: _Z3ctzc
-// CHECK20-NOT: _Z16convert_char_rtec
+// CHECK20: _Z16convert_char_rtec
 char f(char x) {
-#if !defined(__OPENCL_CPP_VERSION__) && (__OPENCL_C_VERSION__ != 
CL_VERSION_2_0)
-  return convert_char_rte(x);
-
-#else //__OPENCL_C_VERSION__
+// Check functionality from OpenCL 2.0 onwards
+#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0)
   ndrange_t t;
-  return ctz(x);
+  x = ctz(x);
 #endif //__OPENCL_C_VERSION__
+  return convert_char_rte(x);
 }
 
 // Verify that a builtin using a write_only image3d_t type is available


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


r356888 - [OpenCL] Allow addr space spelling without __ prefix in C++.

2019-03-25 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Mon Mar 25 04:54:02 2019
New Revision: 356888

URL: http://llvm.org/viewvc/llvm-project?rev=356888&view=rev
Log:
[OpenCL] Allow addr space spelling without __ prefix in C++.

For backwards compatibility we allow alternative spelling of address
spaces - 'private', 'local', 'global', 'constant', 'generic'.

In order to accept 'private' correctly, parsing has been changed to
understand different use cases - access specifier vs address space.

Fixes PR40707 and PR41011!

Differential Revision: https://reviews.llvm.org/D59603


Modified:
cfe/trunk/include/clang/Basic/TokenKinds.def
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseTentative.cpp
cfe/trunk/test/Parser/opencl-cxx-keywords.cl

Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=356888&r1=356887&r2=356888&view=diff
==
--- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/trunk/include/clang/Basic/TokenKinds.def Mon Mar 25 04:54:02 2019
@@ -539,11 +539,11 @@ KEYWORD(__local , KE
 KEYWORD(__constant  , KEYOPENCLC | KEYOPENCLCXX)
 KEYWORD(__private   , KEYOPENCLC | KEYOPENCLCXX)
 KEYWORD(__generic   , KEYOPENCLC | KEYOPENCLCXX)
-ALIAS("global", __global, KEYOPENCLC)
-ALIAS("local", __local  , KEYOPENCLC)
-ALIAS("constant", __constant, KEYOPENCLC)
+ALIAS("global", __global, KEYOPENCLC | KEYOPENCLCXX)
+ALIAS("local", __local  , KEYOPENCLC | KEYOPENCLCXX)
+ALIAS("constant", __constant, KEYOPENCLC | KEYOPENCLCXX)
 ALIAS("private", __private  , KEYOPENCLC)
-ALIAS("generic", __generic  , KEYOPENCLC)
+ALIAS("generic", __generic  , KEYOPENCLC | KEYOPENCLCXX)
 // OpenCL function qualifiers
 KEYWORD(__kernel, KEYOPENCLC | KEYOPENCLCXX)
 ALIAS("kernel", __kernel, KEYOPENCLC | KEYOPENCLCXX)

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=356888&r1=356887&r2=356888&view=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Mar 25 04:54:02 2019
@@ -3824,6 +3824,7 @@ void Parser::ParseDeclarationSpecifiers(
 break;
   };
   LLVM_FALLTHROUGH;
+case tok::kw_private:
 case tok::kw___private:
 case tok::kw___global:
 case tok::kw___local:
@@ -4790,6 +4791,7 @@ bool Parser::isTypeSpecifierQualifier()
 
   case tok::kw___kindof:
 
+  case tok::kw_private:
   case tok::kw___private:
   case tok::kw___local:
   case tok::kw___global:
@@ -4980,6 +4982,7 @@ bool Parser::isDeclarationSpecifier(bool
 
   case tok::kw___kindof:
 
+  case tok::kw_private:
   case tok::kw___private:
   case tok::kw___local:
   case tok::kw___global:
@@ -5192,6 +5195,7 @@ void Parser::ParseTypeQualifierListOpt(
   break;
 
 // OpenCL qualifiers:
+case tok::kw_private:
 case tok::kw___private:
 case tok::kw___global:
 case tok::kw___local:

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=356888&r1=356887&r2=356888&view=diff
==
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Mon Mar 25 04:54:02 2019
@@ -3047,9 +3047,14 @@ Parser::DeclGroupPtrTy Parser::ParseCXXC
 DiagnoseUnexpectedNamespace(cast(TagDecl));
 return nullptr;
 
+  case tok::kw_private:
+// FIXME: We don't accept GNU attributes on access specifiers in OpenCL 
mode
+// yet.
+if (getLangOpts().OpenCL && !NextToken().is(tok::colon))
+  return ParseCXXClassMemberDeclaration(AS, AccessAttrs);
+LLVM_FALLTHROUGH;
   case tok::kw_public:
-  case tok::kw_protected:
-  case tok::kw_private: {
+  case tok::kw_protected: {
 AccessSpecifier NewAS = getAccessSpecifierIfPresent();
 assert(NewAS != AS_none);
 // Current token is a C++ access specifier.

Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=356888&r1=356887&r2=356888&view=diff
==
--- cfe/trunk/lib/Parse/ParseTentative.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTentative.cpp Mon Mar 25 04:54:02 2019
@@ -1411,6 +1411,7 @@ Parser::isCXXDeclarationSpecifier(Parser
   case tok::kw_const:
   case tok::kw_volatile:
 // OpenCL address space qualifiers
+  case tok::kw_private:
   case tok::kw___private:
   case tok::kw___local:
   case tok::kw___global:

Modified: cfe/trunk/test/Parser/opencl-cxx-keyw

r356987 - [OpenCL] Allow variadic macros as Clang feature.

2019-03-26 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Tue Mar 26 04:22:37 2019
New Revision: 356987

URL: http://llvm.org/viewvc/llvm-project?rev=356987&view=rev
Log:
[OpenCL] Allow variadic macros as Clang feature.


Modified:
cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/test/Misc/warning-flags.c
cfe/trunk/test/Preprocessor/macro_variadic.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=356987&r1=356986&r2=356987&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Tue Mar 26 04:22:37 2019
@@ -395,8 +395,8 @@ def warn_cxx98_compat_empty_fnmacro_arg
 def note_macro_here : Note<"macro %0 defined here">;
 def note_macro_expansion_here : Note<"expansion of macro %0 requested here">;
 
-def err_pp_opencl_variadic_macros :
-  Error<"variadic macros not supported in OpenCL">;
+def ext_pp_opencl_variadic_macros : Extension<
+  "variadic macros are a Clang extension in OpenCL">;
 
 def err_pp_invalid_directive : Error<"invalid preprocessing directive">;
 def err_pp_directive_required : Error<

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=356987&r1=356986&r2=356987&view=diff
==
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Tue Mar 26 04:22:37 2019
@@ -2181,8 +2181,7 @@ bool Preprocessor::ReadMacroParameterLis
 
   // OpenCL v1.2 s6.9.e: variadic macros are not supported.
   if (LangOpts.OpenCL) {
-Diag(Tok, diag::err_pp_opencl_variadic_macros);
-return true;
+Diag(Tok, diag::ext_pp_opencl_variadic_macros);
   }
 
   // Lex the token after the identifier.

Modified: cfe/trunk/test/Misc/warning-flags.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/warning-flags.c?rev=356987&r1=356986&r2=356987&view=diff
==
--- cfe/trunk/test/Misc/warning-flags.c (original)
+++ cfe/trunk/test/Misc/warning-flags.c Tue Mar 26 04:22:37 2019
@@ -96,4 +96,4 @@ CHECK-NEXT:   warn_weak_import
 
 The list of warnings in -Wpedantic should NEVER grow.
 
-CHECK: Number in -Wpedantic (not covered by other -W flags): 27
+CHECK: Number in -Wpedantic (not covered by other -W flags): 28

Modified: cfe/trunk/test/Preprocessor/macro_variadic.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/macro_variadic.cl?rev=356987&r1=356986&r2=356987&view=diff
==
--- cfe/trunk/test/Preprocessor/macro_variadic.cl (original)
+++ cfe/trunk/test/Preprocessor/macro_variadic.cl Tue Mar 26 04:22:37 2019
@@ -1,3 +1,20 @@
-// RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -verify %s -cl-std=CL1.2
+// RUN: %clang_cc1 -verify %s -pedantic -DPEDANTIC -cl-std=CL1.2
 
-#define X(...) 1 // expected-error {{variadic macros not supported in OpenCL}}
+
+#define NO_VAR_FUNC(...)  5
+#define VAR_FUNC(...) func(__VA_ARGS__);
+#define VAR_PRINTF(str, ...) printf(str, __VA_ARGS__);
+#ifdef PEDANTIC
+// expected-warning@-4{{variadic macros are a Clang extension in OpenCL}}
+// expected-warning@-4{{variadic macros are a Clang extension in OpenCL}}
+// expected-warning@-4{{variadic macros are a Clang extension in OpenCL}}
+#endif
+
+int printf(__constant const char *st, ...);
+
+void foo() {
+  NO_VAR_FUNC(1, 2, 3);
+  VAR_FUNC(1, 2, 3); //expected-error{{implicit declaration of function 'func' 
is invalid in OpenCL}}
+  VAR_PRINTF("%i", 1);
+}


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


r357162 - [PR41247] Fixed parsing of private keyword in C++.

2019-03-28 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu Mar 28 04:47:14 2019
New Revision: 357162

URL: http://llvm.org/viewvc/llvm-project?rev=357162&view=rev
Log:
[PR41247] Fixed parsing of private keyword in C++.

Fixed bug in C++ to prevent parsing 'private' as a
valid address space qualifier.

Differential Revision: https://reviews.llvm.org/D59874


Added:
cfe/trunk/test/SemaOpenCLCXX/private-access-specifier.cpp
Modified:
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseTentative.cpp

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=357162&r1=357161&r2=357162&view=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Thu Mar 28 04:47:14 2019
@@ -4791,7 +4791,6 @@ bool Parser::isTypeSpecifierQualifier()
 
   case tok::kw___kindof:
 
-  case tok::kw_private:
   case tok::kw___private:
   case tok::kw___local:
   case tok::kw___global:
@@ -4800,9 +4799,11 @@ bool Parser::isTypeSpecifierQualifier()
   case tok::kw___read_only:
   case tok::kw___read_write:
   case tok::kw___write_only:
-
 return true;
 
+  case tok::kw_private:
+return getLangOpts().OpenCL;
+
   // C11 _Atomic
   case tok::kw__Atomic:
 return true;
@@ -4982,7 +4983,6 @@ bool Parser::isDeclarationSpecifier(bool
 
   case tok::kw___kindof:
 
-  case tok::kw_private:
   case tok::kw___private:
   case tok::kw___local:
   case tok::kw___global:
@@ -4995,6 +4995,9 @@ bool Parser::isDeclarationSpecifier(bool
 #include "clang/Basic/OpenCLImageTypes.def"
 
 return true;
+
+  case tok::kw_private:
+return getLangOpts().OpenCL;
   }
 }
 
@@ -5196,6 +5199,9 @@ void Parser::ParseTypeQualifierListOpt(
 
 // OpenCL qualifiers:
 case tok::kw_private:
+  if (!getLangOpts().OpenCL)
+goto DoneWithTypeQuals;
+  LLVM_FALLTHROUGH;
 case tok::kw___private:
 case tok::kw___global:
 case tok::kw___local:

Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=357162&r1=357161&r2=357162&view=diff
==
--- cfe/trunk/lib/Parse/ParseTentative.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTentative.cpp Thu Mar 28 04:47:14 2019
@@ -1414,8 +1414,13 @@ Parser::isCXXDeclarationSpecifier(Parser
 // cv-qualifier
   case tok::kw_const:
   case tok::kw_volatile:
+return TPResult::True;
+
 // OpenCL address space qualifiers
   case tok::kw_private:
+if (!getLangOpts().OpenCL)
+  return TPResult::False;
+LLVM_FALLTHROUGH;
   case tok::kw___private:
   case tok::kw___local:
   case tok::kw___global:

Added: cfe/trunk/test/SemaOpenCLCXX/private-access-specifier.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCLCXX/private-access-specifier.cpp?rev=357162&view=auto
==
--- cfe/trunk/test/SemaOpenCLCXX/private-access-specifier.cpp (added)
+++ cfe/trunk/test/SemaOpenCLCXX/private-access-specifier.cpp Thu Mar 28 
04:47:14 2019
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -pedantic -verify -fsyntax-only
+
+// Test that 'private' is not parsed as an address space qualifier
+// in regular C++ mode.
+
+struct B {
+  virtual ~B() // expected-error{{expected ';' at end of declaration list}}
+private:
+   void foo();
+   private int* i; // expected-error{{expected ':'}}
+};
+
+void bar(private int*); //expected-error{{variable has incomplete type 
'void'}} expected-error{{expected expression}}


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


r357682 - [PR41276] Fixed incorrect generation of addr space cast for 'this' in C++.

2019-04-04 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu Apr  4 03:48:36 2019
New Revision: 357682

URL: http://llvm.org/viewvc/llvm-project?rev=357682&view=rev
Log:
[PR41276] Fixed incorrect generation of addr space cast for 'this' in C++.
 
Improved classification of address space cast when qualification
conversion is performed - prevent adding addr space cast for
non-pointer and non-reference types. Take address space correctly
from the pointee.

Also pass correct address space from 'this' object using
AggValueSlot when generating addrspacecast in the constructor
call.

Differential Revision: https://reviews.llvm.org/D59988


Added:
cfe/trunk/test/CodeGenCXX/address-space-of-this.cpp
Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/SemaInit.cpp

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=357682&r1=357681&r2=357682&view=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Thu Apr  4 03:48:36 2019
@@ -1678,7 +1678,7 @@ bool CastExpr::CastConsistency() const {
 auto Ty = getType();
 auto SETy = getSubExpr()->getType();
 assert(getValueKindForType(Ty) == Expr::getValueKindForType(SETy));
-if (isRValue()) {
+if (/*isRValue()*/ !Ty->getPointeeType().isNull()) {
   Ty = Ty->getPointeeType();
   SETy = SETy->getPointeeType();
 }

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=357682&r1=357681&r2=357682&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Thu Apr  4 03:48:36 2019
@@ -1978,10 +1978,14 @@ void CodeGenFunction::EmitCXXAggrConstru
   pushRegularPartialArrayCleanup(arrayBegin, cur, type, eltAlignment,
  *destroyer);
 }
-
+auto currAVS = AggValueSlot::forAddr(
+curAddr, type.getQualifiers(), AggValueSlot::IsDestructed,
+AggValueSlot::DoesNotNeedGCBarriers, AggValueSlot::IsNotAliased,
+AggValueSlot::DoesNotOverlap, AggValueSlot::IsNotZeroed,
+NewPointerIsChecked ? AggValueSlot::IsSanitizerChecked
+: AggValueSlot::IsNotSanitizerChecked);
 EmitCXXConstructorCall(ctor, Ctor_Complete, /*ForVirtualBase=*/false,
-   /*Delegating=*/false, curAddr, E,
-   AggValueSlot::DoesNotOverlap, NewPointerIsChecked);
+   /*Delegating=*/false, currAVS, E);
   }
 
   // Go to the next element.
@@ -2015,16 +2019,16 @@ void CodeGenFunction::destroyCXXObject(C
 void CodeGenFunction::EmitCXXConstructorCall(const CXXConstructorDecl *D,
  CXXCtorType Type,
  bool ForVirtualBase,
- bool Delegating, Address This,
- const CXXConstructExpr *E,
- AggValueSlot::Overlap_t Overlap,
- bool NewPointerIsChecked) {
+ bool Delegating,
+ AggValueSlot ThisAVS,
+ const CXXConstructExpr *E) {
   CallArgList Args;
-
-  LangAS SlotAS = E->getType().getAddressSpace();
+  Address This = ThisAVS.getAddress();
+  LangAS SlotAS = ThisAVS.getQualifiers().getAddressSpace();
   QualType ThisType = D->getThisType();
   LangAS ThisAS = ThisType.getTypePtr()->getPointeeType().getAddressSpace();
   llvm::Value *ThisPtr = This.getPointer();
+
   if (SlotAS != ThisAS) {
 unsigned TargetThisAS = getContext().getTargetAddressSpace(ThisAS);
 llvm::Type *NewType =
@@ -2032,6 +2036,7 @@ void CodeGenFunction::EmitCXXConstructor
 ThisPtr = getTargetHooks().performAddrSpaceCast(*this, This.getPointer(),
 ThisAS, SlotAS, NewType);
   }
+
   // Push the this ptr.
   Args.add(RValue::get(ThisPtr), D->getThisType());
 
@@ -2045,7 +2050,7 @@ void CodeGenFunction::EmitCXXConstructor
 LValue Src = EmitLValue(Arg);
 QualType DestTy = getContext().getTypeDeclType(D->getParent());
 LValue Dest = MakeAddrLValue(This, DestTy);
-EmitAggregateCopyCtor(Dest, Src, Overlap);
+EmitAggregateCopyCtor(Dest, Src, ThisAVS.mayOverlap());
 return;
   }
 
@@ -2058,7 +2063,8 @@ void CodeGenFunction::EmitCXXConstructor
/*ParamsToSkip*/ 0, Order);
 
   EmitCXXConstructorCall(D, Type, ForVirtualBase, Delegating, This, Args,
- Overlap, E->getExprLoc(), NewPointer

r357684 - [PR41157][OpenCL] Prevent implicit init of local addr space var in C++ mode.

2019-04-04 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu Apr  4 04:08:51 2019
New Revision: 357684

URL: http://llvm.org/viewvc/llvm-project?rev=357684&view=rev
Log:
[PR41157][OpenCL] Prevent implicit init of local addr space var in C++ mode.

Prevent adding initializers implicitly to variables declared in
local address space. This happens when they get converted into
global variables and therefore theoretically have to be default
initialized in C++.

Differential Revision: https://reviews.llvm.org/D59646


Added:
cfe/trunk/test/CodeGenOpenCLCXX/local_addrspace_init.cl
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=357684&r1=357683&r2=357684&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Apr  4 04:08:51 2019
@@ -11682,7 +11682,11 @@ void Sema::ActOnUninitializedDecl(Decl *
   setFunctionHasBranchProtectedScope();
   }
 }
-
+// In OpenCL, we can't initialize objects in the __local address space,
+// even implicitly, so don't synthesize an implicit initializer.
+if (getLangOpts().OpenCL &&
+Var->getType().getAddressSpace() == LangAS::opencl_local)
+  return;
 // C++03 [dcl.init]p9:
 //   If no initializer is specified for an object, and the
 //   object is of (possibly cv-qualified) non-POD class type (or

Modified: cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl?rev=357684&r1=357683&r2=357684&view=diff
==
--- cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl (original)
+++ cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl Thu Apr  4 04:08:51 
2019
@@ -150,15 +150,13 @@ __kernel void test__global() {
 TEST(__local)
 
 // COMMON-LABEL: _Z11test__localv
-// EXPL: @__cxa_guard_acquire
 
-// Test the address space of 'this' when invoking a constructor for an object 
in non-default address space
-// EXPL: call void @_ZNU3AS41CC1Ev(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C addrspace(4)*))
+// Test that we don't initialize an object in local address space.
+// EXPL-NOT: call void @_ZNU3AS41CC1Ev(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C addrspace(4)*))
 
 // Test the address space of 'this' when invoking a method.
 // COMMON: %call = call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* 
addrspacecast (%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C 
addrspace(4)*))
 
-
 // Test the address space of 'this' when invoking copy-constructor.
 // COMMON: [[C1GEN:%[0-9]+]] = addrspacecast %class.C* %c1 to %class.C 
addrspace(4)*
 // EXPL: call void @_ZNU3AS41CC1ERU3AS4KS_(%class.C addrspace(4)* [[C1GEN]], 
%class.C addrspace(4)* dereferenceable(4) addrspacecast (%class.C addrspace(3)* 
@_ZZ11test__localvE1c to %class.C addrspace(4)*))

Added: cfe/trunk/test/CodeGenOpenCLCXX/local_addrspace_init.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/local_addrspace_init.cl?rev=357684&view=auto
==
--- cfe/trunk/test/CodeGenOpenCLCXX/local_addrspace_init.cl (added)
+++ cfe/trunk/test/CodeGenOpenCLCXX/local_addrspace_init.cl Thu Apr  4 04:08:51 
2019
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -triple spir -cl-std=c++ -emit-llvm -O0 -o - | FileCheck 
%s
+
+// Test that we don't initialize local address space objects.
+//CHECK: @_ZZ4testvE1i = internal addrspace(3) global i32 undef
+//CHECK: @_ZZ4testvE2ii = internal addrspace(3) global %class.C undef
+class C {
+  int i;
+};
+
+kernel void test() {
+  __local int i;
+  __local C ii;
+  // FIXME: In OpenCL C we don't accept initializers for local
+  // address space variables. User defined initialization could
+  // make sense, but would it mean that all work items need to
+  // execute it? Potentially disallowing any initialization would
+  // make things easier and assingments can be used to set specific
+  // values. This rules should make it consistent with OpenCL C.
+  //__local C c();
+}


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


r359789 - [OpenCL] Deduce static data members to __global addr space.

2019-05-02 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu May  2 07:40:40 2019
New Revision: 359789

URL: http://llvm.org/viewvc/llvm-project?rev=359789&view=rev
Log:
[OpenCL] Deduce static data members to __global addr space.

Similarly to static variables in OpenCL, static class data
members should be deduced to __global addr space.

Differential Revision: https://reviews.llvm.org/D61304


Added:
cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
Modified:
cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=359789&r1=359788&r2=359789&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu May  2 07:40:40 2019
@@ -7308,8 +7308,10 @@ static void deduceOpenCLImplicitAddrSpac
// otherwise it will fail some sema check.
   IsFuncReturnType || IsFuncType ||
   // Do not deduce addr space for member types of struct, except the 
pointee
-  // type of a pointer member type.
-  (D.getContext() == DeclaratorContext::MemberContext && !IsPointee) ||
+  // type of a pointer member type or static data members.
+  (D.getContext() == DeclaratorContext::MemberContext &&
+   (!IsPointee &&
+D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static)) ||
   // Do not deduce addr space for types used to define a typedef and the
   // typedef itself, except the pointee type of a pointer type which is 
used
   // to define the typedef.

Added: cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl?rev=359789&view=auto
==
--- cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl (added)
+++ cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl Thu May  2 07:40:40 
2019
@@ -0,0 +1,12 @@
+//RUN: %clang_cc1 %s -cl-std=c++ -pedantic -ast-dump -verify
+
+//expected-no-diagnostics
+
+//CHECK: |-VarDecl  foo {{.*}} 'const __global int' constexpr cinit
+constexpr int foo = 0;
+
+class c {
+public:
+  //CHECK: `-VarDecl {{.*}} foo2 'const __global int' static constexpr cinit
+  static constexpr int foo2 = 0;
+};


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


r359798 - [OpenCL] Fix initialisation of this via pointer.

2019-05-02 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu May  2 09:10:50 2019
New Revision: 359798

URL: http://llvm.org/viewvc/llvm-project?rev=359798&view=rev
Log:
[OpenCL] Fix initialisation of this via pointer.

When the expression used to initialise 'this' has a pointer type,
check the address space of the pointee type instead of the pointer
type to decide whether an address space cast is required.
It is the pointee type that carries the address space qualifier.

Fixing PR41674.

Patch by kpet (Kevin Petit)!

Differential Revision: https://reviews.llvm.org/D61319


Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=359798&r1=359797&r2=359798&view=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu May  2 09:10:50 2019
@@ -5279,12 +5279,12 @@ Sema::PerformObjectArgumentInitializatio
   }
 
   if (!Context.hasSameType(From->getType(), DestType)) {
-if (From->getType().getAddressSpace() != DestType.getAddressSpace())
-  From = ImpCastExprToType(From, DestType, CK_AddressSpaceConversion,
- From->getValueKind()).get();
+CastKind CK;
+if (FromRecordType.getAddressSpace() != DestType.getAddressSpace())
+  CK = CK_AddressSpaceConversion;
 else
-  From = ImpCastExprToType(From, DestType, CK_NoOp,
- From->getValueKind()).get();
+  CK = CK_NoOp;
+From = ImpCastExprToType(From, DestType, CK, From->getValueKind()).get();
   }
   return From;
 }

Modified: cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl?rev=359798&r1=359797&r2=359798&view=diff
==
--- cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl (original)
+++ cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl Thu May  2 09:10:50 
2019
@@ -59,7 +59,8 @@ __global C c;
 
 __kernel void test__global() {
   int i = c.get();
-  int i2 = c.outside();
+  int i2 = (&c)->get();
+  int i3 = c.outside();
   C c1(c);
   C c2;
   c2 = c1;
@@ -85,10 +86,12 @@ __kernel void test__global() {
 // COMMON-LABEL: @_Z12test__globalv()
 
 // Test the address space of 'this' when invoking a method.
-// COMMON: %call = call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* 
addrspacecast (%class.C addrspace(1)* @c to %class.C addrspace(4)*))
+// COMMON: call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(1)* @c to %class.C addrspace(4)*))
+// Test the address space of 'this' when invoking a method using a pointer to 
the object.
+// COMMON: call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(1)* @c to %class.C addrspace(4)*))
 
 // Test the address space of 'this' when invoking a method that is declared in 
the file contex.
-// COMMON: %call1 = call i32 @_ZNU3AS41C7outsideEv(%class.C addrspace(4)* 
addrspacecast (%class.C addrspace(1)* @c to %class.C addrspace(4)*))
+// COMMON: call i32 @_ZNU3AS41C7outsideEv(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(1)* @c to %class.C addrspace(4)*))
 
 // Test the address space of 'this' when invoking copy-constructor.
 // COMMON: [[C1GEN:%[0-9]+]] = addrspacecast %class.C* %c1 to %class.C 
addrspace(4)*
@@ -130,7 +133,7 @@ __kernel void test__global() {
 // Test the address space of 'this' when invoking the move assignment
 // COMMON: [[C5GEN:%[0-9]+]] = addrspacecast %class.C* %c5 to %class.C 
addrspace(4)*
 // COMMON: [[CALL:%call[0-9]+]] = call spir_func dereferenceable(4) %class.C 
addrspace(4)* @_Z3foov()
-// EXPL: call void @_ZNU3AS41CC1EOU3AS4S_(%class.C addrspace(4)* 
[[C5GEN:%[0-9]+]], %class.C addrspace(4)* dereferenceable(4) %call4)
+// EXPL: call void @_ZNU3AS41CC1EOU3AS4S_(%class.C addrspace(4)* 
[[C5GEN:%[0-9]+]], %class.C addrspace(4)* dereferenceable(4) [[CALL]])
 // IMPL: [[C5VOID:%[0-9]+]] = bitcast %class.C* %c5 to i8*
 // IMPL: [[CALLVOID:%[0-9]+]] = bitcast %class.C addrspace(4)* [[CALL]] to i8 
addrspace(4)*
 // IMPL: call void @llvm.memcpy.p0i8.p4i8.i32(i8* {{.*}}[[C5VOID]], i8 
addrspace(4)* {{.*}}[[CALLVOID]]
@@ -155,7 +158,7 @@ TEST(__local)
 // EXPL-NOT: call void @_ZNU3AS41CC1Ev(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C addrspace(4)*))
 
 // Test the address space of 'this' when invoking a method.
-// COMMON: %call = call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* 
addrspacecast (%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C 
addrspace(4)*))
+// COMMON: call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C addrspace(4)*))
 
 // Test the address space of 'this' when invo

r360152 - [OpenCL] Prevent mangling kernel functions.

2019-05-07 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Tue May  7 07:22:34 2019
New Revision: 360152

URL: http://llvm.org/viewvc/llvm-project?rev=360152&view=rev
Log:
[OpenCL] Prevent mangling kernel functions.

Kernel function names have to be preserved as in the original
source to be able to access them from the host API side. 

This commit also adds restriction to kernels that prevents them
from being used in overloading, templates, etc.

Differential Revision: https://reviews.llvm.org/D60454


Added:
cfe/trunk/test/SemaOpenCLCXX/kernel_invalid.cl
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl
cfe/trunk/test/CodeGenOpenCLCXX/local_addrspace_init.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=360152&r1=360151&r2=360152&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue May  7 07:22:34 
2019
@@ -8582,6 +8582,10 @@ def err_invalid_astype_of_different_size
   "invalid reinterpretation: sizes of %0 and %1 must match">;
 def err_static_kernel : Error<
   "kernel functions cannot be declared static">;
+def err_method_kernel : Error<
+  "kernel functions cannot be class members">;
+def err_template_kernel : Error<
+  "kernel functions cannot be used in a template declaration, instantiation or 
specialization">;
 def err_opencl_ptrptr_kernel_param : Error<
   "kernel parameter cannot be declared as a pointer to a pointer">;
 def err_kernel_arg_address_space : Error<

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=360152&r1=360151&r2=360152&view=diff
==
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Tue May  7 07:22:34 2019
@@ -2961,6 +2961,8 @@ bool FunctionDecl::isExternC() const {
 }
 
 bool FunctionDecl::isInExternCContext() const {
+  if (hasAttr())
+return true;
   return getLexicalDeclContext()->isExternCContext();
 }
 

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=360152&r1=360151&r2=360152&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue May  7 07:22:34 2019
@@ -9214,18 +9214,9 @@ Sema::ActOnFunctionDeclarator(Scope *S,
 
   MarkUnusedFileScopedDecl(NewFD);
 
-  if (getLangOpts().CPlusPlus) {
-if (FunctionTemplate) {
-  if (NewFD->isInvalidDecl())
-FunctionTemplate->setInvalidDecl();
-  return FunctionTemplate;
-}
 
-if (isMemberSpecialization && !NewFD->isInvalidDecl())
-  CompleteMemberSpecialization(NewFD, Previous);
-  }
 
-  if (NewFD->hasAttr()) {
+  if (getLangOpts().OpenCL && NewFD->hasAttr()) {
 // OpenCL v1.2 s6.8 static is invalid for kernel functions.
 if ((getLangOpts().OpenCLVersion >= 120)
 && (SC == SC_Static)) {
@@ -9245,7 +9236,30 @@ Sema::ActOnFunctionDeclarator(Scope *S,
 llvm::SmallPtrSet ValidTypes;
 for (auto Param : NewFD->parameters())
   checkIsValidOpenCLKernelParameter(*this, D, Param, ValidTypes);
+
+if (getLangOpts().OpenCLCPlusPlus) {
+  if (DC->isRecord()) {
+Diag(D.getIdentifierLoc(), diag::err_method_kernel);
+D.setInvalidType();
+  }
+  if (FunctionTemplate) {
+Diag(D.getIdentifierLoc(), diag::err_template_kernel);
+D.setInvalidType();
+  }
+}
   }
+
+  if (getLangOpts().CPlusPlus) {
+if (FunctionTemplate) {
+  if (NewFD->isInvalidDecl())
+FunctionTemplate->setInvalidDecl();
+  return FunctionTemplate;
+}
+
+if (isMemberSpecialization && !NewFD->isInvalidDecl())
+  CompleteMemberSpecialization(NewFD, Previous);
+  }
+
   for (const ParmVarDecl *Param : NewFD->parameters()) {
 QualType PT = Param->getType();
 

Modified: cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl?rev=360152&r1=360151&r2=360152&view=diff
==
--- cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl (original)
+++ cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl Tue May  7 07:22:34 
2019
@@ -83,7 +83,7 @@ __kernel void test__global() {
 // EXPL-LABEL: @__cxx_global_var_init()
 // EXPL: call void @_ZNU3AS41CC1Ev(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(1)* @c to %class.C addrspace(4)*))
 
-// COMMON-LABEL: @_Z12test__globalv()
+// COMMON-LABEL: @test__global()
 
 // Test the address space of 'this' w

r360258 - [Sema][OpenCL] Make address space conversions a bit stricter.

2019-05-08 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Wed May  8 07:23:49 2019
New Revision: 360258

URL: http://llvm.org/viewvc/llvm-project?rev=360258&view=rev
Log:
[Sema][OpenCL] Make address space conversions a bit stricter.

The semantics for converting nested pointers between address
spaces are not very well defined. Some conversions which do not
really carry any meaning only produce warnings, and in some cases
warnings hide invalid conversions, such as 'global int*' to
'local float*'!

This patch changes the logic in checkPointerTypesForAssignment
and checkAddressSpaceCast to fail properly on implicit conversions
that should definitely not be permitted. We also dig deeper into the
pointer types and warn on explicit conversions where the address
space in a nested pointer changes, regardless of whether the address
space is compatible with the corresponding pointer nesting level
on the destination type.

Fixes PR39674!

Patch by ebevhan (Bevin Hansson)!

Differential Revision: https://reviews.llvm.org/D58236


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaCast.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/CodeGenOpenCL/numbered-address-space.cl
cfe/trunk/test/SemaOpenCL/address-spaces.cl
cfe/trunk/test/SemaOpenCL/event_t_overload.cl
cfe/trunk/test/SemaOpenCL/numbered-address-space.cl
cfe/trunk/test/SemaOpenCL/queue_t_overload.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=360258&r1=360257&r2=360258&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed May  8 07:23:49 
2019
@@ -7005,6 +7005,19 @@ def err_typecheck_incompatible_address_s
   "sending to parameter of different type}0,1"
   "|%diff{casting $ to type $|casting between types}0,1}2"
   " changes address space of pointer">;
+def err_typecheck_incompatible_nested_address_space : Error<
+  "%select{%diff{assigning $ to $|assigning to different types}1,0"
+  "|%diff{passing $ to parameter of type $|"
+  "passing to parameter of different type}0,1"
+  "|%diff{returning $ from a function with result type $|"
+  "returning from function with different return type}0,1"
+  "|%diff{converting $ to type $|converting between types}0,1"
+  "|%diff{initializing $ with an expression of type $|"
+  "initializing with expression of different type}0,1"
+  "|%diff{sending $ to parameter of type $|"
+  "sending to parameter of different type}0,1"
+  "|%diff{casting $ to type $|casting between types}0,1}2"
+  " changes address space of nested pointer">;
 def err_typecheck_incompatible_ownership : Error<
   "%select{%diff{assigning $ to $|assigning to different types}1,0"
   "|%diff{passing $ to parameter of type $|"

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=360258&r1=360257&r2=360258&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed May  8 07:23:49 2019
@@ -9726,6 +9726,12 @@ public:
 /// like address spaces.
 IncompatiblePointerDiscardsQualifiers,
 
+/// IncompatibleNestedPointerAddressSpaceMismatch - The assignment
+/// changes address spaces in nested pointer types which is not allowed.
+/// For instance, converting __private int ** to __generic int ** is
+/// illegal even though __private could be converted to __generic.
+IncompatibleNestedPointerAddressSpaceMismatch,
+
 /// IncompatibleNestedPointerQualifiers - The assignment is between two
 /// nested pointer types, and the qualifiers other than the first two
 /// levels differ e.g. char ** -> const char **, but we accept them as an

Modified: cfe/trunk/lib/Sema/SemaCast.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=360258&r1=360257&r2=360258&view=diff
==
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCast.cpp Wed May  8 07:23:49 2019
@@ -2323,19 +2323,41 @@ void CastOperation::checkAddressSpaceCas
   // In OpenCL only conversions between pointers to objects in overlapping
   // addr spaces are allowed. v2.0 s6.5.5 - Generic addr space overlaps
   // with any named one, except for constant.
+
+  // Converting the top level pointee addrspace is permitted for compatible
+  // addrspaces (such as 'generic int *' to 'local int *' or vice versa), but
+  // if any of the nested pointee addrspaces differ, we emit a warning
+  // regardless of addrspace compatibility. This makes
+  //   local int ** p;
+  //   return (generic int **) p;
+  // warn even though loc

r360325 - [SPIR] Simplified target checking.

2019-05-09 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu May  9 03:25:45 2019
New Revision: 360325

URL: http://llvm.org/viewvc/llvm-project?rev=360325&view=rev
Log:
[SPIR] Simplified target checking.

Switched to Triple::isSPIR() helper to simplify code.

Patch by kpet (Kevin Petit)!

Differential revision: https://reviews.llvm.org/D61639


Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=360325&r1=360324&r2=360325&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu May  9 03:25:45 2019
@@ -539,8 +539,7 @@ void CodeGenModule::Release() {
   if (LangOpts.OpenCL) {
 EmitOpenCLMetadata();
 // Emit SPIR version.
-if (getTriple().getArch() == llvm::Triple::spir ||
-getTriple().getArch() == llvm::Triple::spir64) {
+if (getTriple().isSPIR()) {
   // SPIR v2.0 s2.12 - The SPIR version used by the module is stored in the
   // opencl.spir.version named metadata.
   llvm::Metadata *SPIRVerElts[] = {

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=360325&r1=360324&r2=360325&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu May  9 03:25:45 2019
@@ -3349,10 +3349,8 @@ bool CompilerInvocation::CreateFromArgs(
   Res.getFrontendOpts().ProgramAction);
 
   // Turn on -Wspir-compat for SPIR target.
-  auto Arch = T.getArch();
-  if (Arch == llvm::Triple::spir || Arch == llvm::Triple::spir64) {
+  if (T.isSPIR())
 Res.getDiagnosticOpts().Warnings.push_back("spir-compat");
-  }
 
   // If sanitizer is enabled, disable OPT_ffine_grained_bitfield_accesses.
   if (Res.getCodeGenOpts().FineGrainedBitfieldAccesses &&

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=360325&r1=360324&r2=360325&view=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Thu May  9 03:25:45 2019
@@ -1072,8 +1072,7 @@ static void InitializePredefinedMacros(c
 Builder.defineMacro(#Ext);
 #include "clang/Basic/OpenCLExtensions.def"
 
-auto Arch = TI.getTriple().getArch();
-if (Arch == llvm::Triple::spir || Arch == llvm::Triple::spir64)
+if (TI.getTriple().isSPIR())
   Builder.defineMacro("__IMAGE_SUPPORT__");
   }
 


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


r360330 - [OpenCL] Switched CXX mode to be derived from C++17

2019-05-09 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu May  9 04:55:24 2019
New Revision: 360330

URL: http://llvm.org/viewvc/llvm-project?rev=360330&view=rev
Log:
[OpenCL] Switched CXX mode to be derived from C++17

Differential revision: https://reviews.llvm.org/D61506


Modified:
cfe/trunk/include/clang/Frontend/LangStandards.def
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl

Modified: cfe/trunk/include/clang/Frontend/LangStandards.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/LangStandards.def?rev=360330&r1=360329&r2=360330&view=diff
==
--- cfe/trunk/include/clang/Frontend/LangStandards.def (original)
+++ cfe/trunk/include/clang/Frontend/LangStandards.def Thu May  9 04:55:24 2019
@@ -159,7 +159,8 @@ LANGSTANDARD(opencl20, "cl2.0",
  LineComment | C99 | Digraphs | HexFloat | OpenCL)
 LANGSTANDARD(openclcpp, "c++",
  OpenCL, "OpenCL C++ 1.0",
- LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs | 
OpenCL)
+ LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 
|
+ Digraphs | HexFloat | OpenCL)
 
 LANGSTANDARD_ALIAS_DEPR(opencl10, "CL")
 LANGSTANDARD_ALIAS_DEPR(opencl11, "CL1.1")

Modified: cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl?rev=360330&r1=360329&r2=360330&view=diff
==
--- cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl (original)
+++ cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl Thu May  9 04:55:24 
2019
@@ -112,15 +112,9 @@ __kernel void test__global() {
 // IMPL: call void @llvm.memcpy.p4i8.p4i8.i32(i8 addrspace(4)* 
{{.*}}[[C2GENVOID]], i8 addrspace(4)* {{.*}}[[C1GENVOID]]
 
 // Test the address space of 'this' when invoking the operator+
-// COMMON: [[C3GEN:%[0-9]+]] = addrspacecast %class.C* %c3 to %class.C 
addrspace(4)*
 // COMMON: [[C1GEN:%[0-9]+]] = addrspacecast %class.C* %c1 to %class.C 
addrspace(4)*
 // COMMON: [[C2GEN:%[0-9]+]] = addrspacecast %class.C* %c2 to %class.C 
addrspace(4)*
-// COMMON: call void @_ZNU3AS41CplERU3AS4KS_(%class.C* sret %ref.tmp, %class.C 
addrspace(4)* [[C1GEN]], %class.C addrspace(4)* dereferenceable(4) [[C2GEN]])
-// COMMON: [[REFGEN:%[0-9]+]] = addrspacecast %class.C* %ref.tmp to %class.C 
addrspace(4)*
-// EXPL: call void @_ZNU3AS41CC1EOU3AS4S_(%class.C addrspace(4)* [[C3GEN]], 
%class.C addrspace(4)* dereferenceable(4) [[REFGEN]])
-// IMPL: [[C3VOID:%[0-9]+]] = bitcast %class.C* %c3 to i8*
-// IMPL: [[REFGENVOID:%[0-9]+]] = bitcast %class.C addrspace(4)* [[REFGEN]] to 
i8 addrspace(4)*
-// IMPL: call void @llvm.memcpy.p0i8.p4i8.i32(i8* {{.*}}[[C3VOID]], i8 
addrspace(4)* {{.*}}[[REFGENVOID]]
+// COMMON: call void @_ZNU3AS41CplERU3AS4KS_(%class.C* sret %c3, %class.C 
addrspace(4)* [[C1GEN]], %class.C addrspace(4)* dereferenceable(4) [[C2GEN]])
 
 // Test the address space of 'this' when invoking the move constructor
 // COMMON: [[C4GEN:%[0-9]+]] = addrspacecast %class.C* %c4 to %class.C 
addrspace(4)*


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


r360342 - [OpenCL] Make global ctor init function a kernel

2019-05-09 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu May  9 06:55:44 2019
New Revision: 360342

URL: http://llvm.org/viewvc/llvm-project?rev=360342&view=rev
Log:
[OpenCL] Make global ctor init function a kernel

We need to be able to enqueue internal function that initializes
global constructors on the host side. Therefore it has to be
converted to a kernel.

This change factors out common logic for adding kernel metadata
and moves it from CodeGenFunction to CodeGenModule in order to
make it accessible for the extra use case.

Differential revision: https://reviews.llvm.org/D61488


Added:
cfe/trunk/test/CodeGenOpenCLCXX/global_init.cl
Modified:
cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h

Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=360342&r1=360341&r2=360342&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Thu May  9 06:55:44 2019
@@ -580,6 +580,19 @@ CodeGenModule::EmitCXXGlobalInitFunc() {
   CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn, CXXGlobalInits);
   AddGlobalCtor(Fn);
 
+  // In OpenCL global init functions must be converted to kernels in order to
+  // be able to launch them from the host.
+  // FIXME: Some more work might be needed to handle destructors correctly.
+  // Current initialization function makes use of function pointers callbacks.
+  // We can't support function pointers especially between host and device.
+  // However it seems global destruction has little meaning without any
+  // dynamic resource allocation on the device and program scope variables are
+  // destroyed by the runtime when program is released.
+  if (getLangOpts().OpenCL) {
+GenOpenCLArgMetadata(Fn);
+Fn->setCallingConv(llvm::CallingConv::SPIR_KERNEL);
+  }
+
   CXXGlobalInits.clear();
 }
 

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=360342&r1=360341&r2=360342&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Thu May  9 06:55:44 2019
@@ -536,205 +536,6 @@ CodeGenFunction::DecodeAddrUsedInPrologu
 "decoded_addr");
 }
 
-static void removeImageAccessQualifier(std::string& TyName) {
-  std::string ReadOnlyQual("__read_only");
-  std::string::size_type ReadOnlyPos = TyName.find(ReadOnlyQual);
-  if (ReadOnlyPos != std::string::npos)
-// "+ 1" for the space after access qualifier.
-TyName.erase(ReadOnlyPos, ReadOnlyQual.size() + 1);
-  else {
-std::string WriteOnlyQual("__write_only");
-std::string::size_type WriteOnlyPos = TyName.find(WriteOnlyQual);
-if (WriteOnlyPos != std::string::npos)
-  TyName.erase(WriteOnlyPos, WriteOnlyQual.size() + 1);
-else {
-  std::string ReadWriteQual("__read_write");
-  std::string::size_type ReadWritePos = TyName.find(ReadWriteQual);
-  if (ReadWritePos != std::string::npos)
-TyName.erase(ReadWritePos, ReadWriteQual.size() + 1);
-}
-  }
-}
-
-// Returns the address space id that should be produced to the
-// kernel_arg_addr_space metadata. This is always fixed to the ids
-// as specified in the SPIR 2.0 specification in order to differentiate
-// for example in clGetKernelArgInfo() implementation between the address
-// spaces with targets without unique mapping to the OpenCL address spaces
-// (basically all single AS CPUs).
-static unsigned ArgInfoAddressSpace(LangAS AS) {
-  switch (AS) {
-  case LangAS::opencl_global:   return 1;
-  case LangAS::opencl_constant: return 2;
-  case LangAS::opencl_local:return 3;
-  case LangAS::opencl_generic:  return 4; // Not in SPIR 2.0 specs.
-  default:
-return 0; // Assume private.
-  }
-}
-
-// OpenCL v1.2 s5.6.4.6 allows the compiler to store kernel argument
-// information in the program executable. The argument information stored
-// includes the argument name, its type, the address and access qualifiers 
used.
-static void GenOpenCLArgMetadata(const FunctionDecl *FD, llvm::Function *Fn,
- CodeGenModule &CGM, llvm::LLVMContext 
&Context,
- CGBuilderTy &Builder, ASTContext &ASTCtx) {
-  // Create MDNodes that represent the kernel arg metadata.
-  // Each MDNode is a list in the form of "key", N number of values which is
-  // the same number of values as their are kernel arguments.
-
-  const PrintingPolicy &Policy = ASTCtx.getPrintingPolicy();
-
-  // MDNode for the kernel argument address space qualifiers.
-  SmallVector addressQuals;
-
-  // MDNode for the kernel argument access qualifiers (images only).
-  SmallVector access

r342885 - Revert "We allow implicit function declarations as an extension in all C dialects. Remove OpenCL special case."

2018-09-24 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Mon Sep 24 07:21:56 2018
New Revision: 342885

URL: http://llvm.org/viewvc/llvm-project?rev=342885&view=rev
Log:
Revert "We allow implicit function declarations as an extension in all C 
dialects. Remove OpenCL special case."

Discussed on cfe-commits (Week-of-Mon-20180820), this change leads to
the generation of invalid IR for OpenCL without giving an error.
Therefore, the conclusion was to revert.


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaOpenCL/clang-builtin-version.cl
cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=342885&r1=342884&r2=342885&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Sep 24 07:21:56 
2018
@@ -369,7 +369,7 @@ def warn_implicit_function_decl : Warnin
   "implicit declaration of function %0">,
   InGroup, DefaultIgnore;
 def ext_implicit_function_decl : ExtWarn<
-  "implicit declaration of function %0 is invalid in %select{C99|OpenCL}1">,
+  "implicit declaration of function %0 is invalid in C99">,
   InGroup;
 def note_function_suggestion : Note<"did you mean %0?">;
 
@@ -8556,6 +8556,8 @@ def err_opencl_scalar_type_rank_greater_
 "element. (%0 and %1)">;
 def err_bad_kernel_param_type : Error<
   "%0 cannot be used as the type of a kernel parameter">;
+def err_opencl_implicit_function_decl : Error<
+  "implicit declaration of function %0 is invalid in OpenCL">;
 def err_record_with_pointers_kernel_param : Error<
   "%select{struct|union}0 kernel parameters may not contain pointers">;
 def note_within_field_of_type : Note<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=342885&r1=342884&r2=342885&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Sep 24 07:21:56 2018
@@ -13360,15 +13360,17 @@ NamedDecl *Sema::ImplicitlyDefineFunctio
   }
 
   // Extension in C99.  Legal in C90, but warn about it.
-  // OpenCL v2.0 s6.9.u - Implicit function declaration is not supported.
   unsigned diag_id;
   if (II.getName().startswith("__builtin_"))
 diag_id = diag::warn_builtin_unknown;
-  else if (getLangOpts().C99 || getLangOpts().OpenCL)
+  // OpenCL v2.0 s6.9.u - Implicit function declaration is not supported.
+  else if (getLangOpts().OpenCL)
+diag_id = diag::err_opencl_implicit_function_decl;
+  else if (getLangOpts().C99)
 diag_id = diag::ext_implicit_function_decl;
   else
 diag_id = diag::warn_implicit_function_decl;
-  Diag(Loc, diag_id) << &II << getLangOpts().OpenCL;
+  Diag(Loc, diag_id) << &II;
 
   // If we found a prior declaration of this function, don't bother building
   // another one. We've already pushed that one into scope, so there's nothing

Modified: cfe/trunk/test/SemaOpenCL/clang-builtin-version.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/clang-builtin-version.cl?rev=342885&r1=342884&r2=342885&view=diff
==
--- cfe/trunk/test/SemaOpenCL/clang-builtin-version.cl (original)
+++ cfe/trunk/test/SemaOpenCL/clang-builtin-version.cl Mon Sep 24 07:21:56 2018
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -fblocks -verify -pedantic-errors -fsyntax-only 
-ferror-limit 100
+// RUN: %clang_cc1 %s -fblocks -verify -pedantic -fsyntax-only -ferror-limit 
100
 
 // Confirm CL2.0 Clang builtins are not available in earlier versions
 

Modified: cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl?rev=342885&r1=342884&r2=342885&view=diff
==
--- cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl (original)
+++ cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl Mon Sep 24 07:21:56 2018
@@ -10,7 +10,7 @@ void test(void) {
 
   glob = to_global(glob, loc);
 #if __OPENCL_C_VERSION__ < CL_VERSION_2_0
-  // expected-warning@-2{{implicit declaration of function 'to_global' is 
invalid in OpenCL}}
+  // expected-error@-2{{implicit declaration of function 'to_global' is 
invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning 
to '__global int *' from 'int'}}
 #else
   // expected-error@-5{{invalid number of arguments to function: 'to_global'}}


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


r353160 - Fix ICE on reference binding with mismatching addr spaces.

2019-02-05 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Tue Feb  5 03:32:58 2019
New Revision: 353160

URL: http://llvm.org/viewvc/llvm-project?rev=353160&view=rev
Log:
Fix ICE on reference binding with mismatching addr spaces.

When we attempt to add an addr space qual to a type already
qualified by an addr space ICE is triggered. Before creating
a type with new address space, remove the old addr space.

Fixing PR38614!

Differential Revision: https://reviews.llvm.org/D57524


Added:
cfe/trunk/test/SemaOpenCLCXX/address-space-of-this.cl
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=353160&r1=353159&r2=353160&view=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Tue Feb  5 03:32:58 2019
@@ -4670,19 +4670,23 @@ static void TryReferenceInitializationCo
 //   applied.
 // Postpone address space conversions to after the temporary 
materialization
 // conversion to allow creating temporaries in the alloca address space.
-auto AS1 = T1Quals.getAddressSpace();
-auto AS2 = T2Quals.getAddressSpace();
-T1Quals.removeAddressSpace();
-T2Quals.removeAddressSpace();
-QualType cv1T4 = S.Context.getQualifiedType(cv2T2, T1Quals);
-if (T1Quals != T2Quals)
+auto T1QualsIgnoreAS = T1Quals;
+auto T2QualsIgnoreAS = T2Quals;
+if (T1Quals.getAddressSpace() != T2Quals.getAddressSpace()) {
+  T1QualsIgnoreAS.removeAddressSpace();
+  T2QualsIgnoreAS.removeAddressSpace();
+}
+QualType cv1T4 = S.Context.getQualifiedType(cv2T2, T1QualsIgnoreAS);
+if (T1QualsIgnoreAS != T2QualsIgnoreAS)
   Sequence.AddQualificationConversionStep(cv1T4, ValueKind);
 Sequence.AddReferenceBindingStep(cv1T4, ValueKind == VK_RValue);
 ValueKind = isLValueRef ? VK_LValue : VK_XValue;
-if (AS1 != AS2) {
-  T1Quals.addAddressSpace(AS1);
-  QualType cv1AST4 = S.Context.getQualifiedType(cv2T2, T1Quals);
-  Sequence.AddQualificationConversionStep(cv1AST4, ValueKind);
+// Add addr space conversion if required.
+if (T1Quals.getAddressSpace() != T2Quals.getAddressSpace()) {
+  auto T4Quals = cv1T4.getQualifiers();
+  T4Quals.addAddressSpace(T1Quals.getAddressSpace());
+  QualType cv1T4WithAS = S.Context.getQualifiedType(T2, T4Quals);
+  Sequence.AddQualificationConversionStep(cv1T4WithAS, ValueKind);
 }
 
 //   In any case, the reference is bound to the resulting glvalue (or to

Added: cfe/trunk/test/SemaOpenCLCXX/address-space-of-this.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCLCXX/address-space-of-this.cl?rev=353160&view=auto
==
--- cfe/trunk/test/SemaOpenCLCXX/address-space-of-this.cl (added)
+++ cfe/trunk/test/SemaOpenCLCXX/address-space-of-this.cl Tue Feb  5 03:32:58 
2019
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic 
-verify -fsyntax-only
+// expected-no-diagnostics
+
+// Extract from PR38614
+struct C {};
+
+C f1() {
+ return C{};
+}
+
+C f2(){
+C c;
+return c;
+}


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


r353431 - [OpenCL][PR40603] In C++ preserve compatibility with OpenCL C v2.0

2019-02-07 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu Feb  7 09:32:37 2019
New Revision: 353431

URL: http://llvm.org/viewvc/llvm-project?rev=353431&view=rev
Log:
[OpenCL][PR40603] In C++ preserve compatibility with OpenCL C v2.0

Valid OpenCL C code should still compile in C++ mode.

This change enables extensions and OpenCL types.

Differential Revision: https://reviews.llvm.org/D57824


Modified:
cfe/trunk/include/clang/Basic/OpenCLOptions.h
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/lib/Parse/ParsePragma.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/test/SemaOpenCL/extension-version.cl
cfe/trunk/test/SemaOpenCL/extensions.cl

Modified: cfe/trunk/include/clang/Basic/OpenCLOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenCLOptions.h?rev=353431&r1=353430&r2=353431&view=diff
==
--- cfe/trunk/include/clang/Basic/OpenCLOptions.h (original)
+++ cfe/trunk/include/clang/Basic/OpenCLOptions.h Thu Feb  7 09:32:37 2019
@@ -14,6 +14,7 @@
 #ifndef LLVM_CLANG_BASIC_OPENCLOPTIONS_H
 #define LLVM_CLANG_BASIC_OPENCLOPTIONS_H
 
+#include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/StringMap.h"
 
 namespace clang {
@@ -41,25 +42,29 @@ public:
 
   // Is supported as either an extension or an (optional) core feature for
   // OpenCL version \p CLVer.
-  bool isSupported(llvm::StringRef Ext, unsigned CLVer) const {
+  bool isSupported(llvm::StringRef Ext, LangOptions LO) const {
+// In C++ mode all extensions should work at least as in v2.0.
+auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion;
 auto I = OptMap.find(Ext)->getValue();
 return I.Supported && I.Avail <= CLVer;
   }
 
   // Is supported (optional) OpenCL core features for OpenCL version \p CLVer.
   // For supported extension, return false.
-  bool isSupportedCore(llvm::StringRef Ext, unsigned CLVer) const {
+  bool isSupportedCore(llvm::StringRef Ext, LangOptions LO) const {
+// In C++ mode all extensions should work at least as in v2.0.
+auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion;
 auto I = OptMap.find(Ext)->getValue();
-return I.Supported && I.Avail <= CLVer &&
-  I.Core != ~0U && CLVer >= I.Core;
+return I.Supported && I.Avail <= CLVer && I.Core != ~0U && CLVer >= I.Core;
   }
 
   // Is supported OpenCL extension for OpenCL version \p CLVer.
   // For supported (optional) core feature, return false.
- bool isSupportedExtension(llvm::StringRef Ext, unsigned CLVer) const {
+  bool isSupportedExtension(llvm::StringRef Ext, LangOptions LO) const {
+// In C++ mode all extensions should work at least as in v2.0.
+auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion;
 auto I = OptMap.find(Ext)->getValue();
-return I.Supported && I.Avail <= CLVer &&
-  (I.Core == ~0U || CLVer < I.Core);
+return I.Supported && I.Avail <= CLVer && (I.Core == ~0U || CLVer < 
I.Core);
   }
 
   void enable(llvm::StringRef Ext, bool V = true) {
@@ -121,10 +126,10 @@ public:
   I->second.Enabled = false;
   }
 
-  void enableSupportedCore(unsigned CLVer) {
-for (llvm::StringMap::iterator I = OptMap.begin(),
- E = OptMap.end(); I != E; ++I)
-  if (isSupportedCore(I->getKey(), CLVer))
+  void enableSupportedCore(LangOptions LO) {
+for (llvm::StringMap::iterator I = OptMap.begin(), E = OptMap.end();
+ I != E; ++I)
+  if (isSupportedCore(I->getKey(), LO))
 I->second.Enabled = true;
   }
 
@@ -132,6 +137,6 @@ public:
   friend class ASTReader;
 };
 
-}  // end namespace clang
+} // end namespace clang
 
 #endif

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=353431&r1=353430&r2=353431&view=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Thu Feb  7 09:32:37 2019
@@ -1058,10 +1058,9 @@ static void InitializePredefinedMacros(c
 
   // OpenCL definitions.
   if (LangOpts.OpenCL) {
-#define OPENCLEXT(Ext) \
-if (TI.getSupportedOpenCLOpts().isSupported(#Ext, \
-LangOpts.OpenCLVersion)) \
-  Builder.defineMacro(#Ext);
+#define OPENCLEXT(Ext) 
\
+  if (TI.getSupportedOpenCLOpts().isSupported(#Ext, LangOpts)) 
\
+Builder.defineMacro(#Ext);
 #include "clang/Basic/OpenCLExtensions.def"
 
 auto Arch = TI.getTriple().getArch();

Modified: cfe/trunk/lib/Parse/ParsePragma.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.cpp?rev=353431&r1=353430&r2=353431&view=diff
==
--- cfe/trunk/lib/Parse/ParsePragma.cpp (original)
+++ cfe/trunk/lib/Parse/ParsePragma.cpp Thu Feb  7 09:32:37 2019
@@ -692,13 +692,12 @@ void Parser::HandlePragma

r354121 - [OpenCL][PR40707] Allow OpenCL C types in C++ mode.

2019-02-15 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Fri Feb 15 04:07:57 2019
New Revision: 354121

URL: http://llvm.org/viewvc/llvm-project?rev=354121&view=rev
Log:
[OpenCL][PR40707] Allow OpenCL C types in C++ mode.

Allow all OpenCL types to be parsed in C++ mode.


Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/TokenKinds.def
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseTentative.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/CodeGenOpenCL/images.cl
cfe/trunk/test/SemaOpenCL/invalid-image.cl
cfe/trunk/test/SemaOpenCLCXX/restricted.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=354121&r1=354120&r2=354121&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Fri Feb 15 04:07:57 
2019
@@ -1133,8 +1133,6 @@ def err_opencl_logical_exclusive_or : Er
 // OpenCL C++.
 def err_openclcxx_virtual_function : Error<
   "virtual functions are not supported in OpenCL C++">;
-def err_openclcxx_reserved : Error<
-  "'%0' is a reserved keyword in OpenCL C++">;
 
 // OpenMP support.
 def warn_pragma_omp_ignored : Warning<

Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=354121&r1=354120&r2=354121&view=diff
==
--- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/trunk/include/clang/Basic/TokenKinds.def Fri Feb 15 04:07:57 2019
@@ -550,9 +550,9 @@ ALIAS("read_only", __read_only  , KE
 ALIAS("write_only", __write_only, KEYOPENCLC | KEYOPENCLCXX)
 ALIAS("read_write", __read_write, KEYOPENCLC | KEYOPENCLCXX)
 // OpenCL builtins
-KEYWORD(__builtin_astype, KEYOPENCLC)
+KEYWORD(__builtin_astype, KEYOPENCLC | KEYOPENCLCXX)
 KEYWORD(vec_step, KEYOPENCLC | KEYALTIVEC | KEYZVECTOR)
-#define GENERIC_IMAGE_TYPE(ImgType, Id) KEYWORD(ImgType##_t, KEYOPENCLC)
+#define GENERIC_IMAGE_TYPE(ImgType, Id) KEYWORD(ImgType##_t, KEYOPENCLC | 
KEYOPENCLCXX)
 #include "clang/Basic/OpenCLImageTypes.def"
 
 // OpenMP Type Traits

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=354121&r1=354120&r2=354121&view=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Feb 15 04:07:57 2019
@@ -3809,19 +3809,6 @@ void Parser::ParseDeclarationSpecifiers(
  getLangOpts());
   break;
 
-// OpenCL access qualifiers:
-case tok::kw___read_only:
-case tok::kw___write_only:
-case tok::kw___read_write:
-  // OpenCL C++ 1.0 s2.2: access qualifiers are reserved keywords.
-  if (Actions.getLangOpts().OpenCLCPlusPlus) {
-DiagID = diag::err_openclcxx_reserved;
-PrevSpec = Tok.getIdentifierInfo()->getNameStart();
-isInvalid = true;
-  }
-  ParseOpenCLQualifiers(DS.getAttributes());
-  break;
-
 // OpenCL address space qualifiers:
 case tok::kw___generic:
   // generic address space is introduced only in OpenCL v2.0
@@ -3838,6 +3825,10 @@ void Parser::ParseDeclarationSpecifiers(
 case tok::kw___global:
 case tok::kw___local:
 case tok::kw___constant:
+// OpenCL access qualifiers:
+case tok::kw___read_only:
+case tok::kw___write_only:
+case tok::kw___read_write:
   ParseOpenCLQualifiers(DS.getAttributes());
   break;
 

Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=354121&r1=354120&r2=354121&view=diff
==
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Fri Feb 15 04:07:57 2019
@@ -1998,6 +1998,13 @@ void Parser::ParseCXXSimpleTypeSpecifier
   case tok::kw_bool:
 DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec, DiagID, Policy);
 break;
+#define GENERIC_IMAGE_TYPE(ImgType, Id)
\
+  case tok::kw_##ImgType##_t:  
\
+DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, DiagID, 
\
+   Policy);
\
+break;
+#include "clang/Basic/OpenCLImageTypes.def"
+
   case tok::annot_decltype:
   case tok::kw_decltype:
 DS.SetRangeEnd(ParseDecltypeSpecifier(DS));

Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
URL: 
http://llvm.org/viewvc/llvm

r312728 - [OpenCL] Handle taking an address of block captures.

2017-09-07 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu Sep  7 10:00:33 2017
New Revision: 312728

URL: http://llvm.org/viewvc/llvm-project?rev=312728&view=rev
Log:
[OpenCL] Handle taking an address of block captures.

Block captures can have different physical locations
in memory segments depending on the use case (as a function
call or as a kernel enqueue) and in different vendor
implementations.

Therefore it's unclear how to add address space to capture
addresses uniformly. Currently it has been decided to disallow
taking addresses of captured variables until further
clarifications in the spec.

Differential Revision: https://reviews.llvm.org/D36410


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaOpenCL/invalid-block.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=312728&r1=312727&r2=312728&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Sep  7 10:00:33 
2017
@@ -7349,8 +7349,8 @@ def err_invalid_conversion_between_vecto
 def err_opencl_function_pointer : Error<
   "pointers to functions are not allowed">;
 
-def err_opencl_taking_function_address : Error<
-  "taking address of function is not allowed">;
+def err_opencl_taking_address_capture : Error<
+  "taking address of a capture is not allowed">;
 
 def err_invalid_conversion_between_vector_and_scalar : Error<
   "invalid conversion between vector type %0 and scalar type %1">;

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=312728&r1=312727&r2=312728&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Sep  7 10:00:33 2017
@@ -425,14 +425,6 @@ ExprResult Sema::DefaultFunctionArrayCon
   assert(!Ty.isNull() && "DefaultFunctionArrayConversion - missing type");
 
   if (Ty->isFunctionType()) {
-// If we are here, we are not calling a function but taking
-// its address (which is not allowed in OpenCL v1.0 s6.8.a.3).
-if (getLangOpts().OpenCL) {
-  if (Diagnose)
-Diag(E->getExprLoc(), diag::err_opencl_taking_function_address);
-  return ExprError();
-}
-
 if (auto *DRE = dyn_cast(E->IgnoreParenCasts()))
   if (auto *FD = dyn_cast(DRE->getDecl()))
 if (!checkAddressOfFunctionIsAvailable(FD, Diagnose, E->getExprLoc()))
@@ -10869,10 +10861,17 @@ QualType Sema::CheckAddressOfOperand(Exp
   // Make sure to ignore parentheses in subsequent checks
   Expr *op = OrigOp.get()->IgnoreParens();
 
-  // OpenCL v1.0 s6.8.a.3: Pointers to functions are not allowed.
-  if (LangOpts.OpenCL && op->getType()->isFunctionType()) {
-Diag(op->getExprLoc(), diag::err_opencl_taking_function_address);
-return QualType();
+  // In OpenCL captures for blocks called as lambda functions
+  // are located in the private address space. Blocks used in
+  // enqueue_kernel can be located in a different address space
+  // depending on a vendor implementation. Thus preventing
+  // taking an address of the capture to avoid invalid AS casts.
+  if (LangOpts.OpenCL) {
+auto* VarRef = dyn_cast(op);
+if (VarRef && VarRef->refersToEnclosingVariableOrCapture()) {
+  Diag(op->getExprLoc(), diag::err_opencl_taking_address_capture);
+  return QualType();
+}
   }
 
   if (getLangOpts().C99) {

Modified: cfe/trunk/test/SemaOpenCL/invalid-block.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-block.cl?rev=312728&r1=312727&r2=312728&view=diff
==
--- cfe/trunk/test/SemaOpenCL/invalid-block.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-block.cl Thu Sep  7 10:00:33 2017
@@ -81,3 +81,14 @@ kernel void f7() {
   };
   return;
 }
+
+// Taking address of a capture is not allowed
+int g;
+kernel void f8(int a1) {
+  int a2;
+  void (^bl)(void) = ^(void) {
+&g; //expected-warning{{expression result unused}}
+&a1; //expected-error{{taking address of a capture is not allowed}}
+&a2; //expected-error{{taking address of a capture is not allowed}}
+  };
+}


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


r362102 - [OpenCL] Fix OpenCL/SPIR version metadata in C++ mode.

2019-05-30 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu May 30 08:18:07 2019
New Revision: 362102

URL: http://llvm.org/viewvc/llvm-project?rev=362102&view=rev
Log:
[OpenCL] Fix OpenCL/SPIR version metadata in C++ mode.

C++ is derived from OpenCL v2.0 therefore set the versions
identically.

Differential Revision: https://reviews.llvm.org/D62657


Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGenOpenCL/spir_version.cl

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=362102&r1=362101&r2=362102&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu May 30 08:18:07 2019
@@ -564,11 +564,13 @@ void CodeGenModule::Release() {
 if (getTriple().isSPIR()) {
   // SPIR v2.0 s2.12 - The SPIR version used by the module is stored in the
   // opencl.spir.version named metadata.
+  // C++ is backwards compatible with OpenCL v2.0.
+  auto Version = LangOpts.OpenCLCPlusPlus ? 200 : LangOpts.OpenCLVersion;
   llvm::Metadata *SPIRVerElts[] = {
   llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
-  Int32Ty, LangOpts.OpenCLVersion / 100)),
+  Int32Ty, Version / 100)),
   llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
-  Int32Ty, (LangOpts.OpenCLVersion / 100 > 1) ? 0 : 2))};
+  Int32Ty, (Version / 100 > 1) ? 0 : 2))};
   llvm::NamedMDNode *SPIRVerMD =
   TheModule.getOrInsertNamedMetadata("opencl.spir.version");
   llvm::LLVMContext &Ctx = TheModule.getContext();
@@ -623,11 +625,14 @@ void CodeGenModule::Release() {
 void CodeGenModule::EmitOpenCLMetadata() {
   // SPIR v2.0 s2.13 - The OpenCL version used by the module is stored in the
   // opencl.ocl.version named metadata node.
+  // C++ is backwards compatible with OpenCL v2.0.
+  // FIXME: We might need to add CXX version at some point too?
+  auto Version = LangOpts.OpenCLCPlusPlus ? 200 : LangOpts.OpenCLVersion;
   llvm::Metadata *OCLVerElts[] = {
   llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
-  Int32Ty, LangOpts.OpenCLVersion / 100)),
+  Int32Ty, Version / 100)),
   llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
-  Int32Ty, (LangOpts.OpenCLVersion % 100) / 10))};
+  Int32Ty, (Version % 100) / 10))};
   llvm::NamedMDNode *OCLVerMD =
   TheModule.getOrInsertNamedMetadata("opencl.ocl.version");
   llvm::LLVMContext &Ctx = TheModule.getContext();

Modified: cfe/trunk/test/CodeGenOpenCL/spir_version.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/spir_version.cl?rev=362102&r1=362101&r2=362102&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/spir_version.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/spir_version.cl Thu May 30 08:18:07 2019
@@ -5,6 +5,9 @@
 // RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - 
-cl-std=CL1.2 | FileCheck %s --check-prefix=CHECK-SPIR-CL12
 // RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - 
-cl-std=CL2.0 | FileCheck %s --check-prefix=CHECK-SPIR-CL20
 
+
+// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - 
-cl-std=c++ | FileCheck %s --check-prefix=CHECK-SPIR-CL20
+
 // RUN: %clang_cc1 %s -triple "amdgcn--amdhsa" -emit-llvm -o - | FileCheck %s 
--check-prefix=CHECK-AMDGCN-CL10
 // RUN: %clang_cc1 %s -triple "amdgcn--amdhsa" -emit-llvm -o - -cl-std=CL1.2 | 
FileCheck %s --check-prefix=CHECK-AMDGCN-CL12
 // RUN: %clang_cc1 %s -triple "amdgcn--amdhsa" -emit-llvm -o - -cl-std=CL2.0 | 
FileCheck %s --check-prefix=CHECK-AMDGCN-CL20


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


r362409 - [PR41567][Sema] Fixed cast kind in addr space conversions

2019-06-03 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Mon Jun  3 08:42:36 2019
New Revision: 362409

URL: http://llvm.org/viewvc/llvm-project?rev=362409&view=rev
Log:
[PR41567][Sema] Fixed cast kind in addr space conversions

This change sets missing cast kind correctly in the address
space conversion case.

Differential Revision: https://reviews.llvm.org/D62299


Added:
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-conversion.cl
Modified:
cfe/trunk/lib/Sema/SemaCast.cpp

Modified: cfe/trunk/lib/Sema/SemaCast.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=362409&r1=362408&r2=362409&view=diff
==
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCast.cpp Mon Jun  3 08:42:36 2019
@@ -2450,6 +2450,10 @@ void CastOperation::CheckCXXCStyleCast(b
 tcr = TryAddressSpaceCast(Self, SrcExpr, DestType, /*CStyle*/ true, msg);
 if (SrcExpr.isInvalid())
   return;
+
+if (isValidCast(tcr))
+  Kind = CK_AddressSpaceConversion;
+
 if (tcr == TC_NotApplicable) {
   // ... or if that is not possible, a static_cast, ignoring const, ...
   tcr = TryStaticCast(Self, SrcExpr, DestType, CCK, OpRange, msg, Kind,

Added: cfe/trunk/test/CodeGenOpenCLCXX/addrspace-conversion.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/addrspace-conversion.cl?rev=362409&view=auto
==
--- cfe/trunk/test/CodeGenOpenCLCXX/addrspace-conversion.cl (added)
+++ cfe/trunk/test/CodeGenOpenCLCXX/addrspace-conversion.cl Mon Jun  3 08:42:36 
2019
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -emit-llvm -O0 
-o - | FileCheck %s
+
+void bar(__generic volatile unsigned int* ptr)
+{
+  //CHECK: addrspacecast i32 addrspace(4)* %{{.+}} to i32 addrspace(1)*
+  auto gptr = (__global volatile unsigned int*)ptr;
+}


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


r362604 - [Sema] Prevent binding incompatible addr space ref to temporaries

2019-06-05 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Wed Jun  5 07:03:34 2019
New Revision: 362604

URL: http://llvm.org/viewvc/llvm-project?rev=362604&view=rev
Log:
[Sema] Prevent binding incompatible addr space ref to temporaries

References to arbitrary address spaces can't always be bound to
temporaries. This change extends the reference binding logic to
check that the address space of a temporary can be implicitly
converted to the address space in a reference when temporary
materialization is performed.

Differential Revision: https://reviews.llvm.org/D61318


Added:
cfe/trunk/test/SemaOpenCLCXX/address-space-references.cl
Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Initialization.h
cfe/trunk/lib/Sema/SemaInit.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=362604&r1=362603&r2=362604&view=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Wed Jun  5 07:03:34 2019
@@ -460,21 +460,25 @@ public:
 Mask |= qs.Mask;
   }
 
-  /// Returns true if this address space is a superset of the other one.
+  /// Returns true if address space A is equal to or a superset of B.
   /// OpenCL v2.0 defines conversion rules (OpenCLC v2.0 s6.5.5) and notion of
   /// overlapping address spaces.
   /// CL1.1 or CL1.2:
   ///   every address space is a superset of itself.
   /// CL2.0 adds:
   ///   __generic is a superset of any address space except for __constant.
+  static bool isAddressSpaceSupersetOf(LangAS A, LangAS B) {
+// Address spaces must match exactly.
+return A == B ||
+   // Otherwise in OpenCLC v2.0 s6.5.5: every address space except
+   // for __constant can be used as __generic.
+   (A == LangAS::opencl_generic && B != LangAS::opencl_constant);
+  }
+
+  /// Returns true if the address space in these qualifiers is equal to or
+  /// a superset of the address space in the argument qualifiers.
   bool isAddressSpaceSupersetOf(Qualifiers other) const {
-return
-// Address spaces must match exactly.
-getAddressSpace() == other.getAddressSpace() ||
-// Otherwise in OpenCLC v2.0 s6.5.5: every address space except
-// for __constant can be used as __generic.
-(getAddressSpace() == LangAS::opencl_generic &&
- other.getAddressSpace() != LangAS::opencl_constant);
+return isAddressSpaceSupersetOf(getAddressSpace(), 
other.getAddressSpace());
   }
 
   /// Determines if these qualifiers compatibly include another set.

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=362604&r1=362603&r2=362604&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jun  5 07:03:34 
2019
@@ -1857,6 +1857,9 @@ def err_reference_bind_failed : Error<
   "reference %diff{to %select{type|incomplete type}1 $ could not bind to an "
   "%select{rvalue|lvalue}2 of type $|could not bind to %select{rvalue|lvalue}2 
of "
   "incompatible type}0,3">;
+def err_reference_bind_temporary_addrspace : Error<
+  "reference of type %0 cannot bind to a temporary object because of "
+  "address space mismatch">;
 def err_reference_bind_init_list : Error<
   "reference to type %0 cannot bind to an initializer list">;
 def err_init_list_bad_dest_type : Error<

Modified: cfe/trunk/include/clang/Sema/Initialization.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Initialization.h?rev=362604&r1=362603&r2=362604&view=diff
==
--- cfe/trunk/include/clang/Sema/Initialization.h (original)
+++ cfe/trunk/include/clang/Sema/Initialization.h Wed Jun  5 07:03:34 2019
@@ -1012,6 +1012,9 @@ public:
 /// Reference binding drops qualifiers.
 FK_ReferenceInitDropsQualifiers,
 
+/// Reference with mismatching address space binding to temporary.
+FK_ReferenceAddrspaceMismatchTemporary,
+
 /// Reference binding failed.
 FK_ReferenceInitFailed,
 

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=362604&r1=362603&r2=362604&view=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Jun  5 07:03:34 2019
@@ -3344,6 +3344,7 @@ bool InitializationSequence::isAmbiguous
   case FK_NonConstLValueReferenceBindingToVectorElement:
   case FK_NonConstLValueReferenceBindingToUnrelated:
   case FK_RValueReferenceBindingToLValue:
+  case FK_ReferenceAddrspaceMis

r362611 - [OpenCL][PR42031] Prevent deducing addr space in type alias.

2019-06-05 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Wed Jun  5 07:50:01 2019
New Revision: 362611

URL: http://llvm.org/viewvc/llvm-project?rev=362611&view=rev
Log:
[OpenCL][PR42031] Prevent deducing addr space in type alias.
 
Similar to typedefs we shouldn't deduce addr space in
type alias.
 
Differential Revision: https://reviews.llvm.org/D62591


Modified:
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=362611&r1=362610&r2=362611&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Jun  5 07:50:01 2019
@@ -7401,6 +7401,9 @@ static void deduceOpenCLImplicitAddrSpac
   (D.getContext() == DeclaratorContext::MemberContext &&
(!IsPointee &&
 D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static)) ||
+  // Do not deduce addr space of non-pointee in type alias because it
+  // doesn't define any object.
+  (D.getContext() == DeclaratorContext::AliasDeclContext && !IsPointee) ||
   // Do not deduce addr space for types used to define a typedef and the
   // typedef itself, except the pointee type of a pointer type which is 
used
   // to define the typedef.

Modified: cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl?rev=362611&r1=362610&r2=362611&view=diff
==
--- cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl (original)
+++ cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl Wed Jun  5 07:50:01 
2019
@@ -1,12 +1,26 @@
-//RUN: %clang_cc1 %s -cl-std=c++ -pedantic -ast-dump -verify
+//RUN: %clang_cc1 %s -cl-std=c++ -pedantic -ast-dump -verify | FileCheck %s
 
 //expected-no-diagnostics
 
-//CHECK: |-VarDecl  foo {{.*}} 'const __global int' constexpr cinit
+//CHECK: |-VarDecl {{.*}} foo 'const __global int'
 constexpr int foo = 0;
 
 class c {
 public:
-  //CHECK: `-VarDecl {{.*}} foo2 'const __global int' static constexpr cinit
+  //CHECK: `-VarDecl {{.*}} foo2 'const __global int'
   static constexpr int foo2 = 0;
 };
+
+struct c1 {};
+
+// We only deduce addr space in type alias in pointer types.
+//CHECK: TypeAliasDecl {{.*}} alias_c1 'c1'
+using alias_c1 = c1;
+//CHECK: TypeAliasDecl {{.*}} alias_c1_ptr '__generic c1 *'
+using alias_c1_ptr = c1 *;
+
+struct c2 {
+  alias_c1 y;
+  alias_c1_ptr ptr = &y;
+};
+


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


r362623 - [Clang] Fix pretty printing of CUDA address spaces

2019-06-05 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Wed Jun  5 10:29:00 2019
New Revision: 362623

URL: http://llvm.org/viewvc/llvm-project?rev=362623&view=rev
Log:
[Clang] Fix pretty printing of CUDA address spaces

Patch by richardmembarth (Richard Membarth)!

Differential Revision: https://reviews.llvm.org/D54258


Modified:
cfe/trunk/lib/AST/TypePrinter.cpp

Modified: cfe/trunk/lib/AST/TypePrinter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=362623&r1=362622&r2=362623&view=diff
==
--- cfe/trunk/lib/AST/TypePrinter.cpp (original)
+++ cfe/trunk/lib/AST/TypePrinter.cpp Wed Jun  5 10:29:00 2019
@@ -1805,17 +1805,19 @@ void Qualifiers::print(raw_ostream &OS,
   case LangAS::opencl_private:
 break;
   case LangAS::opencl_constant:
-  case LangAS::cuda_constant:
 OS << "__constant";
 break;
   case LangAS::opencl_generic:
 OS << "__generic";
 break;
   case LangAS::cuda_device:
-OS << "__device";
+OS << "__device__";
+break;
+  case LangAS::cuda_constant:
+OS << "__constant__";
 break;
   case LangAS::cuda_shared:
-OS << "__shared";
+OS << "__shared__";
 break;
   default:
 OS << "__attribute__((address_space(";


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


r363944 - [Sema] Diagnose addr space mismatch while constructing objects

2019-06-20 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu Jun 20 09:23:28 2019
New Revision: 363944

URL: http://llvm.org/viewvc/llvm-project?rev=363944&view=rev
Log:
[Sema] Diagnose addr space mismatch while constructing objects

If we construct an object in some arbitrary non-default addr space
it should fail unless either:
- There is an implicit conversion from the address space to default
/generic address space.
- There is a matching ctor qualified with an address space that is
either exactly matching or convertible to the address space of an
object.

Differential Revision: https://reviews.llvm.org/D62156


Added:
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-ctor.cl
cfe/trunk/test/SemaCXX/address-space-ctor.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Overload.h
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/CodeGenCXX/address-space-of-this.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=363944&r1=363943&r2=363944&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jun 20 09:23:28 
2019
@@ -3683,6 +3683,9 @@ def note_ovl_candidate_inherited_constru
 def note_ovl_candidate_illegal_constructor : Note<
 "candidate %select{constructor|template}0 ignored: "
 "instantiation %select{takes|would take}0 its own class type by value">;
+def note_ovl_candidate_illegal_constructor_adrspace_mismatch : Note<
+"candidate constructor ignored: cannot be used to construct an object "
+"in address space %0">;
 def note_ovl_candidate_bad_deduction : Note<
 "candidate template ignored: failed template argument deduction">;
 def note_ovl_candidate_incomplete_deduction : Note<"candidate template 
ignored: "

Modified: cfe/trunk/include/clang/Sema/Overload.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Overload.h?rev=363944&r1=363943&r2=363944&view=diff
==
--- cfe/trunk/include/clang/Sema/Overload.h (original)
+++ cfe/trunk/include/clang/Sema/Overload.h Thu Jun 20 09:23:28 2019
@@ -723,6 +723,11 @@ class Sema;
 /// This candidate was not viable because it is a non-default 
multiversioned
 /// function.
 ovl_non_default_multiversion_function,
+
+/// This constructor/conversion candidate fail due to an address space
+/// mismatch between the object being constructed and the overload
+/// candidate.
+ovl_fail_object_addrspace_mismatch
   };
 
   /// A list of implicit conversion sequences for the arguments of an
@@ -878,6 +883,9 @@ class Sema;
 unsigned NumInlineBytesUsed = 0;
 llvm::AlignedCharArray InlineSpace;
 
+// Address space of the object being constructed.
+LangAS DestAS = LangAS::Default;
+
 /// If we have space, allocates from inline storage. Otherwise, allocates
 /// from the slab allocator.
 /// FIXME: It would probably be nice to have a SmallBumpPtrAllocator
@@ -983,6 +991,17 @@ class Sema;
 ArrayRef Cands,
 StringRef Opc = "",
 SourceLocation OpLoc = SourceLocation());
+
+LangAS getDestAS() { return DestAS; }
+
+void setDestAS(LangAS AS) {
+  assert((Kind == CSK_InitByConstructor ||
+  Kind == CSK_InitByUserDefinedConversion) &&
+ "can't set the destination address space when not constructing an 
"
+ "object");
+  DestAS = AS;
+}
+
   };
 
   bool isBetterOverloadCandidate(Sema &S,

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=363944&r1=363943&r2=363944&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Jun 20 09:23:28 2019
@@ -8232,12 +8232,19 @@ QualType Sema::CheckConstructorDeclarato
 
   DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo();
   if (FTI.hasMethodTypeQualifiers()) {
+bool DiagOccured = false;
 FTI.MethodQualifiers->forEachQualifier(
 [&](DeclSpec::TQ TypeQual, StringRef QualName, SourceLocation SL) {
+  // This diagnostic should be emitted on any qualifier except an addr
+  // space qualifier. However, forEachQualifier currently doesn't visit
+  // addr space qualifiers, so there's no way to write this condition
+  // right now; we just diagnose on everything.
   Diag(SL, diag::err_invalid_qualified_constructor)
   << QualName << SourceRange(SL);
+  DiagOccured = true;
 });
-D.setInvalidType();

r366059 - [OpenCL][PR41727] Prevent ICE on global dtors

2019-07-15 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Mon Jul 15 04:58:10 2019
New Revision: 366059

URL: http://llvm.org/viewvc/llvm-project?rev=366059&view=rev
Log:
[OpenCL][PR41727] Prevent ICE on global dtors

Pass NULL to pointer arg of __cxa_atexit if addr space
is not matching with its param. This doesn't align yet
with how dtors are generated that should be changed too.

Differential Revision: https://reviews.llvm.org/D62413


Added:
cfe/trunk/test/CodeGenOpenCLCXX/atexit.cl
Modified:
cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/TargetInfo.h

Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=366059&r1=366058&r2=366059&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Mon Jul 15 04:58:10 2019
@@ -14,6 +14,7 @@
 #include "CGCXXABI.h"
 #include "CGObjCRuntime.h"
 #include "CGOpenMPRuntime.h"
+#include "TargetInfo.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/IR/Intrinsics.h"
@@ -118,9 +119,22 @@ static void EmitDeclDestroy(CodeGenFunct
 CXXDestructorDecl *Dtor = Record->getDestructor();
 
 Func = CGM.getAddrAndTypeOfCXXStructor(GlobalDecl(Dtor, Dtor_Complete));
-Argument = llvm::ConstantExpr::getBitCast(
-Addr.getPointer(), CGF.getTypes().ConvertType(Type)->getPointerTo());
-
+if (CGF.getContext().getLangOpts().OpenCL) {
+  auto DestAS =
+  CGM.getTargetCodeGenInfo().getAddrSpaceOfCxaAtexitPtrParam();
+  auto DestTy = CGF.getTypes().ConvertType(Type)->getPointerTo(
+  CGM.getContext().getTargetAddressSpace(DestAS));
+  auto SrcAS = D.getType().getQualifiers().getAddressSpace();
+  if (DestAS == SrcAS)
+Argument = llvm::ConstantExpr::getBitCast(Addr.getPointer(), DestTy);
+  else
+// FIXME: On addr space mismatch we are passing NULL. The generation
+// of the global destructor function should be adjusted accordingly.
+Argument = llvm::ConstantPointerNull::get(DestTy);
+} else {
+  Argument = llvm::ConstantExpr::getBitCast(
+  Addr.getPointer(), CGF.getTypes().ConvertType(Type)->getPointerTo());
+}
   // Otherwise, the standard logic requires a helper function.
   } else {
 Func = CodeGenFunction(CGM)

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=366059&r1=366058&r2=366059&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Jul 15 04:58:10 2019
@@ -3577,8 +3577,12 @@ llvm::Constant *CodeGenModule::GetAddrOf
 llvm::Constant *
 CodeGenModule::CreateRuntimeVariable(llvm::Type *Ty,
  StringRef Name) {
-  auto *Ret =
-  GetOrCreateLLVMGlobal(Name, llvm::PointerType::getUnqual(Ty), nullptr);
+  auto PtrTy =
+  getContext().getLangOpts().OpenCL
+  ? llvm::PointerType::get(
+Ty, getContext().getTargetAddressSpace(LangAS::opencl_global))
+  : llvm::PointerType::getUnqual(Ty);
+  auto *Ret = GetOrCreateLLVMGlobal(Name, PtrTy, nullptr);
   setDSOLocal(cast(Ret->stripPointerCasts()));
   return Ret;
 }

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=366059&r1=366058&r2=366059&view=diff
==
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Mon Jul 15 04:58:10 2019
@@ -2284,8 +2284,19 @@ static void emitGlobalDtorWithCXAAtExit(
   llvm::Type *dtorTy =
 llvm::FunctionType::get(CGF.VoidTy, CGF.Int8PtrTy, false)->getPointerTo();
 
+  // Preserve address space of addr.
+  auto AddrAS = addr ? addr->getType()->getPointerAddressSpace() : 0;
+  auto AddrInt8PtrTy =
+  AddrAS ? CGF.Int8Ty->getPointerTo(AddrAS) : CGF.Int8PtrTy;
+
+  // Create a variable that binds the atexit to this shared object.
+  llvm::Constant *handle =
+  CGF.CGM.CreateRuntimeVariable(CGF.Int8Ty, "__dso_handle");
+  auto *GV = cast(handle->stripPointerCasts());
+  GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
+
   // extern "C" int __cxa_atexit(void (*f)(void *), void *p, void *d);
-  llvm::Type *paramTys[] = { dtorTy, CGF.Int8PtrTy, CGF.Int8PtrTy };
+  llvm::Type *paramTys[] = {dtorTy, AddrInt8PtrTy, handle->getType()};
   llvm::FunctionType *atexitTy =
 llvm::FunctionType::get(CGF.IntTy, paramTys, false);
 
@@ -2294,12 +2305,6 @@ static void emitGlobalDtorWithCXAAtExit(
   if (llvm::Function *fn = dyn_cast(atexit.getCallee()))
 fn->setDoesNotThrow();
 
-  // Create 

r366063 - [OpenCL] Deduce addr space for pointee of dependent types in instantiation.

2019-07-15 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Mon Jul 15 06:02:21 2019
New Revision: 366063

URL: http://llvm.org/viewvc/llvm-project?rev=366063&view=rev
Log:
[OpenCL] Deduce addr space for pointee of dependent types in instantiation.

Since pointee doesn't require context sensitive addr space deduction
it's easier to handle pointee of dependent types during templ
instantiation.

Differential Revision: https://reviews.llvm.org/D64400


Modified:
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=366063&r1=366062&r2=366063&view=diff
==
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Mon Jul 15 06:02:21 2019
@@ -4536,6 +4536,14 @@ QualType TreeTransform::Transfo
   return Result;
 }
 
+/// Helper to deduce addr space of a pointee type in OpenCL mode.
+/// If the type is updated it will be overwritten in PointeeType param.
+static void deduceOpenCLPointeeAddrSpace(Sema &SemaRef, QualType &PointeeType) 
{
+  if (PointeeType.getAddressSpace() == LangAS::Default)
+PointeeType = SemaRef.Context.getAddrSpaceQualType(PointeeType,
+   LangAS::opencl_generic);
+}
+
 template
 QualType TreeTransform::TransformPointerType(TypeLocBuilder &TLB,
   PointerTypeLoc TL) {
@@ -4544,6 +4552,9 @@ QualType TreeTransform::Transfo
   if (PointeeType.isNull())
 return QualType();
 
+  if (SemaRef.getLangOpts().OpenCL)
+deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType);
+
   QualType Result = TL.getType();
   if (PointeeType->getAs()) {
 // A dependent pointer type 'T *' has is being transformed such
@@ -4582,6 +4593,9 @@ TreeTransform::TransformBlockPo
   if (PointeeType.isNull())
 return QualType();
 
+  if (SemaRef.getLangOpts().OpenCL)
+deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType);
+
   QualType Result = TL.getType();
   if (getDerived().AlwaysRebuild() ||
   PointeeType != TL.getPointeeLoc().getType()) {
@@ -4611,6 +4625,9 @@ TreeTransform::TransformReferen
   if (PointeeType.isNull())
 return QualType();
 
+  if (SemaRef.getLangOpts().OpenCL)
+deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType);
+
   QualType Result = TL.getType();
   if (getDerived().AlwaysRebuild() ||
   PointeeType != T->getPointeeTypeAsWritten()) {

Modified: cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl?rev=366063&r1=366062&r2=366063&view=diff
==
--- cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl (original)
+++ cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl Mon Jul 15 06:02:21 
2019
@@ -24,3 +24,42 @@ struct c2 {
   alias_c1_ptr ptr = &y;
 };
 
+
+// Addr spaces for pointee of dependent types are not deduced
+// during parsing but during template instantiation instead.
+
+template 
+struct x1 {
+//CHECK: -CXXMethodDecl {{.*}} operator= 'x1 &(const x1 &) __generic'
+//CHECK: -CXXMethodDecl {{.*}} operator= '__generic x1 &(const __generic 
x1 &) __generic'
+  x1& operator=(const x1& xx) {
+y = xx.y;
+return *this;
+  }
+  int y;
+};
+
+template 
+struct x2 {
+//CHECK: -CXXMethodDecl {{.*}} foo 'void (x1 *) __generic'
+//CHECK: -CXXMethodDecl {{.*}} foo 'void (__generic x1 *) __generic'
+  void foo(x1* xx) {
+m[0] = *xx;
+  }
+//CHECK: -FieldDecl {{.*}}  m 'x1 [2]'
+  x1 m[2];
+};
+
+void bar(__global x1 *xx, __global x2 *bar) {
+  bar->foo(xx);
+}
+
+template 
+class x3 : public T {
+public:
+  //CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &) __generic'
+  x3(const x3 &t);
+};
+//CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &) __generic'
+template 
+x3::x3(const x3 &t) {}


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


r366351 - [Docs][OpenCL] Documentation of C++ for OpenCL mode

2019-07-17 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Wed Jul 17 10:21:31 2019
New Revision: 366351

URL: http://llvm.org/viewvc/llvm-project?rev=366351&view=rev
Log:
[Docs][OpenCL] Documentation of C++ for OpenCL mode

Added documentation of C++ for OpenCL mode into Clang
User Manual and Language Extensions document.

Differential Revision: https://reviews.llvm.org/D64418


Modified:
cfe/trunk/docs/LanguageExtensions.rst
cfe/trunk/docs/UsersManual.rst

Modified: cfe/trunk/docs/LanguageExtensions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LanguageExtensions.rst?rev=366351&r1=366350&r2=366351&view=diff
==
--- cfe/trunk/docs/LanguageExtensions.rst (original)
+++ cfe/trunk/docs/LanguageExtensions.rst Wed Jul 17 10:21:31 2019
@@ -1518,6 +1518,275 @@ parameters of protocol-qualified type.
 Query the presence of this new mangling with
 ``__has_feature(objc_protocol_qualifier_mangling)``.
 
+
+OpenCL Features
+===
+
+C++ for OpenCL
+--
+
+This functionality is built on top of OpenCL C v2.0 and C++17. Regular C++
+features can be used in OpenCL kernel code. All functionality from OpenCL C
+is inherited. This section describes minor differences to OpenCL C and any
+limitations related to C++ support as well as interactions between OpenCL and
+C++ features that are not documented elsewhere.
+
+Restrictions to C++17
+^
+
+The following features are not supported:
+
+- Virtual functions
+- ``dynamic_cast`` operator
+- Non-placement ``new``/``delete`` operators
+- Standard C++ libraries. Currently there is no solution for alternative C++
+  libraries provided. Future release will feature library support.
+
+
+Interplay of OpenCL and C++ features
+
+
+Address space behavior
+""
+
+Address spaces are part of the type qualifiers; many rules are just inherited
+from the qualifier behavior documented in OpenCL C v2.0 s6.5 and Embedded C
+extension ISO/IEC JTC1 SC22 WG14 N1021 s3.1. Note that since the address space
+behavior in C++ is not documented formally yet, Clang extends existing concept
+from C and OpenCL. For example conversion rules are extended from qualification
+conversion but the compatibility is determined using sets and overlapping from
+Embedded C (ISO/IEC JTC1 SC22 WG14 N1021 s3.1.3). For OpenCL it means that
+implicit conversions are allowed from named to ``__generic`` but not vice versa
+(OpenCL C v2.0 s6.5.5) except for ``__constant`` address space. Most of the
+rules are built on top of this behavior.
+
+**Casts**
+
+C style cast will follow OpenCL C v2.0 rules (s6.5.5). All cast operators will
+permit implicit conversion to ``__generic``. However converting from named
+address spaces to ``__generic`` can only be done using ``addrspace_cast``. Note
+that conversions between ``__constant`` and any other is still disallowed.
+
+.. _opencl_cpp_addrsp_deduction:
+
+**Deduction**
+
+Address spaces are not deduced for:
+
+- non-pointer/non-reference template parameters or any dependent types except
+  for template specializations.
+- non-pointer/non-reference class members except for static data members that 
are
+  deduced to ``__global`` address space.
+- non-pointer/non-reference alias declarations.
+- ``decltype`` expression.
+
+.. code-block:: c++
+
+  template 
+  void foo() {
+T m; // address space of m will be known at template instantiation time.
+T * ptr; // ptr points to __generic address space object.
+T & ref = ...; // ref references an object in __generic address space.
+  };
+
+  template 
+  struct S {
+int i; // i has no address space
+static int ii; // ii is in global address space
+int * ptr; // ptr points to __generic address space int.
+int & ref = ...; // ref references int in __generic address space.
+  };
+
+  template 
+  void bar()
+  {
+S s; // s is in __private address space
+  }
+
+TODO: Add example for type alias and decltype!
+
+**References**
+
+References types can be qualified with an address space.
+
+.. code-block:: c++
+
+  __private int & ref = ...; // references int in __private address space
+
+By default references will refer to ``__generic`` address space objects, except
+for dependent types that are not template specializations
+(see :ref:`Deduction `). Address space 
compatibility
+checks are performed when references are bound to values. The logic follows the
+rules from address space pointer conversion (OpenCL v2.0 s6.5.5).
+
+**Default address space**
+
+All non-static member functions take an implicit object parameter ``this`` that
+is a pointer type. By default this pointer parameter is in ``__generic`` 
address
+space. All concrete objects passed as an argument to ``this`` parameter will be
+converted to ``__generic`` address space first if the conversion is valid.
+Therefore programs using objects in ``__constant`` address space won't be 
compiled
+unless addre

r366417 - [OpenCL][PR42033] Fix addr space deduction with template parameters

2019-07-18 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu Jul 18 02:12:49 2019
New Revision: 366417

URL: http://llvm.org/viewvc/llvm-project?rev=366417&view=rev
Log:
[OpenCL][PR42033] Fix addr space deduction with template parameters

If dependent types appear in pointers or references we allow addr
space deduction because the addr space in template argument will
belong to the pointee and not the pointer or reference itself.

We also don't diagnose addr space on a function return type after
template instantiation. If any addr space for the return type was
provided on a template parameter this will be diagnosed during the
parsing of template definition.

Differential Revision: https://reviews.llvm.org/D62584


Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
cfe/trunk/test/SemaOpenCLCXX/address-space-templates.cl

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=366417&r1=366416&r2=366417&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Jul 18 02:12:49 2019
@@ -7491,7 +7491,10 @@ void Sema::CheckVariableDeclarationType(
 return;
   }
 }
-  } else if (T.getAddressSpace() != LangAS::opencl_private) {
+  } else if (T.getAddressSpace() != LangAS::opencl_private &&
+ // If we are parsing a template we didn't deduce an addr
+ // space yet.
+ T.getAddressSpace() != LangAS::Default) {
 // Do not allow other address spaces on automatic variable.
 Diag(NewVD->getLocation(), diag::err_as_qualified_auto_decl) << 1;
 NewVD->setInvalidDecl();

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=366417&r1=366416&r2=366417&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Jul 18 02:12:49 2019
@@ -7419,7 +7419,9 @@ static void deduceOpenCLImplicitAddrSpac
   (T->isVoidType() && !IsPointee) ||
   // Do not deduce addr spaces for dependent types because they might end
   // up instantiating to a type with an explicit address space qualifier.
-  T->isDependentType() ||
+  // Except for pointer or reference types because the addr space in
+  // template argument can only belong to a pointee.
+  (T->isDependentType() && !T->isPointerType() && !T->isReferenceType()) ||
   // Do not deduce addr space of decltype because it will be taken from
   // its argument.
   T->isDecltypeType() ||

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=366417&r1=366416&r2=366417&view=diff
==
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Thu Jul 18 02:12:49 2019
@@ -5392,13 +5392,6 @@ QualType TreeTransform::Transfo
 if (ResultType.isNull())
   return QualType();
 
-// Return type can not be qualified with an address space.
-if (ResultType.getAddressSpace() != LangAS::Default) {
-  SemaRef.Diag(TL.getReturnLoc().getBeginLoc(),
-   diag::err_attribute_address_function_type);
-  return QualType();
-}
-
 if (getDerived().TransformFunctionTypeParams(
 TL.getBeginLoc(), TL.getParams(),
 TL.getTypePtr()->param_type_begin(),

Modified: cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl?rev=366417&r1=366416&r2=366417&view=diff
==
--- cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl (original)
+++ cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl Thu Jul 18 02:12:49 
2019
@@ -63,3 +63,18 @@ public:
 //CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &){{( 
__attribute__.*)?}} __generic'
 template 
 x3::x3(const x3 &t) {}
+
+template 
+T xxx(T *in) {
+  // This pointer can't be deduced to generic because addr space
+  // will be taken from the template argument.
+  //CHECK: `-VarDecl {{.*}} i 'T *' cinit
+  T *i = in;
+  T ii;
+  return *i;
+}
+
+__kernel void test() {
+  int foo[10];
+  xxx(&foo[0]);
+}

Modified: cfe/trunk/test/SemaOpenCLCXX/address-space-templates.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCLCXX/address-space-templates.cl?rev=366417&r1=366416&r2=366417&view=diff
==
--- cfe/trunk/test/SemaOpenCLCXX/address-space-templates.cl (original)
+++ cfe/trunk/tes

r366421 - [OpenCL] Update comments/diagnostics to refer to C++ for OpenCL

2019-07-18 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu Jul 18 03:02:35 2019
New Revision: 366421

URL: http://llvm.org/viewvc/llvm-project?rev=366421&view=rev
Log:
[OpenCL] Update comments/diagnostics to refer to C++ for OpenCL

Clang doesn't implement OpenCL C++, change the comments to
reflect that.

Differential Revision: https://reviews.llvm.org/D64867


Modified:
cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/LangOptions.def
cfe/trunk/include/clang/Basic/TokenKinds.def
cfe/trunk/include/clang/Frontend/LangStandards.def
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Sema/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaCast.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/Driver/unknown-std.cl
cfe/trunk/test/Parser/opencl-cxx-keywords.cl
cfe/trunk/test/Parser/opencl-cxx-virtual.cl
cfe/trunk/test/SemaOpenCLCXX/newdelete.cl
cfe/trunk/test/SemaOpenCLCXX/restricted.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td?rev=366421&r1=366420&r2=366421&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td Thu Jul 18 03:02:35 
2019
@@ -132,8 +132,8 @@ def err_nullability_conflicting : Error<
 
 // OpenCL Section 6.8.g
 def err_opencl_unknown_type_specifier : Error<
-  "OpenCL %select{C|C++}0 version %1 does not support the '%2' "
-  "%select{type qualifier|storage class specifier}3">;
+  "%select{OpenCL C|C++ for OpenCL}0 version %1 does not support the "
+  "'%2' %select{type qualifier|storage class specifier}3">;
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
@@ -291,9 +291,9 @@ def note_mt_message : Note<"[rewriter] %
 def warn_arcmt_nsalloc_realloc : Warning<"[rewriter] call returns pointer to 
GC managed memory; it will become unmanaged in ARC">;
 def err_arcmt_nsinvocation_ownership : Error<"NSInvocation's %0 is not safe to 
be used with an object with ownership other than __unsafe_unretained">;
 
-// OpenCL C++.
+// C++ for OpenCL.
 def err_openclcxx_not_supported : Error<
-  "'%0' is not supported in OpenCL C++">;
+  "'%0' is not supported in C++ for OpenCL">;
 
 // OpenMP
 def err_omp_more_one_clause : Error<

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=366421&r1=366420&r2=366421&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Thu Jul 18 03:02:35 
2019
@@ -1154,9 +1154,9 @@ def err_opencl_taking_function_address_p
 def err_opencl_logical_exclusive_or : Error<
   "^^ is a reserved operator in OpenCL">;
 
-// OpenCL C++.
+// C++ for OpenCL.
 def err_openclcxx_virtual_function : Error<
-  "virtual functions are not supported in OpenCL C++">;
+  "virtual functions are not supported in C++ for OpenCL">;
 
 // OpenMP support.
 def warn_pragma_omp_ignored : Warning<

Modified: cfe/trunk/include/clang/Basic/LangOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=366421&r1=366420&r2=366421&view=diff
==
--- cfe/trunk/include/clang/Basic/LangOptions.def (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.def Thu Jul 18 03:02:35 2019
@@ -197,8 +197,8 @@ LANGOPT(ShortEnums, 1, 0, "short
 
 LANGOPT(OpenCL, 1, 0, "OpenCL")
 LANGOPT(OpenCLVersion , 32, 0, "OpenCL C version")
-LANGOPT(OpenCLCPlusPlus   , 1, 0, "OpenCL C++")
-LANGOPT(OpenCLCPlusPlusVersion , 32, 0, "OpenCL C++ version")
+LANGOPT(OpenCLCPlusPlus   , 1, 0, "C++ for OpenCL")
+LANGOPT(OpenCLCPlusPlusVersion , 32, 0, "C++ for OpenCL version")
 LANGOPT(NativeHalfType, 1, 0, "Native half type support")
 LANGOPT(NativeHalfArgsAndReturns, 1, 0, "Native half args and returns")
 LANGOPT(HalfArgsAndReturns, 1, 0, "half args and returns")

Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=366421&r1=366420&r2=366421&view=diff
==
--- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/trunk/include/clang/Basic/TokenKinds.def Thu Jul 18 03:02:35 2019
@@ -252,9 +252,8 @@ PUNCTUATOR(caretcaret,"^^")
 //   KEYNOMS18 - This is a keyword that must never be enabled under
 //  

Re: r366694 - [NFC] Relaxed regression tests for PR42665

2019-07-23 Thread Anastasia Stulova via cfe-commits

+ cfe-commits


From: Anastasia Stulova
Sent: 23 July 2019 15:16
To: Hans Wennborg 
Cc: Marco Antognini 
Subject: Re: r366694 - [NFC] Relaxed regression tests for PR42665


@Hans, would it be possible to merge this commit along with r366670 to the 
release 9.0?


FY, I have also added this to the blocker bug: 
https://bugs.llvm.org/show_bug.cgi?id=41727

Thanks!
Anastasia

From: cfe-commits  on behalf of Marco 
Antognini via cfe-commits 
Sent: 22 July 2019 15:47
To: cfe-commits@lists.llvm.org 
Subject: r366694 - [NFC] Relaxed regression tests for PR42665

Author: mantognini
Date: Mon Jul 22 07:47:36 2019
New Revision: 366694

URL: http://llvm.org/viewvc/llvm-project?rev=366694&view=rev
Log:
[NFC] Relaxed regression tests for PR42665

Following up on the buildbot failures, this commits relaxes some tests:
instead of checking for specific IR output, it now ensures that the
underlying issue (the crash), and only that, doesn't happen.

Modified:
cfe/trunk/test/CodeGenCXX/PR42665.cpp

Modified: cfe/trunk/test/CodeGenCXX/PR42665.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/PR42665.cpp?rev=366694&r1=366693&r2=366694&view=diff
==
--- cfe/trunk/test/CodeGenCXX/PR42665.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/PR42665.cpp Mon Jul 22 07:47:36 2019
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -std=c++17 -O0 %s -o 
- | FileCheck %s
-// RUN: %clang_cc1 -triple %ms_abi_triple -emit-llvm -std=c++17 -O0 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++17 -O0 %s -emit-llvm -o /dev/null -verify -triple 
%itanium_abi_triple
+// RUN: %clang_cc1 -std=c++17 -O0 %s -emit-llvm -o /dev/null -verify -triple 
%ms_abi_triple

 // Minimal reproducer for PR42665.
+// expected-no-diagnostics

 struct Foo {
   Foo() = default;
@@ -31,31 +32,3 @@ void foobar() {
   d(f); // Invoke virtual destructor of Foo through d.
 } // p's destructor is invoked.

-// Regexes are used to handle both kind of mangling.
-//
-// CHECK-LABEL: define linkonce_odr{{( dso_local)?}} void 
@{{.*deleter.*Foo.*}}(%struct.Foo* dereferenceable({{[0-9]+}})
-// CHECK-SAME: [[T:%.*]])
-// CHECK: [[T_ADDR:%.*]] = alloca %struct.Foo*
-// CHECK: store %struct.Foo* [[T]], %struct.Foo** [[T_ADDR]]
-// CHECK: [[R0:%.*]] = load %struct.Foo*, %struct.Foo** [[T_ADDR]]
-// CHECK: [[R1:%.*]] = bitcast %struct.Foo* [[R0]] to 
[[TYPE:.*struct\.Foo.*]]***
-// CHECK: [[VTABLE:%.*]] = load [[TYPE]]**, [[TYPE]]*** [[R1]]
-// CHECK: [[VFUN:%.*]] = getelementptr inbounds [[TYPE]]*, [[TYPE]]** 
[[VTABLE]], i64 0
-// CHECK: [[DTOR:%.*]] = load [[TYPE]]*, [[TYPE]]** [[VFUN]]
-// CHECK: call {{(void|i8\*)}} [[DTOR]](%struct.Foo* [[R0]]
-//
-// CHECK-LABEL: define{{( dso_local)?}} void @{{.*foobar.*}}()
-// CHECK: [[P:%.*]] = alloca %struct.Pair
-// CHECK: [[F:%.*]] = alloca %struct.Foo*
-// CHECK: [[D:%.*]] = alloca [[TYPE:void \(%struct.Foo\*\)]]**
-// CHECK: call void @{{.*make_pair.*}}(%struct.Pair* sret [[P]])
-// CHECK: [[FIRST:%.*]] = getelementptr inbounds %struct.Pair, %struct.Pair* 
[[P]], i32 0, i32 0
-// CHECK: store %struct.Foo* [[FIRST]], %struct.Foo** [[F]]
-// CHECK: [[SECOND:%.*]] = getelementptr inbounds %struct.Pair, %struct.Pair* 
[[P]], i32 0, i32 1
-// CHECK: store void (%struct.Foo*)** [[SECOND]], [[TYPE]]*** [[D]]
-// CHECK: [[R0:%.*]] = load [[TYPE]]**, [[TYPE]]*** [[D]]
-// CHECK: [[R1:%.*]] = load [[TYPE]]*, [[TYPE]]** [[R0]]
-// CHECK: [[R2:%.*]] = load %struct.Foo*, %struct.Foo** [[F]]
-// CHECK: call void [[R1]](%struct.Foo* dereferenceable({{[0-9]+}}) [[R2]])
-// CHECK: call void @{{.*Pair.*Foo.*}}(%struct.Pair* [[P]])
-


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


Re: r366694 - [NFC] Relaxed regression tests for PR42665

2019-07-23 Thread Anastasia Stulova via cfe-commits

Great! Thanks!


From: Hans Wennborg 
Sent: 23 July 2019 15:58
To: Anastasia Stulova 
Cc: Marco Antognini ; Clang Commits 
; nd 
Subject: Re: r366694 - [NFC] Relaxed regression tests for PR42665

Merged them both in r366814.

Thanks,
Hans

On Tue, Jul 23, 2019 at 7:20 AM Anastasia Stulova
 wrote:
>
>
> + cfe-commits
>
> 
> From: Anastasia Stulova
> Sent: 23 July 2019 15:16
> To: Hans Wennborg 
> Cc: Marco Antognini 
> Subject: Re: r366694 - [NFC] Relaxed regression tests for PR42665
>
>
> @Hans, would it be possible to merge this commit along with r366670 to the 
> release 9.0?
>
>
> FY, I have also added this to the blocker bug: 
> https://bugs.llvm.org/show_bug.cgi?id=41727
>
> Thanks!
> Anastasia
> 
> From: cfe-commits  on behalf of Marco 
> Antognini via cfe-commits 
> Sent: 22 July 2019 15:47
> To: cfe-commits@lists.llvm.org 
> Subject: r366694 - [NFC] Relaxed regression tests for PR42665
>
> Author: mantognini
> Date: Mon Jul 22 07:47:36 2019
> New Revision: 366694
>
> URL: http://llvm.org/viewvc/llvm-project?rev=366694&view=rev
> Log:
> [NFC] Relaxed regression tests for PR42665
>
> Following up on the buildbot failures, this commits relaxes some tests:
> instead of checking for specific IR output, it now ensures that the
> underlying issue (the crash), and only that, doesn't happen.
>
> Modified:
> cfe/trunk/test/CodeGenCXX/PR42665.cpp
>
> Modified: cfe/trunk/test/CodeGenCXX/PR42665.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/PR42665.cpp?rev=366694&r1=366693&r2=366694&view=diff
> ==
> --- cfe/trunk/test/CodeGenCXX/PR42665.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/PR42665.cpp Mon Jul 22 07:47:36 2019
> @@ -1,7 +1,8 @@
> -// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -std=c++17 -O0 %s 
> -o - | FileCheck %s
> -// RUN: %clang_cc1 -triple %ms_abi_triple -emit-llvm -std=c++17 -O0 %s -o - 
> | FileCheck %s
> +// RUN: %clang_cc1 -std=c++17 -O0 %s -emit-llvm -o /dev/null -verify -triple 
> %itanium_abi_triple
> +// RUN: %clang_cc1 -std=c++17 -O0 %s -emit-llvm -o /dev/null -verify -triple 
> %ms_abi_triple
>
>  // Minimal reproducer for PR42665.
> +// expected-no-diagnostics
>
>  struct Foo {
>Foo() = default;
> @@ -31,31 +32,3 @@ void foobar() {
>d(f); // Invoke virtual destructor of Foo through d.
>  } // p's destructor is invoked.
>
> -// Regexes are used to handle both kind of mangling.
> -//
> -// CHECK-LABEL: define linkonce_odr{{( dso_local)?}} void 
> @{{.*deleter.*Foo.*}}(%struct.Foo* dereferenceable({{[0-9]+}})
> -// CHECK-SAME: [[T:%.*]])
> -// CHECK: [[T_ADDR:%.*]] = alloca %struct.Foo*
> -// CHECK: store %struct.Foo* [[T]], %struct.Foo** [[T_ADDR]]
> -// CHECK: [[R0:%.*]] = load %struct.Foo*, %struct.Foo** [[T_ADDR]]
> -// CHECK: [[R1:%.*]] = bitcast %struct.Foo* [[R0]] to 
> [[TYPE:.*struct\.Foo.*]]***
> -// CHECK: [[VTABLE:%.*]] = load [[TYPE]]**, [[TYPE]]*** [[R1]]
> -// CHECK: [[VFUN:%.*]] = getelementptr inbounds [[TYPE]]*, [[TYPE]]** 
> [[VTABLE]], i64 0
> -// CHECK: [[DTOR:%.*]] = load [[TYPE]]*, [[TYPE]]** [[VFUN]]
> -// CHECK: call {{(void|i8\*)}} [[DTOR]](%struct.Foo* [[R0]]
> -//
> -// CHECK-LABEL: define{{( dso_local)?}} void @{{.*foobar.*}}()
> -// CHECK: [[P:%.*]] = alloca %struct.Pair
> -// CHECK: [[F:%.*]] = alloca %struct.Foo*
> -// CHECK: [[D:%.*]] = alloca [[TYPE:void \(%struct.Foo\*\)]]**
> -// CHECK: call void @{{.*make_pair.*}}(%struct.Pair* sret [[P]])
> -// CHECK: [[FIRST:%.*]] = getelementptr inbounds %struct.Pair, %struct.Pair* 
> [[P]], i32 0, i32 0
> -// CHECK: store %struct.Foo* [[FIRST]], %struct.Foo** [[F]]
> -// CHECK: [[SECOND:%.*]] = getelementptr inbounds %struct.Pair, 
> %struct.Pair* [[P]], i32 0, i32 1
> -// CHECK: store void (%struct.Foo*)** [[SECOND]], [[TYPE]]*** [[D]]
> -// CHECK: [[R0:%.*]] = load [[TYPE]]**, [[TYPE]]*** [[D]]
> -// CHECK: [[R1:%.*]] = load [[TYPE]]*, [[TYPE]]** [[R0]]
> -// CHECK: [[R2:%.*]] = load %struct.Foo*, %struct.Foo** [[F]]
> -// CHECK: call void [[R1]](%struct.Foo* dereferenceable({{[0-9]+}}) [[R2]])
> -// CHECK: call void @{{.*Pair.*Foo.*}}(%struct.Pair* [[P]])
> -
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r367008 - [OpenCL] Rename lang mode flag for C++ mode

2019-07-25 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu Jul 25 04:04:29 2019
New Revision: 367008

URL: http://llvm.org/viewvc/llvm-project?rev=367008&view=rev
Log:
[OpenCL] Rename lang mode flag for C++ mode

Rename lang mode flag to -cl-std=clc++/-cl-std=CLC++
or -std=clc++/-std=CLC++.

This aligns with OpenCL C conversion and removes ambiguity
with OpenCL C++. 

Differential Revision: https://reviews.llvm.org/D65102



Modified:
cfe/trunk/docs/LanguageExtensions.rst
cfe/trunk/docs/UsersManual.rst
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/LangStandards.def
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/CodeGenCXX/mangle-address-space.cpp
cfe/trunk/test/CodeGenOpenCL/builtins.cl
cfe/trunk/test/CodeGenOpenCL/images.cl
cfe/trunk/test/CodeGenOpenCL/logical-ops.cl
cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
cfe/trunk/test/CodeGenOpenCL/sampler.cl
cfe/trunk/test/CodeGenOpenCL/spir_version.cl
cfe/trunk/test/CodeGenOpenCL/to_addr_builtin.cl
cfe/trunk/test/CodeGenOpenCLCXX/address-space-castoperators.cpp
cfe/trunk/test/CodeGenOpenCLCXX/address-space-deduction.cl
cfe/trunk/test/CodeGenOpenCLCXX/address-space-deduction2.cl
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-conversion.cl
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-operators.cl
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-references.cl
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-with-class.cl
cfe/trunk/test/CodeGenOpenCLCXX/atexit.cl
cfe/trunk/test/CodeGenOpenCLCXX/global_init.cl
cfe/trunk/test/CodeGenOpenCLCXX/local_addrspace_init.cl
cfe/trunk/test/CodeGenOpenCLCXX/method-overload-address-space.cl
cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl
cfe/trunk/test/Driver/autocomplete.c
cfe/trunk/test/Driver/opencl.cl
cfe/trunk/test/Frontend/opencl.cl
cfe/trunk/test/Frontend/stdlang.c
cfe/trunk/test/Headers/opencl-c-header.cl
cfe/trunk/test/Parser/opencl-cxx-keywords.cl
cfe/trunk/test/Parser/opencl-cxx-virtual.cl
cfe/trunk/test/Preprocessor/predefined-macros.c
cfe/trunk/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
cfe/trunk/test/SemaOpenCL/address-spaces.cl
cfe/trunk/test/SemaOpenCL/builtin.cl
cfe/trunk/test/SemaOpenCL/clk_event_t.cl
cfe/trunk/test/SemaOpenCL/extension-version.cl
cfe/trunk/test/SemaOpenCL/extensions.cl
cfe/trunk/test/SemaOpenCL/invalid-image.cl
cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl
cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
cfe/trunk/test/SemaOpenCLCXX/address-space-of-this-class-scope.cl
cfe/trunk/test/SemaOpenCLCXX/address-space-of-this.cl
cfe/trunk/test/SemaOpenCLCXX/address-space-references.cl
cfe/trunk/test/SemaOpenCLCXX/address-space-templates.cl
cfe/trunk/test/SemaOpenCLCXX/address_space_overloading.cl
cfe/trunk/test/SemaOpenCLCXX/kernel_invalid.cl
cfe/trunk/test/SemaOpenCLCXX/method-overload-address-space.cl
cfe/trunk/test/SemaOpenCLCXX/newdelete.cl
cfe/trunk/test/SemaOpenCLCXX/restricted.cl

Modified: cfe/trunk/docs/LanguageExtensions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LanguageExtensions.rst?rev=367008&r1=367007&r2=367008&view=diff
==
--- cfe/trunk/docs/LanguageExtensions.rst (original)
+++ cfe/trunk/docs/LanguageExtensions.rst Thu Jul 25 04:04:29 2019
@@ -1779,7 +1779,7 @@ invoked.
 
 .. code-block:: console
 
- clang -cl-std=c++ test.cl
+ clang -cl-std=clc++ test.cl
 
 If there are any global objects to be initialized the final binary will
 contain ``@_GLOBAL__sub_I_test.cl`` kernel to be enqueued.

Modified: cfe/trunk/docs/UsersManual.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=367008&r1=367007&r2=367008&view=diff
==
--- cfe/trunk/docs/UsersManual.rst (original)
+++ cfe/trunk/docs/UsersManual.rst Thu Jul 25 04:04:29 2019
@@ -2776,7 +2776,7 @@ restrictions from OpenCL C v2.0 will inh
 and function libraries are supported and can be used in the new mode.
 
 To enable the new mode pass the following command line option when compiling 
``.cl``
-file ``-cl-std=c++`` or ``-std=c++``.
+file ``-cl-std=clc++``, ``-cl-std=CLC++``, ``-std=clc++`` or ``-std=CLC++``.
 
.. code-block:: c++
 
@@ -2794,7 +2794,7 @@ file ``-cl-std=c++`` or ``-std=c++``.
 
.. code-block:: console
 
- clang -cl-std=c++ test.cl
+ clang -cl-std=clc++ test.cl
 
 .. _target_features:
 

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=367008&r1=367007&r2=367008&view=diff
==
--- cfe/trunk/include/clang/Driver/Options

r367675 - [OpenCL] Allow OpenCL C style vector initialization in C++

2019-08-02 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Fri Aug  2 04:19:35 2019
New Revision: 367675

URL: http://llvm.org/viewvc/llvm-project?rev=367675&view=rev
Log:
[OpenCL] Allow OpenCL C style vector initialization in C++

Allow creating vector literals from other vectors.

 float4 a = (float4)(1.0f, 2.0f, 3.0f, 4.0f);
 float4 v = (float4)(a.s23, a.s01);

Differential revision: https://reviews.llvm.org/D65286


Removed:
cfe/trunk/test/CodeGenOpenCL/vector_literals_nested.cl
cfe/trunk/test/SemaOpenCL/vector_literals_const.cl
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/CodeGenOpenCL/vector_literals_valid.cl
cfe/trunk/test/SemaCXX/vector.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=367675&r1=367674&r2=367675&view=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Aug  2 04:19:35 2019
@@ -1289,7 +1289,16 @@ void InitListChecker::CheckSubElementTyp
 // FIXME: Better EqualLoc?
 InitializationKind Kind =
 InitializationKind::CreateCopy(expr->getBeginLoc(), SourceLocation());
-InitializationSequence Seq(SemaRef, Entity, Kind, expr,
+
+// Vector elements can be initialized from other vectors in which case
+// we need initialization entity with a type of a vector (and not a vector
+// element!) initializing multiple vector elements.
+auto TmpEntity =
+(ElemType->isExtVectorType() && !Entity.getType()->isExtVectorType())
+? InitializedEntity::InitializeTemporary(ElemType)
+: Entity;
+
+InitializationSequence Seq(SemaRef, TmpEntity, Kind, expr,
/*TopLevelOfInitList*/ true);
 
 // C++14 [dcl.init.aggr]p13:
@@ -1300,8 +1309,7 @@ void InitListChecker::CheckSubElementTyp
 // assignment-expression.
 if (Seq || isa(expr)) {
   if (!VerifyOnly) {
-ExprResult Result =
-  Seq.Perform(SemaRef, Entity, Kind, expr);
+ExprResult Result = Seq.Perform(SemaRef, TmpEntity, Kind, expr);
 if (Result.isInvalid())
   hadError = true;
 

Removed: cfe/trunk/test/CodeGenOpenCL/vector_literals_nested.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/vector_literals_nested.cl?rev=367674&view=auto
==
--- cfe/trunk/test/CodeGenOpenCL/vector_literals_nested.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/vector_literals_nested.cl (removed)
@@ -1,23 +0,0 @@
-// RUN: %clang_cc1 %s -emit-llvm -O3 -o - | FileCheck %s
-
-typedef int int2 __attribute((ext_vector_type(2)));
-typedef int int4 __attribute((ext_vector_type(4)));
-
-__constant const int4 itest1 = (int4)(1, 2, ((int2)(3, 4)));
-// CHECK: constant <4 x i32> 
-__constant const int4 itest2 = (int4)(1, 2, ((int2)(3)));
-// CHECK: constant <4 x i32> 
-
-typedef float float2 __attribute((ext_vector_type(2)));
-typedef float float4 __attribute((ext_vector_type(4)));
-
-void ftest1(float4 *p) {
-  *p = (float4)(1.1f, 1.2f, ((float2)(1.3f, 1.4f)));
-// CHECK: store <4 x float> 
-}
-
-float4 ftest2(float4 *p) {
-   *p =  (float4)(1.1f, 1.2f, ((float2)(1.3f)));
-// CHECK: store <4 x float> 
-}
-

Modified: cfe/trunk/test/CodeGenOpenCL/vector_literals_valid.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/vector_literals_valid.cl?rev=367675&r1=367674&r2=367675&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/vector_literals_valid.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/vector_literals_valid.cl Fri Aug  2 04:19:35 
2019
@@ -1,22 +1,65 @@
-// RUN: %clang_cc1 -emit-llvm %s -o %t
+// RUN: %clang_cc1 -emit-llvm %s -o - -O0 | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm %s -o - -cl-std=clc++ -O0 | FileCheck %s
 
-typedef __attribute__(( ext_vector_type(2) ))  int int2;
-typedef __attribute__(( ext_vector_type(3) ))  int int3;
-typedef __attribute__(( ext_vector_type(4) ))  int int4;
-typedef __attribute__(( ext_vector_type(8) ))  int int8;
-typedef __attribute__(( ext_vector_type(4) ))  float float4;
+typedef __attribute__((ext_vector_type(2))) int int2;
+typedef __attribute__((ext_vector_type(3))) int int3;
+typedef __attribute__((ext_vector_type(4)))  int int4;
+typedef __attribute__((ext_vector_type(8)))  int int8;
+typedef __attribute__((ext_vector_type(4))) float float4;
+
+__constant const int4 c1 = (int4)(1, 2, ((int2)(3)));
+// CHECK: constant <4 x i32> 
+
+__constant const int4 c2 = (int4)(1, 2, ((int2)(3, 4)));
+// CHECK: constant <4 x i32> 
 
 void vector_literals_valid() {
-  int4 a_1_1_1_1 = (int4)(1,2,3,4);
-  int4 a_2_1_1 = (int4)((int2)(1,2),3,4);
-  int4 a_1_2_1 = (int4)(1,(int2)(2,3),4);
-  int4 a_1_1_2 = (int4)(1,2,(int2)(3,4));
-  int4 a_2_2 = (int4)((int2)(1,2),(int2)(3,4));
-  int4 a_3_1 = (int4)((int3)(1,2,3),4);
-  int4 a_1_3 = 

r367823 - [OpenCL] Fix vector literal test broken in rL367675.

2019-08-05 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Mon Aug  5 02:50:28 2019
New Revision: 367823

URL: http://llvm.org/viewvc/llvm-project?rev=367823&view=rev
Log:
[OpenCL] Fix vector literal test broken in rL367675.

Avoid checking alignment unnecessary that is not portable
among targets.


Modified:
cfe/trunk/test/CodeGenOpenCL/vector_literals_valid.cl

Modified: cfe/trunk/test/CodeGenOpenCL/vector_literals_valid.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/vector_literals_valid.cl?rev=367823&r1=367822&r2=367823&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/vector_literals_valid.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/vector_literals_valid.cl Mon Aug  5 02:50:28 
2019
@@ -51,11 +51,11 @@ void vector_literals_valid() {
   //CHECK: store <4 x i32> , <4 x i32>* %a
   int4 a = (int4)(1);
 
-  //CHECK: load <4 x i32>, <4 x i32>* %a, align 16
+  //CHECK: load <4 x i32>, <4 x i32>* %a
   //CHECK: shufflevector <4 x i32> %{{[0-9]+}}, <4 x i32> undef, <2 x i32> 

   //CHECK: shufflevector <2 x i32> %{{[0-9]+}}, <2 x i32> undef, <8 x i32> 

   //CHECK: shufflevector <8 x i32> , <8 x i32> %{{.+}}, <8 x i32> 
-  //CHECK: load <4 x i32>, <4 x i32>* %a, align 16
+  //CHECK: load <4 x i32>, <4 x i32>* %a
   //CHECK: shufflevector <4 x i32> %{{[0-9]+}}, <4 x i32> undef, <8 x i32> 

   //CHECK: shufflevector <8 x i32> %{{.+}}, <8 x i32> %{{.+}}, <8 x i32> 
   int8 b = (int8)(1, 2, a.xy, a);


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


Re: r367675 - [OpenCL] Allow OpenCL C style vector initialization in C++

2019-08-05 Thread Anastasia Stulova via cfe-commits
Hi Yvan,


Sorry for this, it should now be fixed  in r367823.


Thanks,

Anastasia



From: Yvan Roux 
Sent: 02 August 2019 14:09
To: Anastasia Stulova 
Cc: cfe-commits 
Subject: Re: r367675 - [OpenCL] Allow OpenCL C style vector initialization in 
C++

Hi Anastasia,

This commit broke ARMv8 bots, logs are available here:

http://lab.llvm.org:8011/builders/clang-cmake-armv8-quick/builds/14655/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Avector_literals_valid.cl

Thanks,
Yvan

On Fri, 2 Aug 2019 at 13:18, Anastasia Stulova via cfe-commits
 wrote:
>
> Author: stulova
> Date: Fri Aug  2 04:19:35 2019
> New Revision: 367675
>
> URL: http://llvm.org/viewvc/llvm-project?rev=367675&view=rev
> Log:
> [OpenCL] Allow OpenCL C style vector initialization in C++
>
> Allow creating vector literals from other vectors.
>
>  float4 a = (float4)(1.0f, 2.0f, 3.0f, 4.0f);
>  float4 v = (float4)(a.s23, a.s01);
>
> Differential revision: https://reviews.llvm.org/D65286
>
>
> Removed:
> cfe/trunk/test/CodeGenOpenCL/vector_literals_nested.cl
> cfe/trunk/test/SemaOpenCL/vector_literals_const.cl
> Modified:
> cfe/trunk/lib/Sema/SemaInit.cpp
> cfe/trunk/test/CodeGenOpenCL/vector_literals_valid.cl
> cfe/trunk/test/SemaCXX/vector.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaInit.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=367675&r1=367674&r2=367675&view=diff
> ==
> --- cfe/trunk/lib/Sema/SemaInit.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Aug  2 04:19:35 2019
> @@ -1289,7 +1289,16 @@ void InitListChecker::CheckSubElementTyp
>  // FIXME: Better EqualLoc?
>  InitializationKind Kind =
>  InitializationKind::CreateCopy(expr->getBeginLoc(), 
> SourceLocation());
> -InitializationSequence Seq(SemaRef, Entity, Kind, expr,
> +
> +// Vector elements can be initialized from other vectors in which case
> +// we need initialization entity with a type of a vector (and not a 
> vector
> +// element!) initializing multiple vector elements.
> +auto TmpEntity =
> +(ElemType->isExtVectorType() && !Entity.getType()->isExtVectorType())
> +? InitializedEntity::InitializeTemporary(ElemType)
> +: Entity;
> +
> +InitializationSequence Seq(SemaRef, TmpEntity, Kind, expr,
> /*TopLevelOfInitList*/ true);
>
>  // C++14 [dcl.init.aggr]p13:
> @@ -1300,8 +1309,7 @@ void InitListChecker::CheckSubElementTyp
>  // assignment-expression.
>  if (Seq || isa(expr)) {
>if (!VerifyOnly) {
> -ExprResult Result =
> -  Seq.Perform(SemaRef, Entity, Kind, expr);
> +ExprResult Result = Seq.Perform(SemaRef, TmpEntity, Kind, expr);
>  if (Result.isInvalid())
>hadError = true;
>
>
> Removed: cfe/trunk/test/CodeGenOpenCL/vector_literals_nested.cl
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/vector_literals_nested.cl?rev=367674&view=auto
> ==
> --- cfe/trunk/test/CodeGenOpenCL/vector_literals_nested.cl (original)
> +++ cfe/trunk/test/CodeGenOpenCL/vector_literals_nested.cl (removed)
> @@ -1,23 +0,0 @@
> -// RUN: %clang_cc1 %s -emit-llvm -O3 -o - | FileCheck %s
> -
> -typedef int int2 __attribute((ext_vector_type(2)));
> -typedef int int4 __attribute((ext_vector_type(4)));
> -
> -__constant const int4 itest1 = (int4)(1, 2, ((int2)(3, 4)));
> -// CHECK: constant <4 x i32> 
> -__constant const int4 itest2 = (int4)(1, 2, ((int2)(3)));
> -// CHECK: constant <4 x i32> 
> -
> -typedef float float2 __attribute((ext_vector_type(2)));
> -typedef float float4 __attribute((ext_vector_type(4)));
> -
> -void ftest1(float4 *p) {
> -  *p = (float4)(1.1f, 1.2f, ((float2)(1.3f, 1.4f)));
> -// CHECK: store <4 x float>  0x3FF34000, float 0x3FF4C000, float 0x3FF66000>
> -}
> -
> -float4 ftest2(float4 *p) {
> -   *p =  (float4)(1.1f, 1.2f, ((float2)(1.3f)));
> -// CHECK: store <4 x float>  0x3FF34000, float 0x3FF4C000, float 0x3FF4C000>
> -}
> -
>
> Modified: cfe/trunk/test/CodeGenOpenCL/vector_literals_valid.cl
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/vector_literals_valid.cl?rev=367675&r1=367674&r2=367675&view=diff
> ==
> --- cfe/trunk/test/CodeGenOpenCL/vector_literals_valid.cl (original)
> +++ cfe/trunk/test/CodeGen

r368552 - [OpenCL] Fix lang mode predefined macros for C++ mode.

2019-08-12 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Mon Aug 12 03:44:07 2019
New Revision: 368552

URL: http://llvm.org/viewvc/llvm-project?rev=368552&view=rev
Log:
[OpenCL] Fix lang mode predefined macros for C++ mode.

In C++ mode we should only avoid adding __OPENCL_C_VERSION__,
all other predefined macros about the language mode are still
valid.

This change also fixes the language version check in the
headers accordingly.

Differential Revision: https://reviews.llvm.org/D65941


Modified:
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/lib/Headers/opencl-c-base.h
cfe/trunk/lib/Headers/opencl-c.h

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=368552&r1=368551&r2=368552&view=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Mon Aug 12 03:44:07 2019
@@ -437,17 +437,17 @@ static void InitializeStandardPredefined
   default:
 llvm_unreachable("Unsupported OpenCL version");
   }
-  Builder.defineMacro("CL_VERSION_1_0", "100");
-  Builder.defineMacro("CL_VERSION_1_1", "110");
-  Builder.defineMacro("CL_VERSION_1_2", "120");
-  Builder.defineMacro("CL_VERSION_2_0", "200");
+}
+Builder.defineMacro("CL_VERSION_1_0", "100");
+Builder.defineMacro("CL_VERSION_1_1", "110");
+Builder.defineMacro("CL_VERSION_1_2", "120");
+Builder.defineMacro("CL_VERSION_2_0", "200");
 
-  if (TI.isLittleEndian())
-Builder.defineMacro("__ENDIAN_LITTLE__");
+if (TI.isLittleEndian())
+  Builder.defineMacro("__ENDIAN_LITTLE__");
 
-  if (LangOpts.FastRelaxedMath)
-Builder.defineMacro("__FAST_RELAXED_MATH__");
-}
+if (LangOpts.FastRelaxedMath)
+  Builder.defineMacro("__FAST_RELAXED_MATH__");
   }
   // Not "standard" per se, but available even with the -undef flag.
   if (LangOpts.AsmPreprocessor)

Modified: cfe/trunk/lib/Headers/opencl-c-base.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/opencl-c-base.h?rev=368552&r1=368551&r2=368552&view=diff
==
--- cfe/trunk/lib/Headers/opencl-c-base.h (original)
+++ cfe/trunk/lib/Headers/opencl-c-base.h Mon Aug 12 03:44:07 2019
@@ -126,7 +126,7 @@ typedef double double8 __attribute__((ex
 typedef double double16 __attribute__((ext_vector_type(16)));
 #endif
 
-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
 #define NULL ((void*)0)
 #endif
 
@@ -276,7 +276,7 @@ typedef uint cl_mem_fence_flags;
  */
 #define CLK_GLOBAL_MEM_FENCE   0x02
 
-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
 
 typedef enum memory_scope {
   memory_scope_work_item = __OPENCL_MEMORY_SCOPE_WORK_ITEM,
@@ -288,9 +288,6 @@ typedef enum memory_scope {
 #endif
 } memory_scope;
 
-#endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
-
-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 /**
  * Queue a memory fence to ensure correct ordering of memory
  * operations between work-items of a work-group to
@@ -313,7 +310,7 @@ typedef enum memory_order
   memory_order_seq_cst = __ATOMIC_SEQ_CST
 } memory_order;
 
-#endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#endif // defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)
 
 // OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14 - Image Read and Write 
Functions
 
@@ -389,14 +386,10 @@ typedef enum memory_order
 #endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
 
 // OpenCL v2.0 s6.13.16 - Pipe Functions
-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
 #define CLK_NULL_RESERVE_ID (__builtin_astype(((void*)(__SIZE_MAX__)), 
reserve_id_t))
-#endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
-
 
 // OpenCL v2.0 s6.13.17 - Enqueue Kernels
-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
-
 #define CL_COMPLETE 0x0
 #define CL_RUNNING  0x1
 #define CL_SUBMITTED0x2
@@ -435,7 +428,7 @@ typedef struct {
   size_t localWorkSize[MAX_WORK_DIM];
 } ndrange_t;
 
-#endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#endif // defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)
 
 #ifdef cl_intel_device_side_avc_motion_estimation
 #pragma OPENCL EXTENSION cl_intel_device_side_avc_motion_estimation : begin

Modified: cfe/trunk/lib/Headers/opencl-c.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/opencl-c.h?rev=368552&r1=368551&r2=368552&view=diff
==
--- cfe/trunk/lib/Headers/opencl-c.h (original)
+++ cfe/trunk/lib/Headers/opencl-c.h Mon Aug 12 03:44:07 2019
@@

Re: r368561 - [OpenCL] Ignore parentheses for sampler initialization

2019-08-13 Thread Anastasia Stulova via cfe-commits
Hi Hans,


Can this be merged into the release 9.0 branch please?

Thank you!
Anastasia


From: cfe-commits  on behalf of Sven van 
Haastregt via cfe-commits 
Sent: 12 August 2019 13:44
To: cfe-commits@lists.llvm.org 
Subject: r368561 - [OpenCL] Ignore parentheses for sampler initialization

Author: svenvh
Date: Mon Aug 12 05:44:26 2019
New Revision: 368561

URL: http://llvm.org/viewvc/llvm-project?rev=368561&view=rev
Log:
[OpenCL] Ignore parentheses for sampler initialization

The sampler handling logic in SemaInit.cpp would inadvertently treat
parentheses around sampler arguments as an implicit cast, leading to
an unreachable "can't implicitly cast lvalue to rvalue with
this cast kind".  Fix by ignoring parentheses once we are in the
sampler initializer case.

Differential Revision: https://reviews.llvm.org/D66080

Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/SemaOpenCL/sampler_t.cl

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=368561&r1=368560&r2=368561&view=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Mon Aug 12 05:44:26 2019
@@ -8248,7 +8248,7 @@ ExprResult InitializationSequence::Perfo
   // argument passing.
   assert(Step->Type->isSamplerT() &&
  "Sampler initialization on non-sampler type.");
-  Expr *Init = CurInit.get();
+  Expr *Init = CurInit.get()->IgnoreParens();
   QualType SourceType = Init->getType();
   // Case 1
   if (Entity.isParameterKind()) {

Modified: cfe/trunk/test/SemaOpenCL/sampler_t.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/sampler_t.cl?rev=368561&r1=368560&r2=368561&view=diff
==
--- cfe/trunk/test/SemaOpenCL/sampler_t.cl (original)
+++ cfe/trunk/test/SemaOpenCL/sampler_t.cl Mon Aug 12 05:44:26 2019
@@ -10,6 +10,9 @@
 #define CLK_FILTER_NEAREST  0x10
 #define CLK_FILTER_LINEAR   0x20

+typedef float float4 __attribute__((ext_vector_type(4)));
+float4 read_imagef(read_only image1d_t, sampler_t, float);
+
 constant sampler_t glb_smp = CLK_ADDRESS_CLAMP_TO_EDGE | 
CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
 constant sampler_t glb_smp2; // expected-error{{variable in constant address 
space must be initialized}}
 global sampler_t glb_smp3 = CLK_ADDRESS_CLAMP_TO_EDGE | 
CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_NEAREST; // expected-error{{sampler 
type cannot be used with the __local and __global address space qualifiers}} 
expected-error {{global sampler requires a const or constant address space 
qualifier}}
@@ -74,3 +77,7 @@ void bar() {
   foo(smp1+1); //expected-error{{invalid operands to binary expression 
('sampler_t' and 'int')}}
 }

+void smp_args(read_only image1d_t image) {
+  // Test that parentheses around sampler arguments are ignored.
+  float4 res = read_imagef(image, (glb_smp10), 0.0f);
+}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
IMPORTANT NOTICE: The contents of this email and any attachments are 
confidential and may also be privileged. If you are not the intended recipient, 
please notify the sender immediately and do not disclose the contents to any 
other person, use it for any purpose, or store or copy the information in any 
medium. Thank you.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r368552 - [OpenCL] Fix lang mode predefined macros for C++ mode.

2019-08-13 Thread Anastasia Stulova via cfe-commits
Hi Hans,


Can this be merged into the release 9.0 branch please?

Thank you!
Anastasia



From: cfe-commits  on behalf of Anastasia 
Stulova via cfe-commits 
Sent: 12 August 2019 11:44
To: cfe-commits@lists.llvm.org 
Subject: r368552 - [OpenCL] Fix lang mode predefined macros for C++ mode.

Author: stulova
Date: Mon Aug 12 03:44:07 2019
New Revision: 368552

URL: http://llvm.org/viewvc/llvm-project?rev=368552&view=rev
Log:
[OpenCL] Fix lang mode predefined macros for C++ mode.

In C++ mode we should only avoid adding __OPENCL_C_VERSION__,
all other predefined macros about the language mode are still
valid.

This change also fixes the language version check in the
headers accordingly.

Differential Revision: https://reviews.llvm.org/D65941


Modified:
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/lib/Headers/opencl-c-base.h
cfe/trunk/lib/Headers/opencl-c.h

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=368552&r1=368551&r2=368552&view=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Mon Aug 12 03:44:07 2019
@@ -437,17 +437,17 @@ static void InitializeStandardPredefined
   default:
 llvm_unreachable("Unsupported OpenCL version");
   }
-  Builder.defineMacro("CL_VERSION_1_0", "100");
-  Builder.defineMacro("CL_VERSION_1_1", "110");
-  Builder.defineMacro("CL_VERSION_1_2", "120");
-  Builder.defineMacro("CL_VERSION_2_0", "200");
+}
+Builder.defineMacro("CL_VERSION_1_0", "100");
+Builder.defineMacro("CL_VERSION_1_1", "110");
+Builder.defineMacro("CL_VERSION_1_2", "120");
+Builder.defineMacro("CL_VERSION_2_0", "200");

-  if (TI.isLittleEndian())
-Builder.defineMacro("__ENDIAN_LITTLE__");
+if (TI.isLittleEndian())
+  Builder.defineMacro("__ENDIAN_LITTLE__");

-  if (LangOpts.FastRelaxedMath)
-Builder.defineMacro("__FAST_RELAXED_MATH__");
-}
+if (LangOpts.FastRelaxedMath)
+  Builder.defineMacro("__FAST_RELAXED_MATH__");
   }
   // Not "standard" per se, but available even with the -undef flag.
   if (LangOpts.AsmPreprocessor)

Modified: cfe/trunk/lib/Headers/opencl-c-base.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/opencl-c-base.h?rev=368552&r1=368551&r2=368552&view=diff
==
--- cfe/trunk/lib/Headers/opencl-c-base.h (original)
+++ cfe/trunk/lib/Headers/opencl-c-base.h Mon Aug 12 03:44:07 2019
@@ -126,7 +126,7 @@ typedef double double8 __attribute__((ex
 typedef double double16 __attribute__((ext_vector_type(16)));
 #endif

-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
 #define NULL ((void*)0)
 #endif

@@ -276,7 +276,7 @@ typedef uint cl_mem_fence_flags;
  */
 #define CLK_GLOBAL_MEM_FENCE   0x02

-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)

 typedef enum memory_scope {
   memory_scope_work_item = __OPENCL_MEMORY_SCOPE_WORK_ITEM,
@@ -288,9 +288,6 @@ typedef enum memory_scope {
 #endif
 } memory_scope;

-#endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
-
-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 /**
  * Queue a memory fence to ensure correct ordering of memory
  * operations between work-items of a work-group to
@@ -313,7 +310,7 @@ typedef enum memory_order
   memory_order_seq_cst = __ATOMIC_SEQ_CST
 } memory_order;

-#endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#endif // defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)

 // OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14 - Image Read and Write 
Functions

@@ -389,14 +386,10 @@ typedef enum memory_order
 #endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0

 // OpenCL v2.0 s6.13.16 - Pipe Functions
-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
 #define CLK_NULL_RESERVE_ID (__builtin_astype(((void*)(__SIZE_MAX__)), 
reserve_id_t))
-#endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
-

 // OpenCL v2.0 s6.13.17 - Enqueue Kernels
-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
-
 #define CL_COMPLETE 0x0
 #define CL_RUNNING  0x1
 #define CL_SUBMITTED0x2
@@ -435,7 +428,7 @@ typedef struct {
   size_t localWorkSize[MAX_WORK_DIM];
 } ndrange_t;

-#endif //__OPENCL

r369251 - [OpenCL] Fix addr space deduction for pointers/references to arrays.

2019-08-19 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Mon Aug 19 04:43:16 2019
New Revision: 369251

URL: http://llvm.org/viewvc/llvm-project?rev=369251&view=rev
Log:
[OpenCL] Fix addr space deduction for pointers/references to arrays.

Rewrite the logic for detecting if we are deducing addr space of
a pointee type to take into account special logic for arrays. For
pointers/references to arrays we can have any number of parentheses
expressions as well as nested pointers.

Differential Revision: https://reviews.llvm.org/D66137


Modified:
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=369251&r1=369250&r2=369251&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Aug 19 04:43:16 2019
@@ -7385,8 +7385,22 @@ static void deduceOpenCLImplicitAddrSpac
   bool IsPointee =
   ChunkIndex > 0 &&
   (D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Pointer ||
-   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::BlockPointer ||
-   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Reference);
+   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Reference ||
+   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::BlockPointer);
+  // For pointers/references to arrays the next chunk is always an array
+  // followed by any number of parentheses.
+  if (!IsPointee && ChunkIndex > 1) {
+auto AdjustedCI = ChunkIndex - 1;
+if (D.getTypeObject(AdjustedCI).Kind == DeclaratorChunk::Array)
+  AdjustedCI--;
+// Skip over all parentheses.
+while (AdjustedCI > 0 &&
+   D.getTypeObject(AdjustedCI).Kind == DeclaratorChunk::Paren)
+  AdjustedCI--;
+if (D.getTypeObject(AdjustedCI).Kind == DeclaratorChunk::Pointer ||
+D.getTypeObject(AdjustedCI).Kind == DeclaratorChunk::Reference)
+  IsPointee = true;
+  }
   bool IsFuncReturnType =
   ChunkIndex > 0 &&
   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Function;

Modified: cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl?rev=369251&r1=369250&r2=369251&view=diff
==
--- cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl (original)
+++ cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl Mon Aug 19 04:43:16 
2019
@@ -78,3 +78,25 @@ __kernel void test() {
   int foo[10];
   xxx(&foo[0]);
 }
+
+// Addr space for pointer/reference to an array
+//CHECK: FunctionDecl {{.*}} t1 'void (const __generic float (&)[2])'
+void t1(const float (&fYZ)[2]);
+//CHECK: FunctionDecl {{.*}} t2 'void (const __generic float (*)[2])'
+void t2(const float (*fYZ)[2]);
+//CHECK: FunctionDecl {{.*}} t3 'void (__generic float (((*)))[2])'
+void t3(float(((*fYZ)))[2]);
+//CHECK: FunctionDecl {{.*}} t4 'void (__generic float (((*__generic *)))[2])'
+void t4(float(((**fYZ)))[2]);
+//CHECK: FunctionDecl {{.*}} t5 'void (__generic float (*__generic (*))[2])'
+void t5(float (*(*fYZ))[2]);
+
+__kernel void k() {
+  __local float x[2];
+  __local float(*p)[2];
+  t1(x);
+  t2(&x);
+  t3(&x);
+  t4(&p);
+  t5(&p);
+}


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


Re: r369251 - [OpenCL] Fix addr space deduction for pointers/references to arrays.

2019-08-20 Thread Anastasia Stulova via cfe-commits

Hi Hans,

Is it still possible to port this fix to the release branch?

Thanks,
Anastasia


From: cfe-commits  on behalf of Anastasia 
Stulova via cfe-commits 
Sent: 19 August 2019 12:43
To: cfe-commits@lists.llvm.org 
Subject: r369251 - [OpenCL] Fix addr space deduction for pointers/references to 
arrays.

Author: stulova
Date: Mon Aug 19 04:43:16 2019
New Revision: 369251

URL: http://llvm.org/viewvc/llvm-project?rev=369251&view=rev
Log:
[OpenCL] Fix addr space deduction for pointers/references to arrays.

Rewrite the logic for detecting if we are deducing addr space of
a pointee type to take into account special logic for arrays. For
pointers/references to arrays we can have any number of parentheses
expressions as well as nested pointers.

Differential Revision: https://reviews.llvm.org/D66137


Modified:
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=369251&r1=369250&r2=369251&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Aug 19 04:43:16 2019
@@ -7385,8 +7385,22 @@ static void deduceOpenCLImplicitAddrSpac
   bool IsPointee =
   ChunkIndex > 0 &&
   (D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Pointer ||
-   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::BlockPointer ||
-   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Reference);
+   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Reference ||
+   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::BlockPointer);
+  // For pointers/references to arrays the next chunk is always an array
+  // followed by any number of parentheses.
+  if (!IsPointee && ChunkIndex > 1) {
+auto AdjustedCI = ChunkIndex - 1;
+if (D.getTypeObject(AdjustedCI).Kind == DeclaratorChunk::Array)
+  AdjustedCI--;
+// Skip over all parentheses.
+while (AdjustedCI > 0 &&
+   D.getTypeObject(AdjustedCI).Kind == DeclaratorChunk::Paren)
+  AdjustedCI--;
+if (D.getTypeObject(AdjustedCI).Kind == DeclaratorChunk::Pointer ||
+D.getTypeObject(AdjustedCI).Kind == DeclaratorChunk::Reference)
+  IsPointee = true;
+  }
   bool IsFuncReturnType =
   ChunkIndex > 0 &&
   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Function;

Modified: cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl?rev=369251&r1=369250&r2=369251&view=diff
==
--- cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl (original)
+++ cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl Mon Aug 19 04:43:16 
2019
@@ -78,3 +78,25 @@ __kernel void test() {
   int foo[10];
   xxx(&foo[0]);
 }
+
+// Addr space for pointer/reference to an array
+//CHECK: FunctionDecl {{.*}} t1 'void (const __generic float (&)[2])'
+void t1(const float (&fYZ)[2]);
+//CHECK: FunctionDecl {{.*}} t2 'void (const __generic float (*)[2])'
+void t2(const float (*fYZ)[2]);
+//CHECK: FunctionDecl {{.*}} t3 'void (__generic float (((*)))[2])'
+void t3(float(((*fYZ)))[2]);
+//CHECK: FunctionDecl {{.*}} t4 'void (__generic float (((*__generic *)))[2])'
+void t4(float(((**fYZ)))[2]);
+//CHECK: FunctionDecl {{.*}} t5 'void (__generic float (*__generic (*))[2])'
+void t5(float (*(*fYZ))[2]);
+
+__kernel void k() {
+  __local float x[2];
+  __local float(*p)[2];
+  t1(x);
+  t2(&x);
+  t3(&x);
+  t4(&p);
+  t5(&p);
+}


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


r364023 - [Sema] Improved diagnostic for qualifiers in reference binding

2019-06-21 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Fri Jun 21 03:50:02 2019
New Revision: 364023

URL: http://llvm.org/viewvc/llvm-project?rev=364023&view=rev
Log:
[Sema] Improved diagnostic for qualifiers in reference binding

Improved wording and also simplified by using printing
method from qualifiers.

Differential Revision: https://reviews.llvm.org/D62914


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp
cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-var.cpp
cfe/trunk/test/CXX/expr/expr.post/expr.static.cast/p3-p4-0x.cpp
cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p16.cpp
cfe/trunk/test/Misc/diag-template-diffing.cpp
cfe/trunk/test/SemaCXX/builtins-arm.cpp
cfe/trunk/test/SemaCXX/err_reference_bind_drops_quals.cpp
cfe/trunk/test/SemaCXX/references.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=364023&r1=364022&r2=364023&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jun 21 03:50:02 
2019
@@ -1851,10 +1851,8 @@ def err_lvalue_reference_bind_to_unrelat
   "%diff{to type $ cannot bind to a value of unrelated type $|"
   "cannot bind to a value of unrelated type}1,2">;
 def err_reference_bind_drops_quals : Error<
-  "binding value %diff{of type $ to reference to type $|to reference}0,1 "
-  "drops %select{<>|'const'|'restrict'|'const' and 'restrict'|"
-  "'volatile'|'const' and 'volatile'|'restrict' and 'volatile'|"
-  "'const', 'restrict', and 'volatile'}2 qualifier%plural{1:|2:|4:|:s}2">;
+  "binding reference %diff{of type $ to value of type $|to value}0,1 "
+  "drops %2 qualifier%plural{1:|2:|4:|:s}3">;
 def err_reference_bind_failed : Error<
   "reference %diff{to %select{type|incomplete type}1 $ could not bind to an "
   "%select{rvalue|lvalue}2 of type $|could not bind to %select{rvalue|lvalue}2 
of "

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=364023&r1=364022&r2=364023&view=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Jun 21 03:50:02 2019
@@ -8522,8 +8522,9 @@ bool InitializationSequence::Diagnose(Se
 SourceType.getQualifiers() - NonRefType.getQualifiers();
 
 S.Diag(Kind.getLocation(), diag::err_reference_bind_drops_quals)
-  << SourceType
   << NonRefType
+  << SourceType
+  << Qualifiers::fromCVRMask(DroppedQualifiers.getCVRQualifiers())
   << DroppedQualifiers.getCVRQualifiers()
   << Args[0]->getSourceRange();
 break;

Modified: cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp?rev=364023&r1=364022&r2=364023&view=diff
==
--- cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp (original)
+++ cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp Fri Jun 21 
03:50:02 2019
@@ -122,8 +122,8 @@ namespace std_example_2 {
 
   const double& rcd2 = 2;
   double&& rrd = 2;
-  const volatile int cvi = 1; 
-  const int& r2 = cvi; // expected-error{{binding value of type 'const 
volatile int' to reference to type 'const int' drops 'volatile' qualifier}}
+  const volatile int cvi = 1;
+  const int& r2 = cvi; // expected-error{{binding reference of type 'const 
int' to value of type 'const volatile int' drops 'volatile' qualifier}}
 
   double d;
   double&& rrd2 = d; // expected-error{{rvalue reference to type 'double' 
cannot bind to lvalue of type 'double'}}

Modified: cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-var.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-var.cpp?rev=364023&r1=364022&r2=364023&view=diff
==
--- cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-var.cpp (original)
+++ cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-var.cpp Fri Jun 21 
03:50:02 2019
@@ -69,10 +69,10 @@ void bind_lvalue_quals(volatile Base b,
volatile const int ivc) {
   volatile Base &bvr1 = b;
   volatile Base &bvr2 = d;
-  volatile Base &bvr3 = bvc; // expected-error{{binding value of type 'const 
volatile Base' to reference to type 'volatile Base' drops 'const' qualifier}}
-  volatile Base &bvr4 = dvc; // expected-error{{binding value of type 'const 
volatile Derived' to reference to type 'volatile Base' drops 'const' qualifier}}
-  
-  volatile int &ir = ivc; // expected-error{{binding value of typ

r364032 - [Sema] Fix diagnostic for addr spaces in reference binding

2019-06-21 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Fri Jun 21 04:36:15 2019
New Revision: 364032

URL: http://llvm.org/viewvc/llvm-project?rev=364032&view=rev
Log:
[Sema] Fix diagnostic for addr spaces in reference binding

Extend reference binding behavior to account for address spaces.

Differential Revision: https://reviews.llvm.org/D62914


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/SemaOpenCLCXX/address-space-references.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=364032&r1=364031&r2=364032&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jun 21 04:36:15 
2019
@@ -1852,7 +1852,7 @@ def err_lvalue_reference_bind_to_unrelat
   "cannot bind to a value of unrelated type}1,2">;
 def err_reference_bind_drops_quals : Error<
   "binding reference %diff{of type $ to value of type $|to value}0,1 "
-  "drops %2 qualifier%plural{1:|2:|4:|:s}3">;
+  "%select{drops %3 qualifier%plural{1:|2:|4:|:s}4|changes address space}2">;
 def err_reference_bind_failed : Error<
   "reference %diff{to %select{type|incomplete type}1 $ could not bind to an "
   "%select{rvalue|lvalue}2 of type $|could not bind to %select{rvalue|lvalue}2 
of "

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=364032&r1=364031&r2=364032&view=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Jun 21 04:36:15 2019
@@ -4631,7 +4631,10 @@ static void TryReferenceInitializationCo
   // - Otherwise, the reference shall be an lvalue reference to a
   //   non-volatile const type (i.e., cv1 shall be const), or the reference
   //   shall be an rvalue reference.
-  if (isLValueRef && !(T1Quals.hasConst() && !T1Quals.hasVolatile())) {
+  //   For address spaces, we interpret this to mean that an addr space
+  //   of a reference "cv1 T1" is a superset of addr space of "cv2 T2".
+  if (isLValueRef && !(T1Quals.hasConst() && !T1Quals.hasVolatile() &&
+   T1Quals.isAddressSpaceSupersetOf(T2Quals))) {
 if (S.Context.getCanonicalType(T2) == S.Context.OverloadTy)
   Sequence.SetFailed(InitializationSequence::FK_AddressOfOverloadFailed);
 else if (ConvOvlResult && !Sequence.getFailedCandidateSet().empty())
@@ -4640,7 +4643,10 @@ static void TryReferenceInitializationCo
   ConvOvlResult);
 else if (!InitCategory.isLValue())
   Sequence.SetFailed(
-  
InitializationSequence::FK_NonConstLValueReferenceBindingToTemporary);
+  T1Quals.isAddressSpaceSupersetOf(T2Quals)
+  ? InitializationSequence::
+FK_NonConstLValueReferenceBindingToTemporary
+  : InitializationSequence::FK_ReferenceInitDropsQualifiers);
 else {
   InitializationSequence::FailureKind FK;
   switch (RefRelationship) {
@@ -8521,12 +8527,16 @@ bool InitializationSequence::Diagnose(Se
 Qualifiers DroppedQualifiers =
 SourceType.getQualifiers() - NonRefType.getQualifiers();
 
-S.Diag(Kind.getLocation(), diag::err_reference_bind_drops_quals)
-  << NonRefType
-  << SourceType
-  << Qualifiers::fromCVRMask(DroppedQualifiers.getCVRQualifiers())
-  << DroppedQualifiers.getCVRQualifiers()
-  << Args[0]->getSourceRange();
+if (!NonRefType.getQualifiers().isAddressSpaceSupersetOf(
+SourceType.getQualifiers()))
+  S.Diag(Kind.getLocation(), diag::err_reference_bind_drops_quals)
+  << NonRefType << SourceType << 1 /*addr space*/
+  << Args[0]->getSourceRange();
+else
+  S.Diag(Kind.getLocation(), diag::err_reference_bind_drops_quals)
+  << NonRefType << SourceType << 0 /*cv quals*/
+  << Qualifiers::fromCVRMask(DroppedQualifiers.getCVRQualifiers())
+  << DroppedQualifiers.getCVRQualifiers() << Args[0]->getSourceRange();
 break;
   }
 

Modified: cfe/trunk/test/SemaOpenCLCXX/address-space-references.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCLCXX/address-space-references.cl?rev=364032&r1=364031&r2=364032&view=diff
==
--- cfe/trunk/test/SemaOpenCLCXX/address-space-references.cl (original)
+++ cfe/trunk/test/SemaOpenCLCXX/address-space-references.cl Fri Jun 21 
04:36:15 2019
@@ -3,3 +3,13 @@
 __global const int& f(__global float &ref) {
   return ref; // expected-error{{reference of type 'const __global int &' 
cannot bind to a temporary object because of address space mismatch}}
 }
+
+int bar(const __global unsigned int &i); // expect

r364071 - [OpenCL][PR41963] Add generic addr space to old atomics in C++ mode

2019-06-21 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Fri Jun 21 09:19:16 2019
New Revision: 364071

URL: http://llvm.org/viewvc/llvm-project?rev=364071&view=rev
Log:
[OpenCL][PR41963] Add generic addr space to old atomics in C++ mode

Add overloads with generic address space pointer to old atomics.
This is currently only added for C++ compilation mode.

Differential Revision: https://reviews.llvm.org/D62335


Modified:
cfe/trunk/lib/Headers/opencl-c.h
cfe/trunk/test/Headers/opencl-c-header.cl

Modified: cfe/trunk/lib/Headers/opencl-c.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/opencl-c.h?rev=364071&r1=364070&r2=364071&view=diff
==
--- cfe/trunk/lib/Headers/opencl-c.h (original)
+++ cfe/trunk/lib/Headers/opencl-c.h Fri Jun 21 09:19:16 2019
@@ -13055,6 +13055,10 @@ int __ovld atomic_add(volatile __global
 unsigned int __ovld atomic_add(volatile __global unsigned int *p, unsigned int 
val);
 int __ovld atomic_add(volatile __local int *p, int val);
 unsigned int __ovld atomic_add(volatile __local unsigned int *p, unsigned int 
val);
+#ifdef __OPENCL_CPP_VERSION__
+int __ovld atomic_add(volatile int *p, int val);
+unsigned int __ovld atomic_add(volatile unsigned int *p, unsigned int val);
+#endif
 
 #if defined(cl_khr_global_int32_base_atomics)
 int __ovld atom_add(volatile __global int *p, int val);
@@ -13081,6 +13085,10 @@ int __ovld atomic_sub(volatile __global
 unsigned int __ovld atomic_sub(volatile __global unsigned int *p, unsigned int 
val);
 int __ovld atomic_sub(volatile __local int *p, int val);
 unsigned int __ovld atomic_sub(volatile __local unsigned int *p, unsigned int 
val);
+#ifdef __OPENCL_CPP_VERSION__
+int __ovld atomic_sub(volatile int *p, int val);
+unsigned int __ovld atomic_sub(volatile unsigned int *p, unsigned int val);
+#endif
 
 #if defined(cl_khr_global_int32_base_atomics)
 int __ovld atom_sub(volatile __global int *p, int val);
@@ -13109,6 +13117,11 @@ int __ovld atomic_xchg(volatile __local
 unsigned int __ovld atomic_xchg(volatile __local unsigned int *p, unsigned int 
val);
 float __ovld atomic_xchg(volatile __global float *p, float val);
 float __ovld atomic_xchg(volatile __local float *p, float val);
+#ifdef __OPENCL_CPP_VERSION__
+int __ovld atomic_xchg(volatile int *p, int val);
+unsigned int __ovld atomic_xchg(volatile unsigned int *p, unsigned int val);
+float __ovld atomic_xchg(volatile float *p, float val);
+#endif
 
 #if defined(cl_khr_global_int32_base_atomics)
 int __ovld atom_xchg(volatile __global int *p, int val);
@@ -13136,6 +13149,10 @@ int __ovld atomic_inc(volatile __global
 unsigned int __ovld atomic_inc(volatile __global unsigned int *p);
 int __ovld atomic_inc(volatile __local int *p);
 unsigned int __ovld atomic_inc(volatile __local unsigned int *p);
+#ifdef __OPENCL_CPP_VERSION__
+int __ovld atomic_inc(volatile int *p);
+unsigned int __ovld atomic_inc(volatile unsigned int *p);
+#endif
 
 #if defined(cl_khr_global_int32_base_atomics)
 int __ovld atom_inc(volatile __global int *p);
@@ -13163,6 +13180,10 @@ int __ovld atomic_dec(volatile __global
 unsigned int __ovld atomic_dec(volatile __global unsigned int *p);
 int __ovld atomic_dec(volatile __local int *p);
 unsigned int __ovld atomic_dec(volatile __local unsigned int *p);
+#ifdef __OPENCL_CPP_VERSION__
+int __ovld atomic_dec(volatile int *p);
+unsigned int __ovld atomic_dec(volatile unsigned int *p);
+#endif
 
 #if defined(cl_khr_global_int32_base_atomics)
 int __ovld atom_dec(volatile __global int *p);
@@ -13191,6 +13212,10 @@ int __ovld atomic_cmpxchg(volatile __glo
 unsigned int __ovld atomic_cmpxchg(volatile __global unsigned int *p, unsigned 
int cmp, unsigned int val);
 int __ovld atomic_cmpxchg(volatile __local int *p, int cmp, int val);
 unsigned int __ovld atomic_cmpxchg(volatile __local unsigned int *p, unsigned 
int cmp, unsigned int val);
+#ifdef __OPENCL_CPP_VERSION__
+int __ovld atomic_cmpxchg(volatile int *p, int cmp, int val);
+unsigned int __ovld atomic_cmpxchg(volatile unsigned int *p, unsigned int cmp, 
unsigned int val);
+#endif
 
 #if defined(cl_khr_global_int32_base_atomics)
 int __ovld atom_cmpxchg(volatile __global int *p, int cmp, int val);
@@ -13219,6 +13244,10 @@ int __ovld atomic_min(volatile __global
 unsigned int __ovld atomic_min(volatile __global unsigned int *p, unsigned int 
val);
 int __ovld atomic_min(volatile __local int *p, int val);
 unsigned int __ovld atomic_min(volatile __local unsigned int *p, unsigned int 
val);
+#ifdef __OPENCL_CPP_VERSION__
+int __ovld atomic_min(volatile int *p, int val);
+unsigned int __ovld atomic_min(volatile unsigned int *p, unsigned int val);
+#endif
 
 #if defined(cl_khr_global_int32_extended_atomics)
 int __ovld atom_min(volatile __global int *p, int val);
@@ -13247,6 +13276,10 @@ int __ovld atomic_max(volatile __global
 unsigned int __ovld atomic_max(volatile __global unsigned int *p, unsigned int 
val);
 int __ovld atomic_max(volatile __local int *p, int val

r350386 - [Basic] Extend DiagnosticEngine to store and format Qualifiers.

2019-01-04 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Fri Jan  4 03:50:36 2019
New Revision: 350386

URL: http://llvm.org/viewvc/llvm-project?rev=350386&view=rev
Log:
[Basic] Extend DiagnosticEngine to store and format Qualifiers.
 
Qualifiers can now be streamed into the DiagnosticEngine using
regular << operator. If Qualifiers are empty 'unqualified' will
be printed in the diagnostic otherwise regular qual syntax is
used.

Differential Revision: https://reviews.llvm.org/D56198


Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/Basic/Diagnostic.h
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/AST/ASTDiagnostic.cpp
cfe/trunk/lib/Basic/Diagnostic.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/SemaCXX/addr-of-overloaded-function.cpp
cfe/trunk/test/SemaCXX/warn-overloaded-virtual.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=350386&r1=350385&r2=350386&view=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Fri Jan  4 03:50:36 2019
@@ -6701,6 +6701,24 @@ inline const Type *Type::getPointeeOrArr
   return type;
 }
 
+/// Insertion operator for diagnostics. This allows sending Qualifiers into a
+/// diagnostic with <<.
+inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
+   Qualifiers Q) {
+  DB.AddTaggedVal(Q.getAsOpaqueValue(),
+  DiagnosticsEngine::ArgumentKind::ak_qual);
+  return DB;
+}
+
+/// Insertion operator for partial diagnostics. This allows sending Qualifiers
+/// into a diagnostic with <<.
+inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
+   Qualifiers Q) {
+  PD.AddTaggedVal(Q.getAsOpaqueValue(),
+  DiagnosticsEngine::ArgumentKind::ak_qual);
+  return PD;
+}
+
 /// Insertion operator for diagnostics.  This allows sending QualType's into a
 /// diagnostic with <<.
 inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=350386&r1=350385&r2=350386&view=diff
==
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Fri Jan  4 03:50:36 2019
@@ -177,6 +177,9 @@ public:
 /// IdentifierInfo
 ak_identifierinfo,
 
+/// Qualifiers
+ak_qual,
+
 /// QualType
 ak_qualtype,
 

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=350386&r1=350385&r2=350386&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jan  4 03:50:36 
2019
@@ -1809,11 +1809,7 @@ def err_init_conversion_failed : Error<
   "|: different number of parameters (%5 vs %6)"
   "|: type mismatch at %ordinal5 parameter%diff{ ($ vs $)|}6,7"
   "|: different return type%diff{ ($ vs $)|}5,6"
-  "|: different qualifiers ("
-  "%select{none|const|restrict|const and restrict|volatile|const and volatile|"
-  "volatile and restrict|const, volatile, and restrict}5 vs "
-  "%select{none|const|restrict|const and restrict|volatile|const and volatile|"
-  "volatile and restrict|const, volatile, and restrict}6)"
+  "|: different qualifiers (%5 vs %6)"
   "|: different exception specifications}4">;
 
 def err_lvalue_to_rvalue_ref : Error<"rvalue reference %diff{to type $ cannot "
@@ -3593,11 +3589,7 @@ def note_ovl_candidate : Note<
 "| has type mismatch at %ordinal5 parameter"
 "%diff{ (expected $ but has $)|}6,7"
 "| has different return type%diff{ ($ expected but has $)|}5,6"
-"| has different qualifiers (expected "
-"%select{none|const|restrict|const and restrict|volatile|const and 
volatile"
-"|volatile and restrict|const, volatile, and restrict}5 but found "
-"%select{none|const|restrict|const and restrict|volatile|const and 
volatile"
-"|volatile and restrict|const, volatile, and restrict}6)"
+"| has different qualifiers (expected %5 but found %6)"
 "| has different exception specification}4">;
 
 def note_ovl_candidate_inherited_constructor : Note<
@@ -6470,11 +6462,7 @@ def note_hidden_overloaded_virtual_decla
   "|: different number of parameters (%2 vs %3)"
   "|: type mismatch at %ordinal2 parameter%diff{ ($ vs $)|}3,4"
   "|: different return type%diff{ ($ vs $)|}2,3"
-  "|: different qualifiers ("
-  "%select{none|const|restrict|const and restrict|volatile|const and volatile|"
-  "volatile and restrict|const, volatile, and restrict}2

r350703 - Use DeclSpec for quals in DeclaratorChunk::FunctionTypeInfo.

2019-01-09 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Wed Jan  9 03:25:09 2019
New Revision: 350703

URL: http://llvm.org/viewvc/llvm-project?rev=350703&view=rev
Log:
Use DeclSpec for quals in DeclaratorChunk::FunctionTypeInfo.

Rather than duplicating data fields, use DeclSpec directly to store
the qualifiers for the functions/methods. This change doesn't handle
attributes yet and has to be extended further.

Differential revision: https://reviews.llvm.org/D55948


Modified:
cfe/trunk/include/clang/Sema/DeclSpec.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Sema/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaLambda.cpp
cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/include/clang/Sema/DeclSpec.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/DeclSpec.h?rev=350703&r1=350702&r2=350703&view=diff
==
--- cfe/trunk/include/clang/Sema/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Sema/DeclSpec.h Wed Jan  9 03:25:09 2019
@@ -593,6 +593,18 @@ public:
 FS_noreturnLoc = SourceLocation();
   }
 
+  /// This method calls the passed in handler on each CVRU qual being
+  /// set.
+  /// Handle - a handler to be invoked.
+  void forEachCVRUQualifier(
+  llvm::function_ref Handle);
+
+  /// This method calls the passed in handler on each qual being
+  /// set.
+  /// Handle - a handler to be invoked.
+  void forEachQualifier(
+  llvm::function_ref Handle);
+
   /// Return true if any type-specifier has been found.
   bool hasTypeSpecifier() const {
 return getTypeSpecType() != DeclSpec::TST_unspecified ||
@@ -683,6 +695,8 @@ public:
 ExprRep = Rep;
   }
 
+  bool SetTypeQual(TQ T, SourceLocation Loc);
+
   bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
unsigned &DiagID, const LangOptions &Lang);
 
@@ -1250,10 +1264,6 @@ struct DeclaratorChunk {
 /// Otherwise, it's an rvalue reference.
 unsigned RefQualifierIsLValueRef : 1;
 
-/// The type qualifiers: const/volatile/restrict/__unaligned
-/// The qualifier bitmask values are the same as in QualType.
-unsigned TypeQuals : 4;
-
 /// ExceptionSpecType - An ExceptionSpecificationType value.
 unsigned ExceptionSpecType : 4;
 
@@ -1287,21 +1297,6 @@ struct DeclaratorChunk {
 /// If this is an invalid location, there is no ref-qualifier.
 unsigned RefQualifierLoc;
 
-/// The location of the const-qualifier, if any.
-///
-/// If this is an invalid location, there is no const-qualifier.
-unsigned ConstQualifierLoc;
-
-/// The location of the volatile-qualifier, if any.
-///
-/// If this is an invalid location, there is no volatile-qualifier.
-unsigned VolatileQualifierLoc;
-
-/// The location of the restrict-qualifier, if any.
-///
-/// If this is an invalid location, there is no restrict-qualifier.
-unsigned RestrictQualifierLoc;
-
 /// The location of the 'mutable' qualifer in a lambda-declarator, if
 /// any.
 unsigned MutableLoc;
@@ -1317,6 +1312,12 @@ struct DeclaratorChunk {
 /// there are no parameters specified.
 ParamInfo *Params;
 
+/// DeclSpec for the function with the qualifier related info.
+DeclSpec *MethodQualifiers;
+
+/// AtttibuteFactory for the MethodQualifiers.
+AttributeFactory *QualAttrFactory;
+
 union {
   /// Pointer to a new[]'d array of TypeAndRange objects that
   /// contain the types in the function's dynamic exception specification
@@ -1356,6 +1357,8 @@ struct DeclaratorChunk {
 
 void destroy() {
   freeParams();
+  delete QualAttrFactory;
+  delete MethodQualifiers;
   switch (getExceptionSpecType()) {
   default:
 break;
@@ -1372,6 +1375,14 @@ struct DeclaratorChunk {
   }
 }
 
+DeclSpec &getOrCreateMethodQualifiers() {
+  if (!MethodQualifiers) {
+QualAttrFactory = new AttributeFactory();
+MethodQualifiers = new DeclSpec(*QualAttrFactory);
+  }
+  return *MethodQualifiers;
+}
+
 /// isKNRPrototype - Return true if this is a K&R style identifier list,
 /// like "void foo(a,b,c)".  In a function definition, this will be 
followed
 /// by the parameter type definitions.
@@ -1406,19 +1417,22 @@ struct DeclaratorChunk {
   return SourceLocation::getFromRawEncoding(RefQualifierLoc);
 }
 
-/// Retrieve the location of the 'const' qualifier, if any.
+/// Retrieve the location of the 'const' qualifier.
 SourceLocation getConstQualifierLoc() const {
-  return SourceLocation::getFromRawEncoding(ConstQualifierLoc);
+  assert(MethodQualifiers);
+  return MethodQualifiers->getConstSpecLoc();
 }
 
-/// Retrieve the location of the 'volatile' qualifier, if any.
+///

r329911 - [OpenCL] Added -std/-cl-std=c++

2018-04-12 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu Apr 12 07:17:04 2018
New Revision: 329911

URL: http://llvm.org/viewvc/llvm-project?rev=329911&view=rev
Log:
[OpenCL] Added -std/-cl-std=c++

This is std option for OpenCL C++ v1.0.

Differential Revision: https://reviews.llvm.org/D45363


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Basic/LangOptions.def
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/LangStandards.def
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/test/Driver/autocomplete.c
cfe/trunk/test/Driver/opencl.cl
cfe/trunk/test/Driver/unknown-std.cl
cfe/trunk/test/Frontend/opencl.cl
cfe/trunk/test/Frontend/stdlang.c
cfe/trunk/test/Preprocessor/predefined-macros.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=329911&r1=329910&r2=329911&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Apr 12 07:17:04 
2018
@@ -7966,7 +7966,7 @@ def err_generic_sel_multi_match : Error<
 
 // Blocks
 def err_blocks_disable : Error<"blocks support disabled - compile with 
-fblocks"
-  " or %select{pick a deployment target that supports them|for OpenCL 2.0 or 
above}0">;
+  " or %select{pick a deployment target that supports them|for OpenCL 2.0}0">;
 def err_block_returning_array_function : Error<
   "block cannot return %select{array|function}0 type %1">;
 

Modified: cfe/trunk/include/clang/Basic/LangOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=329911&r1=329910&r2=329911&view=diff
==
--- cfe/trunk/include/clang/Basic/LangOptions.def (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.def Thu Apr 12 07:17:04 2018
@@ -188,7 +188,8 @@ ENUM_LANGOPT(DefaultCallingConv, Default
 LANGOPT(ShortEnums, 1, 0, "short enum types")
 
 LANGOPT(OpenCL, 1, 0, "OpenCL")
-LANGOPT(OpenCLVersion , 32, 0, "OpenCL version")
+LANGOPT(OpenCLVersion , 32, 0, "OpenCL C version")
+LANGOPT(OpenCLCPlusPlusVersion , 32, 0, "OpenCL C++ version")
 LANGOPT(NativeHalfType, 1, 0, "Native half type support")
 LANGOPT(NativeHalfArgsAndReturns, 1, 0, "Native half args and returns")
 LANGOPT(HalfArgsAndReturns, 1, 0, "half args and returns")

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=329911&r1=329910&r2=329911&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Thu Apr 12 07:17:04 2018
@@ -514,7 +514,7 @@ def cl_mad_enable : Flag<["-"], "cl-mad-
 def cl_no_signed_zeros : Flag<["-"], "cl-no-signed-zeros">, 
Group, Flags<[CC1Option]>,
   HelpText<"OpenCL only. Allow use of less precise no signed zeros 
computations in the generated binary.">;
 def cl_std_EQ : Joined<["-"], "cl-std=">, Group, 
Flags<[CC1Option]>,
-  HelpText<"OpenCL language standard to compile for.">, 
Values<"cl,CL,cl1.1,CL1.1,cl1.2,CL1.2,cl2.0,CL2.0">;
+  HelpText<"OpenCL language standard to compile for.">, 
Values<"cl,CL,cl1.1,CL1.1,cl1.2,CL1.2,cl2.0,CL2.0,c++">;
 def cl_denorms_are_zero : Flag<["-"], "cl-denorms-are-zero">, 
Group, Flags<[CC1Option]>,
   HelpText<"OpenCL only. Allow denormals to be flushed to zero.">;
 def cl_fp32_correctly_rounded_divide_sqrt : Flag<["-"], 
"cl-fp32-correctly-rounded-divide-sqrt">, Group, 
Flags<[CC1Option]>,

Modified: cfe/trunk/include/clang/Frontend/LangStandards.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/LangStandards.def?rev=329911&r1=329910&r2=329911&view=diff
==
--- cfe/trunk/include/clang/Frontend/LangStandards.def (original)
+++ cfe/trunk/include/clang/Frontend/LangStandards.def Thu Apr 12 07:17:04 2018
@@ -155,6 +155,9 @@ LANGSTANDARD(opencl12, "cl1.2",
 LANGSTANDARD(opencl20, "cl2.0",
  OpenCL, "OpenCL 2.0",
  LineComment | C99 | Digraphs | HexFloat | OpenCL)
+LANGSTANDARD(openclcpp, "c++",
+ OpenCL, "OpenCL C++ 1.0",
+ LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs | 
OpenCL)
 
 LANGSTANDARD_ALIAS_DEPR(opencl10, "CL")
 LANGSTANDARD_ALIAS_DEPR(opencl11, "CL1.1")

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=329911&r1=329910&r2=329911&view=diff
==
--- cfe/trunk/lib

[clang] 92fa91b - [OpenCL] Fixed missing address space for templated copy constructor.

2020-07-27 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-07-27T15:18:49+01:00
New Revision: 92fa91bb402921a5705507c38f583e9b8e9d84e4

URL: 
https://github.com/llvm/llvm-project/commit/92fa91bb402921a5705507c38f583e9b8e9d84e4
DIFF: 
https://github.com/llvm/llvm-project/commit/92fa91bb402921a5705507c38f583e9b8e9d84e4.diff

LOG: [OpenCL] Fixed missing address space for templated copy constructor.

Added missing address space for the parameter of copy ctor created
for templated constructor with an R-value reference.

Patch by Ole Strohm (olestrohm)!

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83665

Added: 


Modified: 
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/SemaOpenCLCXX/address-space-templates.cl

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 52062e9a5039..8e7b4e1655ea 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3815,8 +3815,11 @@ static bool AdjustFunctionParmAndArgTypesForDeduction(
 //   If P is a forwarding reference and the argument is an lvalue, the type
 //   "lvalue reference to A" is used in place of A for type deduction.
 if (isForwardingReference(QualType(ParamRefType, 0), FirstInnerIndex) &&
-Arg->isLValue())
+Arg->isLValue()) {
+  if (S.getLangOpts().OpenCL)
+ArgType = S.Context.getAddrSpaceQualType(ArgType, 
LangAS::opencl_generic);
   ArgType = S.Context.getLValueReferenceType(ArgType);
+}
   } else {
 // C++ [temp.deduct.call]p2:
 //   If P is not a reference type:

diff  --git a/clang/test/SemaOpenCLCXX/address-space-templates.cl 
b/clang/test/SemaOpenCLCXX/address-space-templates.cl
index 6b304d2fdda4..be187de5684b 100644
--- a/clang/test/SemaOpenCLCXX/address-space-templates.cl
+++ b/clang/test/SemaOpenCLCXX/address-space-templates.cl
@@ -22,10 +22,28 @@ void foo3() {
   __private T ii; // expected-error{{conflicting address space qualifiers are 
provided between types '__private T' and '__global int'}}
 }
 
+template  struct remove_reference { typedef _Tp type; };
+template  struct remove_reference<_Tp &>  { typedef _Tp type; };
+template  struct as_pointer {
+typedef typename remove_reference<_Tp>::type* type;
+};
+
+struct rep {
+  // CHECK |-CXXConstructorDecl {{.*}} rep 'void (const __generic rep 
&__private) __generic'
+  template::type>
+  rep(U&& v) {}
+};
+
+struct rep_outer : private rep {
+  rep_outer()
+: rep(0) {}
+};
+
 void bar() {
   S sintgl; // expected-note{{in instantiation of template 
class 'S' requested here}}
 
   foo1<__local int>(1); // expected-error{{no matching function for call to 
'foo1'}}
   foo2<__global int>(0);
   foo3<__global int>(); // expected-note{{in instantiation of function 
template specialization 'foo3<__global int>' requested here}}
+  rep_outer r;
 }



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


[clang] 4a4402f - [OpenCL] Add cl_khr_extended_subgroup extensions.

2020-06-04 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-06-04T13:29:30+01:00
New Revision: 4a4402f0d72167477a6252e4c3daf5089ebc8f9a

URL: 
https://github.com/llvm/llvm-project/commit/4a4402f0d72167477a6252e4c3daf5089ebc8f9a
DIFF: 
https://github.com/llvm/llvm-project/commit/4a4402f0d72167477a6252e4c3daf5089ebc8f9a.diff

LOG: [OpenCL] Add cl_khr_extended_subgroup extensions.

Added extensions and their function declarations into
the standard header.

Patch by Piotr Fusik!

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79781

Added: 


Modified: 
clang/include/clang/Basic/OpenCLExtensions.def
clang/lib/Headers/opencl-c.h
clang/test/SemaOpenCL/extension-version.cl

Removed: 




diff  --git a/clang/include/clang/Basic/OpenCLExtensions.def 
b/clang/include/clang/Basic/OpenCLExtensions.def
index 517481584313..1ae36b32fb0a 100644
--- a/clang/include/clang/Basic/OpenCLExtensions.def
+++ b/clang/include/clang/Basic/OpenCLExtensions.def
@@ -74,6 +74,13 @@ OPENCLEXT_INTERNAL(cl_khr_mipmap_image_writes, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_srgb_image_writes, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_subgroups, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_terminate_context, 200, ~0U)
+OPENCLEXT_INTERNAL(cl_khr_subgroup_extended_types, 200, ~0U)
+OPENCLEXT_INTERNAL(cl_khr_subgroup_non_uniform_vote, 200, ~0U)
+OPENCLEXT_INTERNAL(cl_khr_subgroup_ballot, 200, ~0U)
+OPENCLEXT_INTERNAL(cl_khr_subgroup_non_uniform_arithmetic, 200, ~0U)
+OPENCLEXT_INTERNAL(cl_khr_subgroup_shuffle, 200, ~0U)
+OPENCLEXT_INTERNAL(cl_khr_subgroup_shuffle_relative, 200, ~0U)
+OPENCLEXT_INTERNAL(cl_khr_subgroup_clustered_reduce, 200, ~0U)
 
 // Clang Extensions.
 OPENCLEXT_INTERNAL(cl_clang_storage_class_specifiers, 100, ~0U)

diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 6ac9f92d23a2..66e18bdd47bb 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -15460,6 +15460,674 @@ double  __ovld __conv 
sub_group_scan_inclusive_max(double x);
 
 #endif //cl_khr_subgroups cl_intel_subgroups
 
+#if defined(cl_khr_subgroup_extended_types)
+char __ovld __conv sub_group_broadcast( char value, uint index );
+char2 __ovld __conv sub_group_broadcast( char2 value, uint index );
+char3 __ovld __conv sub_group_broadcast( char3 value, uint index );
+char4 __ovld __conv sub_group_broadcast( char4 value, uint index );
+char8 __ovld __conv sub_group_broadcast( char8 value, uint index );
+char16 __ovld __conv sub_group_broadcast( char16 value, uint index );
+
+uchar __ovld __conv sub_group_broadcast( uchar value, uint index );
+uchar2 __ovld __conv sub_group_broadcast( uchar2 value, uint index );
+uchar3 __ovld __conv sub_group_broadcast( uchar3 value, uint index );
+uchar4 __ovld __conv sub_group_broadcast( uchar4 value, uint index );
+uchar8 __ovld __conv sub_group_broadcast( uchar8 value, uint index );
+uchar16 __ovld __conv sub_group_broadcast( uchar16 value, uint index );
+
+short __ovld __conv sub_group_broadcast( short value, uint index );
+short2 __ovld __conv sub_group_broadcast( short2 value, uint index );
+short3 __ovld __conv sub_group_broadcast( short3 value, uint index );
+short4 __ovld __conv sub_group_broadcast( short4 value, uint index );
+short8 __ovld __conv sub_group_broadcast( short8 value, uint index );
+short16 __ovld __conv sub_group_broadcast( short16 value, uint index );
+
+ushort __ovld __conv sub_group_broadcast( ushort value, uint index );
+ushort2 __ovld __conv sub_group_broadcast( ushort2 value, uint index );
+ushort3 __ovld __conv sub_group_broadcast( ushort3 value, uint index );
+ushort4 __ovld __conv sub_group_broadcast( ushort4 value, uint index );
+ushort8 __ovld __conv sub_group_broadcast( ushort8 value, uint index );
+ushort16 __ovld __conv sub_group_broadcast( ushort16 value, uint index );
+
+// scalar int broadcast is part of cl_khr_subgroups
+int2 __ovld __conv sub_group_broadcast( int2 value, uint index );
+int3 __ovld __conv sub_group_broadcast( int3 value, uint index );
+int4 __ovld __conv sub_group_broadcast( int4 value, uint index );
+int8 __ovld __conv sub_group_broadcast( int8 value, uint index );
+int16 __ovld __conv sub_group_broadcast( int16 value, uint index );
+
+// scalar uint broadcast is part of cl_khr_subgroups
+uint2 __ovld __conv sub_group_broadcast( uint2 value, uint index );
+uint3 __ovld __conv sub_group_broadcast( uint3 value, uint index );
+uint4 __ovld __conv sub_group_broadcast( uint4 value, uint index );
+uint8 __ovld __conv sub_group_broadcast( uint8 value, uint index );
+uint16 __ovld __conv sub_group_broadcast( uint16 value, uint index );
+
+// scalar long broadcast is part of cl_khr_subgroups
+long2 __ovld __conv sub_group_broadcast( long2 value, uint index );
+long3 __ovld __conv sub_group_broadcast( long3 value, uint index );
+long4 __ovld __conv sub_group_broadcast( long4 value, uint index );
+long8 __ovld __conv sub_group_broadcast( long8 value, uint ind

[clang] 8c8a2fd - [OpenCL] Fixed typo for ctor stub name in UsersManual

2020-07-10 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-07-10T19:04:49+01:00
New Revision: 8c8a2fd1f015525d048444610a6e27c66aa96293

URL: 
https://github.com/llvm/llvm-project/commit/8c8a2fd1f015525d048444610a6e27c66aa96293
DIFF: 
https://github.com/llvm/llvm-project/commit/8c8a2fd1f015525d048444610a6e27c66aa96293.diff

LOG: [OpenCL] Fixed typo for ctor stub name in UsersManual

Added: 


Modified: 
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 4b4e28a8b65c..8615a77596b4 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3132,7 +3132,7 @@ Global objects must be constructed before the first 
kernel using the global obje
 is executed and destroyed just after the last kernel using the program objects 
is
 executed. In OpenCL v2.0 drivers there is no specific API for invoking global
 constructors. However, an easy workaround would be to enqueue a constructor
-initialization kernel that has a name ``@_GLOBAL__sub_I_``.
+initialization kernel that has a name ``_GLOBAL__sub_I_``.
 This kernel is only present if there are any global objects to be initialized 
in
 the compiled binary. One way to check this is by passing 
``CL_PROGRAM_KERNEL_NAMES``
 to ``clGetProgramInfo`` (OpenCL v2.0 s5.8.7).
@@ -3148,7 +3148,7 @@ before running any kernels in which the objects are used.
  clang -cl-std=clc++ test.cl
 
 If there are any global objects to be initialized, the final binary will 
contain
-the ``@_GLOBAL__sub_I_test.cl`` kernel to be enqueued.
+the ``_GLOBAL__sub_I_test.cl`` kernel to be enqueued.
 
 Global destructors can not be invoked in OpenCL v2.0 drivers. However, all 
memory used
 for program scope objects is released on ``clReleaseProgram``.



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


[clang] 6050c15 - [OpenCL] Defer addr space deduction for dependent type.

2020-07-13 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-07-13T11:44:38+01:00
New Revision: 6050c156ab4f13a3c54ca6ec297a72ece95966d7

URL: 
https://github.com/llvm/llvm-project/commit/6050c156ab4f13a3c54ca6ec297a72ece95966d7
DIFF: 
https://github.com/llvm/llvm-project/commit/6050c156ab4f13a3c54ca6ec297a72ece95966d7.diff

LOG: [OpenCL] Defer addr space deduction for dependent type.

This patch removes deduction of address spaces in parsing
for types that depend on template parameter even if an
address space is already known. Deducing it early interferes
with template instantiation/specialization logic that uses
source address space where address space is not present.

Address space deduction for templates is therefore fully
moved to the template instantiation/specialization phase.

Patch by Ole Strohm (olestrohm)!

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82781

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaOpenCLCXX/address-space-deduction.cl

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index f5e375134c29..3e2b61ae8cdf 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6290,6 +6290,8 @@ bool Sema::inferObjCARCLifetime(ValueDecl *decl) {
 void Sema::deduceOpenCLAddressSpace(ValueDecl *Decl) {
   if (Decl->getType().hasAddressSpace())
 return;
+  if (Decl->getType()->isDependentType())
+return;
   if (VarDecl *Var = dyn_cast(Decl)) {
 QualType Type = Var->getType();
 if (Type->isSamplerT() || Type->isVoidType())
@@ -7859,6 +7861,7 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) {
 if (NewVD->isFileVarDecl() || NewVD->isStaticLocal() ||
 NewVD->hasExternalStorage()) {
   if (!T->isSamplerT() &&
+  !T->isDependentType() &&
   !(T.getAddressSpace() == LangAS::opencl_constant ||
 (T.getAddressSpace() == LangAS::opencl_global &&
  (getLangOpts().OpenCLVersion == 200 ||

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 85adc4ef2dbd..2efb7acb9724 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3625,6 +3625,9 @@ Decl 
*TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl(
   if (InsertPos)
 VarTemplate->AddSpecialization(Var, InsertPos);
 
+  if (SemaRef.getLangOpts().OpenCL)
+SemaRef.deduceOpenCLAddressSpace(Var);
+
   // Substitute the nested name specifier, if any.
   if (SubstQualifier(D, Var))
 return nullptr;
@@ -4895,6 +4898,9 @@ VarTemplateSpecializationDecl 
*Sema::CompleteVarTemplateSpecializationDecl(
   // Instantiate the initializer.
   InstantiateVariableInitializer(VarSpec, PatternDecl, TemplateArgs);
 
+  if (getLangOpts().OpenCL)
+deduceOpenCLAddressSpace(VarSpec);
+
   return VarSpec;
 }
 

diff  --git a/clang/test/SemaOpenCLCXX/address-space-deduction.cl 
b/clang/test/SemaOpenCLCXX/address-space-deduction.cl
index 6a81a8b2d7c7..ddfdb6da4347 100644
--- a/clang/test/SemaOpenCLCXX/address-space-deduction.cl
+++ b/clang/test/SemaOpenCLCXX/address-space-deduction.cl
@@ -5,6 +5,11 @@
 //CHECK: |-VarDecl {{.*}} foo 'const __global int'
 constexpr int foo = 0;
 
+//CHECK: |-VarDecl {{.*}} foo1 'T' cinit
+//CHECK: `-VarTemplateSpecializationDecl {{.*}} used foo1 '__global 
long':'__global long' cinit
+template 
+T foo1 = 0;
+
 class c {
 public:
   //CHECK: `-VarDecl {{.*}} foo2 'const __global int'
@@ -30,7 +35,7 @@ struct c2 {
 
 template 
 struct x1 {
-//CHECK: -CXXMethodDecl {{.*}} operator= 'x1 &(const x1 &__private){{( 
__attribute__.*)?}} __generic'
+//CHECK: -CXXMethodDecl {{.*}} operator= 'x1 &(const x1 &){{( 
__attribute__.*)?}} __generic'
 //CHECK: -CXXMethodDecl {{.*}} operator= '__generic x1 &(const __generic 
x1 &__private){{( __attribute__.*)?}} __generic'
   x1& operator=(const x1& xx) {
 y = xx.y;
@@ -41,7 +46,7 @@ struct x1 {
 
 template 
 struct x2 {
-//CHECK: -CXXMethodDecl {{.*}} foo 'void (x1 *__private){{( 
__attribute__.*)?}} __generic'
+//CHECK: -CXXMethodDecl {{.*}} foo 'void (x1 *){{( __attribute__.*)?}} 
__generic'
 //CHECK: -CXXMethodDecl {{.*}} foo 'void (__generic x1 *__private){{( 
__attribute__.*)?}} __generic'
   void foo(x1* xx) {
 m[0] = *xx;
@@ -57,10 +62,10 @@ void bar(__global x1 *xx, __global x2 *bar) {
 template 
 class x3 : public T {
 public:
-  //CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &__private){{( 
__attribute__.*)?}} __generic'
+  //CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &){{( 
__attribute__.*)?}} __generic'
   x3(const x3 &t);
 };
-//CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &__private){{( 
__attribute__.*)?}} __generic'
+//CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &){{( 
__attribute__.*)?}} __generic'
 template 
 x3::x3(const x3

[clang] fe667e8 - [OpenCL] Fixed test for the cast operators.

2020-04-28 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-04-28T12:46:36+01:00
New Revision: fe667e8522a6be5f73b2aed1adf4ec92d0470695

URL: 
https://github.com/llvm/llvm-project/commit/fe667e8522a6be5f73b2aed1adf4ec92d0470695
DIFF: 
https://github.com/llvm/llvm-project/commit/fe667e8522a6be5f73b2aed1adf4ec92d0470695.diff

LOG: [OpenCL] Fixed test for the cast operators.

The test had unused variable because it missed to cover
case with __constant address space. This change now
completes the testing fully.

Added: 


Modified: 
clang/test/SemaOpenCLCXX/address-space-castoperators.cl

Removed: 




diff  --git a/clang/test/SemaOpenCLCXX/address-space-castoperators.cl 
b/clang/test/SemaOpenCLCXX/address-space-castoperators.cl
index d61a9a72573c..7fd7f728fda3 100644
--- a/clang/test/SemaOpenCLCXX/address-space-castoperators.cl
+++ b/clang/test/SemaOpenCLCXX/address-space-castoperators.cl
@@ -9,4 +9,9 @@ void nester_ptr() {
   gengen = static_cast(locgen); //expected-error{{static_cast from 
'__local int *__generic *' to '__generic int *__generic *' is not allowed}}
 // CHECK-NOT: AddressSpaceConversion
   gengen = reinterpret_cast(locgen); 
//expected-warning{{reinterpret_cast from '__local int *__generic *' to 
'__generic int *__generic *' changes address space of nested pointers}}
+
+  gengen = const_cast(congen); //expected-error{{const_cast from 
'__constant int *__generic *' to '__generic int *__generic *' is not allowed}}
+  gengen = static_cast(congen); //expected-error{{static_cast from 
'__constant int *__generic *' to '__generic int *__generic *' is not allowed}}
+// CHECK-NOT: AddressSpaceConversion
+  gengen = reinterpret_cast(congen); 
//expected-warning{{reinterpret_cast from '__constant int *__generic *' to 
'__generic int *__generic *' changes address space of nested pointers}}
 }



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


[clang] 3c8a4ee - [OpenCL] Remove warning for variadic macros in C++ for OpenCL.

2020-08-12 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-08-12T16:17:54+01:00
New Revision: 3c8a4ee0764cafb2ba204c7cb7d8b37e6adf72a8

URL: 
https://github.com/llvm/llvm-project/commit/3c8a4ee0764cafb2ba204c7cb7d8b37e6adf72a8
DIFF: 
https://github.com/llvm/llvm-project/commit/3c8a4ee0764cafb2ba204c7cb7d8b37e6adf72a8.diff

LOG: [OpenCL] Remove warning for variadic macros in C++ for OpenCL.

Patch by Ole Strohm (olestrohm)!

Tags: #clang

Differential Revision: https://reviews.llvm.org/D85429

Added: 


Modified: 
clang/lib/Lex/PPDirectives.cpp
clang/test/Preprocessor/macro_variadic.cl

Removed: 




diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 053ef1d2dd18..e4b901a950ae 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -2397,7 +2397,7 @@ bool Preprocessor::ReadMacroParameterList(MacroInfo *MI, 
Token &Tok) {
  diag::ext_variadic_macro);
 
   // OpenCL v1.2 s6.9.e: variadic macros are not supported.
-  if (LangOpts.OpenCL) {
+  if (LangOpts.OpenCL && !LangOpts.OpenCLCPlusPlus) {
 Diag(Tok, diag::ext_pp_opencl_variadic_macros);
   }
 

diff  --git a/clang/test/Preprocessor/macro_variadic.cl 
b/clang/test/Preprocessor/macro_variadic.cl
index cc9458da558e..e58896487121 100644
--- a/clang/test/Preprocessor/macro_variadic.cl
+++ b/clang/test/Preprocessor/macro_variadic.cl
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -verify %s -cl-std=CL1.2
 // RUN: %clang_cc1 -verify %s -pedantic -DPEDANTIC -cl-std=CL1.2
+// RUN: %clang_cc1 -verify %s -cl-std=CLC++
+// RUN: %clang_cc1 -verify %s -pedantic -cl-std=CLC++
 
 
 #define NO_VAR_FUNC(...)  5
@@ -15,6 +17,11 @@ int printf(__constant const char *st, ...);
 
 void foo() {
   NO_VAR_FUNC(1, 2, 3);
-  VAR_FUNC(1, 2, 3); //expected-error{{implicit declaration of function 'func' 
is invalid in OpenCL}}
+  VAR_FUNC(1, 2, 3);
+#if !__OPENCL_CPP_VERSION__
+// expected-error@-2{{implicit declaration of function 'func' is invalid in 
OpenCL}}
+#else
+// expected-error@-4{{use of undeclared identifier 'func'}}
+#endif
   VAR_PRINTF("%i", 1);
 }



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


[clang] a6a237f - [OpenCL] Added addrspace_cast operator in C++ mode.

2020-05-18 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-05-18T12:07:54+01:00
New Revision: a6a237f2046ad8993db30481c8b61aeb2f73a5ad

URL: 
https://github.com/llvm/llvm-project/commit/a6a237f2046ad8993db30481c8b61aeb2f73a5ad
DIFF: 
https://github.com/llvm/llvm-project/commit/a6a237f2046ad8993db30481c8b61aeb2f73a5ad.diff

LOG: [OpenCL] Added addrspace_cast operator in C++ mode.

This operator is intended for casting between
pointers to objects in different address spaces
and follows similar logic as const_cast in C++.

Tags: #clang

Differential Revision: https://reviews.llvm.org/D60193

Added: 
clang/test/CodeGenOpenCLCXX/addrspace_cast.cl
clang/test/Index/cxx.cl
clang/test/SemaOpenCLCXX/addrspace_cast.cl
clang/test/SemaOpenCLCXX/addrspace_cast_ast_dump.cl

Modified: 
clang/include/clang-c/Index.h
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/StmtNodes.td
clang/include/clang/Basic/TokenKinds.def
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/lib/AST/Expr.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/AST/ExprClassification.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/SemaCast.cpp
clang/lib/Sema/SemaExceptionSpec.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXCursor.cpp

Removed: 




diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 8e367b617bd3..3a8a1fdcae0c 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2052,58 +2052,62 @@ enum CXCursorKind {
*/
   CXCursor_CXXFunctionalCastExpr = 128,
 
+  /** OpenCL's addrspace_cast<> expression.
+   */
+  CXCursor_CXXAddrspaceCastExpr = 129,
+
   /** A C++ typeid expression (C++ [expr.typeid]).
*/
-  CXCursor_CXXTypeidExpr = 129,
+  CXCursor_CXXTypeidExpr = 130,
 
   /** [C++ 2.13.5] C++ Boolean Literal.
*/
-  CXCursor_CXXBoolLiteralExpr = 130,
+  CXCursor_CXXBoolLiteralExpr = 131,
 
   /** [C++0x 2.14.7] C++ Pointer Literal.
*/
-  CXCursor_CXXNullPtrLiteralExpr = 131,
+  CXCursor_CXXNullPtrLiteralExpr = 132,
 
   /** Represents the "this" expression in C++
*/
-  CXCursor_CXXThisExpr = 132,
+  CXCursor_CXXThisExpr = 133,
 
   /** [C++ 15] C++ Throw Expression.
*
* This handles 'throw' and 'throw' assignment-expression. When
* assignment-expression isn't present, Op will be null.
*/
-  CXCursor_CXXThrowExpr = 133,
+  CXCursor_CXXThrowExpr = 134,
 
   /** A new expression for memory allocation and constructor calls, e.g:
* "new CXXNewExpr(foo)".
*/
-  CXCursor_CXXNewExpr = 134,
+  CXCursor_CXXNewExpr = 135,
 
   /** A delete expression for memory deallocation and destructor calls,
* e.g. "delete[] pArray".
*/
-  CXCursor_CXXDeleteExpr = 135,
+  CXCursor_CXXDeleteExpr = 136,
 
   /** A unary expression. (noexcept, sizeof, or other traits)
*/
-  CXCursor_UnaryExpr = 136,
+  CXCursor_UnaryExpr = 137,
 
   /** An Objective-C string literal i.e. @"foo".
*/
-  CXCursor_ObjCStringLiteral = 137,
+  CXCursor_ObjCStringLiteral = 138,
 
   /** An Objective-C \@encode expression.
*/
-  CXCursor_ObjCEncodeExpr = 138,
+  CXCursor_ObjCEncodeExpr = 139,
 
   /** An Objective-C \@selector expression.
*/
-  CXCursor_ObjCSelectorExpr = 139,
+  CXCursor_ObjCSelectorExpr = 140,
 
   /** An Objective-C \@protocol expression.
*/
-  CXCursor_ObjCProtocolExpr = 140,
+  CXCursor_ObjCProtocolExpr = 141,
 
   /** An Objective-C "bridged" cast expression, which casts between
* Objective-C pointers and C pointers, transferring ownership in the 
process.
@@ -2112,7 +2116,7 @@ enum CXCursorKind {
*   NSString *str = (__bridge_transfer NSString *)CFCreateString();
* \endcode
*/
-  CXCursor_ObjCBridgedCastExpr = 141,
+  CXCursor_ObjCBridgedCastExpr = 142,
 
   /** Represents a C++0x pack expansion that produces a sequence of
* expressions.
@@ -2127,7 +2131,7 @@ enum CXCursorKind {
* }
* \endcode
*/
-  CXCursor_PackExpansionExpr = 142,
+  CXCursor_PackExpansionExpr = 143,
 
   /** Represents an expression that computes the length of a parameter
* pack.
@@ -2139,7 +2143,7 @@ enum CXCursorKind {
* };
* \endcode
*/
-  CXCursor_SizeOfPackExpr = 143,
+  CXCursor_SizeOfPackExpr = 144,
 
   /* Represents a C++ lambda expression that produces a local function

Re: [PATCH] D24626: [OpenCL] Diagnose assignment to dereference of half type pointer

2016-09-17 Thread Anastasia Stulova via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.

LGTM!


https://reviews.llvm.org/D24626



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


Re: [PATCH] D24666: [OpenCL] Allow half type kernel argument when cl_khr_fp16 is enabled

2016-09-17 Thread Anastasia Stulova via cfe-commits
Anastasia added inline comments.


Comment at: lib/Sema/SemaDecl.cpp:7600
@@ +7599,3 @@
+// Do not diagnose half type since it is diagnosed as invalid argument
+// type for any function eleswhere.
+if (!PT->isHalfType())

-> elsewhere


https://reviews.llvm.org/D24666



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


Re: [PATCH] D21698: [OpenCL] Allow disabling types and declarations associated with extensions

2016-09-21 Thread Anastasia Stulova via cfe-commits
Anastasia added a comment.

In https://reviews.llvm.org/D21698#546733, @yaxunl wrote:

> In https://reviews.llvm.org/D21698#540237, @Anastasia wrote:
>
> > I have made an experiment with a simple kernel:
> >
> >   void foo1(void);
> >   void foo2(void);
> >   void foo3(void);
> >   void foo4(void);
> >   void foo5(void);
> >   void foo6(void);
> >   void foo7(void);
> >   void foo8(void);
> >   void foo9(void);
> >   void foo10(void);
> >  
> >   void test(){
> > foo1();
> > foo2();
> > foo3();
> > foo4();
> > foo5();
> > foo6();
> > foo7();
> > foo8();
> > foo9();
> > foo10();
> >   }
> >   
> >
> > I am using time utility of linux to measure the compile time running Clang 
> > in CL2.0 mode and average over 100 samples. It shows me around 7% overhead 
> > with your approach.
>
>
> Since the program is very small, it is difficult to measure the compilation 
> time accurately. I compile the program 1000 times and measure its time in a 
> script:
>
>$ cat run.sh
>run() {
>i=1
>while [[ $i -le 1000 ]]; do
>  ./$1 -cc1 -emit-llvm tmp.cl
>  i=$((i+1))
>done
>}
>   
>   time -p run $1
>
>
>
> Even so, I found large variations in the measured compilation time. I ran the 
> script 10 times for clang before my change and I got the real time
>
>   real 8.96
>   real 9.01
>   real 8.99
>   real 9.07
>   real 9.03
>   real 8.99
>   real 9.03
>   real 9.01
>   real 8.99
>   real 9.01
>  
>
>
> and the average time is 9.009s.
>
> For clang after my change, I got
>
>   real 9.06
>   real 9.09
>   real 9.10
>   real 9.03
>   real 9.05
>   real 9.17
>   real 9.08
>   real 9.08
>   real 9.07
>   real 9.08
>  
>
>
> And the average time is 9.081s.
>
> The increase of compilation time is 0.8%. Considering this program consists 
> mostly of function declarations, which emphasized the cost of evaluating 
> disabled function declarations unrealistically. In real programs this 
> increment in compilation time should be even smaller.
>
> Since the increment of compilation time is less than 1% even for exaggerated 
> cases, I think it is reasonable to accept the cost for the improved 
> diagnostics for extensions.
>
> If there are concerns that the newly added diagnostics may break applications 
> which use builtin functions associated with an extension without enabling it, 
> we can make the diagnostic msg a warning which can be turned off.


Ok. Sure. I will profile a few more benchmarks and let you know.


https://reviews.llvm.org/D21698



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


Re: [PATCH] D24813: Driver: Add a test for triple with opencl environment

2016-09-26 Thread Anastasia Stulova via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM!


https://reviews.llvm.org/D24813



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


Re: [PATCH] D23712: [OpenCL] Override supported OpenCL extensions with -cl-ext option

2016-09-27 Thread Anastasia Stulova via cfe-commits
Anastasia added inline comments.


Comment at: include/clang/Basic/OpenCLOptions.h:39
@@ +38,3 @@
+
+  void set(llvm::StringRef Ext, bool Enable = true) {
+assert(!Ext.empty() && "Extension is empty.");

yaxunl wrote:
> Better add a comments for this function about its semantics, i.e., if Ext 
> does not starts with +/-, it is enabled/disabled by \p Enable, otherwise +/- 
> overrides \p Enable, since this is not obvious.
Indeed, generally it would be nice to add a comment explaining the purpose of 
this functions. I don't think the name is descriptive enough.


Comment at: include/clang/Driver/Options.td:394
@@ -393,1 +393,3 @@
   HelpText<"OpenCL only. Specify that single precision floating-point divide 
and sqrt used in the program source are correctly rounded.">;
+def cl_ext_EQ : CommaJoined<["-"], "cl-ext=">, Group, 
Flags<[CC1Option]>,
+  HelpText<"OpenCL only. Enable or disable specific OpenCL extensions 
separated by comma. Use 'all' for all extensions.">;

I would see it as cc1 option instead to avoid confusions on its intension.


Comment at: include/clang/Driver/Options.td:395
@@ -394,1 +394,3 @@
+def cl_ext_EQ : CommaJoined<["-"], "cl-ext=">, Group, 
Flags<[CC1Option]>,
+  HelpText<"OpenCL only. Enable or disable specific OpenCL extensions 
separated by comma. Use 'all' for all extensions.">;
 def client__name : JoinedOrSeparate<["-"], "client_name">;

Could we also add a short statement, that +/- are used to turn the extesions on 
and off. 


Comment at: lib/Basic/Targets.cpp:1882
@@ -1881,1 +1881,3 @@
+
+setOpenCLExtensionOpts();
   }

Is this really target specific? I feel this should rather go into common code.


https://reviews.llvm.org/D23712



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


[PATCH] [Commented On] D21698: [OpenCL] Allow disabling types and declarations associated with extensions

2016-09-30 Thread Anastasia Stulova via cfe-commits
Anastasia added a comment.

Sam, I ran a few more tests and understood that the overhead mainly comes from 
extra initialization (in Sema::Initialize()). Therefore, it's more noticeable 
on a very small kernels.  However, I agree we can probably neglect the overhead 
as it account for only a couple % of overall time max in Release mode. Sorry, 
for taking this long time.



> yaxunl wrote in DiagnosticSemaKinds.td:7998
> these two error msgs have different format.
> 
>   def err_type_requires_extension : Error<
>"use of type %0 requires %1 extension to be enabled">;
> 
> err_type_requires_extension has an extra type name argument.

I guess we could multiplex with select and pass an empty string as a first 
parameter to the diagnostic? Apart from that, the core part seems to be the 
same.

> yaxunl wrote in ParsePragma.cpp:461
> Using PointerIntPair with 2 bits requires IdentifierInfo to be aligned at 4 
> bytes, however this is not true. IdentifierInfo has no explicit alignment 
> specifier, therefore it can only hold 1 bit in PointerIntPair.

Based on its structure with having a pointer member I think it's reasonable to 
assume at least 4 bytes alignment... Although this doesn't seem to affect the 
performance anyways.

> ParsePragma.cpp:1429
>PP.Lex(Tok);
> -  if (Tok.isNot(tok::identifier)) {
> -PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_enable_disable);
> +  if (Tok.isNot(tok::identifier) && Tok.isNot(tok::kw_register)) {
> +PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_predicate) << 0;

Not clear why register keyword is here too?

> Sema.cpp:226
>   Context.getAtomicType(Context.UnsignedIntTy));
> -  addImplicitTypedef("atomic_long", 
> Context.getAtomicType(Context.LongTy));
> -  addImplicitTypedef("atomic_ulong",
> - Context.getAtomicType(Context.UnsignedLongTy));
> +  auto AtomicLongT = Context.getAtomicType(Context.LongTy);
> +  addImplicitTypedef("atomic_long", AtomicLongT);

Any reason for changing this too?

> yaxunl wrote in Sema.cpp:1558
> This function can be called grammatically to set extensions for a group of 
> image types, e.g., the extensions associated with image types. It is more 
> convenient to allow empty string here. If empty string is not allowed, it can 
> be diagnosed before calling this function.

Could we then check for an empty string ExtStr as a first function statement 
instead?

> opencl-atomics-cl20.cl:51
>  // expected-error@-28 {{use of type 'atomic_double' (aka '_Atomic(double)') 
> requires cl_khr_int64_extended_atomics extension to be enabled}}
> -// expected-error-re@-27 {{use of type 'atomic_intptr_t' (aka 
> '_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be 
> enabled}}
> -// expected-error-re@-28 {{use of type 'atomic_intptr_t' (aka 
> '_Atomic({{.+}})') requires cl_khr_int64_extended_atomics extension to be 
> enabled}}
> -// expected-error-re@-28 {{use of type 'atomic_uintptr_t' (aka 
> '_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be 
> enabled}}
> -// expected-error-re@-29 {{use of type 'atomic_uintptr_t' (aka 
> '_Atomic({{.+}})') requires cl_khr_int64_extended_atomics extension to be 
> enabled}}
> -// expected-error-re@-29 {{use of type 'atomic_size_t' (aka 
> '_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be 
> enabled}}
> -// expected-error-re@-30 {{use of type 'atomic_size_t' (aka 
> '_Atomic({{.+}})') requires cl_khr_int64_extended_atomics extension to be 
> enabled}}
> -// expected-error-re@-30 {{use of type 'atomic_ptrdiff_t' (aka 
> '_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be 
> enabled}}
> -// expected-error-re@-31 {{use of type 'atomic_ptrdiff_t' (aka 
> '_Atomic({{.+}})') requires cl_khr_int64_extended_atomics extension to be 
> enabled}}
> +#if __LP64__
> +// expected-error-re@-28 {{use of type 'atomic_intptr_t' (aka 
> '_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be 
> enabled}}

Why this change?

> extension-begin.cl:27
> +}
> +
> +#pragma OPENCL EXTENSION my_ext : disable 

Could you please add case with typedef of a type from an extensions and also 
using it with qualifiers for the better coverage.

https://reviews.llvm.org/D21698



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


[PATCH] D25123: [OpenCL] Fix bug in __builtin_astype causing invalid LLVM cast instructions

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

LGTM! Thanks!


https://reviews.llvm.org/D25123



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


[PATCH] D24715: [OpenCL] Block captured variables in dynamic parallelism - OpenCL 2.0

2016-10-04 Thread Anastasia Stulova via cfe-commits
Anastasia added a comment.



> Regarding the improvement proposed by us which "flatten" captured variables 
> into invoke_function argument list and block_literal pointer wouldn't be 
> passed as first argument(to invoke_function) anymore. The reason why it 
> doesn't require global memory management is that we can retrieve captured 
> variables with cap_num field and cap_copy_helper routine INSIDE 
> __enqueue_kernel_XXX and passed those captures as arguments to child kernel, 
> rather than saving block_literal variable globally and postpone the 
> retrieving actions until invoke_function, the child kernel body.

Just to be clear, we are now comparing the following two approaches:

(1)

  __enqueue_kernel_XXX ( ... block_literal, size ... ) { // size seems to be 
missing in the current implementation (?)
 ...
// copy block literal into accessible for enqueued kernel memory
memcpy(accessible_mem, block_literal, size); // for efficiency 
(block_literal + static_header_size) can be used instead
// activate  block_literal->invoke as a kernel
...
  }
  
  void invoke_function(block_decriptor* d){
use(d->capA, d->capB);
  }

(2)

  __enqueue_kernel_XXX ( ... block_literal ... ) {
...
// copy block literal captures into accessible for enqueued kernel memory
memcpy(accessible_mem, &(block_literal->capA), 
sizeof(block_literal->capA)); // which can be done using cap_copy_helper instead
memcpy(accessible_mem + sizeof(block_literal->capA), 
&(block_literal->capB), sizeof(block_literal->capB)); // which can be done 
using cap_copy_helper instead
// activate  block_literal->invoke as a kernel
...
  }
  
  void invoke_function(capA_t capA, capB_t capB){
use(capA, capB);
  }

From this picture I don't see how the flattening itself can help us to avoid 
using global memory. Surely in both cases the captures content will have to be 
copied into the memory accessible for the enqueued kernel (which is a global 
memory in a general case, but doesn't have to be in some cases I am guessing). 
Perhaps I am missing some extra step in the approach you are proposing. If you 
rely on the parameter passing using normal function call into the block_invoke 
then in both cases we can skip the memcpy of captures at all. Otherwise both 
appoaches will need to make a copy of the captures.

What we can improve though is avoiding extra data copy using the copy helpers 
you are proposing (this can also be achieved by calling mempy passing the 
capture offset pointer into block_literal and captures size instead of the the 
whole block_literal as highlighted above). We can also potentially avoid 
reloading of the captures in the enqueued kernel though the capture flattening, 
but this depends on the calling convention (or rather enqueueing convension I 
would say).

> About the second implementation category, which implement builtins directly 
> in compiler, we haven't spend time thinking about its detail approach. Maybe 
> we can discuss about this.

Neither did I look at it to be honest as I also find it quite difficult from 
the maintanance point of view as well as future modifications.


https://reviews.llvm.org/D24715



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


[PATCH] D24715: [OpenCL] Block captured variables in dynamic parallelism - OpenCL 2.0

2016-10-08 Thread Anastasia Stulova via cfe-commits
Anastasia added a comment.

However, it seems like we didn't provide quite complete implementation with 
respect to the captures yet as it's not possible at the moment for 
__enqueue_kernel_XXX to know the size of the captures or even the block literal 
struct itself to be able to copy the block data correctly.


https://reviews.llvm.org/D24715



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


[PATCH] D25343: [OpenCL] Mark group functions as noduplicate in opencl-c.h

2016-10-08 Thread Anastasia Stulova via cfe-commits
Anastasia added a comment.

Do you have any code example where Clang/LLVM performs wrong optimizations with 
respect to the control flow of SPMD execution?

My understanding from the earlier discussion we have had: 
https://www.mail-archive.com/cfe-commits@lists.llvm.org/msg22643.html that 
noduplicate is essentially enough for the frontend to prevent erroneous 
optimizations. Because in general compiler can't do much with unknown function 
calls.

For LLVM intrinsics it is slightly different as I can deduce from this 
discussion:http://lists.llvm.org/pipermail/llvm-dev/2015-May/085558.html . It 
seems like by default it's assumed to be side effect free and can be optimized 
in various ways.


https://reviews.llvm.org/D25343



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


[PATCH] D25335: [OpenCL] Allow partial initializer for array and struct

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

LGTM!




Comment at: test/CodeGenOpenCL/partial_initializer.cl:5
+
+// CHECK: @GA = addrspace(1) global [6 x [6 x float]] {{[[][[]}}6 x float] 
[float 1.00e+00, float 2.00e+00, float 0.00e+00, float 
0.00e+00, float 0.00e+00, float 0.00e+00],
+// CHEC:[6 x float] zeroinitializer, [6 x float] zeroinitializer, [6 x 
float] zeroinitializer, [6 x float] zeroinitializer, [6 x float] 
zeroinitializer], align 4 

These could be moved down to each member.


https://reviews.llvm.org/D25335



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


[clang] 6b1a045 - [OpenCL][SPIR-V] Test extern functions with a pointer arg.

2022-09-01 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2022-09-01T10:22:47+01:00
New Revision: 6b1a04529c8fba4019b3a7f56fe6e4938f3a188a

URL: 
https://github.com/llvm/llvm-project/commit/6b1a04529c8fba4019b3a7f56fe6e4938f3a188a
DIFF: 
https://github.com/llvm/llvm-project/commit/6b1a04529c8fba4019b3a7f56fe6e4938f3a188a.diff

LOG: [OpenCL][SPIR-V] Test extern functions with a pointer arg.

Added a test case that enhances coverage of opaque pointers
particularly for the problematic case with extern functions
for which there is no solution found for type recovery.

Differential Revision: https://reviews.llvm.org/D130768

Added: 
clang/test/CodeGenOpenCL/opaque-ptr-spirv.cl

Modified: 


Removed: 




diff  --git a/clang/test/CodeGenOpenCL/opaque-ptr-spirv.cl 
b/clang/test/CodeGenOpenCL/opaque-ptr-spirv.cl
new file mode 100644
index ..93220ef98f18
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/opaque-ptr-spirv.cl
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -o - -triple spirv64 %s | 
FileCheck %s
+
+// Check that we have a way to recover pointer
+// types for extern function prototypes (see PR56660).
+extern void foo(global int * ptr);
+kernel void k(global int * ptr) {
+  foo(ptr);
+}
+//CHECK: define spir_kernel void @k(i32 {{.*}}*
+//CHECK: declare spir_func void @foo(i32 {{.*}}*



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


[clang] b510e01 - [OpenCL][NFC] Refactors lang version check in test.

2021-07-22 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-07-22T16:47:38+01:00
New Revision: b510e0127da38d47b9224b082842e827c04947a8

URL: 
https://github.com/llvm/llvm-project/commit/b510e0127da38d47b9224b082842e827c04947a8
DIFF: 
https://github.com/llvm/llvm-project/commit/b510e0127da38d47b9224b082842e827c04947a8.diff

LOG: [OpenCL][NFC] Refactors lang version check in test.

Fixed test to use predefined version marco instead
of passing extra macro in the command line.

Patch by Topotuna (Justas Janickas)!

Differential Revision: https://reviews.llvm.org/D106254

Added: 


Modified: 
clang/test/SemaOpenCL/null_literal.cl

Removed: 




diff  --git a/clang/test/SemaOpenCL/null_literal.cl 
b/clang/test/SemaOpenCL/null_literal.cl
index fb0f938d5952a..e84228a06fc41 100644
--- a/clang/test/SemaOpenCL/null_literal.cl
+++ b/clang/test/SemaOpenCL/null_literal.cl
@@ -1,5 +1,5 @@
 // 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)
 
@@ -13,7 +13,7 @@ constant int* ptr3 = NULL;
 
 constant int* ptr4 = (global void*)0; // expected-error{{initializing 
'__constant int *__private' with an expression of type '__global void *' 
changes address space of pointer}}
 
-#ifdef CL20
+#if __OPENCL_C_VERSION__ == CL_VERSION_2_0
 // Accept explicitly pointer to generic address space in OpenCL v2.0.
 global int* ptr5 = (generic void*)0;
 #endif



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


  1   2   3   4   5   6   7   >