[PATCH] D43783: [OpenCL] Remove block invoke function from emitted block literal struct

2018-08-17 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

Sorry for digging up an old commit...

Apparently this broke block arguments, e.g. the following test case:

  int foo(int (^ bl)(void)) {
return bl();
  }
  
  int get21() {
return foo(^{return 21;});
  }
  
  int get42() {
return foo(^{return 42;});
  }

In particular, the VarDecl that `getBlockExpr()` sees doesn't have an 
initializer when the called block comes from an argument (causing clang to 
crash).


Repository:
  rC Clang

https://reviews.llvm.org/D43783



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


[PATCH] D50738: Remove vestiges of configure buildsystem

2018-08-23 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: CMakeLists.txt:288
 
-if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
-  message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite 
"
-"the makefiles distributed with LLVM. Please create a directory and run cmake "
+if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
+  message(FATAL_ERROR "In-source builds are not allowed. "

The `NOT MSVC_IDE` condition is still present in llvm's `CMakeLists.txt`, at 
least in r340526 (line 230), so not sure if we should remove it here?


Repository:
  rC Clang

https://reviews.llvm.org/D50738



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


[PATCH] D46022: [OpenCL] Restrict various keywords in OpenCL C++ mode

2018-05-09 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC331874: [OpenCL] Restrict various keywords in OpenCL C++ 
mode (authored by svenvh, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D46022?vs=144745&id=145904#toc

Repository:
  rC Clang

https://reviews.llvm.org/D46022

Files:
  include/clang/Basic/DiagnosticCommonKinds.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TokenKinds.def
  lib/Basic/IdentifierTable.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Parse/ParseDecl.cpp
  lib/Sema/SemaCast.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExprCXX.cpp
  test/Parser/opencl-cl20.cl
  test/Parser/opencl-cxx-keywords.cl
  test/Parser/opencl-storage-class.cl
  test/SemaOpenCL/storageclass.cl
  test/SemaOpenCLCXX/restricted.cl

Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -8609,7 +8609,8 @@
 
 // OpenCL Section 6.8.g
 def err_opencl_unknown_type_specifier : Error<
-  "OpenCL version %0 does not support the '%1' %select{type qualifier|storage class specifier}2">;
+  "OpenCL %select{C|C++}0 version %1 does not support the '%2' "
+  "%select{type qualifier|storage class specifier}3">;
 
 // OpenCL v2.0 s6.12.5 Blocks restrictions
 def err_opencl_block_storage_type : Error<
Index: include/clang/Basic/DiagnosticParseKinds.td
===
--- include/clang/Basic/DiagnosticParseKinds.td
+++ include/clang/Basic/DiagnosticParseKinds.td
@@ -1078,6 +1078,8 @@
 // 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<
Index: include/clang/Basic/TokenKinds.def
===
--- include/clang/Basic/TokenKinds.def
+++ include/clang/Basic/TokenKinds.def
@@ -249,8 +249,10 @@
 //   KEYMS- This is a keyword if Microsoft extensions are enabled
 //   KEYNOMS18 - This is a keyword that must never be enabled under
 //   MSVC <= v18.
-//   KEYOPENCL  - This is a keyword in OpenCL
-//   KEYNOOPENCL  - This is a keyword that is not supported in OpenCL
+//   KEYOPENCLC   - This is a keyword in OpenCL C
+//   KEYOPENCLCXX - This is a keyword in OpenCL C++
+//   KEYNOOPENCL  - This is a keyword that is not supported in OpenCL C
+//  nor in OpenCL C++.
 //   KEYALTIVEC - This is a keyword in AltiVec
 //   KEYZVECTOR - This is a keyword for the System z vector extensions,
 //which are heavily based on AltiVec
@@ -525,36 +527,36 @@
 KEYWORD(__super , KEYMS)
 
 // OpenCL address space qualifiers
-KEYWORD(__global, KEYOPENCL)
-KEYWORD(__local , KEYOPENCL)
-KEYWORD(__constant  , KEYOPENCL)
-KEYWORD(__private   , KEYOPENCL)
-KEYWORD(__generic   , KEYOPENCL)
-ALIAS("global", __global, KEYOPENCL)
-ALIAS("local", __local  , KEYOPENCL)
-ALIAS("constant", __constant, KEYOPENCL)
-ALIAS("private", __private  , KEYOPENCL)
-ALIAS("generic", __generic  , KEYOPENCL)
+KEYWORD(__global, KEYOPENCLC | KEYOPENCLCXX)
+KEYWORD(__local , KEYOPENCLC | KEYOPENCLCXX)
+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("private", __private  , KEYOPENCLC)
+ALIAS("generic", __generic  , KEYOPENCLC)
 // OpenCL function qualifiers
-KEYWORD(__kernel, KEYOPENCL)
-ALIAS("kernel", __kernel, KEYOPENCL)
+KEYWORD(__kernel, KEYOPENCLC | KEYOPENCLCXX)
+ALIAS("kernel", __kernel, KEYOPENCLC | KEYOPENCLCXX)
 // OpenCL access qualifiers
-KEYWORD(__read_only , KEYOPENCL)
-KEYWORD(__write_only, KEYOPENCL)
-KEYWORD(__read_write, KEYOPENCL)
-ALIAS("read_only", __read_only  , KEYOPENCL)
-ALIAS("write_only", __write_only, KEYOPENCL)
-ALIAS("read_write", __read_write, KEYOPENCL)
+KEYWORD(__read_only , KEYOPENCLC | KEYOPENCLCXX)
+KEYWORD(__write_only, KEYOPENCLC | KEYOPENCLCXX)
+KEYWORD(__read_write, KEYOPENCLC | KEYOPENCLCXX)
+ALIAS("read_only", __read_only  , KEYOPENCLC | KEYOPENCLCXX)
+ALIAS("write_only", __write_only, KEYOPENCLC | KEYOPENCLCXX)
+ALIAS("rea

[PATCH] D46651: [OpenCL] Support placement new/delete in Sema

2018-05-09 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added reviewers: yaxunl, Anastasia.
Herald added a subscriber: cfe-commits.

Stop crashing on placement new/delete in OpenCL C++ mode, and reject
non-placement new/delete with a diagnostic instead of a crash.


Repository:
  rC Clang

https://reviews.llvm.org/D46651

Files:
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaType.cpp
  test/SemaOpenCLCXX/newdelete.cl

Index: test/SemaOpenCLCXX/newdelete.cl
===
--- /dev/null
+++ test/SemaOpenCLCXX/newdelete.cl
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -verify -fsyntax-only
+
+class A {
+  public:
+  A() : x(21) {}
+  int x;
+};
+
+typedef __SIZE_TYPE__ size_t;
+void *operator new(size_t _s, void *ptr) noexcept {
+  return ptr;
+}
+
+void *operator new[](size_t _s, void *ptr) noexcept {
+  return ptr;
+}
+
+// Test that only placement new and delete are available.
+void test_new_delete(void *buffer, A **a) {
+  *a = new A; // expected-error {{'non-placement new/delete' is not supported in OpenCL C++}}
+  delete a;   // expected-error {{'delete' is not supported in OpenCL C++}}
+
+  a = new A[20]; // expected-error {{'non-placement new/delete' is not supported in OpenCL C++}}
+  delete[] a;// expected-error {{'delete' is not supported in OpenCL C++}}
+
+  // Placement new is supported.
+  *a = new (buffer) A;
+
+  // Placement new is supported.
+  *a = new (buffer) A[30];
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -7137,8 +7137,9 @@
   // The default address space name for arguments to a function in a
   // program, or local variables of a function is __private. All function
   // arguments shall be in the __private address space.
-  if (State.getSema().getLangOpts().OpenCLVersion <= 120) {
-  ImpAddr = LangAS::opencl_private;
+  if (State.getSema().getLangOpts().OpenCLVersion <= 120 &&
+  !State.getSema().getLangOpts().OpenCLCPlusPlus) {
+ImpAddr = LangAS::opencl_private;
   } else {
 // If address space is not set, OpenCL 2.0 defines non private default
 // address spaces for some cases:
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -2019,6 +2019,15 @@
 
 if (!AllPlaceArgs.empty())
   PlacementArgs = AllPlaceArgs;
+else {
+  // OpenCL C++ 1.0 s2.9: non-placement new and delete operators are
+  // not supported.
+  if (getLangOpts().OpenCLCPlusPlus) {
+Diag(StartLoc, diag::err_openclcxx_not_supported)
+<< "non-placement new/delete";
+return ExprError();
+  }
+}
 
 // FIXME: This is wrong: PlacementArgs misses out the first (size) argument.
 DiagnoseSentinelCalls(OperatorNew, PlacementLParen, PlacementArgs);
@@ -2146,7 +2155,8 @@
   else if (AllocType->isVariablyModifiedType())
 return Diag(Loc, diag::err_variably_modified_new_type)
  << AllocType;
-  else if (AllocType.getAddressSpace() != LangAS::Default)
+  else if (AllocType.getAddressSpace() != LangAS::Default &&
+  !getLangOpts().OpenCLCPlusPlus)
 return Diag(Loc, diag::err_address_space_qualified_new)
   << AllocType.getUnqualifiedType()
   << AllocType.getQualifiers().getAddressSpaceAttributePrintValue();
@@ -3157,6 +3167,11 @@
   bool ArrayFormAsWritten = ArrayForm;
   bool UsualArrayDeleteWantsSize = false;
 
+  if (getLangOpts().OpenCLCPlusPlus) {
+Diag(StartLoc, diag::err_openclcxx_not_supported) << "delete";
+return ExprError();
+  }
+
   if (!Ex.get()->isTypeDependent()) {
 // Perform lvalue-to-rvalue cast, if needed.
 Ex = DefaultLvalueConversion(Ex.get());
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -12981,6 +12981,18 @@
 diag::err_operator_new_delete_dependent_result_type)
 << FnDecl->getDeclName() << ExpectedResultType;
 
+  // OpenCL C++: ignore the address space as the operator is valid on any
+  // address space.
+  if (SemaRef.getLangOpts().OpenCLCPlusPlus) {
+if (auto *PtrTy = ResultType.getTypePtr()->getAs()) {
+  QualType PteeTy = PtrTy->getPointeeType();
+  Qualifiers Quals = PteeTy.getQualifiers();
+  Quals.removeAddressSpace();
+  ResultType = SemaRef.Context.getQualifiedType(PteeTy.getUnqualifiedType(), Quals);
+  ResultType = SemaRef.Context.getPointerType(ResultType);
+}
+  }
+
   // Check that the result type is what we expect.
   if (SemaRef.Context.getCanonicalType(ResultType) != ExpectedResultType)
 return SemaRef.Diag(FnDecl->getLocation(),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/

[PATCH] D46651: [OpenCL] Support placement new/delete in Sema

2018-05-11 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: lib/Sema/SemaExprCXX.cpp:2030
+  }
+}
 

rjmccall wrote:
> I think a better interpretation of this rule would be to just error on 
> attempts to use the standard non-placement operator new/delete instead of 
> trying to outlaw the operator declarations.  For example, I don't know why a 
> user-defined non-global operator new would be problematic.
Good point, I have raised this with Khronos, so I will hold this off until we 
have clarification.


Repository:
  rC Clang

https://reviews.llvm.org/D46651



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


[PATCH] D51544: [OpenCL] Split opencl-c.h header

2018-09-04 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: lib/Headers/opencl-c-common.h:9
+//===--===//
+
+#ifndef __OPENCL_C_COMMON_H__

Would it be worth having a brief explanation here about what is supposed to go 
in this file?  Although that merely repeats what's already in opencl-c.h of 
course.

Or perhaps you could make the description on line 1 more specific to each file.



Comment at: lib/Headers/opencl-c.h:23
+///
+///   3. Functions which which satisfy (2), but require fp16 or fp64 support
+///  should go into opencl-c-fp16.h and opencl-c-fp64.h.

nitpick: double "which"


Repository:
  rC Clang

https://reviews.llvm.org/D51544



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


[PATCH] D50104: [OpenCL] Always emit alloca in entry block for enqueue_kernel builtin

2018-08-01 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

You'll probably also need to update 
`test/CodeGenOpenCL/cl20-device-side-enqueue.cl`; please verify with make/ninja 
`check-clang`.


https://reviews.llvm.org/D50104



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


[PATCH] D50104: [OpenCL] Always emit alloca in entry block for enqueue_kernel builtin

2018-08-02 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh accepted this revision.
svenvh added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


https://reviews.llvm.org/D50104



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


[PATCH] D33989: [OpenCL] Allow targets to select address space per type

2017-06-07 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.

Generalize getOpenCLImageAddrSpace into getOpenCLTypeAddrSpace, such
that targets can select the address space per type.

No functional changes intended.  In particular, this is already
covered by test/CodeGenOpenCL/opencl_types.cl .

Patch by Simon Perretta.


https://reviews.llvm.org/D33989

Files:
  include/clang/Basic/TargetInfo.h
  lib/AST/ASTContext.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGOpenCLRuntime.cpp

Index: lib/CodeGen/CGOpenCLRuntime.cpp
===
--- lib/CodeGen/CGOpenCLRuntime.cpp
+++ lib/CodeGen/CGOpenCLRuntime.cpp
@@ -35,32 +35,39 @@
  "Not an OpenCL specific type!");
 
   llvm::LLVMContext& Ctx = CGM.getLLVMContext();
-  uint32_t ImgAddrSpc = CGM.getContext().getTargetAddressSpace(
-CGM.getTarget().getOpenCLImageAddrSpace());
   switch (cast(T)->getKind()) {
   default:
 llvm_unreachable("Unexpected opencl builtin type!");
 return nullptr;
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
   case BuiltinType::Id: \
 return llvm::PointerType::get( \
 llvm::StructType::create(Ctx, "opencl." #ImgType "_" #Suffix "_t"), \
-ImgAddrSpc);
+CGM.getContext().getTargetAddressSpace( \
+CGM.getTarget().getOpenCLTypeAddrSpace(BuiltinType::Id)));
 #include "clang/Basic/OpenCLImageTypes.def"
   case BuiltinType::OCLSampler:
 return getSamplerType();
   case BuiltinType::OCLEvent:
-return llvm::PointerType::get(llvm::StructType::create(
-   Ctx, "opencl.event_t"), 0);
+return llvm::PointerType::get(
+llvm::StructType::create(Ctx, "opencl.event_t"),
+CGM.getContext().getTargetAddressSpace(
+CGM.getTarget().getOpenCLTypeAddrSpace(BuiltinType::OCLEvent)));
   case BuiltinType::OCLClkEvent:
 return llvm::PointerType::get(
-llvm::StructType::create(Ctx, "opencl.clk_event_t"), 0);
+llvm::StructType::create(Ctx, "opencl.clk_event_t"),
+CGM.getContext().getTargetAddressSpace(
+CGM.getTarget().getOpenCLTypeAddrSpace(BuiltinType::OCLClkEvent)));
   case BuiltinType::OCLQueue:
 return llvm::PointerType::get(
-llvm::StructType::create(Ctx, "opencl.queue_t"), 0);
+llvm::StructType::create(Ctx, "opencl.queue_t"),
+CGM.getContext().getTargetAddressSpace(
+CGM.getTarget().getOpenCLTypeAddrSpace(BuiltinType::OCLQueue)));
   case BuiltinType::OCLReserveID:
 return llvm::PointerType::get(
-llvm::StructType::create(Ctx, "opencl.reserve_id_t"), 0);
+llvm::StructType::create(Ctx, "opencl.reserve_id_t"),
+CGM.getContext().getTargetAddressSpace(
+CGM.getTarget().getOpenCLTypeAddrSpace(BuiltinType::OCLReserveID)));
   }
 }
 
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -2364,8 +2364,17 @@
 }
   }
 
-  LangAS::ID getOpenCLImageAddrSpace() const override {
+  virtual LangAS::ID
+  getOpenCLTypeAddrSpace(BuiltinType::Kind K) const override {
+switch (K) {
+#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   \
+  case BuiltinType::Id:\
 return LangAS::opencl_constant;
+#include "clang/Basic/OpenCLImageTypes.def"
+
+default:
+  return LangAS::Default;
+}
   }
 
   /// \returns Target specific vtbl ptr address space.
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -1624,6 +1624,7 @@
   uint64_t Width = 0;
   unsigned Align = 8;
   bool AlignIsRequired = false;
+  unsigned AS = 0;
   switch (T->getTypeClass()) {
 #define TYPE(Class, Base)
 #define ABSTRACT_TYPE(Class, Base)
@@ -1771,7 +1772,7 @@
   Align = Target->getPointerAlign(0);
   break;
 case BuiltinType::OCLSampler: {
-  auto AS = getTargetAddressSpace(LangAS::opencl_constant);
+  AS = getTargetAddressSpace(LangAS::opencl_constant);
   Width = Target->getPointerWidth(AS);
   Align = Target->getPointerAlign(AS);
   break;
@@ -1785,10 +1786,10 @@
   Align = Target->getPointerAlign(0);
   break;
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
-case BuiltinType::Id:
+case BuiltinType::Id: \
+  AS = getTargetAddressSpace(Target->getOpenCLTypeAddrSpace(BuiltinType::Id));
 #include "clang/Basic/OpenCLImageTypes.def"
   {
-auto AS = getTargetAddressSpace(Target->getOpenCLImageAddrSpace());
 Width = Target->getPointerWidth(AS);
 Align = Target->getPointerAlign(AS);
   }
@@ -1799,24 +1800,22 @@
 Align = Target->getPointerAlign(0);
 break;
   case Type::BlockPointer: {
-unsigned AS = getTargetAddressSpace(
-cast(T)->getPointeeType());
+AS = getTargetAddressSpace(cast(T)->getPointeeType());
 Width = Targ

[PATCH] D34024: [OpenCL] Diagnose scoped address-space qualified variables

2017-06-08 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.

Variables qualified with the local or const address space may only be
declared in the outermost scope of a kernel.

Patch by Simon Perretta.


https://reviews.llvm.org/D34024

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


Index: test/SemaOpenCL/storageclass.cl
===
--- test/SemaOpenCL/storageclass.cl
+++ test/SemaOpenCL/storageclass.cl
@@ -47,3 +47,10 @@
   static int L7 = 0; // expected-error{{variables in function scope cannot 
be declared static}}
   static int L8; // expected-error{{variables in function scope cannot 
be declared static}}
 }
+
+kernel void invalidScope() {
+  if (true) {
+local int lInt; // expected-error {{variables in the local address space 
can only be declared in the outermost scope of a kernel function}}
+constant int cInt = 42; // expected-error {{variables in the constant 
address space can only be declared in the outermost scope of a kernel function}}
+  }
+}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -7260,11 +7260,11 @@
 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 @@
   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;
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -8311,6 +8311,9 @@
   "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<


Index: test/SemaOpenCL/storageclass.cl
===
--- test/SemaOpenCL/storageclass.cl
+++ test/SemaOpenCL/storageclass.cl
@@ -47,3 +47,10 @@
   static int L7 = 0; // expected-error{{variables in function scope cannot be declared static}}
   static int L8; // expected-error{{variables in function scope cannot be declared static}}
 }
+
+kernel void invalidScope() {
+  if (true) {
+local int lInt; // expected-error {{variables in the local address space can only be declared in the outermost scope of a kernel function}}
+constant int cInt = 42; // expected-error {{variables in the constant address space can only be declared in the outermost scope of a kernel function}}
+  }
+}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -7260,11 +7260,11 @@
 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(

[PATCH] D34031: [OpenCL] Diagnose some reserved types

2017-06-08 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.

Catch uses of the 'long long', 'unsigned long long', and 'long double'
reserved types.

Remove use of 'long long' in test/Misc/languageOptsOpenCL.cl; it
shouldn't have been added there in the first place as the OpenCL
specification explicitly forbids it in s6.1.4.

Initial patch by Simon Perretta.


https://reviews.llvm.org/D34031

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaType.cpp
  test/Misc/languageOptsOpenCL.cl
  test/SemaOpenCL/unsupported.cl


Index: test/SemaOpenCL/unsupported.cl
===
--- test/SemaOpenCL/unsupported.cl
+++ test/SemaOpenCL/unsupported.cl
@@ -11,3 +11,10 @@
 void no_logxor(int n) {
   int logxor = n ^^ n; // expected-error {{^^ is a reserved operator in 
OpenCL}}
 }
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+kernel void no_long_double(global long double *n) {} // expected-error {{'long 
double' is a reserved type in OpenCL}}
+
+kernel void no_long_long(global long long *n) {} // expected-error {{'long 
long' is a reserved type in OpenCL}}
+kernel void no_unsigned_long_long(global unsigned long long *n) {} // 
expected-error {{'unsigned long long' is a reserved type in OpenCL}}
Index: test/Misc/languageOptsOpenCL.cl
===
--- test/Misc/languageOptsOpenCL.cl
+++ test/Misc/languageOptsOpenCL.cl
@@ -8,14 +8,12 @@
   int v1[(__alignof(int)== 4) - 1];
   int v2[(sizeof(long) == 8) - 1];
   int v3[(__alignof(long)== 8) - 1];
-  int v4[(sizeof(long long) == 16) - 1];
-  int v5[(__alignof(long long)== 16) - 1];
-  int v6[(sizeof(float) == 4) - 1];
-  int v7[(__alignof(float)== 4) - 1];
+  int v4[(sizeof(float) == 4) - 1];
+  int v5[(__alignof(float)== 4) - 1];
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
-  int v8[(sizeof(double) == 8) - 1];
-  int v9[(__alignof(double)== 8) - 1];
+  int v6[(sizeof(double) == 8) - 1];
+  int v7[(__alignof(double)== 8) - 1];
 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
-  int v10[(sizeof(half) == 2) - 1];
-  int v11[(__alignof(half) == 2) - 1];
+  int v8[(sizeof(half) == 2) - 1];
+  int v9[(__alignof(half) == 2) - 1];
 }
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -1363,6 +1363,11 @@
   else
 S.Diag(DS.getTypeSpecWidthLoc(), diag::ext_c99_longlong);
 }
+else if (S.getLangOpts().OpenCL) {
+  // OpenCL v2.0 s6.1.4: 'long long' is a reserved data type.
+  S.Diag(DS.getTypeSpecWidthLoc(), diag::err_ocl_type_reserved)
+<< "long long";
+}
 break;
   }
 } else {
@@ -1382,6 +1387,11 @@
   else
 S.Diag(DS.getTypeSpecWidthLoc(), diag::ext_c99_longlong);
 }
+else if (S.getLangOpts().OpenCL) {
+  // OpenCL v2.0 s6.1.4: 'unsigned long long' is a reserved data type.
+  S.Diag(DS.getTypeSpecWidthLoc(), diag::err_ocl_type_reserved)
+<< "unsigned long long";
+}
 break;
   }
 }
@@ -1399,9 +1409,14 @@
   case DeclSpec::TST_half: Result = Context.HalfTy; break;
   case DeclSpec::TST_float: Result = Context.FloatTy; break;
   case DeclSpec::TST_double:
-if (DS.getTypeSpecWidth() == DeclSpec::TSW_long)
+if (DS.getTypeSpecWidth() == DeclSpec::TSW_long) {
   Result = Context.LongDoubleTy;
-else
+  if (S.getLangOpts().OpenCL) {
+// OpenCL v2.0 s6.1.4: 'long double' is a reserved data type.
+S.Diag(DS.getTypeSpecWidthLoc(), diag::err_ocl_type_reserved)
+  << "long double";
+  }
+} else
   Result = Context.DoubleTy;
 break;
   case DeclSpec::TST_float128:
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -8156,6 +8156,8 @@
   "feature, not permitted in C++">;
 def err_type_unsupported : Error<
   "%0 is not supported on this target">;
+def err_ocl_type_reserved : Error<
+  "'%0' is a reserved type in OpenCL">;
 def err_nsconsumed_attribute_mismatch : Error<
   "overriding method has mismatched ns_consumed attribute on its"
   " parameter">;


Index: test/SemaOpenCL/unsupported.cl
===
--- test/SemaOpenCL/unsupported.cl
+++ test/SemaOpenCL/unsupported.cl
@@ -11,3 +11,10 @@
 void no_logxor(int n) {
   int logxor = n ^^ n; // expected-error {{^^ is a reserved operator in OpenCL}}
 }
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+kernel void no_long_double(global long double *n) {} // expected-error {{'long double' is a reserved type in OpenCL}}
+
+kernel void no_long_long(global long long *n) {} // expected-error {{'long long' is a reserved type in OpenCL}}
+kernel void no_unsigned_long_long(global unsigned long long *n) {} // expecte

[PATCH] D33598: [libclang] [OpenCL] Expose CIndex functions for typedef and address space

2017-06-08 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL304978: [libclang] Expose typedef and address space 
functions (authored by svenvh).

Changed prior to commit:
  https://reviews.llvm.org/D33598?vs=100404&id=101918#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33598

Files:
  cfe/trunk/bindings/python/clang/cindex.py
  cfe/trunk/bindings/python/tests/cindex/test_type.py
  cfe/trunk/include/clang-c/Index.h
  cfe/trunk/tools/libclang/CXType.cpp
  cfe/trunk/tools/libclang/libclang.exports

Index: cfe/trunk/include/clang-c/Index.h
===
--- cfe/trunk/include/clang-c/Index.h
+++ cfe/trunk/include/clang-c/Index.h
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 41
+#define CINDEX_VERSION_MINOR 42
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -3417,6 +3417,16 @@
 CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
 
 /**
+ * \brief Returns the address space of the given type.
+ */
+CINDEX_LINKAGE unsigned clang_getAddressSpace(CXType T);
+
+/**
+ * \brief Returns the typedef name of the given type.
+ */
+CINDEX_LINKAGE CXString clang_getTypedefName(CXType CT);
+
+/**
  * \brief For pointer types, returns the type of the pointee.
  */
 CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
Index: cfe/trunk/tools/libclang/libclang.exports
===
--- cfe/trunk/tools/libclang/libclang.exports
+++ cfe/trunk/tools/libclang/libclang.exports
@@ -147,6 +147,7 @@
 clang_findReferencesInFileWithBlock
 clang_formatDiagnostic
 clang_free
+clang_getAddressSpace
 clang_getAllSkippedRanges
 clang_getArgType
 clang_getArrayElementType
@@ -259,6 +260,7 @@
 clang_getTypeKindSpelling
 clang_getTypeSpelling
 clang_getTypedefDeclUnderlyingType
+clang_getTypedefName
 clang_hashCursor
 clang_indexLoc_getCXSourceLocation
 clang_indexLoc_getFileLocation
Index: cfe/trunk/tools/libclang/CXType.cpp
===
--- cfe/trunk/tools/libclang/CXType.cpp
+++ cfe/trunk/tools/libclang/CXType.cpp
@@ -21,6 +21,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/Type.h"
+#include "clang/Basic/AddressSpaces.h"
 #include "clang/Frontend/ASTUnit.h"
 
 using namespace clang;
@@ -394,6 +395,27 @@
   return T.isLocalRestrictQualified();
 }
 
+unsigned clang_getAddressSpace(CXType CT) {
+  QualType T = GetQualType(CT);
+
+  // For non language-specific address space, use separate helper function.
+  if (T.getAddressSpace() >= LangAS::FirstTargetAddressSpace) {
+return T.getQualifiers().getAddressSpaceAttributePrintValue();
+  }
+  return T.getAddressSpace();
+}
+
+CXString clang_getTypedefName(CXType CT) {
+  QualType T = GetQualType(CT);
+  const TypedefType *TT = T->getAs();
+  if (TT) {
+TypedefNameDecl *TD = TT->getDecl();
+if (TD)
+  return cxstring::createDup(TD->getNameAsString().c_str());
+  }
+  return cxstring::createEmpty();
+}
+
 CXType clang_getPointeeType(CXType CT) {
   QualType T = GetQualType(CT);
   const Type *TP = T.getTypePtrOrNull();
Index: cfe/trunk/bindings/python/clang/cindex.py
===
--- cfe/trunk/bindings/python/clang/cindex.py
+++ cfe/trunk/bindings/python/clang/cindex.py
@@ -2162,6 +2162,12 @@
 
 return conf.lib.clang_isFunctionTypeVariadic(self)
 
+def get_address_space(self):
+return conf.lib.clang_getAddressSpace(self)
+
+def get_typedef_name(self):
+return conf.lib.clang_getTypedefName(self)
+
 def is_pod(self):
 """Determine whether this Type represents plain old data (POD)."""
 return conf.lib.clang_isPODType(self)
@@ -3665,6 +3671,11 @@
Type,
Type.from_result),
 
+  ("clang_getTypedefName",
+   [Type],
+   _CXString,
+   _CXString.from_result),
+
   ("clang_getTypeKindSpelling",
[c_uint],
_CXString,
Index: cfe/trunk/bindings/python/tests/cindex/test_type.py
===
--- cfe/trunk/bindings/python/tests/cindex/test_type.py
+++ cfe/trunk/bindings/python/tests/cindex/test_type.py
@@ -37,44 +37,52 @@
 assert not fields[0].type.is_const_qualified()
 assert fields[0].type.kind == TypeKind.INT
 assert fields[0].type.get_canonical().kind == TypeKind.INT
+assert fields[0].type.get_typedef_name() == ''
 
 assert fields[1].spelling == 'b'
 assert not fields[1].type.is_const_qualified()
 assert fields[1].type.kind == TypeKind.TYPEDEF
 assert fields[1].type.get_canonical().kind == TypeKind.INT
 assert fields[1].type.get_declaration().spelling == 'I'
+assert fields[1].type.get_typedef_name() == 'I'
 
 assert fields[2].spelling == 'c'
 assert not field

[PATCH] D46651: [OpenCL] Support new/delete in Sema

2018-06-08 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh updated this revision to Diff 150535.
svenvh retitled this revision from "[OpenCL] Support placement new/delete in 
Sema" to "[OpenCL] Support new/delete in Sema".
svenvh edited the summary of this revision.
svenvh added a comment.

Relaxed the new/delete restrictions following the Khronos advice.


https://reviews.llvm.org/D46651

Files:
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaType.cpp
  test/SemaOpenCLCXX/newdelete.cl

Index: test/SemaOpenCLCXX/newdelete.cl
===
--- /dev/null
+++ test/SemaOpenCLCXX/newdelete.cl
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -verify -fsyntax-only
+
+class A {
+  public:
+  A() : x(21) {}
+  int x;
+};
+
+typedef __SIZE_TYPE__ size_t;
+
+class B {
+  public:
+  B() : bx(42) {}
+  void *operator new(size_t);
+  void operator delete(void *ptr);
+  int bx;
+};
+
+// There are no global user-defined new operators at this point. Test that clang
+// rejects these gracefully.
+void test_default_new_delete(void *buffer, A **pa) {
+  A *a = new A; // expected-error {{'default new' is not supported in OpenCL C++}}
+  delete a; // expected-error {{'default delete' is not supported in OpenCL C++}}
+  *pa = new (buffer) A; // expected-error {{'default new' is not supported in OpenCL C++}}
+}
+
+// expected-note@+1 {{candidate function not viable: requires 2 arguments, but 1 was provided}}
+void *operator new(size_t _s, void *ptr) noexcept {
+  return ptr;
+}
+
+// expected-note@+1 {{candidate function not viable: requires 2 arguments, but 1 was provided}}
+void *operator new[](size_t _s, void *ptr) noexcept {
+  return ptr;
+}
+
+void test_new_delete(void *buffer, A **a, B **b) {
+  *a = new A; // expected-error {{no matching function for call to 'operator new'}}
+  delete a;   // expected-error {{'default delete' is not supported in OpenCL C++}}
+
+  *a = new A[20]; // expected-error {{no matching function for call to 'operator new[]'}}
+  delete[] *a;// expected-error {{'default delete' is not supported in OpenCL C++}}
+
+  // User-defined placement new is supported.
+  *a = new (buffer) A;
+
+  // User-defined placement new[] is supported.
+  *a = new (buffer) A[30];
+
+  // User-defined new is supported.
+  *b = new B;
+
+  // User-defined delete is supported.
+  delete *b;
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -7137,8 +7137,9 @@
   // The default address space name for arguments to a function in a
   // program, or local variables of a function is __private. All function
   // arguments shall be in the __private address space.
-  if (State.getSema().getLangOpts().OpenCLVersion <= 120) {
-  ImpAddr = LangAS::opencl_private;
+  if (State.getSema().getLangOpts().OpenCLVersion <= 120 &&
+  !State.getSema().getLangOpts().OpenCLCPlusPlus) {
+ImpAddr = LangAS::opencl_private;
   } else {
 // If address space is not set, OpenCL 2.0 defines non private default
 // address spaces for some cases:
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -2146,7 +2146,8 @@
   else if (AllocType->isVariablyModifiedType())
 return Diag(Loc, diag::err_variably_modified_new_type)
  << AllocType;
-  else if (AllocType.getAddressSpace() != LangAS::Default)
+  else if (AllocType.getAddressSpace() != LangAS::Default &&
+  !getLangOpts().OpenCLCPlusPlus)
 return Diag(Loc, diag::err_address_space_qualified_new)
   << AllocType.getUnqualifiedType()
   << AllocType.getQualifiers().getAddressSpaceAttributePrintValue();
@@ -2362,6 +2363,11 @@
   LookupQualifiedName(R, Context.getTranslationUnitDecl());
 }
 
+if (getLangOpts().OpenCLCPlusPlus && R.empty()) {
+  Diag(StartLoc, diag::err_openclcxx_not_supported) << "default new";
+  return true;
+}
+
 assert(!R.empty() && "implicitly declared allocation functions not found");
 assert(!R.isAmbiguous() && "global allocation functions are ambiguous");
 
@@ -2597,6 +2603,11 @@
   if (GlobalNewDeleteDeclared)
 return;
 
+  // OpenCL C++ 1.0 s2.9: the implicitly declared new and delete operators
+  // are not supported.
+  if (getLangOpts().OpenCLCPlusPlus)
+return;
+
   // C++ [basic.std.dynamic]p2:
   //   [...] The following allocation and deallocation functions (18.4) are
   //   implicitly declared in global scope in each translation unit of a
@@ -3230,7 +3241,8 @@
 QualType Pointee = Type->getAs()->getPointeeType();
 QualType PointeeElem = Context.getBaseElementType(Pointee);
 
-if (Pointee.getAddressSpace() != LangAS::Default)
+if (Pointee.getAddressSpace() != LangAS::Default &&
+!getLangOpts().OpenCLCPlusPlus)
   return Diag(Ex.get()->getLocStart(),
   diag::e

[PATCH] D46651: [OpenCL] Support new/delete in Sema

2018-06-11 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh updated this revision to Diff 150788.
svenvh added a comment.

Dropped 2 redundant uses of `getTypePtr()`; minor formatting changes.


https://reviews.llvm.org/D46651

Files:
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaType.cpp
  test/SemaOpenCLCXX/newdelete.cl

Index: test/SemaOpenCLCXX/newdelete.cl
===
--- /dev/null
+++ test/SemaOpenCLCXX/newdelete.cl
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -verify -fsyntax-only
+
+class A {
+  public:
+  A() : x(21) {}
+  int x;
+};
+
+typedef __SIZE_TYPE__ size_t;
+
+class B {
+  public:
+  B() : bx(42) {}
+  void *operator new(size_t);
+  void operator delete(void *ptr);
+  int bx;
+};
+
+// There are no global user-defined new operators at this point. Test that clang
+// rejects these gracefully.
+void test_default_new_delete(void *buffer, A **pa) {
+  A *a = new A; // expected-error {{'default new' is not supported in OpenCL C++}}
+  delete a; // expected-error {{'default delete' is not supported in OpenCL C++}}
+  *pa = new (buffer) A; // expected-error {{'default new' is not supported in OpenCL C++}}
+}
+
+// expected-note@+1 {{candidate function not viable: requires 2 arguments, but 1 was provided}}
+void *operator new(size_t _s, void *ptr) noexcept {
+  return ptr;
+}
+
+// expected-note@+1 {{candidate function not viable: requires 2 arguments, but 1 was provided}}
+void *operator new[](size_t _s, void *ptr) noexcept {
+  return ptr;
+}
+
+void test_new_delete(void *buffer, A **a, B **b) {
+  *a = new A; // expected-error {{no matching function for call to 'operator new'}}
+  delete a;   // expected-error {{'default delete' is not supported in OpenCL C++}}
+
+  *a = new A[20]; // expected-error {{no matching function for call to 'operator new[]'}}
+  delete[] *a;// expected-error {{'default delete' is not supported in OpenCL C++}}
+
+  // User-defined placement new is supported.
+  *a = new (buffer) A;
+
+  // User-defined placement new[] is supported.
+  *a = new (buffer) A[30];
+
+  // User-defined new is supported.
+  *b = new B;
+
+  // User-defined delete is supported.
+  delete *b;
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -7137,8 +7137,9 @@
   // The default address space name for arguments to a function in a
   // program, or local variables of a function is __private. All function
   // arguments shall be in the __private address space.
-  if (State.getSema().getLangOpts().OpenCLVersion <= 120) {
-  ImpAddr = LangAS::opencl_private;
+  if (State.getSema().getLangOpts().OpenCLVersion <= 120 &&
+  !State.getSema().getLangOpts().OpenCLCPlusPlus) {
+ImpAddr = LangAS::opencl_private;
   } else {
 // If address space is not set, OpenCL 2.0 defines non private default
 // address spaces for some cases:
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -2146,7 +2146,8 @@
   else if (AllocType->isVariablyModifiedType())
 return Diag(Loc, diag::err_variably_modified_new_type)
  << AllocType;
-  else if (AllocType.getAddressSpace() != LangAS::Default)
+  else if (AllocType.getAddressSpace() != LangAS::Default &&
+   !getLangOpts().OpenCLCPlusPlus)
 return Diag(Loc, diag::err_address_space_qualified_new)
   << AllocType.getUnqualifiedType()
   << AllocType.getQualifiers().getAddressSpaceAttributePrintValue();
@@ -2362,6 +2363,11 @@
   LookupQualifiedName(R, Context.getTranslationUnitDecl());
 }
 
+if (getLangOpts().OpenCLCPlusPlus && R.empty()) {
+  Diag(StartLoc, diag::err_openclcxx_not_supported) << "default new";
+  return true;
+}
+
 assert(!R.empty() && "implicitly declared allocation functions not found");
 assert(!R.isAmbiguous() && "global allocation functions are ambiguous");
 
@@ -2597,6 +2603,11 @@
   if (GlobalNewDeleteDeclared)
 return;
 
+  // OpenCL C++ 1.0 s2.9: the implicitly declared new and delete operators
+  // are not supported.
+  if (getLangOpts().OpenCLCPlusPlus)
+return;
+
   // C++ [basic.std.dynamic]p2:
   //   [...] The following allocation and deallocation functions (18.4) are
   //   implicitly declared in global scope in each translation unit of a
@@ -3230,7 +3241,8 @@
 QualType Pointee = Type->getAs()->getPointeeType();
 QualType PointeeElem = Context.getBaseElementType(Pointee);
 
-if (Pointee.getAddressSpace() != LangAS::Default)
+if (Pointee.getAddressSpace() != LangAS::Default &&
+!getLangOpts().OpenCLCPlusPlus)
   return Diag(Ex.get()->getLocStart(),
   diag::err_address_space_qualified_delete)
<< Pointee.getUnqualifiedType()
@@ -3305,6 +3317,11 @@
 }
 
 if (!OperatorDelete) {
+ 

[PATCH] D46651: [OpenCL] Support new/delete in Sema

2018-06-11 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: lib/Sema/SemaExprCXX.cpp:2030
+  }
+}
 

rjmccall wrote:
> Anastasia wrote:
> > svenvh wrote:
> > > rjmccall wrote:
> > > > I think a better interpretation of this rule would be to just error on 
> > > > attempts to use the standard non-placement operator new/delete instead 
> > > > of trying to outlaw the operator declarations.  For example, I don't 
> > > > know why a user-defined non-global operator new would be problematic.
> > > Good point, I have raised this with Khronos, so I will hold this off 
> > > until we have clarification.
> > The decision by Khronos is to allow all user defined new/delete operators 
> > (even global). I have submitted the change to the spec. The next publishing 
> > date is however in July.
> Okay.  I agree with your decision in this patch to treat this as a defect in 
> the spec and thus to go ahead and do the right thing now.
I can postpone committing this until the revised spec has been published, if 
that's more desirable?


https://reviews.llvm.org/D46651



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


[PATCH] D46651: [OpenCL] Support new/delete in Sema

2018-06-14 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC334700: [OpenCL] Support new/delete in Sema (authored by 
svenvh, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D46651

Files:
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaType.cpp
  test/SemaOpenCLCXX/newdelete.cl

Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -2146,7 +2146,8 @@
   else if (AllocType->isVariablyModifiedType())
 return Diag(Loc, diag::err_variably_modified_new_type)
  << AllocType;
-  else if (AllocType.getAddressSpace() != LangAS::Default)
+  else if (AllocType.getAddressSpace() != LangAS::Default &&
+   !getLangOpts().OpenCLCPlusPlus)
 return Diag(Loc, diag::err_address_space_qualified_new)
   << AllocType.getUnqualifiedType()
   << AllocType.getQualifiers().getAddressSpaceAttributePrintValue();
@@ -2362,6 +2363,11 @@
   LookupQualifiedName(R, Context.getTranslationUnitDecl());
 }
 
+if (getLangOpts().OpenCLCPlusPlus && R.empty()) {
+  Diag(StartLoc, diag::err_openclcxx_not_supported) << "default new";
+  return true;
+}
+
 assert(!R.empty() && "implicitly declared allocation functions not found");
 assert(!R.isAmbiguous() && "global allocation functions are ambiguous");
 
@@ -2597,6 +2603,11 @@
   if (GlobalNewDeleteDeclared)
 return;
 
+  // OpenCL C++ 1.0 s2.9: the implicitly declared new and delete operators
+  // are not supported.
+  if (getLangOpts().OpenCLCPlusPlus)
+return;
+
   // C++ [basic.std.dynamic]p2:
   //   [...] The following allocation and deallocation functions (18.4) are
   //   implicitly declared in global scope in each translation unit of a
@@ -3230,7 +3241,8 @@
 QualType Pointee = Type->getAs()->getPointeeType();
 QualType PointeeElem = Context.getBaseElementType(Pointee);
 
-if (Pointee.getAddressSpace() != LangAS::Default)
+if (Pointee.getAddressSpace() != LangAS::Default &&
+!getLangOpts().OpenCLCPlusPlus)
   return Diag(Ex.get()->getLocStart(),
   diag::err_address_space_qualified_delete)
<< Pointee.getUnqualifiedType()
@@ -3305,6 +3317,11 @@
 }
 
 if (!OperatorDelete) {
+  if (getLangOpts().OpenCLCPlusPlus) {
+Diag(StartLoc, diag::err_openclcxx_not_supported) << "default delete";
+return ExprError();
+  }
+
   bool IsComplete = isCompleteType(StartLoc, Pointee);
   bool CanProvideSize =
   IsComplete && (!ArrayForm || UsualArrayDeleteWantsSize ||
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -13007,6 +13007,13 @@
   return false;
 }
 
+static QualType
+RemoveAddressSpaceFromPtr(Sema &SemaRef, const PointerType *PtrTy) {
+  QualType QTy = PtrTy->getPointeeType();
+  QTy = SemaRef.Context.removeAddrSpaceQualType(QTy);
+  return SemaRef.Context.getPointerType(QTy);
+}
+
 static inline bool
 CheckOperatorNewDeleteTypes(Sema &SemaRef, const FunctionDecl *FnDecl,
 CanQualType ExpectedResultType,
@@ -13022,6 +13029,13 @@
 diag::err_operator_new_delete_dependent_result_type)
 << FnDecl->getDeclName() << ExpectedResultType;
 
+  // OpenCL C++: the operator is valid on any address space.
+  if (SemaRef.getLangOpts().OpenCLCPlusPlus) {
+if (auto *PtrTy = ResultType->getAs()) {
+  ResultType = RemoveAddressSpaceFromPtr(SemaRef, PtrTy);
+}
+  }
+
   // Check that the result type is what we expect.
   if (SemaRef.Context.getCanonicalType(ResultType) != ExpectedResultType)
 return SemaRef.Diag(FnDecl->getLocation(),
@@ -13047,6 +13061,13 @@
   << FnDecl->getDeclName() << ExpectedFirstParamType;
 
   // Check that the first parameter type is what we expect.
+  if (SemaRef.getLangOpts().OpenCLCPlusPlus) {
+// OpenCL C++: the operator is valid on any address space.
+if (auto *PtrTy =
+FnDecl->getParamDecl(0)->getType()->getAs()) {
+  FirstParamType = RemoveAddressSpaceFromPtr(SemaRef, PtrTy);
+}
+  }
   if (SemaRef.Context.getCanonicalType(FirstParamType).getUnqualifiedType() !=
   ExpectedFirstParamType)
 return SemaRef.Diag(FnDecl->getLocation(), InvalidParamTypeDiag)
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -7173,8 +7173,9 @@
   // The default address space name for arguments to a function in a
   // program, or local variables of a function is __private. All function
   // arguments shall be in the __private address space.
-  if (State.getSema().getLangOpts().OpenCLVersion <= 120) {
-  ImpAddr = LangAS::opencl_private;
+  if (State.getSema().getLangOpts().OpenCLVersion <= 120 &&
+  !State.getSema().getLa

[PATCH] D53705: [OpenCL] Postpone PSV address space diagnostic

2018-10-25 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added reviewers: Anastasia, rjmccall.
Herald added subscribers: cfe-commits, yaxunl.

In OpenCL C++ mode, the "program scope variable must reside ..."
diagnostic is firing early in some cases, potentially confusing the
user.  It is the first diagnostic reported for

  int g(global int *p) {}

but the actual problem is the undeclared identifier `global`.

The main reason to improve error reporting for the example above is
that OpenCL C address space qualifiers such as `global` are not part
of OpenCL C++.  This means the PSV diagnostic will fire when porting
OpenCL C code to OpenCL C++ if an address space qualifier is left in
by accident.

The PSV diagnostic is emitted for the example above because the parser
believes `g` is a variable declaration instead of a function
declaration.  This seems to be inherent to C++ parsing, so postpone
the PSV diagnostic until we have parsed the entire declarator group.
We still get the PSV diagnostic for the example, but it is no longer
the first so it should be easier for the user to see what the actual
problem is.


Repository:
  rC Clang

https://reviews.llvm.org/D53705

Files:
  lib/Sema/SemaDecl.cpp
  test/SemaOpenCL/storageclass-cl20.cl
  test/SemaOpenCL/storageclass.cl
  test/SemaOpenCLCXX/invalid-qualifier.cl

Index: test/SemaOpenCLCXX/invalid-qualifier.cl
===
--- /dev/null
+++ test/SemaOpenCLCXX/invalid-qualifier.cl
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -fsyntax-only -verify
+// RUN: not %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -fsyntax-only 2>&1 | FileCheck %s
+
+// Use FileCheck to check that "program scope variable must reside ..." is not
+// the first diagnostic reported.
+
+int f1(global int *p) {}
+// expected-error@-1{{use of undeclared identifier 'global'}}
+// expected-error@-2{{expected ';' after top level declarator}}
+// expected-error@-3{{program scope variable must reside in constant address space}}
+// CHECK: use of undeclared identifier 'global'
+// CHECK: program scope variable must reside in constant address space
+
+; // For parser recovery.
+
+int f2(local int *p) {}
+// expected-error@-1{{use of undeclared identifier 'local'}}
+// expected-error@-2{{expected ';' after top level declarator}}
+// expected-error@-3{{program scope variable must reside in constant address space}}
+// CHECK: use of undeclared identifier 'local'
+// CHECK: program scope variable must reside in constant address space
+
+; // For parser recovery.
+
+int g(abcdef int q) {}
+// expected-error@-1{{use of undeclared identifier 'abcdef'}}
+// expected-error@-2{{expected ';' after top level declarator}}
+// expected-error@-3{{program scope variable must reside in constant address space}}
+// CHECK: use of undeclared identifier 'abcdef'
+// CHECK: program scope variable must reside in constant address space
+
+; // For parser recovery.
Index: test/SemaOpenCL/storageclass.cl
===
--- test/SemaOpenCL/storageclass.cl
+++ test/SemaOpenCL/storageclass.cl
@@ -4,11 +4,12 @@
 constant int G2 = 0;
 int G3 = 0;// expected-error{{program scope variable must reside in constant address space}}
 global int G4 = 0; // expected-error{{program scope variable must reside in constant address space}}
+int G5, G6;// expected-error 2 {{program scope variable must reside in constant address space}}
 
 static float g_implicit_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
 static constant float g_constant_static_var = 0;
 static global float g_global_static_var = 0;   // expected-error {{program scope variable must reside in constant address space}}
-static local float g_local_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
+static local float g_local_static_var = 0; // expected-error {{'__local' variable cannot have an initializer}}
 static private float g_private_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
 static generic float g_generic_static_var = 0; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address space}}
 
Index: test/SemaOpenCL/storageclass-cl20.cl
===
--- test/SemaOpenCL/storageclass-cl20.cl
+++ test/SemaOpenCL/storageclass-cl20.cl
@@ -2,12 +2,12 @@
 
 int G2 = 0;
 global int G3 = 0;
-local int G4 = 0;  // expected-error{{program scope variable must reside in global or constant address space}}
+local int G4 = 0;  // expected-error{{'__local' variable cannot have an initializer}}
 
 static float g_implicit_static_var = 0;
 static constant float g_constant_static_var = 0;
 static 

[PATCH] D53705: [OpenCL] Postpone PSV address space diagnostic

2018-10-29 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

Unlikely, since address spaces are provided in a different way in OpenCL C++ vs 
OpenCL C.

OpenCL C provides qualifiers such as `global` as part of the language.  OpenCL 
C++ provides template classes such as `cl::global` through a header file.


Repository:
  rC Clang

https://reviews.llvm.org/D53705



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


[PATCH] D53871: [OpenCL] Allow clk_event_t comparisons

2018-10-30 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: mantognini.
Herald added subscribers: cfe-commits, Anastasia, yaxunl.

Also rename `invalid-clk-events-cl2.0.cl` to `clk_event_t.cl` and
repurpose it to include both positive and negative clk_event_t tests.


Repository:
  rC Clang

https://reviews.llvm.org/D53871

Files:
  lib/Sema/SemaExpr.cpp
  test/SemaOpenCL/clk_event_t.cl
  test/SemaOpenCL/invalid-clk-events-cl2.0.cl


Index: test/SemaOpenCL/clk_event_t.cl
===
--- test/SemaOpenCL/clk_event_t.cl
+++ test/SemaOpenCL/clk_event_t.cl
@@ -1,3 +1,24 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
 
+#define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
+
 global clk_event_t ce; // expected-error {{the '__global clk_event_t' type 
cannot be used to declare a program scope variable}}
+
+int clk_event_tests() {
+  event_t e;
+  clk_event_t ce1;
+  clk_event_t ce2;
+
+  if (e == ce1) { // expected-error {{invalid operands to binary expression 
('event_t' and 'clk_event_t')}}
+return 9;
+  }
+
+  if (ce1 != ce2) {
+return 1;
+  }
+  else if (ce1 == CLK_NULL_EVENT || ce2 != CLK_NULL_EVENT) {
+return 0;
+  }
+
+  return 2;
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -10497,6 +10497,10 @@
   }
 
   if (getLangOpts().OpenCLVersion >= 200) {
+if (LHSType->isClkEventT() && RHSType->isClkEventT()) {
+  return computeResultTy();
+}
+
 if (LHSType->isQueueT() && RHSType->isQueueT()) {
   return computeResultTy();
 }


Index: test/SemaOpenCL/clk_event_t.cl
===
--- test/SemaOpenCL/clk_event_t.cl
+++ test/SemaOpenCL/clk_event_t.cl
@@ -1,3 +1,24 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
 
+#define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
+
 global clk_event_t ce; // expected-error {{the '__global clk_event_t' type cannot be used to declare a program scope variable}}
+
+int clk_event_tests() {
+  event_t e;
+  clk_event_t ce1;
+  clk_event_t ce2;
+
+  if (e == ce1) { // expected-error {{invalid operands to binary expression ('event_t' and 'clk_event_t')}}
+return 9;
+  }
+
+  if (ce1 != ce2) {
+return 1;
+  }
+  else if (ce1 == CLK_NULL_EVENT || ce2 != CLK_NULL_EVENT) {
+return 0;
+  }
+
+  return 2;
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -10497,6 +10497,10 @@
   }
 
   if (getLangOpts().OpenCLVersion >= 200) {
+if (LHSType->isClkEventT() && RHSType->isClkEventT()) {
+  return computeResultTy();
+}
+
 if (LHSType->isQueueT() && RHSType->isQueueT()) {
   return computeResultTy();
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53871: [OpenCL] Allow clk_event_t comparisons

2018-11-01 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC345825: Allow clk_event_t comparisons (authored by svenvh, 
committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D53871?vs=171711&id=172110#toc

Repository:
  rC Clang

https://reviews.llvm.org/D53871

Files:
  lib/Sema/SemaExpr.cpp
  test/SemaOpenCL/clk_event_t.cl
  test/SemaOpenCL/invalid-clk-events-cl2.0.cl


Index: test/SemaOpenCL/clk_event_t.cl
===
--- test/SemaOpenCL/clk_event_t.cl
+++ test/SemaOpenCL/clk_event_t.cl
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+
+// Taken from opencl-c.h
+#define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
+
+global clk_event_t ce; // expected-error {{the '__global clk_event_t' type 
cannot be used to declare a program scope variable}}
+
+int clk_event_tests() {
+  event_t e;
+  clk_event_t ce1;
+  clk_event_t ce2;
+
+  if (e == ce1) { // expected-error {{invalid operands to binary expression 
('event_t' and 'clk_event_t')}}
+return 9;
+  }
+
+  if (ce1 != ce2) {
+return 1;
+  }
+  else if (ce1 == CLK_NULL_EVENT || ce2 != CLK_NULL_EVENT) {
+return 0;
+  }
+
+  return 2;
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -10497,6 +10497,10 @@
   }
 
   if (getLangOpts().OpenCLVersion >= 200) {
+if (LHSType->isClkEventT() && RHSType->isClkEventT()) {
+  return computeResultTy();
+}
+
 if (LHSType->isQueueT() && RHSType->isQueueT()) {
   return computeResultTy();
 }
Index: test/SemaOpenCL/invalid-clk-events-cl2.0.cl
===
--- test/SemaOpenCL/invalid-clk-events-cl2.0.cl
+++ test/SemaOpenCL/invalid-clk-events-cl2.0.cl
@@ -1,3 +0,0 @@
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
-
-global clk_event_t ce; // expected-error {{the '__global clk_event_t' type 
cannot be used to declare a program scope variable}}


Index: test/SemaOpenCL/clk_event_t.cl
===
--- test/SemaOpenCL/clk_event_t.cl
+++ test/SemaOpenCL/clk_event_t.cl
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+
+// Taken from opencl-c.h
+#define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
+
+global clk_event_t ce; // expected-error {{the '__global clk_event_t' type cannot be used to declare a program scope variable}}
+
+int clk_event_tests() {
+  event_t e;
+  clk_event_t ce1;
+  clk_event_t ce2;
+
+  if (e == ce1) { // expected-error {{invalid operands to binary expression ('event_t' and 'clk_event_t')}}
+return 9;
+  }
+
+  if (ce1 != ce2) {
+return 1;
+  }
+  else if (ce1 == CLK_NULL_EVENT || ce2 != CLK_NULL_EVENT) {
+return 0;
+  }
+
+  return 2;
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -10497,6 +10497,10 @@
   }
 
   if (getLangOpts().OpenCLVersion >= 200) {
+if (LHSType->isClkEventT() && RHSType->isClkEventT()) {
+  return computeResultTy();
+}
+
 if (LHSType->isQueueT() && RHSType->isQueueT()) {
   return computeResultTy();
 }
Index: test/SemaOpenCL/invalid-clk-events-cl2.0.cl
===
--- test/SemaOpenCL/invalid-clk-events-cl2.0.cl
+++ test/SemaOpenCL/invalid-clk-events-cl2.0.cl
@@ -1,3 +0,0 @@
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
-
-global clk_event_t ce; // expected-error {{the '__global clk_event_t' type cannot be used to declare a program scope variable}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D60775: [libclang] Expose ext_vector_type

2019-04-16 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: Anastasia.
Herald added subscribers: cfe-commits, arphaman.
Herald added a project: clang.

Expose `ext_vector_type` through the C API.


Repository:
  rC Clang

https://reviews.llvm.org/D60775

Files:
  bindings/python/clang/cindex.py
  include/clang-c/Index.h
  test/Index/opencl-types.cl
  tools/libclang/CXType.cpp


Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -109,6 +109,7 @@
 TKCASE(VariableArray);
 TKCASE(DependentSizedArray);
 TKCASE(Vector);
+TKCASE(ExtVector);
 TKCASE(MemberPointer);
 TKCASE(Auto);
 TKCASE(Elaborated);
@@ -600,6 +601,7 @@
 TKIND(VariableArray);
 TKIND(DependentSizedArray);
 TKIND(Vector);
+TKIND(ExtVector);
 TKIND(MemberPointer);
 TKIND(Auto);
 TKIND(Elaborated);
@@ -804,6 +806,9 @@
 case Type::Vector:
   ET = cast (TP)->getElementType();
   break;
+case Type::ExtVector:
+  ET = cast(TP)->getElementType();
+  break;
 case Type::Complex:
   ET = cast (TP)->getElementType();
   break;
@@ -827,6 +832,9 @@
 case Type::Vector:
   result = cast (TP)->getNumElements();
   break;
+case Type::ExtVector:
+  result = cast(TP)->getNumElements();
+  break;
 default:
   break;
 }
Index: test/Index/opencl-types.cl
===
--- test/Index/opencl-types.cl
+++ test/Index/opencl-types.cl
@@ -17,11 +17,11 @@
 }
 
 // CHECK: VarDecl=scalarHalf:11:8 (Definition){{( \(invalid\))?}} [type=half] 
[typekind=Half] [isPOD=1]
-// CHECK: VarDecl=vectorHalf:12:9 (Definition) [type=half4] [typekind=Typedef] 
[canonicaltype=half __attribute__((ext_vector_type(4)))] 
[canonicaltypekind=Unexposed] [isPOD=1]
+// CHECK: VarDecl=vectorHalf:12:9 (Definition) [type=half4] [typekind=Typedef] 
[canonicaltype=half __attribute__((ext_vector_type(4)))] 
[canonicaltypekind=ExtVector] [isPOD=1]
 // CHECK: VarDecl=scalarFloat:13:9 (Definition) [type=float] [typekind=Float] 
[isPOD=1]
-// CHECK: VarDecl=vectorFloat:14:10 (Definition) [type=float4] 
[typekind=Typedef] [canonicaltype=float __attribute__((ext_vector_type(4)))] 
[canonicaltypekind=Unexposed] [isPOD=1]
+// CHECK: VarDecl=vectorFloat:14:10 (Definition) [type=float4] 
[typekind=Typedef] [canonicaltype=float __attribute__((ext_vector_type(4)))] 
[canonicaltypekind=ExtVector] [isPOD=1]
 // CHECK: VarDecl=scalarDouble:15:10 (Definition){{( \(invalid\))?}} 
[type=double] [typekind=Double] [isPOD=1]
-// CHECK: VarDecl=vectorDouble:16:11 (Definition){{( \(invalid\))?}} 
[type=double4] [typekind=Typedef] [canonicaltype=double 
__attribute__((ext_vector_type(4)))] [canonicaltypekind=Unexposed] [isPOD=1]
+// CHECK: VarDecl=vectorDouble:16:11 (Definition){{( \(invalid\))?}} 
[type=double4] [typekind=Typedef] [canonicaltype=double 
__attribute__((ext_vector_type(4)))] [canonicaltypekind=ExtVector] [isPOD=1]
 
 #pragma OPENCL EXTENSION cl_khr_gl_msaa_sharing : enable
 
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 54
+#define CINDEX_VERSION_MINOR 55
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -3315,7 +3315,9 @@
   CXType_OCLIntelSubgroupAVCImeResultDualRefStreamout = 173,
   CXType_OCLIntelSubgroupAVCImeSingleRefStreamin = 174,
 
-  CXType_OCLIntelSubgroupAVCImeDualRefStreamin = 175
+  CXType_OCLIntelSubgroupAVCImeDualRefStreamin = 175,
+
+  CXType_ExtVector = 176
 };
 
 /**
Index: bindings/python/clang/cindex.py
===
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -2121,6 +2121,8 @@
 TypeKind.OCLQUEUE = TypeKind(159)
 TypeKind.OCLRESERVEID = TypeKind(160)
 
+TypeKind.EXTVECTOR = TypeKind(176)
+
 class RefQualifierKind(BaseEnumeration):
 """Describes a specific ref-qualifier of a type."""
 


Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -109,6 +109,7 @@
 TKCASE(VariableArray);
 TKCASE(DependentSizedArray);
 TKCASE(Vector);
+TKCASE(ExtVector);
 TKCASE(MemberPointer);
 TKCASE(Auto);
 TKCASE(Elaborated);
@@ -600,6 +601,7 @@
 TKIND(VariableArray);
 TKIND(DependentSizedArray);
 TKIND(Vector);
+TKIND(ExtVector);
 TKIND(MemberPointer);
 TKIND(Auto);
 TKIND(Elaborated);
@@ -804,6 +806,9 @@
 case Type::Vector:
   ET = cast (TP)->getElementType();
   break;
+case Type::ExtVector:
+  ET = cast(TP)->getElementType();
+  break;
 

[PATCH] D60775: [libclang] Expose ext_vector_type

2019-04-17 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL358566: [libclang] Expose ext_vector_type (authored by 
svenvh, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D60775?vs=195373&id=195521#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60775/new/

https://reviews.llvm.org/D60775

Files:
  cfe/trunk/bindings/python/clang/cindex.py
  cfe/trunk/include/clang-c/Index.h
  cfe/trunk/test/Index/opencl-types.cl
  cfe/trunk/tools/libclang/CXType.cpp


Index: cfe/trunk/include/clang-c/Index.h
===
--- cfe/trunk/include/clang-c/Index.h
+++ cfe/trunk/include/clang-c/Index.h
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 54
+#define CINDEX_VERSION_MINOR 55
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -3315,7 +3315,9 @@
   CXType_OCLIntelSubgroupAVCImeResultDualRefStreamout = 173,
   CXType_OCLIntelSubgroupAVCImeSingleRefStreamin = 174,
 
-  CXType_OCLIntelSubgroupAVCImeDualRefStreamin = 175
+  CXType_OCLIntelSubgroupAVCImeDualRefStreamin = 175,
+
+  CXType_ExtVector = 176
 };
 
 /**
Index: cfe/trunk/test/Index/opencl-types.cl
===
--- cfe/trunk/test/Index/opencl-types.cl
+++ cfe/trunk/test/Index/opencl-types.cl
@@ -17,11 +17,11 @@
 }
 
 // CHECK: VarDecl=scalarHalf:11:8 (Definition){{( \(invalid\))?}} [type=half] 
[typekind=Half] [isPOD=1]
-// CHECK: VarDecl=vectorHalf:12:9 (Definition) [type=half4] [typekind=Typedef] 
[canonicaltype=half __attribute__((ext_vector_type(4)))] 
[canonicaltypekind=Unexposed] [isPOD=1]
+// CHECK: VarDecl=vectorHalf:12:9 (Definition) [type=half4] [typekind=Typedef] 
[canonicaltype=half __attribute__((ext_vector_type(4)))] 
[canonicaltypekind=ExtVector] [isPOD=1]
 // CHECK: VarDecl=scalarFloat:13:9 (Definition) [type=float] [typekind=Float] 
[isPOD=1]
-// CHECK: VarDecl=vectorFloat:14:10 (Definition) [type=float4] 
[typekind=Typedef] [canonicaltype=float __attribute__((ext_vector_type(4)))] 
[canonicaltypekind=Unexposed] [isPOD=1]
+// CHECK: VarDecl=vectorFloat:14:10 (Definition) [type=float4] 
[typekind=Typedef] [canonicaltype=float __attribute__((ext_vector_type(4)))] 
[canonicaltypekind=ExtVector] [isPOD=1]
 // CHECK: VarDecl=scalarDouble:15:10 (Definition){{( \(invalid\))?}} 
[type=double] [typekind=Double] [isPOD=1]
-// CHECK: VarDecl=vectorDouble:16:11 (Definition){{( \(invalid\))?}} 
[type=double4] [typekind=Typedef] [canonicaltype=double 
__attribute__((ext_vector_type(4)))] [canonicaltypekind=Unexposed] [isPOD=1]
+// CHECK: VarDecl=vectorDouble:16:11 (Definition){{( \(invalid\))?}} 
[type=double4] [typekind=Typedef] [canonicaltype=double 
__attribute__((ext_vector_type(4)))] [canonicaltypekind=ExtVector] [isPOD=1]
 
 #pragma OPENCL EXTENSION cl_khr_gl_msaa_sharing : enable
 
Index: cfe/trunk/tools/libclang/CXType.cpp
===
--- cfe/trunk/tools/libclang/CXType.cpp
+++ cfe/trunk/tools/libclang/CXType.cpp
@@ -109,6 +109,7 @@
 TKCASE(VariableArray);
 TKCASE(DependentSizedArray);
 TKCASE(Vector);
+TKCASE(ExtVector);
 TKCASE(MemberPointer);
 TKCASE(Auto);
 TKCASE(Elaborated);
@@ -600,6 +601,7 @@
 TKIND(VariableArray);
 TKIND(DependentSizedArray);
 TKIND(Vector);
+TKIND(ExtVector);
 TKIND(MemberPointer);
 TKIND(Auto);
 TKIND(Elaborated);
@@ -804,6 +806,9 @@
 case Type::Vector:
   ET = cast (TP)->getElementType();
   break;
+case Type::ExtVector:
+  ET = cast(TP)->getElementType();
+  break;
 case Type::Complex:
   ET = cast (TP)->getElementType();
   break;
@@ -827,6 +832,9 @@
 case Type::Vector:
   result = cast (TP)->getNumElements();
   break;
+case Type::ExtVector:
+  result = cast(TP)->getNumElements();
+  break;
 default:
   break;
 }
Index: cfe/trunk/bindings/python/clang/cindex.py
===
--- cfe/trunk/bindings/python/clang/cindex.py
+++ cfe/trunk/bindings/python/clang/cindex.py
@@ -2121,6 +2121,8 @@
 TypeKind.OCLQUEUE = TypeKind(159)
 TypeKind.OCLRESERVEID = TypeKind(160)
 
+TypeKind.EXTVECTOR = TypeKind(176)
+
 class RefQualifierKind(BaseEnumeration):
 """Describes a specific ref-qualifier of a type."""
 


Index: cfe/trunk/include/clang-c/Index.h
===
--- cfe/trunk/include/clang-c/Index.h
+++ cfe/trunk/include/clang-c/Index.h
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 54
+#define CINDEX_VERSION_MINOR 5

[PATCH] D51411: [OpenCL] Improve diagnostic of argument in address space conversion builtins

2018-09-20 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL342638: [OpenCL] Diagnose redundant address space conversion 
(authored by svenvh, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D51411?vs=164835&id=166253#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D51411

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl


Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -849,6 +849,13 @@
 return true;
   }
 
+  if (RT->getPointeeType().getAddressSpace() != LangAS::opencl_generic) {
+S.Diag(Call->getArg(0)->getBeginLoc(),
+   diag::warn_opencl_generic_address_space_arg)
+<< Call->getDirectCallee()->getNameInfo().getAsString()
+<< Call->getArg(0)->getSourceRange();
+  }
+
   RT = RT->getPointeeType();
   auto Qual = RT.getQualifiers();
   switch (BuiltinID) {
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8613,6 +8613,10 @@
   "invalid prototype, variadic arguments are not allowed in OpenCL">;
 def err_opencl_requires_extension : Error<
   "use of %select{type|declaration}0 %1 requires %2 extension to be enabled">;
+def warn_opencl_generic_address_space_arg : Warning<
+  "passing non-generic address space pointer to %0"
+  " may cause dynamic conversion affecting performance">,
+  InGroup, DefaultIgnore;
 
 // OpenCL v2.0 s6.13.6 -- Builtin Pipe Functions
 def err_opencl_builtin_pipe_first_arg : Error<
Index: cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl
===
--- cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl
+++ cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -verify -fsyntax-only %s
-// RUN: %clang_cc1 -verify -fsyntax-only -cl-std=CL2.0 %s
+// RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL2.0 %s
 
 void test(void) {
   global int *glob;
@@ -43,13 +43,15 @@
   // expected-warning@-2{{incompatible integer to pointer conversion assigning 
to '__local int *' from 'int'}}
 #else
   // expected-error@-4{{assigning '__global int *' to '__local int *' changes 
address space of pointer}}
+  // expected-warning@-5{{passing non-generic address space pointer to 
to_global may cause dynamic conversion affecting performance}}
 #endif
 
   global char *glob_c = to_global(loc);
 #if __OPENCL_C_VERSION__ < CL_VERSION_2_0
   // expected-warning@-2{{incompatible integer to pointer conversion 
initializing '__global char *' with an expression of type 'int'}}
 #else
   // expected-warning@-4{{incompatible pointer types initializing '__global 
char *' with an expression of type '__global int *'}}
+  // expected-warning@-5{{passing non-generic address space pointer to 
to_global may cause dynamic conversion affecting performance}}
 #endif
 
 }


Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -849,6 +849,13 @@
 return true;
   }
 
+  if (RT->getPointeeType().getAddressSpace() != LangAS::opencl_generic) {
+S.Diag(Call->getArg(0)->getBeginLoc(),
+   diag::warn_opencl_generic_address_space_arg)
+<< Call->getDirectCallee()->getNameInfo().getAsString()
+<< Call->getArg(0)->getSourceRange();
+  }
+
   RT = RT->getPointeeType();
   auto Qual = RT.getQualifiers();
   switch (BuiltinID) {
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8613,6 +8613,10 @@
   "invalid prototype, variadic arguments are not allowed in OpenCL">;
 def err_opencl_requires_extension : Error<
   "use of %select{type|declaration}0 %1 requires %2 extension to be enabled">;
+def warn_opencl_generic_address_space_arg : Warning<
+  "passing non-generic address space pointer to %0"
+  " may cause dynamic conversion affecting performance">,
+  InGroup, DefaultIgnore;
 
 // OpenCL v2.0 s6.13.6 -- Builtin Pipe Functions
 def err_opencl_builtin_pipe_first_arg : Error<
Index: cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl
===
--- cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl
+++ cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -verify -fsyntax-only %s
-// RUN: %clang_cc1 -verify -fsyntax-only -cl-std=CL2.0 %s
+// RUN: %clang_cc1 -Wconversion -

[PATCH] D51727: [OpenCL] Allow zero assignment and comparisons between queue_t type variables

2018-09-25 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC342968: [OpenCL] Allow zero assignment and comparisons 
between queue_t type variables (authored by svenvh, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D51727

Files:
  lib/Sema/SemaExpr.cpp
  test/SemaOpenCL/null_queue.cl


Index: test/SemaOpenCL/null_queue.cl
===
--- test/SemaOpenCL/null_queue.cl
+++ test/SemaOpenCL/null_queue.cl
@@ -1,12 +1,30 @@
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
 extern queue_t get_default_queue();
 
-bool compare() {
-  return 1 == get_default_queue() && // expected-error{{invalid operands to 
binary expression ('int' and 'queue_t')}}
- get_default_queue() == 1; // expected-error{{invalid operands to 
binary expression ('queue_t' and 'int')}}
-}
+void queue_arg(queue_t); // expected-note {{passing argument to parameter 
here}}
 
 void init() {
   queue_t q1 = 1; // expected-error{{initializing 'queue_t' with an expression 
of incompatible type 'int'}}
   queue_t q = 0;
 }
+
+void assign() {
+  queue_t q2, q3;
+  q2 = 5; // expected-error{{assigning to 'queue_t' from incompatible type 
'int'}}
+  q3 = 0;
+  q2 = q3 = 0;
+}
+
+bool compare() {
+  queue_t q4, q5;
+  return 1 == get_default_queue() && // expected-error{{invalid operands to 
binary expression ('int' and 'queue_t')}}
+ get_default_queue() == 1 && // expected-error{{invalid operands to 
binary expression ('queue_t' and 'int')}}
+q4 == q5 &&
+q4 != 0 &&
+q4 != 0.0f; // expected-error{{invalid operands to binary 
expression ('queue_t' and 'float')}}
+}
+
+void call() {
+  queue_arg(5); // expected-error {{passing 'int' to parameter of incompatible 
type 'queue_t'}}
+  queue_arg(0);
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -8086,6 +8086,13 @@
 return Compatible;
   }
 
+  // OpenCL queue_t type assignment.
+  if (LHSType->isQueueT() && RHS.get()->isNullPointerConstant(
+ Context, Expr::NPC_ValueDependentIsNull)) {
+RHS = ImpCastExprToType(RHS.get(), LHSType, CK_NullToPointer);
+return Compatible;
+  }
+
   // This check seems unnatural, however it is necessary to ensure the proper
   // conversion of functions/arrays. If the conversion were done for all
   // DeclExpr's (created by ActOnIdExpression), it would mess up the unary
@@ -10423,6 +10430,10 @@
   }
 
   if (getLangOpts().OpenCLVersion >= 200) {
+if (LHSType->isQueueT() && RHSType->isQueueT()) {
+  return computeResultTy();
+}
+
 if (LHSIsNull && RHSType->isQueueT()) {
   LHS = ImpCastExprToType(LHS.get(), RHSType, CK_NullToPointer);
   return computeResultTy();


Index: test/SemaOpenCL/null_queue.cl
===
--- test/SemaOpenCL/null_queue.cl
+++ test/SemaOpenCL/null_queue.cl
@@ -1,12 +1,30 @@
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
 extern queue_t get_default_queue();
 
-bool compare() {
-  return 1 == get_default_queue() && // expected-error{{invalid operands to binary expression ('int' and 'queue_t')}}
- get_default_queue() == 1; // expected-error{{invalid operands to binary expression ('queue_t' and 'int')}}
-}
+void queue_arg(queue_t); // expected-note {{passing argument to parameter here}}
 
 void init() {
   queue_t q1 = 1; // expected-error{{initializing 'queue_t' with an expression of incompatible type 'int'}}
   queue_t q = 0;
 }
+
+void assign() {
+  queue_t q2, q3;
+  q2 = 5; // expected-error{{assigning to 'queue_t' from incompatible type 'int'}}
+  q3 = 0;
+  q2 = q3 = 0;
+}
+
+bool compare() {
+  queue_t q4, q5;
+  return 1 == get_default_queue() && // expected-error{{invalid operands to binary expression ('int' and 'queue_t')}}
+ get_default_queue() == 1 && // expected-error{{invalid operands to binary expression ('queue_t' and 'int')}}
+	 q4 == q5 &&
+	 q4 != 0 &&
+	 q4 != 0.0f; // expected-error{{invalid operands to binary expression ('queue_t' and 'float')}}
+}
+
+void call() {
+  queue_arg(5); // expected-error {{passing 'int' to parameter of incompatible type 'queue_t'}}
+  queue_arg(0);
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -8086,6 +8086,13 @@
 return Compatible;
   }
 
+  // OpenCL queue_t type assignment.
+  if (LHSType->isQueueT() && RHS.get()->isNullPointerConstant(
+ Context, Expr::NPC_ValueDependentIsNull)) {
+RHS = ImpCastExprToType(RHS.get(), LHSType, CK_NullToPointer);
+return Compatible;
+  }
+
   // This check seems unnatural, however it is necessary to ensure the proper
   // conversion of functions/arrays. If the conversion w

[PATCH] D51727: [OpenCL] Allow zero assignment and comparisons between queue_t type variables

2018-09-25 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL342968: [OpenCL] Allow zero assignment and comparisons 
between queue_t type variables (authored by svenvh, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D51727?vs=164184&id=166860#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D51727

Files:
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/test/SemaOpenCL/null_queue.cl


Index: cfe/trunk/test/SemaOpenCL/null_queue.cl
===
--- cfe/trunk/test/SemaOpenCL/null_queue.cl
+++ cfe/trunk/test/SemaOpenCL/null_queue.cl
@@ -1,12 +1,30 @@
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
 extern queue_t get_default_queue();
 
-bool compare() {
-  return 1 == get_default_queue() && // expected-error{{invalid operands to 
binary expression ('int' and 'queue_t')}}
- get_default_queue() == 1; // expected-error{{invalid operands to 
binary expression ('queue_t' and 'int')}}
-}
+void queue_arg(queue_t); // expected-note {{passing argument to parameter 
here}}
 
 void init() {
   queue_t q1 = 1; // expected-error{{initializing 'queue_t' with an expression 
of incompatible type 'int'}}
   queue_t q = 0;
 }
+
+void assign() {
+  queue_t q2, q3;
+  q2 = 5; // expected-error{{assigning to 'queue_t' from incompatible type 
'int'}}
+  q3 = 0;
+  q2 = q3 = 0;
+}
+
+bool compare() {
+  queue_t q4, q5;
+  return 1 == get_default_queue() && // expected-error{{invalid operands to 
binary expression ('int' and 'queue_t')}}
+ get_default_queue() == 1 && // expected-error{{invalid operands to 
binary expression ('queue_t' and 'int')}}
+q4 == q5 &&
+q4 != 0 &&
+q4 != 0.0f; // expected-error{{invalid operands to binary 
expression ('queue_t' and 'float')}}
+}
+
+void call() {
+  queue_arg(5); // expected-error {{passing 'int' to parameter of incompatible 
type 'queue_t'}}
+  queue_arg(0);
+}
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -8086,6 +8086,13 @@
 return Compatible;
   }
 
+  // OpenCL queue_t type assignment.
+  if (LHSType->isQueueT() && RHS.get()->isNullPointerConstant(
+ Context, Expr::NPC_ValueDependentIsNull)) {
+RHS = ImpCastExprToType(RHS.get(), LHSType, CK_NullToPointer);
+return Compatible;
+  }
+
   // This check seems unnatural, however it is necessary to ensure the proper
   // conversion of functions/arrays. If the conversion were done for all
   // DeclExpr's (created by ActOnIdExpression), it would mess up the unary
@@ -10423,6 +10430,10 @@
   }
 
   if (getLangOpts().OpenCLVersion >= 200) {
+if (LHSType->isQueueT() && RHSType->isQueueT()) {
+  return computeResultTy();
+}
+
 if (LHSIsNull && RHSType->isQueueT()) {
   LHS = ImpCastExprToType(LHS.get(), RHSType, CK_NullToPointer);
   return computeResultTy();


Index: cfe/trunk/test/SemaOpenCL/null_queue.cl
===
--- cfe/trunk/test/SemaOpenCL/null_queue.cl
+++ cfe/trunk/test/SemaOpenCL/null_queue.cl
@@ -1,12 +1,30 @@
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
 extern queue_t get_default_queue();
 
-bool compare() {
-  return 1 == get_default_queue() && // expected-error{{invalid operands to binary expression ('int' and 'queue_t')}}
- get_default_queue() == 1; // expected-error{{invalid operands to binary expression ('queue_t' and 'int')}}
-}
+void queue_arg(queue_t); // expected-note {{passing argument to parameter here}}
 
 void init() {
   queue_t q1 = 1; // expected-error{{initializing 'queue_t' with an expression of incompatible type 'int'}}
   queue_t q = 0;
 }
+
+void assign() {
+  queue_t q2, q3;
+  q2 = 5; // expected-error{{assigning to 'queue_t' from incompatible type 'int'}}
+  q3 = 0;
+  q2 = q3 = 0;
+}
+
+bool compare() {
+  queue_t q4, q5;
+  return 1 == get_default_queue() && // expected-error{{invalid operands to binary expression ('int' and 'queue_t')}}
+ get_default_queue() == 1 && // expected-error{{invalid operands to binary expression ('queue_t' and 'int')}}
+	 q4 == q5 &&
+	 q4 != 0 &&
+	 q4 != 0.0f; // expected-error{{invalid operands to binary expression ('queue_t' and 'float')}}
+}
+
+void call() {
+  queue_arg(5); // expected-error {{passing 'int' to parameter of incompatible type 'queue_t'}}
+  queue_arg(0);
+}
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -8086,6 +8086,13 @@
 return Compatible;
   }
 
+  // OpenCL queue_t type assignment.
+  if (LHSType->isQueueT() && RHS.get()->isNullPointerConstant(
+ Context, Expr:

[PATCH] D52020: [OpenCL] Improve extension-version.cl and to_addr_builtin.cl tests

2018-09-27 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL343207: [OpenCL] Improve extension-version.cl and 
to_addr_builtin.cl tests (authored by svenvh, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D52020?vs=165239&id=167302#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D52020

Files:
  cfe/trunk/test/SemaOpenCL/extension-version.cl
  cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl

Index: cfe/trunk/test/SemaOpenCL/extension-version.cl
===
--- cfe/trunk/test/SemaOpenCL/extension-version.cl
+++ cfe/trunk/test/SemaOpenCL/extension-version.cl
@@ -283,6 +283,18 @@
 #pragma OPENCL EXTENSION cl_amd_media_ops2: enable
 
 #if (__OPENCL_C_VERSION__ >= 120)
+#ifndef cl_khr_depth_images
+#error "Missing cl_khr_depth_images define"
+#endif
+#else
+#ifdef cl_khr_depth_images
+#error "Incorrect cl_khr_depth_images define"
+#endif
+// expected-warning@+2{{unsupported OpenCL extension 'cl_khr_depth_images' - ignoring}}
+#endif
+#pragma OPENCL EXTENSION cl_khr_depth_images: enable
+
+#if (__OPENCL_C_VERSION__ >= 120)
 #ifndef cl_intel_subgroups
 #error "Missing cl_intel_subgroups define"
 #endif
Index: cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl
===
--- cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl
+++ cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl
@@ -5,6 +5,8 @@
   global int *glob;
   local int *loc;
   constant int *con;
+  private int *priv;
+  global float *glob_wrong_ty;
   typedef constant int const_int_ty;
   const_int_ty *con_typedef;
 
@@ -46,12 +48,86 @@
   // expected-warning@-5{{passing non-generic address space pointer to to_global may cause dynamic conversion affecting performance}}
 #endif
 
+  loc = to_private(glob);
+#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+  // expected-error@-2{{implicit declaration of function 'to_private' is invalid in OpenCL}}
+  // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__local int *' from 'int'}}
+#else
+  // expected-error@-5{{assigning 'int *' to '__local int *' changes address space of pointer}}
+  // expected-warning@-6{{passing non-generic address space pointer to to_private may cause dynamic conversion affecting performance}}
+#endif
+
+  loc = to_local(glob);
+#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+  // expected-error@-2{{implicit declaration of function 'to_local' is invalid in OpenCL}}
+  // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__local int *' from 'int'}}
+  // expected-note@-4{{did you mean 'to_global'}}
+  // expected-note@13{{'to_global' declared here}}
+#else
+  // expected-warning@-7{{passing non-generic address space pointer to to_local may cause dynamic conversion affecting performance}}
+#endif
+
+  priv = to_global(glob);
+#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+  // expected-warning@-2{{incompatible integer to pointer conversion assigning to 'int *' from 'int'}}
+#else
+  // expected-error@-4{{assigning '__global int *' to 'int *' changes address space of pointer}}
+  // expected-warning@-5{{passing non-generic address space pointer to to_global may cause dynamic conversion affecting performance}}
+#endif
+
+  priv = to_private(glob);
+#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+  // expected-warning@-2{{incompatible integer to pointer conversion assigning to 'int *' from 'int'}}
+#else
+  // expected-warning@-4{{passing non-generic address space pointer to to_private may cause dynamic conversion affecting performance}}
+#endif
+
+
+  priv = to_local(glob);
+#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+  // expected-warning@-2{{incompatible integer to pointer conversion assigning to 'int *' from 'int'}}
+#else
+  // expected-error@-4{{assigning '__local int *' to 'int *' changes address space of pointer}}
+  // expected-warning@-5{{passing non-generic address space pointer to to_local may cause dynamic conversion affecting performance}}
+#endif
+
+  glob = to_global(glob);
+#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+  // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
+#else
+  // expected-warning@-4{{passing non-generic address space pointer to to_global may cause dynamic conversion affecting performance}}
+#endif
+
+  glob = to_private(glob);
+#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+  // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
+#else
+  // expected-error@-4{{assigning 'int *' to '__global int *' changes address space of pointer}}
+  // expected-warning@-5{{passing non-generic address space pointer to to_private may cause dynamic conversion affecting performance}}
+#endif
+
+  glob = to_local(glob);
+#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+  // expected-warning@-2{{incompatible integer to pointer conversion assigning to

[PATCH] D43783: [OpenCL] Remove block invoke function from emitted block literal struct

2018-10-02 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

Reverted in r343582, test added in r343583.


Repository:
  rC Clang

https://reviews.llvm.org/D43783



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


[PATCH] D57824: [OpenCL][PR40603] Align the use of extensions in C++ to be backwards compatible with OpenCL C v2.0

2019-02-07 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: lib/Frontend/InitPreprocessor.cpp:1063
+auto OpenCLVersion =
+LangOpts.OpenCLCPlusPlus ? 200 : LangOpts.OpenCLVersion;
+#define OPENCLEXT(Ext) 
\

Why not set `OpenCLVersion` in `lib/Frontend/CompilerInvocation.cpp` instead?  
Then you wouldn't have to "override" the version in multiple places (which 
increases the risk of missing one or more places).



Comment at: lib/Sema/Sema.cpp:265
 addImplicitTypedef("event_t", Context.OCLEventTy);
-if (getLangOpts().OpenCLVersion >= 200) {
+if (getLangOpts().OpenCLCPlusPlus || getLangOpts().OpenCLVersion >= 200) {
   addImplicitTypedef("clk_event_t", Context.OCLClkEventTy);

This also exposes the OpenCL 2.0 types in OpenCL C++ mode; it would be good to 
mention that in the commit message.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57824/new/

https://reviews.llvm.org/D57824



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


[PATCH] D57824: [OpenCL][PR40603] In C++ preserve backwards compatibility with OpenCL C v2.0

2019-02-07 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh accepted this revision.
svenvh added a comment.
This revision is now accepted and ready to land.

Even nicer to have it only inside the extension logic indeed.

LGTM.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57824/new/

https://reviews.llvm.org/D57824



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


[PATCH] D57946: [libclang] Add attribute support for 'convergent'.

2019-02-11 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC353690: [libclang] Add attribute support for 
'convergent'. (authored by svenvh, committed by ).

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57946/new/

https://reviews.llvm.org/D57946

Files:
  bindings/python/clang/cindex.py
  include/clang-c/Index.h
  test/Index/attributes.c
  tools/libclang/CIndex.cpp
  tools/libclang/CXCursor.cpp


Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 50
+#define CINDEX_VERSION_MINOR 51
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -2586,7 +2586,8 @@
   CXCursor_ObjCRuntimeVisible= 435,
   CXCursor_ObjCBoxable   = 436,
   CXCursor_FlagEnum  = 437,
-  CXCursor_LastAttr  = CXCursor_FlagEnum,
+  CXCursor_ConvergentAttr= 438,
+  CXCursor_LastAttr  = CXCursor_ConvergentAttr,
 
   /* Preprocessing */
   CXCursor_PreprocessingDirective= 500,
Index: test/Index/attributes.c
===
--- test/Index/attributes.c
+++ test/Index/attributes.c
@@ -12,6 +12,8 @@
   Foo
 };
 
+void convergent_fn() __attribute__((convergent));
+
 // CHECK: attributes.c:3:32: StructDecl=Test2:3:32 (Definition) Extent=[3:1 - 
5:2]
 // CHECK: attributes.c:3:23: attribute(packed)=packed Extent=[3:23 - 3:29]
 // CHECK: attributes.c:4:8: FieldDecl=a:4:8 (Definition) Extent=[4:3 - 4:9] 
[access=public]
@@ -24,3 +26,6 @@
 // CHECK: attributes.c:9:38: attribute(noduplicate)= Extent=[9:38 - 9:49]
 // CHECK: attributes.c:11:31: EnumDecl=FlagEnum:11:31 (Definition) 
Extent=[11:1 - 13:2]
 // CHECK: attributes.c:11:19: attribute(flag_enum)= Extent=[11:19 - 11:28]
+// CHECK: attributes.c:12:3: EnumConstantDecl=Foo:12:3 (Definition) 
Extent=[12:3 - 12:6]
+// CHECK: attributes.c:15:6: FunctionDecl=convergent_fn:15:6 Extent=[15:1 - 
15:49]
+// CHECK: attributes.c:15:37: attribute(convergent)= Extent=[15:37 - 15:47]
Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -5474,7 +5474,9 @@
   case CXCursor_StaticAssert:
   return cxstring::createRef("StaticAssert");
   case CXCursor_FriendDecl:
-return cxstring::createRef("FriendDecl");
+  return cxstring::createRef("FriendDecl");
+  case CXCursor_ConvergentAttr:
+  return cxstring::createRef("attribute(convergent)");
   }
 
   llvm_unreachable("Unhandled CXCursorKind");
Index: tools/libclang/CXCursor.cpp
===
--- tools/libclang/CXCursor.cpp
+++ tools/libclang/CXCursor.cpp
@@ -78,6 +78,7 @@
 case attr::ObjCRuntimeVisible: return CXCursor_ObjCRuntimeVisible;
 case attr::ObjCBoxable: return CXCursor_ObjCBoxable;
 case attr::FlagEnum: return CXCursor_FlagEnum;
+case attr::Convergent: return CXCursor_ConvergentAttr;
   }
 
   return CXCursor_UnexposedAttr;
Index: bindings/python/clang/cindex.py
===
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -1342,6 +1342,7 @@
 
 CursorKind.DLLEXPORT_ATTR = CursorKind(418)
 CursorKind.DLLIMPORT_ATTR = CursorKind(419)
+CursorKind.CONVERGENT_ATTR = CursorKind(420)
 
 ###
 # Preprocessing


Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 50
+#define CINDEX_VERSION_MINOR 51
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -2586,7 +2586,8 @@
   CXCursor_ObjCRuntimeVisible= 435,
   CXCursor_ObjCBoxable   = 436,
   CXCursor_FlagEnum  = 437,
-  CXCursor_LastAttr  = CXCursor_FlagEnum,
+  CXCursor_ConvergentAttr= 438,
+  CXCursor_LastAttr  = CXCursor_ConvergentAttr,
 
   /* Preprocessing */
   CXCursor_PreprocessingDirective= 500,
Index: test/Index/attributes.c
===
--- test/Index/attributes.c
+++ test/Index/attributes.c
@@ -12,6 +12,8 @@
   Foo
 };
 
+void convergent_fn() __attribute__((convergent));
+
 // CHECK: attributes.c:3:32: StructDecl=Test2:3:32 (Definition) Extent=[3:1 - 5:2]
 // CHECK: attributes.c:3:23: attribute(packed)=packed Extent=[3:23 - 3:29]
 // CHECK: at

[PATCH] D58179: [OpenCL][PR40707] Allow OpenCL C types in C++ mode

2019-02-15 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh accepted this revision.
svenvh added a comment.
This revision is now accepted and ready to land.

LGTM!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58179/new/

https://reviews.llvm.org/D58179



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


[PATCH] D62588: [OpenCL] Support logical vector operators in C++ mode

2019-05-30 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL362087: [OpenCL] Support logical vector operators in C++ 
mode (authored by svenvh, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D62588?vs=201897&id=202162#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62588/new/

https://reviews.llvm.org/D62588

Files:
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/test/CodeGenOpenCL/logical-ops.cl


Index: cfe/trunk/test/CodeGenOpenCL/logical-ops.cl
===
--- cfe/trunk/test/CodeGenOpenCL/logical-ops.cl
+++ cfe/trunk/test/CodeGenOpenCL/logical-ops.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL1.2 -O1 -triple 
x86_64-unknown-linux-gnu | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=c++ -O1 -triple 
x86_64-unknown-linux-gnu | FileCheck %s
 
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
 
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -10902,7 +10902,7 @@
   if (vType.isNull())
 return InvalidOperands(Loc, LHS, RHS);
   if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion < 120 &&
-  vType->hasFloatingRepresentation())
+  !getLangOpts().OpenCLCPlusPlus && vType->hasFloatingRepresentation())
 return InvalidOperands(Loc, LHS, RHS);
   // FIXME: The check for C++ here is for GCC compatibility. GCC rejects the
   //usage of the logical operators && and || with vectors in C. This
@@ -13165,7 +13165,8 @@
   }
 } else if (resultType->isExtVectorType()) {
   if (Context.getLangOpts().OpenCL &&
-  Context.getLangOpts().OpenCLVersion < 120) {
+  Context.getLangOpts().OpenCLVersion < 120 &&
+  !Context.getLangOpts().OpenCLCPlusPlus) {
 // OpenCL v1.1 6.3.h: The logical operator not (!) does not
 // operate on vector float types.
 QualType T = resultType->getAs()->getElementType();


Index: cfe/trunk/test/CodeGenOpenCL/logical-ops.cl
===
--- cfe/trunk/test/CodeGenOpenCL/logical-ops.cl
+++ cfe/trunk/test/CodeGenOpenCL/logical-ops.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL1.2 -O1 -triple x86_64-unknown-linux-gnu | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=c++ -O1 -triple x86_64-unknown-linux-gnu | FileCheck %s
 
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
 
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -10902,7 +10902,7 @@
   if (vType.isNull())
 return InvalidOperands(Loc, LHS, RHS);
   if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion < 120 &&
-  vType->hasFloatingRepresentation())
+  !getLangOpts().OpenCLCPlusPlus && vType->hasFloatingRepresentation())
 return InvalidOperands(Loc, LHS, RHS);
   // FIXME: The check for C++ here is for GCC compatibility. GCC rejects the
   //usage of the logical operators && and || with vectors in C. This
@@ -13165,7 +13165,8 @@
   }
 } else if (resultType->isExtVectorType()) {
   if (Context.getLangOpts().OpenCL &&
-  Context.getLangOpts().OpenCLVersion < 120) {
+  Context.getLangOpts().OpenCLVersion < 120 &&
+  !Context.getLangOpts().OpenCLCPlusPlus) {
 // OpenCL v1.1 6.3.h: The logical operator not (!) does not
 // operate on vector float types.
 QualType T = resultType->getAs()->getElementType();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62657: [OpenCL] Fix OpenCL/SPIR version metadata

2019-05-30 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh accepted this revision.
svenvh added a comment.
This revision is now accepted and ready to land.

LGTM!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62657/new/

https://reviews.llvm.org/D62657



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


[PATCH] D60763: Prototype OpenCL BIFs using Tablegen

2019-05-30 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: clang/include/clang/Basic/OpenCLBuiltins.td:298-302
+def write_imagef : Builtin<"write_imagef",
+[void_t,
+  image2d_WO_t,
+  VectorType,
+  VectorType]>;

AlexeySotkin wrote:
> Pierre wrote:
> > AlexeySotkin wrote:
> > > It seems like there is something wrong with access qualifiers for images. 
> > > I have applied this patch and tried to compile the following code:
> > > 
> > > ```
> > > typedef int int2 __attribute__((ext_vector_type(2)));
> > > typedef float float4 __attribute__((ext_vector_type(4)));
> > > 
> > > void kernel k(write_only image2d_t image, int2 coord, float4 data) {
> > >   write_imagef(image, coord, data);
> > > }
> > > 
> > > ```
> > > I got the following output:
> > > ```
> > > clang -cc1 -triple spir /work/tmp/tmp.cl -emit-llvm -o -  
> > > -fadd-opencl-builtins
> > > /work/tmp/tmp.cl:5:16: error: passing '__write_only image2d_t' to 
> > > parameter of incompatible type '__read_only image2d_t'
> > >   write_imagef(image, coord, data);
> > >  ^
> > > 1 error generated.
> > > ```
> > What you are saying is right. This patch is incomplete and some features 
> > are missing/ broken. 
> > I have a new version of the tablegen builtin feature where the access 
> > qualifiers are actually taken into account, but I cannot extract only this 
> > from my version. This would imply uploading the whole new version. 
> > The new version will hopefully be on top of this patch, making access 
> > qualifiers work.
> Thanks, Pierre. I'd like to start early testing of image builtins with this 
> prototype. Do you have an idea when you will have image builtins done in this 
> (or other) patch?
> If it is not going to happen in the nearest future, would you mind if I'll 
> propose some changes for this patch/prototype meanwhile?
We're planning to commit the basic infrastructure early next week, which should 
make it easier to extend this work and enable contributions from the wider 
community.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60763/new/

https://reviews.llvm.org/D60763



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


[PATCH] D60763: Prototype OpenCL BIFs using Tablegen

2019-05-31 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

Looks good overall, I'd like to propose a few more minor changes to this patch 
before landing:

- isPointer can be a `bit` / `bool` instead of an `int` / `unsigned`.
- Renaming the command line option from `-fadd-declare-builtins` to 
`-fdeclare-opencl-builtins` should hopefully convey the meaning of the option a 
bit better.
- Drop the spurious `;` in `OCL2Qual`.
- Emit spaces instead of tabs for `OCL2Qual`, like the rest of the generated 
file.
- Bring the format of OpenCL spec references into alignment with the rest of 
clang (e.g. OpenCL v2.0 s9.17.3).
- Adding //(experimental)// to the help text of `-fdeclare-opencl-builtins`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60763/new/

https://reviews.llvm.org/D60763



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


[PATCH] D60763: Prototype OpenCL BIFs using Tablegen

2019-06-03 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL362371: [OpenCL] Declare builtin functions using TableGen 
(authored by svenvh, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D60763?vs=200961&id=202673#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60763/new/

https://reviews.llvm.org/D60763

Files:
  cfe/trunk/include/clang/Basic/CMakeLists.txt
  cfe/trunk/include/clang/Basic/LangOptions.def
  cfe/trunk/include/clang/Basic/OpenCLBuiltins.td
  cfe/trunk/include/clang/Driver/CC1Options.td
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/lib/Sema/SemaLookup.cpp
  cfe/trunk/test/SemaOpenCL/fdeclare-opencl-builtins.cl
  cfe/trunk/utils/TableGen/CMakeLists.txt
  cfe/trunk/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
  cfe/trunk/utils/TableGen/TableGen.cpp
  cfe/trunk/utils/TableGen/TableGenBackends.h

Index: cfe/trunk/include/clang/Driver/CC1Options.td
===
--- cfe/trunk/include/clang/Driver/CC1Options.td
+++ cfe/trunk/include/clang/Driver/CC1Options.td
@@ -778,7 +778,9 @@
 def fdefault_calling_conv_EQ : Joined<["-"], "fdefault-calling-conv=">,
   HelpText<"Set default calling convention">, Values<"cdecl,fastcall,stdcall,vectorcall,regcall">;
 def finclude_default_header : Flag<["-"], "finclude-default-header">,
-  HelpText<"Include the default header file for OpenCL">;
+  HelpText<"Include default header file for OpenCL">;
+def fdeclare_opencl_builtins : Flag<["-"], "fdeclare-opencl-builtins">,
+  HelpText<"Add OpenCL builtin function declarations (experimental)">;
 def fpreserve_vec3_type : Flag<["-"], "fpreserve-vec3-type">,
   HelpText<"Preserve 3-component vector type">;
 def fwchar_type_EQ : Joined<["-"], "fwchar-type=">,
Index: cfe/trunk/include/clang/Basic/CMakeLists.txt
===
--- cfe/trunk/include/clang/Basic/CMakeLists.txt
+++ cfe/trunk/include/clang/Basic/CMakeLists.txt
@@ -41,6 +41,12 @@
   TARGET ClangAttrHasAttributeImpl
   )
 
+clang_tablegen(OpenCLBuiltins.inc
+  -I ${CMAKE_CURRENT_SOURCE_DIR}/../../ -gen-clang-opencl-builtins
+  SOURCE OpenCLBuiltins.td
+  TARGET ClangOpenCLBuiltinsImpl
+  )
+
 # ARM NEON
 clang_tablegen(arm_neon.inc -gen-arm-neon-sema
   SOURCE arm_neon.td
Index: cfe/trunk/include/clang/Basic/OpenCLBuiltins.td
===
--- cfe/trunk/include/clang/Basic/OpenCLBuiltins.td
+++ cfe/trunk/include/clang/Basic/OpenCLBuiltins.td
@@ -0,0 +1,296 @@
+//==--- OpenCLBuiltins.td - OpenCL builtin declarations ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file contains TableGen definitions for OpenCL builtin function
+// declarations.  In case of an unresolved function name in OpenCL, Clang will
+// check for a function described in this file when -fdeclare-opencl-builtins
+// is specified.
+//
+//===--===//
+
+//===--===//
+//  Definitions of miscellaneous basic entities.
+//===--===//
+// Versions of OpenCL
+class Version {
+  int Version = _Version;
+}
+def CL10: Version<100>;
+def CL11: Version<110>;
+def CL12: Version<120>;
+def CL20: Version<200>;
+
+// Address spaces
+// Pointer types need to be assigned an address space.
+class AddressSpace {
+  string AddrSpace = _AS;
+}
+def default_as: AddressSpace<"clang::LangAS::Default">;
+def private_as: AddressSpace<"clang::LangAS::opencl_private">;
+def global_as : AddressSpace<"clang::LangAS::opencl_global">;
+def constant_as   : AddressSpace<"clang::LangAS::opencl_constant">;
+def local_as  : AddressSpace<"clang::LangAS::opencl_local">;
+def generic_as: AddressSpace<"clang::LangAS::opencl_generic">;
+
+
+// Qualified Type. Allow to retrieve one ASTContext QualType.
+class QualType {
+  // Name of the field or function in a clang::ASTContext
+  // E.g. Name="IntTy" for the int type, and "getIntPtrType()" for an intptr_t
+  string Name = _Name;
+}
+
+// Helper class to store type access qualifiers (volatile, const, ...).
+class Qualifier {
+  string QualName = _QualName;
+}
+
+//===--===//
+//  OpenCL C classes for types
+//===--===//
+// OpenCL types (int,

[PATCH] D63256: [OpenCL] Split type and macro definitions into opencl-c-base.h

2019-06-13 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: asavonic.
Herald added subscribers: cfe-commits, jfb, yaxunl, mgorny.
Herald added a project: clang.

Using the -fdeclare-opencl-builtins option will require a way to
predefine types and macros such as `int4`, `CLK_GLOBAL_MEM_FENCE`,
etc.  Move these out of opencl-c.h into opencl-c-base.h that is shared
by -fdeclare-opencl-builtins and -finclude-default-header.


Repository:
  rC Clang

https://reviews.llvm.org/D63256

Files:
  lib/Frontend/CompilerInvocation.cpp
  lib/Headers/CMakeLists.txt
  lib/Headers/opencl-c-base.h
  lib/Headers/opencl-c.h
  test/SemaOpenCL/fdeclare-opencl-builtins.cl

Index: test/SemaOpenCL/fdeclare-opencl-builtins.cl
===
--- test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -2,12 +2,6 @@
 
 // Test the -fdeclare-opencl-builtins option.
 
-typedef float float4 __attribute__((ext_vector_type(4)));
-typedef int int4 __attribute__((ext_vector_type(4)));
-typedef int int2 __attribute__((ext_vector_type(2)));
-typedef unsigned int uint;
-typedef __SIZE_TYPE__ size_t;
-
 kernel void basic_conversion(global float4 *buf, global int4 *res) {
   res[0] = convert_int4(buf[0]);
 }
Index: lib/Headers/opencl-c.h
===
--- lib/Headers/opencl-c.h
+++ lib/Headers/opencl-c.h
@@ -9,6 +9,8 @@
 #ifndef _OPENCL_H_
 #define _OPENCL_H_
 
+#include "opencl-c-base.h"
+
 #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 #ifndef cl_khr_depth_images
 #define cl_khr_depth_images
@@ -33,255 +35,6 @@
 #define __purefn __attribute__((pure))
 #define __cnfn __attribute__((const))
 
-// built-in scalar data types:
-
-/**
- * An unsigned 8-bit integer.
- */
-typedef unsigned char uchar;
-
-/**
- * An unsigned 16-bit integer.
- */
-typedef unsigned short ushort;
-
-/**
- * An unsigned 32-bit integer.
- */
-typedef unsigned int uint;
-
-/**
- * An unsigned 64-bit integer.
- */
-typedef unsigned long ulong;
-
-/**
- * The unsigned integer type of the result of the sizeof operator. This
- * is a 32-bit unsigned integer if CL_DEVICE_ADDRESS_BITS
- * defined in table 4.3 is 32-bits and is a 64-bit unsigned integer if
- * CL_DEVICE_ADDRESS_BITS is 64-bits.
- */
-typedef __SIZE_TYPE__ size_t;
-
-/**
- * A signed integer type that is the result of subtracting two pointers.
- * This is a 32-bit signed integer if CL_DEVICE_ADDRESS_BITS
- * defined in table 4.3 is 32-bits and is a 64-bit signed integer if
- * CL_DEVICE_ADDRESS_BITS is 64-bits.
- */
-typedef __PTRDIFF_TYPE__ ptrdiff_t;
-
-/**
-* A signed integer type with the property that any valid pointer to
-* void can be converted to this type, then converted back to pointer
-* to void, and the result will compare equal to the original pointer.
-*/
-typedef __INTPTR_TYPE__ intptr_t;
-
-/**
-* An unsigned integer type with the property that any valid pointer to
-* void can be converted to this type, then converted back to pointer
-* to void, and the result will compare equal to the original pointer.
-*/
-typedef __UINTPTR_TYPE__ uintptr_t;
-
-// built-in vector data types:
-typedef char char2 __attribute__((ext_vector_type(2)));
-typedef char char3 __attribute__((ext_vector_type(3)));
-typedef char char4 __attribute__((ext_vector_type(4)));
-typedef char char8 __attribute__((ext_vector_type(8)));
-typedef char char16 __attribute__((ext_vector_type(16)));
-typedef uchar uchar2 __attribute__((ext_vector_type(2)));
-typedef uchar uchar3 __attribute__((ext_vector_type(3)));
-typedef uchar uchar4 __attribute__((ext_vector_type(4)));
-typedef uchar uchar8 __attribute__((ext_vector_type(8)));
-typedef uchar uchar16 __attribute__((ext_vector_type(16)));
-typedef short short2 __attribute__((ext_vector_type(2)));
-typedef short short3 __attribute__((ext_vector_type(3)));
-typedef short short4 __attribute__((ext_vector_type(4)));
-typedef short short8 __attribute__((ext_vector_type(8)));
-typedef short short16 __attribute__((ext_vector_type(16)));
-typedef ushort ushort2 __attribute__((ext_vector_type(2)));
-typedef ushort ushort3 __attribute__((ext_vector_type(3)));
-typedef ushort ushort4 __attribute__((ext_vector_type(4)));
-typedef ushort ushort8 __attribute__((ext_vector_type(8)));
-typedef ushort ushort16 __attribute__((ext_vector_type(16)));
-typedef int int2 __attribute__((ext_vector_type(2)));
-typedef int int3 __attribute__((ext_vector_type(3)));
-typedef int int4 __attribute__((ext_vector_type(4)));
-typedef int int8 __attribute__((ext_vector_type(8)));
-typedef int int16 __attribute__((ext_vector_type(16)));
-typedef uint uint2 __attribute__((ext_vector_type(2)));
-typedef uint uint3 __attribute__((ext_vector_type(3)));
-typedef uint uint4 __attribute__((ext_vector_type(4)));
-typedef uint uint8 __attribute__((ext_vector_type(8)));
-typedef uint uint16 __attribute__((ext_vector_type(16)));
-typedef long long2 __attribute__((ext_vector_type(2)));
-typedef long l

[PATCH] D63256: [OpenCL] Split type and macro definitions into opencl-c-base.h

2019-06-14 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh updated this revision to Diff 204796.
svenvh added a comment.

Change `IncludeDefaultHeader` and `DeclareOpenCLBuiltins` logic as per 
@asavonic's comments.  Also extend 
`test/SemaOpenCL/fdeclare-opencl-builtins.cl` to test the interplay of both 
options.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63256/new/

https://reviews.llvm.org/D63256

Files:
  lib/Frontend/CompilerInvocation.cpp
  lib/Headers/CMakeLists.txt
  lib/Headers/opencl-c-base.h
  lib/Headers/opencl-c.h
  test/SemaOpenCL/fdeclare-opencl-builtins.cl

Index: test/SemaOpenCL/fdeclare-opencl-builtins.cl
===
--- test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -1,12 +1,16 @@
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -DNO_HEADER
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header
 
 // Test the -fdeclare-opencl-builtins option.
 
+// Provide typedefs when invoking clang without -finclude-default-header.
+#ifdef NO_HEADER
 typedef float float4 __attribute__((ext_vector_type(4)));
 typedef int int4 __attribute__((ext_vector_type(4)));
 typedef int int2 __attribute__((ext_vector_type(2)));
 typedef unsigned int uint;
 typedef __SIZE_TYPE__ size_t;
+#endif
 
 kernel void basic_conversion(global float4 *buf, global int4 *res) {
   res[0] = convert_int4(buf[0]);
Index: lib/Headers/opencl-c.h
===
--- lib/Headers/opencl-c.h
+++ lib/Headers/opencl-c.h
@@ -9,6 +9,8 @@
 #ifndef _OPENCL_H_
 #define _OPENCL_H_
 
+#include "opencl-c-base.h"
+
 #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 #ifndef cl_khr_depth_images
 #define cl_khr_depth_images
@@ -33,255 +35,6 @@
 #define __purefn __attribute__((pure))
 #define __cnfn __attribute__((const))
 
-// built-in scalar data types:
-
-/**
- * An unsigned 8-bit integer.
- */
-typedef unsigned char uchar;
-
-/**
- * An unsigned 16-bit integer.
- */
-typedef unsigned short ushort;
-
-/**
- * An unsigned 32-bit integer.
- */
-typedef unsigned int uint;
-
-/**
- * An unsigned 64-bit integer.
- */
-typedef unsigned long ulong;
-
-/**
- * The unsigned integer type of the result of the sizeof operator. This
- * is a 32-bit unsigned integer if CL_DEVICE_ADDRESS_BITS
- * defined in table 4.3 is 32-bits and is a 64-bit unsigned integer if
- * CL_DEVICE_ADDRESS_BITS is 64-bits.
- */
-typedef __SIZE_TYPE__ size_t;
-
-/**
- * A signed integer type that is the result of subtracting two pointers.
- * This is a 32-bit signed integer if CL_DEVICE_ADDRESS_BITS
- * defined in table 4.3 is 32-bits and is a 64-bit signed integer if
- * CL_DEVICE_ADDRESS_BITS is 64-bits.
- */
-typedef __PTRDIFF_TYPE__ ptrdiff_t;
-
-/**
-* A signed integer type with the property that any valid pointer to
-* void can be converted to this type, then converted back to pointer
-* to void, and the result will compare equal to the original pointer.
-*/
-typedef __INTPTR_TYPE__ intptr_t;
-
-/**
-* An unsigned integer type with the property that any valid pointer to
-* void can be converted to this type, then converted back to pointer
-* to void, and the result will compare equal to the original pointer.
-*/
-typedef __UINTPTR_TYPE__ uintptr_t;
-
-// built-in vector data types:
-typedef char char2 __attribute__((ext_vector_type(2)));
-typedef char char3 __attribute__((ext_vector_type(3)));
-typedef char char4 __attribute__((ext_vector_type(4)));
-typedef char char8 __attribute__((ext_vector_type(8)));
-typedef char char16 __attribute__((ext_vector_type(16)));
-typedef uchar uchar2 __attribute__((ext_vector_type(2)));
-typedef uchar uchar3 __attribute__((ext_vector_type(3)));
-typedef uchar uchar4 __attribute__((ext_vector_type(4)));
-typedef uchar uchar8 __attribute__((ext_vector_type(8)));
-typedef uchar uchar16 __attribute__((ext_vector_type(16)));
-typedef short short2 __attribute__((ext_vector_type(2)));
-typedef short short3 __attribute__((ext_vector_type(3)));
-typedef short short4 __attribute__((ext_vector_type(4)));
-typedef short short8 __attribute__((ext_vector_type(8)));
-typedef short short16 __attribute__((ext_vector_type(16)));
-typedef ushort ushort2 __attribute__((ext_vector_type(2)));
-typedef ushort ushort3 __attribute__((ext_vector_type(3)));
-typedef ushort ushort4 __attribute__((ext_vector_type(4)));
-typedef ushort ushort8 __attribute__((ext_vector_type(8)));
-typedef ushort ushort16 __attribute__((ext_vector_type(16)));
-typedef int int2 __attribute__((ext_vector_type(2)));
-typedef int int3 __attribute__((ext_vector_type(3)));
-typedef int int4 __attribute__((ext_vector_type(4)));
-typedef int int8 __attribute__((ext_vector_type(8)));
-typedef int int16 __attribute__((ext_vector_type(16)));
-typedef uin

[PATCH] D63256: [OpenCL] Split type and macro definitions into opencl-c-base.h

2019-06-19 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363794: [OpenCL] Split type and macro definitions into 
opencl-c-base.h (authored by svenvh, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63256?vs=204796&id=205558#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63256/new/

https://reviews.llvm.org/D63256

Files:
  cfe/trunk/include/clang/Basic/SyncScope.h
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/lib/Headers/CMakeLists.txt
  cfe/trunk/lib/Headers/module.modulemap
  cfe/trunk/lib/Headers/opencl-c-base.h
  cfe/trunk/lib/Headers/opencl-c.h
  cfe/trunk/test/SemaOpenCL/fdeclare-opencl-builtins.cl

Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -2194,9 +2194,15 @@
 Opts.NativeHalfType = 1;
 Opts.NativeHalfArgsAndReturns = 1;
 Opts.OpenCLCPlusPlus = Opts.CPlusPlus;
+
 // Include default header file for OpenCL.
-if (Opts.IncludeDefaultHeader && !Opts.DeclareOpenCLBuiltins) {
-  PPOpts.Includes.push_back("opencl-c.h");
+if (Opts.IncludeDefaultHeader) {
+  if (Opts.DeclareOpenCLBuiltins) {
+// Only include base header file for builtin types and constants.
+PPOpts.Includes.push_back("opencl-c-base.h");
+  } else {
+PPOpts.Includes.push_back("opencl-c.h");
+  }
 }
   }
 
Index: cfe/trunk/lib/Headers/opencl-c.h
===
--- cfe/trunk/lib/Headers/opencl-c.h
+++ cfe/trunk/lib/Headers/opencl-c.h
@@ -9,6 +9,8 @@
 #ifndef _OPENCL_H_
 #define _OPENCL_H_
 
+#include "opencl-c-base.h"
+
 #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 #ifndef cl_khr_depth_images
 #define cl_khr_depth_images
@@ -33,255 +35,6 @@
 #define __purefn __attribute__((pure))
 #define __cnfn __attribute__((const))
 
-// built-in scalar data types:
-
-/**
- * An unsigned 8-bit integer.
- */
-typedef unsigned char uchar;
-
-/**
- * An unsigned 16-bit integer.
- */
-typedef unsigned short ushort;
-
-/**
- * An unsigned 32-bit integer.
- */
-typedef unsigned int uint;
-
-/**
- * An unsigned 64-bit integer.
- */
-typedef unsigned long ulong;
-
-/**
- * The unsigned integer type of the result of the sizeof operator. This
- * is a 32-bit unsigned integer if CL_DEVICE_ADDRESS_BITS
- * defined in table 4.3 is 32-bits and is a 64-bit unsigned integer if
- * CL_DEVICE_ADDRESS_BITS is 64-bits.
- */
-typedef __SIZE_TYPE__ size_t;
-
-/**
- * A signed integer type that is the result of subtracting two pointers.
- * This is a 32-bit signed integer if CL_DEVICE_ADDRESS_BITS
- * defined in table 4.3 is 32-bits and is a 64-bit signed integer if
- * CL_DEVICE_ADDRESS_BITS is 64-bits.
- */
-typedef __PTRDIFF_TYPE__ ptrdiff_t;
-
-/**
-* A signed integer type with the property that any valid pointer to
-* void can be converted to this type, then converted back to pointer
-* to void, and the result will compare equal to the original pointer.
-*/
-typedef __INTPTR_TYPE__ intptr_t;
-
-/**
-* An unsigned integer type with the property that any valid pointer to
-* void can be converted to this type, then converted back to pointer
-* to void, and the result will compare equal to the original pointer.
-*/
-typedef __UINTPTR_TYPE__ uintptr_t;
-
-// built-in vector data types:
-typedef char char2 __attribute__((ext_vector_type(2)));
-typedef char char3 __attribute__((ext_vector_type(3)));
-typedef char char4 __attribute__((ext_vector_type(4)));
-typedef char char8 __attribute__((ext_vector_type(8)));
-typedef char char16 __attribute__((ext_vector_type(16)));
-typedef uchar uchar2 __attribute__((ext_vector_type(2)));
-typedef uchar uchar3 __attribute__((ext_vector_type(3)));
-typedef uchar uchar4 __attribute__((ext_vector_type(4)));
-typedef uchar uchar8 __attribute__((ext_vector_type(8)));
-typedef uchar uchar16 __attribute__((ext_vector_type(16)));
-typedef short short2 __attribute__((ext_vector_type(2)));
-typedef short short3 __attribute__((ext_vector_type(3)));
-typedef short short4 __attribute__((ext_vector_type(4)));
-typedef short short8 __attribute__((ext_vector_type(8)));
-typedef short short16 __attribute__((ext_vector_type(16)));
-typedef ushort ushort2 __attribute__((ext_vector_type(2)));
-typedef ushort ushort3 __attribute__((ext_vector_type(3)));
-typedef ushort ushort4 __attribute__((ext_vector_type(4)));
-typedef ushort ushort8 __attribute__((ext_vector_type(8)));
-typedef ushort ushort16 __attribute__((ext_vector_type(16)));
-typedef int int2 __attribute__((ext_vector_type(2)));
-typedef int int3 __attribute__((ext_vector_type(3)));
-typedef int int4 __attribute__((ext_vector_type(4)));
-typedef int int8 __attribute__((ext_vector_type(8)));
-typedef int int16 __attribute__((ext_vector_t

[PATCH] D63561: [OpenCL] Improve diagnostic for placement new

2019-06-19 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: Anastasia.
Herald added subscribers: cfe-commits, yaxunl.
Herald added a project: clang.

Without an explicit declaration for placement new, clang would reject
uses of placement new with "default new' is not supported in OpenCL
C++", suggesting that placement new is not supported, see e.g.
PR42060.


Repository:
  rC Clang

https://reviews.llvm.org/D63561

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaExprCXX.cpp
  test/SemaOpenCLCXX/newdelete.cl


Index: test/SemaOpenCLCXX/newdelete.cl
===
--- test/SemaOpenCLCXX/newdelete.cl
+++ test/SemaOpenCLCXX/newdelete.cl
@@ -21,7 +21,7 @@
 void test_default_new_delete(void *buffer, A **pa) {
   A *a = new A; // expected-error {{'default new' is not supported in 
OpenCL C++}}
   delete a; // expected-error {{'default delete' is not supported 
in OpenCL C++}}
-  *pa = new (buffer) A; // expected-error {{'default new' is not supported in 
OpenCL C++}}
+  *pa = new (buffer) A; // expected-error {{use of placement new requires 
explicit declaration}}
 }
 
 // expected-note@+1 {{candidate function not viable: requires 2 arguments, but 
1 was provided}}
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -2413,7 +2413,11 @@
 }
 
 if (getLangOpts().OpenCLCPlusPlus && R.empty()) {
-  Diag(StartLoc, diag::err_openclcxx_not_supported) << "default new";
+  if (PlaceArgs.empty()) {
+Diag(StartLoc, diag::err_openclcxx_not_supported) << "default new";
+  } else {
+Diag(StartLoc, diag::err_openclcxx_placement_new);
+  }
   return true;
 }
 
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -8808,6 +8808,9 @@
   "vector component name '%0' is an OpenCL version 2.2 feature">,
   InGroup;
 
+def err_openclcxx_placement_new : Error<
+  "use of placement new requires explicit declaration">;
+
 // MIG routine annotations.
 def warn_mig_server_routine_does_not_return_kern_return_t : Warning<
   "'mig_server_routine' attribute only applies to routines that return a 
kern_return_t">,


Index: test/SemaOpenCLCXX/newdelete.cl
===
--- test/SemaOpenCLCXX/newdelete.cl
+++ test/SemaOpenCLCXX/newdelete.cl
@@ -21,7 +21,7 @@
 void test_default_new_delete(void *buffer, A **pa) {
   A *a = new A; // expected-error {{'default new' is not supported in OpenCL C++}}
   delete a; // expected-error {{'default delete' is not supported in OpenCL C++}}
-  *pa = new (buffer) A; // expected-error {{'default new' is not supported in OpenCL C++}}
+  *pa = new (buffer) A; // expected-error {{use of placement new requires explicit declaration}}
 }
 
 // expected-note@+1 {{candidate function not viable: requires 2 arguments, but 1 was provided}}
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -2413,7 +2413,11 @@
 }
 
 if (getLangOpts().OpenCLCPlusPlus && R.empty()) {
-  Diag(StartLoc, diag::err_openclcxx_not_supported) << "default new";
+  if (PlaceArgs.empty()) {
+Diag(StartLoc, diag::err_openclcxx_not_supported) << "default new";
+  } else {
+Diag(StartLoc, diag::err_openclcxx_placement_new);
+  }
   return true;
 }
 
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -8808,6 +8808,9 @@
   "vector component name '%0' is an OpenCL version 2.2 feature">,
   InGroup;
 
+def err_openclcxx_placement_new : Error<
+  "use of placement new requires explicit declaration">;
+
 // MIG routine annotations.
 def warn_mig_server_routine_does_not_return_kern_return_t : Warning<
   "'mig_server_routine' attribute only applies to routines that return a kern_return_t">,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64867: [OpenCL] Update comments/diagnostics to refer to C++ for OpenCL mode

2019-07-17 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

It would be good if you could provide some motivation for this change in the 
description of this review.




Comment at: include/clang/Basic/DiagnosticParseKinds.td:1157
 
-// OpenCL C++.
+// C++ for OpenCL.
 def err_openclcxx_virtual_function : Error<

Please align on either "C++ for OpenCL" or "C++ for OpenCL mode" (in 
DiagnosticCommonKinds.td).



Comment at: lib/Sema/SemaDecl.cpp:6429
 
-// OpenCL C++ 1.0 s2.9: the thread_local storage qualifier is not
-// supported.  OpenCL C does not support thread_local either, and
+// C++ for OpenCL does not allow thread_local storage qualifier.
+// OpenCL C does not support thread_local either, and

*the* thread_local storage qualifier.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64867/new/

https://reviews.llvm.org/D64867



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


[PATCH] D64867: [OpenCL] Update comments/diagnostics to refer to C++ for OpenCL mode

2019-07-18 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh accepted this revision.
svenvh added a comment.
This revision is now accepted and ready to land.

LGTM


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64867/new/

https://reviews.llvm.org/D64867



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


[PATCH] D63876: [OpenCL] Define CLK_NULL_EVENT without cast

2019-07-19 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366546: [OpenCL] Define CLK_NULL_EVENT without cast 
(authored by svenvh, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63876?vs=206850&id=210778#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63876/new/

https://reviews.llvm.org/D63876

Files:
  cfe/trunk/lib/Headers/opencl-c-base.h
  cfe/trunk/test/SemaOpenCL/clk_event_t.cl


Index: cfe/trunk/test/SemaOpenCL/clk_event_t.cl
===
--- cfe/trunk/test/SemaOpenCL/clk_event_t.cl
+++ cfe/trunk/test/SemaOpenCL/clk_event_t.cl
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=c++
 
 // Taken from opencl-c.h
-#define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
+#define CLK_NULL_EVENT (__builtin_astype(((__SIZE_MAX__)), clk_event_t))
 
 global clk_event_t ce; // expected-error {{the '__global clk_event_t' type 
cannot be used to declare a program scope variable}}
 
@@ -10,6 +10,7 @@
   event_t e;
   clk_event_t ce1;
   clk_event_t ce2;
+  clk_event_t ce3 = CLK_NULL_EVENT;
 
   if (e == ce1) { // expected-error {{invalid operands to binary expression 
('event_t' and 'clk_event_t')}}
 return 9;
Index: cfe/trunk/lib/Headers/opencl-c-base.h
===
--- cfe/trunk/lib/Headers/opencl-c-base.h
+++ cfe/trunk/lib/Headers/opencl-c-base.h
@@ -413,7 +413,7 @@
 #define CLK_OUT_OF_RESOURCES-5
 
 #define CLK_NULL_QUEUE  0
-#define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
+#define CLK_NULL_EVENT (__builtin_astype(((__SIZE_MAX__)), clk_event_t))
 
 // execution model related definitions
 #define CLK_ENQUEUE_FLAGS_NO_WAIT   0x0


Index: cfe/trunk/test/SemaOpenCL/clk_event_t.cl
===
--- cfe/trunk/test/SemaOpenCL/clk_event_t.cl
+++ cfe/trunk/test/SemaOpenCL/clk_event_t.cl
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=c++
 
 // Taken from opencl-c.h
-#define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
+#define CLK_NULL_EVENT (__builtin_astype(((__SIZE_MAX__)), clk_event_t))
 
 global clk_event_t ce; // expected-error {{the '__global clk_event_t' type cannot be used to declare a program scope variable}}
 
@@ -10,6 +10,7 @@
   event_t e;
   clk_event_t ce1;
   clk_event_t ce2;
+  clk_event_t ce3 = CLK_NULL_EVENT;
 
   if (e == ce1) { // expected-error {{invalid operands to binary expression ('event_t' and 'clk_event_t')}}
 return 9;
Index: cfe/trunk/lib/Headers/opencl-c-base.h
===
--- cfe/trunk/lib/Headers/opencl-c-base.h
+++ cfe/trunk/lib/Headers/opencl-c-base.h
@@ -413,7 +413,7 @@
 #define CLK_OUT_OF_RESOURCES-5
 
 #define CLK_NULL_QUEUE  0
-#define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
+#define CLK_NULL_EVENT (__builtin_astype(((__SIZE_MAX__)), clk_event_t))
 
 // execution model related definitions
 #define CLK_ENQUEUE_FLAGS_NO_WAIT   0x0
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65102: [OpenCL] Rename lang mode flag for C++ mode

2019-07-24 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh accepted this revision.
svenvh added a comment.
This revision is now accepted and ready to land.

LGTM!




Comment at: include/clang/Frontend/LangStandards.def:177
 LANGSTANDARD_ALIAS_DEPR(opencl20, "CL2.0")
+LANGSTANDARD_ALIAS_DEPR(openclcpp, "CLC++")
 

It surprised me that the capitalized aliases for the (non-C++) CL standards are 
considered deprecated, because the OpenCL spec only mentions the capitalized 
variants.  The deprecation was introduced by 59456511f4 ("Improve diagnostics 
for bad -std= flag.", 2017-04-27).  It doesn't seem to have any practical 
implications though.

The convention for non-OpenCL standards seems to be all lowercase though (e.g. 
`c99`, `c++14`, so it sounds reasonable to mark the capitalized `CLC++` as 
deprecated.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65102/new/

https://reviews.llvm.org/D65102



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


[PATCH] D65456: [OpenCL] Add generic type handling for builtin functions

2019-07-30 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: Anastasia.
Herald added subscribers: cfe-commits, kristina, yaxunl.
Herald added a reviewer: rengolin.
Herald added a project: clang.

Generic types are an abstraction of type sets.  It mimics the way
functions are defined in the OpenCL specification.  For example,
floatN can abstract all the vector sizes of the float type.

This allows to

- stick more closely to the specification, which uses generic types;
- factorize definitions of functions with numerous prototypes in the tablegen 
file; and
- reduce the memory impact of functions with many overloads.

Patch by Pierre Gondois and Sven van Haastregt.

Continuation of https://reviews.llvm.org/D63434


Repository:
  rC Clang

https://reviews.llvm.org/D65456

Files:
  clang/lib/Sema/OpenCLBuiltins.td
  clang/lib/Sema/SemaLookup.cpp
  clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
  clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Index: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
===
--- clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -15,12 +15,39 @@
 //
 // For a successful lookup of e.g. the "cos" builtin, isOpenCLBuiltin("cos")
 // returns a pair .
-// OpenCLBuiltins[Index] to OpenCLBuiltins[Index + Len] contains the pairs
+// BuiltinTable[Index] to BuiltinTable[Index + Len] contains the pairs
 //  of the overloads of "cos".
-// OpenCLSignature[SigIndex] to OpenCLSignature[SigIndex + SigLen] contains
-// one of the signatures of "cos". The OpenCLSignature entry can be
-// referenced by other functions, i.e. "sin", since multiple OpenCL builtins
-// share the same signature.
+// SignatureTable[SigIndex] to SignatureTable[SigIndex + SigLen] contains
+// one of the signatures of "cos". The SignatureTable entry can be
+// referenced by other functions, e.g. "sin", to exploit the fact that
+// many OpenCL builtins share the same signature.
+//
+// The file generated by this TableGen emitter contains the following:
+//
+//  * Structs and enums to represent types and function signatures.
+//
+//  * OpenCLTypeStruct TypeTable[]
+//Type information for return types and arguments.
+//
+//  * unsigned SignatureTable[]
+//A list of types representing function signatures.  Each entry is an index
+//into the above TypeTable.  Multiple entries following each other form a
+//signature, where the first entry is the return type and subsequent
+//entries are the argument types.
+//
+//  * OpenCLBuiltinStruct BuiltinTable[]
+//Each entry represents one overload of an OpenCL builtin function and
+//consists of an index into the SignatureTable and the number of arguments.
+//
+//  * std::pair isOpenCLBuiltin(llvm::StringRef Name)
+//Find out whether a string matches an existing OpenCL builtin function
+//name and return an index into BuiltinTable and the number of overloads.
+//
+//  * void OCL2Qual(ASTContext&, OpenCLTypeStruct, std::vector&)
+//Convert an OpenCLTypeStruct type to a list of QualType instances.
+//One OpenCLTypeStruct can represent multiple types, primarily when using
+//GenTypes.
+//
 //===--===//
 
 #include "llvm/ADT/MapVector.h"
@@ -57,34 +84,52 @@
   // The output file.
   raw_ostream &OS;
 
-  // Emit the enums and structs.
+  // Helper function for BuiltinNameEmitter::EmitDeclarations.  Generate enum
+  // definitions in the Output string parameter, and save their Record instance
+  // in the List parameter.
+  // \param Types (in) List containing the Types to extract.
+  // \param TypesSeen (out) List containing the Types already extracted.
+  // \param Output (out) String containing the enums to emit in the output file.
+  // \param List (out) List to fill with the extracted types.
+  void ExtractEnumTypes(std::vector &Types,
+StringMap &TypesSeen, std::string &Output,
+std::vector &List);
+
+  // Emit the enum or struct used in the generated file.
+  // Populate the TypeList at the same time.
   void EmitDeclarations();
 
-  // Parse the Records generated by TableGen and populate OverloadInfo and
-  // SignatureSet.
+  // Parse the Records generated by TableGen to populate the SignaturesList,
+  // FctOverloadMap and TypeMap.
   void GetOverloads();
 
-  // Emit the OpenCLSignature table. This table contains all possible
-  // signatures, and is a struct OpenCLType. A signature is composed of a
-  // return type (mandatory), followed by zero or more argument types.
+  // Emit the TypeTable. This table contains all the possible types. A type can
+  // have several attributes (e.g. vector size, whether it is a pointer type,
+  // constness, ...).
+  // For example
+  //   {OCLT_Double, 2},
+  // is describing the type "Double", being a vector of 2 elements. See the
+  // struct OpenCLTypeStruct for 

[PATCH] D65456: [OpenCL] Add generic type handling for builtin functions

2019-07-30 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

Main changes since D63434 :

- Rename List* to Vec*.
- Rename TLnn -> TLAll, TLInt, TLFloat.
- Apply clang-format.
- Improve/update documentation.
- Factor out renaming of base types into separate commit.
- Change return type of OCL2Qual.
- Remove default case from OCL2Qual switch statement: it should be fully 
covering the enum.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65456/new/

https://reviews.llvm.org/D65456



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


[PATCH] D65456: [OpenCL] Add generic type handling for builtin functions

2019-08-07 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh marked 23 inline comments as done.
svenvh added a subscriber: Pierre.
svenvh added inline comments.



Comment at: clang/lib/Sema/OpenCLBuiltins.td:51
-// Helper class to store type access qualifiers (volatile, const, ...).
-class Qualifier {
-  string QualName = _QualName;

Anastasia wrote:
> Are the qualifiers added elsewhere?
Good point, this change should be part of the next patch (D63442).  I've taken 
it out of this patch.



Comment at: clang/lib/Sema/OpenCLBuiltins.td:221
+
+// GenType definitions.
+def FGenTypeN   : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;

Anastasia wrote:
> Is this float GenType?
We will be adding more definitions for integers here in followup patches.



Comment at: clang/lib/Sema/OpenCLBuiltins.td:222
+// GenType definitions.
+def FGenTypeN   : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
+// Generate basic GenTypes.  Names are like: GenTypeFloatVecAndScalar.

Anastasia wrote:
> Would it make sense to use the same name scheme as below?
No, because FGenType is for all floating point types (half / float / double), 
as it uses the `TLFloat` type list.  `GenTypeFloatVecAndScalar` is for the 
float type (i.e. fp32) only.

I will update the comments of both definitions to clarify the difference.



Comment at: clang/lib/Sema/SemaLookup.cpp:680
+/// \param OpenCLBuiltin (in) The signature currently handled.
+/// \param GenTypeMaxCnt (out) Maximum number of types contained in a generic
+///type used as return type or as argument.

Anastasia wrote:
> What if both return and args use GenType, does `GenTypeMaxCnt` return max of 
> all? Or do they have to align?
They have to be compatible, otherwise we will hit the `llvm_reachable` below.



Comment at: clang/lib/Sema/SemaLookup.cpp:708
+  }
+  for (unsigned Index = 0; Index < ArgTypes.size(); Index++) {
+unsigned TypeCntAtIndex = ArgTypes[Index].size();

Anastasia wrote:
> I don't get this logic?
While trying to clarify this, I realized this checking should probably be moved 
to the TableGen emitter, as this is checking validity of the .td input so 
ideally we should check that at compiler compile time.  @Pierre mentioned that 
this might not be trivial, but I'll have a look at it.



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:70
 namespace {
 class BuiltinNameEmitter {
 public:

Anastasia wrote:
> Perhaps not something for this patch, but I am wondering if a better name for 
> this class would be `OpenCLBuiltinTrieEmitter`?
It's emitting more than a trie; also tables and structs.  How about 
`OpenCLBuiltinEmitter` (which aligns nicely with the file name)?



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:94
+  // \param List (out) List to fill with the extracted types.
+  void ExtractEnumTypes(std::vector &Types,
+StringMap &TypesSeen, std::string &Output,

Anastasia wrote:
> I am a bit confused about the purpose of this function as input and output 
> seem to be both vectors of the Record. It might make sense to explain the 
> difference. :)
Clarified comment.



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:225
+
+  // Generic types are defined at the end of the enum.
+  std::vector GenTypes =

Anastasia wrote:
> I find this comment confusing... may be because it belongs to the code later. 
> I am not sure it adds any value.
Elaborated.



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:281
 auto it =
-std::find_if(SignatureSet.begin(), SignatureSet.end(),
+std::find_if(SignaturesList.begin(), SignaturesList.end(),
  [&](const std::pair, unsigned> &a) {

Anastasia wrote:
> Is this logic to avoid duplicate signatures? If so it might be worth 
> explaining it.
Added comment.



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:377
+// is returned.
+static void OCL2Qual(ASTContext &Context, const OpenCLTypeStruct &Ty,
+ std::vector &QT) {

Anastasia wrote:
> I feel it would be good to explain the structure of the function we are 
> trying to generate i.e something like:
> - We first generate switch/case statement over all type names that populates 
> the list of type IDs
> - Then we walk over the type IDs from the list and map them to the AST type 
> and attributes accordingly.
Added comment.



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:404
+// the plain scalar types for now; the ExtVector type will be added after
+// the switch statement such that it is only added for the case matching
+// the input to the OCL2Qual function.

Anastasia wrote:
> I am not sure what you

[PATCH] D65456: [OpenCL] Add generic type handling for builtin functions

2019-08-07 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh updated this revision to Diff 213904.
svenvh marked 9 inline comments as done.
svenvh added a comment.

Addressing review comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65456/new/

https://reviews.llvm.org/D65456

Files:
  clang/lib/Sema/OpenCLBuiltins.td
  clang/lib/Sema/SemaLookup.cpp
  clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
  clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Index: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
===
--- clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -15,12 +15,39 @@
 //
 // For a successful lookup of e.g. the "cos" builtin, isOpenCLBuiltin("cos")
 // returns a pair .
-// OpenCLBuiltins[Index] to OpenCLBuiltins[Index + Len] contains the pairs
+// BuiltinTable[Index] to BuiltinTable[Index + Len] contains the pairs
 //  of the overloads of "cos".
-// OpenCLSignature[SigIndex] to OpenCLSignature[SigIndex + SigLen] contains
-// one of the signatures of "cos". The OpenCLSignature entry can be
-// referenced by other functions, i.e. "sin", since multiple OpenCL builtins
-// share the same signature.
+// SignatureTable[SigIndex] to SignatureTable[SigIndex + SigLen] contains
+// one of the signatures of "cos". The SignatureTable entry can be
+// referenced by other functions, e.g. "sin", to exploit the fact that
+// many OpenCL builtins share the same signature.
+//
+// The file generated by this TableGen emitter contains the following:
+//
+//  * Structs and enums to represent types and function signatures.
+//
+//  * OpenCLTypeStruct TypeTable[]
+//Type information for return types and arguments.
+//
+//  * unsigned SignatureTable[]
+//A list of types representing function signatures.  Each entry is an index
+//into the above TypeTable.  Multiple entries following each other form a
+//signature, where the first entry is the return type and subsequent
+//entries are the argument types.
+//
+//  * OpenCLBuiltinStruct BuiltinTable[]
+//Each entry represents one overload of an OpenCL builtin function and
+//consists of an index into the SignatureTable and the number of arguments.
+//
+//  * std::pair isOpenCLBuiltin(llvm::StringRef Name)
+//Find out whether a string matches an existing OpenCL builtin function
+//name and return an index into BuiltinTable and the number of overloads.
+//
+//  * void OCL2Qual(ASTContext&, OpenCLTypeStruct, std::vector&)
+//Convert an OpenCLTypeStruct type to a list of QualType instances.
+//One OpenCLTypeStruct can represent multiple types, primarily when using
+//GenTypes.
+//
 //===--===//
 
 #include "llvm/ADT/MapVector.h"
@@ -57,34 +84,47 @@
   // The output file.
   raw_ostream &OS;
 
-  // Emit the enums and structs.
+  // Helper function for BuiltinNameEmitter::EmitDeclarations.  Generate enum
+  // definitions in the Output string parameter, and save their Record instances
+  // in the List parameter.
+  // \param Types (in) List containing the Types to extract.
+  // \param TypesSeen (inout) List containing the Types already extracted.
+  // \param Output (out) String containing the enums to emit in the output file.
+  // \param List (out) List containing the extracted Types, except the Types in
+  //TypesSeen.
+  void ExtractEnumTypes(std::vector &Types,
+StringMap &TypesSeen, std::string &Output,
+std::vector &List);
+
+  // Emit the enum or struct used in the generated file.
+  // Populate the TypeList at the same time.
   void EmitDeclarations();
 
-  // Parse the Records generated by TableGen and populate OverloadInfo and
-  // SignatureSet.
+  // Parse the Records generated by TableGen to populate the SignaturesList,
+  // FctOverloadMap and TypeMap.
   void GetOverloads();
 
-  // Emit the OpenCLSignature table. This table contains all possible
-  // signatures, and is a struct OpenCLType. A signature is composed of a
-  // return type (mandatory), followed by zero or more argument types.
+  // Emit the TypeTable containing all types used by OpenCL builtins.
+  void EmitTypeTable();
+
+  // Emit the SignatureTable. This table contains all the possible signatures.
+  // A signature is stored as a list of indexes of the TypeTable.
+  // The first index references the return type (mandatory), and the followings
+  // reference its arguments.
   // E.g.:
-  // // 12
-  // { OCLT_uchar, 4, clang::LangAS::Default, false },
-  // { OCLT_float, 4, clang::LangAS::Default, false },
-  // This means that index 12 represents a signature
-  //   - returning a uchar vector of 4 elements, and
-  //   - taking as first argument a float vector of 4 elements.
+  // 15, 2, 15 can represent a function with the signature:
+  // int func(float, int)
+  // The "int" type being at the index 15 in the TypeTable.
   void Emit

[PATCH] D65941: [OpenCL] Fix lang mode predefined macros for C++ mode

2019-08-08 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh accepted this revision.
svenvh added a comment.
This revision is now accepted and ready to land.

LGTM!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65941/new/

https://reviews.llvm.org/D65941



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


[PATCH] D65456: [OpenCL] Add generic type handling for builtin functions

2019-08-08 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh updated this revision to Diff 214169.
svenvh added a comment.

- Move checking of GenType compatibility from SemaLookup to TableGen emitter.
- Provide more elaborate explanation about combining GenTypes in a declaration.
- Add `max`/`min` definitions to cover "sgentype" behavior and add test for 
`max`.
- Minor scattered comment improvements.

Combining GenTypes in an incorrect way will now produce an error from TableGen, 
e.g.:

  OpenCLBuiltins.td:1601:1: error: number of vector sizes should be equal or 1 
for all gentypes in a declaration
  def : Builtin<"crashme", [GenTypeFloatVecNoScalar, GenTypeFloatVecAndScalar]>
  ^
  
  OpenCLBuiltins.td:1602:1: error: number of types should be equal or 1 for all 
gentypes in a declaration
  def : Builtin<"crashme2", [IGenTypeN, FGenTypeN]>;
  ^


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65456/new/

https://reviews.llvm.org/D65456

Files:
  clang/lib/Sema/OpenCLBuiltins.td
  clang/lib/Sema/SemaLookup.cpp
  clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
  clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Index: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
===
--- clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -15,12 +15,39 @@
 //
 // For a successful lookup of e.g. the "cos" builtin, isOpenCLBuiltin("cos")
 // returns a pair .
-// OpenCLBuiltins[Index] to OpenCLBuiltins[Index + Len] contains the pairs
+// BuiltinTable[Index] to BuiltinTable[Index + Len] contains the pairs
 //  of the overloads of "cos".
-// OpenCLSignature[SigIndex] to OpenCLSignature[SigIndex + SigLen] contains
-// one of the signatures of "cos". The OpenCLSignature entry can be
-// referenced by other functions, i.e. "sin", since multiple OpenCL builtins
-// share the same signature.
+// SignatureTable[SigIndex] to SignatureTable[SigIndex + SigLen] contains
+// one of the signatures of "cos". The SignatureTable entry can be
+// referenced by other functions, e.g. "sin", to exploit the fact that
+// many OpenCL builtins share the same signature.
+//
+// The file generated by this TableGen emitter contains the following:
+//
+//  * Structs and enums to represent types and function signatures.
+//
+//  * OpenCLTypeStruct TypeTable[]
+//Type information for return types and arguments.
+//
+//  * unsigned SignatureTable[]
+//A list of types representing function signatures.  Each entry is an index
+//into the above TypeTable.  Multiple entries following each other form a
+//signature, where the first entry is the return type and subsequent
+//entries are the argument types.
+//
+//  * OpenCLBuiltinStruct BuiltinTable[]
+//Each entry represents one overload of an OpenCL builtin function and
+//consists of an index into the SignatureTable and the number of arguments.
+//
+//  * std::pair isOpenCLBuiltin(llvm::StringRef Name)
+//Find out whether a string matches an existing OpenCL builtin function
+//name and return an index into BuiltinTable and the number of overloads.
+//
+//  * void OCL2Qual(ASTContext&, OpenCLTypeStruct, std::vector&)
+//Convert an OpenCLTypeStruct type to a list of QualType instances.
+//One OpenCLTypeStruct can represent multiple types, primarily when using
+//GenTypes.
+//
 //===--===//
 
 #include "llvm/ADT/MapVector.h"
@@ -57,34 +84,47 @@
   // The output file.
   raw_ostream &OS;
 
-  // Emit the enums and structs.
+  // Helper function for BuiltinNameEmitter::EmitDeclarations.  Generate enum
+  // definitions in the Output string parameter, and save their Record instances
+  // in the List parameter.
+  // \param Types (in) List containing the Types to extract.
+  // \param TypesSeen (inout) List containing the Types already extracted.
+  // \param Output (out) String containing the enums to emit in the output file.
+  // \param List (out) List containing the extracted Types, except the Types in
+  //TypesSeen.
+  void ExtractEnumTypes(std::vector &Types,
+StringMap &TypesSeen, std::string &Output,
+std::vector &List);
+
+  // Emit the enum or struct used in the generated file.
+  // Populate the TypeList at the same time.
   void EmitDeclarations();
 
-  // Parse the Records generated by TableGen and populate OverloadInfo and
-  // SignatureSet.
+  // Parse the Records generated by TableGen to populate the SignaturesList,
+  // FctOverloadMap and TypeMap.
   void GetOverloads();
 
-  // Emit the OpenCLSignature table. This table contains all possible
-  // signatures, and is a struct OpenCLType. A signature is composed of a
-  // return type (mandatory), followed by zero or more argument types.
+  // Emit the TypeTable containing all types used by OpenCL builtins.
+  void EmitTypeTable();
+
+  // Emit the SignatureTable. This table contains all the pos

[PATCH] D65456: [OpenCL] Add generic type handling for builtin functions

2019-08-08 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh marked 6 inline comments as done.
svenvh added inline comments.



Comment at: clang/lib/Sema/OpenCLBuiltins.td:116
+// combination of Types and vector sizes.
+//
+// E.g.: If TypeListField =  and VectorList = <1, 2, 4>, then

Pierre wrote:
> Maybe it would be worth adding more information on how to use GenTypes. I was 
> thinking of something like this : 
> 
> When using multiple generic types :
>   * The maximal cardinal of the used  GenTypes must be the PGCM of all the 
> cardinals.
>   * The generic types combine as if it was an array like 
> GenType[Type][VecSize].
> I.e: With GT1 = [half, <1, 2>] and GT2 = [float, int, <1, 2>], they will 
> combine as
> , , , 
> The maximal cardinal of GT1 and GT2 is 4 (= 2 types * 2 vector sizes).
> 4 is the PGCM of GT1 (=2) and GT2 (=4).
I've added some rules about combining GenTypes in the comment below based on 
your example.



Comment at: clang/lib/Sema/SemaLookup.cpp:708
+  }
+  for (unsigned Index = 0; Index < ArgTypes.size(); Index++) {
+unsigned TypeCntAtIndex = ArgTypes[Index].size();

svenvh wrote:
> Anastasia wrote:
> > I don't get this logic?
> While trying to clarify this, I realized this checking should probably be 
> moved to the TableGen emitter, as this is checking validity of the .td input 
> so ideally we should check that at compiler compile time.  @Pierre mentioned 
> that this might not be trivial, but I'll have a look at it.
The checking has been moved into `ClangOpenCLBuiltinEmitter.cpp` now, see 
`VerifySignature`.



Comment at: clang/lib/Sema/SemaLookup.cpp:817
   }
-  New->setParams(Params);
+  NewOpenCLBuiltin->addAttr(OverloadableAttr::CreateImplicit(Context));
+  LR.addDecl(NewOpenCLBuiltin);

Anastasia wrote:
> I guess this should be done conditionally for C++ mode. But perhaps we don't 
> have to do this now. It might be worth adding a FIXME.
Done.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65456/new/

https://reviews.llvm.org/D65456



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


[PATCH] D66080: [OpenCL] Ignore parentheses for sampler initialization

2019-08-12 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: Anastasia.
Herald added subscribers: cfe-commits, yaxunl.
Herald added a project: clang.

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.


Repository:
  rC Clang

https://reviews.llvm.org/D66080

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaOpenCL/sampler_t.cl


Index: clang/test/SemaOpenCL/sampler_t.cl
===
--- clang/test/SemaOpenCL/sampler_t.cl
+++ clang/test/SemaOpenCL/sampler_t.cl
@@ -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 @@
   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);
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -8248,7 +8248,7 @@
   // 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()) {


Index: clang/test/SemaOpenCL/sampler_t.cl
===
--- clang/test/SemaOpenCL/sampler_t.cl
+++ clang/test/SemaOpenCL/sampler_t.cl
@@ -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 @@
   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);
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -8248,7 +8248,7 @@
   // 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()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66080: [OpenCL] Ignore parentheses for sampler initialization

2019-08-12 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368561: [OpenCL] Ignore parentheses for sampler 
initialization (authored by svenvh, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66080?vs=214602&id=214611#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66080/new/

https://reviews.llvm.org/D66080

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


Index: cfe/trunk/test/SemaOpenCL/sampler_t.cl
===
--- cfe/trunk/test/SemaOpenCL/sampler_t.cl
+++ cfe/trunk/test/SemaOpenCL/sampler_t.cl
@@ -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 @@
   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);
+}
Index: cfe/trunk/lib/Sema/SemaInit.cpp
===
--- cfe/trunk/lib/Sema/SemaInit.cpp
+++ cfe/trunk/lib/Sema/SemaInit.cpp
@@ -8248,7 +8248,7 @@
   // 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()) {


Index: cfe/trunk/test/SemaOpenCL/sampler_t.cl
===
--- cfe/trunk/test/SemaOpenCL/sampler_t.cl
+++ cfe/trunk/test/SemaOpenCL/sampler_t.cl
@@ -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 @@
   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);
+}
Index: cfe/trunk/lib/Sema/SemaInit.cpp
===
--- cfe/trunk/lib/Sema/SemaInit.cpp
+++ cfe/trunk/lib/Sema/SemaInit.cpp
@@ -8248,7 +8248,7 @@
   // 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()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65456: [OpenCL] Add generic type handling for builtin functions

2019-08-14 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: clang/lib/Sema/OpenCLBuiltins.td:222
+// GenType definitions.
+def FGenTypeN   : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
+// Generate basic GenTypes.  Names are like: GenTypeFloatVecAndScalar.

Anastasia wrote:
> svenvh wrote:
> > Anastasia wrote:
> > > Would it make sense to use the same name scheme as below?
> > No, because FGenType is for all floating point types (half / float / 
> > double), as it uses the `TLFloat` type list.  `GenTypeFloatVecAndScalar` is 
> > for the float type (i.e. fp32) only.
> > 
> > I will update the comments of both definitions to clarify the difference.
> Ok, it could though be
> 
> `GenTypeAllFloats`
> 
> `GenTypeF`
> 
> Just that naming scheme feels a bit random right now.
The convention is a bit subtle perhaps, but it is not random.  For manual 
definitions that have multiple base types, the convention is 
typeinfo#GenType#vecinfo.  For generated definitions that have a single base 
type, the convention is GenType#typeinfo#vecinfo.  Having different conventions 
prevents the manual definitions from colliding with the generated ones.



Comment at: clang/lib/Sema/OpenCLBuiltins.td:124
+//
+// Some rules apply for combining GenericTypes in a declaration:
+//   1. The number of vector sizes must be equal or 1 for all gentypes in a

Anastasia wrote:
> What does combining mean?
Clarified.



Comment at: clang/lib/Sema/SemaLookup.cpp:680
+/// \param OpenCLBuiltin (in) The signature currently handled.
+/// \param GenTypeMaxCnt (out) Maximum number of types contained in a generic
+///type used as return type or as argument.

Anastasia wrote:
> svenvh wrote:
> > Anastasia wrote:
> > > What if both return and args use GenType, does `GenTypeMaxCnt` return max 
> > > of all? Or do they have to align?
> > They have to be compatible, otherwise we will hit the `llvm_reachable` 
> > below.
> Do we say anywhere they have to be compatible?
Yes, in OpenCLBuiltins.td near the definition of `GenericType`.



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:261
+// a signature to contain different GenTypes if these GenTypes represent
+// the same number of actual types.
+//

Anastasia wrote:
> I feel what you are checking is whether the vector sizes and types match but 
> not just that the number of types match...
"actual types" here means "final" non-generic types, such as half2, int, 
short4, etc.

Rephrased as "actual scalar or vector types", does that help?



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:265
+static void VerifySignature(const std::vector &Signature,
+const Record *B) {
+  unsigned GenTypeVecSizes = 1;

Anastasia wrote:
> Can we rename B to something meaningful or add a comment explaining it?
Renamed to `BuiltinRec`.



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:269
+
+  for (const auto *T : Signature) {
+if (T->isSubClassOf("GenericType")) {

Anastasia wrote:
> I feel there is some black magic here. :)
Added some comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65456/new/

https://reviews.llvm.org/D65456



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


[PATCH] D65456: [OpenCL] Add generic type handling for builtin functions

2019-08-14 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh updated this revision to Diff 215086.
svenvh marked 15 inline comments as done.
svenvh added a comment.

- Update comments as per review comments.
- Rename iterator `List` to `VecSizes` in OpenCLBuiltins.td
- Format GenericType definition.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65456/new/

https://reviews.llvm.org/D65456

Files:
  clang/lib/Sema/OpenCLBuiltins.td
  clang/lib/Sema/SemaLookup.cpp
  clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
  clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Index: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
===
--- clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -15,12 +15,39 @@
 //
 // For a successful lookup of e.g. the "cos" builtin, isOpenCLBuiltin("cos")
 // returns a pair .
-// OpenCLBuiltins[Index] to OpenCLBuiltins[Index + Len] contains the pairs
+// BuiltinTable[Index] to BuiltinTable[Index + Len] contains the pairs
 //  of the overloads of "cos".
-// OpenCLSignature[SigIndex] to OpenCLSignature[SigIndex + SigLen] contains
-// one of the signatures of "cos". The OpenCLSignature entry can be
-// referenced by other functions, i.e. "sin", since multiple OpenCL builtins
-// share the same signature.
+// SignatureTable[SigIndex] to SignatureTable[SigIndex + SigLen] contains
+// one of the signatures of "cos". The SignatureTable entry can be
+// referenced by other functions, e.g. "sin", to exploit the fact that
+// many OpenCL builtins share the same signature.
+//
+// The file generated by this TableGen emitter contains the following:
+//
+//  * Structs and enums to represent types and function signatures.
+//
+//  * OpenCLTypeStruct TypeTable[]
+//Type information for return types and arguments.
+//
+//  * unsigned SignatureTable[]
+//A list of types representing function signatures.  Each entry is an index
+//into the above TypeTable.  Multiple entries following each other form a
+//signature, where the first entry is the return type and subsequent
+//entries are the argument types.
+//
+//  * OpenCLBuiltinStruct BuiltinTable[]
+//Each entry represents one overload of an OpenCL builtin function and
+//consists of an index into the SignatureTable and the number of arguments.
+//
+//  * std::pair isOpenCLBuiltin(llvm::StringRef Name)
+//Find out whether a string matches an existing OpenCL builtin function
+//name and return an index into BuiltinTable and the number of overloads.
+//
+//  * void OCL2Qual(ASTContext&, OpenCLTypeStruct, std::vector&)
+//Convert an OpenCLTypeStruct type to a list of QualType instances.
+//One OpenCLTypeStruct can represent multiple types, primarily when using
+//GenTypes.
+//
 //===--===//
 
 #include "llvm/ADT/MapVector.h"
@@ -57,34 +84,47 @@
   // The output file.
   raw_ostream &OS;
 
-  // Emit the enums and structs.
+  // Helper function for BuiltinNameEmitter::EmitDeclarations.  Generate enum
+  // definitions in the Output string parameter, and save their Record instances
+  // in the List parameter.
+  // \param Types (in) List containing the Types to extract.
+  // \param TypesSeen (inout) List containing the Types already extracted.
+  // \param Output (out) String containing the enums to emit in the output file.
+  // \param List (out) List containing the extracted Types, except the Types in
+  //TypesSeen.
+  void ExtractEnumTypes(std::vector &Types,
+StringMap &TypesSeen, std::string &Output,
+std::vector &List);
+
+  // Emit the enum or struct used in the generated file.
+  // Populate the TypeList at the same time.
   void EmitDeclarations();
 
-  // Parse the Records generated by TableGen and populate OverloadInfo and
-  // SignatureSet.
+  // Parse the Records generated by TableGen to populate the SignaturesList,
+  // FctOverloadMap and TypeMap.
   void GetOverloads();
 
-  // Emit the OpenCLSignature table. This table contains all possible
-  // signatures, and is a struct OpenCLType. A signature is composed of a
-  // return type (mandatory), followed by zero or more argument types.
+  // Emit the TypeTable containing all types used by OpenCL builtins.
+  void EmitTypeTable();
+
+  // Emit the SignatureTable. This table contains all the possible signatures.
+  // A signature is stored as a list of indexes of the TypeTable.
+  // The first index references the return type (mandatory), and the followings
+  // reference its arguments.
   // E.g.:
-  // // 12
-  // { OCLT_uchar, 4, clang::LangAS::Default, false },
-  // { OCLT_float, 4, clang::LangAS::Default, false },
-  // This means that index 12 represents a signature
-  //   - returning a uchar vector of 4 elements, and
-  //   - taking as first argument a float vector of 4 elements.
+  // 15, 2, 15 can represent a function with the sig

[PATCH] D64418: [Docs][OpenCL] Documentation of C++ for OpenCL mode

2019-08-15 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: docs/LanguageExtensions.rst:1561
+s3.1.3). For OpenCL it means that implicit conversions are allowed from
+named address space except for ``__constant`` to ``__generic`` address space
+that is a superset of all others except for ``__constant`` (OpenCL C v2.0

"For OpenCL it means that implicit conversions are allowed from a ​named 
address space except for conversion from the ``__constant`` to the 
``__generic`` address space."

I would omit "that is a superset of all others except for ``__constant``" as 
that is already documented in the OpenCL spec and it might confuse readers 
here.  If you want to keep it, I suggest rephrasing it as a separate sentence.



Comment at: docs/LanguageExtensions.rst:1563
+that is a superset of all others except for ``__constant`` (OpenCL C v2.0
+s6.5.5). Reverse conversion is only allowed explicitly.  ``__constant``
+address space does not overlap with any other and therefore no valid conversion

+The+ ``__constant`` address space



Comment at: docs/LanguageExtensions.rst:1570
+
+C style cast will follow OpenCL C v2.0 rules (s6.5.5). All cast operators will
+permit conversion to ``__generic`` implicitly. However converting from

"C-style casts follow"



Comment at: docs/LanguageExtensions.rst:1630
+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

+the+ ``__generic`` address space

(also in the next few lines)



Comment at: docs/LanguageExtensions.rst:1647
+
+Clang allows specifying address space qualifier on member functions to signal 
that
+they are to be used with objects constructed in some specific address space. 
This

+an+ address space qualifier



Comment at: docs/LanguageExtensions.rst:1650
+works just the same as qualifying member functions with ``const`` or any other
+qualifiers. The overloading resolution will select ithe overload with most 
specific
+address space if multiple candidates are provided. If there is no conversion to

ithe -> the



Comment at: docs/LanguageExtensions.rst:1651
+qualifiers. The overloading resolution will select ithe overload with most 
specific
+address space if multiple candidates are provided. If there is no conversion to
+to an address space among existing overloads compilation will fail with a

Duplicate "to" (to to)



Comment at: docs/LanguageExtensions.rst:1652
+address space if multiple candidates are provided. If there is no conversion to
+to an address space among existing overloads compilation will fail with a
+diagnostic.

Add comma:
... overloads, compilation ...



Comment at: docs/LanguageExtensions.rst:1715
+definition and instantiation. If multiple different address spaces are 
specified in
+template definition and instantiation compilation of such a program will fail 
with a
+diagnostic.

Add comma:
... instantiation, compilation ...



Comment at: docs/LanguageExtensions.rst:1730
+
+Once template is instantiated regular restrictions for address spaces will 
apply.
+

Once a template has been instantiated, regular restrictions for address spaces 
will apply.



Comment at: docs/LanguageExtensions.rst:1746
+
+All temporaries are materialized in ``__private`` address space. If a reference
+with some other address space is bound to them, the conversion will be 
generated

the ``__private`` address space



Comment at: docs/LanguageExtensions.rst:1747
+All temporaries are materialized in ``__private`` address space. If a reference
+with some other address space is bound to them, the conversion will be 
generated
+in case it's valid otherwise compilation will fail with a diagnostic.

some other -> another



Comment at: docs/LanguageExtensions.rst:1748
+with some other address space is bound to them, the conversion will be 
generated
+in case it's valid otherwise compilation will fail with a diagnostic.
+

it's -> it is

add comma:
... valid, otherwise ...



Comment at: docs/LanguageExtensions.rst:1776
+API for invoking global constructors. However, an easy workaround would be
+to enqueue constructor initialization kernel that has a name
+``@_GLOBAL__sub_I_``. This kernel is only present if there

enqueue *a* constructor



Comment at: docs/LanguageExtensions.rst:1782
+
+Note that if multiple files are compiled and linked into libraries multiple
+kernels that initialize global objects for multiple modules would have to be
-

[PATCH] D66294: [Docs][OpenCL] Release 9.0 notes for OpenCL

2019-08-15 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: docs/ReleaseNotes.rst:173
+
+- Added initial support for implicitly including OpenCL BIFs using
+  efficient trie lookup generated by TableGen. A corresponding

mantognini wrote:
> If the BIF acronym wasn't introduced before, it should be replaced with 
> "builtin functions". It seems we don't have more file context in this review 
> so I cannot tell.
BIFs -> built-in functions



Comment at: docs/ReleaseNotes.rst:175
+  efficient trie lookup generated by TableGen. A corresponding
+  frontend only flag ``-fadd-opencl-builtins`` has been added to
+  enable trie during parsing.

mantognini wrote:
> I'm not 100% sure about the grammar rule in English, but shouldn't there be a 
> "-" between "frontend" and "only" here to make it an adjective-ish?
The flag is called `-fdeclare-opencl-builtins` (not -fadd...).



Comment at: docs/ReleaseNotes.rst:176
+  frontend only flag ``-fadd-opencl-builtins`` has been added to
+  enable trie during parsing.
+

The option does not only "enable a trie" during parsing.  I'd suggest to just 
drop "to enable trie during parsing".



Comment at: docs/ReleaseNotes.rst:179
+- Refactored header file to be used for common parts between
+  regular header and TableGen trie.
+

Refactored the `opencl-c.h` header file ...

TableGen trie -> `-fdeclare-opencl-builtins`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66294/new/

https://reviews.llvm.org/D66294



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


[PATCH] D66137: [OpenCL][PR42385] Improve addr space deduction for pointers/references to arrays

2019-08-19 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh accepted this revision.
svenvh added a comment.
This revision is now accepted and ready to land.

LGTM, but please clang-format your patch before committing (esp. spacing around 
binary operators).




Comment at: lib/Sema/SemaType.cpp:7396
+  // For pointers/references to arrays the next chunk is always an array
+  // followed by any number of parenthesis.
+  if (!IsPointee && ChunkIndex > 1) {

parentheses (also below).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66137/new/

https://reviews.llvm.org/D66137



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


[PATCH] D65456: [OpenCL] Add generic type handling for builtin functions

2019-08-19 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369253: [OpenCL] Add generic type handling for builtin 
functions (authored by svenvh, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65456?vs=215086&id=215859#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65456/new/

https://reviews.llvm.org/D65456

Files:
  cfe/trunk/lib/Sema/OpenCLBuiltins.td
  cfe/trunk/lib/Sema/SemaLookup.cpp
  cfe/trunk/test/SemaOpenCL/fdeclare-opencl-builtins.cl
  cfe/trunk/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Index: cfe/trunk/lib/Sema/SemaLookup.cpp
===
--- cfe/trunk/lib/Sema/SemaLookup.cpp
+++ cfe/trunk/lib/Sema/SemaLookup.cpp
@@ -673,76 +673,148 @@
 D->dump();
 }
 
-/// When trying to resolve a function name, if the isOpenCLBuiltin function
-/// defined in "OpenCLBuiltins.inc" returns a non-null , then the
-/// identifier is referencing an OpenCL builtin function. Thus, all its
-/// prototypes are added to the LookUpResult.
-///
-/// \param S The Sema instance
-/// \param LR  The LookupResult instance
-/// \param II  The identifier being resolved
-/// \param Index  The list of prototypes starts at Index in OpenCLBuiltins[]
-/// \param Len  The list of prototypes has Len elements
-static void InsertOCLBuiltinDeclarations(Sema &S, LookupResult &LR,
- IdentifierInfo *II, unsigned Index,
- unsigned Len) {
-
-  for (unsigned i = 0; i < Len; ++i) {
-const OpenCLBuiltinDecl &Decl = OpenCLBuiltins[Index - 1 + i];
-ASTContext &Context = S.Context;
+/// Get the QualType instances of the return type and arguments for an OpenCL
+/// builtin function signature.
+/// \param Context (in) The Context instance.
+/// \param OpenCLBuiltin (in) The signature currently handled.
+/// \param GenTypeMaxCnt (out) Maximum number of types contained in a generic
+///type used as return type or as argument.
+///Only meaningful for generic types, otherwise equals 1.
+/// \param RetTypes (out) List of the possible return types.
+/// \param ArgTypes (out) List of the possible argument types.  For each
+///argument, ArgTypes contains QualTypes for the Cartesian product
+///of (vector sizes) x (types) .
+static void GetQualTypesForOpenCLBuiltin(
+ASTContext &Context, const OpenCLBuiltinStruct &OpenCLBuiltin,
+unsigned &GenTypeMaxCnt, std::vector &RetTypes,
+SmallVector, 5> &ArgTypes) {
+  // Get the QualType instances of the return types.
+  unsigned Sig = SignatureTable[OpenCLBuiltin.SigTableIndex];
+  OCL2Qual(Context, TypeTable[Sig], RetTypes);
+  GenTypeMaxCnt = RetTypes.size();
+
+  // Get the QualType instances of the arguments.
+  // First type is the return type, skip it.
+  for (unsigned Index = 1; Index < OpenCLBuiltin.NumTypes; Index++) {
+std::vector Ty;
+OCL2Qual(Context,
+TypeTable[SignatureTable[OpenCLBuiltin.SigTableIndex + Index]], Ty);
+ArgTypes.push_back(Ty);
+GenTypeMaxCnt = (Ty.size() > GenTypeMaxCnt) ? Ty.size() : GenTypeMaxCnt;
+  }
+}
 
-// Ignore this BIF if the version is incorrect.
-if (Context.getLangOpts().OpenCLVersion < Decl.Version)
-  continue;
+/// Create a list of the candidate function overloads for an OpenCL builtin
+/// function.
+/// \param Context (in) The ASTContext instance.
+/// \param GenTypeMaxCnt (in) Maximum number of types contained in a generic
+///type used as return type or as argument.
+///Only meaningful for generic types, otherwise equals 1.
+/// \param FunctionList (out) List of FunctionTypes.
+/// \param RetTypes (in) List of the possible return types.
+/// \param ArgTypes (in) List of the possible types for the arguments.
+static void
+GetOpenCLBuiltinFctOverloads(ASTContext &Context, unsigned GenTypeMaxCnt,
+ std::vector &FunctionList,
+ std::vector &RetTypes,
+ SmallVector, 5> &ArgTypes) {
+  FunctionProtoType::ExtProtoInfo PI;
+  PI.Variadic = false;
+
+  // Create FunctionTypes for each (gen)type.
+  for (unsigned IGenType = 0; IGenType < GenTypeMaxCnt; IGenType++) {
+SmallVector ArgList;
+
+for (unsigned A = 0; A < ArgTypes.size(); A++) {
+  // Builtins such as "max" have an "sgentype" argument that represents
+  // the corresponding scalar type of a gentype.  The number of gentypes
+  // must be a multiple of the number of sgentypes.
+  assert(GenTypeMaxCnt % ArgTypes[A].size() == 0 &&
+ "argument type count not compatible with gentype type count");
+  unsigned Idx = IGenType % ArgTypes[A].size();
+  ArgList.push_back(ArgTypes[A][Idx]);
+}
+
+FunctionList.push_back(Context.getFunctionType(
+RetTypes[(RetTypes.size() != 1) ? IGenType : 

[PATCH] D64418: [Docs][OpenCL] Documentation of C++ for OpenCL mode

2019-08-19 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh accepted this revision.
svenvh added a comment.

LGTM!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64418/new/

https://reviews.llvm.org/D64418



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


[PATCH] D59673: [Clang] Harmonize Split DWARF options with llc

2019-06-21 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

As a followup to r363496, I've added llvm-dwarfdump as a clang test dependency 
in r364021.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59673/new/

https://reviews.llvm.org/D59673



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


[PATCH] D63256: [OpenCL] Split type and macro definitions into opencl-c-base.h

2019-06-24 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh marked 3 inline comments as done.
svenvh added inline comments.



Comment at: cfe/trunk/lib/Headers/opencl-c.h:13638-13640
-#ifndef ATOMIC_VAR_INIT
-#define ATOMIC_VAR_INIT(x) (x)
-#endif //ATOMIC_VAR_INIT

yaxunl wrote:
> kzhuravl wrote:
> > Any reason this piece of code got completely removed?
> Removing ATOMIC_VAR_INIT caused regression in our compiler.
> 
> Could you please put it back?
> 
> Thanks.
Apologies, that was not intended; thanks for reporting!  Restored the macro in 
r364174 together with a test.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63256/new/

https://reviews.llvm.org/D63256



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


[PATCH] D63561: [OpenCL] Improve diagnostic for placement new

2019-06-26 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL364423: [OpenCL] Improve diagnostic for placement new 
(authored by svenvh, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63561?vs=205611&id=206650#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63561/new/

https://reviews.llvm.org/D63561

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaExprCXX.cpp
  cfe/trunk/test/SemaOpenCLCXX/newdelete.cl


Index: cfe/trunk/lib/Sema/SemaExprCXX.cpp
===
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp
@@ -2413,7 +2413,11 @@
 }
 
 if (getLangOpts().OpenCLCPlusPlus && R.empty()) {
-  Diag(StartLoc, diag::err_openclcxx_not_supported) << "default new";
+  if (PlaceArgs.empty()) {
+Diag(StartLoc, diag::err_openclcxx_not_supported) << "default new";
+  } else {
+Diag(StartLoc, diag::err_openclcxx_placement_new);
+  }
   return true;
 }
 
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8809,6 +8809,9 @@
   "vector component name '%0' is an OpenCL version 2.2 feature">,
   InGroup;
 
+def err_openclcxx_placement_new : Error<
+  "use of placement new requires explicit declaration">;
+
 // MIG routine annotations.
 def warn_mig_server_routine_does_not_return_kern_return_t : Warning<
   "'mig_server_routine' attribute only applies to routines that return a 
kern_return_t">,
Index: cfe/trunk/test/SemaOpenCLCXX/newdelete.cl
===
--- cfe/trunk/test/SemaOpenCLCXX/newdelete.cl
+++ cfe/trunk/test/SemaOpenCLCXX/newdelete.cl
@@ -21,7 +21,7 @@
 void test_default_new_delete(void *buffer, A **pa) {
   A *a = new A; // expected-error {{'default new' is not supported in 
OpenCL C++}}
   delete a; // expected-error {{'default delete' is not supported 
in OpenCL C++}}
-  *pa = new (buffer) A; // expected-error {{'default new' is not supported in 
OpenCL C++}}
+  *pa = new (buffer) A; // expected-error {{use of placement new requires 
explicit declaration}}
 }
 
 // expected-note@+1 {{candidate function not viable: requires 2 arguments, but 
1 was provided}}


Index: cfe/trunk/lib/Sema/SemaExprCXX.cpp
===
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp
@@ -2413,7 +2413,11 @@
 }
 
 if (getLangOpts().OpenCLCPlusPlus && R.empty()) {
-  Diag(StartLoc, diag::err_openclcxx_not_supported) << "default new";
+  if (PlaceArgs.empty()) {
+Diag(StartLoc, diag::err_openclcxx_not_supported) << "default new";
+  } else {
+Diag(StartLoc, diag::err_openclcxx_placement_new);
+  }
   return true;
 }
 
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8809,6 +8809,9 @@
   "vector component name '%0' is an OpenCL version 2.2 feature">,
   InGroup;
 
+def err_openclcxx_placement_new : Error<
+  "use of placement new requires explicit declaration">;
+
 // MIG routine annotations.
 def warn_mig_server_routine_does_not_return_kern_return_t : Warning<
   "'mig_server_routine' attribute only applies to routines that return a kern_return_t">,
Index: cfe/trunk/test/SemaOpenCLCXX/newdelete.cl
===
--- cfe/trunk/test/SemaOpenCLCXX/newdelete.cl
+++ cfe/trunk/test/SemaOpenCLCXX/newdelete.cl
@@ -21,7 +21,7 @@
 void test_default_new_delete(void *buffer, A **pa) {
   A *a = new A; // expected-error {{'default new' is not supported in OpenCL C++}}
   delete a; // expected-error {{'default delete' is not supported in OpenCL C++}}
-  *pa = new (buffer) A; // expected-error {{'default new' is not supported in OpenCL C++}}
+  *pa = new (buffer) A; // expected-error {{use of placement new requires explicit declaration}}
 }
 
 // expected-note@+1 {{candidate function not viable: requires 2 arguments, but 1 was provided}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63876: [OpenCL] Define CLK_NULL_EVENT without cast

2019-06-27 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added reviewers: Anastasia, yaxunl.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Defining CLK_NULL_EVENT with a `(void*)` cast has the (unintended?)
side-effect that the address space will be fixed (as generic in OpenCL
2.0 mode).  The consequence is that any target specific address space
for the clk_event_t type will not be applied.

It is not clear why the void pointer cast was needed in the first
place, and it seems we can do without it.


Repository:
  rC Clang

https://reviews.llvm.org/D63876

Files:
  lib/Headers/opencl-c-base.h
  test/SemaOpenCL/clk_event_t.cl


Index: test/SemaOpenCL/clk_event_t.cl
===
--- test/SemaOpenCL/clk_event_t.cl
+++ test/SemaOpenCL/clk_event_t.cl
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=c++
 
 // Taken from opencl-c.h
-#define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
+#define CLK_NULL_EVENT (__builtin_astype(((__SIZE_MAX__)), clk_event_t))
 
 global clk_event_t ce; // expected-error {{the '__global clk_event_t' type 
cannot be used to declare a program scope variable}}
 
@@ -10,6 +10,7 @@
   event_t e;
   clk_event_t ce1;
   clk_event_t ce2;
+  clk_event_t ce3 = CLK_NULL_EVENT;
 
   if (e == ce1) { // expected-error {{invalid operands to binary expression 
('event_t' and 'clk_event_t')}}
 return 9;
Index: lib/Headers/opencl-c-base.h
===
--- lib/Headers/opencl-c-base.h
+++ lib/Headers/opencl-c-base.h
@@ -413,7 +413,7 @@
 #define CLK_OUT_OF_RESOURCES-5
 
 #define CLK_NULL_QUEUE  0
-#define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
+#define CLK_NULL_EVENT (__builtin_astype(((__SIZE_MAX__)), clk_event_t))
 
 // execution model related definitions
 #define CLK_ENQUEUE_FLAGS_NO_WAIT   0x0


Index: test/SemaOpenCL/clk_event_t.cl
===
--- test/SemaOpenCL/clk_event_t.cl
+++ test/SemaOpenCL/clk_event_t.cl
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=c++
 
 // Taken from opencl-c.h
-#define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
+#define CLK_NULL_EVENT (__builtin_astype(((__SIZE_MAX__)), clk_event_t))
 
 global clk_event_t ce; // expected-error {{the '__global clk_event_t' type cannot be used to declare a program scope variable}}
 
@@ -10,6 +10,7 @@
   event_t e;
   clk_event_t ce1;
   clk_event_t ce2;
+  clk_event_t ce3 = CLK_NULL_EVENT;
 
   if (e == ce1) { // expected-error {{invalid operands to binary expression ('event_t' and 'clk_event_t')}}
 return 9;
Index: lib/Headers/opencl-c-base.h
===
--- lib/Headers/opencl-c-base.h
+++ lib/Headers/opencl-c-base.h
@@ -413,7 +413,7 @@
 #define CLK_OUT_OF_RESOURCES-5
 
 #define CLK_NULL_QUEUE  0
-#define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
+#define CLK_NULL_EVENT (__builtin_astype(((__SIZE_MAX__)), clk_event_t))
 
 // execution model related definitions
 #define CLK_ENQUEUE_FLAGS_NO_WAIT   0x0
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63876: [OpenCL] Define CLK_NULL_EVENT without cast

2019-07-03 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

In D63876#1565004 , @Anastasia wrote:

> btw, there seems to be the same issue with `reserve_id_t`?


Yes, `CLK_NULL_RESERVE_ID` has the same cast.  I don't have any use case that 
is affected by it at the moment, so I left it out of this patch.  But I can 
also update it if you prefer.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63876/new/

https://reviews.llvm.org/D63876



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


[PATCH] D53023: Prototype OpenCL BIFs using Tablegen

2019-05-13 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

In D53023#1499942 , @AlexeySotkin 
wrote:

> LGTM! @joey, any idea when it will be landed?


This work is being continued in https://reviews.llvm.org/D60763


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53023/new/

https://reviews.llvm.org/D53023



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


[PATCH] D62181: [OpenCL] Support pipe keyword in C++ mode

2019-05-21 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: Anastasia.
Herald added subscribers: cfe-commits, yaxunl.
Herald added a project: clang.

Support the OpenCL C pipe feature in C++ for OpenCL mode, to preserve backwards 
compatibility with OpenCL C.


Repository:
  rC Clang

https://reviews.llvm.org/D62181

Files:
  include/clang/Basic/TokenKinds.def
  lib/Basic/Builtins.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaType.cpp
  test/SemaOpenCL/invalid-pipes-cl2.0.cl

Index: test/SemaOpenCL/invalid-pipes-cl2.0.cl
===
--- test/SemaOpenCL/invalid-pipes-cl2.0.cl
+++ test/SemaOpenCL/invalid-pipes-cl2.0.cl
@@ -1,9 +1,10 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=c++
 
 global pipe int gp;// expected-error {{type '__global read_only pipe int' can only be used as a function parameter in OpenCL}}
 global reserve_id_t rid;  // expected-error {{the '__global reserve_id_t' type cannot be used to declare a program scope variable}}
 
-extern pipe write_only int get_pipe(); // expected-error {{type '__global write_only pipe int (void)' can only be used as a function parameter in OpenCL}}
+extern pipe write_only int get_pipe(); // expected-error-re{{type '__global write_only pipe int ({{(void)?}})' can only be used as a function parameter in OpenCL}}
 
 kernel void test_invalid_reserved_id(reserve_id_t ID) { // expected-error {{'reserve_id_t' cannot be used as the type of a kernel parameter}}
 }
@@ -35,6 +36,7 @@
 }
 
 // Tests ASTContext::mergeTypes rejects this.
+#ifndef __OPENCL_CPP_VERSION__
 int f(pipe int x, int y); // expected-note {{previous declaration is here}}
 int f(x, y) // expected-error {{conflicting types for 'f}}
 pipe short x;
@@ -42,3 +44,4 @@
 {
 return y;
 }
+#endif
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -1356,7 +1356,7 @@
   // "At least one type specifier shall be given in the declaration
   // specifiers in each declaration, and in the specifier-qualifier list in
   // each struct declaration and type name."
-  if (S.getLangOpts().CPlusPlus) {
+  if (S.getLangOpts().CPlusPlus && !DS.isTypeSpecPipe()) {
 S.Diag(DeclLoc, diag::err_missing_type_specifier)
   << DS.getSourceRange();
 
@@ -1364,7 +1364,9 @@
 // value being declared, poison it as invalid so we don't get chains of
 // errors.
 declarator.setInvalidType(true);
-  } else if (S.getLangOpts().OpenCLVersion >= 200 && DS.isTypeSpecPipe()){
+  } else if ((S.getLangOpts().OpenCLVersion >= 200 ||
+  S.getLangOpts().OpenCLCPlusPlus) &&
+ DS.isTypeSpecPipe()) {
 S.Diag(DeclLoc, diag::err_missing_actual_pipe_type)
   << DS.getSourceRange();
 declarator.setInvalidType(true);
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -9288,7 +9288,7 @@
 
 // OpenCL 2.0 pipe restrictions forbids pipe packet types to be non-value
 // types.
-if (getLangOpts().OpenCLVersion >= 200) {
+if (getLangOpts().OpenCLVersion >= 200 || getLangOpts().OpenCLCPlusPlus) {
   if(const PipeType *PipeTy = PT->getAs()) {
 QualType ElemTy = PipeTy->getElementType();
   if (ElemTy->isReferenceType() || ElemTy->isPointerType()) {
Index: lib/Parse/ParseTentative.cpp
===
--- lib/Parse/ParseTentative.cpp
+++ lib/Parse/ParseTentative.cpp
@@ -1437,6 +1437,8 @@
   case tok::kw___read_only:
   case tok::kw___write_only:
   case tok::kw___read_write:
+// OpenCL pipe
+  case tok::kw_pipe:
 
 // GNU
   case tok::kw_restrict:
Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -2560,6 +2560,11 @@
 return false;
   }
 
+  // Early exit as Sema has a dedicated missing_actual_pipe_type diagnostic
+  // for incomplete declarations such as `pipe p`.
+  if (getLangOpts().OpenCLCPlusPlus && DS.isTypeSpecPipe())
+return false;
+
   if (getLangOpts().CPlusPlus &&
   DS.getStorageClassSpec() == DeclSpec::SCS_auto) {
 // Don't require a type specifier if we have the 'auto' storage class
@@ -3769,7 +3774,8 @@
   isInvalid = DS.SetTypeAltiVecBool(true, Loc, PrevSpec, DiagID, Policy);
   break;
 case tok::kw_pipe:
-  if (!getLangOpts().OpenCL || (getLangOpts().OpenCLVersion < 200)) {
+  if (!getLangOpts().OpenCL || (getLangOpts().OpenCLVersion < 200 &&
+!getLangOpts().OpenCLCPlusPlus)) {
 // OpenCL 2.0 defined this keyword. OpenCL 1.2 and earlier should
 

[PATCH] D62208: [OpenCL] Enable queue_t and clk_event_t comparisons in C++ mode

2019-05-21 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: Anastasia.
Herald added subscribers: cfe-commits, yaxunl.
Herald added a project: clang.

Support queue_t and clk_event_t comparisons in C++ for OpenCL mode, to
preserve backwards compatibility with OpenCL C.


Repository:
  rC Clang

https://reviews.llvm.org/D62208

Files:
  lib/Sema/SemaExpr.cpp
  test/SemaOpenCL/clk_event_t.cl


Index: test/SemaOpenCL/clk_event_t.cl
===
--- test/SemaOpenCL/clk_event_t.cl
+++ test/SemaOpenCL/clk_event_t.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=c++
 
 // Taken from opencl-c.h
 #define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -10808,7 +10808,7 @@
 return computeResultTy();
   }
 
-  if (getLangOpts().OpenCLVersion >= 200) {
+  if (getLangOpts().OpenCLVersion >= 200 || getLangOpts().OpenCLCPlusPlus) {
 if (LHSType->isClkEventT() && RHSType->isClkEventT()) {
   return computeResultTy();
 }


Index: test/SemaOpenCL/clk_event_t.cl
===
--- test/SemaOpenCL/clk_event_t.cl
+++ test/SemaOpenCL/clk_event_t.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=c++
 
 // Taken from opencl-c.h
 #define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -10808,7 +10808,7 @@
 return computeResultTy();
   }
 
-  if (getLangOpts().OpenCLVersion >= 200) {
+  if (getLangOpts().OpenCLVersion >= 200 || getLangOpts().OpenCLCPlusPlus) {
 if (LHSType->isClkEventT() && RHSType->isClkEventT()) {
   return computeResultTy();
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62181: [OpenCL] Support pipe keyword in C++ mode

2019-05-22 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC361382: [OpenCL] Support pipe keyword in C++ mode (authored 
by svenvh, committed by ).

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62181/new/

https://reviews.llvm.org/D62181

Files:
  include/clang/Basic/TokenKinds.def
  lib/Basic/Builtins.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaType.cpp
  test/SemaOpenCL/invalid-pipes-cl2.0.cl

Index: include/clang/Basic/TokenKinds.def
===
--- include/clang/Basic/TokenKinds.def
+++ include/clang/Basic/TokenKinds.def
@@ -568,7 +568,7 @@
 // OpenMP Type Traits
 KEYWORD(__builtin_omp_required_simd_align, KEYALL)
 
-KEYWORD(pipe, KEYOPENCLC)
+KEYWORD(pipe, KEYOPENCLC | KEYOPENCLCXX)
 
 // Borland Extensions.
 KEYWORD(__pascal, KEYALL)
Index: test/SemaOpenCL/invalid-pipes-cl2.0.cl
===
--- test/SemaOpenCL/invalid-pipes-cl2.0.cl
+++ test/SemaOpenCL/invalid-pipes-cl2.0.cl
@@ -1,9 +1,10 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=c++
 
 global pipe int gp;// expected-error {{type '__global read_only pipe int' can only be used as a function parameter in OpenCL}}
 global reserve_id_t rid;  // expected-error {{the '__global reserve_id_t' type cannot be used to declare a program scope variable}}
 
-extern pipe write_only int get_pipe(); // expected-error {{type '__global write_only pipe int (void)' can only be used as a function parameter in OpenCL}}
+extern pipe write_only int get_pipe(); // expected-error-re{{type '__global write_only pipe int ({{(void)?}})' can only be used as a function parameter in OpenCL}}
 
 kernel void test_invalid_reserved_id(reserve_id_t ID) { // expected-error {{'reserve_id_t' cannot be used as the type of a kernel parameter}}
 }
@@ -35,6 +36,7 @@
 }
 
 // Tests ASTContext::mergeTypes rejects this.
+#ifndef __OPENCL_CPP_VERSION__
 int f(pipe int x, int y); // expected-note {{previous declaration is here}}
 int f(x, y) // expected-error {{conflicting types for 'f}}
 pipe short x;
@@ -42,3 +44,4 @@
 {
 return y;
 }
+#endif
Index: lib/Basic/Builtins.cpp
===
--- lib/Basic/Builtins.cpp
+++ lib/Basic/Builtins.cpp
@@ -70,8 +70,9 @@
   bool ObjCUnsupported = !LangOpts.ObjC && BuiltinInfo.Langs == OBJC_LANG;
   bool OclC1Unsupported = (LangOpts.OpenCLVersion / 100) != 1 &&
   (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES ) ==  OCLC1X_LANG;
-  bool OclC2Unsupported = LangOpts.OpenCLVersion != 200 &&
-  (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES) == OCLC20_LANG;
+  bool OclC2Unsupported =
+  (LangOpts.OpenCLVersion != 200 && !LangOpts.OpenCLCPlusPlus) &&
+  (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES) == OCLC20_LANG;
   bool OclCUnsupported = !LangOpts.OpenCL &&
  (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES);
   bool OpenMPUnsupported = !LangOpts.OpenMP && BuiltinInfo.Langs == OMP_LANG;
Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -2560,6 +2560,11 @@
 return false;
   }
 
+  // Early exit as Sema has a dedicated missing_actual_pipe_type diagnostic
+  // for incomplete declarations such as `pipe p`.
+  if (getLangOpts().OpenCLCPlusPlus && DS.isTypeSpecPipe())
+return false;
+
   if (getLangOpts().CPlusPlus &&
   DS.getStorageClassSpec() == DeclSpec::SCS_auto) {
 // Don't require a type specifier if we have the 'auto' storage class
@@ -3769,7 +3774,8 @@
   isInvalid = DS.SetTypeAltiVecBool(true, Loc, PrevSpec, DiagID, Policy);
   break;
 case tok::kw_pipe:
-  if (!getLangOpts().OpenCL || (getLangOpts().OpenCLVersion < 200)) {
+  if (!getLangOpts().OpenCL || (getLangOpts().OpenCLVersion < 200 &&
+!getLangOpts().OpenCLCPlusPlus)) {
 // OpenCL 2.0 defined this keyword. OpenCL 1.2 and earlier should
 // support the "pipe" word as identifier.
 Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
@@ -4896,7 +4902,8 @@
   default: return false;
 
   case tok::kw_pipe:
-return getLangOpts().OpenCL && (getLangOpts().OpenCLVersion >= 200);
+return (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200) ||
+   getLangOpts().OpenCLCPlusPlus;
 
   case tok::identifier:   // foo::bar
 // Unfortunate hack to support "Class.factoryMethod" notation.
@@ -5384,7 +5391,8 @@
   if (Kind == tok::star || Kind == tok::caret)
 return true;
 
-  if ((Kind == tok::kw_pipe) && Lang.OpenCL && (Lang.OpenCLVersion >= 200))
+  if (Kind == tok::kw_pipe

[PATCH] D62208: [OpenCL] Enable queue_t and clk_event_t comparisons in C++ mode

2019-05-23 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL361467: Enable queue_t and clk_event_t comparisons in C++ 
mode (authored by svenvh, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D62208?vs=200534&id=200895#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62208/new/

https://reviews.llvm.org/D62208

Files:
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/test/SemaOpenCL/clk_event_t.cl


Index: cfe/trunk/test/SemaOpenCL/clk_event_t.cl
===
--- cfe/trunk/test/SemaOpenCL/clk_event_t.cl
+++ cfe/trunk/test/SemaOpenCL/clk_event_t.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=c++
 
 // Taken from opencl-c.h
 #define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -10808,7 +10808,7 @@
 return computeResultTy();
   }
 
-  if (getLangOpts().OpenCLVersion >= 200) {
+  if (getLangOpts().OpenCLVersion >= 200 || getLangOpts().OpenCLCPlusPlus) {
 if (LHSType->isClkEventT() && RHSType->isClkEventT()) {
   return computeResultTy();
 }


Index: cfe/trunk/test/SemaOpenCL/clk_event_t.cl
===
--- cfe/trunk/test/SemaOpenCL/clk_event_t.cl
+++ cfe/trunk/test/SemaOpenCL/clk_event_t.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=c++
 
 // Taken from opencl-c.h
 #define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -10808,7 +10808,7 @@
 return computeResultTy();
   }
 
-  if (getLangOpts().OpenCLVersion >= 200) {
+  if (getLangOpts().OpenCLVersion >= 200 || getLangOpts().OpenCLCPlusPlus) {
 if (LHSType->isClkEventT() && RHSType->isClkEventT()) {
   return computeResultTy();
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62588: [OpenCL] Support logical vector operators in C++ mode

2019-05-29 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: Anastasia.
Herald added subscribers: cfe-commits, yaxunl.
Herald added a project: clang.

Support logical operators on vectors in C++ for OpenCL mode, to
preserve backwards compatibility with OpenCL C.


Repository:
  rC Clang

https://reviews.llvm.org/D62588

Files:
  lib/Sema/SemaExpr.cpp
  test/CodeGenOpenCL/logical-ops.cl


Index: test/CodeGenOpenCL/logical-ops.cl
===
--- test/CodeGenOpenCL/logical-ops.cl
+++ test/CodeGenOpenCL/logical-ops.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL1.2 -O1 -triple 
x86_64-unknown-linux-gnu | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=c++ -O1 -triple 
x86_64-unknown-linux-gnu | FileCheck %s
 
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
 
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -10902,7 +10902,7 @@
   if (vType.isNull())
 return InvalidOperands(Loc, LHS, RHS);
   if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion < 120 &&
-  vType->hasFloatingRepresentation())
+  !getLangOpts().OpenCLCPlusPlus && vType->hasFloatingRepresentation())
 return InvalidOperands(Loc, LHS, RHS);
   // FIXME: The check for C++ here is for GCC compatibility. GCC rejects the
   //usage of the logical operators && and || with vectors in C. This
@@ -13165,7 +13165,8 @@
   }
 } else if (resultType->isExtVectorType()) {
   if (Context.getLangOpts().OpenCL &&
-  Context.getLangOpts().OpenCLVersion < 120) {
+  Context.getLangOpts().OpenCLVersion < 120 &&
+  !Context.getLangOpts().OpenCLCPlusPlus) {
 // OpenCL v1.1 6.3.h: The logical operator not (!) does not
 // operate on vector float types.
 QualType T = resultType->getAs()->getElementType();


Index: test/CodeGenOpenCL/logical-ops.cl
===
--- test/CodeGenOpenCL/logical-ops.cl
+++ test/CodeGenOpenCL/logical-ops.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL1.2 -O1 -triple x86_64-unknown-linux-gnu | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=c++ -O1 -triple x86_64-unknown-linux-gnu | FileCheck %s
 
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
 
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -10902,7 +10902,7 @@
   if (vType.isNull())
 return InvalidOperands(Loc, LHS, RHS);
   if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion < 120 &&
-  vType->hasFloatingRepresentation())
+  !getLangOpts().OpenCLCPlusPlus && vType->hasFloatingRepresentation())
 return InvalidOperands(Loc, LHS, RHS);
   // FIXME: The check for C++ here is for GCC compatibility. GCC rejects the
   //usage of the logical operators && and || with vectors in C. This
@@ -13165,7 +13165,8 @@
   }
 } else if (resultType->isExtVectorType()) {
   if (Context.getLangOpts().OpenCL &&
-  Context.getLangOpts().OpenCLVersion < 120) {
+  Context.getLangOpts().OpenCLVersion < 120 &&
+  !Context.getLangOpts().OpenCLCPlusPlus) {
 // OpenCL v1.1 6.3.h: The logical operator not (!) does not
 // operate on vector float types.
 QualType T = resultType->getAs()->getElementType();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62335: [OpenCL][PR41963] Add overloads of old atomics with generic pointer type in C++ mode

2019-05-29 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh accepted this revision.
svenvh added a comment.
This revision is now accepted and ready to land.

LGTM, please address style issue before committing.




Comment at: test/Headers/opencl-c-header.cl:79
+{
+atomic_add(a, 1);
+}

Probably better to follow the style of the other tests above (i.e. indent and 
brace placement).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62335/new/

https://reviews.llvm.org/D62335



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


[PATCH] D67713: [OpenCL] Add image query builtin functions

2019-09-18 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: Anastasia.
Herald added subscribers: cfe-commits, kristina, yaxunl.
Herald added a reviewer: rengolin.
Herald added a project: clang.

Add the image query builtin functions from the OpenCL C specification.

Patch by Pierre Gondois and Sven van Haastregt.


Repository:
  rC Clang

https://reviews.llvm.org/D67713

Files:
  clang/lib/Sema/OpenCLBuiltins.td
  clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl


Index: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
===
--- clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -71,6 +71,8 @@
   resf = read_imagef(image_read_only_image2d, i2);
   res = read_imageh(image_read_only_image2d, i2);
   res = read_imageh(image_read_only_image2d, sampler, i2);
+
+  int imgWidth = get_image_width(image_read_only_image2d);
 }
 
 #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
@@ -79,6 +81,8 @@
   int4 i4;
 
   write_imageh(image_read_write_image3d, i4, h4);
+
+  int imgDepth = get_image_depth(image_read_write_image3d);
 }
 #endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 
Index: clang/lib/Sema/OpenCLBuiltins.td
===
--- clang/lib/Sema/OpenCLBuiltins.td
+++ clang/lib/Sema/OpenCLBuiltins.td
@@ -593,6 +593,31 @@
   def : Builtin<"write_imagef", [Void, ImageType, 
VectorType, Float]>;
 }
 
+// --- Table 25: Image Query Functions ---
+foreach aQual = ["RO", "WO", "RW"] in {
+  foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d,
+   Image1dArray, Image2dArray, Image2dDepth,
+   Image2dArrayDepth] in {
+foreach name = ["get_image_width", "get_image_channel_data_type",
+"get_image_channel_order"] in {
+  def : Builtin]>;
+}
+  }
+  foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth,
+   Image2dArrayDepth] in {
+def : Builtin<"get_image_height", [Int, ImageType]>;
+  }
+  def : Builtin<"get_image_depth", [Int, ImageType]>;
+  foreach imgTy = [Image2d, Image2dArray, Image2dDepth,
+   Image2dArrayDepth] in {
+def : Builtin<"get_image_dim", [VectorType, ImageType]>;
+  }
+  def : Builtin<"get_image_dim", [VectorType, ImageType]>;
+  foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in {
+def : Builtin<"get_image_array_size", [Size, ImageType]>;
+  }
+}
+
 // OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
 // --- Table 8 ---
 foreach aQual = ["RO"] in {


Index: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
===
--- clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -71,6 +71,8 @@
   resf = read_imagef(image_read_only_image2d, i2);
   res = read_imageh(image_read_only_image2d, i2);
   res = read_imageh(image_read_only_image2d, sampler, i2);
+
+  int imgWidth = get_image_width(image_read_only_image2d);
 }
 
 #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
@@ -79,6 +81,8 @@
   int4 i4;
 
   write_imageh(image_read_write_image3d, i4, h4);
+
+  int imgDepth = get_image_depth(image_read_write_image3d);
 }
 #endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 
Index: clang/lib/Sema/OpenCLBuiltins.td
===
--- clang/lib/Sema/OpenCLBuiltins.td
+++ clang/lib/Sema/OpenCLBuiltins.td
@@ -593,6 +593,31 @@
   def : Builtin<"write_imagef", [Void, ImageType, VectorType, Float]>;
 }
 
+// --- Table 25: Image Query Functions ---
+foreach aQual = ["RO", "WO", "RW"] in {
+  foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d,
+   Image1dArray, Image2dArray, Image2dDepth,
+   Image2dArrayDepth] in {
+foreach name = ["get_image_width", "get_image_channel_data_type",
+"get_image_channel_order"] in {
+  def : Builtin]>;
+}
+  }
+  foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth,
+   Image2dArrayDepth] in {
+def : Builtin<"get_image_height", [Int, ImageType]>;
+  }
+  def : Builtin<"get_image_depth", [Int, ImageType]>;
+  foreach imgTy = [Image2d, Image2dArray, Image2dDepth,
+   Image2dArrayDepth] in {
+def : Builtin<"get_image_dim", [VectorType, ImageType]>;
+  }
+  def : Builtin<"get_image_dim", [VectorType, ImageType]>;
+  foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in {
+def : Builtin<"get_image_array_size", [Size, ImageType]>;
+  }
+}
+
 // OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
 // --- Table 8 ---
 foreach aQual = ["RO"] in {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67714: [OpenCL] Add -Wconversion to fdeclare-opencl-builtins test

2019-09-18 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: Anastasia.
Herald added subscribers: cfe-commits, kristina, yaxunl.
Herald added a reviewer: rengolin.
Herald added a project: clang.

Add the -Wconversion -Werror options to check no unexpected conversion
is done.

Patch by Pierre Gondois and Sven van Haastregt.


Repository:
  rC Clang

https://reviews.llvm.org/D67714

Files:
  clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl


Index: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
===
--- clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only -cl-std=CL 
-fdeclare-opencl-builtins -DNO_HEADER
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only -cl-std=CL 
-fdeclare-opencl-builtins -finclude-default-header
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only 
-cl-std=CL1.2 -fdeclare-opencl-builtins -DNO_HEADER
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only 
-cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only 
-cl-std=CL2.0 -fdeclare-opencl-builtins -DNO_HEADER
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only 
-cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -DNO_HEADER
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -DNO_HEADER
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -DNO_HEADER
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header
 
 #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 // expected-no-diagnostics
@@ -99,6 +99,7 @@
   out[0] = get_sub_group_size();
 #if __OPENCL_C_VERSION__ < CL_VERSION_2_0
 // expected-error@-2{{implicit declaration of function 'get_sub_group_size' is 
invalid in OpenCL}}
+// expected-error@-3{{implicit conversion changes signedness: 'int' to 'uint' 
(aka 'unsigned int')}}
 #endif
 }
 


Index: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
===
--- clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -DNO_HEADER
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -finclude-default-header
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -DNO_HEADER
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -DNO_HEADER
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -DNO_HEADER
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -DNO_HEADER
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -DNO_HEADER
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header
 
 #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 // expected-no-diagnostics
@@ -99,6 +99,7 @@
   out[0] = get_sub_group_size();
 #if __OPENCL_C_VERSION__ < CL_VERSION_2_0
 // expected-error@-2{{implicit declaration of function 'get_sub_group_size' is invalid in OpenCL}}
+// expected-error@-3{{implicit conversion changes signedness: 'int' to 'uint' (aka 'unsigned int')}}
 #endif
 }
 
__

[PATCH] D67714: [OpenCL] Add -Wconversion to fdeclare-opencl-builtins test

2019-09-24 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh marked an inline comment as done.
svenvh added inline comments.



Comment at: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl:102
 // expected-error@-2{{implicit declaration of function 'get_sub_group_size' is 
invalid in OpenCL}}
+// expected-error@-3{{implicit conversion changes signedness: 'int' to 'uint' 
(aka 'unsigned int')}}
 #endif

Anastasia wrote:
> I am slightly confused about this error, isn't `get_sub_group_size` supposed 
> to return uint?
I think this is a side-effect from the previous error.  It failed to resolve 
`get_sub_group_size` so it inserted a placeholder declaration with return type 
`int`.  Does that make sense?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67714/new/

https://reviews.llvm.org/D67714



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


[PATCH] D67713: [OpenCL] Add image query builtin functions

2019-09-25 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL372833: [OpenCL] Add image query builtin functions (authored 
by svenvh, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D67713?vs=220683&id=221691#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67713/new/

https://reviews.llvm.org/D67713

Files:
  cfe/trunk/lib/Sema/OpenCLBuiltins.td
  cfe/trunk/test/SemaOpenCL/fdeclare-opencl-builtins.cl


Index: cfe/trunk/lib/Sema/OpenCLBuiltins.td
===
--- cfe/trunk/lib/Sema/OpenCLBuiltins.td
+++ cfe/trunk/lib/Sema/OpenCLBuiltins.td
@@ -593,6 +593,31 @@
   def : Builtin<"write_imagef", [Void, ImageType, 
VectorType, Float]>;
 }
 
+// --- Table 25: Image Query Functions ---
+foreach aQual = ["RO", "WO", "RW"] in {
+  foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d,
+   Image1dArray, Image2dArray, Image2dDepth,
+   Image2dArrayDepth] in {
+foreach name = ["get_image_width", "get_image_channel_data_type",
+"get_image_channel_order"] in {
+  def : Builtin]>;
+}
+  }
+  foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth,
+   Image2dArrayDepth] in {
+def : Builtin<"get_image_height", [Int, ImageType]>;
+  }
+  def : Builtin<"get_image_depth", [Int, ImageType]>;
+  foreach imgTy = [Image2d, Image2dArray, Image2dDepth,
+   Image2dArrayDepth] in {
+def : Builtin<"get_image_dim", [VectorType, ImageType]>;
+  }
+  def : Builtin<"get_image_dim", [VectorType, ImageType]>;
+  foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in {
+def : Builtin<"get_image_array_size", [Size, ImageType]>;
+  }
+}
+
 // OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
 // --- Table 8 ---
 foreach aQual = ["RO"] in {
Index: cfe/trunk/test/SemaOpenCL/fdeclare-opencl-builtins.cl
===
--- cfe/trunk/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ cfe/trunk/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -71,6 +71,8 @@
   resf = read_imagef(image_read_only_image2d, i2);
   res = read_imageh(image_read_only_image2d, i2);
   res = read_imageh(image_read_only_image2d, sampler, i2);
+
+  int imgWidth = get_image_width(image_read_only_image2d);
 }
 
 #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
@@ -79,6 +81,8 @@
   int4 i4;
 
   write_imageh(image_read_write_image3d, i4, h4);
+
+  int imgDepth = get_image_depth(image_read_write_image3d);
 }
 #endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 


Index: cfe/trunk/lib/Sema/OpenCLBuiltins.td
===
--- cfe/trunk/lib/Sema/OpenCLBuiltins.td
+++ cfe/trunk/lib/Sema/OpenCLBuiltins.td
@@ -593,6 +593,31 @@
   def : Builtin<"write_imagef", [Void, ImageType, VectorType, Float]>;
 }
 
+// --- Table 25: Image Query Functions ---
+foreach aQual = ["RO", "WO", "RW"] in {
+  foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d,
+   Image1dArray, Image2dArray, Image2dDepth,
+   Image2dArrayDepth] in {
+foreach name = ["get_image_width", "get_image_channel_data_type",
+"get_image_channel_order"] in {
+  def : Builtin]>;
+}
+  }
+  foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth,
+   Image2dArrayDepth] in {
+def : Builtin<"get_image_height", [Int, ImageType]>;
+  }
+  def : Builtin<"get_image_depth", [Int, ImageType]>;
+  foreach imgTy = [Image2d, Image2dArray, Image2dDepth,
+   Image2dArrayDepth] in {
+def : Builtin<"get_image_dim", [VectorType, ImageType]>;
+  }
+  def : Builtin<"get_image_dim", [VectorType, ImageType]>;
+  foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in {
+def : Builtin<"get_image_array_size", [Size, ImageType]>;
+  }
+}
+
 // OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
 // --- Table 8 ---
 foreach aQual = ["RO"] in {
Index: cfe/trunk/test/SemaOpenCL/fdeclare-opencl-builtins.cl
===
--- cfe/trunk/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ cfe/trunk/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -71,6 +71,8 @@
   resf = read_imagef(image_read_only_image2d, i2);
   res = read_imageh(image_read_only_image2d, i2);
   res = read_imageh(image_read_only_image2d, sampler, i2);
+
+  int imgWidth = get_image_width(image_read_only_image2d);
 }
 
 #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
@@ -79,6 +81,8 @@
   int4 i4;
 
   write_imageh(image_read_write_image3d, i4, h4);
+
+  int imgDepth = get_image_depth(image_read_write_image3d);
 }
 #endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm

[PATCH] D67714: [OpenCL] Add -Wconversion to fdeclare-opencl-builtins test

2019-09-26 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL372975: [OpenCL] Add -Wconversion to 
fdeclare-opencl-builtins test (authored by svenvh, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D67714?vs=220684&id=221933#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67714/new/

https://reviews.llvm.org/D67714

Files:
  cfe/trunk/test/SemaOpenCL/fdeclare-opencl-builtins.cl


Index: cfe/trunk/test/SemaOpenCL/fdeclare-opencl-builtins.cl
===
--- cfe/trunk/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ cfe/trunk/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only -cl-std=CL 
-fdeclare-opencl-builtins -DNO_HEADER
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only -cl-std=CL 
-fdeclare-opencl-builtins -finclude-default-header
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only 
-cl-std=CL1.2 -fdeclare-opencl-builtins -DNO_HEADER
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only 
-cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only 
-cl-std=CL2.0 -fdeclare-opencl-builtins -DNO_HEADER
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only 
-cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -DNO_HEADER
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -DNO_HEADER
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -DNO_HEADER
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header
 
 #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 // expected-no-diagnostics
@@ -99,6 +99,7 @@
   out[0] = get_sub_group_size();
 #if __OPENCL_C_VERSION__ < CL_VERSION_2_0
 // expected-error@-2{{implicit declaration of function 'get_sub_group_size' is 
invalid in OpenCL}}
+// expected-error@-3{{implicit conversion changes signedness: 'int' to 'uint' 
(aka 'unsigned int')}}
 #endif
 }
 


Index: cfe/trunk/test/SemaOpenCL/fdeclare-opencl-builtins.cl
===
--- cfe/trunk/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ cfe/trunk/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -DNO_HEADER
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -finclude-default-header
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -DNO_HEADER
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -DNO_HEADER
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -DNO_HEADER
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -DNO_HEADER
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -DNO_HEADER
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header
 
 #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 // expected-no-diagnostics
@@ -99,6 +99,7 @@
   out[0] = get_sub_group_size();
 #if __OPENCL_C_VERSION__ < CL_VERSION_2_0
 // expected-error@-2{{implicit declaration of function 'get_sub_group_size' is invalid in OpenCL}}
+//

[PATCH] D64319: [OpenCL] Add function attributes handling for builtin functions

2019-09-27 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh updated this revision to Diff 222197.
svenvh edited the summary of this revision.
svenvh added a comment.
Herald added a reviewer: rengolin.

- Rebase onto recent master.
- Fix formatting.
- Use predefined attribute sets like "Attr.Const" instead of bit lists.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64319/new/

https://reviews.llvm.org/D64319

Files:
  clang/lib/Sema/OpenCLBuiltins.td
  clang/lib/Sema/SemaLookup.cpp
  clang/test/CodeGenOpenCL/fdeclare-opencl-builtins.cl
  clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Index: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
===
--- clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -270,6 +270,12 @@
   // the SignatureTable represent the complete signature.  The first type at
   // index SigTableIndex is the return type.
   const unsigned NumTypes;
+  // Function attribute __attribute__((pure))
+  const bool IsPure;
+  // Function attribute __attribute__((const))
+  const bool IsConst;
+  // Function attribute __attribute__((convergent))
+  const bool IsConv;
   // First OpenCL version in which this overload was introduced (e.g. CL20).
   const unsigned short MinVersion;
   // First OpenCL version in which this overload was removed (e.g. CL20).
@@ -408,6 +414,9 @@
 for (const auto &Overload : FOM.second) {
   OS << "  { " << Overload.second << ", "
  << Overload.first->getValueAsListOfDefs("Signature").size() << ", "
+ << (Overload.first->getValueAsBit("IsPure")) << ", "
+ << (Overload.first->getValueAsBit("IsConst")) << ", "
+ << (Overload.first->getValueAsBit("IsConv")) << ", "
  << Overload.first->getValueAsDef("MinVersion")->getValueAsInt("ID")
  << ", "
  << Overload.first->getValueAsDef("MaxVersion")->getValueAsInt("ID")
Index: clang/test/CodeGenOpenCL/fdeclare-opencl-builtins.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/fdeclare-opencl-builtins.cl
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -emit-llvm -o - -O0 -triple spir-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header %s | FileCheck %s
+
+// Test that Attr.Const from OpenCLBuiltins.td is lowered to a readnone attribute.
+// CHECK-LABEL: @test_const_attr
+// CHECK: call i32 @_Z3maxii({{.*}}) [[ATTR_CONST:#[0-9]]]
+// CHECK: ret
+int test_const_attr(int a) {
+  return max(a, 2);
+}
+
+// Test that Attr.Pure from OpenCLBuiltins.td is lowered to a readonly attribute.
+// CHECK-LABEL: @test_pure_attr
+// CHECK: call <4 x float> @_Z11read_imagef{{.*}} [[ATTR_PURE:#[0-9]]]
+// CHECK: ret
+kernel void test_pure_attr(read_only image1d_t img) {
+  float4 resf = read_imagef(img, 42);
+}
+
+// CHECK: attributes [[ATTR_CONST]] =
+// CHECK-SAME: readnone
+// CHECK: attributes [[ATTR_PURE]] =
+// CHECK-SAME: readonly
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -812,9 +812,17 @@
 }
 NewOpenCLBuiltin->setParams(ParmList);
   }
-  if (!S.getLangOpts().OpenCLCPlusPlus) {
+
+  // Add function attributes.
+  if (OpenCLBuiltin.IsPure)
+NewOpenCLBuiltin->addAttr(PureAttr::CreateImplicit(Context));
+  if (OpenCLBuiltin.IsConst)
+NewOpenCLBuiltin->addAttr(ConstAttr::CreateImplicit(Context));
+  if (OpenCLBuiltin.IsConv)
+NewOpenCLBuiltin->addAttr(ConvergentAttr::CreateImplicit(Context));
+  if ((GenTypeMaxCnt > 1 || Len > 1) && !S.getLangOpts().OpenCLCPlusPlus)
 NewOpenCLBuiltin->addAttr(OverloadableAttr::CreateImplicit(Context));
-  }
+
   LR.addDecl(NewOpenCLBuiltin);
 }
   }
Index: clang/lib/Sema/OpenCLBuiltins.td
===
--- clang/lib/Sema/OpenCLBuiltins.td
+++ clang/lib/Sema/OpenCLBuiltins.td
@@ -180,10 +180,18 @@
   let VecWidth = 0;
 }
 
+// Builtin function attributes.
+def Attr {
+  list None = [0, 0, 0];
+  list Pure = [1, 0, 0];
+  list Const = [0, 1, 0];
+  list Convergent = [0, 0, 1];
+}
+
 //===--===//
 //  OpenCL C class for builtin functions
 //===--===//
-class Builtin _Signature> {
+class Builtin _Signature, list _Attributes = Attr.None> {
   // Name of the builtin function
   string Name = _Name;
   // List of types used by the function. The first one is the return type and
@@ -192,6 +200,12 @@
   list Signature = _Signature;
   // OpenCL Extension to which the function belongs (cl_khr_subgroups, ...)
   string Extension = "";
+  // Function attribute __attribute__((pure))
+  bit IsPure = _Attributes[0];
+  // Function attribute __attribute__((const))
+  bit IsConst = _Attributes[1];
+

[PATCH] D68403: [OpenCL] PR43145: preserve addrspace for class accesses

2019-10-03 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: Anastasia.
Herald added subscribers: cfe-commits, yaxunl.
Herald added a project: clang.

PR43145 revealed two places where Clang was attempting to create a
bitcast without considering the address space of class types during
C++ class codegen.


Repository:
  rC Clang

https://reviews.llvm.org/D68403

Files:
  lib/CodeGen/CGClass.cpp
  test/CodeGenOpenCLCXX/addrspace-derived-base.cl


Index: test/CodeGenOpenCLCXX/addrspace-derived-base.cl
===
--- test/CodeGenOpenCLCXX/addrspace-derived-base.cl
+++ test/CodeGenOpenCLCXX/addrspace-derived-base.cl
@@ -11,6 +11,7 @@
 
 void foo() {
   D d;
+  //CHECK-LABEL: foo
   //CHECK: addrspacecast %class.D* %d to %class.D addrspace(4)*
   //CHECK: call spir_func i32 @_ZNU3AS41D5getmbEv(%class.D addrspace(4)*
   d.getmb();
@@ -20,3 +21,32 @@
 
 //CHECK: define linkonce_odr spir_func i32 @_ZNU3AS41D5getmbEv(%class.D 
addrspace(4)* %this)
 //CHECK: bitcast %class.D addrspace(4)* %this1 to %struct.B addrspace(4)*
+
+
+// Calling base method through multiple inheritance.
+
+class B2 {
+  public:
+void baseMethod() const {  }
+int bb;
+};
+
+class Derived : public B, public B2 {
+  public:
+void work() const { baseMethod(); }
+// CHECK-LABEL: work
+// CHECK: bitcast i8 addrspace(4)* %add.ptr to %class.B2 addrspace(4)*
+};
+
+void pr43145(const Derived *argDerived) {
+  argDerived->work();
+}
+
+// Casting from base to derived.
+
+void pr43145_2(B *argB) {
+  Derived *x = (Derived*)argB;
+}
+
+// CHECK-LABEL: @_Z9pr43145_2
+// CHECK: bitcast %struct.B addrspace(4)* %0 to %class.Derived addrspace(4)*
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -246,7 +246,8 @@
 
   // Apply the base offset.
   llvm::Value *ptr = addr.getPointer();
-  ptr = CGF.Builder.CreateBitCast(ptr, CGF.Int8PtrTy);
+  unsigned AddrSpace = ptr->getType()->getPointerAddressSpace();
+  ptr = CGF.Builder.CreateBitCast(ptr, CGF.Int8Ty->getPointerTo(AddrSpace));
   ptr = CGF.Builder.CreateInBoundsGEP(ptr, baseOffset, "add.ptr");
 
   // If we have a virtual component, the alignment of the result will
@@ -381,7 +382,9 @@
 
   QualType DerivedTy =
 getContext().getCanonicalType(getContext().getTagDeclType(Derived));
-  llvm::Type *DerivedPtrTy = ConvertType(DerivedTy)->getPointerTo();
+  unsigned AddrSpace =
+BaseAddr.getPointer()->getType()->getPointerAddressSpace();
+  llvm::Type *DerivedPtrTy = ConvertType(DerivedTy)->getPointerTo(AddrSpace);
 
   llvm::Value *NonVirtualOffset =
 CGM.GetNonVirtualBaseClassOffset(Derived, PathBegin, PathEnd);


Index: test/CodeGenOpenCLCXX/addrspace-derived-base.cl
===
--- test/CodeGenOpenCLCXX/addrspace-derived-base.cl
+++ test/CodeGenOpenCLCXX/addrspace-derived-base.cl
@@ -11,6 +11,7 @@
 
 void foo() {
   D d;
+  //CHECK-LABEL: foo
   //CHECK: addrspacecast %class.D* %d to %class.D addrspace(4)*
   //CHECK: call spir_func i32 @_ZNU3AS41D5getmbEv(%class.D addrspace(4)*
   d.getmb();
@@ -20,3 +21,32 @@
 
 //CHECK: define linkonce_odr spir_func i32 @_ZNU3AS41D5getmbEv(%class.D addrspace(4)* %this)
 //CHECK: bitcast %class.D addrspace(4)* %this1 to %struct.B addrspace(4)*
+
+
+// Calling base method through multiple inheritance.
+
+class B2 {
+  public:
+void baseMethod() const {  }
+int bb;
+};
+
+class Derived : public B, public B2 {
+  public:
+void work() const { baseMethod(); }
+// CHECK-LABEL: work
+// CHECK: bitcast i8 addrspace(4)* %add.ptr to %class.B2 addrspace(4)*
+};
+
+void pr43145(const Derived *argDerived) {
+  argDerived->work();
+}
+
+// Casting from base to derived.
+
+void pr43145_2(B *argB) {
+  Derived *x = (Derived*)argB;
+}
+
+// CHECK-LABEL: @_Z9pr43145_2
+// CHECK: bitcast %struct.B addrspace(4)* %0 to %class.Derived addrspace(4)*
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -246,7 +246,8 @@
 
   // Apply the base offset.
   llvm::Value *ptr = addr.getPointer();
-  ptr = CGF.Builder.CreateBitCast(ptr, CGF.Int8PtrTy);
+  unsigned AddrSpace = ptr->getType()->getPointerAddressSpace();
+  ptr = CGF.Builder.CreateBitCast(ptr, CGF.Int8Ty->getPointerTo(AddrSpace));
   ptr = CGF.Builder.CreateInBoundsGEP(ptr, baseOffset, "add.ptr");
 
   // If we have a virtual component, the alignment of the result will
@@ -381,7 +382,9 @@
 
   QualType DerivedTy =
 getContext().getCanonicalType(getContext().getTagDeclType(Derived));
-  llvm::Type *DerivedPtrTy = ConvertType(DerivedTy)->getPointerTo();
+  unsigned AddrSpace =
+BaseAddr.getPointer()->getType()->getPointerAddressSpace();
+  llvm::Type *DerivedPtrTy = ConvertType(DerivedTy)->getPointerTo(AddrSpace);
 
   llvm::Value *NonVirtualOffset =
 CGM.GetNonVirtua

[PATCH] D45873: [OpenCL] Reject virtual functions for OpenCL C++

2018-04-20 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added reviewers: yaxunl, bader.
Herald added a subscriber: cfe-commits.

The OpenCL C++ specification doesn't mention restricting virtual inheritance, 
so leaving that unaffected for now.


Repository:
  rC Clang

https://reviews.llvm.org/D45873

Files:
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/LangOptions.def
  lib/Frontend/CompilerInvocation.cpp
  lib/Parse/ParseDecl.cpp
  test/Parser/opencl-cxx-virtual.cl

Index: test/Parser/opencl-cxx-virtual.cl
===
--- /dev/null
+++ test/Parser/opencl-cxx-virtual.cl
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -fsyntax-only -verify
+
+// Test that virtual functions and abstract classes are rejected.
+class virtual_functions {
+  virtual void bad1() {}
+  //expected-error@-1 {{virtual functions are not supported in OpenCL C++}}
+
+  virtual void bad2() =0;
+  //expected-error@-1 {{virtual functions are not supported in OpenCL C++}}
+  //expected-error@-2 {{'bad2' is not virtual and cannot be declared pure}}
+};
+
+// Test that virtual base classes are allowed.
+struct A {
+  int a;
+  void foo();
+};
+
+struct B : virtual A {
+  int b;
+};
+
+struct C : public virtual A {
+  int c;
+};
+
+struct D : B, C {
+  int d;
+};
+
+kernel void virtual_inheritance() {
+  D d;
+
+  d.foo();
+  d.a = 11;
+  d.b = 22;
+  d.c = 33;
+  d.d = 44;
+}
Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -3466,7 +3466,15 @@
   isInvalid = DS.setFunctionSpecInline(Loc, PrevSpec, DiagID);
   break;
 case tok::kw_virtual:
-  isInvalid = DS.setFunctionSpecVirtual(Loc, PrevSpec, DiagID);
+  // OpenCL C++ v1.0 s2.9: the virtual function qualifier is not supported.
+  if (getLangOpts().OpenCLCPlusPlus) {
+DiagID = diag::err_openclcxx_virtual_function;
+PrevSpec = Tok.getIdentifierInfo()->getNameStart();
+isInvalid = true;
+  }
+  else {
+isInvalid = DS.setFunctionSpecVirtual(Loc, PrevSpec, DiagID);
+  }
   break;
 case tok::kw_explicit:
   isInvalid = DS.setFunctionSpecExplicit(Loc, PrevSpec, DiagID);
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1925,6 +1925,7 @@
 Opts.setDefaultFPContractMode(LangOptions::FPC_On);
 Opts.NativeHalfType = 1;
 Opts.NativeHalfArgsAndReturns = 1;
+Opts.OpenCLCPlusPlus = Opts.CPlusPlus;
 // Include default header file for OpenCL.
 if (Opts.IncludeDefaultHeader) {
   PPOpts.Includes.push_back("opencl-c.h");
Index: include/clang/Basic/LangOptions.def
===
--- include/clang/Basic/LangOptions.def
+++ include/clang/Basic/LangOptions.def
@@ -189,6 +189,7 @@
 
 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(NativeHalfType, 1, 0, "Native half type support")
 LANGOPT(NativeHalfArgsAndReturns, 1, 0, "Native half args and returns")
Index: include/clang/Basic/DiagnosticParseKinds.td
===
--- include/clang/Basic/DiagnosticParseKinds.td
+++ include/clang/Basic/DiagnosticParseKinds.td
@@ -1073,6 +1073,10 @@
 def err_opencl_logical_exclusive_or : Error<
   "^^ is a reserved operator in OpenCL">;
 
+// OpenCL C++.
+def err_openclcxx_virtual_function : Error<
+  "virtual functions are not supported in OpenCL C++">;
+
 // OpenMP support.
 def warn_pragma_omp_ignored : Warning<
   "unexpected '#pragma omp ...' in program">, InGroup, DefaultIgnore;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45873: [OpenCL] Reject virtual functions for OpenCL C++

2018-04-20 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh updated this revision to Diff 143330.
svenvh added a comment.

Added a template class test as requested.


https://reviews.llvm.org/D45873

Files:
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/LangOptions.def
  lib/Frontend/CompilerInvocation.cpp
  lib/Parse/ParseDecl.cpp
  test/Parser/opencl-cxx-virtual.cl

Index: test/Parser/opencl-cxx-virtual.cl
===
--- /dev/null
+++ test/Parser/opencl-cxx-virtual.cl
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -fsyntax-only -verify
+
+// Test that virtual functions and abstract classes are rejected.
+class virtual_functions {
+  virtual void bad1() {}
+  //expected-error@-1 {{virtual functions are not supported in OpenCL C++}}
+
+  virtual void bad2() =0;
+  //expected-error@-1 {{virtual functions are not supported in OpenCL C++}}
+  //expected-error@-2 {{'bad2' is not virtual and cannot be declared pure}}
+};
+
+template 
+class X {
+  virtual T f();
+  //expected-error@-1 {{virtual functions are not supported in OpenCL C++}}
+};
+
+// Test that virtual base classes are allowed.
+struct A {
+  int a;
+  void foo();
+};
+
+struct B : virtual A {
+  int b;
+};
+
+struct C : public virtual A {
+  int c;
+};
+
+struct D : B, C {
+  int d;
+};
+
+kernel void virtual_inheritance() {
+  D d;
+
+  d.foo();
+  d.a = 11;
+  d.b = 22;
+  d.c = 33;
+  d.d = 44;
+}
Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -3466,7 +3466,15 @@
   isInvalid = DS.setFunctionSpecInline(Loc, PrevSpec, DiagID);
   break;
 case tok::kw_virtual:
-  isInvalid = DS.setFunctionSpecVirtual(Loc, PrevSpec, DiagID);
+  // OpenCL C++ v1.0 s2.9: the virtual function qualifier is not supported.
+  if (getLangOpts().OpenCLCPlusPlus) {
+DiagID = diag::err_openclcxx_virtual_function;
+PrevSpec = Tok.getIdentifierInfo()->getNameStart();
+isInvalid = true;
+  }
+  else {
+isInvalid = DS.setFunctionSpecVirtual(Loc, PrevSpec, DiagID);
+  }
   break;
 case tok::kw_explicit:
   isInvalid = DS.setFunctionSpecExplicit(Loc, PrevSpec, DiagID);
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1925,6 +1925,7 @@
 Opts.setDefaultFPContractMode(LangOptions::FPC_On);
 Opts.NativeHalfType = 1;
 Opts.NativeHalfArgsAndReturns = 1;
+Opts.OpenCLCPlusPlus = Opts.CPlusPlus;
 // Include default header file for OpenCL.
 if (Opts.IncludeDefaultHeader) {
   PPOpts.Includes.push_back("opencl-c.h");
Index: include/clang/Basic/LangOptions.def
===
--- include/clang/Basic/LangOptions.def
+++ include/clang/Basic/LangOptions.def
@@ -189,6 +189,7 @@
 
 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(NativeHalfType, 1, 0, "Native half type support")
 LANGOPT(NativeHalfArgsAndReturns, 1, 0, "Native half args and returns")
Index: include/clang/Basic/DiagnosticParseKinds.td
===
--- include/clang/Basic/DiagnosticParseKinds.td
+++ include/clang/Basic/DiagnosticParseKinds.td
@@ -1073,6 +1073,10 @@
 def err_opencl_logical_exclusive_or : Error<
   "^^ is a reserved operator in OpenCL">;
 
+// OpenCL C++.
+def err_openclcxx_virtual_function : Error<
+  "virtual functions are not supported in OpenCL C++">;
+
 // OpenMP support.
 def warn_pragma_omp_ignored : Warning<
   "unexpected '#pragma omp ...' in program">, InGroup, DefaultIgnore;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45873: [OpenCL] Reject virtual functions for OpenCL C++

2018-04-23 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC330579: [OpenCL] Reject virtual functions for OpenCL C++ 
(authored by svenvh, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D45873?vs=143330&id=143524#toc

Repository:
  rC Clang

https://reviews.llvm.org/D45873

Files:
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/LangOptions.def
  lib/Frontend/CompilerInvocation.cpp
  lib/Parse/ParseDecl.cpp
  test/Parser/opencl-cxx-virtual.cl

Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -3466,7 +3466,15 @@
   isInvalid = DS.setFunctionSpecInline(Loc, PrevSpec, DiagID);
   break;
 case tok::kw_virtual:
-  isInvalid = DS.setFunctionSpecVirtual(Loc, PrevSpec, DiagID);
+  // OpenCL C++ v1.0 s2.9: the virtual function qualifier is not supported.
+  if (getLangOpts().OpenCLCPlusPlus) {
+DiagID = diag::err_openclcxx_virtual_function;
+PrevSpec = Tok.getIdentifierInfo()->getNameStart();
+isInvalid = true;
+  }
+  else {
+isInvalid = DS.setFunctionSpecVirtual(Loc, PrevSpec, DiagID);
+  }
   break;
 case tok::kw_explicit:
   isInvalid = DS.setFunctionSpecExplicit(Loc, PrevSpec, DiagID);
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1927,6 +1927,7 @@
 Opts.setDefaultFPContractMode(LangOptions::FPC_On);
 Opts.NativeHalfType = 1;
 Opts.NativeHalfArgsAndReturns = 1;
+Opts.OpenCLCPlusPlus = Opts.CPlusPlus;
 // Include default header file for OpenCL.
 if (Opts.IncludeDefaultHeader) {
   PPOpts.Includes.push_back("opencl-c.h");
Index: include/clang/Basic/DiagnosticParseKinds.td
===
--- include/clang/Basic/DiagnosticParseKinds.td
+++ include/clang/Basic/DiagnosticParseKinds.td
@@ -1073,6 +1073,10 @@
 def err_opencl_logical_exclusive_or : Error<
   "^^ is a reserved operator in OpenCL">;
 
+// OpenCL C++.
+def err_openclcxx_virtual_function : Error<
+  "virtual functions are not supported in OpenCL C++">;
+
 // OpenMP support.
 def warn_pragma_omp_ignored : Warning<
   "unexpected '#pragma omp ...' in program">, InGroup, DefaultIgnore;
Index: include/clang/Basic/LangOptions.def
===
--- include/clang/Basic/LangOptions.def
+++ include/clang/Basic/LangOptions.def
@@ -189,6 +189,7 @@
 
 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(NativeHalfType, 1, 0, "Native half type support")
 LANGOPT(NativeHalfArgsAndReturns, 1, 0, "Native half args and returns")
Index: test/Parser/opencl-cxx-virtual.cl
===
--- test/Parser/opencl-cxx-virtual.cl
+++ test/Parser/opencl-cxx-virtual.cl
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -fsyntax-only -verify
+
+// Test that virtual functions and abstract classes are rejected.
+class virtual_functions {
+  virtual void bad1() {}
+  //expected-error@-1 {{virtual functions are not supported in OpenCL C++}}
+
+  virtual void bad2() = 0;
+  //expected-error@-1 {{virtual functions are not supported in OpenCL C++}}
+  //expected-error@-2 {{'bad2' is not virtual and cannot be declared pure}}
+};
+
+template 
+class X {
+  virtual T f();
+  //expected-error@-1 {{virtual functions are not supported in OpenCL C++}}
+};
+
+// Test that virtual base classes are allowed.
+struct A {
+  int a;
+  void foo();
+};
+
+struct B : virtual A {
+  int b;
+};
+
+struct C : public virtual A {
+  int c;
+};
+
+struct D : B, C {
+  int d;
+};
+
+kernel void virtual_inheritance() {
+  D d;
+
+  d.foo();
+  d.a = 11;
+  d.b = 22;
+  d.c = 33;
+  d.d = 44;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46022: [OpenCL] Restrict various keywords in OpenCL C++ mode

2018-04-24 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added reviewers: yaxunl, bader.
Herald added subscribers: cfe-commits, Anastasia.

Restrict the following keywords in the OpenCL C++ language mode,
according to Section 2.9 of the OpenCL C++ 1.0 Specification.

- dynamic_cast
- typeid
- goto
- register (already restricted in OpenCL C, update the diagnostic)
- thread_local
- asm
- exceptions (try/catch/throw)

Support the __global, __local, __constant, __private, and __generic
keywords in OpenCL C++.  OpenCL C++ does not provide the unprefixed
address space qualifiers such as global.  Instead, libclcxx provides
explicit address space pointer classes such as global_ptr and
global that are implemented using the __-prefixed qualifiers.

This patch is only a first stab at implementing the restrictions of
OpenCL C++ and is by no means complete.  It primarily covers
restrictions that are easily caught before Sema.


Repository:
  rC Clang

https://reviews.llvm.org/D46022

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TokenKinds.def
  include/clang/Sema/DeclSpec.h
  lib/Basic/IdentifierTable.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Parse/ParseDecl.cpp
  lib/Sema/DeclSpec.cpp
  test/Parser/opencl-cl20.cl
  test/Parser/opencl-cxx-keywords.cl
  test/Parser/opencl-storage-class.cl
  test/SemaOpenCL/storageclass.cl
  test/SemaOpenCLCXX/restricted.cl

Index: test/SemaOpenCLCXX/restricted.cl
===
--- /dev/null
+++ test/SemaOpenCLCXX/restricted.cl
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -verify -fsyntax-only
+
+// This test checks that various C/C++/OpenCL C constructs are not available in
+// OpenCL C++, according to OpenCL C++ 1.0 Specification Section 2.9.
+
+// Test storage class qualifiers.
+kernel void test_storage_classes() {
+  register int x;
+  // expected-error@-1 {{OpenCL C++ version 1.0 does not support the 'register' storage class specifier}}
+  thread_local int y;
+  // expected-error@-1 {{OpenCL C++ version 1.0 does not support the 'thread_local' storage class specifier}}
+}
Index: test/SemaOpenCL/storageclass.cl
===
--- test/SemaOpenCL/storageclass.cl
+++ test/SemaOpenCL/storageclass.cl
@@ -10,14 +10,14 @@
 static global float g_global_static_var = 0;   // expected-error {{program scope variable must reside in constant address space}}
 static local float g_local_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
 static private float g_private_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
-static generic float g_generic_static_var = 0; // expected-error{{OpenCL version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address space}}
+static generic float g_generic_static_var = 0; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address space}}
 
 extern float g_implicit_extern_var; // expected-error {{extern variable must reside in constant address space}}
 extern constant float g_constant_extern_var;
 extern global float g_global_extern_var;   // expected-error {{extern variable must reside in constant address space}}
 extern local float g_local_extern_var; // expected-error {{extern variable must reside in constant address space}}
 extern private float g_private_extern_var; // expected-error {{extern variable must reside in constant address space}}
-extern generic float g_generic_extern_var; // expected-error{{OpenCL version 1.2 does not support the 'generic' type qualifier}} // expected-error {{extern variable must reside in constant address space}}
+extern generic float g_generic_extern_var; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error {{extern variable must reside in constant address space}}
 
 void kernel foo(int x) {
   // static is not allowed at local scope before CL2.0
@@ -32,7 +32,7 @@
 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}}
+  auto int L3 = 7;// expected-error{{OpenCL C 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}}
 
@@ -64,12 +64,12 @@
   static global float l_global_static_var = 0; // expected-

[PATCH] D46049: [OpenCL] Add constant address space to __func__ in AST

2018-04-25 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:3056
+  if (LangOpts.OpenCL)
+  ResTy = Context.getAddrSpaceQualType(ResTy, LangAS::opencl_constant);
   ResTy = Context.getConstantArrayType(ResTy, LengthI, ArrayType::Normal,

Nitpick: local indent style is 2 spaces.



Comment at: test/SemaOpenCL/predefind-expr.cl:1
+// RUN: %clang_cc1 %s -verify
+

predefind-expr.cl -> predefined_expr.cl

Also please indent the function body.


https://reviews.llvm.org/D46049



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


[PATCH] D46022: [OpenCL] Restrict various keywords in OpenCL C++ mode

2018-04-25 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh updated this revision to Diff 143951.
svenvh edited the summary of this revision.
svenvh added a comment.

Implemented most of the restrictions as parser or Sema checks instead.  This 
results in nicer diagnostics too, thanks for the suggestion!

For the address space qualifiers such as global / __global / local / ..., I 
still think we should differentiate them in the lexer, as "global", "local" 
etc. are not reserved keywords in OpenCL C++.


https://reviews.llvm.org/D46022

Files:
  include/clang/Basic/DiagnosticCommonKinds.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TokenKinds.def
  include/clang/Sema/DeclSpec.h
  lib/Basic/IdentifierTable.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseStmtAsm.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaCast.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaStmt.cpp
  test/Parser/opencl-cl20.cl
  test/Parser/opencl-cxx-keywords.cl
  test/Parser/opencl-storage-class.cl
  test/SemaOpenCL/storageclass.cl
  test/SemaOpenCLCXX/restricted.cl

Index: test/SemaOpenCLCXX/restricted.cl
===
--- /dev/null
+++ test/SemaOpenCLCXX/restricted.cl
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -verify -fsyntax-only
+
+// This test checks that various C/C++/OpenCL C constructs are not available in
+// OpenCL C++, according to OpenCL C++ 1.0 Specification Section 2.9.
+
+// Test that typeid is not available in OpenCL C++.
+namespace std {
+  // Provide a dummy std::type_info so that we can use typeid.
+  class type_info {
+int a;
+  };
+}
+__constant std::type_info int_ti = typeid(int);
+// expected-error@-1 {{'typeid' is not supported in OpenCL C++}}
+
+// Test that dynamic_cast is not available in OpenCL C++.
+class A {
+public:
+  int a;
+};
+
+class B : public A {
+  int b;
+};
+
+B *test_dynamic_cast(B *p) {
+  return dynamic_cast(p);
+  // expected-error@-1 {{'dynamic_cast' is not supported in OpenCL C++}}
+}
+
+// Test storage class qualifiers.
+kernel void test_storage_classes() {
+  register int x;
+  // expected-error@-1 {{OpenCL C++ version 1.0 does not support the 'register' storage class specifier}}
+  thread_local int y;
+  // expected-error@-1 {{OpenCL C++ version 1.0 does not support the 'thread_local' storage class specifier}}
+}
+
+// Test other keywords that are not available in OpenCL C++.
+kernel void test_misc() {
+  goto label;
+  // expected-error@-1 {{'goto' is not supported in OpenCL C++}}
+label:
+  asm("");
+  // expected-error@-1 {{'asm' is not supported in OpenCL C++}}
+  // expected-warning@-2 {{expression result unused}}
+}
Index: test/SemaOpenCL/storageclass.cl
===
--- test/SemaOpenCL/storageclass.cl
+++ test/SemaOpenCL/storageclass.cl
@@ -10,14 +10,14 @@
 static global float g_global_static_var = 0;   // expected-error {{program scope variable must reside in constant address space}}
 static local float g_local_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
 static private float g_private_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
-static generic float g_generic_static_var = 0; // expected-error{{OpenCL version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address space}}
+static generic float g_generic_static_var = 0; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address space}}
 
 extern float g_implicit_extern_var; // expected-error {{extern variable must reside in constant address space}}
 extern constant float g_constant_extern_var;
 extern global float g_global_extern_var;   // expected-error {{extern variable must reside in constant address space}}
 extern local float g_local_extern_var; // expected-error {{extern variable must reside in constant address space}}
 extern private float g_private_extern_var; // expected-error {{extern variable must reside in constant address space}}
-extern generic float g_generic_extern_var; // expected-error{{OpenCL version 1.2 does not support the 'generic' type qualifier}} // expected-error {{extern variable must reside in constant address space}}
+extern generic float g_generic_extern_var; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error {{extern variable must reside in constant address space}}
 
 void kernel foo(int x) {
   // static is not allowed at local scope before CL2.0
@@ -32,7 +32,7 @@
 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 vers

[PATCH] D46022: [OpenCL] Restrict various keywords in OpenCL C++ mode

2018-04-26 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh updated this revision to Diff 144098.
svenvh edited the summary of this revision.
svenvh added a comment.

Updated patch to reject any thread storage class specifier, not just 
`thread_local`.

Also mark the OpenCL access qualifiers as reserved keywords as per OpenCL C++ 
1.0 s2.2, and add a test for those.


https://reviews.llvm.org/D46022

Files:
  include/clang/Basic/DiagnosticCommonKinds.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TokenKinds.def
  include/clang/Sema/DeclSpec.h
  lib/Basic/IdentifierTable.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseStmtAsm.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaCast.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaStmt.cpp
  test/Parser/opencl-cl20.cl
  test/Parser/opencl-cxx-keywords.cl
  test/Parser/opencl-storage-class.cl
  test/SemaOpenCL/storageclass.cl
  test/SemaOpenCLCXX/restricted.cl

Index: test/SemaOpenCLCXX/restricted.cl
===
--- /dev/null
+++ test/SemaOpenCLCXX/restricted.cl
@@ -0,0 +1,73 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -verify -fsyntax-only
+
+// This test checks that various C/C++/OpenCL C constructs are not available in
+// OpenCL C++, according to OpenCL C++ 1.0 Specification Section 2.9.
+
+// Test that typeid is not available in OpenCL C++.
+namespace std {
+  // Provide a dummy std::type_info so that we can use typeid.
+  class type_info {
+int a;
+  };
+}
+__constant std::type_info int_ti = typeid(int);
+// expected-error@-1 {{'typeid' is not supported in OpenCL C++}}
+
+// Test that dynamic_cast is not available in OpenCL C++.
+class A {
+public:
+  int a;
+};
+
+class B : public A {
+  int b;
+};
+
+B *test_dynamic_cast(B *p) {
+  return dynamic_cast(p);
+  // expected-error@-1 {{'dynamic_cast' is not supported in OpenCL C++}}
+}
+
+// Test storage class qualifiers.
+__constant _Thread_local int a = 1;
+// expected-error@-1 {{OpenCL C++ version 1.0 does not support the '_Thread_local' storage class specifier}}
+__constant __thread int b = 2;
+// expected-error@-1 {{OpenCL C++ version 1.0 does not support the '__thread' storage class specifier}}
+kernel void test_storage_classes() {
+  register int x;
+  // expected-error@-1 {{OpenCL C++ version 1.0 does not support the 'register' storage class specifier}}
+  thread_local int y;
+  // expected-error@-1 {{OpenCL C++ version 1.0 does not support the 'thread_local' storage class specifier}}
+}
+
+// Test that access qualifiers are reserved keywords.
+kernel void test_access_qualifiers() {
+  int read_only;
+  // expected-error@-1 {{'read_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int __read_only;
+  // expected-error@-1 {{'__read_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int write_only;
+  // expected-error@-1 {{'write_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int __write_only;
+  // expected-error@-1 {{'__write_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int read_write;
+  // expected-error@-1 {{'read_write' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int __read_write;
+  // expected-error@-1 {{'__read_write' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+}
+
+// Test other keywords that are not available in OpenCL C++.
+kernel void test_misc() {
+  goto label;
+  // expected-error@-1 {{'goto' is not supported in OpenCL C++}}
+label:
+  asm("");
+  // expected-error@-1 {{'asm' is not supported in OpenCL C++}}
+  // expected-warning@-2 {{expression result unused}}
+}
Index: test/SemaOpenCL/storageclass.cl
===
--- test/SemaOpenCL/storageclass.cl
+++ test/SemaOpenCL/storageclass.cl
@@ -10,14 +10,14 @@
 static global float g_global_static_var = 0;   // expected-error {{program scope variable must reside in constant address space}}
 static local float g_local_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
 static private float g_private_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
-static generic float g_generic_static_var = 0; // expected-error{{OpenCL version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address space}}
+static generic float g_generic_static_var = 0; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address

[PATCH] D46022: [OpenCL] Restrict various keywords in OpenCL C++ mode

2018-04-26 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: include/clang/Basic/TokenKinds.def:255
+//   KEYNOOPENCL  - This is a keyword that is not supported in OpenCL C
+//  nor in OpenCL C++.
 //   KEYALTIVEC - This is a keyword in AltiVec

rjmccall wrote:
> `KEYNOOPENCL` is dead now, I think.
There are still some other uses of `KEYNOOPENCL` (already there before this 
patch).



Comment at: lib/Sema/DeclSpec.cpp:621
+// OpenCL C++ 1.0 s2.9: the thread_local storage qualifier is not
+// supported.
+case TSCS_thread_local:

rjmccall wrote:
> Do you really care about the spelling of the specifier?  Presumably 
> `__thread` (the GNU extension) and `_Thread_local` (the C11 feature) are 
> unsupported; where are those diagnosed?
Fair enough, I have updated the patch to just reject any thread qualifier here.


https://reviews.llvm.org/D46022



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


[PATCH] D46022: [OpenCL] Restrict various keywords in OpenCL C++ mode

2018-04-26 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: lib/Parse/ParseStmtAsm.cpp:696
+return StmtError();
+  }
+

rjmccall wrote:
> You might consider parsing the statement normally and then just diagnosing 
> after the fact, maybe in Sema.  You'd have to add the check in a couple 
> different places, though.
Precisely the reason why I did it in the parser, otherwise we'd have to 
duplicate the check in multiple places.



Comment at: lib/Sema/DeclSpec.cpp:621
+// OpenCL C++ 1.0 s2.9: the thread_local storage qualifier is not
+// supported.
+case TSCS_thread_local:

rjmccall wrote:
> svenvh wrote:
> > rjmccall wrote:
> > > Do you really care about the spelling of the specifier?  Presumably 
> > > `__thread` (the GNU extension) and `_Thread_local` (the C11 feature) are 
> > > unsupported; where are those diagnosed?
> > Fair enough, I have updated the patch to just reject any thread qualifier 
> > here.
> I meant it as a question, but I take it from this response that we don't 
> actually diagnose these.
> 
> It might make more sense to diagnose this in `Sema::ActOnVariableDeclarator`, 
> where we're already doing some checking about whether e.g. the target 
> supports the feature.
We do actually diagnose the others in `Sema::ActOnVariableDeclarator` 
("thread-local storage is not supported for the current target").  But your 
question made me realize there is no real need to differentiate here for the 
OpenCL C++ case.



Comment at: lib/Sema/SemaStmt.cpp:2791
+ << "goto");
+  }
+

rjmccall wrote:
> Is this restriction really OpenCL C++-specific?  I mean, if that's what the 
> language spec says, that's what it says, but I don't know what about OpenCL 
> C++ would make `goto` unsupportable when it's supportable in ordinary OpenCL.
> 
> You should also add this check to ActOnIndirectGotoStmt.
Yes (oddly enough).  The OpenCL C++ 1.0 spec explicitly mentions `goto` in the 
Restrictions section on page 51.  The OpenCL C 1.1 / 2.0 specs ("ordinary 
OpenCL") do not restrict goto.

I'll add the check for indirect goto statements.


https://reviews.llvm.org/D46022



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


[PATCH] D46022: [OpenCL] Restrict various keywords in OpenCL C++ mode

2018-04-26 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh updated this revision to Diff 144138.
svenvh added a comment.

Reject goto in `Sema::ActOnIndirectGotoStmt` too, and add a test for indirect 
goto.


https://reviews.llvm.org/D46022

Files:
  include/clang/Basic/DiagnosticCommonKinds.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TokenKinds.def
  include/clang/Sema/DeclSpec.h
  lib/Basic/IdentifierTable.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseStmtAsm.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaCast.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaStmt.cpp
  test/Parser/opencl-cl20.cl
  test/Parser/opencl-cxx-keywords.cl
  test/Parser/opencl-storage-class.cl
  test/SemaOpenCL/storageclass.cl
  test/SemaOpenCLCXX/restricted.cl

Index: test/SemaOpenCLCXX/restricted.cl
===
--- /dev/null
+++ test/SemaOpenCLCXX/restricted.cl
@@ -0,0 +1,77 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -verify -fsyntax-only
+
+// This test checks that various C/C++/OpenCL C constructs are not available in
+// OpenCL C++, according to OpenCL C++ 1.0 Specification Section 2.9.
+
+// Test that typeid is not available in OpenCL C++.
+namespace std {
+  // Provide a dummy std::type_info so that we can use typeid.
+  class type_info {
+int a;
+  };
+}
+__constant std::type_info int_ti = typeid(int);
+// expected-error@-1 {{'typeid' is not supported in OpenCL C++}}
+
+// Test that dynamic_cast is not available in OpenCL C++.
+class A {
+public:
+  int a;
+};
+
+class B : public A {
+  int b;
+};
+
+B *test_dynamic_cast(B *p) {
+  return dynamic_cast(p);
+  // expected-error@-1 {{'dynamic_cast' is not supported in OpenCL C++}}
+}
+
+// Test storage class qualifiers.
+__constant _Thread_local int a = 1;
+// expected-error@-1 {{OpenCL C++ version 1.0 does not support the '_Thread_local' storage class specifier}}
+__constant __thread int b = 2;
+// expected-error@-1 {{OpenCL C++ version 1.0 does not support the '__thread' storage class specifier}}
+kernel void test_storage_classes() {
+  register int x;
+  // expected-error@-1 {{OpenCL C++ version 1.0 does not support the 'register' storage class specifier}}
+  thread_local int y;
+  // expected-error@-1 {{OpenCL C++ version 1.0 does not support the 'thread_local' storage class specifier}}
+}
+
+// Test that access qualifiers are reserved keywords.
+kernel void test_access_qualifiers() {
+  int read_only;
+  // expected-error@-1 {{'read_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int __read_only;
+  // expected-error@-1 {{'__read_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int write_only;
+  // expected-error@-1 {{'write_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int __write_only;
+  // expected-error@-1 {{'__write_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int read_write;
+  // expected-error@-1 {{'read_write' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int __read_write;
+  // expected-error@-1 {{'__read_write' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+}
+
+// Test other keywords that are not available in OpenCL C++.
+kernel void test_misc() {
+  goto label;
+  // expected-error@-1 {{'goto' is not supported in OpenCL C++}}
+  goto *&&label;
+  // expected-error@-1 {{'goto' is not supported in OpenCL C++}}
+  // expected-warning@-2 {{use of GNU indirect-goto extension}}
+  // expected-warning@-3 {{use of GNU address-of-label extension}}
+label:
+  asm("");
+  // expected-error@-1 {{'asm' is not supported in OpenCL C++}}
+  // expected-warning@-2 {{expression result unused}}
+}
Index: test/SemaOpenCL/storageclass.cl
===
--- test/SemaOpenCL/storageclass.cl
+++ test/SemaOpenCL/storageclass.cl
@@ -10,14 +10,14 @@
 static global float g_global_static_var = 0;   // expected-error {{program scope variable must reside in constant address space}}
 static local float g_local_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
 static private float g_private_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
-static generic float g_generic_static_var = 0; // expected-error{{OpenCL version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address space}}
+static generic float g_generic_static_var = 0; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error 

[PATCH] D46022: [OpenCL] Restrict various keywords in OpenCL C++ mode

2018-04-26 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: lib/Parse/ParseStmtAsm.cpp:696
+return StmtError();
+  }
+

rjmccall wrote:
> svenvh wrote:
> > rjmccall wrote:
> > > You might consider parsing the statement normally and then just 
> > > diagnosing after the fact, maybe in Sema.  You'd have to add the check in 
> > > a couple different places, though.
> > Precisely the reason why I did it in the parser, otherwise we'd have to 
> > duplicate the check in multiple places.
> The downside of this is that the parser recovery is probably very bad.  But 
> since this is asm, it's not likely to matter too much.
> 
> ...is this *also* really only an OpenCL C++ restriction?  Maybe we should 
> read this one as a general restriction that happens to have been overlooked 
> in the OpenCL C spec.
Yes, `asm` is only explicitly restricted in OpenCL C++.  Not sure if it's safe 
to assume `asm` has been overlooked for OpenCL C though, it's not explicitly 
forbidden so people may be using it.



Comment at: lib/Sema/DeclSpec.cpp:621
+// OpenCL C++ 1.0 s2.9: the thread_local storage qualifier is not
+// supported.
+case TSCS_thread_local:

rjmccall wrote:
> svenvh wrote:
> > rjmccall wrote:
> > > svenvh wrote:
> > > > rjmccall wrote:
> > > > > Do you really care about the spelling of the specifier?  Presumably 
> > > > > `__thread` (the GNU extension) and `_Thread_local` (the C11 feature) 
> > > > > are unsupported; where are those diagnosed?
> > > > Fair enough, I have updated the patch to just reject any thread 
> > > > qualifier here.
> > > I meant it as a question, but I take it from this response that we don't 
> > > actually diagnose these.
> > > 
> > > It might make more sense to diagnose this in 
> > > `Sema::ActOnVariableDeclarator`, where we're already doing some checking 
> > > about whether e.g. the target supports the feature.
> > We do actually diagnose the others in `Sema::ActOnVariableDeclarator` 
> > ("thread-local storage is not supported for the current target").  But your 
> > question made me realize there is no real need to differentiate here for 
> > the OpenCL C++ case.
> Okay.  So we can remove this code, then.
Sorry if my previous comment was ambiguous: I meant here we now reject *any* 
thread storage class specifier for OpenCL C++, not just the `thread_local` 
spelling (my original patch was only rejecting `TSCS_thread_local`).


https://reviews.llvm.org/D46022



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


[PATCH] D46015: [OpenCL] Add separate read_only and write_only pipe IR types

2018-04-27 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331026: [OpenCL] Add separate read_only and write_only pipe 
IR types (authored by svenvh, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46015?vs=143938&id=144307#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46015

Files:
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/lib/CodeGen/CGOpenCLRuntime.cpp
  cfe/trunk/lib/CodeGen/CGOpenCLRuntime.h
  cfe/trunk/test/CodeGenOpenCL/opencl_types.cl
  cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
  cfe/trunk/test/CodeGenOpenCL/pipe_types.cl
  cfe/trunk/test/Index/pipe-size.cl

Index: cfe/trunk/test/CodeGenOpenCL/pipe_types.cl
===
--- cfe/trunk/test/CodeGenOpenCL/pipe_types.cl
+++ cfe/trunk/test/CodeGenOpenCL/pipe_types.cl
@@ -1,34 +1,35 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck %s
 
-// CHECK: %opencl.pipe_t = type opaque
+// CHECK: %opencl.pipe_ro_t = type opaque
+// CHECK: %opencl.pipe_wo_t = type opaque
 typedef unsigned char __attribute__((ext_vector_type(3))) uchar3;
 typedef int __attribute__((ext_vector_type(4))) int4;
 
 void test1(read_only pipe int p) {
-// CHECK: define void @test1(%opencl.pipe_t* %p)
+// CHECK: define void @test1(%opencl.pipe_ro_t* %p)
   reserve_id_t rid;
 // CHECK: %rid = alloca %opencl.reserve_id_t
 }
 
 void test2(write_only pipe float p) {
-// CHECK: define void @test2(%opencl.pipe_t* %p)
+// CHECK: define void @test2(%opencl.pipe_wo_t* %p)
 }
 
 void test3(read_only pipe const int p) {
-// CHECK: define void @test3(%opencl.pipe_t* %p)
+// CHECK: define void @test3(%opencl.pipe_ro_t* %p)
 }
 
 void test4(read_only pipe uchar3 p) {
-// CHECK: define void @test4(%opencl.pipe_t* %p)
+// CHECK: define void @test4(%opencl.pipe_ro_t* %p)
 }
 
 void test5(read_only pipe int4 p) {
-// CHECK: define void @test5(%opencl.pipe_t* %p)
+// CHECK: define void @test5(%opencl.pipe_ro_t* %p)
 }
 
 typedef read_only pipe int MyPipe;
 kernel void test6(MyPipe p) {
-// CHECK: define spir_kernel void @test6(%opencl.pipe_t* %p)
+// CHECK: define spir_kernel void @test6(%opencl.pipe_ro_t* %p)
 }
 
 struct Person {
@@ -41,7 +42,7 @@
  read_only pipe struct Person SPipe) {
 // CHECK: define void @test_reserved_read_pipe
   read_pipe (SPipe, SDst);
-  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8)
+  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_ro_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8)
   read_pipe (SPipe, SDst);
-  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8)
+  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_ro_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8)
 }
Index: cfe/trunk/test/CodeGenOpenCL/opencl_types.cl
===
--- cfe/trunk/test/CodeGenOpenCL/opencl_types.cl
+++ cfe/trunk/test/CodeGenOpenCL/opencl_types.cl
@@ -63,9 +63,13 @@
   // CHECK-AMDGCN: call {{.*}}void @fnc4smp(%opencl.sampler_t addrspace(4)*
 }
 
-kernel void foo_pipe(read_only pipe int p) {}
-// CHECK-SPIR: @foo_pipe(%opencl.pipe_t addrspace(1)* %p)
-// CHECK_AMDGCN: @foo_pipe(%opencl.pipe_t addrspace(1)* %p)
+kernel void foo_ro_pipe(read_only pipe int p) {}
+// CHECK-SPIR: @foo_ro_pipe(%opencl.pipe_ro_t addrspace(1)* %p)
+// CHECK_AMDGCN: @foo_ro_pipe(%opencl.pipe_ro_t addrspace(1)* %p)
+
+kernel void foo_wo_pipe(write_only pipe int p) {}
+// CHECK-SPIR: @foo_wo_pipe(%opencl.pipe_wo_t addrspace(1)* %p)
+// CHECK_AMDGCN: @foo_wo_pipe(%opencl.pipe_wo_t addrspace(1)* %p)
 
 void __attribute__((overloadable)) bad1(image1d_t b, image2d_t c, image2d_t d) {}
 // CHECK-SPIR-LABEL: @{{_Z4bad114ocl_image1d_ro14ocl_image2d_roS0_|"\\01\?bad1@@\$\$J0YAXPAUocl_image1d_ro@@PAUocl_image2d_ro@@1@Z"}}
Index: cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
===
--- cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
+++ cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
@@ -1,79 +1,93 @@
 // RUN: %clang_cc1 -emit-llvm -cl-ext=+cl_khr_subgroups -O0 -cl-std=CL2.0 -o - %s | FileCheck %s
 
-// CHECK: %opencl.pipe_t = type opaque
-// CHECK: %opencl.reserve_id_t = type opaque
+// CHECK-DAG: %opencl.pipe_ro_t = type opaque
+// CHECK-DAG: %opencl.pipe_wo_t = type opaque
+// CHECK-DAG: %opencl.reserve_id_t = type opaque
 
 #pragma OPENCL EXTENSION cl_khr_subgroups : enable
 
 void test1(read_only pipe int p, global int *ptr) {
-  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}}, i32 4, i32 4)
+  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_ro_t* %{{.*}}, i8* %{{.*}}, i32 4, i32 4)
   read_pipe(p, ptr);
-  // CHECK: call %opencl.reserve_id_t* @__reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
+ 

[PATCH] D46022: [OpenCL] Restrict various keywords in OpenCL C++ mode

2018-04-30 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh updated this revision to Diff 144583.
svenvh added a comment.

Moved thread storage class specifier diagnosing to `ActOnVariableDeclarator`.


https://reviews.llvm.org/D46022

Files:
  include/clang/Basic/DiagnosticCommonKinds.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TokenKinds.def
  lib/Basic/IdentifierTable.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseStmtAsm.cpp
  lib/Sema/SemaCast.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaStmt.cpp
  test/Parser/opencl-cl20.cl
  test/Parser/opencl-cxx-keywords.cl
  test/Parser/opencl-storage-class.cl
  test/SemaOpenCL/storageclass.cl
  test/SemaOpenCLCXX/restricted.cl

Index: test/SemaOpenCLCXX/restricted.cl
===
--- /dev/null
+++ test/SemaOpenCLCXX/restricted.cl
@@ -0,0 +1,77 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -verify -fsyntax-only
+
+// This test checks that various C/C++/OpenCL C constructs are not available in
+// OpenCL C++, according to OpenCL C++ 1.0 Specification Section 2.9.
+
+// Test that typeid is not available in OpenCL C++.
+namespace std {
+  // Provide a dummy std::type_info so that we can use typeid.
+  class type_info {
+int a;
+  };
+}
+__constant std::type_info int_ti = typeid(int);
+// expected-error@-1 {{'typeid' is not supported in OpenCL C++}}
+
+// Test that dynamic_cast is not available in OpenCL C++.
+class A {
+public:
+  int a;
+};
+
+class B : public A {
+  int b;
+};
+
+B *test_dynamic_cast(B *p) {
+  return dynamic_cast(p);
+  // expected-error@-1 {{'dynamic_cast' is not supported in OpenCL C++}}
+}
+
+// Test storage class qualifiers.
+__constant _Thread_local int a = 1;
+// expected-error@-1 {{OpenCL C++ version 1.0 does not support the '_Thread_local' storage class specifier}}
+__constant __thread int b = 2;
+// expected-error@-1 {{OpenCL C++ version 1.0 does not support the '__thread' storage class specifier}}
+kernel void test_storage_classes() {
+  register int x;
+  // expected-error@-1 {{OpenCL C++ version 1.0 does not support the 'register' storage class specifier}}
+  thread_local int y;
+  // expected-error@-1 {{OpenCL C++ version 1.0 does not support the 'thread_local' storage class specifier}}
+}
+
+// Test that access qualifiers are reserved keywords.
+kernel void test_access_qualifiers() {
+  int read_only;
+  // expected-error@-1 {{'read_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int __read_only;
+  // expected-error@-1 {{'__read_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int write_only;
+  // expected-error@-1 {{'write_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int __write_only;
+  // expected-error@-1 {{'__write_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int read_write;
+  // expected-error@-1 {{'read_write' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int __read_write;
+  // expected-error@-1 {{'__read_write' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+}
+
+// Test other keywords that are not available in OpenCL C++.
+kernel void test_misc() {
+  goto label;
+  // expected-error@-1 {{'goto' is not supported in OpenCL C++}}
+  goto *&&label;
+  // expected-error@-1 {{'goto' is not supported in OpenCL C++}}
+  // expected-warning@-2 {{use of GNU indirect-goto extension}}
+  // expected-warning@-3 {{use of GNU address-of-label extension}}
+label:
+  asm("");
+  // expected-error@-1 {{'asm' is not supported in OpenCL C++}}
+  // expected-warning@-2 {{expression result unused}}
+}
Index: test/SemaOpenCL/storageclass.cl
===
--- test/SemaOpenCL/storageclass.cl
+++ test/SemaOpenCL/storageclass.cl
@@ -10,14 +10,14 @@
 static global float g_global_static_var = 0;   // expected-error {{program scope variable must reside in constant address space}}
 static local float g_local_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
 static private float g_private_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
-static generic float g_generic_static_var = 0; // expected-error{{OpenCL version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address space}}
+static generic float g_generic_static_var = 0; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in

[PATCH] D46022: [OpenCL] Restrict various keywords in OpenCL C++ mode

2018-04-30 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: lib/Parse/ParseStmtAsm.cpp:696
+return StmtError();
+  }
+

rjmccall wrote:
> svenvh wrote:
> > rjmccall wrote:
> > > svenvh wrote:
> > > > rjmccall wrote:
> > > > > You might consider parsing the statement normally and then just 
> > > > > diagnosing after the fact, maybe in Sema.  You'd have to add the 
> > > > > check in a couple different places, though.
> > > > Precisely the reason why I did it in the parser, otherwise we'd have to 
> > > > duplicate the check in multiple places.
> > > The downside of this is that the parser recovery is probably very bad.  
> > > But since this is asm, it's not likely to matter too much.
> > > 
> > > ...is this *also* really only an OpenCL C++ restriction?  Maybe we should 
> > > read this one as a general restriction that happens to have been 
> > > overlooked in the OpenCL C spec.
> > Yes, `asm` is only explicitly restricted in OpenCL C++.  Not sure if it's 
> > safe to assume `asm` has been overlooked for OpenCL C though, it's not 
> > explicitly forbidden so people may be using it.
> Do you have any contact with the OpenCL committee?  You might want to collect 
> these issues and present them to them.  They may just not be aware that `asm` 
> is just as much a feature in C as it is in C++, and it would be good to 
> understand what the purpose of the `goto` restriction is.
Yes, we can clarify this with Khronos.  Shall I leave the `asm` and `goto` 
restrictions out of this patch for now until we have clarification?


https://reviews.llvm.org/D46022



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


[PATCH] D46022: [OpenCL] Restrict various keywords in OpenCL C++ mode

2018-05-01 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh updated this revision to Diff 144745.
svenvh edited the summary of this revision.
svenvh added a comment.

Dropped the `asm` and `goto` restrictions from this patch for now until we have 
clarification from Khronos.

Applied the `thread_local` restrictions to OpenCL C too.


https://reviews.llvm.org/D46022

Files:
  include/clang/Basic/DiagnosticCommonKinds.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TokenKinds.def
  lib/Basic/IdentifierTable.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Parse/ParseDecl.cpp
  lib/Sema/SemaCast.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExprCXX.cpp
  test/Parser/opencl-cl20.cl
  test/Parser/opencl-cxx-keywords.cl
  test/Parser/opencl-storage-class.cl
  test/SemaOpenCL/storageclass.cl
  test/SemaOpenCLCXX/restricted.cl

Index: test/SemaOpenCLCXX/restricted.cl
===
--- /dev/null
+++ test/SemaOpenCLCXX/restricted.cl
@@ -0,0 +1,63 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -verify -fsyntax-only
+
+// This test checks that various C/C++/OpenCL C constructs are not available in
+// OpenCL C++, according to OpenCL C++ 1.0 Specification Section 2.9.
+
+// Test that typeid is not available in OpenCL C++.
+namespace std {
+  // Provide a dummy std::type_info so that we can use typeid.
+  class type_info {
+int a;
+  };
+}
+__constant std::type_info int_ti = typeid(int);
+// expected-error@-1 {{'typeid' is not supported in OpenCL C++}}
+
+// Test that dynamic_cast is not available in OpenCL C++.
+class A {
+public:
+  int a;
+};
+
+class B : public A {
+  int b;
+};
+
+B *test_dynamic_cast(B *p) {
+  return dynamic_cast(p);
+  // expected-error@-1 {{'dynamic_cast' is not supported in OpenCL C++}}
+}
+
+// Test storage class qualifiers.
+__constant _Thread_local int a = 1;
+// expected-error@-1 {{OpenCL C++ version 1.0 does not support the '_Thread_local' storage class specifier}}
+__constant __thread int b = 2;
+// expected-error@-1 {{OpenCL C++ version 1.0 does not support the '__thread' storage class specifier}}
+kernel void test_storage_classes() {
+  register int x;
+  // expected-error@-1 {{OpenCL C++ version 1.0 does not support the 'register' storage class specifier}}
+  thread_local int y;
+  // expected-error@-1 {{OpenCL C++ version 1.0 does not support the 'thread_local' storage class specifier}}
+}
+
+// Test that access qualifiers are reserved keywords.
+kernel void test_access_qualifiers() {
+  int read_only;
+  // expected-error@-1 {{'read_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int __read_only;
+  // expected-error@-1 {{'__read_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int write_only;
+  // expected-error@-1 {{'write_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int __write_only;
+  // expected-error@-1 {{'__write_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int read_write;
+  // expected-error@-1 {{'read_write' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int __read_write;
+  // expected-error@-1 {{'__read_write' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+}
Index: test/SemaOpenCL/storageclass.cl
===
--- test/SemaOpenCL/storageclass.cl
+++ test/SemaOpenCL/storageclass.cl
@@ -10,14 +10,14 @@
 static global float g_global_static_var = 0;   // expected-error {{program scope variable must reside in constant address space}}
 static local float g_local_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
 static private float g_private_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
-static generic float g_generic_static_var = 0; // expected-error{{OpenCL version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address space}}
+static generic float g_generic_static_var = 0; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address space}}
 
 extern float g_implicit_extern_var; // expected-error {{extern variable must reside in constant address space}}
 extern constant float g_constant_extern_var;
 extern global float g_global_extern_var;   // expected-error {{extern variable must reside in constant address space}}
 extern local float g_local_extern_var; // expected-error {{extern variable must reside in constant address space}}
 extern private float g_p

[PATCH] D46382: [OpenCL] Factor out language version printing

2018-05-03 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: rivanvx.
Herald added a subscriber: cfe-commits.

Generate a printable OpenCL language version number in a single place
and select between the OpenCL C or OpenCL C++ version accordingly.


Repository:
  rC Clang

https://reviews.llvm.org/D46382

Files:
  include/clang/Basic/LangOptions.h
  lib/Basic/LangOptions.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Parse/ParseDecl.cpp


Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -29,7 +29,6 @@
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
-#include "llvm/Support/ScopedPrinter.h"
 
 using namespace clang;
 
@@ -3806,11 +3805,8 @@
 Diag(Tok, DiagID)
   << PrevSpec << FixItHint::CreateRemoval(Tok.getLocation());
   else if (DiagID == diag::err_opencl_unknown_type_specifier) {
-const int OpenCLVer = getLangOpts().OpenCLVersion;
-std::string VerSpec = llvm::to_string(OpenCLVer / 100) +
-  std::string (".") +
-  llvm::to_string((OpenCLVer % 100) / 10);
-Diag(Tok, DiagID) << VerSpec << PrevSpec << isStorageClass;
+Diag(Tok, DiagID) << 
getLangOpts().getOpenCLVersionTuple().getAsString()
+  << PrevSpec << isStorageClass;
   } else
 Diag(Tok, DiagID) << PrevSpec;
 }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -76,7 +76,6 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Regex.h"
-#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetOptions.h"
 #include 
@@ -2145,11 +2144,9 @@
   // this option was added for compatibility with OpenCL 1.0.
   if (Args.getLastArg(OPT_cl_strict_aliasing)
&& Opts.OpenCLVersion > 100) {
-std::string VerSpec = llvm::to_string(Opts.OpenCLVersion / 100) +
-  std::string(".") +
-  llvm::to_string((Opts.OpenCLVersion % 100) / 10);
 Diags.Report(diag::warn_option_invalid_ocl_version)
-  << VerSpec << Args.getLastArg(OPT_cl_strict_aliasing)->getAsString(Args);
+<< Opts.getOpenCLVersionTuple().getAsString()
+<< Args.getLastArg(OPT_cl_strict_aliasing)->getAsString(Args);
   }
 
   // We abuse '-f[no-]gnu-keywords' to force overriding all GNU-extension
Index: lib/Basic/LangOptions.cpp
===
--- lib/Basic/LangOptions.cpp
+++ lib/Basic/LangOptions.cpp
@@ -43,3 +43,8 @@
   return true;
   return false;
 }
+
+VersionTuple LangOptions::getOpenCLVersionTuple() const {
+  const int Ver = OpenCLCPlusPlus ? OpenCLCPlusPlusVersion : OpenCLVersion;
+  return VersionTuple(Ver / 100, (Ver % 100) / 10);
+}
Index: include/clang/Basic/LangOptions.h
===
--- include/clang/Basic/LangOptions.h
+++ include/clang/Basic/LangOptions.h
@@ -254,6 +254,9 @@
   bool assumeFunctionsAreConvergent() const {
 return (CUDA && CUDAIsDevice) || OpenCL;
   }
+
+  /// \brief Return the OpenCL C or C++ version as a VersionTuple.
+  VersionTuple getOpenCLVersionTuple() const;
 };
 
 /// \brief Floating point control options


Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -29,7 +29,6 @@
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
-#include "llvm/Support/ScopedPrinter.h"
 
 using namespace clang;
 
@@ -3806,11 +3805,8 @@
 Diag(Tok, DiagID)
   << PrevSpec << FixItHint::CreateRemoval(Tok.getLocation());
   else if (DiagID == diag::err_opencl_unknown_type_specifier) {
-const int OpenCLVer = getLangOpts().OpenCLVersion;
-std::string VerSpec = llvm::to_string(OpenCLVer / 100) +
-  std::string (".") +
-  llvm::to_string((OpenCLVer % 100) / 10);
-Diag(Tok, DiagID) << VerSpec << PrevSpec << isStorageClass;
+Diag(Tok, DiagID) << getLangOpts().getOpenCLVersionTuple().getAsString()
+  << PrevSpec << isStorageClass;
   } else
 Diag(Tok, DiagID) << PrevSpec;
 }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -76,7 +76,6 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Regex.h"
-#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/Tar

[PATCH] D46382: [OpenCL] Factor out language version printing

2018-05-08 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331766: [OpenCL] Factor out language version printing 
(authored by svenvh, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46382?vs=144991&id=145684#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46382

Files:
  cfe/trunk/include/clang/Basic/LangOptions.h
  cfe/trunk/lib/Basic/LangOptions.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/lib/Parse/ParseDecl.cpp


Index: cfe/trunk/lib/Basic/LangOptions.cpp
===
--- cfe/trunk/lib/Basic/LangOptions.cpp
+++ cfe/trunk/lib/Basic/LangOptions.cpp
@@ -43,3 +43,8 @@
   return true;
   return false;
 }
+
+VersionTuple LangOptions::getOpenCLVersionTuple() const {
+  const int Ver = OpenCLCPlusPlus ? OpenCLCPlusPlusVersion : OpenCLVersion;
+  return VersionTuple(Ver / 100, (Ver % 100) / 10);
+}
Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -76,7 +76,6 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Regex.h"
-#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetOptions.h"
 #include 
@@ -2157,11 +2156,9 @@
   // this option was added for compatibility with OpenCL 1.0.
   if (Args.getLastArg(OPT_cl_strict_aliasing)
&& Opts.OpenCLVersion > 100) {
-std::string VerSpec = llvm::to_string(Opts.OpenCLVersion / 100) +
-  std::string(".") +
-  llvm::to_string((Opts.OpenCLVersion % 100) / 10);
 Diags.Report(diag::warn_option_invalid_ocl_version)
-  << VerSpec << Args.getLastArg(OPT_cl_strict_aliasing)->getAsString(Args);
+<< Opts.getOpenCLVersionTuple().getAsString()
+<< Args.getLastArg(OPT_cl_strict_aliasing)->getAsString(Args);
   }
 
   // We abuse '-f[no-]gnu-keywords' to force overriding all GNU-extension
Index: cfe/trunk/lib/Parse/ParseDecl.cpp
===
--- cfe/trunk/lib/Parse/ParseDecl.cpp
+++ cfe/trunk/lib/Parse/ParseDecl.cpp
@@ -29,7 +29,6 @@
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
-#include "llvm/Support/ScopedPrinter.h"
 
 using namespace clang;
 
@@ -3806,11 +3805,8 @@
 Diag(Tok, DiagID)
   << PrevSpec << FixItHint::CreateRemoval(Tok.getLocation());
   else if (DiagID == diag::err_opencl_unknown_type_specifier) {
-const int OpenCLVer = getLangOpts().OpenCLVersion;
-std::string VerSpec = llvm::to_string(OpenCLVer / 100) +
-  std::string (".") +
-  llvm::to_string((OpenCLVer % 100) / 10);
-Diag(Tok, DiagID) << VerSpec << PrevSpec << isStorageClass;
+Diag(Tok, DiagID) << 
getLangOpts().getOpenCLVersionTuple().getAsString()
+  << PrevSpec << isStorageClass;
   } else
 Diag(Tok, DiagID) << PrevSpec;
 }
Index: cfe/trunk/include/clang/Basic/LangOptions.h
===
--- cfe/trunk/include/clang/Basic/LangOptions.h
+++ cfe/trunk/include/clang/Basic/LangOptions.h
@@ -254,6 +254,9 @@
   bool assumeFunctionsAreConvergent() const {
 return (CUDA && CUDAIsDevice) || OpenCL;
   }
+
+  /// \brief Return the OpenCL C or C++ version as a VersionTuple.
+  VersionTuple getOpenCLVersionTuple() const;
 };
 
 /// \brief Floating point control options


Index: cfe/trunk/lib/Basic/LangOptions.cpp
===
--- cfe/trunk/lib/Basic/LangOptions.cpp
+++ cfe/trunk/lib/Basic/LangOptions.cpp
@@ -43,3 +43,8 @@
   return true;
   return false;
 }
+
+VersionTuple LangOptions::getOpenCLVersionTuple() const {
+  const int Ver = OpenCLCPlusPlus ? OpenCLCPlusPlusVersion : OpenCLVersion;
+  return VersionTuple(Ver / 100, (Ver % 100) / 10);
+}
Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -76,7 +76,6 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Regex.h"
-#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetOptions.h"
 #include 
@@ -2157,11 +2156,9 @@
   // this option was added for compatibility with OpenCL 1.0.
   if (Args.getLastArg(OPT_cl_strict_aliasing)
&& Opts.OpenCLVersion > 100) {
-std::string VerSpec = llvm::to_string(Opts.OpenCLVersion / 100) +
-  std::string(".") +
-  llvm::to_strin

[PATCH] D69072: [OpenCL] Added doc to describe OpenCL support

2019-10-17 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5e962e8d7dc7: [OpenCL] Add doc to describe OpenCL support 
(authored by svenvh).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D69072?vs=225391&id=225413#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69072/new/

https://reviews.llvm.org/D69072

Files:
  clang/docs/OpenCLSupport.rst
  clang/docs/index.rst


Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -41,6 +41,7 @@
SourceBasedCodeCoverage
Modules
MSVCCompatibility
+   OpenCLSupport
OpenMPSupport
ThinLTO
CommandGuide/index
Index: clang/docs/OpenCLSupport.rst
===
--- /dev/null
+++ clang/docs/OpenCLSupport.rst
@@ -0,0 +1,47 @@
+.. raw:: html
+
+  
+.none { background-color: #FF }
+.partial { background-color: #99 }
+.good { background-color: #CCFF99 }
+  
+
+.. role:: none
+.. role:: partial
+.. role:: good
+
+.. contents::
+   :local:
+
+==
+OpenCL Support
+==
+
+Clang fully supports all OpenCL C versions from 1.1 to 2.0.
+
+Please refer to `Bugzilla
+`_
+for the most up to date bug reports.
+
+
+C++ for OpenCL Implementation Status
+
+
+Bugzilla bugs for this functionality are typically prefixed
+with '[C++]'.
+
+Differences to OpenCL C
+---
+
+TODO!
+
+Missing features or with limited support
+
+
+- Use of ObjC blocks is disabled.
+
+- Global destructor invocation is not generated correctly.
+
+- Initialization of objects in `__constant` address spaces is not guaranteed 
to work.
+
+- `addrspace_cast` operator is not supported.


Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -41,6 +41,7 @@
SourceBasedCodeCoverage
Modules
MSVCCompatibility
+   OpenCLSupport
OpenMPSupport
ThinLTO
CommandGuide/index
Index: clang/docs/OpenCLSupport.rst
===
--- /dev/null
+++ clang/docs/OpenCLSupport.rst
@@ -0,0 +1,47 @@
+.. raw:: html
+
+  
+.none { background-color: #FF }
+.partial { background-color: #99 }
+.good { background-color: #CCFF99 }
+  
+
+.. role:: none
+.. role:: partial
+.. role:: good
+
+.. contents::
+   :local:
+
+==
+OpenCL Support
+==
+
+Clang fully supports all OpenCL C versions from 1.1 to 2.0.
+
+Please refer to `Bugzilla
+`_
+for the most up to date bug reports.
+
+
+C++ for OpenCL Implementation Status
+
+
+Bugzilla bugs for this functionality are typically prefixed
+with '[C++]'.
+
+Differences to OpenCL C
+---
+
+TODO!
+
+Missing features or with limited support
+
+
+- Use of ObjC blocks is disabled.
+
+- Global destructor invocation is not generated correctly.
+
+- Initialization of objects in `__constant` address spaces is not guaranteed to work.
+
+- `addrspace_cast` operator is not supported.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D68403: [OpenCL] PR43145: preserve addrspace for class accesses

2019-10-17 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaf6248cbb9e7: [OpenCL] Preserve addrspace in CGClass 
(PR43145) (authored by svenvh).

Changed prior to commit:
  https://reviews.llvm.org/D68403?vs=223037&id=225426#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68403/new/

https://reviews.llvm.org/D68403

Files:
  clang/lib/CodeGen/CGClass.cpp
  clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl


Index: clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
===
--- clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
+++ clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
@@ -11,6 +11,7 @@
 
 void foo() {
   D d;
+  //CHECK-LABEL: foo
   //CHECK: addrspacecast %class.D* %d to %class.D addrspace(4)*
   //CHECK: call spir_func i32 @_ZNU3AS41D5getmbEv(%class.D addrspace(4)*
   d.getmb();
@@ -20,3 +21,32 @@
 
 //CHECK: define linkonce_odr spir_func i32 @_ZNU3AS41D5getmbEv(%class.D 
addrspace(4)* %this)
 //CHECK: bitcast %class.D addrspace(4)* %this1 to %struct.B addrspace(4)*
+
+
+// Calling base method through multiple inheritance.
+
+class B2 {
+  public:
+void baseMethod() const {  }
+int bb;
+};
+
+class Derived : public B, public B2 {
+  public:
+void work() const { baseMethod(); }
+// CHECK-LABEL: work
+// CHECK: bitcast i8 addrspace(4)* %add.ptr to %class.B2 addrspace(4)*
+};
+
+void pr43145(const Derived *argDerived) {
+  argDerived->work();
+}
+
+// Casting from base to derived.
+
+void pr43145_2(B *argB) {
+  Derived *x = (Derived*)argB;
+}
+
+// CHECK-LABEL: @_Z9pr43145_2
+// CHECK: bitcast %struct.B addrspace(4)* %0 to %class.Derived addrspace(4)*
Index: clang/lib/CodeGen/CGClass.cpp
===
--- clang/lib/CodeGen/CGClass.cpp
+++ clang/lib/CodeGen/CGClass.cpp
@@ -246,7 +246,8 @@
 
   // Apply the base offset.
   llvm::Value *ptr = addr.getPointer();
-  ptr = CGF.Builder.CreateBitCast(ptr, CGF.Int8PtrTy);
+  unsigned AddrSpace = ptr->getType()->getPointerAddressSpace();
+  ptr = CGF.Builder.CreateBitCast(ptr, CGF.Int8Ty->getPointerTo(AddrSpace));
   ptr = CGF.Builder.CreateInBoundsGEP(ptr, baseOffset, "add.ptr");
 
   // If we have a virtual component, the alignment of the result will
@@ -381,7 +382,9 @@
 
   QualType DerivedTy =
 getContext().getCanonicalType(getContext().getTagDeclType(Derived));
-  llvm::Type *DerivedPtrTy = ConvertType(DerivedTy)->getPointerTo();
+  unsigned AddrSpace =
+BaseAddr.getPointer()->getType()->getPointerAddressSpace();
+  llvm::Type *DerivedPtrTy = ConvertType(DerivedTy)->getPointerTo(AddrSpace);
 
   llvm::Value *NonVirtualOffset =
 CGM.GetNonVirtualBaseClassOffset(Derived, PathBegin, PathEnd);


Index: clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
===
--- clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
+++ clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
@@ -11,6 +11,7 @@
 
 void foo() {
   D d;
+  //CHECK-LABEL: foo
   //CHECK: addrspacecast %class.D* %d to %class.D addrspace(4)*
   //CHECK: call spir_func i32 @_ZNU3AS41D5getmbEv(%class.D addrspace(4)*
   d.getmb();
@@ -20,3 +21,32 @@
 
 //CHECK: define linkonce_odr spir_func i32 @_ZNU3AS41D5getmbEv(%class.D addrspace(4)* %this)
 //CHECK: bitcast %class.D addrspace(4)* %this1 to %struct.B addrspace(4)*
+
+
+// Calling base method through multiple inheritance.
+
+class B2 {
+  public:
+void baseMethod() const {  }
+int bb;
+};
+
+class Derived : public B, public B2 {
+  public:
+void work() const { baseMethod(); }
+// CHECK-LABEL: work
+// CHECK: bitcast i8 addrspace(4)* %add.ptr to %class.B2 addrspace(4)*
+};
+
+void pr43145(const Derived *argDerived) {
+  argDerived->work();
+}
+
+// Casting from base to derived.
+
+void pr43145_2(B *argB) {
+  Derived *x = (Derived*)argB;
+}
+
+// CHECK-LABEL: @_Z9pr43145_2
+// CHECK: bitcast %struct.B addrspace(4)* %0 to %class.Derived addrspace(4)*
Index: clang/lib/CodeGen/CGClass.cpp
===
--- clang/lib/CodeGen/CGClass.cpp
+++ clang/lib/CodeGen/CGClass.cpp
@@ -246,7 +246,8 @@
 
   // Apply the base offset.
   llvm::Value *ptr = addr.getPointer();
-  ptr = CGF.Builder.CreateBitCast(ptr, CGF.Int8PtrTy);
+  unsigned AddrSpace = ptr->getType()->getPointerAddressSpace();
+  ptr = CGF.Builder.CreateBitCast(ptr, CGF.Int8Ty->getPointerTo(AddrSpace));
   ptr = CGF.Builder.CreateInBoundsGEP(ptr, baseOffset, "add.ptr");
 
   // If we have a virtual component, the alignment of the result will
@@ -381,7 +382,9 @@
 
   QualType DerivedTy =
 getContext().getCanonicalType(getContext().getTagDeclType(Derived));
-  llvm::Type *DerivedPtrTy = ConvertType(DerivedTy)->getPointerTo();
+  unsigned AddrSpace =
+BaseAddr.getPointer()->getType()->getPointerAddressSpace();
+  llvm::

[PATCH] D69233: [OpenCL] Support -fdeclare-opencl-builtins in C++ mode

2019-10-20 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: Anastasia.
Herald added subscribers: cfe-commits, kristina, yaxunl.
Herald added a project: clang.

Support for C++ mode was accidentally lacking due to not checking the
OpenCLCPlusPlus LangOpts version.


Repository:
  rC Clang

https://reviews.llvm.org/D69233

Files:
  clang/lib/Sema/SemaLookup.cpp
  clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl


Index: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
===
--- clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -4,8 +4,10 @@
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -DNO_HEADER
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CLC++ -fdeclare-opencl-builtins -DNO_HEADER
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CLC++ -fdeclare-opencl-builtins -finclude-default-header
 
-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#if defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 // expected-no-diagnostics
 #endif
 
@@ -97,7 +99,7 @@
 
 kernel void basic_subgroup(global uint *out) {
   out[0] = get_sub_group_size();
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if !defined(__OPENCL_CPP_VERSION__) && __OPENCL_C_VERSION__ < CL_VERSION_2_0
 // expected-error@-2{{implicit declaration of function 'get_sub_group_size' is 
invalid in OpenCL}}
 // expected-error@-3{{implicit conversion changes signedness: 'int' to 'uint' 
(aka 'unsigned int')}}
 #endif
@@ -130,7 +132,7 @@
   uint ui;
 
   get_enqueued_local_size(ui);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if !defined(__OPENCL_CPP_VERSION__) && __OPENCL_C_VERSION__ < CL_VERSION_2_0
 // expected-error@-2{{implicit declaration of function 
'get_enqueued_local_size' is invalid in OpenCL}}
 #endif
 }
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -765,10 +765,13 @@
 ASTContext &Context = S.Context;
 
 // Ignore this BIF if its version does not match the language options.
-if (Context.getLangOpts().OpenCLVersion < OpenCLBuiltin.MinVersion)
+unsigned OpenCLVersion = Context.getLangOpts().OpenCLVersion;
+if (Context.getLangOpts().OpenCLCPlusPlus)
+  OpenCLVersion = 200;
+if (OpenCLVersion < OpenCLBuiltin.MinVersion)
   continue;
 if ((OpenCLBuiltin.MaxVersion != 0) &&
-(Context.getLangOpts().OpenCLVersion >= OpenCLBuiltin.MaxVersion))
+(OpenCLVersion >= OpenCLBuiltin.MaxVersion))
   continue;
 
 SmallVector RetTypes;


Index: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
===
--- clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -4,8 +4,10 @@
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -DNO_HEADER
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CLC++ -fdeclare-opencl-builtins -DNO_HEADER
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CLC++ -fdeclare-opencl-builtins -finclude-default-header
 
-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#if defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 // expected-no-diagnostics
 #endif
 
@@ -97,7 +99,7 @@
 
 kernel void basic_subgroup(global uint *out) {
   out[0] = get_sub_group_size();
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if !defined(__OPENCL_CPP_VERSION__) && __OPENCL_C_VERSION__ < CL_VERSION_2_0
 // expected-error@-2{{implicit declaration of function 'get_sub_group_size' is invalid in OpenCL}}
 // expected-error@-3{{implicit conversion changes signedness: 'int' to 'uint' (aka 'unsigned int')}}
 #endif
@@ -130,7 +132,7 @@
   uint ui;
 
   get_enqueued_local_size(ui);
-#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+#if !defined(__OPENCL_CPP_VERSION__) && __OPENCL_C_VERSION__ < CL_VERSION_2_0
 // expected-error@-2{{implicit declaration of function 'get_enqueued_local_size' is inva

[PATCH] D83325: [Sema] Be more thorough when unpacking the AS-qualified pointee for a pointer conversion.

2020-07-23 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

Wondering if stripping the sugar is the right thing to do here, because it 
means we don't have any sugar on the resulting type if it has gone through the 
SCS and pointer type reconstruction?

> I'm unsure if this is currently broken upstream without other patches to 
> exploit the behavior,

I'm not sure either; perhaps @rjmccall has some insights.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83325/new/

https://reviews.llvm.org/D83325



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


  1   2   3   4   5   >