comparison clang/lib/Parse/ParseExpr.cpp @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 79ff65ed7e25
children 173fe712db74 1f2b6ac9f198
comparison
equal deleted inserted replaced
232:70dce7da266c 236:c4bab56944e8
398 GreaterThanIsOperator, 398 GreaterThanIsOperator,
399 getLangOpts().CPlusPlus11); 399 getLangOpts().CPlusPlus11);
400 SourceLocation ColonLoc; 400 SourceLocation ColonLoc;
401 401
402 auto SavedType = PreferredType; 402 auto SavedType = PreferredType;
403 while (1) { 403 while (true) {
404 // Every iteration may rely on a preferred type for the whole expression. 404 // Every iteration may rely on a preferred type for the whole expression.
405 PreferredType = SavedType; 405 PreferredType = SavedType;
406 // If this token has a lower precedence than we are allowed to parse (e.g. 406 // If this token has a lower precedence than we are allowed to parse (e.g.
407 // because we are called recursively, or because the token is not a binop), 407 // because we are called recursively, or because the token is not a binop),
408 // then we are done! 408 // then we are done!
789 /// assign-expr ')' 789 /// assign-expr ')'
790 /// [GNU] '__builtin_FILE' '(' ')' 790 /// [GNU] '__builtin_FILE' '(' ')'
791 /// [GNU] '__builtin_FUNCTION' '(' ')' 791 /// [GNU] '__builtin_FUNCTION' '(' ')'
792 /// [GNU] '__builtin_LINE' '(' ')' 792 /// [GNU] '__builtin_LINE' '(' ')'
793 /// [CLANG] '__builtin_COLUMN' '(' ')' 793 /// [CLANG] '__builtin_COLUMN' '(' ')'
794 /// [GNU] '__builtin_source_location' '(' ')'
794 /// [GNU] '__builtin_types_compatible_p' '(' type-name ',' type-name ')' 795 /// [GNU] '__builtin_types_compatible_p' '(' type-name ',' type-name ')'
795 /// [GNU] '__null' 796 /// [GNU] '__null'
796 /// [OBJC] '[' objc-message-expr ']' 797 /// [OBJC] '[' objc-message-expr ']'
797 /// [OBJC] '\@selector' '(' objc-selector-arg ')' 798 /// [OBJC] '\@selector' '(' objc-selector-arg ')'
798 /// [OBJC] '\@protocol' '(' identifier ')' 799 /// [OBJC] '\@protocol' '(' identifier ')'
940 // If this expression is limited to being a unary-expression, the paren can 941 // If this expression is limited to being a unary-expression, the paren can
941 // not start a cast expression. 942 // not start a cast expression.
942 ParenParseOption ParenExprType; 943 ParenParseOption ParenExprType;
943 switch (ParseKind) { 944 switch (ParseKind) {
944 case CastParseKind::UnaryExprOnly: 945 case CastParseKind::UnaryExprOnly:
945 if (!getLangOpts().CPlusPlus) 946 assert(getLangOpts().CPlusPlus && "not possible to get here in C");
946 ParenExprType = CompoundLiteral; 947 [[fallthrough]];
947 LLVM_FALLTHROUGH;
948 case CastParseKind::AnyCastExpr: 948 case CastParseKind::AnyCastExpr:
949 ParenExprType = ParenParseOption::CastExpr; 949 ParenExprType = ParenParseOption::CastExpr;
950 break; 950 break;
951 case CastParseKind::PrimaryExprOnly: 951 case CastParseKind::PrimaryExprOnly:
952 ParenExprType = FoldExpr; 952 ParenExprType = FoldExpr;
1001 case tok::kw___objc_no: 1001 case tok::kw___objc_no:
1002 Res = ParseObjCBoolLiteral(); 1002 Res = ParseObjCBoolLiteral();
1003 break; 1003 break;
1004 1004
1005 case tok::kw_nullptr: 1005 case tok::kw_nullptr:
1006 Diag(Tok, diag::warn_cxx98_compat_nullptr); 1006 if (getLangOpts().CPlusPlus)
1007 Diag(Tok, diag::warn_cxx98_compat_nullptr);
1008 else
1009 Diag(Tok, getLangOpts().C2x ? diag::warn_c17_compat_nullptr
1010 : diag::ext_c_nullptr);
1011
1007 Res = Actions.ActOnCXXNullPtrLiteral(ConsumeToken()); 1012 Res = Actions.ActOnCXXNullPtrLiteral(ConsumeToken());
1008 break; 1013 break;
1009 1014
1010 case tok::annot_primary_expr: 1015 case tok::annot_primary_expr:
1011 case tok::annot_overload_set: 1016 case tok::annot_overload_set:
1035 return ExprError(); 1040 return ExprError();
1036 assert(Tok.isNot(tok::kw_decltype) && Tok.isNot(tok::kw___super)); 1041 assert(Tok.isNot(tok::kw_decltype) && Tok.isNot(tok::kw___super));
1037 return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast, 1042 return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast,
1038 isVectorLiteral, NotPrimaryExpression); 1043 isVectorLiteral, NotPrimaryExpression);
1039 1044
1040 case tok::identifier: { // primary-expression: identifier 1045 case tok::identifier:
1041 // unqualified-id: identifier 1046 ParseIdentifier: { // primary-expression: identifier
1042 // constant: enumeration-constant 1047 // unqualified-id: identifier
1048 // constant: enumeration-constant
1043 // Turn a potentially qualified name into a annot_typename or 1049 // Turn a potentially qualified name into a annot_typename or
1044 // annot_cxxscope if it would be valid. This handles things like x::y, etc. 1050 // annot_cxxscope if it would be valid. This handles things like x::y, etc.
1045 if (getLangOpts().CPlusPlus) { 1051 if (getLangOpts().CPlusPlus) {
1046 // Avoid the unnecessary parse-time lookup in the common case 1052 // Avoid the unnecessary parse-time lookup in the common case
1047 // where the syntax forbids a type. 1053 // where the syntax forbids a type.
1065 REVERTIBLE_TYPE_TRAIT(__is_aggregate); 1071 REVERTIBLE_TYPE_TRAIT(__is_aggregate);
1066 REVERTIBLE_TYPE_TRAIT(__is_arithmetic); 1072 REVERTIBLE_TYPE_TRAIT(__is_arithmetic);
1067 REVERTIBLE_TYPE_TRAIT(__is_array); 1073 REVERTIBLE_TYPE_TRAIT(__is_array);
1068 REVERTIBLE_TYPE_TRAIT(__is_assignable); 1074 REVERTIBLE_TYPE_TRAIT(__is_assignable);
1069 REVERTIBLE_TYPE_TRAIT(__is_base_of); 1075 REVERTIBLE_TYPE_TRAIT(__is_base_of);
1076 REVERTIBLE_TYPE_TRAIT(__is_bounded_array);
1070 REVERTIBLE_TYPE_TRAIT(__is_class); 1077 REVERTIBLE_TYPE_TRAIT(__is_class);
1071 REVERTIBLE_TYPE_TRAIT(__is_complete_type); 1078 REVERTIBLE_TYPE_TRAIT(__is_complete_type);
1072 REVERTIBLE_TYPE_TRAIT(__is_compound); 1079 REVERTIBLE_TYPE_TRAIT(__is_compound);
1073 REVERTIBLE_TYPE_TRAIT(__is_const); 1080 REVERTIBLE_TYPE_TRAIT(__is_const);
1074 REVERTIBLE_TYPE_TRAIT(__is_constructible); 1081 REVERTIBLE_TYPE_TRAIT(__is_constructible);
1090 REVERTIBLE_TYPE_TRAIT(__is_member_object_pointer); 1097 REVERTIBLE_TYPE_TRAIT(__is_member_object_pointer);
1091 REVERTIBLE_TYPE_TRAIT(__is_member_pointer); 1098 REVERTIBLE_TYPE_TRAIT(__is_member_pointer);
1092 REVERTIBLE_TYPE_TRAIT(__is_nothrow_assignable); 1099 REVERTIBLE_TYPE_TRAIT(__is_nothrow_assignable);
1093 REVERTIBLE_TYPE_TRAIT(__is_nothrow_constructible); 1100 REVERTIBLE_TYPE_TRAIT(__is_nothrow_constructible);
1094 REVERTIBLE_TYPE_TRAIT(__is_nothrow_destructible); 1101 REVERTIBLE_TYPE_TRAIT(__is_nothrow_destructible);
1102 REVERTIBLE_TYPE_TRAIT(__is_nullptr);
1095 REVERTIBLE_TYPE_TRAIT(__is_object); 1103 REVERTIBLE_TYPE_TRAIT(__is_object);
1096 REVERTIBLE_TYPE_TRAIT(__is_pod); 1104 REVERTIBLE_TYPE_TRAIT(__is_pod);
1097 REVERTIBLE_TYPE_TRAIT(__is_pointer); 1105 REVERTIBLE_TYPE_TRAIT(__is_pointer);
1098 REVERTIBLE_TYPE_TRAIT(__is_polymorphic); 1106 REVERTIBLE_TYPE_TRAIT(__is_polymorphic);
1099 REVERTIBLE_TYPE_TRAIT(__is_reference); 1107 REVERTIBLE_TYPE_TRAIT(__is_reference);
1108 REVERTIBLE_TYPE_TRAIT(__is_referenceable);
1100 REVERTIBLE_TYPE_TRAIT(__is_rvalue_expr); 1109 REVERTIBLE_TYPE_TRAIT(__is_rvalue_expr);
1101 REVERTIBLE_TYPE_TRAIT(__is_rvalue_reference); 1110 REVERTIBLE_TYPE_TRAIT(__is_rvalue_reference);
1102 REVERTIBLE_TYPE_TRAIT(__is_same); 1111 REVERTIBLE_TYPE_TRAIT(__is_same);
1103 REVERTIBLE_TYPE_TRAIT(__is_scalar); 1112 REVERTIBLE_TYPE_TRAIT(__is_scalar);
1113 REVERTIBLE_TYPE_TRAIT(__is_scoped_enum);
1104 REVERTIBLE_TYPE_TRAIT(__is_sealed); 1114 REVERTIBLE_TYPE_TRAIT(__is_sealed);
1105 REVERTIBLE_TYPE_TRAIT(__is_signed); 1115 REVERTIBLE_TYPE_TRAIT(__is_signed);
1106 REVERTIBLE_TYPE_TRAIT(__is_standard_layout); 1116 REVERTIBLE_TYPE_TRAIT(__is_standard_layout);
1107 REVERTIBLE_TYPE_TRAIT(__is_trivial); 1117 REVERTIBLE_TYPE_TRAIT(__is_trivial);
1108 REVERTIBLE_TYPE_TRAIT(__is_trivially_assignable); 1118 REVERTIBLE_TYPE_TRAIT(__is_trivially_assignable);
1109 REVERTIBLE_TYPE_TRAIT(__is_trivially_constructible); 1119 REVERTIBLE_TYPE_TRAIT(__is_trivially_constructible);
1110 REVERTIBLE_TYPE_TRAIT(__is_trivially_copyable); 1120 REVERTIBLE_TYPE_TRAIT(__is_trivially_copyable);
1121 REVERTIBLE_TYPE_TRAIT(__is_unbounded_array);
1111 REVERTIBLE_TYPE_TRAIT(__is_union); 1122 REVERTIBLE_TYPE_TRAIT(__is_union);
1112 REVERTIBLE_TYPE_TRAIT(__is_unsigned); 1123 REVERTIBLE_TYPE_TRAIT(__is_unsigned);
1113 REVERTIBLE_TYPE_TRAIT(__is_void); 1124 REVERTIBLE_TYPE_TRAIT(__is_void);
1114 REVERTIBLE_TYPE_TRAIT(__is_volatile); 1125 REVERTIBLE_TYPE_TRAIT(__is_volatile);
1126 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) \
1127 REVERTIBLE_TYPE_TRAIT(RTT_JOIN(__, Trait));
1128 #include "clang/Basic/TransformTypeTraits.def"
1115 #undef REVERTIBLE_TYPE_TRAIT 1129 #undef REVERTIBLE_TYPE_TRAIT
1116 #undef RTT_JOIN 1130 #undef RTT_JOIN
1117 } 1131 }
1118 1132
1119 // If we find that this is in fact the name of a type trait, 1133 // If we find that this is in fact the name of a type trait,
1209 const char *PrevSpec = nullptr; 1223 const char *PrevSpec = nullptr;
1210 unsigned DiagID; 1224 unsigned DiagID;
1211 DS.SetTypeSpecType(TST_typename, ILoc, PrevSpec, DiagID, Typ, 1225 DS.SetTypeSpecType(TST_typename, ILoc, PrevSpec, DiagID, Typ,
1212 Actions.getASTContext().getPrintingPolicy()); 1226 Actions.getASTContext().getPrintingPolicy());
1213 1227
1214 Declarator DeclaratorInfo(DS, DeclaratorContext::TypeName); 1228 Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
1229 DeclaratorContext::TypeName);
1215 TypeResult Ty = Actions.ActOnTypeName(getCurScope(), 1230 TypeResult Ty = Actions.ActOnTypeName(getCurScope(),
1216 DeclaratorInfo); 1231 DeclaratorInfo);
1217 if (Ty.isInvalid()) 1232 if (Ty.isInvalid())
1218 break; 1233 break;
1219 1234
1301 case tok::kw___builtin_convertvector: 1316 case tok::kw___builtin_convertvector:
1302 case tok::kw___builtin_COLUMN: 1317 case tok::kw___builtin_COLUMN:
1303 case tok::kw___builtin_FILE: 1318 case tok::kw___builtin_FILE:
1304 case tok::kw___builtin_FUNCTION: 1319 case tok::kw___builtin_FUNCTION:
1305 case tok::kw___builtin_LINE: 1320 case tok::kw___builtin_LINE:
1321 case tok::kw___builtin_source_location:
1306 if (NotPrimaryExpression) 1322 if (NotPrimaryExpression)
1307 *NotPrimaryExpression = true; 1323 *NotPrimaryExpression = true;
1308 // This parses the complete suffix; we can return early. 1324 // This parses the complete suffix; we can return early.
1309 return ParseBuiltinPrimaryExpression(); 1325 return ParseBuiltinPrimaryExpression();
1310 case tok::kw___null: 1326 case tok::kw___null:
1352 if (NotPrimaryExpression) 1368 if (NotPrimaryExpression)
1353 *NotPrimaryExpression = true; 1369 *NotPrimaryExpression = true;
1354 // Special treatment because of member pointers 1370 // Special treatment because of member pointers
1355 SourceLocation SavedLoc = ConsumeToken(); 1371 SourceLocation SavedLoc = ConsumeToken();
1356 PreferredType.enterUnary(Actions, Tok.getLocation(), tok::amp, SavedLoc); 1372 PreferredType.enterUnary(Actions, Tok.getLocation(), tok::amp, SavedLoc);
1357 Res = ParseCastExpression(AnyCastExpr, true); 1373
1374 Res = ParseCastExpression(AnyCastExpr, /*isAddressOfOperand=*/true);
1358 if (!Res.isInvalid()) { 1375 if (!Res.isInvalid()) {
1359 Expr *Arg = Res.get(); 1376 Expr *Arg = Res.get();
1360 Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Arg); 1377 Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Arg);
1361 if (Res.isInvalid()) 1378 if (Res.isInvalid())
1362 Res = Actions.CreateRecoveryExpr(Tok.getLocation(), Arg->getEndLoc(), 1379 Res = Actions.CreateRecoveryExpr(Tok.getLocation(), Arg->getEndLoc(),
1377 SourceLocation SavedLoc = ConsumeToken(); 1394 SourceLocation SavedLoc = ConsumeToken();
1378 PreferredType.enterUnary(Actions, Tok.getLocation(), SavedKind, SavedLoc); 1395 PreferredType.enterUnary(Actions, Tok.getLocation(), SavedKind, SavedLoc);
1379 Res = ParseCastExpression(AnyCastExpr); 1396 Res = ParseCastExpression(AnyCastExpr);
1380 if (!Res.isInvalid()) { 1397 if (!Res.isInvalid()) {
1381 Expr *Arg = Res.get(); 1398 Expr *Arg = Res.get();
1382 Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Arg); 1399 Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Arg,
1400 isAddressOfOperand);
1383 if (Res.isInvalid()) 1401 if (Res.isInvalid())
1384 Res = Actions.CreateRecoveryExpr(SavedLoc, Arg->getEndLoc(), Arg); 1402 Res = Actions.CreateRecoveryExpr(SavedLoc, Arg->getEndLoc(), Arg);
1385 } 1403 }
1386 return Res; 1404 return Res;
1387 } 1405 }
1408 return Res; 1426 return Res;
1409 } 1427 }
1410 case tok::kw__Alignof: // unary-expression: '_Alignof' '(' type-name ')' 1428 case tok::kw__Alignof: // unary-expression: '_Alignof' '(' type-name ')'
1411 if (!getLangOpts().C11) 1429 if (!getLangOpts().C11)
1412 Diag(Tok, diag::ext_c11_feature) << Tok.getName(); 1430 Diag(Tok, diag::ext_c11_feature) << Tok.getName();
1413 LLVM_FALLTHROUGH; 1431 [[fallthrough]];
1414 case tok::kw_alignof: // unary-expression: 'alignof' '(' type-id ')' 1432 case tok::kw_alignof: // unary-expression: 'alignof' '(' type-id ')'
1415 case tok::kw___alignof: // unary-expression: '__alignof' unary-expression 1433 case tok::kw___alignof: // unary-expression: '__alignof' unary-expression
1416 // unary-expression: '__alignof' '(' type-name ')' 1434 // unary-expression: '__alignof' '(' type-name ')'
1417 case tok::kw_sizeof: // unary-expression: 'sizeof' unary-expression 1435 case tok::kw_sizeof: // unary-expression: 'sizeof' unary-expression
1418 // unary-expression: 'sizeof' '(' type-name ')' 1436 // unary-expression: 'sizeof' '(' type-name ')'
1486 unsigned DiagID; 1504 unsigned DiagID;
1487 DS.SetTypeSpecType(TST_typename, Tok.getAnnotationEndLoc(), 1505 DS.SetTypeSpecType(TST_typename, Tok.getAnnotationEndLoc(),
1488 PrevSpec, DiagID, Type, 1506 PrevSpec, DiagID, Type,
1489 Actions.getASTContext().getPrintingPolicy()); 1507 Actions.getASTContext().getPrintingPolicy());
1490 1508
1491 Declarator DeclaratorInfo(DS, DeclaratorContext::TypeName); 1509 Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
1510 DeclaratorContext::TypeName);
1492 TypeResult Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); 1511 TypeResult Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
1493 if (Ty.isInvalid()) 1512 if (Ty.isInvalid())
1494 break; 1513 break;
1495 1514
1496 ConsumeAnnotationToken(); 1515 ConsumeAnnotationToken();
1497 Res = ParseObjCMessageExpressionBody(SourceLocation(), SourceLocation(), 1516 Res = ParseObjCMessageExpressionBody(SourceLocation(), SourceLocation(),
1498 Ty.get(), nullptr); 1517 Ty.get(), nullptr);
1499 break; 1518 break;
1500 } 1519 }
1501 LLVM_FALLTHROUGH; 1520 [[fallthrough]];
1502 1521
1503 case tok::annot_decltype: 1522 case tok::annot_decltype:
1504 case tok::kw_char: 1523 case tok::kw_char:
1505 case tok::kw_wchar_t: 1524 case tok::kw_wchar_t:
1506 case tok::kw_char8_t: 1525 case tok::kw_char8_t:
1511 case tok::kw_int: 1530 case tok::kw_int:
1512 case tok::kw_long: 1531 case tok::kw_long:
1513 case tok::kw___int64: 1532 case tok::kw___int64:
1514 case tok::kw___int128: 1533 case tok::kw___int128:
1515 case tok::kw__ExtInt: 1534 case tok::kw__ExtInt:
1535 case tok::kw__BitInt:
1516 case tok::kw_signed: 1536 case tok::kw_signed:
1517 case tok::kw_unsigned: 1537 case tok::kw_unsigned:
1518 case tok::kw_half: 1538 case tok::kw_half:
1519 case tok::kw_float: 1539 case tok::kw_float:
1520 case tok::kw_double: 1540 case tok::kw_double:
1521 case tok::kw___bf16: 1541 case tok::kw___bf16:
1522 case tok::kw__Float16: 1542 case tok::kw__Float16:
1523 case tok::kw___float128: 1543 case tok::kw___float128:
1544 case tok::kw___ibm128:
1524 case tok::kw_void: 1545 case tok::kw_void:
1546 case tok::kw_auto:
1525 case tok::kw_typename: 1547 case tok::kw_typename:
1526 case tok::kw_typeof: 1548 case tok::kw_typeof:
1527 case tok::kw___vector: 1549 case tok::kw___vector:
1528 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: 1550 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
1529 #include "clang/Basic/OpenCLImageTypes.def" 1551 #include "clang/Basic/OpenCLImageTypes.def"
1584 // We have a qualified template-id that we know refers to a 1606 // We have a qualified template-id that we know refers to a
1585 // type, translate it into a type and continue parsing as a 1607 // type, translate it into a type and continue parsing as a
1586 // cast expression. 1608 // cast expression.
1587 CXXScopeSpec SS; 1609 CXXScopeSpec SS;
1588 ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/nullptr, 1610 ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/nullptr,
1589 /*ObjectHadErrors=*/false, 1611 /*ObjectHasErrors=*/false,
1590 /*EnteringContext=*/false); 1612 /*EnteringContext=*/false);
1591 AnnotateTemplateIdTokenAsType(SS); 1613 AnnotateTemplateIdTokenAsType(SS, ImplicitTypenameContext::Yes);
1592 return ParseCastExpression(ParseKind, isAddressOfOperand, NotCastExpr, 1614 return ParseCastExpression(ParseKind, isAddressOfOperand, NotCastExpr,
1593 isTypeCast, isVectorLiteral, 1615 isTypeCast, isVectorLiteral,
1594 NotPrimaryExpression); 1616 NotPrimaryExpression);
1595 } 1617 }
1596 } 1618 }
1605 if (TemplateId->Kind == TNK_Type_template) { 1627 if (TemplateId->Kind == TNK_Type_template) {
1606 // We have a template-id that we know refers to a type, 1628 // We have a template-id that we know refers to a type,
1607 // translate it into a type and continue parsing as a cast 1629 // translate it into a type and continue parsing as a cast
1608 // expression. 1630 // expression.
1609 CXXScopeSpec SS; 1631 CXXScopeSpec SS;
1610 AnnotateTemplateIdTokenAsType(SS); 1632 AnnotateTemplateIdTokenAsType(SS, ImplicitTypenameContext::Yes);
1611 return ParseCastExpression(ParseKind, isAddressOfOperand, 1633 return ParseCastExpression(ParseKind, isAddressOfOperand,
1612 NotCastExpr, isTypeCast, isVectorLiteral, 1634 NotCastExpr, isTypeCast, isVectorLiteral,
1613 NotPrimaryExpression); 1635 NotPrimaryExpression);
1614 } 1636 }
1615 1637
1616 // Fall through to treat the template-id as an id-expression. 1638 // Fall through to treat the template-id as an id-expression.
1617 LLVM_FALLTHROUGH; 1639 [[fallthrough]];
1618 } 1640 }
1619 1641
1620 case tok::kw_operator: // [C++] id-expression: operator/conversion-function-id 1642 case tok::kw_operator: // [C++] id-expression: operator/conversion-function-id
1621 Res = ParseCXXIdExpression(isAddressOfOperand); 1643 Res = ParseCXXIdExpression(isAddressOfOperand);
1622 break; 1644 break;
1730 cutOffParsing(); 1752 cutOffParsing();
1731 Actions.CodeCompleteExpression(getCurScope(), 1753 Actions.CodeCompleteExpression(getCurScope(),
1732 PreferredType.get(Tok.getLocation())); 1754 PreferredType.get(Tok.getLocation()));
1733 return ExprError(); 1755 return ExprError();
1734 } 1756 }
1757 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
1758 #include "clang/Basic/TransformTypeTraits.def"
1759 // HACK: libstdc++ uses some of the transform-type-traits as alias
1760 // templates, so we need to work around this.
1761 if (!NextToken().is(tok::l_paren)) {
1762 Tok.setKind(tok::identifier);
1763 Diag(Tok, diag::ext_keyword_as_ident)
1764 << Tok.getIdentifierInfo()->getName() << 0;
1765 goto ParseIdentifier;
1766 }
1767 goto ExpectedExpression;
1735 case tok::l_square: 1768 case tok::l_square:
1736 if (getLangOpts().CPlusPlus11) { 1769 if (getLangOpts().CPlusPlus11) {
1737 if (getLangOpts().ObjC) { 1770 if (getLangOpts().ObjC) {
1738 // C++11 lambda expressions and Objective-C message sends both start with a 1771 // C++11 lambda expressions and Objective-C message sends both start with a
1739 // square bracket. There are three possibilities here: 1772 // square bracket. There are three possibilities here:
1755 } 1788 }
1756 if (getLangOpts().ObjC) { 1789 if (getLangOpts().ObjC) {
1757 Res = ParseObjCMessageExpression(); 1790 Res = ParseObjCMessageExpression();
1758 break; 1791 break;
1759 } 1792 }
1760 LLVM_FALLTHROUGH; 1793 [[fallthrough]];
1761 default: 1794 default:
1795 ExpectedExpression:
1762 NotCastExpr = true; 1796 NotCastExpr = true;
1763 return ExprError(); 1797 return ExprError();
1764 } 1798 }
1765 1799
1766 // Check to see whether Res is a function designator only. If it is and we 1800 // Check to see whether Res is a function designator only. If it is and we
1786 // "expected ';'" or similar is probably the right diagnostic here. Let 1820 // "expected ';'" or similar is probably the right diagnostic here. Let
1787 // the caller decide what to do. 1821 // the caller decide what to do.
1788 if (Tok.isAtStartOfLine()) 1822 if (Tok.isAtStartOfLine())
1789 return Res; 1823 return Res;
1790 1824
1791 LLVM_FALLTHROUGH; 1825 [[fallthrough]];
1792 case tok::period: 1826 case tok::period:
1793 case tok::arrow: 1827 case tok::arrow:
1794 break; 1828 break;
1795 1829
1796 default: 1830 default:
1831 /// \verbatim 1865 /// \verbatim
1832 /// postfix-expression: [C99 6.5.2] 1866 /// postfix-expression: [C99 6.5.2]
1833 /// primary-expression 1867 /// primary-expression
1834 /// postfix-expression '[' expression ']' 1868 /// postfix-expression '[' expression ']'
1835 /// postfix-expression '[' braced-init-list ']' 1869 /// postfix-expression '[' braced-init-list ']'
1870 /// postfix-expression '[' expression-list [opt] ']' [C++2b 12.4.5]
1836 /// postfix-expression '(' argument-expression-list[opt] ')' 1871 /// postfix-expression '(' argument-expression-list[opt] ')'
1837 /// postfix-expression '.' identifier 1872 /// postfix-expression '.' identifier
1838 /// postfix-expression '->' identifier 1873 /// postfix-expression '->' identifier
1839 /// postfix-expression '++' 1874 /// postfix-expression '++'
1840 /// postfix-expression '--' 1875 /// postfix-expression '--'
1849 Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { 1884 Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
1850 // Now that the primary-expression piece of the postfix-expression has been 1885 // Now that the primary-expression piece of the postfix-expression has been
1851 // parsed, see if there are any postfix-expression pieces here. 1886 // parsed, see if there are any postfix-expression pieces here.
1852 SourceLocation Loc; 1887 SourceLocation Loc;
1853 auto SavedType = PreferredType; 1888 auto SavedType = PreferredType;
1854 while (1) { 1889 while (true) {
1855 // Each iteration relies on preferred type for the whole expression. 1890 // Each iteration relies on preferred type for the whole expression.
1856 PreferredType = SavedType; 1891 PreferredType = SavedType;
1857 switch (Tok.getKind()) { 1892 switch (Tok.getKind()) {
1858 case tok::code_completion: 1893 case tok::code_completion:
1859 if (InMessageExpression) 1894 if (InMessageExpression)
1873 LHS = ParseObjCMessageExpressionBody(SourceLocation(), SourceLocation(), 1908 LHS = ParseObjCMessageExpressionBody(SourceLocation(), SourceLocation(),
1874 nullptr, LHS.get()); 1909 nullptr, LHS.get());
1875 break; 1910 break;
1876 } 1911 }
1877 // Fall through; this isn't a message send. 1912 // Fall through; this isn't a message send.
1878 LLVM_FALLTHROUGH; 1913 [[fallthrough]];
1879 1914
1880 default: // Not a postfix-expression suffix. 1915 default: // Not a postfix-expression suffix.
1881 return LHS; 1916 return LHS;
1882 case tok::l_square: { // postfix-expression: p-e '[' expression ']' 1917 case tok::l_square: { // postfix-expression: p-e '[' expression ']'
1883 // If we have a array postfix expression that starts on a new line and 1918 // If we have a array postfix expression that starts on a new line and
1894 // reserved for attributes. 1929 // reserved for attributes.
1895 if (CheckProhibitedCXX11Attribute()) { 1930 if (CheckProhibitedCXX11Attribute()) {
1896 (void)Actions.CorrectDelayedTyposInExpr(LHS); 1931 (void)Actions.CorrectDelayedTyposInExpr(LHS);
1897 return ExprError(); 1932 return ExprError();
1898 } 1933 }
1899
1900 BalancedDelimiterTracker T(*this, tok::l_square); 1934 BalancedDelimiterTracker T(*this, tok::l_square);
1901 T.consumeOpen(); 1935 T.consumeOpen();
1902 Loc = T.getOpenLocation(); 1936 Loc = T.getOpenLocation();
1903 ExprResult Idx, Length, Stride; 1937 ExprResult Length, Stride;
1904 SourceLocation ColonLocFirst, ColonLocSecond; 1938 SourceLocation ColonLocFirst, ColonLocSecond;
1939 ExprVector ArgExprs;
1940 bool HasError = false;
1905 PreferredType.enterSubscript(Actions, Tok.getLocation(), LHS.get()); 1941 PreferredType.enterSubscript(Actions, Tok.getLocation(), LHS.get());
1906 if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { 1942
1907 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); 1943 // We try to parse a list of indexes in all language mode first
1908 Idx = ParseBraceInitializer(); 1944 // and, in we find 0 or one index, we try to parse an OpenMP array
1909 } else if (getLangOpts().OpenMP) { 1945 // section. This allow us to support C++2b multi dimensional subscript and
1946 // OpenMp sections in the same language mode.
1947 if (!getLangOpts().OpenMP || Tok.isNot(tok::colon)) {
1948 if (!getLangOpts().CPlusPlus2b) {
1949 ExprResult Idx;
1950 if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
1951 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
1952 Idx = ParseBraceInitializer();
1953 } else {
1954 Idx = ParseExpression(); // May be a comma expression
1955 }
1956 LHS = Actions.CorrectDelayedTyposInExpr(LHS);
1957 Idx = Actions.CorrectDelayedTyposInExpr(Idx);
1958 if (Idx.isInvalid()) {
1959 HasError = true;
1960 } else {
1961 ArgExprs.push_back(Idx.get());
1962 }
1963 } else if (Tok.isNot(tok::r_square)) {
1964 CommaLocsTy CommaLocs;
1965 if (ParseExpressionList(ArgExprs, CommaLocs)) {
1966 LHS = Actions.CorrectDelayedTyposInExpr(LHS);
1967 HasError = true;
1968 }
1969 assert(
1970 (ArgExprs.empty() || ArgExprs.size() == CommaLocs.size() + 1) &&
1971 "Unexpected number of commas!");
1972 }
1973 }
1974
1975 if (ArgExprs.size() <= 1 && getLangOpts().OpenMP) {
1910 ColonProtectionRAIIObject RAII(*this); 1976 ColonProtectionRAIIObject RAII(*this);
1911 // Parse [: or [ expr or [ expr :
1912 if (!Tok.is(tok::colon)) {
1913 // [ expr
1914 Idx = ParseExpression();
1915 }
1916 if (Tok.is(tok::colon)) { 1977 if (Tok.is(tok::colon)) {
1917 // Consume ':' 1978 // Consume ':'
1918 ColonLocFirst = ConsumeToken(); 1979 ColonLocFirst = ConsumeToken();
1919 if (Tok.isNot(tok::r_square) && 1980 if (Tok.isNot(tok::r_square) &&
1920 (getLangOpts().OpenMP < 50 || 1981 (getLangOpts().OpenMP < 50 ||
1921 ((Tok.isNot(tok::colon) && getLangOpts().OpenMP >= 50)))) 1982 ((Tok.isNot(tok::colon) && getLangOpts().OpenMP >= 50)))) {
1922 Length = ParseExpression(); 1983 Length = ParseExpression();
1984 Length = Actions.CorrectDelayedTyposInExpr(Length);
1985 }
1923 } 1986 }
1924 if (getLangOpts().OpenMP >= 50 && 1987 if (getLangOpts().OpenMP >= 50 &&
1925 (OMPClauseKind == llvm::omp::Clause::OMPC_to || 1988 (OMPClauseKind == llvm::omp::Clause::OMPC_to ||
1926 OMPClauseKind == llvm::omp::Clause::OMPC_from) && 1989 OMPClauseKind == llvm::omp::Clause::OMPC_from) &&
1927 Tok.is(tok::colon)) { 1990 Tok.is(tok::colon)) {
1929 ColonLocSecond = ConsumeToken(); 1992 ColonLocSecond = ConsumeToken();
1930 if (Tok.isNot(tok::r_square)) { 1993 if (Tok.isNot(tok::r_square)) {
1931 Stride = ParseExpression(); 1994 Stride = ParseExpression();
1932 } 1995 }
1933 } 1996 }
1934 } else 1997 }
1935 Idx = ParseExpression();
1936 1998
1937 SourceLocation RLoc = Tok.getLocation(); 1999 SourceLocation RLoc = Tok.getLocation();
1938
1939 LHS = Actions.CorrectDelayedTyposInExpr(LHS); 2000 LHS = Actions.CorrectDelayedTyposInExpr(LHS);
1940 Idx = Actions.CorrectDelayedTyposInExpr(Idx); 2001
1941 Length = Actions.CorrectDelayedTyposInExpr(Length); 2002 if (!LHS.isInvalid() && !HasError && !Length.isInvalid() &&
1942 if (!LHS.isInvalid() && !Idx.isInvalid() && !Length.isInvalid() &&
1943 !Stride.isInvalid() && Tok.is(tok::r_square)) { 2003 !Stride.isInvalid() && Tok.is(tok::r_square)) {
1944 if (ColonLocFirst.isValid() || ColonLocSecond.isValid()) { 2004 if (ColonLocFirst.isValid() || ColonLocSecond.isValid()) {
1945 LHS = Actions.ActOnOMPArraySectionExpr( 2005 LHS = Actions.ActOnOMPArraySectionExpr(
1946 LHS.get(), Loc, Idx.get(), ColonLocFirst, ColonLocSecond, 2006 LHS.get(), Loc, ArgExprs.empty() ? nullptr : ArgExprs[0],
1947 Length.get(), Stride.get(), RLoc); 2007 ColonLocFirst, ColonLocSecond, Length.get(), Stride.get(), RLoc);
1948 } else { 2008 } else {
1949 LHS = Actions.ActOnArraySubscriptExpr(getCurScope(), LHS.get(), Loc, 2009 LHS = Actions.ActOnArraySubscriptExpr(getCurScope(), LHS.get(), Loc,
1950 Idx.get(), RLoc); 2010 ArgExprs, RLoc);
1951 } 2011 }
1952 } else { 2012 } else {
1953 LHS = ExprError(); 2013 LHS = ExprError();
1954 Idx = ExprError();
1955 } 2014 }
1956 2015
1957 // Match the ']'. 2016 // Match the ']'.
1958 T.consumeClose(); 2017 T.consumeClose();
1959 break; 2018 break;
2015 2074
2016 ExprVector ArgExprs; 2075 ExprVector ArgExprs;
2017 CommaLocsTy CommaLocs; 2076 CommaLocsTy CommaLocs;
2018 auto RunSignatureHelp = [&]() -> QualType { 2077 auto RunSignatureHelp = [&]() -> QualType {
2019 QualType PreferredType = Actions.ProduceCallSignatureHelp( 2078 QualType PreferredType = Actions.ProduceCallSignatureHelp(
2020 getCurScope(), LHS.get(), ArgExprs, PT.getOpenLocation()); 2079 LHS.get(), ArgExprs, PT.getOpenLocation());
2021 CalledSignatureHelp = true; 2080 CalledSignatureHelp = true;
2022 return PreferredType; 2081 return PreferredType;
2023 }; 2082 };
2024 if (OpKind == tok::l_paren || !LHS.isInvalid()) { 2083 if (OpKind == tok::l_paren || !LHS.isInvalid()) {
2025 if (Tok.isNot(tok::r_paren)) { 2084 if (Tok.isNot(tok::r_paren)) {
2237 /// 2296 ///
2238 /// [GNU] typeof-specifier: 2297 /// [GNU] typeof-specifier:
2239 /// typeof ( expressions ) 2298 /// typeof ( expressions )
2240 /// typeof ( type-name ) 2299 /// typeof ( type-name )
2241 /// [GNU/C++] typeof unary-expression 2300 /// [GNU/C++] typeof unary-expression
2301 /// [C2x] typeof-specifier:
2302 /// typeof '(' typeof-specifier-argument ')'
2303 /// typeof_unqual '(' typeof-specifier-argument ')'
2304 ///
2305 /// typeof-specifier-argument:
2306 /// expression
2307 /// type-name
2242 /// 2308 ///
2243 /// [OpenCL 1.1 6.11.12] vec_step built-in function: 2309 /// [OpenCL 1.1 6.11.12] vec_step built-in function:
2244 /// vec_step ( expressions ) 2310 /// vec_step ( expressions )
2245 /// vec_step ( type-name ) 2311 /// vec_step ( type-name )
2246 /// \endverbatim 2312 /// \endverbatim
2248 Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok, 2314 Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok,
2249 bool &isCastExpr, 2315 bool &isCastExpr,
2250 ParsedType &CastTy, 2316 ParsedType &CastTy,
2251 SourceRange &CastRange) { 2317 SourceRange &CastRange) {
2252 2318
2253 assert(OpTok.isOneOf(tok::kw_typeof, tok::kw_sizeof, tok::kw___alignof, 2319 assert(OpTok.isOneOf(tok::kw_typeof, tok::kw_typeof_unqual, tok::kw_sizeof,
2254 tok::kw_alignof, tok::kw__Alignof, tok::kw_vec_step, 2320 tok::kw___alignof, tok::kw_alignof, tok::kw__Alignof,
2321 tok::kw_vec_step,
2255 tok::kw___builtin_omp_required_simd_align) && 2322 tok::kw___builtin_omp_required_simd_align) &&
2256 "Not a typeof/sizeof/alignof/vec_step expression!"); 2323 "Not a typeof/sizeof/alignof/vec_step expression!");
2257 2324
2258 ExprResult Operand; 2325 ExprResult Operand;
2259 2326
2264 if (OpTok.isOneOf(tok::kw_sizeof, tok::kw___alignof, tok::kw_alignof, 2331 if (OpTok.isOneOf(tok::kw_sizeof, tok::kw___alignof, tok::kw_alignof,
2265 tok::kw__Alignof)) { 2332 tok::kw__Alignof)) {
2266 if (isTypeIdUnambiguously()) { 2333 if (isTypeIdUnambiguously()) {
2267 DeclSpec DS(AttrFactory); 2334 DeclSpec DS(AttrFactory);
2268 ParseSpecifierQualifierList(DS); 2335 ParseSpecifierQualifierList(DS);
2269 Declarator DeclaratorInfo(DS, DeclaratorContext::TypeName); 2336 Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
2337 DeclaratorContext::TypeName);
2270 ParseDeclarator(DeclaratorInfo); 2338 ParseDeclarator(DeclaratorInfo);
2271 2339
2272 SourceLocation LParenLoc = PP.getLocForEndOfToken(OpTok.getLocation()); 2340 SourceLocation LParenLoc = PP.getLocForEndOfToken(OpTok.getLocation());
2273 SourceLocation RParenLoc = PP.getLocForEndOfToken(PrevTokLocation); 2341 SourceLocation RParenLoc = PP.getLocForEndOfToken(PrevTokLocation);
2274 if (LParenLoc.isInvalid() || RParenLoc.isInvalid()) { 2342 if (LParenLoc.isInvalid() || RParenLoc.isInvalid()) {
2284 return ExprEmpty(); 2352 return ExprEmpty();
2285 } 2353 }
2286 } 2354 }
2287 2355
2288 isCastExpr = false; 2356 isCastExpr = false;
2289 if (OpTok.is(tok::kw_typeof) && !getLangOpts().CPlusPlus) { 2357 if (OpTok.isOneOf(tok::kw_typeof, tok::kw_typeof_unqual) &&
2358 !getLangOpts().CPlusPlus) {
2290 Diag(Tok, diag::err_expected_after) << OpTok.getIdentifierInfo() 2359 Diag(Tok, diag::err_expected_after) << OpTok.getIdentifierInfo()
2291 << tok::l_paren; 2360 << tok::l_paren;
2292 return ExprError(); 2361 return ExprError();
2293 } 2362 }
2294 2363
2310 if (ExprType == CastExpr) { 2379 if (ExprType == CastExpr) {
2311 isCastExpr = true; 2380 isCastExpr = true;
2312 return ExprEmpty(); 2381 return ExprEmpty();
2313 } 2382 }
2314 2383
2315 if (getLangOpts().CPlusPlus || OpTok.isNot(tok::kw_typeof)) { 2384 if (getLangOpts().CPlusPlus ||
2385 !OpTok.isOneOf(tok::kw_typeof, tok::kw_typeof_unqual)) {
2316 // GNU typeof in C requires the expression to be parenthesized. Not so for 2386 // GNU typeof in C requires the expression to be parenthesized. Not so for
2317 // sizeof/alignof or in C++. Therefore, the parenthesized expression is 2387 // sizeof/alignof or in C++. Therefore, the parenthesized expression is
2318 // the start of a unary-expression, but doesn't include any postfix 2388 // the start of a unary-expression, but doesn't include any postfix
2319 // pieces. Parse these now if present. 2389 // pieces. Parse these now if present.
2320 if (!Operand.isInvalid()) 2390 if (!Operand.isInvalid())
2329 2399
2330 /// Parse a __builtin_sycl_unique_stable_name expression. Accepts a type-id as 2400 /// Parse a __builtin_sycl_unique_stable_name expression. Accepts a type-id as
2331 /// a parameter. 2401 /// a parameter.
2332 ExprResult Parser::ParseSYCLUniqueStableNameExpression() { 2402 ExprResult Parser::ParseSYCLUniqueStableNameExpression() {
2333 assert(Tok.is(tok::kw___builtin_sycl_unique_stable_name) && 2403 assert(Tok.is(tok::kw___builtin_sycl_unique_stable_name) &&
2334 "Not __bulitin_sycl_unique_stable_name"); 2404 "Not __builtin_sycl_unique_stable_name");
2335 2405
2336 SourceLocation OpLoc = ConsumeToken(); 2406 SourceLocation OpLoc = ConsumeToken();
2337 BalancedDelimiterTracker T(*this, tok::l_paren); 2407 BalancedDelimiterTracker T(*this, tok::l_paren);
2338 2408
2339 // __builtin_sycl_unique_stable_name expressions are always parenthesized. 2409 // __builtin_sycl_unique_stable_name expressions are always parenthesized.
2478 /// [GNU] '__builtin_types_compatible_p' '(' type-name ',' type-name ')' 2548 /// [GNU] '__builtin_types_compatible_p' '(' type-name ',' type-name ')'
2479 /// [GNU] '__builtin_FILE' '(' ')' 2549 /// [GNU] '__builtin_FILE' '(' ')'
2480 /// [GNU] '__builtin_FUNCTION' '(' ')' 2550 /// [GNU] '__builtin_FUNCTION' '(' ')'
2481 /// [GNU] '__builtin_LINE' '(' ')' 2551 /// [GNU] '__builtin_LINE' '(' ')'
2482 /// [CLANG] '__builtin_COLUMN' '(' ')' 2552 /// [CLANG] '__builtin_COLUMN' '(' ')'
2553 /// [GNU] '__builtin_source_location' '(' ')'
2483 /// [OCL] '__builtin_astype' '(' assignment-expression ',' type-name ')' 2554 /// [OCL] '__builtin_astype' '(' assignment-expression ',' type-name ')'
2484 /// 2555 ///
2485 /// [GNU] offsetof-member-designator: 2556 /// [GNU] offsetof-member-designator:
2486 /// [GNU] identifier 2557 /// [GNU] identifier
2487 /// [GNU] offsetof-member-designator '.' identifier 2558 /// [GNU] offsetof-member-designator '.' identifier
2554 Comps.back().isBrackets = false; 2625 Comps.back().isBrackets = false;
2555 Comps.back().U.IdentInfo = Tok.getIdentifierInfo(); 2626 Comps.back().U.IdentInfo = Tok.getIdentifierInfo();
2556 Comps.back().LocStart = Comps.back().LocEnd = ConsumeToken(); 2627 Comps.back().LocStart = Comps.back().LocEnd = ConsumeToken();
2557 2628
2558 // FIXME: This loop leaks the index expressions on error. 2629 // FIXME: This loop leaks the index expressions on error.
2559 while (1) { 2630 while (true) {
2560 if (Tok.is(tok::period)) { 2631 if (Tok.is(tok::period)) {
2561 // offsetof-member-designator: offsetof-member-designator '.' identifier 2632 // offsetof-member-designator: offsetof-member-designator '.' identifier
2562 Comps.push_back(Sema::OffsetOfComponent()); 2633 Comps.push_back(Sema::OffsetOfComponent());
2563 Comps.back().isBrackets = false; 2634 Comps.back().isBrackets = false;
2564 Comps.back().LocStart = ConsumeToken(); 2635 Comps.back().LocStart = ConsumeToken();
2700 break; 2771 break;
2701 } 2772 }
2702 case tok::kw___builtin_COLUMN: 2773 case tok::kw___builtin_COLUMN:
2703 case tok::kw___builtin_FILE: 2774 case tok::kw___builtin_FILE:
2704 case tok::kw___builtin_FUNCTION: 2775 case tok::kw___builtin_FUNCTION:
2705 case tok::kw___builtin_LINE: { 2776 case tok::kw___builtin_LINE:
2777 case tok::kw___builtin_source_location: {
2706 // Attempt to consume the r-paren. 2778 // Attempt to consume the r-paren.
2707 if (Tok.isNot(tok::r_paren)) { 2779 if (Tok.isNot(tok::r_paren)) {
2708 Diag(Tok, diag::err_expected) << tok::r_paren; 2780 Diag(Tok, diag::err_expected) << tok::r_paren;
2709 SkipUntil(tok::r_paren, StopAtSemi); 2781 SkipUntil(tok::r_paren, StopAtSemi);
2710 return ExprError(); 2782 return ExprError();
2717 return SourceLocExpr::Function; 2789 return SourceLocExpr::Function;
2718 case tok::kw___builtin_LINE: 2790 case tok::kw___builtin_LINE:
2719 return SourceLocExpr::Line; 2791 return SourceLocExpr::Line;
2720 case tok::kw___builtin_COLUMN: 2792 case tok::kw___builtin_COLUMN:
2721 return SourceLocExpr::Column; 2793 return SourceLocExpr::Column;
2794 case tok::kw___builtin_source_location:
2795 return SourceLocExpr::SourceLocStruct;
2722 default: 2796 default:
2723 llvm_unreachable("invalid keyword"); 2797 llvm_unreachable("invalid keyword");
2724 } 2798 }
2725 }(); 2799 }();
2726 Res = Actions.ActOnSourceLocExpr(Kind, StartLoc, ConsumeParen()); 2800 Res = Actions.ActOnSourceLocExpr(Kind, StartLoc, ConsumeParen());
2834 } 2908 }
2835 2909
2836 // None of these cases should fall through with an invalid Result 2910 // None of these cases should fall through with an invalid Result
2837 // unless they've already reported an error. 2911 // unless they've already reported an error.
2838 if (ExprType >= CompoundStmt && Tok.is(tok::l_brace)) { 2912 if (ExprType >= CompoundStmt && Tok.is(tok::l_brace)) {
2839 Diag(Tok, diag::ext_gnu_statement_expr); 2913 Diag(Tok, OpenLoc.isMacroID() ? diag::ext_gnu_statement_expr_macro
2914 : diag::ext_gnu_statement_expr);
2840 2915
2841 checkCompoundToken(OpenLoc, tok::l_paren, CompoundToken::StmtExprBegin); 2916 checkCompoundToken(OpenLoc, tok::l_paren, CompoundToken::StmtExprBegin);
2842 2917
2843 if (!getCurScope()->getFnParent() && !getCurScope()->getBlockParent()) { 2918 if (!getCurScope()->getFnParent() && !getCurScope()->getBlockParent()) {
2844 Result = ExprError(Diag(OpenLoc, diag::err_stmtexpr_file_scope)); 2919 Result = ExprError(Diag(OpenLoc, diag::err_stmtexpr_file_scope));
2922 } 2997 }
2923 2998
2924 // Parse the type declarator. 2999 // Parse the type declarator.
2925 DeclSpec DS(AttrFactory); 3000 DeclSpec DS(AttrFactory);
2926 ParseSpecifierQualifierList(DS); 3001 ParseSpecifierQualifierList(DS);
2927 Declarator DeclaratorInfo(DS, DeclaratorContext::TypeName); 3002 Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
3003 DeclaratorContext::TypeName);
2928 ParseDeclarator(DeclaratorInfo); 3004 ParseDeclarator(DeclaratorInfo);
2929 3005
2930 // If our type is followed by an identifier and either ':' or ']', then 3006 // If our type is followed by an identifier and either ':' or ']', then
2931 // this is probably an Objective-C message send where the leading '[' is 3007 // this is probably an Objective-C message send where the leading '[' is
2932 // missing. Recover as if that were the case. 3008 // missing. Recover as if that were the case.
3239 } 3315 }
3240 DefaultLoc = ConsumeToken(); 3316 DefaultLoc = ConsumeToken();
3241 Ty = nullptr; 3317 Ty = nullptr;
3242 } else { 3318 } else {
3243 ColonProtectionRAIIObject X(*this); 3319 ColonProtectionRAIIObject X(*this);
3244 TypeResult TR = ParseTypeName(); 3320 TypeResult TR = ParseTypeName(nullptr, DeclaratorContext::Association);
3245 if (TR.isInvalid()) { 3321 if (TR.isInvalid()) {
3246 SkipUntil(tok::r_paren, StopAtSemi); 3322 SkipUntil(tok::r_paren, StopAtSemi);
3247 return ExprError(); 3323 return ExprError();
3248 } 3324 }
3249 Ty = TR.get(); 3325 Ty = TR.get();
3352 /// [C++0x] assignment-expression 3428 /// [C++0x] assignment-expression
3353 /// [C++0x] braced-init-list 3429 /// [C++0x] braced-init-list
3354 /// \endverbatim 3430 /// \endverbatim
3355 bool Parser::ParseExpressionList(SmallVectorImpl<Expr *> &Exprs, 3431 bool Parser::ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
3356 SmallVectorImpl<SourceLocation> &CommaLocs, 3432 SmallVectorImpl<SourceLocation> &CommaLocs,
3357 llvm::function_ref<void()> ExpressionStarts) { 3433 llvm::function_ref<void()> ExpressionStarts,
3434 bool FailImmediatelyOnInvalidExpr,
3435 bool EarlyTypoCorrection) {
3358 bool SawError = false; 3436 bool SawError = false;
3359 while (1) { 3437 while (true) {
3360 if (ExpressionStarts) 3438 if (ExpressionStarts)
3361 ExpressionStarts(); 3439 ExpressionStarts();
3362 3440
3363 ExprResult Expr; 3441 ExprResult Expr;
3364 if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { 3442 if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
3365 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); 3443 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
3366 Expr = ParseBraceInitializer(); 3444 Expr = ParseBraceInitializer();
3367 } else 3445 } else
3368 Expr = ParseAssignmentExpression(); 3446 Expr = ParseAssignmentExpression();
3447
3448 if (EarlyTypoCorrection)
3449 Expr = Actions.CorrectDelayedTyposInExpr(Expr);
3369 3450
3370 if (Tok.is(tok::ellipsis)) 3451 if (Tok.is(tok::ellipsis))
3371 Expr = Actions.ActOnPackExpansion(Expr.get(), ConsumeToken()); 3452 Expr = Actions.ActOnPackExpansion(Expr.get(), ConsumeToken());
3372 else if (Tok.is(tok::code_completion)) { 3453 else if (Tok.is(tok::code_completion)) {
3373 // There's nothing to suggest in here as we parsed a full expression. 3454 // There's nothing to suggest in here as we parsed a full expression.
3378 SawError = true; 3459 SawError = true;
3379 cutOffParsing(); 3460 cutOffParsing();
3380 break; 3461 break;
3381 } 3462 }
3382 if (Expr.isInvalid()) { 3463 if (Expr.isInvalid()) {
3464 SawError = true;
3465 if (FailImmediatelyOnInvalidExpr)
3466 break;
3383 SkipUntil(tok::comma, tok::r_paren, StopBeforeMatch); 3467 SkipUntil(tok::comma, tok::r_paren, StopBeforeMatch);
3384 SawError = true;
3385 } else { 3468 } else {
3386 Exprs.push_back(Expr.get()); 3469 Exprs.push_back(Expr.get());
3387 } 3470 }
3388 3471
3389 if (Tok.isNot(tok::comma)) 3472 if (Tok.isNot(tok::comma))
3414 /// simple-expression-list , assignment-expression 3497 /// simple-expression-list , assignment-expression
3415 /// \endverbatim 3498 /// \endverbatim
3416 bool 3499 bool
3417 Parser::ParseSimpleExpressionList(SmallVectorImpl<Expr*> &Exprs, 3500 Parser::ParseSimpleExpressionList(SmallVectorImpl<Expr*> &Exprs,
3418 SmallVectorImpl<SourceLocation> &CommaLocs) { 3501 SmallVectorImpl<SourceLocation> &CommaLocs) {
3419 while (1) { 3502 while (true) {
3420 ExprResult Expr = ParseAssignmentExpression(); 3503 ExprResult Expr = ParseAssignmentExpression();
3421 if (Expr.isInvalid()) 3504 if (Expr.isInvalid())
3422 return true; 3505 return true;
3423 3506
3424 Exprs.push_back(Expr.get()); 3507 Exprs.push_back(Expr.get());
3425 3508
3426 if (Tok.isNot(tok::comma)) 3509 // We might be parsing the LHS of a fold-expression. If we reached the fold
3510 // operator, stop.
3511 if (Tok.isNot(tok::comma) || NextToken().is(tok::ellipsis))
3427 return false; 3512 return false;
3428 3513
3429 // Move to the next argument, remember where the comma was. 3514 // Move to the next argument, remember where the comma was.
3430 Token Comma = Tok; 3515 Token Comma = Tok;
3431 CommaLocs.push_back(ConsumeToken()); 3516 CommaLocs.push_back(ConsumeToken());
3450 // Parse the specifier-qualifier-list piece. 3535 // Parse the specifier-qualifier-list piece.
3451 DeclSpec DS(AttrFactory); 3536 DeclSpec DS(AttrFactory);
3452 ParseSpecifierQualifierList(DS); 3537 ParseSpecifierQualifierList(DS);
3453 3538
3454 // Parse the block-declarator. 3539 // Parse the block-declarator.
3455 Declarator DeclaratorInfo(DS, DeclaratorContext::BlockLiteral); 3540 Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
3541 DeclaratorContext::BlockLiteral);
3456 DeclaratorInfo.setFunctionDefinitionKind(FunctionDefinitionKind::Definition); 3542 DeclaratorInfo.setFunctionDefinitionKind(FunctionDefinitionKind::Definition);
3457 ParseDeclarator(DeclaratorInfo); 3543 ParseDeclarator(DeclaratorInfo);
3458 3544
3459 MaybeParseGNUAttributes(DeclaratorInfo); 3545 MaybeParseGNUAttributes(DeclaratorInfo);
3460 3546
3489 // Inform sema that we are starting a block. 3575 // Inform sema that we are starting a block.
3490 Actions.ActOnBlockStart(CaretLoc, getCurScope()); 3576 Actions.ActOnBlockStart(CaretLoc, getCurScope());
3491 3577
3492 // Parse the return type if present. 3578 // Parse the return type if present.
3493 DeclSpec DS(AttrFactory); 3579 DeclSpec DS(AttrFactory);
3494 Declarator ParamInfo(DS, DeclaratorContext::BlockLiteral); 3580 Declarator ParamInfo(DS, ParsedAttributesView::none(),
3581 DeclaratorContext::BlockLiteral);
3495 ParamInfo.setFunctionDefinitionKind(FunctionDefinitionKind::Definition); 3582 ParamInfo.setFunctionDefinitionKind(FunctionDefinitionKind::Definition);
3496 // FIXME: Since the return type isn't actually parsed, it can't be used to 3583 // FIXME: Since the return type isn't actually parsed, it can't be used to
3497 // fill ParamInfo with an initial valid range, so do it manually. 3584 // fill ParamInfo with an initial valid range, so do it manually.
3498 ParamInfo.SetSourceRange(SourceRange(Tok.getLocation(), Tok.getLocation())); 3585 ParamInfo.SetSourceRange(SourceRange(Tok.getLocation(), Tok.getLocation()));
3499 3586