summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorYaxun Liu <Yaxun.Liu@amd.com>2016-12-18 05:18:55 +0000
committerYaxun Liu <Yaxun.Liu@amd.com>2016-12-18 05:18:55 +0000
commitc6fb598a301143e9d21156a012cc6ef669ff0188 (patch)
tree97a4e43faff52dc33a182642cbae3ed7e318165f /include
parent2c7cf6d8125fa8c2905f1b683ce3dd327997448b (diff)
Recommit r289979 [OpenCL] Allow disabling types and declarations associated with extensions
Fixed undefined behavior due to cast integer to bool in initializer list. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290056 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/clang/Basic/DiagnosticParseKinds.td6
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td6
-rw-r--r--include/clang/Basic/OpenCLImageTypes.def98
-rw-r--r--include/clang/Basic/OpenCLOptions.h111
-rw-r--r--include/clang/Basic/TargetInfo.h2
-rw-r--r--include/clang/Sema/Overload.h5
-rw-r--r--include/clang/Sema/Sema.h67
-rw-r--r--include/clang/Serialization/ASTBitCodes.h28
-rw-r--r--include/clang/Serialization/ASTReader.h8
-rw-r--r--include/clang/Serialization/ASTWriter.h2
10 files changed, 234 insertions, 99 deletions
diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td
index f6d8b3ad54..0ebf34802b 100644
--- a/include/clang/Basic/DiagnosticParseKinds.td
+++ b/include/clang/Basic/DiagnosticParseKinds.td
@@ -968,8 +968,10 @@ def err_opencl_unroll_hint_on_non_loop : Error<
// OpenCL EXTENSION pragma (OpenCL 1.1 [9.1])
def warn_pragma_expected_colon : Warning<
"missing ':' after %0 - ignoring">, InGroup<IgnoredPragmas>;
-def warn_pragma_expected_enable_disable : Warning<
- "expected 'enable' or 'disable' - ignoring">, InGroup<IgnoredPragmas>;
+def warn_pragma_expected_predicate : Warning<
+ "expected %select{'enable', 'disable', 'begin' or 'end'|'disable'}0 - ignoring">, InGroup<IgnoredPragmas>;
+def warn_pragma_begin_end_mismatch : Warning<
+ "OpenCL extension end directive mismatches begin directive - ignoring">, InGroup<IgnoredPragmas>;
def warn_pragma_unknown_extension : Warning<
"unknown OpenCL extension %0 - ignoring">, InGroup<IgnoredPragmas>;
def warn_pragma_unsupported_extension : Warning<
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 8498740146..73f7f4ddd6 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3359,6 +3359,8 @@ def note_ovl_candidate_has_pass_object_size_params: Note<
"pass_object_size attribute">;
def note_ovl_candidate_disabled_by_enable_if_attr : Note<
"candidate disabled: %0">;
+def note_ovl_candidate_disabled_by_extension : Note<
+ "candidate disabled due to OpenCL extension">;
def err_addrof_function_disabled_by_enable_if_attr : Error<
"cannot take address of function %0 becuase it has one or more "
"non-tautological enable_if conditions">;
@@ -7936,8 +7938,6 @@ def ext_c99_array_usage : Extension<
def err_c99_array_usage_cxx : Error<
"%select{qualifier in |static |}0array size %select{||'[*] '}0is a C99 "
"feature, not permitted in C++">;
- def err_type_requires_extension : Error<
- "use of type %0 requires %1 extension to be enabled">;
def err_type_unsupported : Error<
"%0 is not supported on this target">;
def err_nsconsumed_attribute_mismatch : Error<
@@ -8143,6 +8143,8 @@ def warn_opencl_attr_deprecated_ignored : Warning <
InGroup<IgnoredAttributes>;
def err_opencl_variadic_function : Error<
"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">;
// OpenCL v2.0 s6.13.6 -- Builtin Pipe Functions
def err_opencl_builtin_pipe_first_arg : Error<
diff --git a/include/clang/Basic/OpenCLImageTypes.def b/include/clang/Basic/OpenCLImageTypes.def
index 26db4ced60..1ca12f683b 100644
--- a/include/clang/Basic/OpenCLImageTypes.def
+++ b/include/clang/Basic/OpenCLImageTypes.def
@@ -7,73 +7,79 @@
//
//===----------------------------------------------------------------------===//
// 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
+// Custom code should define one of those three 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
+// with given ID, singleton ID access type and a codegen suffix
+// GENERIC_IMAGE_TYPE_EXT(Type, Id, Ext) - a generic image with its Id and
+// required extension without an access type
#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)
+#define IMAGE_READ_TYPE(Type, Id, Ext) GENERIC_IMAGE_TYPE(Type, Id)
+#define IMAGE_WRITE_TYPE(Type, Id, Ext)
+#define IMAGE_READ_WRITE_TYPE(Type, Id, Ext)
-#else
+#elif defined(GENERIC_IMAGE_TYPE_EXT)
+#define IMAGE_READ_TYPE(Type, Id, Ext) GENERIC_IMAGE_TYPE_EXT(Type, Id##ROTy, Ext)
+#define IMAGE_WRITE_TYPE(Type, Id, Ext) GENERIC_IMAGE_TYPE_EXT(Type, Id##WOTy, Ext)
+#define IMAGE_READ_WRITE_TYPE(Type, Id, Ext) GENERIC_IMAGE_TYPE_EXT(Type, Id##RWTy, Ext)
+#else
#ifndef IMAGE_READ_TYPE
-#define IMAGE_READ_TYPE(Type, Id) \
+#define IMAGE_READ_TYPE(Type, Id, Ext) \
IMAGE_TYPE(Type, Id##RO, Id##ROTy, read_only, ro)
#endif
#ifndef IMAGE_WRITE_TYPE
-#define IMAGE_WRITE_TYPE(Type, Id) \
+#define IMAGE_WRITE_TYPE(Type, Id, Ext) \
IMAGE_TYPE(Type, Id##WO, Id##WOTy, write_only, wo)
#endif
#ifndef IMAGE_READ_WRITE_TYPE
-#define IMAGE_READ_WRITE_TYPE(Type, Id) \
+#define IMAGE_READ_WRITE_TYPE(Type, Id, Ext) \
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_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, "cl_khr_gl_msaa_sharing")
+IMAGE_READ_TYPE(image2d_array_msaa, OCLImage2dArrayMSAA, "cl_khr_gl_msaa_sharing")
+IMAGE_READ_TYPE(image2d_msaa_depth, OCLImage2dMSAADepth, "cl_khr_gl_msaa_sharing")
+IMAGE_READ_TYPE(image2d_array_msaa_depth, OCLImage2dArrayMSAADepth, "cl_khr_gl_msaa_sharing")
+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_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, "cl_khr_gl_msaa_sharing")
+IMAGE_WRITE_TYPE(image2d_array_msaa, OCLImage2dArrayMSAA, "cl_khr_gl_msaa_sharing")
+IMAGE_WRITE_TYPE(image2d_msaa_depth, OCLImage2dMSAADepth, "cl_khr_gl_msaa_sharing")
+IMAGE_WRITE_TYPE(image2d_array_msaa_depth, OCLImage2dArrayMSAADepth, "cl_khr_gl_msaa_sharing")
+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)
+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, "cl_khr_gl_msaa_sharing")
+IMAGE_READ_WRITE_TYPE(image2d_array_msaa, OCLImage2dArrayMSAA, "cl_khr_gl_msaa_sharing")
+IMAGE_READ_WRITE_TYPE(image2d_msaa_depth, OCLImage2dMSAADepth, "cl_khr_gl_msaa_sharing")
+IMAGE_READ_WRITE_TYPE(image2d_array_msaa_depth, OCLImage2dArrayMSAADepth, "cl_khr_gl_msaa_sharing")
+IMAGE_READ_WRITE_TYPE(image3d, OCLImage3d, "")
#undef IMAGE_TYPE
#undef GENERIC_IMAGE_TYPE
diff --git a/include/clang/Basic/OpenCLOptions.h b/include/clang/Basic/OpenCLOptions.h
index fa52ae723f..9fb4dbb7ba 100644
--- a/include/clang/Basic/OpenCLOptions.h
+++ b/include/clang/Basic/OpenCLOptions.h
@@ -15,81 +15,122 @@
#ifndef LLVM_CLANG_BASIC_OPENCLOPTIONS_H
#define LLVM_CLANG_BASIC_OPENCLOPTIONS_H
-#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringMap.h"
namespace clang {
/// \brief OpenCL supported extensions and optional core features
class OpenCLOptions {
+ struct Info {
+ bool Supported; // Is this option supported
+ bool Enabled; // Is this option enabled
+ unsigned Avail; // Option starts to be available in this OpenCL version
+ unsigned Core; // Option becomes (optional) core feature in this OpenCL
+ // version
+ Info(bool S = false, bool E = false, unsigned A = 100, unsigned C = ~0U)
+ :Supported(S), Enabled(E), Avail(A), Core(C){}
+ };
+ llvm::StringMap<Info> OptMap;
public:
-#define OPENCLEXT(nm) unsigned nm : 1;
-#include "clang/Basic/OpenCLExtensions.def"
+ bool isKnown(StringRef Ext) const {
+ return OptMap.find(Ext) != OptMap.end();
+ }
- OpenCLOptions() {
-#define OPENCLEXT(nm) nm = 0;
-#include "clang/Basic/OpenCLExtensions.def"
+ bool isEnabled(StringRef Ext) const {
+ return OptMap.find(Ext)->second.Enabled;
}
- // Enable or disable all options.
- void setAll(bool Enable = true) {
-#define OPENCLEXT(nm) nm = Enable;
-#include "clang/Basic/OpenCLExtensions.def"
+ // Is supported as either an extension or an (optional) core feature for
+ // OpenCL version \p CLVer.
+ bool isSupported(StringRef Ext, unsigned CLVer) const {
+ auto I = OptMap.find(Ext)->getValue();
+ return I.Supported && I.Avail <= CLVer;
+ }
+
+ // Is supported (optional) OpenCL core features for OpenCL version \p CLVer.
+ // For supported extension, return false.
+ bool isSupportedCore(StringRef Ext, unsigned CLVer) const {
+ auto I = OptMap.find(Ext)->getValue();
+ return I.Supported && I.Avail <= CLVer &&
+ I.Core != ~0U && CLVer >= I.Core;
+ }
+
+ // Is supported OpenCL extension for OpenCL version \p CLVer.
+ // For supported (optional) core feature, return false.
+ bool isSupportedExtension(StringRef Ext, unsigned CLVer) const {
+ auto I = OptMap.find(Ext)->getValue();
+ return I.Supported && I.Avail <= CLVer &&
+ (I.Core == ~0U || CLVer < I.Core);
+ }
+
+ void enable(StringRef Ext, bool V = true) {
+ OptMap[Ext].Enabled = V;
}
/// \brief Enable or disable support for OpenCL extensions
/// \param Ext name of the extension optionally prefixed with
/// '+' or '-'
/// \param Enable used when \p Ext is not prefixed by '+' or '-'
- void set(llvm::StringRef Ext, bool Enable = true) {
+ void support(StringRef Ext, bool V = true) {
assert(!Ext.empty() && "Extension is empty.");
switch (Ext[0]) {
case '+':
- Enable = true;
+ V = true;
Ext = Ext.drop_front();
break;
case '-':
- Enable = false;
+ V = false;
Ext = Ext.drop_front();
break;
}
if (Ext.equals("all")) {
- setAll(Enable);
+ supportAll(V);
return;
}
+ OptMap[Ext].Supported = V;
+ }
-#define OPENCLEXT(nm) \
- if (Ext.equals(#nm)) { \
- nm = Enable; \
- }
+ OpenCLOptions(){
+#define OPENCLEXT_INTERNAL(Ext, AvailVer, CoreVer) \
+ OptMap[#Ext].Avail = AvailVer; \
+ OptMap[#Ext].Core = CoreVer;
#include "clang/Basic/OpenCLExtensions.def"
}
- // Is supported with OpenCL version \p OCLVer.
-#define OPENCLEXT_INTERNAL(Ext, Avail, ...) \
- bool is_##Ext##_supported(unsigned OCLVer) const { \
- return Ext && OCLVer >= Avail; \
+ void addSupport(const OpenCLOptions &Opts) {
+ for (auto &I:Opts.OptMap)
+ if (I.second.Supported)
+ OptMap[I.getKey()].Supported = true;
+ }
+
+ void copy(const OpenCLOptions &Opts) {
+ OptMap = Opts.OptMap;
}
-#include "clang/Basic/OpenCLExtensions.def"
+ // Turn on or off support of all options.
+ void supportAll(bool On = true) {
+ for (llvm::StringMap<Info>::iterator I = OptMap.begin(),
+ E = OptMap.end(); I != E; ++I)
+ I->second.Supported = On;
+ }
- // Is supported OpenCL extension with OpenCL version \p OCLVer.
- // For supported optional core feature, return false.
-#define OPENCLEXT_INTERNAL(Ext, Avail, Core) \
- bool is_##Ext##_supported_extension(unsigned CLVer) const { \
- return is_##Ext##_supported(CLVer) && (Core == ~0U || CLVer < Core); \
+ void disableAll() {
+ for (llvm::StringMap<Info>::iterator I = OptMap.begin(),
+ E = OptMap.end(); I != E; ++I)
+ I->second.Enabled = false;
}
-#include "clang/Basic/OpenCLExtensions.def"
- // Is supported OpenCL core features with OpenCL version \p OCLVer.
- // For supported extension, return false.
-#define OPENCLEXT_INTERNAL(Ext, Avail, Core) \
- bool is_##Ext##_supported_core(unsigned CLVer) const { \
- return is_##Ext##_supported(CLVer) && Core != ~0U && CLVer >= Core; \
+ void enableSupportedCore(unsigned CLVer) {
+ for (llvm::StringMap<Info>::iterator I = OptMap.begin(),
+ E = OptMap.end(); I != E; ++I)
+ if (isSupportedCore(I->getKey(), CLVer))
+ I->second.Enabled = true;
}
-#include "clang/Basic/OpenCLExtensions.def"
+ friend class ASTWriter;
+ friend class ASTReader;
};
} // end namespace clang
diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h
index ec566f0642..dcd5a088df 100644
--- a/include/clang/Basic/TargetInfo.h
+++ b/include/clang/Basic/TargetInfo.h
@@ -1005,7 +1005,7 @@ public:
/// \brief Set supported OpenCL extensions as written on command line
virtual void setOpenCLExtensionOpts() {
for (const auto &Ext : getTargetOpts().OpenCLExtensionsAsWritten) {
- getTargetOpts().SupportedOpenCLOptions.set(Ext);
+ getTargetOpts().SupportedOpenCLOptions.support(Ext);
}
}
diff --git a/include/clang/Sema/Overload.h b/include/clang/Sema/Overload.h
index f677afe8e2..7c6699aca0 100644
--- a/include/clang/Sema/Overload.h
+++ b/include/clang/Sema/Overload.h
@@ -592,7 +592,10 @@ namespace clang {
ovl_fail_enable_if,
/// This candidate was not viable because its address could not be taken.
- ovl_fail_addr_not_available
+ ovl_fail_addr_not_available,
+
+ /// This candidate was not viable because its OpenCL extension is disabled.
+ ovl_fail_ext_disabled,
};
/// OverloadCandidate - A single candidate in an overload set (C++ 13.3).
diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h
index 42f03e5b80..2b54d5ee14 100644
--- a/include/clang/Sema/Sema.h
+++ b/include/clang/Sema/Sema.h
@@ -8051,6 +8051,58 @@ public:
void CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body);
//===--------------------------------------------------------------------===//
+ // OpenCL extensions.
+ //
+private:
+ std::string CurrOpenCLExtension;
+ /// Extensions required by an OpenCL type.
+ llvm::DenseMap<const Type*, std::set<std::string>> OpenCLTypeExtMap;
+ /// Extensions required by an OpenCL declaration.
+ llvm::DenseMap<const Decl*, std::set<std::string>> OpenCLDeclExtMap;
+public:
+ llvm::StringRef getCurrentOpenCLExtension() const {
+ return CurrOpenCLExtension;
+ }
+ void setCurrentOpenCLExtension(llvm::StringRef Ext) {
+ CurrOpenCLExtension = Ext;
+ }
+
+ /// \brief Set OpenCL extensions for a type which can only be used when these
+ /// OpenCL extensions are enabled. If \p Exts is empty, do nothing.
+ /// \param Exts A space separated list of OpenCL extensions.
+ void setOpenCLExtensionForType(QualType T, llvm::StringRef Exts);
+
+ /// \brief Set OpenCL extensions for a declaration which can only be
+ /// used when these OpenCL extensions are enabled. If \p Exts is empty, do
+ /// nothing.
+ /// \param Exts A space separated list of OpenCL extensions.
+ void setOpenCLExtensionForDecl(Decl *FD, llvm::StringRef Exts);
+
+ /// \brief Set current OpenCL extensions for a type which can only be used
+ /// when these OpenCL extensions are enabled. If current OpenCL extension is
+ /// empty, do nothing.
+ void setCurrentOpenCLExtensionForType(QualType T);
+
+ /// \brief Set current OpenCL extensions for a declaration which
+ /// can only be used when these OpenCL extensions are enabled. If current
+ /// OpenCL extension is empty, do nothing.
+ void setCurrentOpenCLExtensionForDecl(Decl *FD);
+
+ bool isOpenCLDisabledDecl(Decl *FD);
+
+ /// \brief Check if type \p T corresponding to declaration specifier \p DS
+ /// is disabled due to required OpenCL extensions being disabled. If so,
+ /// emit diagnostics.
+ /// \return true if type is disabled.
+ bool checkOpenCLDisabledTypeDeclSpec(const DeclSpec &DS, QualType T);
+
+ /// \brief Check if declaration \p D used by expression \p E
+ /// is disabled due to required OpenCL extensions being disabled. If so,
+ /// emit diagnostics.
+ /// \return true if type is disabled.
+ bool checkOpenCLDisabledDecl(const Decl &D, const Expr &E);
+
+ //===--------------------------------------------------------------------===//
// OpenMP directives and clauses.
//
private:
@@ -8066,6 +8118,21 @@ private:
/// Returns OpenMP nesting level for current directive.
unsigned getOpenMPNestingLevel() const;
+ /// Checks if a type or a declaration is disabled due to the owning extension
+ /// being disabled, and emits diagnostic messages if it is disabled.
+ /// \param D type or declaration to be checked.
+ /// \param DiagLoc source location for the diagnostic message.
+ /// \param DiagInfo information to be emitted for the diagnostic message.
+ /// \param SrcRange source range of the declaration.
+ /// \param Map maps type or declaration to the extensions.
+ /// \param Selector selects diagnostic message: 0 for type and 1 for
+ /// declaration.
+ /// \return true if the type or declaration is disabled.
+ template <typename T, typename DiagLocT, typename DiagInfoT, typename MapT>
+ bool checkOpenCLDisabledTypeOrDecl(T D, DiagLocT DiagLoc, DiagInfoT DiagInfo,
+ MapT &Map, unsigned Selector = 0,
+ SourceRange SrcRange = SourceRange());
+
public:
/// \brief Return true if the provided declaration \a VD should be captured by
/// reference.
diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h
index cdeb6b746b..611c00d0e9 100644
--- a/include/clang/Serialization/ASTBitCodes.h
+++ b/include/clang/Serialization/ASTBitCodes.h
@@ -344,7 +344,7 @@ namespace clang {
///
/// The TYPE_OFFSET constant describes the record that occurs
/// within the AST block. The record itself is an array of offsets that
- /// point into the declarations and types block (identified by
+ /// point into the declarations and types block (identified by
/// DECLTYPES_BLOCK_ID). The index into the array is based on the ID
/// of a type. For a given type ID @c T, the lower three bits of
/// @c T are its qualifiers (const, volatile, restrict), as in
@@ -446,10 +446,10 @@ namespace clang {
/// \brief Record code for the set of ext_vector type names.
EXT_VECTOR_DECLS = 16,
-
+
/// \brief Record code for the array of unused file scoped decls.
UNUSED_FILESCOPED_DECLS = 17,
-
+
/// \brief Record code for the table of offsets to entries in the
/// preprocessing record.
PPD_ENTITIES_OFFSETS = 18,
@@ -465,7 +465,7 @@ namespace clang {
/// \brief Record code for an update to the TU's lexically contained
/// declarations.
TU_UPDATE_LEXICAL = 22,
-
+
// ID 23 used to be for a list of local redeclarations.
/// \brief Record code for declarations that Sema keeps references of.
@@ -490,7 +490,7 @@ namespace clang {
// ID 30 used to be a decl update record. These are now in the DECLTYPES
// block.
-
+
// ID 31 used to be a list of offsets to DECL_CXX_BASE_SPECIFIERS records.
/// \brief Record code for \#pragma diagnostic mappings.
@@ -498,7 +498,7 @@ namespace clang {
/// \brief Record code for special CUDA declarations.
CUDA_SPECIAL_DECL_REFS = 33,
-
+
/// \brief Record code for header search information.
HEADER_SEARCH_TABLE = 34,
@@ -516,7 +516,7 @@ namespace clang {
KNOWN_NAMESPACES = 38,
/// \brief Record code for the remapping information used to relate
- /// loaded modules to the various offsets and IDs(e.g., source location
+ /// loaded modules to the various offsets and IDs(e.g., source location
/// offests, declaration and type IDs) that are used in that module to
/// refer to other modules.
MODULE_OFFSET_MAP = 39,
@@ -525,20 +525,20 @@ namespace clang {
/// which stores information about \#line directives.
SOURCE_MANAGER_LINE_TABLE = 40,
- /// \brief Record code for map of Objective-C class definition IDs to the
+ /// \brief Record code for map of Objective-C class definition IDs to the
/// ObjC categories in a module that are attached to that class.
OBJC_CATEGORIES_MAP = 41,
/// \brief Record code for a file sorted array of DeclIDs in a module.
FILE_SORTED_DECLS = 42,
-
+
/// \brief Record code for an array of all of the (sub)modules that were
/// imported by the AST file.
IMPORTED_MODULES = 43,
-
+
// ID 44 used to be a table of merged canonical declarations.
// ID 45 used to be a list of declaration IDs of local redeclarations.
-
+
/// \brief Record code for the array of Objective-C categories (including
/// extensions).
///
@@ -585,6 +585,12 @@ namespace clang {
/// \brief Number of unmatched #pragma clang cuda_force_host_device begin
/// directives we've seen.
CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH = 57,
+
+ /// \brief Record code for types associated with OpenCL extensions.
+ OPENCL_EXTENSION_TYPES = 58,
+
+ /// \brief Record code for declarations associated with OpenCL extensions.
+ OPENCL_EXTENSION_DECLS = 59,
};
/// \brief Record types used within a source manager block.
diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h
index 6f1a6ace62..57a504cc32 100644
--- a/include/clang/Serialization/ASTReader.h
+++ b/include/clang/Serialization/ASTReader.h
@@ -807,7 +807,13 @@ private:
SourceLocation PointersToMembersPragmaLocation;
/// \brief The OpenCL extension settings.
- SmallVector<uint64_t, 1> OpenCLExtensions;
+ OpenCLOptions OpenCLExtensions;
+
+ /// \brief Extensions required by an OpenCL type.
+ llvm::DenseMap<const Type *, std::set<std::string>> OpenCLTypeExtMap;
+
+ /// \brief Extensions required by an OpenCL declaration.
+ llvm::DenseMap<const Decl *, std::set<std::string>> OpenCLDeclExtMap;
/// \brief A list of the namespaces we've seen.
SmallVector<uint64_t, 4> KnownNamespaces;
diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h
index 2462900cf8..1469555ec2 100644
--- a/include/clang/Serialization/ASTWriter.h
+++ b/include/clang/Serialization/ASTWriter.h
@@ -459,6 +459,8 @@ private:
void WriteDeclContextVisibleUpdate(const DeclContext *DC);
void WriteFPPragmaOptions(const FPOptions &Opts);
void WriteOpenCLExtensions(Sema &SemaRef);
+ void WriteOpenCLExtensionTypes(Sema &SemaRef);
+ void WriteOpenCLExtensionDecls(Sema &SemaRef);
void WriteCUDAPragmas(Sema &SemaRef);
void WriteObjCCategories();
void WriteLateParsedTemplates(Sema &SemaRef);