Skip to content

Commit a5b627a

Browse files
committed
[OpenCL] Introduce new language options for OpenCL keywords.
OpenCL keywords 'pipe' and 'generic' are unconditionally supported for OpenCL C 2.0 or in OpenCL C++ mode. In OpenCL C 3.0 these keywords are available if corresponding optional core feature is supported. Reviewed By: Anastasia, svenvh Differential Revision: https://reviews.llvm.org/D95778
1 parent b90c490 commit a5b627a

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

clang/include/clang/Basic/LangOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ LANGOPT(OpenCL , 1, 0, "OpenCL")
215215
LANGOPT(OpenCLVersion , 32, 0, "OpenCL C version")
216216
LANGOPT(OpenCLCPlusPlus , 1, 0, "C++ for OpenCL")
217217
LANGOPT(OpenCLCPlusPlusVersion , 32, 0, "C++ for OpenCL version")
218+
LANGOPT(OpenCLGenericAddressSpace, 1, 0, "OpenCL generic keyword")
219+
LANGOPT(OpenCLPipe , 1, 0, "OpenCL pipe keyword")
218220
LANGOPT(NativeHalfType , 1, 0, "Native half type support")
219221
LANGOPT(NativeHalfArgsAndReturns, 1, 0, "Native half args and returns")
220222
LANGOPT(HalfArgsAndReturns, 1, 0, "half args and returns")

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,6 +2391,9 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
23912391
Opts.ZVector = 0;
23922392
Opts.setDefaultFPContractMode(LangOptions::FPM_On);
23932393
Opts.OpenCLCPlusPlus = Opts.CPlusPlus;
2394+
Opts.OpenCLPipe = Opts.OpenCLCPlusPlus || Opts.OpenCLVersion == 200;
2395+
Opts.OpenCLGenericAddressSpace =
2396+
Opts.OpenCLCPlusPlus || Opts.OpenCLVersion == 200;
23942397

23952398
// Include default header file for OpenCL.
23962399
if (Opts.IncludeDefaultHeader) {

clang/lib/Parse/ParseDecl.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3896,8 +3896,8 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
38963896
case tok::kw_pipe:
38973897
if (!getLangOpts().OpenCL || (getLangOpts().OpenCLVersion < 200 &&
38983898
!getLangOpts().OpenCLCPlusPlus)) {
3899-
// OpenCL 2.0 defined this keyword. OpenCL 1.2 and earlier should
3900-
// support the "pipe" word as identifier.
3899+
// OpenCL 2.0 and later define this keyword. OpenCL 1.2 and earlier
3900+
// should support the "pipe" word as identifier.
39013901
Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
39023902
goto DoneWithDeclSpec;
39033903
}
@@ -4017,8 +4017,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
40174017
case tok::kw___generic:
40184018
// generic address space is introduced only in OpenCL v2.0
40194019
// see OpenCL C Spec v2.0 s6.5.5
4020-
if (Actions.getLangOpts().OpenCLVersion < 200 &&
4021-
!Actions.getLangOpts().OpenCLCPlusPlus) {
4020+
if (!Actions.getLangOpts().OpenCLGenericAddressSpace) {
40224021
DiagID = diag::err_opencl_unknown_type_specifier;
40234022
PrevSpec = Tok.getIdentifierInfo()->getNameStart();
40244023
isInvalid = true;
@@ -5070,8 +5069,7 @@ bool Parser::isDeclarationSpecifier(bool DisambiguatingWithExpression) {
50705069
default: return false;
50715070

50725071
case tok::kw_pipe:
5073-
return (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200) ||
5074-
getLangOpts().OpenCLCPlusPlus;
5072+
return getLangOpts().OpenCLPipe;
50755073

50765074
case tok::identifier: // foo::bar
50775075
// Unfortunate hack to support "Class.factoryMethod" notation.
@@ -5599,8 +5597,7 @@ static bool isPtrOperatorToken(tok::TokenKind Kind, const LangOptions &Lang,
55995597
if (Kind == tok::star || Kind == tok::caret)
56005598
return true;
56015599

5602-
if (Kind == tok::kw_pipe &&
5603-
((Lang.OpenCL && Lang.OpenCLVersion >= 200) || Lang.OpenCLCPlusPlus))
5600+
if (Kind == tok::kw_pipe && Lang.OpenCLPipe)
56045601
return true;
56055602

56065603
if (!Lang.CPlusPlus)

clang/lib/Sema/SemaType.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,10 +2060,9 @@ static QualType deduceOpenCLPointeeAddrSpace(Sema &S, QualType PointeeType) {
20602060
!PointeeType->isSamplerT() &&
20612061
!PointeeType.hasAddressSpace())
20622062
PointeeType = S.getASTContext().getAddrSpaceQualType(
2063-
PointeeType,
2064-
S.getLangOpts().OpenCLCPlusPlus || S.getLangOpts().OpenCLVersion == 200
2065-
? LangAS::opencl_generic
2066-
: LangAS::opencl_private);
2063+
PointeeType, S.getLangOpts().OpenCLGenericAddressSpace
2064+
? LangAS::opencl_generic
2065+
: LangAS::opencl_private);
20672066
return PointeeType;
20682067
}
20692068

0 commit comments

Comments
 (0)