Skip to content

Commit e57cf6c

Browse files
committed
Merging r353431:
------------------------------------------------------------------------ r353431 | stulova | 2019-02-07 18:32:37 +0100 (Thu, 07 Feb 2019) | 9 lines [OpenCL][PR40603] In C++ preserve compatibility with OpenCL C v2.0 Valid OpenCL C code should still compile in C++ mode. This change enables extensions and OpenCL types. Differential Revision: https://reviews.llvm.org/D57824 ------------------------------------------------------------------------ llvm-svn: 353826
1 parent df368fd commit e57cf6c

File tree

6 files changed

+92
-83
lines changed

6 files changed

+92
-83
lines changed

clang/include/clang/Basic/OpenCLOptions.h

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef LLVM_CLANG_BASIC_OPENCLOPTIONS_H
1616
#define LLVM_CLANG_BASIC_OPENCLOPTIONS_H
1717

18+
#include "clang/Basic/LangOptions.h"
1819
#include "llvm/ADT/StringMap.h"
1920

2021
namespace clang {
@@ -42,25 +43,29 @@ class OpenCLOptions {
4243

4344
// Is supported as either an extension or an (optional) core feature for
4445
// OpenCL version \p CLVer.
45-
bool isSupported(llvm::StringRef Ext, unsigned CLVer) const {
46+
bool isSupported(llvm::StringRef Ext, LangOptions LO) const {
47+
// In C++ mode all extensions should work at least as in v2.0.
48+
auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion;
4649
auto I = OptMap.find(Ext)->getValue();
4750
return I.Supported && I.Avail <= CLVer;
4851
}
4952

5053
// Is supported (optional) OpenCL core features for OpenCL version \p CLVer.
5154
// For supported extension, return false.
52-
bool isSupportedCore(llvm::StringRef Ext, unsigned CLVer) const {
55+
bool isSupportedCore(llvm::StringRef Ext, LangOptions LO) const {
56+
// In C++ mode all extensions should work at least as in v2.0.
57+
auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion;
5358
auto I = OptMap.find(Ext)->getValue();
54-
return I.Supported && I.Avail <= CLVer &&
55-
I.Core != ~0U && CLVer >= I.Core;
59+
return I.Supported && I.Avail <= CLVer && I.Core != ~0U && CLVer >= I.Core;
5660
}
5761

5862
// Is supported OpenCL extension for OpenCL version \p CLVer.
5963
// For supported (optional) core feature, return false.
60-
bool isSupportedExtension(llvm::StringRef Ext, unsigned CLVer) const {
64+
bool isSupportedExtension(llvm::StringRef Ext, LangOptions LO) const {
65+
// In C++ mode all extensions should work at least as in v2.0.
66+
auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion;
6167
auto I = OptMap.find(Ext)->getValue();
62-
return I.Supported && I.Avail <= CLVer &&
63-
(I.Core == ~0U || CLVer < I.Core);
68+
return I.Supported && I.Avail <= CLVer && (I.Core == ~0U || CLVer < I.Core);
6469
}
6570

6671
void enable(llvm::StringRef Ext, bool V = true) {
@@ -122,17 +127,17 @@ class OpenCLOptions {
122127
I->second.Enabled = false;
123128
}
124129

125-
void enableSupportedCore(unsigned CLVer) {
126-
for (llvm::StringMap<Info>::iterator I = OptMap.begin(),
127-
E = OptMap.end(); I != E; ++I)
128-
if (isSupportedCore(I->getKey(), CLVer))
130+
void enableSupportedCore(LangOptions LO) {
131+
for (llvm::StringMap<Info>::iterator I = OptMap.begin(), E = OptMap.end();
132+
I != E; ++I)
133+
if (isSupportedCore(I->getKey(), LO))
129134
I->second.Enabled = true;
130135
}
131136

132137
friend class ASTWriter;
133138
friend class ASTReader;
134139
};
135140

136-
} // end namespace clang
141+
} // end namespace clang
137142

138143
#endif

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,10 +1059,9 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
10591059

10601060
// OpenCL definitions.
10611061
if (LangOpts.OpenCL) {
1062-
#define OPENCLEXT(Ext) \
1063-
if (TI.getSupportedOpenCLOpts().isSupported(#Ext, \
1064-
LangOpts.OpenCLVersion)) \
1065-
Builder.defineMacro(#Ext);
1062+
#define OPENCLEXT(Ext) \
1063+
if (TI.getSupportedOpenCLOpts().isSupported(#Ext, LangOpts)) \
1064+
Builder.defineMacro(#Ext);
10661065
#include "clang/Basic/OpenCLExtensions.def"
10671066

10681067
auto Arch = TI.getTriple().getArch();

clang/lib/Parse/ParsePragma.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -693,13 +693,12 @@ void Parser::HandlePragmaOpenCLExtension() {
693693
if (Name == "all") {
694694
if (State == Disable) {
695695
Opt.disableAll();
696-
Opt.enableSupportedCore(getLangOpts().OpenCLVersion);
696+
Opt.enableSupportedCore(getLangOpts());
697697
} else {
698698
PP.Diag(NameLoc, diag::warn_pragma_expected_predicate) << 1;
699699
}
700700
} else if (State == Begin) {
701-
if (!Opt.isKnown(Name) ||
702-
!Opt.isSupported(Name, getLangOpts().OpenCLVersion)) {
701+
if (!Opt.isKnown(Name) || !Opt.isSupported(Name, getLangOpts())) {
703702
Opt.support(Name);
704703
}
705704
Actions.setCurrentOpenCLExtension(Name);
@@ -709,9 +708,9 @@ void Parser::HandlePragmaOpenCLExtension() {
709708
Actions.setCurrentOpenCLExtension("");
710709
} else if (!Opt.isKnown(Name))
711710
PP.Diag(NameLoc, diag::warn_pragma_unknown_extension) << Ident;
712-
else if (Opt.isSupportedExtension(Name, getLangOpts().OpenCLVersion))
711+
else if (Opt.isSupportedExtension(Name, getLangOpts()))
713712
Opt.enable(Name, State == Enable);
714-
else if (Opt.isSupportedCore(Name, getLangOpts().OpenCLVersion))
713+
else if (Opt.isSupportedCore(Name, getLangOpts()))
715714
PP.Diag(NameLoc, diag::warn_pragma_extension_is_core) << Ident;
716715
else
717716
PP.Diag(NameLoc, diag::warn_pragma_unsupported_extension) << Ident;

clang/lib/Sema/Sema.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,12 @@ void Sema::Initialize() {
256256
// Initialize predefined OpenCL types and supported extensions and (optional)
257257
// core features.
258258
if (getLangOpts().OpenCL) {
259-
getOpenCLOptions().addSupport(Context.getTargetInfo().getSupportedOpenCLOpts());
260-
getOpenCLOptions().enableSupportedCore(getLangOpts().OpenCLVersion);
259+
getOpenCLOptions().addSupport(
260+
Context.getTargetInfo().getSupportedOpenCLOpts());
261+
getOpenCLOptions().enableSupportedCore(getLangOpts());
261262
addImplicitTypedef("sampler_t", Context.OCLSamplerTy);
262263
addImplicitTypedef("event_t", Context.OCLEventTy);
263-
if (getLangOpts().OpenCLVersion >= 200) {
264+
if (getLangOpts().OpenCLCPlusPlus || getLangOpts().OpenCLVersion >= 200) {
264265
addImplicitTypedef("clk_event_t", Context.OCLClkEventTy);
265266
addImplicitTypedef("queue_t", Context.OCLQueueTy);
266267
addImplicitTypedef("reserve_id_t", Context.OCLReserveIDTy);

0 commit comments

Comments
 (0)