From aa8b893ccd9ab06145a7d41168ef65316e93b50f Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Fri, 8 Apr 2016 13:40:33 +0000 Subject: [PATCH] [OpenCL] Complete image types support. I. Current implementation of images is not conformant to spec in the following points: 1. It makes no distinction with respect to access qualifiers and therefore allows to use images with different access type interchangeably. The following code would compile just fine: void write_image(write_only image2d_t img); kernel void foo(read_only image2d_t img) { write_image(img); } // Accepted code which is disallowed according to s6.13.14. 2. It discards access qualifier on generated code, which leads to generated code for the above example: call void @write_image(%opencl.image2d_t* %img); In OpenCL2.0 however we can have different calls into write_image with read_only and wite_only images. Also generally following compiler steps have no easy way to take different path depending on the image access: linking to the right implementation of image types, performing IR opts and backend codegen differently. 3. Image types are language keywords and can't be redeclared s6.1.9, which can happen currently as they are just typedef names. 4. Default access qualifier read_only is to be added if not provided explicitly. II. This patch corrects the above points as follows: 1. All images are encapsulated into a separate .def file that is inserted in different points where image handling is required. This avoid a lot of code repetition as all images are handled the same way in the code with no distinction of their exact type. 2. The Cartesian product of image types and image access qualifiers is added to the builtin types. This simplifies a lot handling of access type mismatch as no operations are allowed by default on distinct Builtin types. Also spec intended access qualifier as special type qualifier that are combined with an image type to form a distinct type (see statement above - images can't be created w/o access qualifiers). 3. Improves testing of images in Clang. Author: Anastasia Stulova Reviewers: bader, mgrang. Subscribers: pxli168, pekka.jaaskelainen, yaxunl. Differential Revision: http://reviews.llvm.org/D17821 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@265783 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ASTContext.h | 8 +- include/clang/AST/BuiltinTypes.def | 14 ---- include/clang/AST/OpenCLImageTypes.def | 82 ++++++++++++++++++++ include/clang/AST/Type.h | 80 ++++--------------- include/clang/Basic/Specifiers.h | 6 +- include/clang/Basic/TokenKinds.def | 2 + include/clang/Sema/DeclSpec.h | 3 + include/clang/Serialization/ASTBitCodes.h | 42 +++------- lib/AST/ASTContext.cpp | 49 +++--------- lib/AST/ASTImporter.cpp | 4 + lib/AST/ExprConstant.cpp | 15 +--- lib/AST/ItaniumMangle.cpp | 41 ++-------- lib/AST/MicrosoftMangle.cpp | 51 +----------- lib/AST/NSAPI.cpp | 15 +--- lib/AST/Type.cpp | 43 ++-------- lib/AST/TypeLoc.cpp | 15 +--- lib/Analysis/PrintfFormatString.cpp | 3 + lib/CodeGen/CGDebugInfo.cpp | 38 ++------- lib/CodeGen/CGDebugInfo.h | 15 +--- lib/CodeGen/CGOpenCLRuntime.cpp | 44 ++--------- lib/CodeGen/CodeGenTypes.cpp | 15 +--- lib/CodeGen/ItaniumCXXABI.cpp | 15 +--- lib/Index/USRGeneration.cpp | 15 +--- lib/Parse/ParseDecl.cpp | 12 +++ lib/Parse/ParseExpr.cpp | 5 +- lib/Parse/ParseTentative.cpp | 2 + lib/Sema/DeclSpec.cpp | 6 ++ lib/Sema/Sema.cpp | 14 ---- lib/Sema/SemaExpr.cpp | 7 +- lib/Sema/SemaTemplateVariadic.cpp | 2 + lib/Sema/SemaType.cpp | 46 +++++++++-- lib/Serialization/ASTCommon.cpp | 39 +--------- lib/Serialization/ASTReader.cpp | 39 +--------- test/CodeGenOpenCL/images.cl | 11 +++ test/CodeGenOpenCL/opencl_types.cl | 28 +++---- test/SemaOpenCL/images.cl | 9 +++ test/SemaOpenCL/invalid-access-qualifier.cl | 2 +- test/SemaOpenCL/invalid-image.cl | 6 +- test/SemaOpenCL/invalid-kernel-parameters.cl | 2 +- tools/libclang/CIndex.cpp | 15 +--- 40 files changed, 310 insertions(+), 550 deletions(-) create mode 100644 include/clang/AST/OpenCLImageTypes.def create mode 100644 test/CodeGenOpenCL/images.cl create mode 100644 test/SemaOpenCL/images.cl diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 55511e03a3..9f880e22ac 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -902,11 +902,9 @@ public: CanQualType PseudoObjectTy, ARCUnbridgedCastTy; CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy; CanQualType ObjCBuiltinBoolTy; - CanQualType OCLImage1dTy, OCLImage1dArrayTy, OCLImage1dBufferTy; - CanQualType OCLImage2dTy, OCLImage2dArrayTy, OCLImage2dDepthTy; - CanQualType OCLImage2dArrayDepthTy, OCLImage2dMSAATy, OCLImage2dArrayMSAATy; - CanQualType OCLImage2dMSAADepthTy, OCLImage2dArrayMSAADepthTy; - CanQualType OCLImage3dTy; +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + CanQualType SingletonId; +#include "clang/AST/OpenCLImageTypes.def" CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy; CanQualType OCLQueueTy, OCLNDRangeTy, OCLReserveIDTy; CanQualType OMPArraySectionTy; diff --git a/include/clang/AST/BuiltinTypes.def b/include/clang/AST/BuiltinTypes.def index a08a683902..dcca44df17 100644 --- a/include/clang/AST/BuiltinTypes.def +++ b/include/clang/AST/BuiltinTypes.def @@ -154,20 +154,6 @@ BUILTIN_TYPE(ObjCClass, ObjCBuiltinClassTy) // type is a typedef of a PointerType to this. BUILTIN_TYPE(ObjCSel, ObjCBuiltinSelTy) -// OpenCL image types. -BUILTIN_TYPE(OCLImage1d, OCLImage1dTy) -BUILTIN_TYPE(OCLImage1dArray, OCLImage1dArrayTy) -BUILTIN_TYPE(OCLImage1dBuffer, OCLImage1dBufferTy) -BUILTIN_TYPE(OCLImage2d, OCLImage2dTy) -BUILTIN_TYPE(OCLImage2dArray, OCLImage2dArrayTy) -BUILTIN_TYPE(OCLImage2dDepth, OCLImage2dDepthTy) -BUILTIN_TYPE(OCLImage2dArrayDepth, OCLImage2dArrayDepthTy) -BUILTIN_TYPE(OCLImage2dMSAA, OCLImage2dMSAATy) -BUILTIN_TYPE(OCLImage2dArrayMSAA, OCLImage2dArrayMSAATy) -BUILTIN_TYPE(OCLImage2dMSAADepth, OCLImage2dMSAADepthTy) -BUILTIN_TYPE(OCLImage2dArrayMSAADepth, OCLImage2dArrayMSAADepthTy) -BUILTIN_TYPE(OCLImage3d, OCLImage3dTy) - // OpenCL sampler_t. BUILTIN_TYPE(OCLSampler, OCLSamplerTy) diff --git a/include/clang/AST/OpenCLImageTypes.def b/include/clang/AST/OpenCLImageTypes.def new file mode 100644 index 0000000000..9b929929e2 --- /dev/null +++ b/include/clang/AST/OpenCLImageTypes.def @@ -0,0 +1,82 @@ +//===-- OpenCLImageTypes.def - Metadata about BuiltinTypes ------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// This file extends builtin types database with OpenCL image singleton types. +// Custom code should define one of those two macros: +// GENERIC_IMAGE_TYPE(Type, Id) - a generic image with its Id without an +// access type +// IMAGE_TYPE(Type, Id, SingletonId, AccessType, CGSuffix) - an image type +// with given ID, singleton ID access type and a codegen suffix + +#ifdef GENERIC_IMAGE_TYPE + +#define IMAGE_READ_TYPE(Type, Id) GENERIC_IMAGE_TYPE(Type, Id) +#define IMAGE_WRITE_TYPE(Type, Id) +#define IMAGE_READ_WRITE_TYPE(Type, Id) + +#else + +#ifndef IMAGE_READ_TYPE +#define IMAGE_READ_TYPE(Type, Id) \ + IMAGE_TYPE(Type, Id##RO, Id##ROTy, read_only, ro) +#endif +#ifndef IMAGE_WRITE_TYPE +#define IMAGE_WRITE_TYPE(Type, Id) \ + IMAGE_TYPE(Type, Id##WO, Id##WOTy, write_only, wo) +#endif +#ifndef IMAGE_READ_WRITE_TYPE +#define IMAGE_READ_WRITE_TYPE(Type, Id) \ + IMAGE_TYPE(Type, Id##RW, Id##RWTy, read_write, rw) +#endif + +#endif + +IMAGE_READ_TYPE(image1d, OCLImage1d) +IMAGE_READ_TYPE(image1d_array, OCLImage1dArray) +IMAGE_READ_TYPE(image1d_buffer, OCLImage1dBuffer) +IMAGE_READ_TYPE(image2d, OCLImage2d) +IMAGE_READ_TYPE(image2d_array, OCLImage2dArray) +IMAGE_READ_TYPE(image2d_depth, OCLImage2dDepth) +IMAGE_READ_TYPE(image2d_array_depth, OCLImage2dArrayDepth) +IMAGE_READ_TYPE(image2d_msaa, OCLImage2dMSAA) +IMAGE_READ_TYPE(image2d_array_msaa, OCLImage2dArrayMSAA) +IMAGE_READ_TYPE(image2d_msaa_depth, OCLImage2dMSAADepth) +IMAGE_READ_TYPE(image2d_array_msaa_depth, OCLImage2dArrayMSAADepth) +IMAGE_READ_TYPE(image3d, OCLImage3d) + +IMAGE_WRITE_TYPE(image1d, OCLImage1d) +IMAGE_WRITE_TYPE(image1d_array, OCLImage1dArray) +IMAGE_WRITE_TYPE(image1d_buffer, OCLImage1dBuffer) +IMAGE_WRITE_TYPE(image2d, OCLImage2d) +IMAGE_WRITE_TYPE(image2d_array, OCLImage2dArray) +IMAGE_WRITE_TYPE(image2d_depth, OCLImage2dDepth) +IMAGE_WRITE_TYPE(image2d_array_depth, OCLImage2dArrayDepth) +IMAGE_WRITE_TYPE(image2d_msaa, OCLImage2dMSAA) +IMAGE_WRITE_TYPE(image2d_array_msaa, OCLImage2dArrayMSAA) +IMAGE_WRITE_TYPE(image2d_msaa_depth, OCLImage2dMSAADepth) +IMAGE_WRITE_TYPE(image2d_array_msaa_depth, OCLImage2dArrayMSAADepth) +IMAGE_WRITE_TYPE(image3d, OCLImage3d) + +IMAGE_READ_WRITE_TYPE(image1d, OCLImage1d) +IMAGE_READ_WRITE_TYPE(image1d_array, OCLImage1dArray) +IMAGE_READ_WRITE_TYPE(image1d_buffer, OCLImage1dBuffer) +IMAGE_READ_WRITE_TYPE(image2d, OCLImage2d) +IMAGE_READ_WRITE_TYPE(image2d_array, OCLImage2dArray) +IMAGE_READ_WRITE_TYPE(image2d_depth, OCLImage2dDepth) +IMAGE_READ_WRITE_TYPE(image2d_array_depth, OCLImage2dArrayDepth) +IMAGE_READ_WRITE_TYPE(image2d_msaa, OCLImage2dMSAA) +IMAGE_READ_WRITE_TYPE(image2d_array_msaa, OCLImage2dArrayMSAA) +IMAGE_READ_WRITE_TYPE(image2d_msaa_depth, OCLImage2dMSAADepth) +IMAGE_READ_WRITE_TYPE(image2d_array_msaa_depth, OCLImage2dArrayMSAADepth) +IMAGE_READ_WRITE_TYPE(image3d, OCLImage3d) + +#undef IMAGE_TYPE +#undef GENERIC_IMAGE_TYPE +#undef IMAGE_READ_TYPE +#undef IMAGE_WRITE_TYPE +#undef IMAGE_READ_WRITE_TYPE \ No newline at end of file diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index e8f54fd4bd..ea5491fb9d 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -1705,18 +1705,9 @@ public: bool isNullPtrType() const; // C++0x nullptr_t bool isAtomicType() const; // C11 _Atomic() - bool isImage1dT() const; // OpenCL image1d_t - bool isImage1dArrayT() const; // OpenCL image1d_array_t - bool isImage1dBufferT() const; // OpenCL image1d_buffer_t - bool isImage2dT() const; // OpenCL image2d_t - bool isImage2dArrayT() const; // OpenCL image2d_array_t - bool isImage2dDepthT() const; // OpenCL image_2d_depth_t - bool isImage2dArrayDepthT() const; // OpenCL image_2d_array_depth_t - bool isImage2dMSAAT() const; // OpenCL image_2d_msaa_t - bool isImage2dArrayMSAAT() const; // OpenCL image_2d_array_msaa_t - bool isImage2dMSAATDepth() const; // OpenCL image_2d_msaa_depth_t - bool isImage2dArrayMSAATDepth() const; // OpenCL image_2d_array_msaa_depth_t - bool isImage3dT() const; // OpenCL image3d_t +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + bool is##Id##Type() const; +#include "clang/AST/OpenCLImageTypes.def" bool isImageType() const; // Any OpenCL image type @@ -2017,6 +2008,10 @@ template <> inline const Class##Type *Type::castAs() const { \ class BuiltinType : public Type { public: enum Kind { +// OpenCL image types +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) Id, +#include "clang/AST/OpenCLImageTypes.def" +// All other builtin types #define BUILTIN_TYPE(Id, SingletonId) Id, #define LAST_BUILTIN_TYPE(Id) LastKind = Id #include "clang/AST/BuiltinTypes.def" @@ -5557,53 +5552,11 @@ inline bool Type::isObjCBuiltinType() const { return isObjCIdType() || isObjCClassType() || isObjCSelType(); } -inline bool Type::isImage1dT() const { - return isSpecificBuiltinType(BuiltinType::OCLImage1d); -} - -inline bool Type::isImage1dArrayT() const { - return isSpecificBuiltinType(BuiltinType::OCLImage1dArray); -} - -inline bool Type::isImage1dBufferT() const { - return isSpecificBuiltinType(BuiltinType::OCLImage1dBuffer); -} - -inline bool Type::isImage2dT() const { - return isSpecificBuiltinType(BuiltinType::OCLImage2d); -} - -inline bool Type::isImage2dArrayT() const { - return isSpecificBuiltinType(BuiltinType::OCLImage2dArray); -} - -inline bool Type::isImage2dDepthT() const { - return isSpecificBuiltinType(BuiltinType::OCLImage2dDepth); -} - -inline bool Type::isImage2dArrayDepthT() const { - return isSpecificBuiltinType(BuiltinType::OCLImage2dArrayDepth); -} - -inline bool Type::isImage2dMSAAT() const { - return isSpecificBuiltinType(BuiltinType::OCLImage2dMSAA); -} - -inline bool Type::isImage2dArrayMSAAT() const { - return isSpecificBuiltinType(BuiltinType::OCLImage2dArrayMSAA); -} - -inline bool Type::isImage2dMSAATDepth() const { - return isSpecificBuiltinType(BuiltinType::OCLImage2dMSAADepth); -} - -inline bool Type::isImage2dArrayMSAATDepth() const { - return isSpecificBuiltinType(BuiltinType::OCLImage2dArrayMSAADepth); -} - -inline bool Type::isImage3dT() const { - return isSpecificBuiltinType(BuiltinType::OCLImage3d); -} +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + inline bool Type::is##Id##Type() const { \ + return isSpecificBuiltinType(BuiltinType::Id); \ + } +#include "clang/AST/OpenCLImageTypes.def" inline bool Type::isSamplerT() const { return isSpecificBuiltinType(BuiltinType::OCLSampler); @@ -5630,11 +5583,10 @@ inline bool Type::isReserveIDT() const { } inline bool Type::isImageType() const { - return isImage3dT() || isImage2dT() || isImage2dArrayT() || - isImage2dDepthT() || isImage2dArrayDepthT() || isImage2dMSAAT() || - isImage2dArrayMSAAT() || isImage2dMSAATDepth() || - isImage2dArrayMSAATDepth() || isImage1dT() || isImage1dArrayT() || - isImage1dBufferT(); +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) is##Id##Type() || + return +#include "clang/AST/OpenCLImageTypes.def" + 0; // end boolean or operation } inline bool Type::isPipeType() const { diff --git a/include/clang/Basic/Specifiers.h b/include/clang/Basic/Specifiers.h index 8857e0df56..6fb0105592 100644 --- a/include/clang/Basic/Specifiers.h +++ b/include/clang/Basic/Specifiers.h @@ -73,9 +73,11 @@ namespace clang { TST_auto_type, // __auto_type extension TST_unknown_anytype, // __unknown_anytype extension TST_atomic, // C11 _Atomic - TST_error // erroneous type +#define GENERIC_IMAGE_TYPE(ImgType, Id) TST_##ImgType##_t, // OpenCL image types +#include "clang/AST/OpenCLImageTypes.def" + TST_error // erroneous type }; - + /// \brief Structure that packs information about the type specifiers that /// were written in a particular type specifier sequence. struct WrittenBuiltinSpecs { diff --git a/include/clang/Basic/TokenKinds.def b/include/clang/Basic/TokenKinds.def index 1a0b141a61..83e8faf8b4 100644 --- a/include/clang/Basic/TokenKinds.def +++ b/include/clang/Basic/TokenKinds.def @@ -518,6 +518,8 @@ ALIAS("read_write", __read_write , KEYOPENCL) // OpenCL builtins KEYWORD(__builtin_astype , KEYOPENCL) KEYWORD(vec_step , KEYOPENCL|KEYALTIVEC|KEYZVECTOR) +#define GENERIC_IMAGE_TYPE(ImgType, Id) KEYWORD(ImgType##_t, KEYOPENCL) +#include "clang/AST/OpenCLImageTypes.def" // OpenMP Type Traits KEYWORD(__builtin_omp_required_simd_align, KEYALL) diff --git a/include/clang/Sema/DeclSpec.h b/include/clang/Sema/DeclSpec.h index 43dc97b20f..eba0ead1cf 100644 --- a/include/clang/Sema/DeclSpec.h +++ b/include/clang/Sema/DeclSpec.h @@ -299,6 +299,9 @@ public: static const TST TST_auto_type = clang::TST_auto_type; static const TST TST_unknown_anytype = clang::TST_unknown_anytype; static const TST TST_atomic = clang::TST_atomic; +#define GENERIC_IMAGE_TYPE(ImgType, Id) \ + static const TST TST_##ImgType##_t = clang::TST_##ImgType##_t; +#include "clang/AST/OpenCLImageTypes.def" static const TST TST_error = clang::TST_error; // type-qualifiers diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h index 4cfedbe3e4..ce6b53f735 100644 --- a/include/clang/Serialization/ASTBitCodes.h +++ b/include/clang/Serialization/ASTBitCodes.h @@ -784,44 +784,24 @@ namespace clang { PREDEF_TYPE_PSEUDO_OBJECT = 35, /// \brief The placeholder type for builtin functions. PREDEF_TYPE_BUILTIN_FN = 36, - /// \brief OpenCL 1d image type. - PREDEF_TYPE_IMAGE1D_ID = 37, - /// \brief OpenCL 1d image array type. - PREDEF_TYPE_IMAGE1D_ARR_ID = 38, - /// \brief OpenCL 1d image buffer type. - PREDEF_TYPE_IMAGE1D_BUFF_ID = 39, - /// \brief OpenCL 2d image type. - PREDEF_TYPE_IMAGE2D_ID = 40, - /// \brief OpenCL 2d image array type. - PREDEF_TYPE_IMAGE2D_ARR_ID = 41, - /// \brief OpenCL 2d image depth type. - PREDEF_TYPE_IMAGE2D_DEP_ID = 42, - /// \brief OpenCL 2d image array depth type. - PREDEF_TYPE_IMAGE2D_ARR_DEP_ID = 43, - /// \brief OpenCL 2d image MSAA type. - PREDEF_TYPE_IMAGE2D_MSAA_ID = 44, - /// \brief OpenCL 2d image array MSAA type. - PREDEF_TYPE_IMAGE2D_ARR_MSAA_ID = 45, - /// \brief OpenCL 2d image MSAA depth type. - PREDEF_TYPE_IMAGE2D_MSAA_DEP_ID = 46, - /// \brief OpenCL 2d image array MSAA depth type. - PREDEF_TYPE_IMAGE2D_ARR_MSAA_DEPTH_ID = 47, - /// \brief OpenCL 3d image type. - PREDEF_TYPE_IMAGE3D_ID = 48, /// \brief OpenCL event type. - PREDEF_TYPE_EVENT_ID = 49, + PREDEF_TYPE_EVENT_ID = 37, /// \brief OpenCL clk event type. - PREDEF_TYPE_CLK_EVENT_ID = 50, + PREDEF_TYPE_CLK_EVENT_ID = 38, /// \brief OpenCL sampler type. - PREDEF_TYPE_SAMPLER_ID = 51, + PREDEF_TYPE_SAMPLER_ID = 39, /// \brief OpenCL queue type. - PREDEF_TYPE_QUEUE_ID = 52, + PREDEF_TYPE_QUEUE_ID = 40, /// \brief OpenCL ndrange type. - PREDEF_TYPE_NDRANGE_ID = 53, + PREDEF_TYPE_NDRANGE_ID = 41, /// \brief OpenCL reserve_id type. - PREDEF_TYPE_RESERVE_ID_ID = 54, + PREDEF_TYPE_RESERVE_ID_ID = 42, /// \brief The placeholder type for OpenMP array section. - PREDEF_TYPE_OMP_ARRAY_SECTION = 55 + PREDEF_TYPE_OMP_ARRAY_SECTION = 43, + /// \brief OpenCL image types with auto numeration +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + PREDEF_TYPE_##Id##_ID, +#include "clang/AST/OpenCLImageTypes.def" }; /// \brief The number of predefined type IDs that are reserved for diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 3a55e2310c..c295f599a3 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -1090,20 +1090,10 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target, InitBuiltinType(ObjCBuiltinClassTy, BuiltinType::ObjCClass); InitBuiltinType(ObjCBuiltinSelTy, BuiltinType::ObjCSel); - if (LangOpts.OpenCL) { - InitBuiltinType(OCLImage1dTy, BuiltinType::OCLImage1d); - InitBuiltinType(OCLImage1dArrayTy, BuiltinType::OCLImage1dArray); - InitBuiltinType(OCLImage1dBufferTy, BuiltinType::OCLImage1dBuffer); - InitBuiltinType(OCLImage2dTy, BuiltinType::OCLImage2d); - InitBuiltinType(OCLImage2dArrayTy, BuiltinType::OCLImage2dArray); - InitBuiltinType(OCLImage2dDepthTy, BuiltinType::OCLImage2dDepth); - InitBuiltinType(OCLImage2dArrayDepthTy, BuiltinType::OCLImage2dArrayDepth); - InitBuiltinType(OCLImage2dMSAATy, BuiltinType::OCLImage2dMSAA); - InitBuiltinType(OCLImage2dArrayMSAATy, BuiltinType::OCLImage2dArrayMSAA); - InitBuiltinType(OCLImage2dMSAADepthTy, BuiltinType::OCLImage2dMSAADepth); - InitBuiltinType(OCLImage2dArrayMSAADepthTy, - BuiltinType::OCLImage2dArrayMSAADepth); - InitBuiltinType(OCLImage3dTy, BuiltinType::OCLImage3d); + if (LangOpts.OpenCL) { +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + InitBuiltinType(SingletonId, BuiltinType::Id); +#include "clang/AST/OpenCLImageTypes.def" InitBuiltinType(OCLSamplerTy, BuiltinType::OCLSampler); InitBuiltinType(OCLEventTy, BuiltinType::OCLEvent); @@ -1681,18 +1671,10 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { case BuiltinType::OCLQueue: case BuiltinType::OCLNDRange: case BuiltinType::OCLReserveID: - case BuiltinType::OCLImage1d: - case BuiltinType::OCLImage1dArray: - case BuiltinType::OCLImage1dBuffer: - case BuiltinType::OCLImage2d: - case BuiltinType::OCLImage2dArray: - case BuiltinType::OCLImage2dDepth: - case BuiltinType::OCLImage2dArrayDepth: - case BuiltinType::OCLImage2dMSAA: - case BuiltinType::OCLImage2dArrayMSAA: - case BuiltinType::OCLImage2dMSAADepth: - case BuiltinType::OCLImage2dArrayMSAADepth: - case BuiltinType::OCLImage3d: +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: +#include "clang/AST/OpenCLImageTypes.def" + // Currently these types are pointers to opaque types. Width = Target->getPointerWidth(0); Align = Target->getPointerAlign(0); @@ -5517,18 +5499,9 @@ static char getObjCEncodingForPrimitiveKind(const ASTContext *C, llvm_unreachable("@encoding ObjC primitive type"); // OpenCL and placeholder types don't need @encodings. - case BuiltinType::OCLImage1d: - case BuiltinType::OCLImage1dArray: - case BuiltinType::OCLImage1dBuffer: - case BuiltinType::OCLImage2d: - case BuiltinType::OCLImage2dArray: - case BuiltinType::OCLImage2dDepth: - case BuiltinType::OCLImage2dArrayDepth: - case BuiltinType::OCLImage2dMSAA: - case BuiltinType::OCLImage2dArrayMSAA: - case BuiltinType::OCLImage2dMSAADepth: - case BuiltinType::OCLImage2dArrayMSAADepth: - case BuiltinType::OCLImage3d: +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: +#include "clang/AST/OpenCLImageTypes.def" case BuiltinType::OCLEvent: case BuiltinType::OCLClkEvent: case BuiltinType::OCLQueue: diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index 5748ea9edc..d2b2c93ecb 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -1509,6 +1509,10 @@ QualType ASTNodeImporter::VisitType(const Type *T) { QualType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { switch (T->getKind()) { +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: \ + return Importer.getToContext().SingletonId; +#include "clang/AST/OpenCLImageTypes.def" #define SHARED_SINGLETON_TYPE(Expansion) #define BUILTIN_TYPE(Id, SingletonId) \ case BuiltinType::Id: return Importer.getToContext().SingletonId; diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 72497d3b6b..152f46a071 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -6301,18 +6301,9 @@ static int EvaluateBuiltinClassifyType(const CallExpr *E, case BuiltinType::ObjCId: case BuiltinType::ObjCClass: case BuiltinType::ObjCSel: - case BuiltinType::OCLImage1d: - case BuiltinType::OCLImage1dArray: - case BuiltinType::OCLImage2d: - case BuiltinType::OCLImage2dArray: - case BuiltinType::OCLImage1dBuffer: - case BuiltinType::OCLImage2dDepth: - case BuiltinType::OCLImage2dArrayDepth: - case BuiltinType::OCLImage2dMSAA: - case BuiltinType::OCLImage2dArrayMSAA: - case BuiltinType::OCLImage2dMSAADepth: - case BuiltinType::OCLImage2dArrayMSAADepth: - case BuiltinType::OCLImage3d: +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: +#include "clang/AST/OpenCLImageTypes.def" case BuiltinType::OCLSampler: case BuiltinType::OCLEvent: case BuiltinType::OCLClkEvent: diff --git a/lib/AST/ItaniumMangle.cpp b/lib/AST/ItaniumMangle.cpp index 2a517a5ccf..cc5f7aebfe 100644 --- a/lib/AST/ItaniumMangle.cpp +++ b/lib/AST/ItaniumMangle.cpp @@ -2001,6 +2001,7 @@ void CXXNameMangler::mangleType(const BuiltinType *T) { // ::= Ds # char16_t // ::= Dn # std::nullptr_t (i.e., decltype(nullptr)) // ::= u # vendor extended type + std::string type_name; switch (T->getKind()) { case BuiltinType::Void: Out << 'v'; @@ -2091,42 +2092,12 @@ void CXXNameMangler::mangleType(const BuiltinType *T) { case BuiltinType::ObjCSel: Out << "13objc_selector"; break; - case BuiltinType::OCLImage1d: - Out << "11ocl_image1d"; - break; - case BuiltinType::OCLImage1dArray: - Out << "16ocl_image1darray"; - break; - case BuiltinType::OCLImage1dBuffer: - Out << "17ocl_image1dbuffer"; - break; - case BuiltinType::OCLImage2d: - Out << "11ocl_image2d"; - break; - case BuiltinType::OCLImage2dArray: - Out << "16ocl_image2darray"; - break; - case BuiltinType::OCLImage2dDepth: - Out << "16ocl_image2ddepth"; - break; - case BuiltinType::OCLImage2dArrayDepth: - Out << "21ocl_image2darraydepth"; - break; - case BuiltinType::OCLImage2dMSAA: - Out << "15ocl_image2dmsaa"; - break; - case BuiltinType::OCLImage2dArrayMSAA: - Out << "20ocl_image2darraymsaa"; - break; - case BuiltinType::OCLImage2dMSAADepth: - Out << "20ocl_image2dmsaadepth"; - break; - case BuiltinType::OCLImage2dArrayMSAADepth: - Out << "25ocl_image2darraymsaadepth"; - break; - case BuiltinType::OCLImage3d: - Out << "11ocl_image3d"; +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: \ + type_name = "ocl_" #ImgType "_" #Suffix; \ + Out << type_name.size() << type_name; \ break; +#include "clang/AST/OpenCLImageTypes.def" case BuiltinType::OCLSampler: Out << "11ocl_sampler"; break; diff --git a/lib/AST/MicrosoftMangle.cpp b/lib/AST/MicrosoftMangle.cpp index 60ad168f87..75627fc8ca 100644 --- a/lib/AST/MicrosoftMangle.cpp +++ b/lib/AST/MicrosoftMangle.cpp @@ -1717,54 +1717,11 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers, mangleArtificalTagType(TTK_Struct, "objc_selector"); break; - case BuiltinType::OCLImage1d: - Out << "PA"; - mangleArtificalTagType(TTK_Struct, "ocl_image1d"); - break; - case BuiltinType::OCLImage1dArray: - Out << "PA"; - mangleArtificalTagType(TTK_Struct, "ocl_image1darray"); - break; - case BuiltinType::OCLImage1dBuffer: - Out << "PA"; - mangleArtificalTagType(TTK_Struct, "ocl_image1dbuffer"); - break; - case BuiltinType::OCLImage2d: - Out << "PA"; - mangleArtificalTagType(TTK_Struct, "ocl_image2d"); - break; - case BuiltinType::OCLImage2dArray: - Out << "PA"; - mangleArtificalTagType(TTK_Struct, "ocl_image2darray"); - break; - case BuiltinType::OCLImage2dDepth: - Out << "PA"; - mangleArtificalTagType(TTK_Struct, "ocl_image2ddepth"); - break; - case BuiltinType::OCLImage2dArrayDepth: - Out << "PA"; - mangleArtificalTagType(TTK_Struct, "ocl_image2darraydepth"); - break; - case BuiltinType::OCLImage2dMSAA: - Out << "PA"; - mangleArtificalTagType(TTK_Struct, "ocl_image2dmsaa"); - break; - case BuiltinType::OCLImage2dArrayMSAA: - Out << "PA"; - mangleArtificalTagType(TTK_Struct, "ocl_image2darraymsaa"); - break; - case BuiltinType::OCLImage2dMSAADepth: - Out << "PA"; - mangleArtificalTagType(TTK_Struct, "ocl_image2dmsaadepth"); - break; - case BuiltinType::OCLImage2dArrayMSAADepth: - Out << "PA"; - mangleArtificalTagType(TTK_Struct, "ocl_image2darraymsaadepth"); - break; - case BuiltinType::OCLImage3d: - Out << "PA"; - mangleArtificalTagType(TTK_Struct, "ocl_image3d"); +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: \ + Out << "PAUocl_" #ImgType "_" #Suffix "@@"; \ break; +#include "clang/AST/OpenCLImageTypes.def" case BuiltinType::OCLSampler: Out << "PA"; mangleArtificalTagType(TTK_Struct, "ocl_sampler"); diff --git a/lib/AST/NSAPI.cpp b/lib/AST/NSAPI.cpp index c562dae632..6201200e50 100644 --- a/lib/AST/NSAPI.cpp +++ b/lib/AST/NSAPI.cpp @@ -445,18 +445,9 @@ NSAPI::getNSNumberFactoryMethodKind(QualType T) const { case BuiltinType::ObjCClass: case BuiltinType::ObjCId: case BuiltinType::ObjCSel: - case BuiltinType::OCLImage1d: - case BuiltinType::OCLImage1dArray: - case BuiltinType::OCLImage1dBuffer: - case BuiltinType::OCLImage2d: - case BuiltinType::OCLImage2dArray: - case BuiltinType::OCLImage2dDepth: - case BuiltinType::OCLImage2dArrayDepth: - case BuiltinType::OCLImage2dMSAA: - case BuiltinType::OCLImage2dArrayMSAA: - case BuiltinType::OCLImage2dMSAADepth: - case BuiltinType::OCLImage2dArrayMSAADepth: - case BuiltinType::OCLImage3d: +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: +#include "clang/AST/OpenCLImageTypes.def" case BuiltinType::OCLSampler: case BuiltinType::OCLEvent: case BuiltinType::OCLClkEvent: diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index d3c7259c38..8d0089f226 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -2581,30 +2581,10 @@ StringRef BuiltinType::getName(const PrintingPolicy &Policy) const { return "Class"; case ObjCSel: return "SEL"; - case OCLImage1d: - return "image1d_t"; - case OCLImage1dArray: - return "image1d_array_t"; - case OCLImage1dBuffer: - return "image1d_buffer_t"; - case OCLImage2d: - return "image2d_t"; - case OCLImage2dArray: - return "image2d_array_t"; - case OCLImage2dDepth: - return "image2d_depth_t"; - case OCLImage2dArrayDepth: - return "image2d_array_depth_t"; - case OCLImage2dMSAA: - return "image2d_msaa_t"; - case OCLImage2dArrayMSAA: - return "image2d_array_msaa_t"; - case OCLImage2dMSAADepth: - return "image2d_msaa_depth_t"; - case OCLImage2dArrayMSAADepth: - return "image2d_array_msaa_depth_t"; - case OCLImage3d: - return "image3d_t"; +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case Id: \ + return "__" #Access " " #ImgType "_t"; +#include "clang/AST/OpenCLImageTypes.def" case OCLSampler: return "sampler_t"; case OCLEvent: @@ -3578,18 +3558,9 @@ bool Type::canHaveNullability() const { case BuiltinType::ObjCId: case BuiltinType::ObjCClass: case BuiltinType::ObjCSel: - case BuiltinType::OCLImage1d: - case BuiltinType::OCLImage1dArray: - case BuiltinType::OCLImage1dBuffer: - case BuiltinType::OCLImage2d: - case BuiltinType::OCLImage2dArray: - case BuiltinType::OCLImage2dDepth: - case BuiltinType::OCLImage2dArrayDepth: - case BuiltinType::OCLImage2dMSAA: - case BuiltinType::OCLImage2dArrayMSAA: - case BuiltinType::OCLImage2dMSAADepth: - case BuiltinType::OCLImage2dArrayMSAADepth: - case BuiltinType::OCLImage3d: +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: +#include "clang/AST/OpenCLImageTypes.def" case BuiltinType::OCLSampler: case BuiltinType::OCLEvent: case BuiltinType::OCLClkEvent: diff --git a/lib/AST/TypeLoc.cpp b/lib/AST/TypeLoc.cpp index 565fa5dfda..548e183e8e 100644 --- a/lib/AST/TypeLoc.cpp +++ b/lib/AST/TypeLoc.cpp @@ -333,18 +333,9 @@ TypeSpecifierType BuiltinTypeLoc::getWrittenTypeSpec() const { case BuiltinType::ObjCId: case BuiltinType::ObjCClass: case BuiltinType::ObjCSel: - case BuiltinType::OCLImage1d: - case BuiltinType::OCLImage1dArray: - case BuiltinType::OCLImage1dBuffer: - case BuiltinType::OCLImage2d: - case BuiltinType::OCLImage2dArray: - case BuiltinType::OCLImage2dDepth: - case BuiltinType::OCLImage2dArrayDepth: - case BuiltinType::OCLImage2dMSAA: - case BuiltinType::OCLImage2dArrayMSAA: - case BuiltinType::OCLImage2dMSAADepth: - case BuiltinType::OCLImage2dArrayMSAADepth: - case BuiltinType::OCLImage3d: +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: +#include "clang/AST/OpenCLImageTypes.def" case BuiltinType::OCLSampler: case BuiltinType::OCLEvent: case BuiltinType::OCLClkEvent: diff --git a/lib/Analysis/PrintfFormatString.cpp b/lib/Analysis/PrintfFormatString.cpp index fb5df61c5e..3cc982d4d0 100644 --- a/lib/Analysis/PrintfFormatString.cpp +++ b/lib/Analysis/PrintfFormatString.cpp @@ -619,6 +619,9 @@ bool PrintfSpecifier::fixType(QualType QT, const LangOptions &LangOpt, // Various types which are non-trivial to correct. return false; +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: +#include "clang/AST/OpenCLImageTypes.def" #define SIGNED_TYPE(Id, SingletonId) #define UNSIGNED_TYPE(Id, SingletonId) #define FLOATING_TYPE(Id, SingletonId) diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 0520a732db..e158d2110f 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -463,39 +463,11 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) { return SelTy; } - case BuiltinType::OCLImage1d: - return getOrCreateStructPtrType("opencl_image1d_t", OCLImage1dDITy); - case BuiltinType::OCLImage1dArray: - return getOrCreateStructPtrType("opencl_image1d_array_t", - OCLImage1dArrayDITy); - case BuiltinType::OCLImage1dBuffer: - return getOrCreateStructPtrType("opencl_image1d_buffer_t", - OCLImage1dBufferDITy); - case BuiltinType::OCLImage2d: - return getOrCreateStructPtrType("opencl_image2d_t", OCLImage2dDITy); - case BuiltinType::OCLImage2dArray: - return getOrCreateStructPtrType("opencl_image2d_array_t", - OCLImage2dArrayDITy); - case BuiltinType::OCLImage2dDepth: - return getOrCreateStructPtrType("opencl_image2d_depth_t", - OCLImage2dDepthDITy); - case BuiltinType::OCLImage2dArrayDepth: - return getOrCreateStructPtrType("opencl_image2d_array_depth_t", - OCLImage2dArrayDepthDITy); - case BuiltinType::OCLImage2dMSAA: - return getOrCreateStructPtrType("opencl_image2d_msaa_t", - OCLImage2dMSAADITy); - case BuiltinType::OCLImage2dArrayMSAA: - return getOrCreateStructPtrType("opencl_image2d_array_msaa_t", - OCLImage2dArrayMSAADITy); - case BuiltinType::OCLImage2dMSAADepth: - return getOrCreateStructPtrType("opencl_image2d_msaa_depth_t", - OCLImage2dMSAADepthDITy); - case BuiltinType::OCLImage2dArrayMSAADepth: - return getOrCreateStructPtrType("opencl_image2d_array_msaa_depth_t", - OCLImage2dArrayMSAADepthDITy); - case BuiltinType::OCLImage3d: - return getOrCreateStructPtrType("opencl_image3d_t", OCLImage3dDITy); +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: \ + return getOrCreateStructPtrType("opencl_" #ImgType "_" #Suffix "_t", \ + SingletonId); +#include "clang/AST/OpenCLImageTypes.def" case BuiltinType::OCLSampler: return DBuilder.createBasicType( "opencl_sampler_t", CGM.getContext().getTypeSize(BT), diff --git a/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h index 2a92acf7f4..356850b560 100644 --- a/lib/CodeGen/CGDebugInfo.h +++ b/lib/CodeGen/CGDebugInfo.h @@ -64,18 +64,9 @@ class CGDebugInfo { llvm::DIType *ClassTy = nullptr; llvm::DICompositeType *ObjTy = nullptr; llvm::DIType *SelTy = nullptr; - llvm::DIType *OCLImage1dDITy = nullptr; - llvm::DIType *OCLImage1dArrayDITy = nullptr; - llvm::DIType *OCLImage1dBufferDITy = nullptr; - llvm::DIType *OCLImage2dDITy = nullptr; - llvm::DIType *OCLImage2dArrayDITy = nullptr; - llvm::DIType *OCLImage2dDepthDITy = nullptr; - llvm::DIType *OCLImage2dArrayDepthDITy = nullptr; - llvm::DIType *OCLImage2dMSAADITy = nullptr; - llvm::DIType *OCLImage2dArrayMSAADITy = nullptr; - llvm::DIType *OCLImage2dMSAADepthDITy = nullptr; - llvm::DIType *OCLImage2dArrayMSAADepthDITy = nullptr; - llvm::DIType *OCLImage3dDITy = nullptr; +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + llvm::DIType *SingletonId = nullptr; +#include "clang/AST/OpenCLImageTypes.def" llvm::DIType *OCLEventDITy = nullptr; llvm::DIType *OCLClkEventDITy = nullptr; llvm::DIType *OCLQueueDITy = nullptr; diff --git a/lib/CodeGen/CGOpenCLRuntime.cpp b/lib/CodeGen/CGOpenCLRuntime.cpp index 686678962d..c89e9cc16c 100644 --- a/lib/CodeGen/CGOpenCLRuntime.cpp +++ b/lib/CodeGen/CGOpenCLRuntime.cpp @@ -40,46 +40,12 @@ llvm::Type *CGOpenCLRuntime::convertOpenCLSpecificType(const Type *T) { default: llvm_unreachable("Unexpected opencl builtin type!"); return nullptr; - case BuiltinType::OCLImage1d: - return llvm::PointerType::get(llvm::StructType::create( - Ctx, "opencl.image1d_t"), ImgAddrSpc); - case BuiltinType::OCLImage1dArray: - return llvm::PointerType::get(llvm::StructType::create( - Ctx, "opencl.image1d_array_t"), ImgAddrSpc); - case BuiltinType::OCLImage1dBuffer: - return llvm::PointerType::get(llvm::StructType::create( - Ctx, "opencl.image1d_buffer_t"), ImgAddrSpc); - case BuiltinType::OCLImage2d: - return llvm::PointerType::get(llvm::StructType::create( - Ctx, "opencl.image2d_t"), ImgAddrSpc); - case BuiltinType::OCLImage2dArray: - return llvm::PointerType::get(llvm::StructType::create( - Ctx, "opencl.image2d_array_t"), ImgAddrSpc); - case BuiltinType::OCLImage2dDepth: - return llvm::PointerType::get( - llvm::StructType::create(Ctx, "opencl.image2d_depth_t"), ImgAddrSpc); - case BuiltinType::OCLImage2dArrayDepth: - return llvm::PointerType::get( - llvm::StructType::create(Ctx, "opencl.image2d_array_depth_t"), +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: \ + return llvm::PointerType::get( \ + llvm::StructType::create(Ctx, "opencl." #ImgType "_" #Suffix "_t"), \ ImgAddrSpc); - case BuiltinType::OCLImage2dMSAA: - return llvm::PointerType::get( - llvm::StructType::create(Ctx, "opencl.image2d_msaa_t"), ImgAddrSpc); - case BuiltinType::OCLImage2dArrayMSAA: - return llvm::PointerType::get( - llvm::StructType::create(Ctx, "opencl.image2d_array_msaa_t"), - ImgAddrSpc); - case BuiltinType::OCLImage2dMSAADepth: - return llvm::PointerType::get( - llvm::StructType::create(Ctx, "opencl.image2d_msaa_depth_t"), - ImgAddrSpc); - case BuiltinType::OCLImage2dArrayMSAADepth: - return llvm::PointerType::get( - llvm::StructType::create(Ctx, "opencl.image2d_array_msaa_depth_t"), - ImgAddrSpc); - case BuiltinType::OCLImage3d: - return llvm::PointerType::get(llvm::StructType::create( - Ctx, "opencl.image3d_t"), ImgAddrSpc); +#include "clang/AST/OpenCLImageTypes.def" case BuiltinType::OCLSampler: return llvm::IntegerType::get(Ctx, 32); case BuiltinType::OCLEvent: diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp index 554f9ff640..e42428fb73 100644 --- a/lib/CodeGen/CodeGenTypes.cpp +++ b/lib/CodeGen/CodeGenTypes.cpp @@ -464,18 +464,9 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) { ResultType = llvm::IntegerType::get(getLLVMContext(), 128); break; - case BuiltinType::OCLImage1d: - case BuiltinType::OCLImage1dArray: - case BuiltinType::OCLImage1dBuffer: - case BuiltinType::OCLImage2d: - case BuiltinType::OCLImage2dArray: - case BuiltinType::OCLImage2dDepth: - case BuiltinType::OCLImage2dArrayDepth: - case BuiltinType::OCLImage2dMSAA: - case BuiltinType::OCLImage2dArrayMSAA: - case BuiltinType::OCLImage2dMSAADepth: - case BuiltinType::OCLImage2dArrayMSAADepth: - case BuiltinType::OCLImage3d: +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: +#include "clang/AST/OpenCLImageTypes.def" case BuiltinType::OCLSampler: case BuiltinType::OCLEvent: case BuiltinType::OCLClkEvent: diff --git a/lib/CodeGen/ItaniumCXXABI.cpp b/lib/CodeGen/ItaniumCXXABI.cpp index a3fa669a9b..25cb5fe371 100644 --- a/lib/CodeGen/ItaniumCXXABI.cpp +++ b/lib/CodeGen/ItaniumCXXABI.cpp @@ -2536,18 +2536,9 @@ static bool TypeInfoIsInStandardLibrary(const BuiltinType *Ty) { case BuiltinType::UInt128: return true; - case BuiltinType::OCLImage1d: - case BuiltinType::OCLImage1dArray: - case BuiltinType::OCLImage1dBuffer: - case BuiltinType::OCLImage2d: - case BuiltinType::OCLImage2dArray: - case BuiltinType::OCLImage2dDepth: - case BuiltinType::OCLImage2dArrayDepth: - case BuiltinType::OCLImage2dMSAA: - case BuiltinType::OCLImage2dArrayMSAA: - case BuiltinType::OCLImage2dMSAADepth: - case BuiltinType::OCLImage2dArrayMSAADepth: - case BuiltinType::OCLImage3d: +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: +#include "clang/AST/OpenCLImageTypes.def" case BuiltinType::OCLSampler: case BuiltinType::OCLEvent: case BuiltinType::OCLClkEvent: diff --git a/lib/Index/USRGeneration.cpp b/lib/Index/USRGeneration.cpp index 2722f081fe..a15ad12b09 100644 --- a/lib/Index/USRGeneration.cpp +++ b/lib/Index/USRGeneration.cpp @@ -624,18 +624,9 @@ void USRGenerator::VisitType(QualType T) { #define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id: #include "clang/AST/BuiltinTypes.def" case BuiltinType::Dependent: - case BuiltinType::OCLImage1d: - case BuiltinType::OCLImage1dArray: - case BuiltinType::OCLImage1dBuffer: - case BuiltinType::OCLImage2d: - case BuiltinType::OCLImage2dArray: - case BuiltinType::OCLImage2dDepth: - case BuiltinType::OCLImage2dArrayDepth: - case BuiltinType::OCLImage2dMSAA: - case BuiltinType::OCLImage2dArrayMSAA: - case BuiltinType::OCLImage2dMSAADepth: - case BuiltinType::OCLImage2dArrayMSAADepth: - case BuiltinType::OCLImage3d: +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: +#include "clang/AST/OpenCLImageTypes.def" case BuiltinType::OCLEvent: case BuiltinType::OCLClkEvent: case BuiltinType::OCLQueue: diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 84204aadb1..7a4e75c48b 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -3363,6 +3363,12 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, } isInvalid = DS.SetTypePipe(true, Loc, PrevSpec, DiagID, Policy); break; +#define GENERIC_IMAGE_TYPE(ImgType, Id) \ + case tok::kw_##ImgType##_t: \ + isInvalid = DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, \ + DiagID, Policy); \ + break; +#include "clang/AST/OpenCLImageTypes.def" case tok::kw___unknown_anytype: isInvalid = DS.SetTypeSpecType(TST_unknown_anytype, Loc, PrevSpec, DiagID, Policy); @@ -4300,6 +4306,8 @@ bool Parser::isKnownToBeTypeSpecifier(const Token &Tok) const { case tok::kw__Decimal64: case tok::kw__Decimal128: case tok::kw___vector: +#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: +#include "clang/AST/OpenCLImageTypes.def" // struct-or-union-specifier (C99) or class-specifier (C++) case tok::kw_class: @@ -4372,6 +4380,8 @@ bool Parser::isTypeSpecifierQualifier() { case tok::kw__Decimal64: case tok::kw__Decimal128: case tok::kw___vector: +#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: +#include "clang/AST/OpenCLImageTypes.def" // struct-or-union-specifier (C99) or class-specifier (C++) case tok::kw_class: @@ -4608,6 +4618,8 @@ bool Parser::isDeclarationSpecifier(bool DisambiguatingWithExpression) { case tok::kw___read_only: case tok::kw___read_write: case tok::kw___write_only: +#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: +#include "clang/AST/OpenCLImageTypes.def" return true; } diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index 07f750550e..12b80ba84f 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -1169,7 +1169,10 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression, case tok::kw_void: case tok::kw_typename: case tok::kw_typeof: - case tok::kw___vector: { + case tok::kw___vector: +#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: +#include "clang/AST/OpenCLImageTypes.def" + { if (!getLangOpts().CPlusPlus) { Diag(Tok, diag::err_expected_expression); return ExprError(); diff --git a/lib/Parse/ParseTentative.cpp b/lib/Parse/ParseTentative.cpp index 6fbcfd9bd2..a521fbfd7b 100644 --- a/lib/Parse/ParseTentative.cpp +++ b/lib/Parse/ParseTentative.cpp @@ -987,6 +987,8 @@ Parser::isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind) { case tok::kw___pixel: case tok::kw___bool: case tok::kw__Atomic: +#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: +#include "clang/AST/OpenCLImageTypes.def" case tok::kw___unknown_anytype: return TPResult::False; diff --git a/lib/Sema/DeclSpec.cpp b/lib/Sema/DeclSpec.cpp index ae0242cce0..cbe1993980 100644 --- a/lib/Sema/DeclSpec.cpp +++ b/lib/Sema/DeclSpec.cpp @@ -302,6 +302,8 @@ bool Declarator::isDeclarationOfFunction() const { case TST_unspecified: case TST_void: case TST_wchar: +#define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t: +#include "clang/AST/OpenCLImageTypes.def" return false; case TST_decltype_auto: @@ -474,6 +476,10 @@ const char *DeclSpec::getSpecifierName(DeclSpec::TST T, case DeclSpec::TST_underlyingType: return "__underlying_type"; case DeclSpec::TST_unknown_anytype: return "__unknown_anytype"; case DeclSpec::TST_atomic: return "_Atomic"; +#define GENERIC_IMAGE_TYPE(ImgType, Id) \ + case DeclSpec::TST_##ImgType##_t: \ + return #ImgType "_t"; +#include "clang/AST/OpenCLImageTypes.def" case DeclSpec::TST_error: return "(error)"; } llvm_unreachable("Unknown typespec!"); diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 997d967aa1..5a8e5510f7 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -208,23 +208,9 @@ void Sema::Initialize() { // Initialize predefined OpenCL types. if (getLangOpts().OpenCL) { - addImplicitTypedef("image1d_t", Context.OCLImage1dTy); - addImplicitTypedef("image1d_array_t", Context.OCLImage1dArrayTy); - addImplicitTypedef("image1d_buffer_t", Context.OCLImage1dBufferTy); - addImplicitTypedef("image2d_t", Context.OCLImage2dTy); - addImplicitTypedef("image2d_array_t", Context.OCLImage2dArrayTy); - addImplicitTypedef("image3d_t", Context.OCLImage3dTy); addImplicitTypedef("sampler_t", Context.OCLSamplerTy); addImplicitTypedef("event_t", Context.OCLEventTy); if (getLangOpts().OpenCLVersion >= 200) { - addImplicitTypedef("image2d_depth_t", Context.OCLImage2dDepthTy); - addImplicitTypedef("image2d_array_depth_t", - Context.OCLImage2dArrayDepthTy); - addImplicitTypedef("image2d_msaa_t", Context.OCLImage2dMSAATy); - addImplicitTypedef("image2d_array_msaa_t", Context.OCLImage2dArrayMSAATy); - addImplicitTypedef("image2d_msaa_depth_t", Context.OCLImage2dMSAADepthTy); - addImplicitTypedef("image2d_array_msaa_depth_t", - Context.OCLImage2dArrayMSAADepthTy); addImplicitTypedef("clk_event_t", Context.OCLClkEventTy); addImplicitTypedef("queue_t", Context.OCLQueueTy); addImplicitTypedef("ndrange_t", Context.OCLNDRangeTy); diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index cfd58983df..32e189a843 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -4915,6 +4915,9 @@ static bool isPlaceholderToRemoveAsArg(QualType type) { switch (placeholder->getKind()) { // Ignore all the non-placeholder types. +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: +#include "clang/AST/OpenCLImageTypes.def" #define PLACEHOLDER_TYPE(ID, SINGLETON_ID) #define BUILTIN_TYPE(ID, SINGLETON_ID) case BuiltinType::ID: #include "clang/AST/BuiltinTypes.def" @@ -14840,8 +14843,10 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) { return ExprError(); // Everything else should be impossible. -#define BUILTIN_TYPE(Id, SingletonId) \ +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ case BuiltinType::Id: +#include "clang/AST/OpenCLImageTypes.def" +#define BUILTIN_TYPE(Id, SingletonId) case BuiltinType::Id: #define PLACEHOLDER_TYPE(Id, SingletonId) #include "clang/AST/BuiltinTypes.def" break; diff --git a/lib/Sema/SemaTemplateVariadic.cpp b/lib/Sema/SemaTemplateVariadic.cpp index c692c9f75c..d2b359b24c 100644 --- a/lib/Sema/SemaTemplateVariadic.cpp +++ b/lib/Sema/SemaTemplateVariadic.cpp @@ -739,6 +739,8 @@ bool Sema::containsUnexpandedParameterPacks(Declarator &D) { case TST_auto: case TST_auto_type: case TST_decltype_auto: +#define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t: +#include "clang/AST/OpenCLImageTypes.def" case TST_unknown_anytype: case TST_error: break; diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 924cd07e02..3b0e3274e5 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -11,7 +11,6 @@ // //===----------------------------------------------------------------------===// -#include "clang/Sema/SemaInternal.h" #include "TypeLocBuilder.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" @@ -22,17 +21,19 @@ #include "clang/AST/Expr.h" #include "clang/AST/TypeLoc.h" #include "clang/AST/TypeLocVisitor.h" -#include "clang/Lex/Preprocessor.h" #include "clang/Basic/PartialDiagnostic.h" #include "clang/Basic/TargetInfo.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Lex/Preprocessor.h" #include "clang/Sema/DeclSpec.h" #include "clang/Sema/DelayedDiagnostic.h" #include "clang/Sema/Lookup.h" #include "clang/Sema/ScopeInfo.h" +#include "clang/Sema/SemaInternal.h" #include "clang/Sema/Template.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringSwitch.h" #include "llvm/Support/ErrorHandling.h" using namespace clang; @@ -1178,6 +1179,21 @@ TypeResult Sema::actOnObjCTypeArgsAndProtocolQualifiers( return CreateParsedType(Result, ResultTInfo); } +static StringRef getImageAccessAttrStr(AttributeList *attrs) { + if (attrs) { + + AttributeList *Next; + do { + AttributeList &Attr = *attrs; + Next = Attr.getNext(); + if (Attr.getKind() == AttributeList::AT_OpenCLAccess) { + return Attr.getName()->getName(); + } + } while (Next); + } + return ""; +} + /// \brief Convert the specified declspec to the appropriate type /// object. /// \param state Specifies the declarator containing the declaration specifier @@ -1362,6 +1378,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) { } break; case DeclSpec::TST_bool: Result = Context.BoolTy; break; // _Bool or bool + break; case DeclSpec::TST_decimal32: // _Decimal32 case DeclSpec::TST_decimal64: // _Decimal64 case DeclSpec::TST_decimal128: // _Decimal128 @@ -1430,9 +1447,18 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) { declarator.setInvalidType(true); } } else if (!S.getOpenCLOptions().cl_khr_gl_msaa_sharing && - (Result->isImage2dMSAAT() || Result->isImage2dArrayMSAAT() || - Result->isImage2dArrayMSAATDepth() || - Result->isImage2dMSAATDepth())) { + (Result->isOCLImage2dArrayMSAADepthROType() || + Result->isOCLImage2dArrayMSAADepthWOType() || + Result->isOCLImage2dArrayMSAADepthRWType() || + Result->isOCLImage2dArrayMSAAROType() || + Result->isOCLImage2dArrayMSAARWType() || + Result->isOCLImage2dArrayMSAAWOType() || + Result->isOCLImage2dMSAADepthROType() || + Result->isOCLImage2dMSAADepthRWType() || + Result->isOCLImage2dMSAADepthWOType() || + Result->isOCLImage2dMSAAROType() || + Result->isOCLImage2dMSAARWType() || + Result->isOCLImage2dMSAAWOType())) { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) << Result << "cl_khr_gl_msaa_sharing"; declarator.setInvalidType(true); @@ -1546,6 +1572,16 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) { } break; +#define GENERIC_IMAGE_TYPE(ImgType, Id) \ + case DeclSpec::TST_##ImgType##_t: \ + Result = llvm::StringSwitch( \ + getImageAccessAttrStr(DS.getAttributes().getList())) \ + .Cases("write_only", "__write_only", Context.Id##WOTy) \ + .Cases("read_write", "__read_write", Context.Id##RWTy) \ + .Default(Context.Id##ROTy); \ + break; +#include "clang/AST/OpenCLImageTypes.def" + case DeclSpec::TST_error: Result = Context.IntTy; declarator.setInvalidType(true); diff --git a/lib/Serialization/ASTCommon.cpp b/lib/Serialization/ASTCommon.cpp index c83c664d2a..76630f5e8a 100644 --- a/lib/Serialization/ASTCommon.cpp +++ b/lib/Serialization/ASTCommon.cpp @@ -127,42 +127,11 @@ serialization::TypeIdxFromBuiltin(const BuiltinType *BT) { case BuiltinType::ObjCSel: ID = PREDEF_TYPE_OBJC_SEL; break; - case BuiltinType::OCLImage1d: - ID = PREDEF_TYPE_IMAGE1D_ID; - break; - case BuiltinType::OCLImage1dArray: - ID = PREDEF_TYPE_IMAGE1D_ARR_ID; - break; - case BuiltinType::OCLImage1dBuffer: - ID = PREDEF_TYPE_IMAGE1D_BUFF_ID; - break; - case BuiltinType::OCLImage2d: - ID = PREDEF_TYPE_IMAGE2D_ID; - break; - case BuiltinType::OCLImage2dArray: - ID = PREDEF_TYPE_IMAGE2D_ARR_ID; - break; - case BuiltinType::OCLImage2dDepth: - ID = PREDEF_TYPE_IMAGE2D_DEP_ID; - break; - case BuiltinType::OCLImage2dArrayDepth: - ID = PREDEF_TYPE_IMAGE2D_ARR_DEP_ID; - break; - case BuiltinType::OCLImage2dMSAA: - ID = PREDEF_TYPE_IMAGE2D_MSAA_ID; - break; - case BuiltinType::OCLImage2dArrayMSAA: - ID = PREDEF_TYPE_IMAGE2D_ARR_MSAA_ID; - break; - case BuiltinType::OCLImage2dMSAADepth: - ID = PREDEF_TYPE_IMAGE2D_MSAA_DEP_ID; - break; - case BuiltinType::OCLImage2dArrayMSAADepth: - ID = PREDEF_TYPE_IMAGE2D_ARR_MSAA_DEPTH_ID; - break; - case BuiltinType::OCLImage3d: - ID = PREDEF_TYPE_IMAGE3D_ID; +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: \ + ID = PREDEF_TYPE_##Id##_ID; \ break; +#include "clang/AST/OpenCLImageTypes.def" case BuiltinType::OCLSampler: ID = PREDEF_TYPE_SAMPLER_ID; break; diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 0ca6c0fea7..0677ee4dbd 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -6092,42 +6092,11 @@ QualType ASTReader::GetType(TypeID ID) { case PREDEF_TYPE_OBJC_SEL: T = Context.ObjCBuiltinSelTy; break; - case PREDEF_TYPE_IMAGE1D_ID: - T = Context.OCLImage1dTy; - break; - case PREDEF_TYPE_IMAGE1D_ARR_ID: - T = Context.OCLImage1dArrayTy; - break; - case PREDEF_TYPE_IMAGE1D_BUFF_ID: - T = Context.OCLImage1dBufferTy; - break; - case PREDEF_TYPE_IMAGE2D_ID: - T = Context.OCLImage2dTy; - break; - case PREDEF_TYPE_IMAGE2D_ARR_ID: - T = Context.OCLImage2dArrayTy; - break; - case PREDEF_TYPE_IMAGE2D_DEP_ID: - T = Context.OCLImage2dDepthTy; - break; - case PREDEF_TYPE_IMAGE2D_ARR_DEP_ID: - T = Context.OCLImage2dArrayDepthTy; - break; - case PREDEF_TYPE_IMAGE2D_MSAA_ID: - T = Context.OCLImage2dMSAATy; - break; - case PREDEF_TYPE_IMAGE2D_ARR_MSAA_ID: - T = Context.OCLImage2dArrayMSAATy; - break; - case PREDEF_TYPE_IMAGE2D_MSAA_DEP_ID: - T = Context.OCLImage2dMSAADepthTy; - break; - case PREDEF_TYPE_IMAGE2D_ARR_MSAA_DEPTH_ID: - T = Context.OCLImage2dArrayMSAADepthTy; - break; - case PREDEF_TYPE_IMAGE3D_ID: - T = Context.OCLImage3dTy; +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case PREDEF_TYPE_##Id##_ID: \ + T = Context.SingletonId; \ break; +#include "clang/AST/OpenCLImageTypes.def" case PREDEF_TYPE_SAMPLER_ID: T = Context.OCLSamplerTy; break; diff --git a/test/CodeGenOpenCL/images.cl b/test/CodeGenOpenCL/images.cl new file mode 100644 index 0000000000..eb054eceb5 --- /dev/null +++ b/test/CodeGenOpenCL/images.cl @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -O0 -emit-llvm -o - | FileCheck %s + +__attribute__((overloadable)) void read_image(read_only image1d_t img_ro); +__attribute__((overloadable)) void read_image(write_only image1d_t img_wo); + +kernel void test_read_image(read_only image1d_t img_ro, write_only image1d_t img_wo) { + // CHECK: call void @_Z10read_image14ocl_image1d_ro(%opencl.image1d_ro_t* %{{[0-9]+}}) + read_image(img_ro); + // CHECK: call void @_Z10read_image14ocl_image1d_wo(%opencl.image1d_wo_t* %{{[0-9]+}}) + read_image(img_wo); +} diff --git a/test/CodeGenOpenCL/opencl_types.cl b/test/CodeGenOpenCL/opencl_types.cl index 6fb39cb78e..5691b27fbe 100644 --- a/test/CodeGenOpenCL/opencl_types.cl +++ b/test/CodeGenOpenCL/opencl_types.cl @@ -4,37 +4,37 @@ constant sampler_t glb_smp = 7; // CHECK: constant i32 7 void fnc1(image1d_t img) {} -// CHECK: @fnc1(%opencl.image1d_t* +// CHECK: @fnc1(%opencl.image1d_ro_t* void fnc1arr(image1d_array_t img) {} -// CHECK: @fnc1arr(%opencl.image1d_array_t* +// CHECK: @fnc1arr(%opencl.image1d_array_ro_t* void fnc1buff(image1d_buffer_t img) {} -// CHECK: @fnc1buff(%opencl.image1d_buffer_t* +// CHECK: @fnc1buff(%opencl.image1d_buffer_ro_t* void fnc2(image2d_t img) {} -// CHECK: @fnc2(%opencl.image2d_t* +// CHECK: @fnc2(%opencl.image2d_ro_t* void fnc2arr(image2d_array_t img) {} -// CHECK: @fnc2arr(%opencl.image2d_array_t* +// CHECK: @fnc2arr(%opencl.image2d_array_ro_t* void fnc3(image3d_t img) {} -// CHECK: @fnc3(%opencl.image3d_t* +// CHECK: @fnc3(%opencl.image3d_ro_t* void fnc4smp(sampler_t s) {} // CHECK-LABEL: define {{.*}}void @fnc4smp(i32 kernel void foo(image1d_t img) { - sampler_t smp = 5; -// CHECK: alloca i32 - event_t evt; -// CHECK: alloca %opencl.event_t* -// CHECK: store i32 5, + sampler_t smp = 5; + // CHECK: alloca i32 + event_t evt; + // CHECK: alloca %opencl.event_t* + // CHECK: store i32 5, fnc4smp(smp); -// CHECK: call {{.*}}void @fnc4smp(i32 + // CHECK: call {{.*}}void @fnc4smp(i32 fnc4smp(glb_smp); -// CHECK: call {{.*}}void @fnc4smp(i32 + // CHECK: call {{.*}}void @fnc4smp(i32 } void __attribute__((overloadable)) bad1(image1d_t b, image2d_t c, image2d_t d) {} -// CHECK-LABEL: @{{_Z4bad111ocl_image1d11ocl_image2dS0_|"\\01\?bad1@@\$\$J0YAXPAUocl_image1d@@PAUocl_image2d@@1@Z"}} +// CHECK-LABEL: @{{_Z4bad114ocl_image1d_ro14ocl_image2d_roS0_|"\\01\?bad1@@\$\$J0YAXPAUocl_image1d_ro@@PAUocl_image2d_ro@@1@Z"}} diff --git a/test/SemaOpenCL/images.cl b/test/SemaOpenCL/images.cl new file mode 100644 index 0000000000..f963de4e13 --- /dev/null +++ b/test/SemaOpenCL/images.cl @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only + +void img2d_ro(__read_only image2d_t img) {} // expected-note{{passing argument to parameter 'img' here}} expected-note{{passing argument to parameter 'img' here}} + +void imgage_access_test(image2d_t img2dro, write_only image2d_t img2dwo, image3d_t img3dro) { + img2d_ro(img2dro); + img2d_ro(img2dwo); // expected-error{{passing '__write_only image2d_t' to parameter of incompatible type '__read_only image2d_t'}} + img2d_ro(img3dro); // expected-error{{passing '__read_only image3d_t' to parameter of incompatible type '__read_only image2d_t'}} +} diff --git a/test/SemaOpenCL/invalid-access-qualifier.cl b/test/SemaOpenCL/invalid-access-qualifier.cl index b090bb5733..5af3c4c959 100644 --- a/test/SemaOpenCL/invalid-access-qualifier.cl +++ b/test/SemaOpenCL/invalid-access-qualifier.cl @@ -10,5 +10,5 @@ void test3(read_only read_only image1d_t i){} // expected-error{{multiple access #ifdef CL20 void test4(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'pipe'}} #else -void test4(__read_write image1d_t i){} // expected-error{{access qualifier '__read_write' can not be used for 'image1d_t' earlier than OpenCL2.0 version}} +void test4(__read_write image1d_t i) {} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' earlier than OpenCL2.0 version}} #endif diff --git a/test/SemaOpenCL/invalid-image.cl b/test/SemaOpenCL/invalid-image.cl index 2ef7abf4cd..ed8af09579 100644 --- a/test/SemaOpenCL/invalid-image.cl +++ b/test/SemaOpenCL/invalid-image.cl @@ -1,8 +1,8 @@ // RUN: %clang_cc1 -verify %s -void test1(image1d_t *i){} // expected-error {{pointer to type 'image1d_t' is invalid in OpenCL}} +void test1(image1d_t *i) {} // expected-error {{pointer to type '__read_only image1d_t' is invalid in OpenCL}} void test2(image1d_t i) { - image1d_t ti; // expected-error {{type 'image1d_t' can only be used as a function parameter}} - image1d_t ai[] = {i,i};// expected-error {{array of 'image1d_t' type is invalid in OpenCL}} + image1d_t ti; // expected-error {{type '__read_only image1d_t' can only be used as a function parameter}} + image1d_t ai[] = {i, i}; // expected-error {{array of '__read_only image1d_t' type is invalid in OpenCL}} } diff --git a/test/SemaOpenCL/invalid-kernel-parameters.cl b/test/SemaOpenCL/invalid-kernel-parameters.cl index 95a56e2972..a30a27faa9 100644 --- a/test/SemaOpenCL/invalid-kernel-parameters.cl +++ b/test/SemaOpenCL/invalid-kernel-parameters.cl @@ -27,7 +27,7 @@ typedef struct FooImage2D // expected-note{{within field of type 'FooImage2D' de // TODO: Clean up needed - we don't really need to check for image, event, etc // as a note here any longer. // They are diagnosed as an error for all struct fields (OpenCL v1.2 s6.9b,r). - image2d_t imageField; // expected-note{{field of illegal type 'image2d_t' declared here}} expected-error{{the 'image2d_t' type cannot be used to declare a structure or union field}} + image2d_t imageField; // expected-note{{field of illegal type '__read_only image2d_t' declared here}} expected-error{{the '__read_only image2d_t' type cannot be used to declare a structure or union field}} } FooImage2D; kernel void image_in_struct_arg(FooImage2D arg) { } // expected-error{{struct kernel parameters may not contain pointers}} diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 5dca6f9207..ef93489710 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -1454,18 +1454,9 @@ bool CursorVisitor::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { case BuiltinType::Void: case BuiltinType::NullPtr: case BuiltinType::Dependent: - case BuiltinType::OCLImage1d: - case BuiltinType::OCLImage1dArray: - case BuiltinType::OCLImage1dBuffer: - case BuiltinType::OCLImage2d: - case BuiltinType::OCLImage2dArray: - case BuiltinType::OCLImage2dDepth: - case BuiltinType::OCLImage2dArrayDepth: - case BuiltinType::OCLImage2dMSAA: - case BuiltinType::OCLImage2dArrayMSAA: - case BuiltinType::OCLImage2dMSAADepth: - case BuiltinType::OCLImage2dArrayMSAADepth: - case BuiltinType::OCLImage3d: +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: +#include "clang/AST/OpenCLImageTypes.def" case BuiltinType::OCLSampler: case BuiltinType::OCLEvent: case BuiltinType::OCLClkEvent: -- 2.40.0