Skip to content

Commit 46a34a3

Browse files
committedMar 29, 2017
[OpenCL] Added parsing for OpenCL vector types.
Reviewers: cfe-commits, Anastasia Reviewed By: Anastasia Subscribers: yaxunl, bader Differential Revision: https://reviews.llvm.org/D31183 llvm-svn: 298976
1 parent f454301 commit 46a34a3

File tree

3 files changed

+69
-6
lines changed

3 files changed

+69
-6
lines changed
 

‎clang/include/clang/Parse/Parser.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -1449,10 +1449,12 @@ class Parser : public CodeCompletionHandler {
14491449
ExprResult ParseCastExpression(bool isUnaryExpression,
14501450
bool isAddressOfOperand,
14511451
bool &NotCastExpr,
1452-
TypeCastState isTypeCast);
1452+
TypeCastState isTypeCast,
1453+
bool isVectorLiteral = false);
14531454
ExprResult ParseCastExpression(bool isUnaryExpression,
14541455
bool isAddressOfOperand = false,
1455-
TypeCastState isTypeCast = NotTypeCast);
1456+
TypeCastState isTypeCast = NotTypeCast,
1457+
bool isVectorLiteral = false);
14561458

14571459
/// Returns true if the next token cannot start an expression.
14581460
bool isNotExpressionStart();

‎clang/lib/Parse/ParseExpr.cpp

+55-4
Original file line numberDiff line numberDiff line change
@@ -473,12 +473,14 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) {
473473
///
474474
ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
475475
bool isAddressOfOperand,
476-
TypeCastState isTypeCast) {
476+
TypeCastState isTypeCast,
477+
bool isVectorLiteral) {
477478
bool NotCastExpr;
478479
ExprResult Res = ParseCastExpression(isUnaryExpression,
479480
isAddressOfOperand,
480481
NotCastExpr,
481-
isTypeCast);
482+
isTypeCast,
483+
isVectorLiteral);
482484
if (NotCastExpr)
483485
Diag(Tok, diag::err_expected_expression);
484486
return Res;
@@ -694,7 +696,8 @@ class CastExpressionIdValidator : public CorrectionCandidateCallback {
694696
ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
695697
bool isAddressOfOperand,
696698
bool &NotCastExpr,
697-
TypeCastState isTypeCast) {
699+
TypeCastState isTypeCast,
700+
bool isVectorLiteral) {
698701
ExprResult Res;
699702
tok::TokenKind SavedKind = Tok.getKind();
700703
NotCastExpr = false;
@@ -722,6 +725,9 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
722725
Res = ParseParenExpression(ParenExprType, false/*stopIfCastExr*/,
723726
isTypeCast == IsTypeCast, CastTy, RParenLoc);
724727

728+
if (isVectorLiteral)
729+
return Res;
730+
725731
switch (ParenExprType) {
726732
case SimpleExpr: break; // Nothing else to do.
727733
case CompoundStmt: break; // Nothing else to do.
@@ -2350,6 +2356,48 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
23502356
return ParseCompoundLiteralExpression(Ty.get(), OpenLoc, RParenLoc);
23512357
}
23522358

2359+
if (Tok.is(tok::l_paren)) {
2360+
// This could be OpenCL vector Literals
2361+
if (getLangOpts().OpenCL)
2362+
{
2363+
TypeResult Ty;
2364+
{
2365+
InMessageExpressionRAIIObject InMessage(*this, false);
2366+
Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
2367+
}
2368+
if(Ty.isInvalid())
2369+
{
2370+
return ExprError();
2371+
}
2372+
QualType QT = Ty.get().get().getCanonicalType();
2373+
if (QT->isVectorType())
2374+
{
2375+
// We parsed '(' vector-type-name ')' followed by '('
2376+
2377+
// Parse the cast-expression that follows it next.
2378+
// isVectorLiteral = true will make sure we don't parse any
2379+
// Postfix expression yet
2380+
Result = ParseCastExpression(/*isUnaryExpression=*/false,
2381+
/*isAddressOfOperand=*/false,
2382+
/*isTypeCast=*/IsTypeCast,
2383+
/*isVectorLiteral=*/true);
2384+
2385+
if (!Result.isInvalid()) {
2386+
Result = Actions.ActOnCastExpr(getCurScope(), OpenLoc,
2387+
DeclaratorInfo, CastTy,
2388+
RParenLoc, Result.get());
2389+
}
2390+
2391+
// After we performed the cast we can check for postfix-expr pieces.
2392+
if (!Result.isInvalid()) {
2393+
Result = ParsePostfixExpressionSuffix(Result);
2394+
}
2395+
2396+
return Result;
2397+
}
2398+
}
2399+
}
2400+
23532401
if (ExprType == CastExpr) {
23542402
// We parsed '(' type-name ')' and the thing after it wasn't a '{'.
23552403

@@ -2379,10 +2427,13 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
23792427
}
23802428

23812429
// Parse the cast-expression that follows it next.
2430+
// isVectorLiteral = true will make sure we don't parse any
2431+
// Postfix expression yet
23822432
// TODO: For cast expression with CastTy.
23832433
Result = ParseCastExpression(/*isUnaryExpression=*/false,
23842434
/*isAddressOfOperand=*/false,
2385-
/*isTypeCast=*/IsTypeCast);
2435+
/*isTypeCast=*/IsTypeCast,
2436+
/*isVectorLiteral=*/true);
23862437
if (!Result.isInvalid()) {
23872438
Result = Actions.ActOnCastExpr(getCurScope(), OpenLoc,
23882439
DeclaratorInfo, CastTy,
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
2+
// expected-no-diagnostics
3+
4+
typedef int int3 __attribute__((ext_vector_type(3)));
5+
6+
void test()
7+
{
8+
int index = (int3)(1, 2, 3).x * (int3)(3, 2, 1).y;
9+
}
10+

0 commit comments

Comments
 (0)