[clang] 3549466 - [OpenCL] Drop pragma handling for extension types/decls.
Anastasia Stulova via cfe-commits
cfe-commits at lists.llvm.org
Mon May 17 04:11:49 PDT 2021
Author: Anastasia Stulova
Date: 2021-05-17T12:09:43+01:00
New Revision: 3549466ac05eda57c9ce13abd7cb6dd365f6d8d6
URL: https://github.com/llvm/llvm-project/commit/3549466ac05eda57c9ce13abd7cb6dd365f6d8d6
DIFF: https://github.com/llvm/llvm-project/commit/3549466ac05eda57c9ce13abd7cb6dd365f6d8d6.diff
LOG: [OpenCL] Drop pragma handling for extension types/decls.
Drop non-conformant extension pragma implementation as
it does not properly disable anything and therefore
enabling non-disabled logic has no meaning.
This simplifies clang code and user interface to the extension
functionality. With this patch extension pragma 'begin'/'end'
and 'enable'/'disable' are only accepted for backward
compatibility and no longer have any default behavior.
Differential Revision: https://reviews.llvm.org/D101043
Added:
Modified:
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Overload.h
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTWriter.h
clang/lib/Parse/ParsePragma.cpp
clang/lib/Parse/Parser.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/SemaOpenCL/extension-begin.cl
clang/test/SemaOpenCL/extension-begin.h
Removed:
clang/test/CodeGenOpenCL/extension-begin.cl
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 9a3f7adc619ba..97cb7020f3452 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1239,8 +1239,6 @@ def warn_pragma_expected_colon : Warning<
"missing ':' after %0 - 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/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0683469506e9b..9dd9b1b5118b5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4372,8 +4372,6 @@ def warn_diagnose_if_succeeded : Warning<"%0">, InGroup<UserDefinedWarnings>,
ShowInSystemHeader;
def note_ovl_candidate_disabled_by_function_cond_attr : Note<
"candidate disabled: %0">;
-def note_ovl_candidate_disabled_by_extension : Note<
- "candidate unavailable as it requires OpenCL extension '%0' to be enabled">;
def err_addrof_function_disabled_by_enable_if_attr : Error<
"cannot take address of function %0 because it has one or more "
"non-tautological enable_if conditions">;
diff --git a/clang/include/clang/Sema/Overload.h b/clang/include/clang/Sema/Overload.h
index 5be6a618711cd..699c3e8088726 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -760,9 +760,6 @@ class Sema;
/// This candidate was not viable because its address could not be taken.
ovl_fail_addr_not_available,
- /// This candidate was not viable because its OpenCL extension is disabled.
- ovl_fail_ext_disabled,
-
/// This inherited constructor is not viable because it would slice the
/// argument.
ovl_fail_inhctor_slice,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 135da703c4df9..3a8f41196cc4a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10142,73 +10142,6 @@ class Sema final {
/// potentially-throwing.
bool checkFinalSuspendNoThrow(const Stmt *FinalSuspend);
- //===--------------------------------------------------------------------===//
- // 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;
- }
-
- /// Check if a function declaration \p FD associates with any
- /// extensions present in OpenCLDeclExtMap and if so return the
- /// extension(s) name(s).
- std::string getOpenCLExtensionsFromDeclExtMap(FunctionDecl *FD);
-
- /// Check if a function type \p FT associates with any
- /// extensions present in OpenCLTypeExtMap and if so return the
- /// extension(s) name(s).
- std::string getOpenCLExtensionsFromTypeExtMap(FunctionType *FT);
-
- /// Find an extension in an appropriate extension map and return its name
- template<typename T, typename MapT>
- std::string getOpenCLExtensionsFromExtMap(T* FT, MapT &Map);
-
- void setCurrentOpenCLExtension(llvm::StringRef Ext) {
- CurrOpenCLExtension = std::string(Ext);
- }
-
- /// 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);
-
- /// 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);
-
- /// 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);
-
- /// 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);
-
- /// 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);
-
- /// 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 NamedDecl &D, const Expr &E);
-
//===--------------------------------------------------------------------===//
// OpenMP directives and clauses.
//
@@ -10262,21 +10195,6 @@ class Sema final {
/// Pop OpenMP function region for non-capturing function.
void popOpenMPFunctionRegion(const sema::FunctionScopeInfo *OldFSI);
- /// 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());
-
/// Helper to keep information about the current `omp begin/end declare
/// variant` nesting.
struct OMPDeclareVariantScope {
diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h
index ea67d6990a8a0..30f5e49c4e628 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -510,8 +510,6 @@ class ASTWriter : public ASTDeserializationListener,
void WriteDeclContextVisibleUpdate(const DeclContext *DC);
void WriteFPPragmaOptions(const FPOptionsOverride &Opts);
void WriteOpenCLExtensions(Sema &SemaRef);
- void WriteOpenCLExtensionTypes(Sema &SemaRef);
- void WriteOpenCLExtensionDecls(Sema &SemaRef);
void WriteCUDAPragmas(Sema &SemaRef);
void WriteObjCCategories();
void WriteLateParsedTemplates(Sema &SemaRef);
diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 660d317f57d07..42072fe63fc88 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -792,11 +792,9 @@ void Parser::HandlePragmaOpenCLExtension() {
// Therefore, it should never be added by default.
Opt.acceptsPragma(Name);
}
- Actions.setCurrentOpenCLExtension(Name);
} else if (State == End) {
- if (Name != Actions.getCurrentOpenCLExtension())
- PP.Diag(NameLoc, diag::warn_pragma_begin_end_mismatch);
- Actions.setCurrentOpenCLExtension("");
+ // There is no behavior for this directive. We only accept this for
+ // backward compatibility.
} else if (!Opt.isKnown(Name) || !Opt.isWithPragma(Name))
PP.Diag(NameLoc, diag::warn_pragma_unknown_extension) << Ident;
else if (Opt.isSupportedExtension(Name, getLangOpts()))
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 1ae3ed4ff0d39..389180ea01f7d 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -1081,8 +1081,6 @@ Parser::ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange &attrs,
Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS_none,
DS, AnonRecord);
DS.complete(TheDecl);
- if (getLangOpts().OpenCL)
- Actions.setCurrentOpenCLExtensionForDecl(TheDecl);
if (AnonRecord) {
Decl* decls[] = {AnonRecord, TheDecl};
return Actions.BuildDeclaratorGroup(decls);
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 36fcadfc9b9b7..d84315f08d1e7 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -369,7 +369,6 @@ void Sema::Initialize() {
#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
if (getOpenCLOptions().isSupported(#Ext, getLangOpts())) { \
addImplicitTypedef(#ExtType, Context.Id##Ty); \
- setOpenCLExtensionForType(Context.Id##Ty, #Ext); \
}
#include "clang/Basic/OpenCLExtensionTypes.def"
}
@@ -2467,115 +2466,3 @@ const llvm::MapVector<FieldDecl *, Sema::DeleteLocs> &
Sema::getMismatchingDeleteExpressions() const {
return DeleteExprs;
}
-
-void Sema::setOpenCLExtensionForType(QualType T, llvm::StringRef ExtStr) {
- if (ExtStr.empty())
- return;
- llvm::SmallVector<StringRef, 1> Exts;
- ExtStr.split(Exts, " ", /* limit */ -1, /* keep empty */ false);
- auto CanT = T.getCanonicalType().getTypePtr();
- for (auto &I : Exts)
- OpenCLTypeExtMap[CanT].insert(I.str());
-}
-
-void Sema::setOpenCLExtensionForDecl(Decl *FD, StringRef ExtStr) {
- llvm::SmallVector<StringRef, 1> Exts;
- ExtStr.split(Exts, " ", /* limit */ -1, /* keep empty */ false);
- if (Exts.empty())
- return;
- for (auto &I : Exts)
- OpenCLDeclExtMap[FD].insert(I.str());
-}
-
-void Sema::setCurrentOpenCLExtensionForType(QualType T) {
- if (CurrOpenCLExtension.empty())
- return;
- setOpenCLExtensionForType(T, CurrOpenCLExtension);
-}
-
-void Sema::setCurrentOpenCLExtensionForDecl(Decl *D) {
- if (CurrOpenCLExtension.empty())
- return;
- setOpenCLExtensionForDecl(D, CurrOpenCLExtension);
-}
-
-std::string Sema::getOpenCLExtensionsFromDeclExtMap(FunctionDecl *FD) {
- if (!OpenCLDeclExtMap.empty())
- return getOpenCLExtensionsFromExtMap(FD, OpenCLDeclExtMap);
-
- return "";
-}
-
-std::string Sema::getOpenCLExtensionsFromTypeExtMap(FunctionType *FT) {
- if (!OpenCLTypeExtMap.empty())
- return getOpenCLExtensionsFromExtMap(FT, OpenCLTypeExtMap);
-
- return "";
-}
-
-template <typename T, typename MapT>
-std::string Sema::getOpenCLExtensionsFromExtMap(T *FDT, MapT &Map) {
- auto Loc = Map.find(FDT);
- return llvm::join(Loc->second, " ");
-}
-
-bool Sema::isOpenCLDisabledDecl(Decl *FD) {
- auto Loc = OpenCLDeclExtMap.find(FD);
- if (Loc == OpenCLDeclExtMap.end())
- return false;
- for (auto &I : Loc->second) {
- if (!getOpenCLOptions().isAvailableOption(I, getLangOpts()))
- return true;
- }
- return false;
-}
-
-template <typename T, typename DiagLocT, typename DiagInfoT, typename MapT>
-bool Sema::checkOpenCLDisabledTypeOrDecl(T D, DiagLocT DiagLoc,
- DiagInfoT DiagInfo, MapT &Map,
- unsigned Selector,
- SourceRange SrcRange) {
- auto Loc = Map.find(D);
- if (Loc == Map.end())
- return false;
- bool Disabled = false;
- for (auto &I : Loc->second) {
- if (I != CurrOpenCLExtension &&
- !getOpenCLOptions().isAvailableOption(I, getLangOpts())) {
- Diag(DiagLoc, diag::err_opencl_requires_extension) << Selector << DiagInfo
- << I << SrcRange;
- Disabled = true;
- }
- }
- return Disabled;
-}
-
-bool Sema::checkOpenCLDisabledTypeDeclSpec(const DeclSpec &DS, QualType QT) {
- // Check extensions for declared types.
- Decl *Decl = nullptr;
- if (auto TypedefT = dyn_cast<TypedefType>(QT.getTypePtr()))
- Decl = TypedefT->getDecl();
- if (auto TagT = dyn_cast<TagType>(QT.getCanonicalType().getTypePtr()))
- Decl = TagT->getDecl();
- auto Loc = DS.getTypeSpecTypeLoc();
-
- // Check extensions for vector types.
- // e.g. double4 is not allowed when cl_khr_fp64 is absent.
- if (QT->isExtVectorType()) {
- auto TypePtr = QT->castAs<ExtVectorType>()->getElementType().getTypePtr();
- return checkOpenCLDisabledTypeOrDecl(TypePtr, Loc, QT, OpenCLTypeExtMap);
- }
-
- if (checkOpenCLDisabledTypeOrDecl(Decl, Loc, QT, OpenCLDeclExtMap))
- return true;
-
- // Check extensions for builtin types.
- return checkOpenCLDisabledTypeOrDecl(QT.getCanonicalType().getTypePtr(), Loc,
- QT, OpenCLTypeExtMap);
-}
-
-bool Sema::checkOpenCLDisabledDecl(const NamedDecl &D, const Expr &E) {
- IdentifierInfo *FnName = D.getIdentifier();
- return checkOpenCLDisabledTypeOrDecl(&D, E.getBeginLoc(), FnName,
- OpenCLDeclExtMap, 1, D.getSourceRange());
-}
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fdb2086669b69..db267089be965 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5579,9 +5579,6 @@ Decl *Sema::ActOnDeclarator(Scope *S, Declarator &D) {
Dcl && Dcl->getDeclContext()->isFileContext())
Dcl->setTopLevelDeclInObjCContainer();
- if (getLangOpts().OpenCL)
- setCurrentOpenCLExtensionForDecl(Dcl);
-
return Dcl;
}
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 6e20eb5b99dde..948d5eddb43b3 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6488,9 +6488,6 @@ ExprResult Sema::BuildCallExpr(Scope *Scope, Expr *Fn, SourceLocation LParenLoc,
FD, /*Complain=*/true, Fn->getBeginLoc()))
return ExprError();
- if (getLangOpts().OpenCL && checkOpenCLDisabledDecl(*FD, *Fn))
- return ExprError();
-
checkDirectCallValidity(*this, Fn, FD, ArgExprs);
}
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 179da2ac26d77..95d6a9f3c8365 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6482,12 +6482,6 @@ void Sema::AddOverloadCandidate(
Candidate.DeductionFailure.Data = FailedAttr;
return;
}
-
- if (LangOpts.OpenCL && isOpenCLDisabledDecl(Function)) {
- Candidate.Viable = false;
- Candidate.FailureKind = ovl_fail_ext_disabled;
- return;
- }
}
ObjCMethodDecl *
@@ -11092,14 +11086,6 @@ static void DiagnoseFailedExplicitSpec(Sema &S, OverloadCandidate *Cand) {
<< (ES.getExpr() ? ES.getExpr()->getSourceRange() : SourceRange());
}
-static void DiagnoseOpenCLExtensionDisabled(Sema &S, OverloadCandidate *Cand) {
- FunctionDecl *Callee = Cand->Function;
-
- S.Diag(Callee->getLocation(),
- diag::note_ovl_candidate_disabled_by_extension)
- << S.getOpenCLExtensionsFromDeclExtMap(Callee);
-}
-
/// Generates a 'note' diagnostic for an overload candidate. We've
/// already generated a primary error at the call site.
///
@@ -11195,9 +11181,6 @@ static void NoteFunctionCandidate(Sema &S, OverloadCandidate *Cand,
case ovl_fail_explicit:
return DiagnoseFailedExplicitSpec(S, Cand);
- case ovl_fail_ext_disabled:
- return DiagnoseOpenCLExtensionDisabled(S, Cand);
-
case ovl_fail_inhctor_slice:
// It's generally not interesting to note copy/move constructors here.
if (cast<CXXConstructorDecl>(Fn)->isCopyOrMoveConstructor())
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index e1c5d3367425f..bb8e3f4f7f0dd 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1727,10 +1727,6 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
declarator.setInvalidType();
}
- if (S.getLangOpts().OpenCL &&
- S.checkOpenCLDisabledTypeDeclSpec(DS, Result))
- declarator.setInvalidType(true);
-
bool IsFixedPointType = DS.getTypeSpecType() == DeclSpec::TST_accum ||
DS.getTypeSpecType() == DeclSpec::TST_fract;
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 60f3b87106a72..eb635b25480be 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -3635,30 +3635,6 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
}
break;
- case OPENCL_EXTENSION_TYPES:
- for (unsigned I = 0, E = Record.size(); I != E;) {
- auto TypeID = static_cast<::TypeID>(Record[I++]);
- auto *Type = GetType(TypeID).getTypePtr();
- auto NumExt = static_cast<unsigned>(Record[I++]);
- for (unsigned II = 0; II != NumExt; ++II) {
- auto Ext = ReadString(Record, I);
- OpenCLTypeExtMap[Type].insert(Ext);
- }
- }
- break;
-
- case OPENCL_EXTENSION_DECLS:
- for (unsigned I = 0, E = Record.size(); I != E;) {
- auto DeclID = static_cast<::DeclID>(Record[I++]);
- auto *Decl = GetDecl(DeclID);
- auto NumExt = static_cast<unsigned>(Record[I++]);
- for (unsigned II = 0; II != NumExt; ++II) {
- auto Ext = ReadString(Record, I);
- OpenCLDeclExtMap[Decl].insert(Ext);
- }
- }
- break;
-
case TENTATIVE_DEFINITIONS:
for (unsigned I = 0, N = Record.size(); I != N; ++I)
TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I]));
@@ -7894,8 +7870,6 @@ void ASTReader::InitializeSema(Sema &S) {
}
SemaObj->OpenCLFeatures = OpenCLExtensions;
- SemaObj->OpenCLTypeExtMap = OpenCLTypeExtMap;
- SemaObj->OpenCLDeclExtMap = OpenCLDeclExtMap;
UpdateSema();
}
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index daa0b54d1b320..267a0785bd109 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -3965,72 +3965,6 @@ void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) {
}
Stream.EmitRecord(OPENCL_EXTENSIONS, Record);
}
-
-void ASTWriter::WriteOpenCLExtensionTypes(Sema &SemaRef) {
- if (!SemaRef.Context.getLangOpts().OpenCL)
- return;
-
- // Sort the elements of the map OpenCLTypeExtMap by TypeIDs,
- // without copying them.
- const llvm::DenseMap<const Type *, std::set<std::string>> &OpenCLTypeExtMap =
- SemaRef.OpenCLTypeExtMap;
- using ElementTy = std::pair<TypeID, const std::set<std::string> *>;
- llvm::SmallVector<ElementTy, 8> StableOpenCLTypeExtMap;
- StableOpenCLTypeExtMap.reserve(OpenCLTypeExtMap.size());
-
- for (const auto &I : OpenCLTypeExtMap)
- StableOpenCLTypeExtMap.emplace_back(
- getTypeID(I.first->getCanonicalTypeInternal()), &I.second);
-
- auto CompareByTypeID = [](const ElementTy &E1, const ElementTy &E2) -> bool {
- return E1.first < E2.first;
- };
- llvm::sort(StableOpenCLTypeExtMap, CompareByTypeID);
-
- RecordData Record;
- for (const ElementTy &E : StableOpenCLTypeExtMap) {
- Record.push_back(E.first); // TypeID
- const std::set<std::string> *ExtSet = E.second;
- Record.push_back(static_cast<unsigned>(ExtSet->size()));
- for (const std::string &Ext : *ExtSet)
- AddString(Ext, Record);
- }
-
- Stream.EmitRecord(OPENCL_EXTENSION_TYPES, Record);
-}
-
-void ASTWriter::WriteOpenCLExtensionDecls(Sema &SemaRef) {
- if (!SemaRef.Context.getLangOpts().OpenCL)
- return;
-
- // Sort the elements of the map OpenCLDeclExtMap by DeclIDs,
- // without copying them.
- const llvm::DenseMap<const Decl *, std::set<std::string>> &OpenCLDeclExtMap =
- SemaRef.OpenCLDeclExtMap;
- using ElementTy = std::pair<DeclID, const std::set<std::string> *>;
- llvm::SmallVector<ElementTy, 8> StableOpenCLDeclExtMap;
- StableOpenCLDeclExtMap.reserve(OpenCLDeclExtMap.size());
-
- for (const auto &I : OpenCLDeclExtMap)
- StableOpenCLDeclExtMap.emplace_back(getDeclID(I.first), &I.second);
-
- auto CompareByDeclID = [](const ElementTy &E1, const ElementTy &E2) -> bool {
- return E1.first < E2.first;
- };
- llvm::sort(StableOpenCLDeclExtMap, CompareByDeclID);
-
- RecordData Record;
- for (const ElementTy &E : StableOpenCLDeclExtMap) {
- Record.push_back(E.first); // DeclID
- const std::set<std::string> *ExtSet = E.second;
- Record.push_back(static_cast<unsigned>(ExtSet->size()));
- for (const std::string &Ext : *ExtSet)
- AddString(Ext, Record);
- }
-
- Stream.EmitRecord(OPENCL_EXTENSION_DECLS, Record);
-}
-
void ASTWriter::WriteCUDAPragmas(Sema &SemaRef) {
if (SemaRef.ForceCUDAHostDeviceDepth > 0) {
RecordData::value_type Record[] = {SemaRef.ForceCUDAHostDeviceDepth};
@@ -4775,17 +4709,12 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot,
WriteIdentifierTable(PP, SemaRef.IdResolver, isModule);
WriteFPPragmaOptions(SemaRef.CurFPFeatureOverrides());
WriteOpenCLExtensions(SemaRef);
- WriteOpenCLExtensionTypes(SemaRef);
WriteCUDAPragmas(SemaRef);
// If we're emitting a module, write out the submodule information.
if (WritingModule)
WriteSubmodules(WritingModule);
- // We need to have information about submodules to correctly deserialize
- // decls from OpenCLExtensionDecls block
- WriteOpenCLExtensionDecls(SemaRef);
-
Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes);
// Write the record containing external, unnamed definitions.
diff --git a/clang/test/CodeGenOpenCL/extension-begin.cl b/clang/test/CodeGenOpenCL/extension-begin.cl
deleted file mode 100644
index 89b4256b2b114..0000000000000
--- a/clang/test/CodeGenOpenCL/extension-begin.cl
+++ /dev/null
@@ -1,25 +0,0 @@
-// RUN: %clang_cc1 %s -triple spir-unknown-unknown -emit-llvm -o - | FileCheck %s
-
-__attribute__((overloadable)) void f(int x);
-
-#pragma OPENCL EXTENSION my_ext : begin
-
-__attribute__((overloadable)) void f(long x);
-
-#pragma OPENCL EXTENSION my_ext : end
-
-#pragma OPENCL EXTENSION my_ext : enable
-
-//CHECK: define{{.*}} spir_func void @test_f1(i64 %x)
-//CHECK: call spir_func void @_Z1fl(i64 %{{.*}})
-void test_f1(long x) {
- f(x);
-}
-
-#pragma OPENCL EXTENSION my_ext : disable
-
-//CHECK: define{{.*}} spir_func void @test_f2(i64 %x)
-//CHECK: call spir_func void @_Z1fi(i32 %{{.*}})
-void test_f2(long x) {
- f(x);
-}
diff --git a/clang/test/SemaOpenCL/extension-begin.cl b/clang/test/SemaOpenCL/extension-begin.cl
index f1f0de084cefd..9124ceba4e2a2 100644
--- a/clang/test/SemaOpenCL/extension-begin.cl
+++ b/clang/test/SemaOpenCL/extension-begin.cl
@@ -29,25 +29,23 @@
#ifndef USE_PCH
// expected-warning at extension-begin.h:4 {{expected 'disable' - ignoring}}
// expected-warning at extension-begin.h:5 {{expected 'disable' - ignoring}}
-// expected-warning at extension-begin.h:21 {{OpenCL extension end directive mismatches begin directive - ignoring}}
#endif // USE_PCH
+#if defined(IMPLICIT_INCLUDE) && defined(USE_PCH)
+//expected-no-diagnostics
+#endif
+
+// Tests that the pragmas are accepted for backward compatibility.
#pragma OPENCL EXTENSION my_ext : enable
-void test_f1(void) {
+#pragma OPENCL EXTENSION my_ext : disable
+
+#ifndef my_ext
+#error "Missing my_ext macro"
+#endif
+
+// When extension is supported its functionality can be used freely.
+void test(void) {
struct A test_A1;
f();
g(0);
}
-
-#pragma OPENCL EXTENSION my_ext : disable
-void test_f2(void) {
- struct A test_A2; // expected-error {{use of type 'struct A' requires my_ext support}}
- const struct A test_A_local; // expected-error {{use of type 'struct A' requires my_ext support}}
- TypedefOfA test_typedef_A; // expected-error {{use of type 'TypedefOfA' (aka 'struct A') requires my_ext support}}
- PointerOfA test_A_pointer; // expected-error {{use of type 'PointerOfA' (aka 'const __private struct A *') requires my_ext support}}
- f(); // expected-error {{use of declaration 'f' requires my_ext support}}
- g(0); // expected-error {{no matching function for call to 'g'}}
- // expected-note at extension-begin.h:18 {{candidate unavailable as it requires OpenCL extension 'my_ext' to be enabled}}
- // expected-note at extension-begin.h:23 {{candidate function not viable: requires 0 arguments, but 1 was provided}}
-}
-
diff --git a/clang/test/SemaOpenCL/extension-begin.h b/clang/test/SemaOpenCL/extension-begin.h
index d9865ba0b33a4..0e262e4adb937 100644
--- a/clang/test/SemaOpenCL/extension-begin.h
+++ b/clang/test/SemaOpenCL/extension-begin.h
@@ -5,10 +5,13 @@
#pragma OPENCL EXTENSION all : end
#pragma OPENCL EXTENSION my_ext : begin
-
struct A {
int a;
};
+#pragma OPENCL EXTENSION my_ext : end
+#pragma OPENCL EXTENSION my_ext : end
+
+#define my_ext
typedef struct A TypedefOfA;
typedef const __private TypedefOfA* PointerOfA;
@@ -17,10 +20,8 @@ void f(void);
__attribute__((overloadable)) void g(long x);
-#pragma OPENCL EXTENSION my_ext : end
-#pragma OPENCL EXTENSION my_ext : end
+
__attribute__((overloadable)) void g(void);
#endif // INCLUDED
-
More information about the cfe-commits
mailing list