1 /* Parser for C and Objective-C. 2 Copyright (C) 1987-2016 Free Software Foundation, Inc. 3 4 Parser actions based on the old Bison parser; structure somewhat 5 influenced by and fragments based on the C++ parser. 6 7 This file is part of GCC. 8 9 GCC is free software; you can redistribute it and/or modify it under 10 the terms of the GNU General Public License as published by the Free 11 Software Foundation; either version 3, or (at your option) any later 12 version. 13 14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY 15 WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17 for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with GCC; see the file COPYING3. If not see 21 <http://www.gnu.org/licenses/>. */ 22 23 /* TODO: 24 25 Make sure all relevant comments, and all relevant code from all 26 actions, brought over from old parser. Verify exact correspondence 27 of syntax accepted. 28 29 Add testcases covering every input symbol in every state in old and 30 new parsers. 31 32 Include full syntax for GNU C, including erroneous cases accepted 33 with error messages, in syntax productions in comments. 34 35 Make more diagnostics in the front end generally take an explicit 36 location rather than implicitly using input_location. */ 37 38 #include "config.h" 39 #include "system.h" 40 #include "coretypes.h" 41 #include "target.h" 42 #include "function.h" 43 #include "c-tree.h" 44 #include "timevar.h" 45 #include "stringpool.h" 46 #include "cgraph.h" 47 #include "attribs.h" 48 #include "stor-layout.h" 49 #include "varasm.h" 50 #include "trans-mem.h" 51 #include "c-family/c-pragma.h" 52 #include "c-lang.h" 53 #include "c-family/c-objc.h" 54 #include "plugin.h" 55 #include "omp-low.h" 56 #include "builtins.h" 57 #include "gomp-constants.h" 58 #include "c-family/c-indentation.h" 59 #include "gimple-expr.h" 60 #include "context.h" 61 62 /* We need to walk over decls with incomplete struct/union/enum types 63 after parsing the whole translation unit. 64 In finish_decl(), if the decl is static, has incomplete 65 struct/union/enum type, it is appeneded to incomplete_record_decls. 66 In c_parser_translation_unit(), we iterate over incomplete_record_decls 67 and report error if any of the decls are still incomplete. */ 68 69 vec<tree> incomplete_record_decls = vNULL; 70 71 void 72 set_c_expr_source_range (c_expr *expr, 73 location_t start, location_t finish) 74 { 75 expr->src_range.m_start = start; 76 expr->src_range.m_finish = finish; 77 if (expr->value) 78 set_source_range (expr->value, start, finish); 79 } 80 81 void 82 set_c_expr_source_range (c_expr *expr, 83 source_range src_range) 84 { 85 expr->src_range = src_range; 86 if (expr->value) 87 set_source_range (expr->value, src_range); 88 } 89 90 91 /* Initialization routine for this file. */ 92 93 void 94 c_parse_init (void) 95 { 96 /* The only initialization required is of the reserved word 97 identifiers. */ 98 unsigned int i; 99 tree id; 100 int mask = 0; 101 102 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in 103 the c_token structure. */ 104 gcc_assert (RID_MAX <= 255); 105 106 mask |= D_CXXONLY; 107 if (!flag_isoc99) 108 mask |= D_C99; 109 if (flag_no_asm) 110 { 111 mask |= D_ASM | D_EXT; 112 if (!flag_isoc99) 113 mask |= D_EXT89; 114 } 115 if (!c_dialect_objc ()) 116 mask |= D_OBJC | D_CXX_OBJC; 117 118 ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX); 119 for (i = 0; i < num_c_common_reswords; i++) 120 { 121 /* If a keyword is disabled, do not enter it into the table 122 and so create a canonical spelling that isn't a keyword. */ 123 if (c_common_reswords[i].disable & mask) 124 { 125 if (warn_cxx_compat 126 && (c_common_reswords[i].disable & D_CXXWARN)) 127 { 128 id = get_identifier (c_common_reswords[i].word); 129 C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN); 130 C_IS_RESERVED_WORD (id) = 1; 131 } 132 continue; 133 } 134 135 id = get_identifier (c_common_reswords[i].word); 136 C_SET_RID_CODE (id, c_common_reswords[i].rid); 137 C_IS_RESERVED_WORD (id) = 1; 138 ridpointers [(int) c_common_reswords[i].rid] = id; 139 } 140 141 for (i = 0; i < NUM_INT_N_ENTS; i++) 142 { 143 /* We always create the symbols but they aren't always supported. */ 144 char name[50]; 145 sprintf (name, "__int%d", int_n_data[i].bitsize); 146 id = get_identifier (name); 147 C_SET_RID_CODE (id, RID_FIRST_INT_N + i); 148 C_IS_RESERVED_WORD (id) = 1; 149 } 150 } 151 152 /* The C lexer intermediates between the lexer in cpplib and c-lex.c 153 and the C parser. Unlike the C++ lexer, the parser structure 154 stores the lexer information instead of using a separate structure. 155 Identifiers are separated into ordinary identifiers, type names, 156 keywords and some other Objective-C types of identifiers, and some 157 look-ahead is maintained. 158 159 ??? It might be a good idea to lex the whole file up front (as for 160 C++). It would then be possible to share more of the C and C++ 161 lexer code, if desired. */ 162 163 /* More information about the type of a CPP_NAME token. */ 164 enum c_id_kind { 165 /* An ordinary identifier. */ 166 C_ID_ID, 167 /* An identifier declared as a typedef name. */ 168 C_ID_TYPENAME, 169 /* An identifier declared as an Objective-C class name. */ 170 C_ID_CLASSNAME, 171 /* An address space identifier. */ 172 C_ID_ADDRSPACE, 173 /* Not an identifier. */ 174 C_ID_NONE 175 }; 176 177 /* A single C token after string literal concatenation and conversion 178 of preprocessing tokens to tokens. */ 179 struct GTY (()) c_token { 180 /* The kind of token. */ 181 ENUM_BITFIELD (cpp_ttype) type : 8; 182 /* If this token is a CPP_NAME, this value indicates whether also 183 declared as some kind of type. Otherwise, it is C_ID_NONE. */ 184 ENUM_BITFIELD (c_id_kind) id_kind : 8; 185 /* If this token is a keyword, this value indicates which keyword. 186 Otherwise, this value is RID_MAX. */ 187 ENUM_BITFIELD (rid) keyword : 8; 188 /* If this token is a CPP_PRAGMA, this indicates the pragma that 189 was seen. Otherwise it is PRAGMA_NONE. */ 190 ENUM_BITFIELD (pragma_kind) pragma_kind : 8; 191 /* The location at which this token was found. */ 192 location_t location; 193 /* The value associated with this token, if any. */ 194 tree value; 195 196 source_range get_range () const 197 { 198 return get_range_from_loc (line_table, location); 199 } 200 201 location_t get_finish () const 202 { 203 return get_range ().m_finish; 204 } 205 }; 206 207 /* A parser structure recording information about the state and 208 context of parsing. Includes lexer information with up to two 209 tokens of look-ahead; more are not needed for C. */ 210 struct GTY(()) c_parser { 211 /* The look-ahead tokens. */ 212 c_token * GTY((skip)) tokens; 213 /* Buffer for look-ahead tokens. */ 214 c_token tokens_buf[4]; 215 /* How many look-ahead tokens are available (0 - 4, or 216 more if parsing from pre-lexed tokens). */ 217 unsigned int tokens_avail; 218 /* True if a syntax error is being recovered from; false otherwise. 219 c_parser_error sets this flag. It should clear this flag when 220 enough tokens have been consumed to recover from the error. */ 221 BOOL_BITFIELD error : 1; 222 /* True if we're processing a pragma, and shouldn't automatically 223 consume CPP_PRAGMA_EOL. */ 224 BOOL_BITFIELD in_pragma : 1; 225 /* True if we're parsing the outermost block of an if statement. */ 226 BOOL_BITFIELD in_if_block : 1; 227 /* True if we want to lex an untranslated string. */ 228 BOOL_BITFIELD lex_untranslated_string : 1; 229 230 /* Objective-C specific parser/lexer information. */ 231 232 /* True if we are in a context where the Objective-C "PQ" keywords 233 are considered keywords. */ 234 BOOL_BITFIELD objc_pq_context : 1; 235 /* True if we are parsing a (potential) Objective-C foreach 236 statement. This is set to true after we parsed 'for (' and while 237 we wait for 'in' or ';' to decide if it's a standard C for loop or an 238 Objective-C foreach loop. */ 239 BOOL_BITFIELD objc_could_be_foreach_context : 1; 240 /* The following flag is needed to contextualize Objective-C lexical 241 analysis. In some cases (e.g., 'int NSObject;'), it is 242 undesirable to bind an identifier to an Objective-C class, even 243 if a class with that name exists. */ 244 BOOL_BITFIELD objc_need_raw_identifier : 1; 245 /* Nonzero if we're processing a __transaction statement. The value 246 is 1 | TM_STMT_ATTR_*. */ 247 unsigned int in_transaction : 4; 248 /* True if we are in a context where the Objective-C "Property attribute" 249 keywords are valid. */ 250 BOOL_BITFIELD objc_property_attr_context : 1; 251 252 /* Cilk Plus specific parser/lexer information. */ 253 254 /* Buffer to hold all the tokens from parsing the vector attribute for the 255 SIMD-enabled functions (formerly known as elemental functions). */ 256 vec <c_token, va_gc> *cilk_simd_fn_tokens; 257 }; 258 259 260 /* The actual parser and external interface. ??? Does this need to be 261 garbage-collected? */ 262 263 static GTY (()) c_parser *the_parser; 264 265 /* Read in and lex a single token, storing it in *TOKEN. */ 266 267 static void 268 c_lex_one_token (c_parser *parser, c_token *token) 269 { 270 timevar_push (TV_LEX); 271 272 token->type = c_lex_with_flags (&token->value, &token->location, NULL, 273 (parser->lex_untranslated_string 274 ? C_LEX_STRING_NO_TRANSLATE : 0)); 275 token->id_kind = C_ID_NONE; 276 token->keyword = RID_MAX; 277 token->pragma_kind = PRAGMA_NONE; 278 279 switch (token->type) 280 { 281 case CPP_NAME: 282 { 283 tree decl; 284 285 bool objc_force_identifier = parser->objc_need_raw_identifier; 286 if (c_dialect_objc ()) 287 parser->objc_need_raw_identifier = false; 288 289 if (C_IS_RESERVED_WORD (token->value)) 290 { 291 enum rid rid_code = C_RID_CODE (token->value); 292 293 if (rid_code == RID_CXX_COMPAT_WARN) 294 { 295 warning_at (token->location, 296 OPT_Wc___compat, 297 "identifier %qE conflicts with C++ keyword", 298 token->value); 299 } 300 else if (rid_code >= RID_FIRST_ADDR_SPACE 301 && rid_code <= RID_LAST_ADDR_SPACE) 302 { 303 token->id_kind = C_ID_ADDRSPACE; 304 token->keyword = rid_code; 305 break; 306 } 307 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code)) 308 { 309 /* We found an Objective-C "pq" keyword (in, out, 310 inout, bycopy, byref, oneway). They need special 311 care because the interpretation depends on the 312 context. */ 313 if (parser->objc_pq_context) 314 { 315 token->type = CPP_KEYWORD; 316 token->keyword = rid_code; 317 break; 318 } 319 else if (parser->objc_could_be_foreach_context 320 && rid_code == RID_IN) 321 { 322 /* We are in Objective-C, inside a (potential) 323 foreach context (which means after having 324 parsed 'for (', but before having parsed ';'), 325 and we found 'in'. We consider it the keyword 326 which terminates the declaration at the 327 beginning of a foreach-statement. Note that 328 this means you can't use 'in' for anything else 329 in that context; in particular, in Objective-C 330 you can't use 'in' as the name of the running 331 variable in a C for loop. We could potentially 332 try to add code here to disambiguate, but it 333 seems a reasonable limitation. */ 334 token->type = CPP_KEYWORD; 335 token->keyword = rid_code; 336 break; 337 } 338 /* Else, "pq" keywords outside of the "pq" context are 339 not keywords, and we fall through to the code for 340 normal tokens. */ 341 } 342 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code)) 343 { 344 /* We found an Objective-C "property attribute" 345 keyword (getter, setter, readonly, etc). These are 346 only valid in the property context. */ 347 if (parser->objc_property_attr_context) 348 { 349 token->type = CPP_KEYWORD; 350 token->keyword = rid_code; 351 break; 352 } 353 /* Else they are not special keywords. 354 */ 355 } 356 else if (c_dialect_objc () 357 && (OBJC_IS_AT_KEYWORD (rid_code) 358 || OBJC_IS_CXX_KEYWORD (rid_code))) 359 { 360 /* We found one of the Objective-C "@" keywords (defs, 361 selector, synchronized, etc) or one of the 362 Objective-C "cxx" keywords (class, private, 363 protected, public, try, catch, throw) without a 364 preceding '@' sign. Do nothing and fall through to 365 the code for normal tokens (in C++ we would still 366 consider the CXX ones keywords, but not in C). */ 367 ; 368 } 369 else 370 { 371 token->type = CPP_KEYWORD; 372 token->keyword = rid_code; 373 break; 374 } 375 } 376 377 decl = lookup_name (token->value); 378 if (decl) 379 { 380 if (TREE_CODE (decl) == TYPE_DECL) 381 { 382 token->id_kind = C_ID_TYPENAME; 383 break; 384 } 385 } 386 else if (c_dialect_objc ()) 387 { 388 tree objc_interface_decl = objc_is_class_name (token->value); 389 /* Objective-C class names are in the same namespace as 390 variables and typedefs, and hence are shadowed by local 391 declarations. */ 392 if (objc_interface_decl 393 && (!objc_force_identifier || global_bindings_p ())) 394 { 395 token->value = objc_interface_decl; 396 token->id_kind = C_ID_CLASSNAME; 397 break; 398 } 399 } 400 token->id_kind = C_ID_ID; 401 } 402 break; 403 case CPP_AT_NAME: 404 /* This only happens in Objective-C; it must be a keyword. */ 405 token->type = CPP_KEYWORD; 406 switch (C_RID_CODE (token->value)) 407 { 408 /* Replace 'class' with '@class', 'private' with '@private', 409 etc. This prevents confusion with the C++ keyword 410 'class', and makes the tokens consistent with other 411 Objective-C 'AT' keywords. For example '@class' is 412 reported as RID_AT_CLASS which is consistent with 413 '@synchronized', which is reported as 414 RID_AT_SYNCHRONIZED. 415 */ 416 case RID_CLASS: token->keyword = RID_AT_CLASS; break; 417 case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break; 418 case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break; 419 case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break; 420 case RID_THROW: token->keyword = RID_AT_THROW; break; 421 case RID_TRY: token->keyword = RID_AT_TRY; break; 422 case RID_CATCH: token->keyword = RID_AT_CATCH; break; 423 case RID_SYNCHRONIZED: token->keyword = RID_AT_SYNCHRONIZED; break; 424 default: token->keyword = C_RID_CODE (token->value); 425 } 426 break; 427 case CPP_COLON: 428 case CPP_COMMA: 429 case CPP_CLOSE_PAREN: 430 case CPP_SEMICOLON: 431 /* These tokens may affect the interpretation of any identifiers 432 following, if doing Objective-C. */ 433 if (c_dialect_objc ()) 434 parser->objc_need_raw_identifier = false; 435 break; 436 case CPP_PRAGMA: 437 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */ 438 token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value); 439 token->value = NULL; 440 break; 441 default: 442 break; 443 } 444 timevar_pop (TV_LEX); 445 } 446 447 /* Return a pointer to the next token from PARSER, reading it in if 448 necessary. */ 449 450 static inline c_token * 451 c_parser_peek_token (c_parser *parser) 452 { 453 if (parser->tokens_avail == 0) 454 { 455 c_lex_one_token (parser, &parser->tokens[0]); 456 parser->tokens_avail = 1; 457 } 458 return &parser->tokens[0]; 459 } 460 461 /* Return true if the next token from PARSER has the indicated 462 TYPE. */ 463 464 static inline bool 465 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type) 466 { 467 return c_parser_peek_token (parser)->type == type; 468 } 469 470 /* Return true if the next token from PARSER does not have the 471 indicated TYPE. */ 472 473 static inline bool 474 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type) 475 { 476 return !c_parser_next_token_is (parser, type); 477 } 478 479 /* Return true if the next token from PARSER is the indicated 480 KEYWORD. */ 481 482 static inline bool 483 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword) 484 { 485 return c_parser_peek_token (parser)->keyword == keyword; 486 } 487 488 /* Return a pointer to the next-but-one token from PARSER, reading it 489 in if necessary. The next token is already read in. */ 490 491 static c_token * 492 c_parser_peek_2nd_token (c_parser *parser) 493 { 494 if (parser->tokens_avail >= 2) 495 return &parser->tokens[1]; 496 gcc_assert (parser->tokens_avail == 1); 497 gcc_assert (parser->tokens[0].type != CPP_EOF); 498 gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL); 499 c_lex_one_token (parser, &parser->tokens[1]); 500 parser->tokens_avail = 2; 501 return &parser->tokens[1]; 502 } 503 504 /* Return a pointer to the Nth token from PARSER, reading it 505 in if necessary. The N-1th token is already read in. */ 506 507 static c_token * 508 c_parser_peek_nth_token (c_parser *parser, unsigned int n) 509 { 510 /* N is 1-based, not zero-based. */ 511 gcc_assert (n > 0); 512 513 if (parser->tokens_avail >= n) 514 return &parser->tokens[n - 1]; 515 gcc_assert (parser->tokens_avail == n - 1); 516 c_lex_one_token (parser, &parser->tokens[n - 1]); 517 parser->tokens_avail = n; 518 return &parser->tokens[n - 1]; 519 } 520 521 /* Return true if TOKEN can start a type name, 522 false otherwise. */ 523 static bool 524 c_token_starts_typename (c_token *token) 525 { 526 switch (token->type) 527 { 528 case CPP_NAME: 529 switch (token->id_kind) 530 { 531 case C_ID_ID: 532 return false; 533 case C_ID_ADDRSPACE: 534 return true; 535 case C_ID_TYPENAME: 536 return true; 537 case C_ID_CLASSNAME: 538 gcc_assert (c_dialect_objc ()); 539 return true; 540 default: 541 gcc_unreachable (); 542 } 543 case CPP_KEYWORD: 544 switch (token->keyword) 545 { 546 case RID_UNSIGNED: 547 case RID_LONG: 548 case RID_SHORT: 549 case RID_SIGNED: 550 case RID_COMPLEX: 551 case RID_INT: 552 case RID_CHAR: 553 case RID_FLOAT: 554 case RID_DOUBLE: 555 case RID_VOID: 556 case RID_DFLOAT32: 557 case RID_DFLOAT64: 558 case RID_DFLOAT128: 559 case RID_BOOL: 560 case RID_ENUM: 561 case RID_STRUCT: 562 case RID_UNION: 563 case RID_TYPEOF: 564 case RID_CONST: 565 case RID_ATOMIC: 566 case RID_VOLATILE: 567 case RID_RESTRICT: 568 case RID_ATTRIBUTE: 569 case RID_FRACT: 570 case RID_ACCUM: 571 case RID_SAT: 572 case RID_AUTO_TYPE: 573 return true; 574 default: 575 if (token->keyword >= RID_FIRST_INT_N 576 && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS 577 && int_n_enabled_p[token->keyword - RID_FIRST_INT_N]) 578 return true; 579 return false; 580 } 581 case CPP_LESS: 582 if (c_dialect_objc ()) 583 return true; 584 return false; 585 default: 586 return false; 587 } 588 } 589 590 enum c_lookahead_kind { 591 /* Always treat unknown identifiers as typenames. */ 592 cla_prefer_type, 593 594 /* Could be parsing a nonabstract declarator. Only treat an identifier 595 as a typename if followed by another identifier or a star. */ 596 cla_nonabstract_decl, 597 598 /* Never treat identifiers as typenames. */ 599 cla_prefer_id 600 }; 601 602 /* Return true if the next token from PARSER can start a type name, 603 false otherwise. LA specifies how to do lookahead in order to 604 detect unknown type names. If unsure, pick CLA_PREFER_ID. */ 605 606 static inline bool 607 c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la) 608 { 609 c_token *token = c_parser_peek_token (parser); 610 if (c_token_starts_typename (token)) 611 return true; 612 613 /* Try a bit harder to detect an unknown typename. */ 614 if (la != cla_prefer_id 615 && token->type == CPP_NAME 616 && token->id_kind == C_ID_ID 617 618 /* Do not try too hard when we could have "object in array". */ 619 && !parser->objc_could_be_foreach_context 620 621 && (la == cla_prefer_type 622 || c_parser_peek_2nd_token (parser)->type == CPP_NAME 623 || c_parser_peek_2nd_token (parser)->type == CPP_MULT) 624 625 /* Only unknown identifiers. */ 626 && !lookup_name (token->value)) 627 return true; 628 629 return false; 630 } 631 632 /* Return true if TOKEN is a type qualifier, false otherwise. */ 633 static bool 634 c_token_is_qualifier (c_token *token) 635 { 636 switch (token->type) 637 { 638 case CPP_NAME: 639 switch (token->id_kind) 640 { 641 case C_ID_ADDRSPACE: 642 return true; 643 default: 644 return false; 645 } 646 case CPP_KEYWORD: 647 switch (token->keyword) 648 { 649 case RID_CONST: 650 case RID_VOLATILE: 651 case RID_RESTRICT: 652 case RID_ATTRIBUTE: 653 case RID_ATOMIC: 654 return true; 655 default: 656 return false; 657 } 658 case CPP_LESS: 659 return false; 660 default: 661 gcc_unreachable (); 662 } 663 } 664 665 /* Return true if the next token from PARSER is a type qualifier, 666 false otherwise. */ 667 static inline bool 668 c_parser_next_token_is_qualifier (c_parser *parser) 669 { 670 c_token *token = c_parser_peek_token (parser); 671 return c_token_is_qualifier (token); 672 } 673 674 /* Return true if TOKEN can start declaration specifiers, false 675 otherwise. */ 676 static bool 677 c_token_starts_declspecs (c_token *token) 678 { 679 switch (token->type) 680 { 681 case CPP_NAME: 682 switch (token->id_kind) 683 { 684 case C_ID_ID: 685 return false; 686 case C_ID_ADDRSPACE: 687 return true; 688 case C_ID_TYPENAME: 689 return true; 690 case C_ID_CLASSNAME: 691 gcc_assert (c_dialect_objc ()); 692 return true; 693 default: 694 gcc_unreachable (); 695 } 696 case CPP_KEYWORD: 697 switch (token->keyword) 698 { 699 case RID_STATIC: 700 case RID_EXTERN: 701 case RID_REGISTER: 702 case RID_TYPEDEF: 703 case RID_INLINE: 704 case RID_NORETURN: 705 case RID_AUTO: 706 case RID_THREAD: 707 case RID_UNSIGNED: 708 case RID_LONG: 709 case RID_SHORT: 710 case RID_SIGNED: 711 case RID_COMPLEX: 712 case RID_INT: 713 case RID_CHAR: 714 case RID_FLOAT: 715 case RID_DOUBLE: 716 case RID_VOID: 717 case RID_DFLOAT32: 718 case RID_DFLOAT64: 719 case RID_DFLOAT128: 720 case RID_BOOL: 721 case RID_ENUM: 722 case RID_STRUCT: 723 case RID_UNION: 724 case RID_TYPEOF: 725 case RID_CONST: 726 case RID_VOLATILE: 727 case RID_RESTRICT: 728 case RID_ATTRIBUTE: 729 case RID_FRACT: 730 case RID_ACCUM: 731 case RID_SAT: 732 case RID_ALIGNAS: 733 case RID_ATOMIC: 734 case RID_AUTO_TYPE: 735 return true; 736 default: 737 if (token->keyword >= RID_FIRST_INT_N 738 && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS 739 && int_n_enabled_p[token->keyword - RID_FIRST_INT_N]) 740 return true; 741 return false; 742 } 743 case CPP_LESS: 744 if (c_dialect_objc ()) 745 return true; 746 return false; 747 default: 748 return false; 749 } 750 } 751 752 753 /* Return true if TOKEN can start declaration specifiers or a static 754 assertion, false otherwise. */ 755 static bool 756 c_token_starts_declaration (c_token *token) 757 { 758 if (c_token_starts_declspecs (token) 759 || token->keyword == RID_STATIC_ASSERT) 760 return true; 761 else 762 return false; 763 } 764 765 /* Return true if the next token from PARSER can start declaration 766 specifiers, false otherwise. */ 767 static inline bool 768 c_parser_next_token_starts_declspecs (c_parser *parser) 769 { 770 c_token *token = c_parser_peek_token (parser); 771 772 /* In Objective-C, a classname normally starts a declspecs unless it 773 is immediately followed by a dot. In that case, it is the 774 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the 775 setter/getter on the class. c_token_starts_declspecs() can't 776 differentiate between the two cases because it only checks the 777 current token, so we have a special check here. */ 778 if (c_dialect_objc () 779 && token->type == CPP_NAME 780 && token->id_kind == C_ID_CLASSNAME 781 && c_parser_peek_2nd_token (parser)->type == CPP_DOT) 782 return false; 783 784 return c_token_starts_declspecs (token); 785 } 786 787 /* Return true if the next tokens from PARSER can start declaration 788 specifiers or a static assertion, false otherwise. */ 789 static inline bool 790 c_parser_next_tokens_start_declaration (c_parser *parser) 791 { 792 c_token *token = c_parser_peek_token (parser); 793 794 /* Same as above. */ 795 if (c_dialect_objc () 796 && token->type == CPP_NAME 797 && token->id_kind == C_ID_CLASSNAME 798 && c_parser_peek_2nd_token (parser)->type == CPP_DOT) 799 return false; 800 801 /* Labels do not start declarations. */ 802 if (token->type == CPP_NAME 803 && c_parser_peek_2nd_token (parser)->type == CPP_COLON) 804 return false; 805 806 if (c_token_starts_declaration (token)) 807 return true; 808 809 if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl)) 810 return true; 811 812 return false; 813 } 814 815 /* Consume the next token from PARSER. */ 816 817 static void 818 c_parser_consume_token (c_parser *parser) 819 { 820 gcc_assert (parser->tokens_avail >= 1); 821 gcc_assert (parser->tokens[0].type != CPP_EOF); 822 gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL); 823 gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA); 824 if (parser->tokens != &parser->tokens_buf[0]) 825 parser->tokens++; 826 else if (parser->tokens_avail == 2) 827 parser->tokens[0] = parser->tokens[1]; 828 parser->tokens_avail--; 829 } 830 831 /* Expect the current token to be a #pragma. Consume it and remember 832 that we've begun parsing a pragma. */ 833 834 static void 835 c_parser_consume_pragma (c_parser *parser) 836 { 837 gcc_assert (!parser->in_pragma); 838 gcc_assert (parser->tokens_avail >= 1); 839 gcc_assert (parser->tokens[0].type == CPP_PRAGMA); 840 if (parser->tokens != &parser->tokens_buf[0]) 841 parser->tokens++; 842 else if (parser->tokens_avail == 2) 843 parser->tokens[0] = parser->tokens[1]; 844 parser->tokens_avail--; 845 parser->in_pragma = true; 846 } 847 848 /* Update the global input_location from TOKEN. */ 849 static inline void 850 c_parser_set_source_position_from_token (c_token *token) 851 { 852 if (token->type != CPP_EOF) 853 { 854 input_location = token->location; 855 } 856 } 857 858 /* Helper function for c_parser_error. 859 Having peeked a token of kind TOK1_KIND that might signify 860 a conflict marker, peek successor tokens to determine 861 if we actually do have a conflict marker. 862 Specifically, we consider a run of 7 '<', '=' or '>' characters 863 at the start of a line as a conflict marker. 864 These come through the lexer as three pairs and a single, 865 e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<'). 866 If it returns true, *OUT_LOC is written to with the location/range 867 of the marker. */ 868 869 static bool 870 c_parser_peek_conflict_marker (c_parser *parser, enum cpp_ttype tok1_kind, 871 location_t *out_loc) 872 { 873 c_token *token2 = c_parser_peek_2nd_token (parser); 874 if (token2->type != tok1_kind) 875 return false; 876 c_token *token3 = c_parser_peek_nth_token (parser, 3); 877 if (token3->type != tok1_kind) 878 return false; 879 c_token *token4 = c_parser_peek_nth_token (parser, 4); 880 if (token4->type != conflict_marker_get_final_tok_kind (tok1_kind)) 881 return false; 882 883 /* It must be at the start of the line. */ 884 location_t start_loc = c_parser_peek_token (parser)->location; 885 if (LOCATION_COLUMN (start_loc) != 1) 886 return false; 887 888 /* We have a conflict marker. Construct a location of the form: 889 <<<<<<< 890 ^~~~~~~ 891 with start == caret, finishing at the end of the marker. */ 892 location_t finish_loc = get_finish (token4->location); 893 *out_loc = make_location (start_loc, start_loc, finish_loc); 894 895 return true; 896 } 897 898 /* Issue a diagnostic of the form 899 FILE:LINE: MESSAGE before TOKEN 900 where TOKEN is the next token in the input stream of PARSER. 901 MESSAGE (specified by the caller) is usually of the form "expected 902 OTHER-TOKEN". 903 904 Do not issue a diagnostic if still recovering from an error. 905 906 ??? This is taken from the C++ parser, but building up messages in 907 this way is not i18n-friendly and some other approach should be 908 used. */ 909 910 static void 911 c_parser_error (c_parser *parser, const char *gmsgid) 912 { 913 c_token *token = c_parser_peek_token (parser); 914 if (parser->error) 915 return; 916 parser->error = true; 917 if (!gmsgid) 918 return; 919 920 /* If this is actually a conflict marker, report it as such. */ 921 if (token->type == CPP_LSHIFT 922 || token->type == CPP_RSHIFT 923 || token->type == CPP_EQ_EQ) 924 { 925 location_t loc; 926 if (c_parser_peek_conflict_marker (parser, token->type, &loc)) 927 { 928 error_at (loc, "version control conflict marker in file"); 929 return; 930 } 931 } 932 933 /* This diagnostic makes more sense if it is tagged to the line of 934 the token we just peeked at. */ 935 c_parser_set_source_position_from_token (token); 936 c_parse_error (gmsgid, 937 /* Because c_parse_error does not understand 938 CPP_KEYWORD, keywords are treated like 939 identifiers. */ 940 (token->type == CPP_KEYWORD ? CPP_NAME : token->type), 941 /* ??? The C parser does not save the cpp flags of a 942 token, we need to pass 0 here and we will not get 943 the source spelling of some tokens but rather the 944 canonical spelling. */ 945 token->value, /*flags=*/0); 946 } 947 948 /* If the next token is of the indicated TYPE, consume it. Otherwise, 949 issue the error MSGID. If MSGID is NULL then a message has already 950 been produced and no message will be produced this time. Returns 951 true if found, false otherwise. */ 952 953 static bool 954 c_parser_require (c_parser *parser, 955 enum cpp_ttype type, 956 const char *msgid) 957 { 958 if (c_parser_next_token_is (parser, type)) 959 { 960 c_parser_consume_token (parser); 961 return true; 962 } 963 else 964 { 965 c_parser_error (parser, msgid); 966 return false; 967 } 968 } 969 970 /* If the next token is the indicated keyword, consume it. Otherwise, 971 issue the error MSGID. Returns true if found, false otherwise. */ 972 973 static bool 974 c_parser_require_keyword (c_parser *parser, 975 enum rid keyword, 976 const char *msgid) 977 { 978 if (c_parser_next_token_is_keyword (parser, keyword)) 979 { 980 c_parser_consume_token (parser); 981 return true; 982 } 983 else 984 { 985 c_parser_error (parser, msgid); 986 return false; 987 } 988 } 989 990 /* Like c_parser_require, except that tokens will be skipped until the 991 desired token is found. An error message is still produced if the 992 next token is not as expected. If MSGID is NULL then a message has 993 already been produced and no message will be produced this 994 time. */ 995 996 static void 997 c_parser_skip_until_found (c_parser *parser, 998 enum cpp_ttype type, 999 const char *msgid) 1000 { 1001 unsigned nesting_depth = 0; 1002 1003 if (c_parser_require (parser, type, msgid)) 1004 return; 1005 1006 /* Skip tokens until the desired token is found. */ 1007 while (true) 1008 { 1009 /* Peek at the next token. */ 1010 c_token *token = c_parser_peek_token (parser); 1011 /* If we've reached the token we want, consume it and stop. */ 1012 if (token->type == type && !nesting_depth) 1013 { 1014 c_parser_consume_token (parser); 1015 break; 1016 } 1017 1018 /* If we've run out of tokens, stop. */ 1019 if (token->type == CPP_EOF) 1020 return; 1021 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma) 1022 return; 1023 if (token->type == CPP_OPEN_BRACE 1024 || token->type == CPP_OPEN_PAREN 1025 || token->type == CPP_OPEN_SQUARE) 1026 ++nesting_depth; 1027 else if (token->type == CPP_CLOSE_BRACE 1028 || token->type == CPP_CLOSE_PAREN 1029 || token->type == CPP_CLOSE_SQUARE) 1030 { 1031 if (nesting_depth-- == 0) 1032 break; 1033 } 1034 /* Consume this token. */ 1035 c_parser_consume_token (parser); 1036 } 1037 parser->error = false; 1038 } 1039 1040 /* Skip tokens until the end of a parameter is found, but do not 1041 consume the comma, semicolon or closing delimiter. */ 1042 1043 static void 1044 c_parser_skip_to_end_of_parameter (c_parser *parser) 1045 { 1046 unsigned nesting_depth = 0; 1047 1048 while (true) 1049 { 1050 c_token *token = c_parser_peek_token (parser); 1051 if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON) 1052 && !nesting_depth) 1053 break; 1054 /* If we've run out of tokens, stop. */ 1055 if (token->type == CPP_EOF) 1056 return; 1057 if (token->type == CPP_PRAGMA_EOL && parser->in_pragma) 1058 return; 1059 if (token->type == CPP_OPEN_BRACE 1060 || token->type == CPP_OPEN_PAREN 1061 || token->type == CPP_OPEN_SQUARE) 1062 ++nesting_depth; 1063 else if (token->type == CPP_CLOSE_BRACE 1064 || token->type == CPP_CLOSE_PAREN 1065 || token->type == CPP_CLOSE_SQUARE) 1066 { 1067 if (nesting_depth-- == 0) 1068 break; 1069 } 1070 /* Consume this token. */ 1071 c_parser_consume_token (parser); 1072 } 1073 parser->error = false; 1074 } 1075 1076 /* Expect to be at the end of the pragma directive and consume an 1077 end of line marker. */ 1078 1079 static void 1080 c_parser_skip_to_pragma_eol (c_parser *parser, bool error_if_not_eol = true) 1081 { 1082 gcc_assert (parser->in_pragma); 1083 parser->in_pragma = false; 1084 1085 if (error_if_not_eol && c_parser_peek_token (parser)->type != CPP_PRAGMA_EOL) 1086 c_parser_error (parser, "expected end of line"); 1087 1088 cpp_ttype token_type; 1089 do 1090 { 1091 c_token *token = c_parser_peek_token (parser); 1092 token_type = token->type; 1093 if (token_type == CPP_EOF) 1094 break; 1095 c_parser_consume_token (parser); 1096 } 1097 while (token_type != CPP_PRAGMA_EOL); 1098 1099 parser->error = false; 1100 } 1101 1102 /* Skip tokens until we have consumed an entire block, or until we 1103 have consumed a non-nested ';'. */ 1104 1105 static void 1106 c_parser_skip_to_end_of_block_or_statement (c_parser *parser) 1107 { 1108 unsigned nesting_depth = 0; 1109 bool save_error = parser->error; 1110 1111 while (true) 1112 { 1113 c_token *token; 1114 1115 /* Peek at the next token. */ 1116 token = c_parser_peek_token (parser); 1117 1118 switch (token->type) 1119 { 1120 case CPP_EOF: 1121 return; 1122 1123 case CPP_PRAGMA_EOL: 1124 if (parser->in_pragma) 1125 return; 1126 break; 1127 1128 case CPP_SEMICOLON: 1129 /* If the next token is a ';', we have reached the 1130 end of the statement. */ 1131 if (!nesting_depth) 1132 { 1133 /* Consume the ';'. */ 1134 c_parser_consume_token (parser); 1135 goto finished; 1136 } 1137 break; 1138 1139 case CPP_CLOSE_BRACE: 1140 /* If the next token is a non-nested '}', then we have 1141 reached the end of the current block. */ 1142 if (nesting_depth == 0 || --nesting_depth == 0) 1143 { 1144 c_parser_consume_token (parser); 1145 goto finished; 1146 } 1147 break; 1148 1149 case CPP_OPEN_BRACE: 1150 /* If it the next token is a '{', then we are entering a new 1151 block. Consume the entire block. */ 1152 ++nesting_depth; 1153 break; 1154 1155 case CPP_PRAGMA: 1156 /* If we see a pragma, consume the whole thing at once. We 1157 have some safeguards against consuming pragmas willy-nilly. 1158 Normally, we'd expect to be here with parser->error set, 1159 which disables these safeguards. But it's possible to get 1160 here for secondary error recovery, after parser->error has 1161 been cleared. */ 1162 c_parser_consume_pragma (parser); 1163 c_parser_skip_to_pragma_eol (parser); 1164 parser->error = save_error; 1165 continue; 1166 1167 default: 1168 break; 1169 } 1170 1171 c_parser_consume_token (parser); 1172 } 1173 1174 finished: 1175 parser->error = false; 1176 } 1177 1178 /* CPP's options (initialized by c-opts.c). */ 1179 extern cpp_options *cpp_opts; 1180 1181 /* Save the warning flags which are controlled by __extension__. */ 1182 1183 static inline int 1184 disable_extension_diagnostics (void) 1185 { 1186 int ret = (pedantic 1187 | (warn_pointer_arith << 1) 1188 | (warn_traditional << 2) 1189 | (flag_iso << 3) 1190 | (warn_long_long << 4) 1191 | (warn_cxx_compat << 5) 1192 | (warn_overlength_strings << 6) 1193 /* warn_c90_c99_compat has three states: -1/0/1, so we must 1194 play tricks to properly restore it. */ 1195 | ((warn_c90_c99_compat == 1) << 7) 1196 | ((warn_c90_c99_compat == -1) << 8) 1197 /* Similarly for warn_c99_c11_compat. */ 1198 | ((warn_c99_c11_compat == 1) << 9) 1199 | ((warn_c99_c11_compat == -1) << 10) 1200 ); 1201 cpp_opts->cpp_pedantic = pedantic = 0; 1202 warn_pointer_arith = 0; 1203 cpp_opts->cpp_warn_traditional = warn_traditional = 0; 1204 flag_iso = 0; 1205 cpp_opts->cpp_warn_long_long = warn_long_long = 0; 1206 warn_cxx_compat = 0; 1207 warn_overlength_strings = 0; 1208 warn_c90_c99_compat = 0; 1209 warn_c99_c11_compat = 0; 1210 return ret; 1211 } 1212 1213 /* Restore the warning flags which are controlled by __extension__. 1214 FLAGS is the return value from disable_extension_diagnostics. */ 1215 1216 static inline void 1217 restore_extension_diagnostics (int flags) 1218 { 1219 cpp_opts->cpp_pedantic = pedantic = flags & 1; 1220 warn_pointer_arith = (flags >> 1) & 1; 1221 cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1; 1222 flag_iso = (flags >> 3) & 1; 1223 cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1; 1224 warn_cxx_compat = (flags >> 5) & 1; 1225 warn_overlength_strings = (flags >> 6) & 1; 1226 /* See above for why is this needed. */ 1227 warn_c90_c99_compat = (flags >> 7) & 1 ? 1 : ((flags >> 8) & 1 ? -1 : 0); 1228 warn_c99_c11_compat = (flags >> 9) & 1 ? 1 : ((flags >> 10) & 1 ? -1 : 0); 1229 } 1230 1231 /* Possibly kinds of declarator to parse. */ 1232 enum c_dtr_syn { 1233 /* A normal declarator with an identifier. */ 1234 C_DTR_NORMAL, 1235 /* An abstract declarator (maybe empty). */ 1236 C_DTR_ABSTRACT, 1237 /* A parameter declarator: may be either, but after a type name does 1238 not redeclare a typedef name as an identifier if it can 1239 alternatively be interpreted as a typedef name; see DR#009, 1240 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2 1241 following DR#249. For example, given a typedef T, "int T" and 1242 "int *T" are valid parameter declarations redeclaring T, while 1243 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are 1244 abstract declarators rather than involving redundant parentheses; 1245 the same applies with attributes inside the parentheses before 1246 "T". */ 1247 C_DTR_PARM 1248 }; 1249 1250 /* The binary operation precedence levels, where 0 is a dummy lowest level 1251 used for the bottom of the stack. */ 1252 enum c_parser_prec { 1253 PREC_NONE, 1254 PREC_LOGOR, 1255 PREC_LOGAND, 1256 PREC_BITOR, 1257 PREC_BITXOR, 1258 PREC_BITAND, 1259 PREC_EQ, 1260 PREC_REL, 1261 PREC_SHIFT, 1262 PREC_ADD, 1263 PREC_MULT, 1264 NUM_PRECS 1265 }; 1266 1267 static void c_parser_external_declaration (c_parser *); 1268 static void c_parser_asm_definition (c_parser *); 1269 static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, 1270 bool, bool, tree *, vec<c_token>, 1271 tree = NULL_TREE); 1272 static void c_parser_static_assert_declaration_no_semi (c_parser *); 1273 static void c_parser_static_assert_declaration (c_parser *); 1274 static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool, 1275 bool, bool, bool, enum c_lookahead_kind); 1276 static struct c_typespec c_parser_enum_specifier (c_parser *); 1277 static struct c_typespec c_parser_struct_or_union_specifier (c_parser *); 1278 static tree c_parser_struct_declaration (c_parser *); 1279 static struct c_typespec c_parser_typeof_specifier (c_parser *); 1280 static tree c_parser_alignas_specifier (c_parser *); 1281 static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn, 1282 bool *); 1283 static struct c_declarator *c_parser_direct_declarator (c_parser *, bool, 1284 c_dtr_syn, bool *); 1285 static struct c_declarator *c_parser_direct_declarator_inner (c_parser *, 1286 bool, 1287 struct c_declarator *); 1288 static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree); 1289 static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree, 1290 tree); 1291 static struct c_parm *c_parser_parameter_declaration (c_parser *, tree); 1292 static tree c_parser_simple_asm_expr (c_parser *); 1293 static tree c_parser_attributes (c_parser *); 1294 static struct c_type_name *c_parser_type_name (c_parser *); 1295 static struct c_expr c_parser_initializer (c_parser *); 1296 static struct c_expr c_parser_braced_init (c_parser *, tree, bool, 1297 struct obstack *); 1298 static void c_parser_initelt (c_parser *, struct obstack *); 1299 static void c_parser_initval (c_parser *, struct c_expr *, 1300 struct obstack *); 1301 static tree c_parser_compound_statement (c_parser *); 1302 static void c_parser_compound_statement_nostart (c_parser *); 1303 static void c_parser_label (c_parser *); 1304 static void c_parser_statement (c_parser *, bool *); 1305 static void c_parser_statement_after_labels (c_parser *, bool *, 1306 vec<tree> * = NULL); 1307 static void c_parser_if_statement (c_parser *, bool *, vec<tree> *); 1308 static void c_parser_switch_statement (c_parser *); 1309 static void c_parser_while_statement (c_parser *, bool, bool *); 1310 static void c_parser_do_statement (c_parser *, bool); 1311 static void c_parser_for_statement (c_parser *, bool, bool *); 1312 static tree c_parser_asm_statement (c_parser *); 1313 static tree c_parser_asm_operands (c_parser *); 1314 static tree c_parser_asm_goto_operands (c_parser *); 1315 static tree c_parser_asm_clobbers (c_parser *); 1316 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *, 1317 tree = NULL_TREE); 1318 static struct c_expr c_parser_conditional_expression (c_parser *, 1319 struct c_expr *, tree); 1320 static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *, 1321 tree); 1322 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *); 1323 static struct c_expr c_parser_unary_expression (c_parser *); 1324 static struct c_expr c_parser_sizeof_expression (c_parser *); 1325 static struct c_expr c_parser_alignof_expression (c_parser *); 1326 static struct c_expr c_parser_postfix_expression (c_parser *); 1327 static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *, 1328 struct c_type_name *, 1329 location_t); 1330 static struct c_expr c_parser_postfix_expression_after_primary (c_parser *, 1331 location_t loc, 1332 struct c_expr); 1333 static tree c_parser_transaction (c_parser *, enum rid); 1334 static struct c_expr c_parser_transaction_expression (c_parser *, enum rid); 1335 static tree c_parser_transaction_cancel (c_parser *); 1336 static struct c_expr c_parser_expression (c_parser *); 1337 static struct c_expr c_parser_expression_conv (c_parser *); 1338 static vec<tree, va_gc> *c_parser_expr_list (c_parser *, bool, bool, 1339 vec<tree, va_gc> **, location_t *, 1340 tree *, vec<location_t> *, 1341 unsigned int * = NULL); 1342 static void c_parser_oacc_declare (c_parser *); 1343 static void c_parser_oacc_enter_exit_data (c_parser *, bool); 1344 static void c_parser_oacc_update (c_parser *); 1345 static void c_parser_omp_construct (c_parser *, bool *); 1346 static void c_parser_omp_threadprivate (c_parser *); 1347 static void c_parser_omp_barrier (c_parser *); 1348 static void c_parser_omp_flush (c_parser *); 1349 static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code, 1350 tree, tree *, bool *); 1351 static void c_parser_omp_taskwait (c_parser *); 1352 static void c_parser_omp_taskyield (c_parser *); 1353 static void c_parser_omp_cancel (c_parser *); 1354 static void c_parser_omp_cancellation_point (c_parser *); 1355 1356 enum pragma_context { pragma_external, pragma_struct, pragma_param, 1357 pragma_stmt, pragma_compound }; 1358 static bool c_parser_pragma (c_parser *, enum pragma_context, bool *); 1359 static bool c_parser_omp_target (c_parser *, enum pragma_context, bool *); 1360 static void c_parser_omp_end_declare_target (c_parser *); 1361 static void c_parser_omp_declare (c_parser *, enum pragma_context); 1362 static bool c_parser_omp_ordered (c_parser *, enum pragma_context, bool *); 1363 static void c_parser_oacc_routine (c_parser *parser, enum pragma_context); 1364 1365 /* These Objective-C parser functions are only ever called when 1366 compiling Objective-C. */ 1367 static void c_parser_objc_class_definition (c_parser *, tree); 1368 static void c_parser_objc_class_instance_variables (c_parser *); 1369 static void c_parser_objc_class_declaration (c_parser *); 1370 static void c_parser_objc_alias_declaration (c_parser *); 1371 static void c_parser_objc_protocol_definition (c_parser *, tree); 1372 static bool c_parser_objc_method_type (c_parser *); 1373 static void c_parser_objc_method_definition (c_parser *); 1374 static void c_parser_objc_methodprotolist (c_parser *); 1375 static void c_parser_objc_methodproto (c_parser *); 1376 static tree c_parser_objc_method_decl (c_parser *, bool, tree *, tree *); 1377 static tree c_parser_objc_type_name (c_parser *); 1378 static tree c_parser_objc_protocol_refs (c_parser *); 1379 static void c_parser_objc_try_catch_finally_statement (c_parser *); 1380 static void c_parser_objc_synchronized_statement (c_parser *); 1381 static tree c_parser_objc_selector (c_parser *); 1382 static tree c_parser_objc_selector_arg (c_parser *); 1383 static tree c_parser_objc_receiver (c_parser *); 1384 static tree c_parser_objc_message_args (c_parser *); 1385 static tree c_parser_objc_keywordexpr (c_parser *); 1386 static void c_parser_objc_at_property_declaration (c_parser *); 1387 static void c_parser_objc_at_synthesize_declaration (c_parser *); 1388 static void c_parser_objc_at_dynamic_declaration (c_parser *); 1389 static bool c_parser_objc_diagnose_bad_element_prefix 1390 (c_parser *, struct c_declspecs *); 1391 1392 /* Cilk Plus supporting routines. */ 1393 static void c_parser_cilk_simd (c_parser *, bool *); 1394 static void c_parser_cilk_for (c_parser *, tree, bool *); 1395 static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context); 1396 static tree c_parser_array_notation (location_t, c_parser *, tree, tree); 1397 static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool); 1398 static void c_parser_cilk_grainsize (c_parser *, bool *); 1399 1400 /* Parse a translation unit (C90 6.7, C99 6.9). 1401 1402 translation-unit: 1403 external-declarations 1404 1405 external-declarations: 1406 external-declaration 1407 external-declarations external-declaration 1408 1409 GNU extensions: 1410 1411 translation-unit: 1412 empty 1413 */ 1414 1415 static void 1416 c_parser_translation_unit (c_parser *parser) 1417 { 1418 if (c_parser_next_token_is (parser, CPP_EOF)) 1419 { 1420 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, 1421 "ISO C forbids an empty translation unit"); 1422 } 1423 else 1424 { 1425 void *obstack_position = obstack_alloc (&parser_obstack, 0); 1426 mark_valid_location_for_stdc_pragma (false); 1427 do 1428 { 1429 ggc_collect (); 1430 c_parser_external_declaration (parser); 1431 obstack_free (&parser_obstack, obstack_position); 1432 } 1433 while (c_parser_next_token_is_not (parser, CPP_EOF)); 1434 } 1435 1436 unsigned int i; 1437 tree decl; 1438 FOR_EACH_VEC_ELT (incomplete_record_decls, i, decl) 1439 if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node) 1440 error ("storage size of %q+D isn%'t known", decl); 1441 } 1442 1443 /* Parse an external declaration (C90 6.7, C99 6.9). 1444 1445 external-declaration: 1446 function-definition 1447 declaration 1448 1449 GNU extensions: 1450 1451 external-declaration: 1452 asm-definition 1453 ; 1454 __extension__ external-declaration 1455 1456 Objective-C: 1457 1458 external-declaration: 1459 objc-class-definition 1460 objc-class-declaration 1461 objc-alias-declaration 1462 objc-protocol-definition 1463 objc-method-definition 1464 @end 1465 */ 1466 1467 static void 1468 c_parser_external_declaration (c_parser *parser) 1469 { 1470 int ext; 1471 switch (c_parser_peek_token (parser)->type) 1472 { 1473 case CPP_KEYWORD: 1474 switch (c_parser_peek_token (parser)->keyword) 1475 { 1476 case RID_EXTENSION: 1477 ext = disable_extension_diagnostics (); 1478 c_parser_consume_token (parser); 1479 c_parser_external_declaration (parser); 1480 restore_extension_diagnostics (ext); 1481 break; 1482 case RID_ASM: 1483 c_parser_asm_definition (parser); 1484 break; 1485 case RID_AT_INTERFACE: 1486 case RID_AT_IMPLEMENTATION: 1487 gcc_assert (c_dialect_objc ()); 1488 c_parser_objc_class_definition (parser, NULL_TREE); 1489 break; 1490 case RID_AT_CLASS: 1491 gcc_assert (c_dialect_objc ()); 1492 c_parser_objc_class_declaration (parser); 1493 break; 1494 case RID_AT_ALIAS: 1495 gcc_assert (c_dialect_objc ()); 1496 c_parser_objc_alias_declaration (parser); 1497 break; 1498 case RID_AT_PROTOCOL: 1499 gcc_assert (c_dialect_objc ()); 1500 c_parser_objc_protocol_definition (parser, NULL_TREE); 1501 break; 1502 case RID_AT_PROPERTY: 1503 gcc_assert (c_dialect_objc ()); 1504 c_parser_objc_at_property_declaration (parser); 1505 break; 1506 case RID_AT_SYNTHESIZE: 1507 gcc_assert (c_dialect_objc ()); 1508 c_parser_objc_at_synthesize_declaration (parser); 1509 break; 1510 case RID_AT_DYNAMIC: 1511 gcc_assert (c_dialect_objc ()); 1512 c_parser_objc_at_dynamic_declaration (parser); 1513 break; 1514 case RID_AT_END: 1515 gcc_assert (c_dialect_objc ()); 1516 c_parser_consume_token (parser); 1517 objc_finish_implementation (); 1518 break; 1519 default: 1520 goto decl_or_fndef; 1521 } 1522 break; 1523 case CPP_SEMICOLON: 1524 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, 1525 "ISO C does not allow extra %<;%> outside of a function"); 1526 c_parser_consume_token (parser); 1527 break; 1528 case CPP_PRAGMA: 1529 mark_valid_location_for_stdc_pragma (true); 1530 c_parser_pragma (parser, pragma_external, NULL); 1531 mark_valid_location_for_stdc_pragma (false); 1532 break; 1533 case CPP_PLUS: 1534 case CPP_MINUS: 1535 if (c_dialect_objc ()) 1536 { 1537 c_parser_objc_method_definition (parser); 1538 break; 1539 } 1540 /* Else fall through, and yield a syntax error trying to parse 1541 as a declaration or function definition. */ 1542 default: 1543 decl_or_fndef: 1544 /* A declaration or a function definition (or, in Objective-C, 1545 an @interface or @protocol with prefix attributes). We can 1546 only tell which after parsing the declaration specifiers, if 1547 any, and the first declarator. */ 1548 c_parser_declaration_or_fndef (parser, true, true, true, false, true, 1549 NULL, vNULL); 1550 break; 1551 } 1552 } 1553 1554 static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec<c_token>); 1555 static void c_finish_oacc_routine (c_parser *, tree, tree, bool, bool, bool); 1556 1557 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99 1558 6.7, 6.9.1). If FNDEF_OK is true, a function definition is 1559 accepted; otherwise (old-style parameter declarations) only other 1560 declarations are accepted. If STATIC_ASSERT_OK is true, a static 1561 assertion is accepted; otherwise (old-style parameter declarations) 1562 it is not. If NESTED is true, we are inside a function or parsing 1563 old-style parameter declarations; any functions encountered are 1564 nested functions and declaration specifiers are required; otherwise 1565 we are at top level and functions are normal functions and 1566 declaration specifiers may be optional. If EMPTY_OK is true, empty 1567 declarations are OK (subject to all other constraints); otherwise 1568 (old-style parameter declarations) they are diagnosed. If 1569 START_ATTR_OK is true, the declaration specifiers may start with 1570 attributes; otherwise they may not. 1571 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed 1572 declaration when parsing an Objective-C foreach statement. 1573 1574 declaration: 1575 declaration-specifiers init-declarator-list[opt] ; 1576 static_assert-declaration 1577 1578 function-definition: 1579 declaration-specifiers[opt] declarator declaration-list[opt] 1580 compound-statement 1581 1582 declaration-list: 1583 declaration 1584 declaration-list declaration 1585 1586 init-declarator-list: 1587 init-declarator 1588 init-declarator-list , init-declarator 1589 1590 init-declarator: 1591 declarator simple-asm-expr[opt] attributes[opt] 1592 declarator simple-asm-expr[opt] attributes[opt] = initializer 1593 1594 GNU extensions: 1595 1596 nested-function-definition: 1597 declaration-specifiers declarator declaration-list[opt] 1598 compound-statement 1599 1600 Objective-C: 1601 attributes objc-class-definition 1602 attributes objc-category-definition 1603 attributes objc-protocol-definition 1604 1605 The simple-asm-expr and attributes are GNU extensions. 1606 1607 This function does not handle __extension__; that is handled in its 1608 callers. ??? Following the old parser, __extension__ may start 1609 external declarations, declarations in functions and declarations 1610 at the start of "for" loops, but not old-style parameter 1611 declarations. 1612 1613 C99 requires declaration specifiers in a function definition; the 1614 absence is diagnosed through the diagnosis of implicit int. In GNU 1615 C we also allow but diagnose declarations without declaration 1616 specifiers, but only at top level (elsewhere they conflict with 1617 other syntax). 1618 1619 In Objective-C, declarations of the looping variable in a foreach 1620 statement are exceptionally terminated by 'in' (for example, 'for 1621 (NSObject *object in array) { ... }'). 1622 1623 OpenMP: 1624 1625 declaration: 1626 threadprivate-directive */ 1627 1628 static void 1629 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, 1630 bool static_assert_ok, bool empty_ok, 1631 bool nested, bool start_attr_ok, 1632 tree *objc_foreach_object_declaration, 1633 vec<c_token> omp_declare_simd_clauses, 1634 tree oacc_routine_clauses) 1635 { 1636 struct c_declspecs *specs; 1637 tree prefix_attrs; 1638 tree all_prefix_attrs; 1639 bool diagnosed_no_specs = false; 1640 location_t here = c_parser_peek_token (parser)->location; 1641 1642 if (static_assert_ok 1643 && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)) 1644 { 1645 c_parser_static_assert_declaration (parser); 1646 return; 1647 } 1648 specs = build_null_declspecs (); 1649 1650 /* Try to detect an unknown type name when we have "A B" or "A *B". */ 1651 if (c_parser_peek_token (parser)->type == CPP_NAME 1652 && c_parser_peek_token (parser)->id_kind == C_ID_ID 1653 && (c_parser_peek_2nd_token (parser)->type == CPP_NAME 1654 || c_parser_peek_2nd_token (parser)->type == CPP_MULT) 1655 && (!nested || !lookup_name (c_parser_peek_token (parser)->value))) 1656 { 1657 tree name = c_parser_peek_token (parser)->value; 1658 error_at (here, "unknown type name %qE", name); 1659 /* Give a hint to the user. This is not C++ with its implicit 1660 typedef. */ 1661 if (tag_exists_p (RECORD_TYPE, name)) 1662 inform (here, "use %<struct%> keyword to refer to the type"); 1663 else if (tag_exists_p (UNION_TYPE, name)) 1664 inform (here, "use %<union%> keyword to refer to the type"); 1665 else if (tag_exists_p (ENUMERAL_TYPE, name)) 1666 inform (here, "use %<enum%> keyword to refer to the type"); 1667 1668 /* Parse declspecs normally to get a correct pointer type, but avoid 1669 a further "fails to be a type name" error. Refuse nested functions 1670 since it is not how the user likely wants us to recover. */ 1671 c_parser_peek_token (parser)->type = CPP_KEYWORD; 1672 c_parser_peek_token (parser)->keyword = RID_VOID; 1673 c_parser_peek_token (parser)->value = error_mark_node; 1674 fndef_ok = !nested; 1675 } 1676 1677 c_parser_declspecs (parser, specs, true, true, start_attr_ok, 1678 true, true, cla_nonabstract_decl); 1679 if (parser->error) 1680 { 1681 c_parser_skip_to_end_of_block_or_statement (parser); 1682 return; 1683 } 1684 if (nested && !specs->declspecs_seen_p) 1685 { 1686 c_parser_error (parser, "expected declaration specifiers"); 1687 c_parser_skip_to_end_of_block_or_statement (parser); 1688 return; 1689 } 1690 finish_declspecs (specs); 1691 bool auto_type_p = specs->typespec_word == cts_auto_type; 1692 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 1693 { 1694 if (auto_type_p) 1695 error_at (here, "%<__auto_type%> in empty declaration"); 1696 else if (empty_ok) 1697 shadow_tag (specs); 1698 else 1699 { 1700 shadow_tag_warned (specs, 1); 1701 pedwarn (here, 0, "empty declaration"); 1702 } 1703 c_parser_consume_token (parser); 1704 if (oacc_routine_clauses) 1705 c_finish_oacc_routine (parser, NULL_TREE, 1706 oacc_routine_clauses, false, true, false); 1707 return; 1708 } 1709 1710 /* Provide better error recovery. Note that a type name here is usually 1711 better diagnosed as a redeclaration. */ 1712 if (empty_ok 1713 && specs->typespec_kind == ctsk_tagdef 1714 && c_parser_next_token_starts_declspecs (parser) 1715 && !c_parser_next_token_is (parser, CPP_NAME)) 1716 { 1717 c_parser_error (parser, "expected %<;%>, identifier or %<(%>"); 1718 parser->error = false; 1719 shadow_tag_warned (specs, 1); 1720 return; 1721 } 1722 else if (c_dialect_objc () && !auto_type_p) 1723 { 1724 /* Prefix attributes are an error on method decls. */ 1725 switch (c_parser_peek_token (parser)->type) 1726 { 1727 case CPP_PLUS: 1728 case CPP_MINUS: 1729 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) 1730 return; 1731 if (specs->attrs) 1732 { 1733 warning_at (c_parser_peek_token (parser)->location, 1734 OPT_Wattributes, 1735 "prefix attributes are ignored for methods"); 1736 specs->attrs = NULL_TREE; 1737 } 1738 if (fndef_ok) 1739 c_parser_objc_method_definition (parser); 1740 else 1741 c_parser_objc_methodproto (parser); 1742 return; 1743 break; 1744 default: 1745 break; 1746 } 1747 /* This is where we parse 'attributes @interface ...', 1748 'attributes @implementation ...', 'attributes @protocol ...' 1749 (where attributes could be, for example, __attribute__ 1750 ((deprecated)). 1751 */ 1752 switch (c_parser_peek_token (parser)->keyword) 1753 { 1754 case RID_AT_INTERFACE: 1755 { 1756 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) 1757 return; 1758 c_parser_objc_class_definition (parser, specs->attrs); 1759 return; 1760 } 1761 break; 1762 case RID_AT_IMPLEMENTATION: 1763 { 1764 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) 1765 return; 1766 if (specs->attrs) 1767 { 1768 warning_at (c_parser_peek_token (parser)->location, 1769 OPT_Wattributes, 1770 "prefix attributes are ignored for implementations"); 1771 specs->attrs = NULL_TREE; 1772 } 1773 c_parser_objc_class_definition (parser, NULL_TREE); 1774 return; 1775 } 1776 break; 1777 case RID_AT_PROTOCOL: 1778 { 1779 if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) 1780 return; 1781 c_parser_objc_protocol_definition (parser, specs->attrs); 1782 return; 1783 } 1784 break; 1785 case RID_AT_ALIAS: 1786 case RID_AT_CLASS: 1787 case RID_AT_END: 1788 case RID_AT_PROPERTY: 1789 if (specs->attrs) 1790 { 1791 c_parser_error (parser, "unexpected attribute"); 1792 specs->attrs = NULL; 1793 } 1794 break; 1795 default: 1796 break; 1797 } 1798 } 1799 1800 pending_xref_error (); 1801 prefix_attrs = specs->attrs; 1802 all_prefix_attrs = prefix_attrs; 1803 specs->attrs = NULL_TREE; 1804 for (bool first = true;; first = false) 1805 { 1806 struct c_declarator *declarator; 1807 bool dummy = false; 1808 timevar_id_t tv; 1809 tree fnbody; 1810 /* Declaring either one or more declarators (in which case we 1811 should diagnose if there were no declaration specifiers) or a 1812 function definition (in which case the diagnostic for 1813 implicit int suffices). */ 1814 declarator = c_parser_declarator (parser, 1815 specs->typespec_kind != ctsk_none, 1816 C_DTR_NORMAL, &dummy); 1817 if (declarator == NULL) 1818 { 1819 if (omp_declare_simd_clauses.exists () 1820 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) 1821 c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE, 1822 omp_declare_simd_clauses); 1823 if (oacc_routine_clauses) 1824 c_finish_oacc_routine (parser, NULL_TREE, 1825 oacc_routine_clauses, 1826 false, first, false); 1827 c_parser_skip_to_end_of_block_or_statement (parser); 1828 return; 1829 } 1830 if (auto_type_p && declarator->kind != cdk_id) 1831 { 1832 error_at (here, 1833 "%<__auto_type%> requires a plain identifier" 1834 " as declarator"); 1835 c_parser_skip_to_end_of_block_or_statement (parser); 1836 return; 1837 } 1838 if (c_parser_next_token_is (parser, CPP_EQ) 1839 || c_parser_next_token_is (parser, CPP_COMMA) 1840 || c_parser_next_token_is (parser, CPP_SEMICOLON) 1841 || c_parser_next_token_is_keyword (parser, RID_ASM) 1842 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE) 1843 || c_parser_next_token_is_keyword (parser, RID_IN)) 1844 { 1845 tree asm_name = NULL_TREE; 1846 tree postfix_attrs = NULL_TREE; 1847 if (!diagnosed_no_specs && !specs->declspecs_seen_p) 1848 { 1849 diagnosed_no_specs = true; 1850 pedwarn (here, 0, "data definition has no type or storage class"); 1851 } 1852 /* Having seen a data definition, there cannot now be a 1853 function definition. */ 1854 fndef_ok = false; 1855 if (c_parser_next_token_is_keyword (parser, RID_ASM)) 1856 asm_name = c_parser_simple_asm_expr (parser); 1857 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) 1858 { 1859 postfix_attrs = c_parser_attributes (parser); 1860 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) 1861 { 1862 /* This means there is an attribute specifier after 1863 the declarator in a function definition. Provide 1864 some more information for the user. */ 1865 error_at (here, "attributes should be specified before the " 1866 "declarator in a function definition"); 1867 c_parser_skip_to_end_of_block_or_statement (parser); 1868 return; 1869 } 1870 } 1871 if (c_parser_next_token_is (parser, CPP_EQ)) 1872 { 1873 tree d; 1874 struct c_expr init; 1875 location_t init_loc; 1876 c_parser_consume_token (parser); 1877 if (auto_type_p) 1878 { 1879 start_init (NULL_TREE, asm_name, global_bindings_p ()); 1880 init_loc = c_parser_peek_token (parser)->location; 1881 init = c_parser_expr_no_commas (parser, NULL); 1882 if (TREE_CODE (init.value) == COMPONENT_REF 1883 && DECL_C_BIT_FIELD (TREE_OPERAND (init.value, 1))) 1884 error_at (here, 1885 "%<__auto_type%> used with a bit-field" 1886 " initializer"); 1887 init = convert_lvalue_to_rvalue (init_loc, init, true, true); 1888 tree init_type = TREE_TYPE (init.value); 1889 /* As with typeof, remove all qualifiers from atomic types. */ 1890 if (init_type != error_mark_node && TYPE_ATOMIC (init_type)) 1891 init_type 1892 = c_build_qualified_type (init_type, TYPE_UNQUALIFIED); 1893 bool vm_type = variably_modified_type_p (init_type, 1894 NULL_TREE); 1895 if (vm_type) 1896 init.value = c_save_expr (init.value); 1897 finish_init (); 1898 specs->typespec_kind = ctsk_typeof; 1899 specs->locations[cdw_typedef] = init_loc; 1900 specs->typedef_p = true; 1901 specs->type = init_type; 1902 if (vm_type) 1903 { 1904 bool maybe_const = true; 1905 tree type_expr = c_fully_fold (init.value, false, 1906 &maybe_const); 1907 specs->expr_const_operands &= maybe_const; 1908 if (specs->expr) 1909 specs->expr = build2 (COMPOUND_EXPR, 1910 TREE_TYPE (type_expr), 1911 specs->expr, type_expr); 1912 else 1913 specs->expr = type_expr; 1914 } 1915 d = start_decl (declarator, specs, true, 1916 chainon (postfix_attrs, all_prefix_attrs)); 1917 if (!d) 1918 d = error_mark_node; 1919 if (omp_declare_simd_clauses.exists () 1920 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) 1921 c_finish_omp_declare_simd (parser, d, NULL_TREE, 1922 omp_declare_simd_clauses); 1923 } 1924 else 1925 { 1926 /* The declaration of the variable is in effect while 1927 its initializer is parsed. */ 1928 d = start_decl (declarator, specs, true, 1929 chainon (postfix_attrs, all_prefix_attrs)); 1930 if (!d) 1931 d = error_mark_node; 1932 if (omp_declare_simd_clauses.exists () 1933 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) 1934 c_finish_omp_declare_simd (parser, d, NULL_TREE, 1935 omp_declare_simd_clauses); 1936 start_init (d, asm_name, global_bindings_p ()); 1937 init_loc = c_parser_peek_token (parser)->location; 1938 init = c_parser_initializer (parser); 1939 finish_init (); 1940 } 1941 if (oacc_routine_clauses) 1942 c_finish_oacc_routine (parser, d, oacc_routine_clauses, 1943 false, first, false); 1944 if (d != error_mark_node) 1945 { 1946 maybe_warn_string_init (init_loc, TREE_TYPE (d), init); 1947 finish_decl (d, init_loc, init.value, 1948 init.original_type, asm_name); 1949 } 1950 } 1951 else 1952 { 1953 if (auto_type_p) 1954 { 1955 error_at (here, 1956 "%<__auto_type%> requires an initialized " 1957 "data declaration"); 1958 c_parser_skip_to_end_of_block_or_statement (parser); 1959 return; 1960 } 1961 tree d = start_decl (declarator, specs, false, 1962 chainon (postfix_attrs, 1963 all_prefix_attrs)); 1964 if (omp_declare_simd_clauses.exists () 1965 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) 1966 { 1967 tree parms = NULL_TREE; 1968 if (d && TREE_CODE (d) == FUNCTION_DECL) 1969 { 1970 struct c_declarator *ce = declarator; 1971 while (ce != NULL) 1972 if (ce->kind == cdk_function) 1973 { 1974 parms = ce->u.arg_info->parms; 1975 break; 1976 } 1977 else 1978 ce = ce->declarator; 1979 } 1980 if (parms) 1981 temp_store_parm_decls (d, parms); 1982 c_finish_omp_declare_simd (parser, d, parms, 1983 omp_declare_simd_clauses); 1984 if (parms) 1985 temp_pop_parm_decls (); 1986 } 1987 if (oacc_routine_clauses) 1988 c_finish_oacc_routine (parser, d, oacc_routine_clauses, 1989 false, first, false); 1990 if (d) 1991 finish_decl (d, UNKNOWN_LOCATION, NULL_TREE, 1992 NULL_TREE, asm_name); 1993 1994 if (c_parser_next_token_is_keyword (parser, RID_IN)) 1995 { 1996 if (d) 1997 *objc_foreach_object_declaration = d; 1998 else 1999 *objc_foreach_object_declaration = error_mark_node; 2000 } 2001 } 2002 if (c_parser_next_token_is (parser, CPP_COMMA)) 2003 { 2004 if (auto_type_p) 2005 { 2006 error_at (here, 2007 "%<__auto_type%> may only be used with" 2008 " a single declarator"); 2009 c_parser_skip_to_end_of_block_or_statement (parser); 2010 return; 2011 } 2012 c_parser_consume_token (parser); 2013 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) 2014 all_prefix_attrs = chainon (c_parser_attributes (parser), 2015 prefix_attrs); 2016 else 2017 all_prefix_attrs = prefix_attrs; 2018 continue; 2019 } 2020 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 2021 { 2022 c_parser_consume_token (parser); 2023 return; 2024 } 2025 else if (c_parser_next_token_is_keyword (parser, RID_IN)) 2026 { 2027 /* This can only happen in Objective-C: we found the 2028 'in' that terminates the declaration inside an 2029 Objective-C foreach statement. Do not consume the 2030 token, so that the caller can use it to determine 2031 that this indeed is a foreach context. */ 2032 return; 2033 } 2034 else 2035 { 2036 c_parser_error (parser, "expected %<,%> or %<;%>"); 2037 c_parser_skip_to_end_of_block_or_statement (parser); 2038 return; 2039 } 2040 } 2041 else if (auto_type_p) 2042 { 2043 error_at (here, 2044 "%<__auto_type%> requires an initialized data declaration"); 2045 c_parser_skip_to_end_of_block_or_statement (parser); 2046 return; 2047 } 2048 else if (!fndef_ok) 2049 { 2050 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, " 2051 "%<asm%> or %<__attribute__%>"); 2052 c_parser_skip_to_end_of_block_or_statement (parser); 2053 return; 2054 } 2055 /* Function definition (nested or otherwise). */ 2056 if (nested) 2057 { 2058 pedwarn (here, OPT_Wpedantic, "ISO C forbids nested functions"); 2059 c_push_function_context (); 2060 } 2061 if (!start_function (specs, declarator, all_prefix_attrs)) 2062 { 2063 /* This can appear in many cases looking nothing like a 2064 function definition, so we don't give a more specific 2065 error suggesting there was one. */ 2066 c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> " 2067 "or %<__attribute__%>"); 2068 if (nested) 2069 c_pop_function_context (); 2070 break; 2071 } 2072 2073 if (DECL_DECLARED_INLINE_P (current_function_decl)) 2074 tv = TV_PARSE_INLINE; 2075 else 2076 tv = TV_PARSE_FUNC; 2077 timevar_push (tv); 2078 2079 /* Parse old-style parameter declarations. ??? Attributes are 2080 not allowed to start declaration specifiers here because of a 2081 syntax conflict between a function declaration with attribute 2082 suffix and a function definition with an attribute prefix on 2083 first old-style parameter declaration. Following the old 2084 parser, they are not accepted on subsequent old-style 2085 parameter declarations either. However, there is no 2086 ambiguity after the first declaration, nor indeed on the 2087 first as long as we don't allow postfix attributes after a 2088 declarator with a nonempty identifier list in a definition; 2089 and postfix attributes have never been accepted here in 2090 function definitions either. */ 2091 while (c_parser_next_token_is_not (parser, CPP_EOF) 2092 && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE)) 2093 c_parser_declaration_or_fndef (parser, false, false, false, 2094 true, false, NULL, vNULL); 2095 store_parm_decls (); 2096 if (omp_declare_simd_clauses.exists () 2097 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) 2098 c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE, 2099 omp_declare_simd_clauses); 2100 if (oacc_routine_clauses) 2101 c_finish_oacc_routine (parser, current_function_decl, 2102 oacc_routine_clauses, false, first, true); 2103 DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus 2104 = c_parser_peek_token (parser)->location; 2105 fnbody = c_parser_compound_statement (parser); 2106 if (flag_cilkplus && contains_array_notation_expr (fnbody)) 2107 fnbody = expand_array_notation_exprs (fnbody); 2108 if (nested) 2109 { 2110 tree decl = current_function_decl; 2111 /* Mark nested functions as needing static-chain initially. 2112 lower_nested_functions will recompute it but the 2113 DECL_STATIC_CHAIN flag is also used before that happens, 2114 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */ 2115 DECL_STATIC_CHAIN (decl) = 1; 2116 add_stmt (fnbody); 2117 finish_function (); 2118 c_pop_function_context (); 2119 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl)); 2120 } 2121 else 2122 { 2123 add_stmt (fnbody); 2124 finish_function (); 2125 } 2126 2127 timevar_pop (tv); 2128 break; 2129 } 2130 } 2131 2132 /* Parse an asm-definition (asm() outside a function body). This is a 2133 GNU extension. 2134 2135 asm-definition: 2136 simple-asm-expr ; 2137 */ 2138 2139 static void 2140 c_parser_asm_definition (c_parser *parser) 2141 { 2142 tree asm_str = c_parser_simple_asm_expr (parser); 2143 if (asm_str) 2144 symtab->finalize_toplevel_asm (asm_str); 2145 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 2146 } 2147 2148 /* Parse a static assertion (C11 6.7.10). 2149 2150 static_assert-declaration: 2151 static_assert-declaration-no-semi ; 2152 */ 2153 2154 static void 2155 c_parser_static_assert_declaration (c_parser *parser) 2156 { 2157 c_parser_static_assert_declaration_no_semi (parser); 2158 if (parser->error 2159 || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) 2160 c_parser_skip_to_end_of_block_or_statement (parser); 2161 } 2162 2163 /* Parse a static assertion (C11 6.7.10), without the trailing 2164 semicolon. 2165 2166 static_assert-declaration-no-semi: 2167 _Static_assert ( constant-expression , string-literal ) 2168 */ 2169 2170 static void 2171 c_parser_static_assert_declaration_no_semi (c_parser *parser) 2172 { 2173 location_t assert_loc, value_loc; 2174 tree value; 2175 tree string; 2176 2177 gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)); 2178 assert_loc = c_parser_peek_token (parser)->location; 2179 if (flag_isoc99) 2180 pedwarn_c99 (assert_loc, OPT_Wpedantic, 2181 "ISO C99 does not support %<_Static_assert%>"); 2182 else 2183 pedwarn_c99 (assert_loc, OPT_Wpedantic, 2184 "ISO C90 does not support %<_Static_assert%>"); 2185 c_parser_consume_token (parser); 2186 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 2187 return; 2188 location_t value_tok_loc = c_parser_peek_token (parser)->location; 2189 value = c_parser_expr_no_commas (parser, NULL).value; 2190 value_loc = EXPR_LOC_OR_LOC (value, value_tok_loc); 2191 parser->lex_untranslated_string = true; 2192 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) 2193 { 2194 parser->lex_untranslated_string = false; 2195 return; 2196 } 2197 switch (c_parser_peek_token (parser)->type) 2198 { 2199 case CPP_STRING: 2200 case CPP_STRING16: 2201 case CPP_STRING32: 2202 case CPP_WSTRING: 2203 case CPP_UTF8STRING: 2204 string = c_parser_peek_token (parser)->value; 2205 c_parser_consume_token (parser); 2206 parser->lex_untranslated_string = false; 2207 break; 2208 default: 2209 c_parser_error (parser, "expected string literal"); 2210 parser->lex_untranslated_string = false; 2211 return; 2212 } 2213 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 2214 2215 if (!INTEGRAL_TYPE_P (TREE_TYPE (value))) 2216 { 2217 error_at (value_loc, "expression in static assertion is not an integer"); 2218 return; 2219 } 2220 if (TREE_CODE (value) != INTEGER_CST) 2221 { 2222 value = c_fully_fold (value, false, NULL); 2223 /* Strip no-op conversions. */ 2224 STRIP_TYPE_NOPS (value); 2225 if (TREE_CODE (value) == INTEGER_CST) 2226 pedwarn (value_loc, OPT_Wpedantic, "expression in static assertion " 2227 "is not an integer constant expression"); 2228 } 2229 if (TREE_CODE (value) != INTEGER_CST) 2230 { 2231 error_at (value_loc, "expression in static assertion is not constant"); 2232 return; 2233 } 2234 constant_expression_warning (value); 2235 if (integer_zerop (value)) 2236 error_at (assert_loc, "static assertion failed: %E", string); 2237 } 2238 2239 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99 2240 6.7), adding them to SPECS (which may already include some). 2241 Storage class specifiers are accepted iff SCSPEC_OK; type 2242 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are 2243 accepted iff ALIGNSPEC_OK; attributes are accepted at the start 2244 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK. 2245 2246 declaration-specifiers: 2247 storage-class-specifier declaration-specifiers[opt] 2248 type-specifier declaration-specifiers[opt] 2249 type-qualifier declaration-specifiers[opt] 2250 function-specifier declaration-specifiers[opt] 2251 alignment-specifier declaration-specifiers[opt] 2252 2253 Function specifiers (inline) are from C99, and are currently 2254 handled as storage class specifiers, as is __thread. Alignment 2255 specifiers are from C11. 2256 2257 C90 6.5.1, C99 6.7.1: 2258 storage-class-specifier: 2259 typedef 2260 extern 2261 static 2262 auto 2263 register 2264 _Thread_local 2265 2266 (_Thread_local is new in C11.) 2267 2268 C99 6.7.4: 2269 function-specifier: 2270 inline 2271 _Noreturn 2272 2273 (_Noreturn is new in C11.) 2274 2275 C90 6.5.2, C99 6.7.2: 2276 type-specifier: 2277 void 2278 char 2279 short 2280 int 2281 long 2282 float 2283 double 2284 signed 2285 unsigned 2286 _Bool 2287 _Complex 2288 [_Imaginary removed in C99 TC2] 2289 struct-or-union-specifier 2290 enum-specifier 2291 typedef-name 2292 atomic-type-specifier 2293 2294 (_Bool and _Complex are new in C99.) 2295 (atomic-type-specifier is new in C11.) 2296 2297 C90 6.5.3, C99 6.7.3: 2298 2299 type-qualifier: 2300 const 2301 restrict 2302 volatile 2303 address-space-qualifier 2304 _Atomic 2305 2306 (restrict is new in C99.) 2307 (_Atomic is new in C11.) 2308 2309 GNU extensions: 2310 2311 declaration-specifiers: 2312 attributes declaration-specifiers[opt] 2313 2314 type-qualifier: 2315 address-space 2316 2317 address-space: 2318 identifier recognized by the target 2319 2320 storage-class-specifier: 2321 __thread 2322 2323 type-specifier: 2324 typeof-specifier 2325 __auto_type 2326 __intN 2327 _Decimal32 2328 _Decimal64 2329 _Decimal128 2330 _Fract 2331 _Accum 2332 _Sat 2333 2334 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037: 2335 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf) 2336 2337 atomic-type-specifier 2338 _Atomic ( type-name ) 2339 2340 Objective-C: 2341 2342 type-specifier: 2343 class-name objc-protocol-refs[opt] 2344 typedef-name objc-protocol-refs 2345 objc-protocol-refs 2346 */ 2347 2348 static void 2349 c_parser_declspecs (c_parser *parser, struct c_declspecs *specs, 2350 bool scspec_ok, bool typespec_ok, bool start_attr_ok, 2351 bool alignspec_ok, bool auto_type_ok, 2352 enum c_lookahead_kind la) 2353 { 2354 bool attrs_ok = start_attr_ok; 2355 bool seen_type = specs->typespec_kind != ctsk_none; 2356 2357 if (!typespec_ok) 2358 gcc_assert (la == cla_prefer_id); 2359 2360 while (c_parser_next_token_is (parser, CPP_NAME) 2361 || c_parser_next_token_is (parser, CPP_KEYWORD) 2362 || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS))) 2363 { 2364 struct c_typespec t; 2365 tree attrs; 2366 tree align; 2367 location_t loc = c_parser_peek_token (parser)->location; 2368 2369 /* If we cannot accept a type, exit if the next token must start 2370 one. Also, if we already have seen a tagged definition, 2371 a typename would be an error anyway and likely the user 2372 has simply forgotten a semicolon, so we exit. */ 2373 if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef) 2374 && c_parser_next_tokens_start_typename (parser, la) 2375 && !c_parser_next_token_is_qualifier (parser)) 2376 break; 2377 2378 if (c_parser_next_token_is (parser, CPP_NAME)) 2379 { 2380 c_token *name_token = c_parser_peek_token (parser); 2381 tree value = name_token->value; 2382 c_id_kind kind = name_token->id_kind; 2383 2384 if (kind == C_ID_ADDRSPACE) 2385 { 2386 addr_space_t as 2387 = name_token->keyword - RID_FIRST_ADDR_SPACE; 2388 declspecs_add_addrspace (name_token->location, specs, as); 2389 c_parser_consume_token (parser); 2390 attrs_ok = true; 2391 continue; 2392 } 2393 2394 gcc_assert (!c_parser_next_token_is_qualifier (parser)); 2395 2396 /* If we cannot accept a type, and the next token must start one, 2397 exit. Do the same if we already have seen a tagged definition, 2398 since it would be an error anyway and likely the user has simply 2399 forgotten a semicolon. */ 2400 if (seen_type || !c_parser_next_tokens_start_typename (parser, la)) 2401 break; 2402 2403 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or 2404 a C_ID_CLASSNAME. */ 2405 c_parser_consume_token (parser); 2406 seen_type = true; 2407 attrs_ok = true; 2408 if (kind == C_ID_ID) 2409 { 2410 error_at (loc, "unknown type name %qE", value); 2411 t.kind = ctsk_typedef; 2412 t.spec = error_mark_node; 2413 } 2414 else if (kind == C_ID_TYPENAME 2415 && (!c_dialect_objc () 2416 || c_parser_next_token_is_not (parser, CPP_LESS))) 2417 { 2418 t.kind = ctsk_typedef; 2419 /* For a typedef name, record the meaning, not the name. 2420 In case of 'foo foo, bar;'. */ 2421 t.spec = lookup_name (value); 2422 } 2423 else 2424 { 2425 tree proto = NULL_TREE; 2426 gcc_assert (c_dialect_objc ()); 2427 t.kind = ctsk_objc; 2428 if (c_parser_next_token_is (parser, CPP_LESS)) 2429 proto = c_parser_objc_protocol_refs (parser); 2430 t.spec = objc_get_protocol_qualified_type (value, proto); 2431 } 2432 t.expr = NULL_TREE; 2433 t.expr_const_operands = true; 2434 declspecs_add_type (name_token->location, specs, t); 2435 continue; 2436 } 2437 if (c_parser_next_token_is (parser, CPP_LESS)) 2438 { 2439 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" - 2440 nisse@lysator.liu.se. */ 2441 tree proto; 2442 gcc_assert (c_dialect_objc ()); 2443 if (!typespec_ok || seen_type) 2444 break; 2445 proto = c_parser_objc_protocol_refs (parser); 2446 t.kind = ctsk_objc; 2447 t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto); 2448 t.expr = NULL_TREE; 2449 t.expr_const_operands = true; 2450 declspecs_add_type (loc, specs, t); 2451 continue; 2452 } 2453 gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD)); 2454 switch (c_parser_peek_token (parser)->keyword) 2455 { 2456 case RID_STATIC: 2457 case RID_EXTERN: 2458 case RID_REGISTER: 2459 case RID_TYPEDEF: 2460 case RID_INLINE: 2461 case RID_NORETURN: 2462 case RID_AUTO: 2463 case RID_THREAD: 2464 if (!scspec_ok) 2465 goto out; 2466 attrs_ok = true; 2467 /* TODO: Distinguish between function specifiers (inline, noreturn) 2468 and storage class specifiers, either here or in 2469 declspecs_add_scspec. */ 2470 declspecs_add_scspec (loc, specs, 2471 c_parser_peek_token (parser)->value); 2472 c_parser_consume_token (parser); 2473 break; 2474 case RID_AUTO_TYPE: 2475 if (!auto_type_ok) 2476 goto out; 2477 /* Fall through. */ 2478 case RID_UNSIGNED: 2479 case RID_LONG: 2480 case RID_SHORT: 2481 case RID_SIGNED: 2482 case RID_COMPLEX: 2483 case RID_INT: 2484 case RID_CHAR: 2485 case RID_FLOAT: 2486 case RID_DOUBLE: 2487 case RID_VOID: 2488 case RID_DFLOAT32: 2489 case RID_DFLOAT64: 2490 case RID_DFLOAT128: 2491 case RID_BOOL: 2492 case RID_FRACT: 2493 case RID_ACCUM: 2494 case RID_SAT: 2495 case RID_INT_N_0: 2496 case RID_INT_N_1: 2497 case RID_INT_N_2: 2498 case RID_INT_N_3: 2499 if (!typespec_ok) 2500 goto out; 2501 attrs_ok = true; 2502 seen_type = true; 2503 if (c_dialect_objc ()) 2504 parser->objc_need_raw_identifier = true; 2505 t.kind = ctsk_resword; 2506 t.spec = c_parser_peek_token (parser)->value; 2507 t.expr = NULL_TREE; 2508 t.expr_const_operands = true; 2509 declspecs_add_type (loc, specs, t); 2510 c_parser_consume_token (parser); 2511 break; 2512 case RID_ENUM: 2513 if (!typespec_ok) 2514 goto out; 2515 attrs_ok = true; 2516 seen_type = true; 2517 t = c_parser_enum_specifier (parser); 2518 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec); 2519 declspecs_add_type (loc, specs, t); 2520 break; 2521 case RID_STRUCT: 2522 case RID_UNION: 2523 if (!typespec_ok) 2524 goto out; 2525 attrs_ok = true; 2526 seen_type = true; 2527 t = c_parser_struct_or_union_specifier (parser); 2528 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec); 2529 declspecs_add_type (loc, specs, t); 2530 break; 2531 case RID_TYPEOF: 2532 /* ??? The old parser rejected typeof after other type 2533 specifiers, but is a syntax error the best way of 2534 handling this? */ 2535 if (!typespec_ok || seen_type) 2536 goto out; 2537 attrs_ok = true; 2538 seen_type = true; 2539 t = c_parser_typeof_specifier (parser); 2540 declspecs_add_type (loc, specs, t); 2541 break; 2542 case RID_ATOMIC: 2543 /* C parser handling of Objective-C constructs needs 2544 checking for correct lvalue-to-rvalue conversions, and 2545 the code in build_modify_expr handling various 2546 Objective-C cases, and that in build_unary_op handling 2547 Objective-C cases for increment / decrement, also needs 2548 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types 2549 and objc_types_are_equivalent may also need updates. */ 2550 if (c_dialect_objc ()) 2551 sorry ("%<_Atomic%> in Objective-C"); 2552 /* C parser handling of OpenMP constructs needs checking for 2553 correct lvalue-to-rvalue conversions. */ 2554 if (flag_openmp) 2555 sorry ("%<_Atomic%> with OpenMP"); 2556 if (flag_isoc99) 2557 pedwarn_c99 (loc, OPT_Wpedantic, 2558 "ISO C99 does not support the %<_Atomic%> qualifier"); 2559 else 2560 pedwarn_c99 (loc, OPT_Wpedantic, 2561 "ISO C90 does not support the %<_Atomic%> qualifier"); 2562 attrs_ok = true; 2563 tree value; 2564 value = c_parser_peek_token (parser)->value; 2565 c_parser_consume_token (parser); 2566 if (typespec_ok && c_parser_next_token_is (parser, CPP_OPEN_PAREN)) 2567 { 2568 /* _Atomic ( type-name ). */ 2569 seen_type = true; 2570 c_parser_consume_token (parser); 2571 struct c_type_name *type = c_parser_type_name (parser); 2572 t.kind = ctsk_typeof; 2573 t.spec = error_mark_node; 2574 t.expr = NULL_TREE; 2575 t.expr_const_operands = true; 2576 if (type != NULL) 2577 t.spec = groktypename (type, &t.expr, 2578 &t.expr_const_operands); 2579 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 2580 "expected %<)%>"); 2581 if (t.spec != error_mark_node) 2582 { 2583 if (TREE_CODE (t.spec) == ARRAY_TYPE) 2584 error_at (loc, "%<_Atomic%>-qualified array type"); 2585 else if (TREE_CODE (t.spec) == FUNCTION_TYPE) 2586 error_at (loc, "%<_Atomic%>-qualified function type"); 2587 else if (TYPE_QUALS (t.spec) != TYPE_UNQUALIFIED) 2588 error_at (loc, "%<_Atomic%> applied to a qualified type"); 2589 else 2590 t.spec = c_build_qualified_type (t.spec, TYPE_QUAL_ATOMIC); 2591 } 2592 declspecs_add_type (loc, specs, t); 2593 } 2594 else 2595 declspecs_add_qual (loc, specs, value); 2596 break; 2597 case RID_CONST: 2598 case RID_VOLATILE: 2599 case RID_RESTRICT: 2600 attrs_ok = true; 2601 declspecs_add_qual (loc, specs, c_parser_peek_token (parser)->value); 2602 c_parser_consume_token (parser); 2603 break; 2604 case RID_ATTRIBUTE: 2605 if (!attrs_ok) 2606 goto out; 2607 attrs = c_parser_attributes (parser); 2608 declspecs_add_attrs (loc, specs, attrs); 2609 break; 2610 case RID_ALIGNAS: 2611 if (!alignspec_ok) 2612 goto out; 2613 align = c_parser_alignas_specifier (parser); 2614 declspecs_add_alignas (loc, specs, align); 2615 break; 2616 default: 2617 goto out; 2618 } 2619 } 2620 out: ; 2621 } 2622 2623 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2). 2624 2625 enum-specifier: 2626 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt] 2627 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt] 2628 enum attributes[opt] identifier 2629 2630 The form with trailing comma is new in C99. The forms with 2631 attributes are GNU extensions. In GNU C, we accept any expression 2632 without commas in the syntax (assignment expressions, not just 2633 conditional expressions); assignment expressions will be diagnosed 2634 as non-constant. 2635 2636 enumerator-list: 2637 enumerator 2638 enumerator-list , enumerator 2639 2640 enumerator: 2641 enumeration-constant 2642 enumeration-constant = constant-expression 2643 2644 GNU Extensions: 2645 2646 enumerator: 2647 enumeration-constant attributes[opt] 2648 enumeration-constant attributes[opt] = constant-expression 2649 2650 */ 2651 2652 static struct c_typespec 2653 c_parser_enum_specifier (c_parser *parser) 2654 { 2655 struct c_typespec ret; 2656 tree attrs; 2657 tree ident = NULL_TREE; 2658 location_t enum_loc; 2659 location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */ 2660 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM)); 2661 enum_loc = c_parser_peek_token (parser)->location; 2662 c_parser_consume_token (parser); 2663 attrs = c_parser_attributes (parser); 2664 enum_loc = c_parser_peek_token (parser)->location; 2665 /* Set the location in case we create a decl now. */ 2666 c_parser_set_source_position_from_token (c_parser_peek_token (parser)); 2667 if (c_parser_next_token_is (parser, CPP_NAME)) 2668 { 2669 ident = c_parser_peek_token (parser)->value; 2670 ident_loc = c_parser_peek_token (parser)->location; 2671 enum_loc = ident_loc; 2672 c_parser_consume_token (parser); 2673 } 2674 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) 2675 { 2676 /* Parse an enum definition. */ 2677 struct c_enum_contents the_enum; 2678 tree type; 2679 tree postfix_attrs; 2680 /* We chain the enumerators in reverse order, then put them in 2681 forward order at the end. */ 2682 tree values; 2683 timevar_push (TV_PARSE_ENUM); 2684 type = start_enum (enum_loc, &the_enum, ident); 2685 values = NULL_TREE; 2686 c_parser_consume_token (parser); 2687 while (true) 2688 { 2689 tree enum_id; 2690 tree enum_value; 2691 tree enum_decl; 2692 bool seen_comma; 2693 c_token *token; 2694 location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */ 2695 location_t decl_loc, value_loc; 2696 if (c_parser_next_token_is_not (parser, CPP_NAME)) 2697 { 2698 /* Give a nicer error for "enum {}". */ 2699 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE) 2700 && !parser->error) 2701 { 2702 error_at (c_parser_peek_token (parser)->location, 2703 "empty enum is invalid"); 2704 parser->error = true; 2705 } 2706 else 2707 c_parser_error (parser, "expected identifier"); 2708 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); 2709 values = error_mark_node; 2710 break; 2711 } 2712 token = c_parser_peek_token (parser); 2713 enum_id = token->value; 2714 /* Set the location in case we create a decl now. */ 2715 c_parser_set_source_position_from_token (token); 2716 decl_loc = value_loc = token->location; 2717 c_parser_consume_token (parser); 2718 /* Parse any specified attributes. */ 2719 tree enum_attrs = c_parser_attributes (parser); 2720 if (c_parser_next_token_is (parser, CPP_EQ)) 2721 { 2722 c_parser_consume_token (parser); 2723 value_loc = c_parser_peek_token (parser)->location; 2724 enum_value = c_parser_expr_no_commas (parser, NULL).value; 2725 } 2726 else 2727 enum_value = NULL_TREE; 2728 enum_decl = build_enumerator (decl_loc, value_loc, 2729 &the_enum, enum_id, enum_value); 2730 if (enum_attrs) 2731 decl_attributes (&TREE_PURPOSE (enum_decl), enum_attrs, 0); 2732 TREE_CHAIN (enum_decl) = values; 2733 values = enum_decl; 2734 seen_comma = false; 2735 if (c_parser_next_token_is (parser, CPP_COMMA)) 2736 { 2737 comma_loc = c_parser_peek_token (parser)->location; 2738 seen_comma = true; 2739 c_parser_consume_token (parser); 2740 } 2741 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) 2742 { 2743 if (seen_comma) 2744 pedwarn_c90 (comma_loc, OPT_Wpedantic, 2745 "comma at end of enumerator list"); 2746 c_parser_consume_token (parser); 2747 break; 2748 } 2749 if (!seen_comma) 2750 { 2751 c_parser_error (parser, "expected %<,%> or %<}%>"); 2752 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); 2753 values = error_mark_node; 2754 break; 2755 } 2756 } 2757 postfix_attrs = c_parser_attributes (parser); 2758 ret.spec = finish_enum (type, nreverse (values), 2759 chainon (attrs, postfix_attrs)); 2760 ret.kind = ctsk_tagdef; 2761 ret.expr = NULL_TREE; 2762 ret.expr_const_operands = true; 2763 timevar_pop (TV_PARSE_ENUM); 2764 return ret; 2765 } 2766 else if (!ident) 2767 { 2768 c_parser_error (parser, "expected %<{%>"); 2769 ret.spec = error_mark_node; 2770 ret.kind = ctsk_tagref; 2771 ret.expr = NULL_TREE; 2772 ret.expr_const_operands = true; 2773 return ret; 2774 } 2775 ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident); 2776 /* In ISO C, enumerated types can be referred to only if already 2777 defined. */ 2778 if (pedantic && !COMPLETE_TYPE_P (ret.spec)) 2779 { 2780 gcc_assert (ident); 2781 pedwarn (enum_loc, OPT_Wpedantic, 2782 "ISO C forbids forward references to %<enum%> types"); 2783 } 2784 return ret; 2785 } 2786 2787 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1). 2788 2789 struct-or-union-specifier: 2790 struct-or-union attributes[opt] identifier[opt] 2791 { struct-contents } attributes[opt] 2792 struct-or-union attributes[opt] identifier 2793 2794 struct-contents: 2795 struct-declaration-list 2796 2797 struct-declaration-list: 2798 struct-declaration ; 2799 struct-declaration-list struct-declaration ; 2800 2801 GNU extensions: 2802 2803 struct-contents: 2804 empty 2805 struct-declaration 2806 struct-declaration-list struct-declaration 2807 2808 struct-declaration-list: 2809 struct-declaration-list ; 2810 ; 2811 2812 (Note that in the syntax here, unlike that in ISO C, the semicolons 2813 are included here rather than in struct-declaration, in order to 2814 describe the syntax with extra semicolons and missing semicolon at 2815 end.) 2816 2817 Objective-C: 2818 2819 struct-declaration-list: 2820 @defs ( class-name ) 2821 2822 (Note this does not include a trailing semicolon, but can be 2823 followed by further declarations, and gets a pedwarn-if-pedantic 2824 when followed by a semicolon.) */ 2825 2826 static struct c_typespec 2827 c_parser_struct_or_union_specifier (c_parser *parser) 2828 { 2829 struct c_typespec ret; 2830 tree attrs; 2831 tree ident = NULL_TREE; 2832 location_t struct_loc; 2833 location_t ident_loc = UNKNOWN_LOCATION; 2834 enum tree_code code; 2835 switch (c_parser_peek_token (parser)->keyword) 2836 { 2837 case RID_STRUCT: 2838 code = RECORD_TYPE; 2839 break; 2840 case RID_UNION: 2841 code = UNION_TYPE; 2842 break; 2843 default: 2844 gcc_unreachable (); 2845 } 2846 struct_loc = c_parser_peek_token (parser)->location; 2847 c_parser_consume_token (parser); 2848 attrs = c_parser_attributes (parser); 2849 2850 /* Set the location in case we create a decl now. */ 2851 c_parser_set_source_position_from_token (c_parser_peek_token (parser)); 2852 2853 if (c_parser_next_token_is (parser, CPP_NAME)) 2854 { 2855 ident = c_parser_peek_token (parser)->value; 2856 ident_loc = c_parser_peek_token (parser)->location; 2857 struct_loc = ident_loc; 2858 c_parser_consume_token (parser); 2859 } 2860 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) 2861 { 2862 /* Parse a struct or union definition. Start the scope of the 2863 tag before parsing components. */ 2864 struct c_struct_parse_info *struct_info; 2865 tree type = start_struct (struct_loc, code, ident, &struct_info); 2866 tree postfix_attrs; 2867 /* We chain the components in reverse order, then put them in 2868 forward order at the end. Each struct-declaration may 2869 declare multiple components (comma-separated), so we must use 2870 chainon to join them, although when parsing each 2871 struct-declaration we can use TREE_CHAIN directly. 2872 2873 The theory behind all this is that there will be more 2874 semicolon separated fields than comma separated fields, and 2875 so we'll be minimizing the number of node traversals required 2876 by chainon. */ 2877 tree contents; 2878 timevar_push (TV_PARSE_STRUCT); 2879 contents = NULL_TREE; 2880 c_parser_consume_token (parser); 2881 /* Handle the Objective-C @defs construct, 2882 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */ 2883 if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS)) 2884 { 2885 tree name; 2886 gcc_assert (c_dialect_objc ()); 2887 c_parser_consume_token (parser); 2888 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 2889 goto end_at_defs; 2890 if (c_parser_next_token_is (parser, CPP_NAME) 2891 && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME) 2892 { 2893 name = c_parser_peek_token (parser)->value; 2894 c_parser_consume_token (parser); 2895 } 2896 else 2897 { 2898 c_parser_error (parser, "expected class name"); 2899 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 2900 goto end_at_defs; 2901 } 2902 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 2903 "expected %<)%>"); 2904 contents = nreverse (objc_get_class_ivars (name)); 2905 } 2906 end_at_defs: 2907 /* Parse the struct-declarations and semicolons. Problems with 2908 semicolons are diagnosed here; empty structures are diagnosed 2909 elsewhere. */ 2910 while (true) 2911 { 2912 tree decls; 2913 /* Parse any stray semicolon. */ 2914 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 2915 { 2916 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, 2917 "extra semicolon in struct or union specified"); 2918 c_parser_consume_token (parser); 2919 continue; 2920 } 2921 /* Stop if at the end of the struct or union contents. */ 2922 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) 2923 { 2924 c_parser_consume_token (parser); 2925 break; 2926 } 2927 /* Accept #pragmas at struct scope. */ 2928 if (c_parser_next_token_is (parser, CPP_PRAGMA)) 2929 { 2930 c_parser_pragma (parser, pragma_struct, NULL); 2931 continue; 2932 } 2933 /* Parse some comma-separated declarations, but not the 2934 trailing semicolon if any. */ 2935 decls = c_parser_struct_declaration (parser); 2936 contents = chainon (decls, contents); 2937 /* If no semicolon follows, either we have a parse error or 2938 are at the end of the struct or union and should 2939 pedwarn. */ 2940 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 2941 c_parser_consume_token (parser); 2942 else 2943 { 2944 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) 2945 pedwarn (c_parser_peek_token (parser)->location, 0, 2946 "no semicolon at end of struct or union"); 2947 else if (parser->error 2948 || !c_parser_next_token_starts_declspecs (parser)) 2949 { 2950 c_parser_error (parser, "expected %<;%>"); 2951 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); 2952 break; 2953 } 2954 2955 /* If we come here, we have already emitted an error 2956 for an expected `;', identifier or `(', and we also 2957 recovered already. Go on with the next field. */ 2958 } 2959 } 2960 postfix_attrs = c_parser_attributes (parser); 2961 ret.spec = finish_struct (struct_loc, type, nreverse (contents), 2962 chainon (attrs, postfix_attrs), struct_info); 2963 ret.kind = ctsk_tagdef; 2964 ret.expr = NULL_TREE; 2965 ret.expr_const_operands = true; 2966 timevar_pop (TV_PARSE_STRUCT); 2967 return ret; 2968 } 2969 else if (!ident) 2970 { 2971 c_parser_error (parser, "expected %<{%>"); 2972 ret.spec = error_mark_node; 2973 ret.kind = ctsk_tagref; 2974 ret.expr = NULL_TREE; 2975 ret.expr_const_operands = true; 2976 return ret; 2977 } 2978 ret = parser_xref_tag (ident_loc, code, ident); 2979 return ret; 2980 } 2981 2982 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without* 2983 the trailing semicolon. 2984 2985 struct-declaration: 2986 specifier-qualifier-list struct-declarator-list 2987 static_assert-declaration-no-semi 2988 2989 specifier-qualifier-list: 2990 type-specifier specifier-qualifier-list[opt] 2991 type-qualifier specifier-qualifier-list[opt] 2992 attributes specifier-qualifier-list[opt] 2993 2994 struct-declarator-list: 2995 struct-declarator 2996 struct-declarator-list , attributes[opt] struct-declarator 2997 2998 struct-declarator: 2999 declarator attributes[opt] 3000 declarator[opt] : constant-expression attributes[opt] 3001 3002 GNU extensions: 3003 3004 struct-declaration: 3005 __extension__ struct-declaration 3006 specifier-qualifier-list 3007 3008 Unlike the ISO C syntax, semicolons are handled elsewhere. The use 3009 of attributes where shown is a GNU extension. In GNU C, we accept 3010 any expression without commas in the syntax (assignment 3011 expressions, not just conditional expressions); assignment 3012 expressions will be diagnosed as non-constant. */ 3013 3014 static tree 3015 c_parser_struct_declaration (c_parser *parser) 3016 { 3017 struct c_declspecs *specs; 3018 tree prefix_attrs; 3019 tree all_prefix_attrs; 3020 tree decls; 3021 location_t decl_loc; 3022 if (c_parser_next_token_is_keyword (parser, RID_EXTENSION)) 3023 { 3024 int ext; 3025 tree decl; 3026 ext = disable_extension_diagnostics (); 3027 c_parser_consume_token (parser); 3028 decl = c_parser_struct_declaration (parser); 3029 restore_extension_diagnostics (ext); 3030 return decl; 3031 } 3032 if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)) 3033 { 3034 c_parser_static_assert_declaration_no_semi (parser); 3035 return NULL_TREE; 3036 } 3037 specs = build_null_declspecs (); 3038 decl_loc = c_parser_peek_token (parser)->location; 3039 /* Strictly by the standard, we shouldn't allow _Alignas here, 3040 but it appears to have been intended to allow it there, so 3041 we're keeping it as it is until WG14 reaches a conclusion 3042 of N1731. 3043 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */ 3044 c_parser_declspecs (parser, specs, false, true, true, 3045 true, false, cla_nonabstract_decl); 3046 if (parser->error) 3047 return NULL_TREE; 3048 if (!specs->declspecs_seen_p) 3049 { 3050 c_parser_error (parser, "expected specifier-qualifier-list"); 3051 return NULL_TREE; 3052 } 3053 finish_declspecs (specs); 3054 if (c_parser_next_token_is (parser, CPP_SEMICOLON) 3055 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) 3056 { 3057 tree ret; 3058 if (specs->typespec_kind == ctsk_none) 3059 { 3060 pedwarn (decl_loc, OPT_Wpedantic, 3061 "ISO C forbids member declarations with no members"); 3062 shadow_tag_warned (specs, pedantic); 3063 ret = NULL_TREE; 3064 } 3065 else 3066 { 3067 /* Support for unnamed structs or unions as members of 3068 structs or unions (which is [a] useful and [b] supports 3069 MS P-SDK). */ 3070 tree attrs = NULL; 3071 3072 ret = grokfield (c_parser_peek_token (parser)->location, 3073 build_id_declarator (NULL_TREE), specs, 3074 NULL_TREE, &attrs); 3075 if (ret) 3076 decl_attributes (&ret, attrs, 0); 3077 } 3078 return ret; 3079 } 3080 3081 /* Provide better error recovery. Note that a type name here is valid, 3082 and will be treated as a field name. */ 3083 if (specs->typespec_kind == ctsk_tagdef 3084 && TREE_CODE (specs->type) != ENUMERAL_TYPE 3085 && c_parser_next_token_starts_declspecs (parser) 3086 && !c_parser_next_token_is (parser, CPP_NAME)) 3087 { 3088 c_parser_error (parser, "expected %<;%>, identifier or %<(%>"); 3089 parser->error = false; 3090 return NULL_TREE; 3091 } 3092 3093 pending_xref_error (); 3094 prefix_attrs = specs->attrs; 3095 all_prefix_attrs = prefix_attrs; 3096 specs->attrs = NULL_TREE; 3097 decls = NULL_TREE; 3098 while (true) 3099 { 3100 /* Declaring one or more declarators or un-named bit-fields. */ 3101 struct c_declarator *declarator; 3102 bool dummy = false; 3103 if (c_parser_next_token_is (parser, CPP_COLON)) 3104 declarator = build_id_declarator (NULL_TREE); 3105 else 3106 declarator = c_parser_declarator (parser, 3107 specs->typespec_kind != ctsk_none, 3108 C_DTR_NORMAL, &dummy); 3109 if (declarator == NULL) 3110 { 3111 c_parser_skip_to_end_of_block_or_statement (parser); 3112 break; 3113 } 3114 if (c_parser_next_token_is (parser, CPP_COLON) 3115 || c_parser_next_token_is (parser, CPP_COMMA) 3116 || c_parser_next_token_is (parser, CPP_SEMICOLON) 3117 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE) 3118 || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) 3119 { 3120 tree postfix_attrs = NULL_TREE; 3121 tree width = NULL_TREE; 3122 tree d; 3123 if (c_parser_next_token_is (parser, CPP_COLON)) 3124 { 3125 c_parser_consume_token (parser); 3126 width = c_parser_expr_no_commas (parser, NULL).value; 3127 } 3128 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) 3129 postfix_attrs = c_parser_attributes (parser); 3130 d = grokfield (c_parser_peek_token (parser)->location, 3131 declarator, specs, width, &all_prefix_attrs); 3132 decl_attributes (&d, chainon (postfix_attrs, 3133 all_prefix_attrs), 0); 3134 DECL_CHAIN (d) = decls; 3135 decls = d; 3136 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) 3137 all_prefix_attrs = chainon (c_parser_attributes (parser), 3138 prefix_attrs); 3139 else 3140 all_prefix_attrs = prefix_attrs; 3141 if (c_parser_next_token_is (parser, CPP_COMMA)) 3142 c_parser_consume_token (parser); 3143 else if (c_parser_next_token_is (parser, CPP_SEMICOLON) 3144 || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) 3145 { 3146 /* Semicolon consumed in caller. */ 3147 break; 3148 } 3149 else 3150 { 3151 c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>"); 3152 break; 3153 } 3154 } 3155 else 3156 { 3157 c_parser_error (parser, 3158 "expected %<:%>, %<,%>, %<;%>, %<}%> or " 3159 "%<__attribute__%>"); 3160 break; 3161 } 3162 } 3163 return decls; 3164 } 3165 3166 /* Parse a typeof specifier (a GNU extension). 3167 3168 typeof-specifier: 3169 typeof ( expression ) 3170 typeof ( type-name ) 3171 */ 3172 3173 static struct c_typespec 3174 c_parser_typeof_specifier (c_parser *parser) 3175 { 3176 struct c_typespec ret; 3177 ret.kind = ctsk_typeof; 3178 ret.spec = error_mark_node; 3179 ret.expr = NULL_TREE; 3180 ret.expr_const_operands = true; 3181 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF)); 3182 c_parser_consume_token (parser); 3183 c_inhibit_evaluation_warnings++; 3184 in_typeof++; 3185 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 3186 { 3187 c_inhibit_evaluation_warnings--; 3188 in_typeof--; 3189 return ret; 3190 } 3191 if (c_parser_next_tokens_start_typename (parser, cla_prefer_id)) 3192 { 3193 struct c_type_name *type = c_parser_type_name (parser); 3194 c_inhibit_evaluation_warnings--; 3195 in_typeof--; 3196 if (type != NULL) 3197 { 3198 ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands); 3199 pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE)); 3200 } 3201 } 3202 else 3203 { 3204 bool was_vm; 3205 location_t here = c_parser_peek_token (parser)->location; 3206 struct c_expr expr = c_parser_expression (parser); 3207 c_inhibit_evaluation_warnings--; 3208 in_typeof--; 3209 if (TREE_CODE (expr.value) == COMPONENT_REF 3210 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1))) 3211 error_at (here, "%<typeof%> applied to a bit-field"); 3212 mark_exp_read (expr.value); 3213 ret.spec = TREE_TYPE (expr.value); 3214 was_vm = variably_modified_type_p (ret.spec, NULL_TREE); 3215 /* This is returned with the type so that when the type is 3216 evaluated, this can be evaluated. */ 3217 if (was_vm) 3218 ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands); 3219 pop_maybe_used (was_vm); 3220 /* For use in macros such as those in <stdatomic.h>, remove all 3221 qualifiers from atomic types. (const can be an issue for more macros 3222 using typeof than just the <stdatomic.h> ones.) */ 3223 if (ret.spec != error_mark_node && TYPE_ATOMIC (ret.spec)) 3224 ret.spec = c_build_qualified_type (ret.spec, TYPE_UNQUALIFIED); 3225 } 3226 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 3227 return ret; 3228 } 3229 3230 /* Parse an alignment-specifier. 3231 3232 C11 6.7.5: 3233 3234 alignment-specifier: 3235 _Alignas ( type-name ) 3236 _Alignas ( constant-expression ) 3237 */ 3238 3239 static tree 3240 c_parser_alignas_specifier (c_parser * parser) 3241 { 3242 tree ret = error_mark_node; 3243 location_t loc = c_parser_peek_token (parser)->location; 3244 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNAS)); 3245 c_parser_consume_token (parser); 3246 if (flag_isoc99) 3247 pedwarn_c99 (loc, OPT_Wpedantic, 3248 "ISO C99 does not support %<_Alignas%>"); 3249 else 3250 pedwarn_c99 (loc, OPT_Wpedantic, 3251 "ISO C90 does not support %<_Alignas%>"); 3252 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 3253 return ret; 3254 if (c_parser_next_tokens_start_typename (parser, cla_prefer_id)) 3255 { 3256 struct c_type_name *type = c_parser_type_name (parser); 3257 if (type != NULL) 3258 ret = c_sizeof_or_alignof_type (loc, groktypename (type, NULL, NULL), 3259 false, true, 1); 3260 } 3261 else 3262 ret = c_parser_expr_no_commas (parser, NULL).value; 3263 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 3264 return ret; 3265 } 3266 3267 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4, 3268 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may 3269 be redeclared; otherwise it may not. KIND indicates which kind of 3270 declarator is wanted. Returns a valid declarator except in the 3271 case of a syntax error in which case NULL is returned. *SEEN_ID is 3272 set to true if an identifier being declared is seen; this is used 3273 to diagnose bad forms of abstract array declarators and to 3274 determine whether an identifier list is syntactically permitted. 3275 3276 declarator: 3277 pointer[opt] direct-declarator 3278 3279 direct-declarator: 3280 identifier 3281 ( attributes[opt] declarator ) 3282 direct-declarator array-declarator 3283 direct-declarator ( parameter-type-list ) 3284 direct-declarator ( identifier-list[opt] ) 3285 3286 pointer: 3287 * type-qualifier-list[opt] 3288 * type-qualifier-list[opt] pointer 3289 3290 type-qualifier-list: 3291 type-qualifier 3292 attributes 3293 type-qualifier-list type-qualifier 3294 type-qualifier-list attributes 3295 3296 array-declarator: 3297 [ type-qualifier-list[opt] assignment-expression[opt] ] 3298 [ static type-qualifier-list[opt] assignment-expression ] 3299 [ type-qualifier-list static assignment-expression ] 3300 [ type-qualifier-list[opt] * ] 3301 3302 parameter-type-list: 3303 parameter-list 3304 parameter-list , ... 3305 3306 parameter-list: 3307 parameter-declaration 3308 parameter-list , parameter-declaration 3309 3310 parameter-declaration: 3311 declaration-specifiers declarator attributes[opt] 3312 declaration-specifiers abstract-declarator[opt] attributes[opt] 3313 3314 identifier-list: 3315 identifier 3316 identifier-list , identifier 3317 3318 abstract-declarator: 3319 pointer 3320 pointer[opt] direct-abstract-declarator 3321 3322 direct-abstract-declarator: 3323 ( attributes[opt] abstract-declarator ) 3324 direct-abstract-declarator[opt] array-declarator 3325 direct-abstract-declarator[opt] ( parameter-type-list[opt] ) 3326 3327 GNU extensions: 3328 3329 direct-declarator: 3330 direct-declarator ( parameter-forward-declarations 3331 parameter-type-list[opt] ) 3332 3333 direct-abstract-declarator: 3334 direct-abstract-declarator[opt] ( parameter-forward-declarations 3335 parameter-type-list[opt] ) 3336 3337 parameter-forward-declarations: 3338 parameter-list ; 3339 parameter-forward-declarations parameter-list ; 3340 3341 The uses of attributes shown above are GNU extensions. 3342 3343 Some forms of array declarator are not included in C99 in the 3344 syntax for abstract declarators; these are disallowed elsewhere. 3345 This may be a defect (DR#289). 3346 3347 This function also accepts an omitted abstract declarator as being 3348 an abstract declarator, although not part of the formal syntax. */ 3349 3350 static struct c_declarator * 3351 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind, 3352 bool *seen_id) 3353 { 3354 /* Parse any initial pointer part. */ 3355 if (c_parser_next_token_is (parser, CPP_MULT)) 3356 { 3357 struct c_declspecs *quals_attrs = build_null_declspecs (); 3358 struct c_declarator *inner; 3359 c_parser_consume_token (parser); 3360 c_parser_declspecs (parser, quals_attrs, false, false, true, 3361 false, false, cla_prefer_id); 3362 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id); 3363 if (inner == NULL) 3364 return NULL; 3365 else 3366 return make_pointer_declarator (quals_attrs, inner); 3367 } 3368 /* Now we have a direct declarator, direct abstract declarator or 3369 nothing (which counts as a direct abstract declarator here). */ 3370 return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id); 3371 } 3372 3373 /* Parse a direct declarator or direct abstract declarator; arguments 3374 as c_parser_declarator. */ 3375 3376 static struct c_declarator * 3377 c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind, 3378 bool *seen_id) 3379 { 3380 /* The direct declarator must start with an identifier (possibly 3381 omitted) or a parenthesized declarator (possibly abstract). In 3382 an ordinary declarator, initial parentheses must start a 3383 parenthesized declarator. In an abstract declarator or parameter 3384 declarator, they could start a parenthesized declarator or a 3385 parameter list. To tell which, the open parenthesis and any 3386 following attributes must be read. If a declaration specifier 3387 follows, then it is a parameter list; if the specifier is a 3388 typedef name, there might be an ambiguity about redeclaring it, 3389 which is resolved in the direction of treating it as a typedef 3390 name. If a close parenthesis follows, it is also an empty 3391 parameter list, as the syntax does not permit empty abstract 3392 declarators. Otherwise, it is a parenthesized declarator (in 3393 which case the analysis may be repeated inside it, recursively). 3394 3395 ??? There is an ambiguity in a parameter declaration "int 3396 (__attribute__((foo)) x)", where x is not a typedef name: it 3397 could be an abstract declarator for a function, or declare x with 3398 parentheses. The proper resolution of this ambiguity needs 3399 documenting. At present we follow an accident of the old 3400 parser's implementation, whereby the first parameter must have 3401 some declaration specifiers other than just attributes. Thus as 3402 a parameter declaration it is treated as a parenthesized 3403 parameter named x, and as an abstract declarator it is 3404 rejected. 3405 3406 ??? Also following the old parser, attributes inside an empty 3407 parameter list are ignored, making it a list not yielding a 3408 prototype, rather than giving an error or making it have one 3409 parameter with implicit type int. 3410 3411 ??? Also following the old parser, typedef names may be 3412 redeclared in declarators, but not Objective-C class names. */ 3413 3414 if (kind != C_DTR_ABSTRACT 3415 && c_parser_next_token_is (parser, CPP_NAME) 3416 && ((type_seen_p 3417 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME 3418 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)) 3419 || c_parser_peek_token (parser)->id_kind == C_ID_ID)) 3420 { 3421 struct c_declarator *inner 3422 = build_id_declarator (c_parser_peek_token (parser)->value); 3423 *seen_id = true; 3424 inner->id_loc = c_parser_peek_token (parser)->location; 3425 c_parser_consume_token (parser); 3426 return c_parser_direct_declarator_inner (parser, *seen_id, inner); 3427 } 3428 3429 if (kind != C_DTR_NORMAL 3430 && c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) 3431 { 3432 struct c_declarator *inner = build_id_declarator (NULL_TREE); 3433 return c_parser_direct_declarator_inner (parser, *seen_id, inner); 3434 } 3435 3436 /* Either we are at the end of an abstract declarator, or we have 3437 parentheses. */ 3438 3439 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) 3440 { 3441 tree attrs; 3442 struct c_declarator *inner; 3443 c_parser_consume_token (parser); 3444 attrs = c_parser_attributes (parser); 3445 if (kind != C_DTR_NORMAL 3446 && (c_parser_next_token_starts_declspecs (parser) 3447 || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))) 3448 { 3449 struct c_arg_info *args 3450 = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL, 3451 attrs); 3452 if (args == NULL) 3453 return NULL; 3454 else 3455 { 3456 inner 3457 = build_function_declarator (args, 3458 build_id_declarator (NULL_TREE)); 3459 return c_parser_direct_declarator_inner (parser, *seen_id, 3460 inner); 3461 } 3462 } 3463 /* A parenthesized declarator. */ 3464 inner = c_parser_declarator (parser, type_seen_p, kind, seen_id); 3465 if (inner != NULL && attrs != NULL) 3466 inner = build_attrs_declarator (attrs, inner); 3467 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 3468 { 3469 c_parser_consume_token (parser); 3470 if (inner == NULL) 3471 return NULL; 3472 else 3473 return c_parser_direct_declarator_inner (parser, *seen_id, inner); 3474 } 3475 else 3476 { 3477 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 3478 "expected %<)%>"); 3479 return NULL; 3480 } 3481 } 3482 else 3483 { 3484 if (kind == C_DTR_NORMAL) 3485 { 3486 c_parser_error (parser, "expected identifier or %<(%>"); 3487 return NULL; 3488 } 3489 else 3490 return build_id_declarator (NULL_TREE); 3491 } 3492 } 3493 3494 /* Parse part of a direct declarator or direct abstract declarator, 3495 given that some (in INNER) has already been parsed; ID_PRESENT is 3496 true if an identifier is present, false for an abstract 3497 declarator. */ 3498 3499 static struct c_declarator * 3500 c_parser_direct_declarator_inner (c_parser *parser, bool id_present, 3501 struct c_declarator *inner) 3502 { 3503 /* Parse a sequence of array declarators and parameter lists. */ 3504 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) 3505 { 3506 location_t brace_loc = c_parser_peek_token (parser)->location; 3507 struct c_declarator *declarator; 3508 struct c_declspecs *quals_attrs = build_null_declspecs (); 3509 bool static_seen; 3510 bool star_seen; 3511 struct c_expr dimen; 3512 dimen.value = NULL_TREE; 3513 dimen.original_code = ERROR_MARK; 3514 dimen.original_type = NULL_TREE; 3515 c_parser_consume_token (parser); 3516 c_parser_declspecs (parser, quals_attrs, false, false, true, 3517 false, false, cla_prefer_id); 3518 static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC); 3519 if (static_seen) 3520 c_parser_consume_token (parser); 3521 if (static_seen && !quals_attrs->declspecs_seen_p) 3522 c_parser_declspecs (parser, quals_attrs, false, false, true, 3523 false, false, cla_prefer_id); 3524 if (!quals_attrs->declspecs_seen_p) 3525 quals_attrs = NULL; 3526 /* If "static" is present, there must be an array dimension. 3527 Otherwise, there may be a dimension, "*", or no 3528 dimension. */ 3529 if (static_seen) 3530 { 3531 star_seen = false; 3532 dimen = c_parser_expr_no_commas (parser, NULL); 3533 } 3534 else 3535 { 3536 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) 3537 { 3538 dimen.value = NULL_TREE; 3539 star_seen = false; 3540 } 3541 else if (flag_cilkplus 3542 && c_parser_next_token_is (parser, CPP_COLON)) 3543 { 3544 dimen.value = error_mark_node; 3545 star_seen = false; 3546 error_at (c_parser_peek_token (parser)->location, 3547 "array notations cannot be used in declaration"); 3548 c_parser_consume_token (parser); 3549 } 3550 else if (c_parser_next_token_is (parser, CPP_MULT)) 3551 { 3552 if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE) 3553 { 3554 dimen.value = NULL_TREE; 3555 star_seen = true; 3556 c_parser_consume_token (parser); 3557 } 3558 else 3559 { 3560 star_seen = false; 3561 dimen = c_parser_expr_no_commas (parser, NULL); 3562 } 3563 } 3564 else 3565 { 3566 star_seen = false; 3567 dimen = c_parser_expr_no_commas (parser, NULL); 3568 } 3569 } 3570 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) 3571 c_parser_consume_token (parser); 3572 else if (flag_cilkplus 3573 && c_parser_next_token_is (parser, CPP_COLON)) 3574 { 3575 error_at (c_parser_peek_token (parser)->location, 3576 "array notations cannot be used in declaration"); 3577 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); 3578 return NULL; 3579 } 3580 else 3581 { 3582 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, 3583 "expected %<]%>"); 3584 return NULL; 3585 } 3586 if (dimen.value) 3587 dimen = convert_lvalue_to_rvalue (brace_loc, dimen, true, true); 3588 declarator = build_array_declarator (brace_loc, dimen.value, quals_attrs, 3589 static_seen, star_seen); 3590 if (declarator == NULL) 3591 return NULL; 3592 inner = set_array_declarator_inner (declarator, inner); 3593 return c_parser_direct_declarator_inner (parser, id_present, inner); 3594 } 3595 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) 3596 { 3597 tree attrs; 3598 struct c_arg_info *args; 3599 c_parser_consume_token (parser); 3600 attrs = c_parser_attributes (parser); 3601 args = c_parser_parms_declarator (parser, id_present, attrs); 3602 if (args == NULL) 3603 return NULL; 3604 else 3605 { 3606 inner = build_function_declarator (args, inner); 3607 return c_parser_direct_declarator_inner (parser, id_present, inner); 3608 } 3609 } 3610 return inner; 3611 } 3612 3613 /* Parse a parameter list or identifier list, including the closing 3614 parenthesis but not the opening one. ATTRS are the attributes at 3615 the start of the list. ID_LIST_OK is true if an identifier list is 3616 acceptable; such a list must not have attributes at the start. */ 3617 3618 static struct c_arg_info * 3619 c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs) 3620 { 3621 push_scope (); 3622 declare_parm_level (); 3623 /* If the list starts with an identifier, it is an identifier list. 3624 Otherwise, it is either a prototype list or an empty list. */ 3625 if (id_list_ok 3626 && !attrs 3627 && c_parser_next_token_is (parser, CPP_NAME) 3628 && c_parser_peek_token (parser)->id_kind == C_ID_ID 3629 3630 /* Look ahead to detect typos in type names. */ 3631 && c_parser_peek_2nd_token (parser)->type != CPP_NAME 3632 && c_parser_peek_2nd_token (parser)->type != CPP_MULT 3633 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN 3634 && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE) 3635 { 3636 tree list = NULL_TREE, *nextp = &list; 3637 while (c_parser_next_token_is (parser, CPP_NAME) 3638 && c_parser_peek_token (parser)->id_kind == C_ID_ID) 3639 { 3640 *nextp = build_tree_list (NULL_TREE, 3641 c_parser_peek_token (parser)->value); 3642 nextp = & TREE_CHAIN (*nextp); 3643 c_parser_consume_token (parser); 3644 if (c_parser_next_token_is_not (parser, CPP_COMMA)) 3645 break; 3646 c_parser_consume_token (parser); 3647 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 3648 { 3649 c_parser_error (parser, "expected identifier"); 3650 break; 3651 } 3652 } 3653 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 3654 { 3655 struct c_arg_info *ret = build_arg_info (); 3656 ret->types = list; 3657 c_parser_consume_token (parser); 3658 pop_scope (); 3659 return ret; 3660 } 3661 else 3662 { 3663 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 3664 "expected %<)%>"); 3665 pop_scope (); 3666 return NULL; 3667 } 3668 } 3669 else 3670 { 3671 struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs, 3672 NULL); 3673 pop_scope (); 3674 return ret; 3675 } 3676 } 3677 3678 /* Parse a parameter list (possibly empty), including the closing 3679 parenthesis but not the opening one. ATTRS are the attributes at 3680 the start of the list. EXPR is NULL or an expression that needs to 3681 be evaluated for the side effects of array size expressions in the 3682 parameters. */ 3683 3684 static struct c_arg_info * 3685 c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr) 3686 { 3687 bool bad_parm = false; 3688 3689 /* ??? Following the old parser, forward parameter declarations may 3690 use abstract declarators, and if no real parameter declarations 3691 follow the forward declarations then this is not diagnosed. Also 3692 note as above that attributes are ignored as the only contents of 3693 the parentheses, or as the only contents after forward 3694 declarations. */ 3695 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 3696 { 3697 struct c_arg_info *ret = build_arg_info (); 3698 c_parser_consume_token (parser); 3699 return ret; 3700 } 3701 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) 3702 { 3703 struct c_arg_info *ret = build_arg_info (); 3704 3705 if (flag_allow_parameterless_variadic_functions) 3706 { 3707 /* F (...) is allowed. */ 3708 ret->types = NULL_TREE; 3709 } 3710 else 3711 { 3712 /* Suppress -Wold-style-definition for this case. */ 3713 ret->types = error_mark_node; 3714 error_at (c_parser_peek_token (parser)->location, 3715 "ISO C requires a named argument before %<...%>"); 3716 } 3717 c_parser_consume_token (parser); 3718 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 3719 { 3720 c_parser_consume_token (parser); 3721 return ret; 3722 } 3723 else 3724 { 3725 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 3726 "expected %<)%>"); 3727 return NULL; 3728 } 3729 } 3730 /* Nonempty list of parameters, either terminated with semicolon 3731 (forward declarations; recurse) or with close parenthesis (normal 3732 function) or with ", ... )" (variadic function). */ 3733 while (true) 3734 { 3735 /* Parse a parameter. */ 3736 struct c_parm *parm = c_parser_parameter_declaration (parser, attrs); 3737 attrs = NULL_TREE; 3738 if (parm == NULL) 3739 bad_parm = true; 3740 else 3741 push_parm_decl (parm, &expr); 3742 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 3743 { 3744 tree new_attrs; 3745 c_parser_consume_token (parser); 3746 mark_forward_parm_decls (); 3747 new_attrs = c_parser_attributes (parser); 3748 return c_parser_parms_list_declarator (parser, new_attrs, expr); 3749 } 3750 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 3751 { 3752 c_parser_consume_token (parser); 3753 if (bad_parm) 3754 return NULL; 3755 else 3756 return get_parm_info (false, expr); 3757 } 3758 if (!c_parser_require (parser, CPP_COMMA, 3759 "expected %<;%>, %<,%> or %<)%>")) 3760 { 3761 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 3762 return NULL; 3763 } 3764 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) 3765 { 3766 c_parser_consume_token (parser); 3767 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 3768 { 3769 c_parser_consume_token (parser); 3770 if (bad_parm) 3771 return NULL; 3772 else 3773 return get_parm_info (true, expr); 3774 } 3775 else 3776 { 3777 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 3778 "expected %<)%>"); 3779 return NULL; 3780 } 3781 } 3782 } 3783 } 3784 3785 /* Parse a parameter declaration. ATTRS are the attributes at the 3786 start of the declaration if it is the first parameter. */ 3787 3788 static struct c_parm * 3789 c_parser_parameter_declaration (c_parser *parser, tree attrs) 3790 { 3791 struct c_declspecs *specs; 3792 struct c_declarator *declarator; 3793 tree prefix_attrs; 3794 tree postfix_attrs = NULL_TREE; 3795 bool dummy = false; 3796 3797 /* Accept #pragmas between parameter declarations. */ 3798 while (c_parser_next_token_is (parser, CPP_PRAGMA)) 3799 c_parser_pragma (parser, pragma_param, NULL); 3800 3801 if (!c_parser_next_token_starts_declspecs (parser)) 3802 { 3803 c_token *token = c_parser_peek_token (parser); 3804 if (parser->error) 3805 return NULL; 3806 c_parser_set_source_position_from_token (token); 3807 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type)) 3808 { 3809 error_at (token->location, "unknown type name %qE", token->value); 3810 parser->error = true; 3811 } 3812 /* ??? In some Objective-C cases '...' isn't applicable so there 3813 should be a different message. */ 3814 else 3815 c_parser_error (parser, 3816 "expected declaration specifiers or %<...%>"); 3817 c_parser_skip_to_end_of_parameter (parser); 3818 return NULL; 3819 } 3820 specs = build_null_declspecs (); 3821 if (attrs) 3822 { 3823 declspecs_add_attrs (input_location, specs, attrs); 3824 attrs = NULL_TREE; 3825 } 3826 c_parser_declspecs (parser, specs, true, true, true, true, false, 3827 cla_nonabstract_decl); 3828 finish_declspecs (specs); 3829 pending_xref_error (); 3830 prefix_attrs = specs->attrs; 3831 specs->attrs = NULL_TREE; 3832 declarator = c_parser_declarator (parser, 3833 specs->typespec_kind != ctsk_none, 3834 C_DTR_PARM, &dummy); 3835 if (declarator == NULL) 3836 { 3837 c_parser_skip_until_found (parser, CPP_COMMA, NULL); 3838 return NULL; 3839 } 3840 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) 3841 postfix_attrs = c_parser_attributes (parser); 3842 return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs), 3843 declarator); 3844 } 3845 3846 /* Parse a string literal in an asm expression. It should not be 3847 translated, and wide string literals are an error although 3848 permitted by the syntax. This is a GNU extension. 3849 3850 asm-string-literal: 3851 string-literal 3852 3853 ??? At present, following the old parser, the caller needs to have 3854 set lex_untranslated_string to 1. It would be better to follow the 3855 C++ parser rather than using this kludge. */ 3856 3857 static tree 3858 c_parser_asm_string_literal (c_parser *parser) 3859 { 3860 tree str; 3861 int save_flag = warn_overlength_strings; 3862 warn_overlength_strings = 0; 3863 if (c_parser_next_token_is (parser, CPP_STRING)) 3864 { 3865 str = c_parser_peek_token (parser)->value; 3866 c_parser_consume_token (parser); 3867 } 3868 else if (c_parser_next_token_is (parser, CPP_WSTRING)) 3869 { 3870 error_at (c_parser_peek_token (parser)->location, 3871 "wide string literal in %<asm%>"); 3872 str = build_string (1, ""); 3873 c_parser_consume_token (parser); 3874 } 3875 else 3876 { 3877 c_parser_error (parser, "expected string literal"); 3878 str = NULL_TREE; 3879 } 3880 warn_overlength_strings = save_flag; 3881 return str; 3882 } 3883 3884 /* Parse a simple asm expression. This is used in restricted 3885 contexts, where a full expression with inputs and outputs does not 3886 make sense. This is a GNU extension. 3887 3888 simple-asm-expr: 3889 asm ( asm-string-literal ) 3890 */ 3891 3892 static tree 3893 c_parser_simple_asm_expr (c_parser *parser) 3894 { 3895 tree str; 3896 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM)); 3897 /* ??? Follow the C++ parser rather than using the 3898 lex_untranslated_string kludge. */ 3899 parser->lex_untranslated_string = true; 3900 c_parser_consume_token (parser); 3901 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 3902 { 3903 parser->lex_untranslated_string = false; 3904 return NULL_TREE; 3905 } 3906 str = c_parser_asm_string_literal (parser); 3907 parser->lex_untranslated_string = false; 3908 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) 3909 { 3910 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 3911 return NULL_TREE; 3912 } 3913 return str; 3914 } 3915 3916 static tree 3917 c_parser_attribute_any_word (c_parser *parser) 3918 { 3919 tree attr_name = NULL_TREE; 3920 3921 if (c_parser_next_token_is (parser, CPP_KEYWORD)) 3922 { 3923 /* ??? See comment above about what keywords are accepted here. */ 3924 bool ok; 3925 switch (c_parser_peek_token (parser)->keyword) 3926 { 3927 case RID_STATIC: 3928 case RID_UNSIGNED: 3929 case RID_LONG: 3930 case RID_CONST: 3931 case RID_EXTERN: 3932 case RID_REGISTER: 3933 case RID_TYPEDEF: 3934 case RID_SHORT: 3935 case RID_INLINE: 3936 case RID_NORETURN: 3937 case RID_VOLATILE: 3938 case RID_SIGNED: 3939 case RID_AUTO: 3940 case RID_RESTRICT: 3941 case RID_COMPLEX: 3942 case RID_THREAD: 3943 case RID_INT: 3944 case RID_CHAR: 3945 case RID_FLOAT: 3946 case RID_DOUBLE: 3947 case RID_VOID: 3948 case RID_DFLOAT32: 3949 case RID_DFLOAT64: 3950 case RID_DFLOAT128: 3951 case RID_BOOL: 3952 case RID_FRACT: 3953 case RID_ACCUM: 3954 case RID_SAT: 3955 case RID_TRANSACTION_ATOMIC: 3956 case RID_TRANSACTION_CANCEL: 3957 case RID_ATOMIC: 3958 case RID_AUTO_TYPE: 3959 case RID_INT_N_0: 3960 case RID_INT_N_1: 3961 case RID_INT_N_2: 3962 case RID_INT_N_3: 3963 ok = true; 3964 break; 3965 default: 3966 ok = false; 3967 break; 3968 } 3969 if (!ok) 3970 return NULL_TREE; 3971 3972 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */ 3973 attr_name = ridpointers[(int) c_parser_peek_token (parser)->keyword]; 3974 } 3975 else if (c_parser_next_token_is (parser, CPP_NAME)) 3976 attr_name = c_parser_peek_token (parser)->value; 3977 3978 return attr_name; 3979 } 3980 3981 #define CILK_SIMD_FN_CLAUSE_MASK \ 3982 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \ 3983 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \ 3984 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \ 3985 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \ 3986 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK)) 3987 3988 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus. 3989 VEC_TOKEN is the "vector" token that is replaced with "simd" and 3990 pushed into the token list. 3991 Syntax: 3992 vector 3993 vector (<vector attributes>). */ 3994 3995 static void 3996 c_parser_cilk_simd_fn_vector_attrs (c_parser *parser, c_token vec_token) 3997 { 3998 gcc_assert (is_cilkplus_vector_p (vec_token.value)); 3999 4000 int paren_scope = 0; 4001 vec_safe_push (parser->cilk_simd_fn_tokens, vec_token); 4002 /* Consume the "vector" token. */ 4003 c_parser_consume_token (parser); 4004 4005 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) 4006 { 4007 c_parser_consume_token (parser); 4008 paren_scope++; 4009 } 4010 while (paren_scope > 0) 4011 { 4012 c_token *token = c_parser_peek_token (parser); 4013 if (token->type == CPP_OPEN_PAREN) 4014 paren_scope++; 4015 else if (token->type == CPP_CLOSE_PAREN) 4016 paren_scope--; 4017 /* Do not push the last ')' since we are not pushing the '('. */ 4018 if (!(token->type == CPP_CLOSE_PAREN && paren_scope == 0)) 4019 vec_safe_push (parser->cilk_simd_fn_tokens, *token); 4020 c_parser_consume_token (parser); 4021 } 4022 4023 /* Since we are converting an attribute to a pragma, we need to end the 4024 attribute with PRAGMA_EOL. */ 4025 c_token eol_token; 4026 memset (&eol_token, 0, sizeof (eol_token)); 4027 eol_token.type = CPP_PRAGMA_EOL; 4028 vec_safe_push (parser->cilk_simd_fn_tokens, eol_token); 4029 } 4030 4031 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */ 4032 4033 static void 4034 c_finish_cilk_simd_fn_tokens (c_parser *parser) 4035 { 4036 c_token last_token = parser->cilk_simd_fn_tokens->last (); 4037 4038 /* c_parser_attributes is called in several places, so if these EOF 4039 tokens are already inserted, then don't do them again. */ 4040 if (last_token.type == CPP_EOF) 4041 return; 4042 4043 /* Two CPP_EOF token are added as a safety net since the normal C 4044 front-end has two token look-ahead. */ 4045 c_token eof_token; 4046 eof_token.type = CPP_EOF; 4047 vec_safe_push (parser->cilk_simd_fn_tokens, eof_token); 4048 vec_safe_push (parser->cilk_simd_fn_tokens, eof_token); 4049 } 4050 4051 /* Parse (possibly empty) attributes. This is a GNU extension. 4052 4053 attributes: 4054 empty 4055 attributes attribute 4056 4057 attribute: 4058 __attribute__ ( ( attribute-list ) ) 4059 4060 attribute-list: 4061 attrib 4062 attribute_list , attrib 4063 4064 attrib: 4065 empty 4066 any-word 4067 any-word ( identifier ) 4068 any-word ( identifier , nonempty-expr-list ) 4069 any-word ( expr-list ) 4070 4071 where the "identifier" must not be declared as a type, and 4072 "any-word" may be any identifier (including one declared as a 4073 type), a reserved word storage class specifier, type specifier or 4074 type qualifier. ??? This still leaves out most reserved keywords 4075 (following the old parser), shouldn't we include them, and why not 4076 allow identifiers declared as types to start the arguments? */ 4077 4078 static tree 4079 c_parser_attributes (c_parser *parser) 4080 { 4081 tree attrs = NULL_TREE; 4082 while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) 4083 { 4084 /* ??? Follow the C++ parser rather than using the 4085 lex_untranslated_string kludge. */ 4086 parser->lex_untranslated_string = true; 4087 /* Consume the `__attribute__' keyword. */ 4088 c_parser_consume_token (parser); 4089 /* Look for the two `(' tokens. */ 4090 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 4091 { 4092 parser->lex_untranslated_string = false; 4093 return attrs; 4094 } 4095 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 4096 { 4097 parser->lex_untranslated_string = false; 4098 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 4099 return attrs; 4100 } 4101 /* Parse the attribute list. */ 4102 while (c_parser_next_token_is (parser, CPP_COMMA) 4103 || c_parser_next_token_is (parser, CPP_NAME) 4104 || c_parser_next_token_is (parser, CPP_KEYWORD)) 4105 { 4106 tree attr, attr_name, attr_args; 4107 vec<tree, va_gc> *expr_list; 4108 if (c_parser_next_token_is (parser, CPP_COMMA)) 4109 { 4110 c_parser_consume_token (parser); 4111 continue; 4112 } 4113 4114 attr_name = c_parser_attribute_any_word (parser); 4115 if (attr_name == NULL) 4116 break; 4117 if (is_cilkplus_vector_p (attr_name)) 4118 { 4119 c_token *v_token = c_parser_peek_token (parser); 4120 c_parser_cilk_simd_fn_vector_attrs (parser, *v_token); 4121 /* If the next token isn't a comma, we're done. */ 4122 if (!c_parser_next_token_is (parser, CPP_COMMA)) 4123 break; 4124 continue; 4125 } 4126 c_parser_consume_token (parser); 4127 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN)) 4128 { 4129 attr = build_tree_list (attr_name, NULL_TREE); 4130 /* Add this attribute to the list. */ 4131 attrs = chainon (attrs, attr); 4132 /* If the next token isn't a comma, we're done. */ 4133 if (!c_parser_next_token_is (parser, CPP_COMMA)) 4134 break; 4135 continue; 4136 } 4137 c_parser_consume_token (parser); 4138 /* Parse the attribute contents. If they start with an 4139 identifier which is followed by a comma or close 4140 parenthesis, then the arguments start with that 4141 identifier; otherwise they are an expression list. 4142 In objective-c the identifier may be a classname. */ 4143 if (c_parser_next_token_is (parser, CPP_NAME) 4144 && (c_parser_peek_token (parser)->id_kind == C_ID_ID 4145 || (c_dialect_objc () 4146 && c_parser_peek_token (parser)->id_kind 4147 == C_ID_CLASSNAME)) 4148 && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA) 4149 || (c_parser_peek_2nd_token (parser)->type 4150 == CPP_CLOSE_PAREN)) 4151 && (attribute_takes_identifier_p (attr_name) 4152 || (c_dialect_objc () 4153 && c_parser_peek_token (parser)->id_kind 4154 == C_ID_CLASSNAME))) 4155 { 4156 tree arg1 = c_parser_peek_token (parser)->value; 4157 c_parser_consume_token (parser); 4158 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 4159 attr_args = build_tree_list (NULL_TREE, arg1); 4160 else 4161 { 4162 tree tree_list; 4163 c_parser_consume_token (parser); 4164 expr_list = c_parser_expr_list (parser, false, true, 4165 NULL, NULL, NULL, NULL); 4166 tree_list = build_tree_list_vec (expr_list); 4167 attr_args = tree_cons (NULL_TREE, arg1, tree_list); 4168 release_tree_vector (expr_list); 4169 } 4170 } 4171 else 4172 { 4173 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 4174 attr_args = NULL_TREE; 4175 else 4176 { 4177 expr_list = c_parser_expr_list (parser, false, true, 4178 NULL, NULL, NULL, NULL); 4179 attr_args = build_tree_list_vec (expr_list); 4180 release_tree_vector (expr_list); 4181 } 4182 } 4183 attr = build_tree_list (attr_name, attr_args); 4184 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 4185 c_parser_consume_token (parser); 4186 else 4187 { 4188 parser->lex_untranslated_string = false; 4189 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 4190 "expected %<)%>"); 4191 return attrs; 4192 } 4193 /* Add this attribute to the list. */ 4194 attrs = chainon (attrs, attr); 4195 /* If the next token isn't a comma, we're done. */ 4196 if (!c_parser_next_token_is (parser, CPP_COMMA)) 4197 break; 4198 } 4199 /* Look for the two `)' tokens. */ 4200 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 4201 c_parser_consume_token (parser); 4202 else 4203 { 4204 parser->lex_untranslated_string = false; 4205 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 4206 "expected %<)%>"); 4207 return attrs; 4208 } 4209 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 4210 c_parser_consume_token (parser); 4211 else 4212 { 4213 parser->lex_untranslated_string = false; 4214 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 4215 "expected %<)%>"); 4216 return attrs; 4217 } 4218 parser->lex_untranslated_string = false; 4219 } 4220 4221 if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) 4222 c_finish_cilk_simd_fn_tokens (parser); 4223 return attrs; 4224 } 4225 4226 /* Parse a type name (C90 6.5.5, C99 6.7.6). 4227 4228 type-name: 4229 specifier-qualifier-list abstract-declarator[opt] 4230 */ 4231 4232 static struct c_type_name * 4233 c_parser_type_name (c_parser *parser) 4234 { 4235 struct c_declspecs *specs = build_null_declspecs (); 4236 struct c_declarator *declarator; 4237 struct c_type_name *ret; 4238 bool dummy = false; 4239 c_parser_declspecs (parser, specs, false, true, true, false, false, 4240 cla_prefer_type); 4241 if (!specs->declspecs_seen_p) 4242 { 4243 c_parser_error (parser, "expected specifier-qualifier-list"); 4244 return NULL; 4245 } 4246 if (specs->type != error_mark_node) 4247 { 4248 pending_xref_error (); 4249 finish_declspecs (specs); 4250 } 4251 declarator = c_parser_declarator (parser, 4252 specs->typespec_kind != ctsk_none, 4253 C_DTR_ABSTRACT, &dummy); 4254 if (declarator == NULL) 4255 return NULL; 4256 ret = XOBNEW (&parser_obstack, struct c_type_name); 4257 ret->specs = specs; 4258 ret->declarator = declarator; 4259 return ret; 4260 } 4261 4262 /* Parse an initializer (C90 6.5.7, C99 6.7.8). 4263 4264 initializer: 4265 assignment-expression 4266 { initializer-list } 4267 { initializer-list , } 4268 4269 initializer-list: 4270 designation[opt] initializer 4271 initializer-list , designation[opt] initializer 4272 4273 designation: 4274 designator-list = 4275 4276 designator-list: 4277 designator 4278 designator-list designator 4279 4280 designator: 4281 array-designator 4282 . identifier 4283 4284 array-designator: 4285 [ constant-expression ] 4286 4287 GNU extensions: 4288 4289 initializer: 4290 { } 4291 4292 designation: 4293 array-designator 4294 identifier : 4295 4296 array-designator: 4297 [ constant-expression ... constant-expression ] 4298 4299 Any expression without commas is accepted in the syntax for the 4300 constant-expressions, with non-constant expressions rejected later. 4301 4302 This function is only used for top-level initializers; for nested 4303 ones, see c_parser_initval. */ 4304 4305 static struct c_expr 4306 c_parser_initializer (c_parser *parser) 4307 { 4308 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) 4309 return c_parser_braced_init (parser, NULL_TREE, false, NULL); 4310 else 4311 { 4312 struct c_expr ret; 4313 location_t loc = c_parser_peek_token (parser)->location; 4314 ret = c_parser_expr_no_commas (parser, NULL); 4315 if (TREE_CODE (ret.value) != STRING_CST 4316 && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR) 4317 ret = convert_lvalue_to_rvalue (loc, ret, true, true); 4318 return ret; 4319 } 4320 } 4321 4322 /* Parse a braced initializer list. TYPE is the type specified for a 4323 compound literal, and NULL_TREE for other initializers and for 4324 nested braced lists. NESTED_P is true for nested braced lists, 4325 false for the list of a compound literal or the list that is the 4326 top-level initializer in a declaration. */ 4327 4328 static struct c_expr 4329 c_parser_braced_init (c_parser *parser, tree type, bool nested_p, 4330 struct obstack *outer_obstack) 4331 { 4332 struct c_expr ret; 4333 struct obstack braced_init_obstack; 4334 location_t brace_loc = c_parser_peek_token (parser)->location; 4335 gcc_obstack_init (&braced_init_obstack); 4336 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE)); 4337 c_parser_consume_token (parser); 4338 if (nested_p) 4339 { 4340 finish_implicit_inits (brace_loc, outer_obstack); 4341 push_init_level (brace_loc, 0, &braced_init_obstack); 4342 } 4343 else 4344 really_start_incremental_init (type); 4345 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) 4346 { 4347 pedwarn (brace_loc, OPT_Wpedantic, "ISO C forbids empty initializer braces"); 4348 } 4349 else 4350 { 4351 /* Parse a non-empty initializer list, possibly with a trailing 4352 comma. */ 4353 while (true) 4354 { 4355 c_parser_initelt (parser, &braced_init_obstack); 4356 if (parser->error) 4357 break; 4358 if (c_parser_next_token_is (parser, CPP_COMMA)) 4359 c_parser_consume_token (parser); 4360 else 4361 break; 4362 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) 4363 break; 4364 } 4365 } 4366 c_token *next_tok = c_parser_peek_token (parser); 4367 if (next_tok->type != CPP_CLOSE_BRACE) 4368 { 4369 ret.value = error_mark_node; 4370 ret.original_code = ERROR_MARK; 4371 ret.original_type = NULL; 4372 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>"); 4373 pop_init_level (brace_loc, 0, &braced_init_obstack); 4374 obstack_free (&braced_init_obstack, NULL); 4375 return ret; 4376 } 4377 location_t close_loc = next_tok->location; 4378 c_parser_consume_token (parser); 4379 ret = pop_init_level (brace_loc, 0, &braced_init_obstack); 4380 obstack_free (&braced_init_obstack, NULL); 4381 set_c_expr_source_range (&ret, brace_loc, close_loc); 4382 return ret; 4383 } 4384 4385 /* Parse a nested initializer, including designators. */ 4386 4387 static void 4388 c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack) 4389 { 4390 /* Parse any designator or designator list. A single array 4391 designator may have the subsequent "=" omitted in GNU C, but a 4392 longer list or a structure member designator may not. */ 4393 if (c_parser_next_token_is (parser, CPP_NAME) 4394 && c_parser_peek_2nd_token (parser)->type == CPP_COLON) 4395 { 4396 /* Old-style structure member designator. */ 4397 set_init_label (c_parser_peek_token (parser)->location, 4398 c_parser_peek_token (parser)->value, 4399 braced_init_obstack); 4400 /* Use the colon as the error location. */ 4401 pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic, 4402 "obsolete use of designated initializer with %<:%>"); 4403 c_parser_consume_token (parser); 4404 c_parser_consume_token (parser); 4405 } 4406 else 4407 { 4408 /* des_seen is 0 if there have been no designators, 1 if there 4409 has been a single array designator and 2 otherwise. */ 4410 int des_seen = 0; 4411 /* Location of a designator. */ 4412 location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */ 4413 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE) 4414 || c_parser_next_token_is (parser, CPP_DOT)) 4415 { 4416 int des_prev = des_seen; 4417 if (!des_seen) 4418 des_loc = c_parser_peek_token (parser)->location; 4419 if (des_seen < 2) 4420 des_seen++; 4421 if (c_parser_next_token_is (parser, CPP_DOT)) 4422 { 4423 des_seen = 2; 4424 c_parser_consume_token (parser); 4425 if (c_parser_next_token_is (parser, CPP_NAME)) 4426 { 4427 set_init_label (des_loc, c_parser_peek_token (parser)->value, 4428 braced_init_obstack); 4429 c_parser_consume_token (parser); 4430 } 4431 else 4432 { 4433 struct c_expr init; 4434 init.value = error_mark_node; 4435 init.original_code = ERROR_MARK; 4436 init.original_type = NULL; 4437 c_parser_error (parser, "expected identifier"); 4438 c_parser_skip_until_found (parser, CPP_COMMA, NULL); 4439 process_init_element (input_location, init, false, 4440 braced_init_obstack); 4441 return; 4442 } 4443 } 4444 else 4445 { 4446 tree first, second; 4447 location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */ 4448 location_t array_index_loc = UNKNOWN_LOCATION; 4449 /* ??? Following the old parser, [ objc-receiver 4450 objc-message-args ] is accepted as an initializer, 4451 being distinguished from a designator by what follows 4452 the first assignment expression inside the square 4453 brackets, but after a first array designator a 4454 subsequent square bracket is for Objective-C taken to 4455 start an expression, using the obsolete form of 4456 designated initializer without '=', rather than 4457 possibly being a second level of designation: in LALR 4458 terms, the '[' is shifted rather than reducing 4459 designator to designator-list. */ 4460 if (des_prev == 1 && c_dialect_objc ()) 4461 { 4462 des_seen = des_prev; 4463 break; 4464 } 4465 if (des_prev == 0 && c_dialect_objc ()) 4466 { 4467 /* This might be an array designator or an 4468 Objective-C message expression. If the former, 4469 continue parsing here; if the latter, parse the 4470 remainder of the initializer given the starting 4471 primary-expression. ??? It might make sense to 4472 distinguish when des_prev == 1 as well; see 4473 previous comment. */ 4474 tree rec, args; 4475 struct c_expr mexpr; 4476 c_parser_consume_token (parser); 4477 if (c_parser_peek_token (parser)->type == CPP_NAME 4478 && ((c_parser_peek_token (parser)->id_kind 4479 == C_ID_TYPENAME) 4480 || (c_parser_peek_token (parser)->id_kind 4481 == C_ID_CLASSNAME))) 4482 { 4483 /* Type name receiver. */ 4484 tree id = c_parser_peek_token (parser)->value; 4485 c_parser_consume_token (parser); 4486 rec = objc_get_class_reference (id); 4487 goto parse_message_args; 4488 } 4489 first = c_parser_expr_no_commas (parser, NULL).value; 4490 mark_exp_read (first); 4491 if (c_parser_next_token_is (parser, CPP_ELLIPSIS) 4492 || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) 4493 goto array_desig_after_first; 4494 /* Expression receiver. So far only one part 4495 without commas has been parsed; there might be 4496 more of the expression. */ 4497 rec = first; 4498 while (c_parser_next_token_is (parser, CPP_COMMA)) 4499 { 4500 struct c_expr next; 4501 location_t comma_loc, exp_loc; 4502 comma_loc = c_parser_peek_token (parser)->location; 4503 c_parser_consume_token (parser); 4504 exp_loc = c_parser_peek_token (parser)->location; 4505 next = c_parser_expr_no_commas (parser, NULL); 4506 next = convert_lvalue_to_rvalue (exp_loc, next, 4507 true, true); 4508 rec = build_compound_expr (comma_loc, rec, next.value); 4509 } 4510 parse_message_args: 4511 /* Now parse the objc-message-args. */ 4512 args = c_parser_objc_message_args (parser); 4513 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, 4514 "expected %<]%>"); 4515 mexpr.value 4516 = objc_build_message_expr (rec, args); 4517 mexpr.original_code = ERROR_MARK; 4518 mexpr.original_type = NULL; 4519 /* Now parse and process the remainder of the 4520 initializer, starting with this message 4521 expression as a primary-expression. */ 4522 c_parser_initval (parser, &mexpr, braced_init_obstack); 4523 return; 4524 } 4525 c_parser_consume_token (parser); 4526 array_index_loc = c_parser_peek_token (parser)->location; 4527 first = c_parser_expr_no_commas (parser, NULL).value; 4528 mark_exp_read (first); 4529 array_desig_after_first: 4530 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) 4531 { 4532 ellipsis_loc = c_parser_peek_token (parser)->location; 4533 c_parser_consume_token (parser); 4534 second = c_parser_expr_no_commas (parser, NULL).value; 4535 mark_exp_read (second); 4536 } 4537 else 4538 second = NULL_TREE; 4539 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) 4540 { 4541 c_parser_consume_token (parser); 4542 set_init_index (array_index_loc, first, second, 4543 braced_init_obstack); 4544 if (second) 4545 pedwarn (ellipsis_loc, OPT_Wpedantic, 4546 "ISO C forbids specifying range of elements to initialize"); 4547 } 4548 else 4549 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, 4550 "expected %<]%>"); 4551 } 4552 } 4553 if (des_seen >= 1) 4554 { 4555 if (c_parser_next_token_is (parser, CPP_EQ)) 4556 { 4557 pedwarn_c90 (des_loc, OPT_Wpedantic, 4558 "ISO C90 forbids specifying subobject " 4559 "to initialize"); 4560 c_parser_consume_token (parser); 4561 } 4562 else 4563 { 4564 if (des_seen == 1) 4565 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, 4566 "obsolete use of designated initializer without %<=%>"); 4567 else 4568 { 4569 struct c_expr init; 4570 init.value = error_mark_node; 4571 init.original_code = ERROR_MARK; 4572 init.original_type = NULL; 4573 c_parser_error (parser, "expected %<=%>"); 4574 c_parser_skip_until_found (parser, CPP_COMMA, NULL); 4575 process_init_element (input_location, init, false, 4576 braced_init_obstack); 4577 return; 4578 } 4579 } 4580 } 4581 } 4582 c_parser_initval (parser, NULL, braced_init_obstack); 4583 } 4584 4585 /* Parse a nested initializer; as c_parser_initializer but parses 4586 initializers within braced lists, after any designators have been 4587 applied. If AFTER is not NULL then it is an Objective-C message 4588 expression which is the primary-expression starting the 4589 initializer. */ 4590 4591 static void 4592 c_parser_initval (c_parser *parser, struct c_expr *after, 4593 struct obstack * braced_init_obstack) 4594 { 4595 struct c_expr init; 4596 gcc_assert (!after || c_dialect_objc ()); 4597 location_t loc = c_parser_peek_token (parser)->location; 4598 4599 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after) 4600 init = c_parser_braced_init (parser, NULL_TREE, true, 4601 braced_init_obstack); 4602 else 4603 { 4604 init = c_parser_expr_no_commas (parser, after); 4605 if (init.value != NULL_TREE 4606 && TREE_CODE (init.value) != STRING_CST 4607 && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR) 4608 init = convert_lvalue_to_rvalue (loc, init, true, true); 4609 } 4610 process_init_element (loc, init, false, braced_init_obstack); 4611 } 4612 4613 /* Parse a compound statement (possibly a function body) (C90 6.6.2, 4614 C99 6.8.2). 4615 4616 compound-statement: 4617 { block-item-list[opt] } 4618 { label-declarations block-item-list } 4619 4620 block-item-list: 4621 block-item 4622 block-item-list block-item 4623 4624 block-item: 4625 nested-declaration 4626 statement 4627 4628 nested-declaration: 4629 declaration 4630 4631 GNU extensions: 4632 4633 compound-statement: 4634 { label-declarations block-item-list } 4635 4636 nested-declaration: 4637 __extension__ nested-declaration 4638 nested-function-definition 4639 4640 label-declarations: 4641 label-declaration 4642 label-declarations label-declaration 4643 4644 label-declaration: 4645 __label__ identifier-list ; 4646 4647 Allowing the mixing of declarations and code is new in C99. The 4648 GNU syntax also permits (not shown above) labels at the end of 4649 compound statements, which yield an error. We don't allow labels 4650 on declarations; this might seem like a natural extension, but 4651 there would be a conflict between attributes on the label and 4652 prefix attributes on the declaration. ??? The syntax follows the 4653 old parser in requiring something after label declarations. 4654 Although they are erroneous if the labels declared aren't defined, 4655 is it useful for the syntax to be this way? 4656 4657 OpenACC: 4658 4659 block-item: 4660 openacc-directive 4661 4662 openacc-directive: 4663 update-directive 4664 4665 OpenMP: 4666 4667 block-item: 4668 openmp-directive 4669 4670 openmp-directive: 4671 barrier-directive 4672 flush-directive 4673 taskwait-directive 4674 taskyield-directive 4675 cancel-directive 4676 cancellation-point-directive */ 4677 4678 static tree 4679 c_parser_compound_statement (c_parser *parser) 4680 { 4681 tree stmt; 4682 location_t brace_loc; 4683 brace_loc = c_parser_peek_token (parser)->location; 4684 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) 4685 { 4686 /* Ensure a scope is entered and left anyway to avoid confusion 4687 if we have just prepared to enter a function body. */ 4688 stmt = c_begin_compound_stmt (true); 4689 c_end_compound_stmt (brace_loc, stmt, true); 4690 return error_mark_node; 4691 } 4692 stmt = c_begin_compound_stmt (true); 4693 c_parser_compound_statement_nostart (parser); 4694 4695 /* If the compound stmt contains array notations, then we expand them. */ 4696 if (flag_cilkplus && contains_array_notation_expr (stmt)) 4697 stmt = expand_array_notation_exprs (stmt); 4698 return c_end_compound_stmt (brace_loc, stmt, true); 4699 } 4700 4701 /* Parse a compound statement except for the opening brace. This is 4702 used for parsing both compound statements and statement expressions 4703 (which follow different paths to handling the opening). */ 4704 4705 static void 4706 c_parser_compound_statement_nostart (c_parser *parser) 4707 { 4708 bool last_stmt = false; 4709 bool last_label = false; 4710 bool save_valid_for_pragma = valid_location_for_stdc_pragma_p (); 4711 location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */ 4712 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) 4713 { 4714 c_parser_consume_token (parser); 4715 return; 4716 } 4717 mark_valid_location_for_stdc_pragma (true); 4718 if (c_parser_next_token_is_keyword (parser, RID_LABEL)) 4719 { 4720 /* Read zero or more forward-declarations for labels that nested 4721 functions can jump to. */ 4722 mark_valid_location_for_stdc_pragma (false); 4723 while (c_parser_next_token_is_keyword (parser, RID_LABEL)) 4724 { 4725 label_loc = c_parser_peek_token (parser)->location; 4726 c_parser_consume_token (parser); 4727 /* Any identifiers, including those declared as type names, 4728 are OK here. */ 4729 while (true) 4730 { 4731 tree label; 4732 if (c_parser_next_token_is_not (parser, CPP_NAME)) 4733 { 4734 c_parser_error (parser, "expected identifier"); 4735 break; 4736 } 4737 label 4738 = declare_label (c_parser_peek_token (parser)->value); 4739 C_DECLARED_LABEL_FLAG (label) = 1; 4740 add_stmt (build_stmt (label_loc, DECL_EXPR, label)); 4741 c_parser_consume_token (parser); 4742 if (c_parser_next_token_is (parser, CPP_COMMA)) 4743 c_parser_consume_token (parser); 4744 else 4745 break; 4746 } 4747 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 4748 } 4749 pedwarn (label_loc, OPT_Wpedantic, "ISO C forbids label declarations"); 4750 } 4751 /* We must now have at least one statement, label or declaration. */ 4752 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) 4753 { 4754 mark_valid_location_for_stdc_pragma (save_valid_for_pragma); 4755 c_parser_error (parser, "expected declaration or statement"); 4756 c_parser_consume_token (parser); 4757 return; 4758 } 4759 while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE)) 4760 { 4761 location_t loc = c_parser_peek_token (parser)->location; 4762 if (c_parser_next_token_is_keyword (parser, RID_CASE) 4763 || c_parser_next_token_is_keyword (parser, RID_DEFAULT) 4764 || (c_parser_next_token_is (parser, CPP_NAME) 4765 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) 4766 { 4767 if (c_parser_next_token_is_keyword (parser, RID_CASE)) 4768 label_loc = c_parser_peek_2nd_token (parser)->location; 4769 else 4770 label_loc = c_parser_peek_token (parser)->location; 4771 last_label = true; 4772 last_stmt = false; 4773 mark_valid_location_for_stdc_pragma (false); 4774 c_parser_label (parser); 4775 } 4776 else if (!last_label 4777 && c_parser_next_tokens_start_declaration (parser)) 4778 { 4779 last_label = false; 4780 mark_valid_location_for_stdc_pragma (false); 4781 c_parser_declaration_or_fndef (parser, true, true, true, true, 4782 true, NULL, vNULL); 4783 if (last_stmt) 4784 pedwarn_c90 (loc, OPT_Wdeclaration_after_statement, 4785 "ISO C90 forbids mixed declarations and code"); 4786 last_stmt = false; 4787 } 4788 else if (!last_label 4789 && c_parser_next_token_is_keyword (parser, RID_EXTENSION)) 4790 { 4791 /* __extension__ can start a declaration, but is also an 4792 unary operator that can start an expression. Consume all 4793 but the last of a possible series of __extension__ to 4794 determine which. */ 4795 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD 4796 && (c_parser_peek_2nd_token (parser)->keyword 4797 == RID_EXTENSION)) 4798 c_parser_consume_token (parser); 4799 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser))) 4800 { 4801 int ext; 4802 ext = disable_extension_diagnostics (); 4803 c_parser_consume_token (parser); 4804 last_label = false; 4805 mark_valid_location_for_stdc_pragma (false); 4806 c_parser_declaration_or_fndef (parser, true, true, true, true, 4807 true, NULL, vNULL); 4808 /* Following the old parser, __extension__ does not 4809 disable this diagnostic. */ 4810 restore_extension_diagnostics (ext); 4811 if (last_stmt) 4812 pedwarn_c90 (loc, OPT_Wdeclaration_after_statement, 4813 "ISO C90 forbids mixed declarations and code"); 4814 last_stmt = false; 4815 } 4816 else 4817 goto statement; 4818 } 4819 else if (c_parser_next_token_is (parser, CPP_PRAGMA)) 4820 { 4821 /* External pragmas, and some omp pragmas, are not associated 4822 with regular c code, and so are not to be considered statements 4823 syntactically. This ensures that the user doesn't put them 4824 places that would turn into syntax errors if the directive 4825 were ignored. */ 4826 if (c_parser_pragma (parser, 4827 last_label ? pragma_stmt : pragma_compound, 4828 NULL)) 4829 last_label = false, last_stmt = true; 4830 } 4831 else if (c_parser_next_token_is (parser, CPP_EOF)) 4832 { 4833 mark_valid_location_for_stdc_pragma (save_valid_for_pragma); 4834 c_parser_error (parser, "expected declaration or statement"); 4835 return; 4836 } 4837 else if (c_parser_next_token_is_keyword (parser, RID_ELSE)) 4838 { 4839 if (parser->in_if_block) 4840 { 4841 mark_valid_location_for_stdc_pragma (save_valid_for_pragma); 4842 error_at (loc, """expected %<}%> before %<else%>"); 4843 return; 4844 } 4845 else 4846 { 4847 error_at (loc, "%<else%> without a previous %<if%>"); 4848 c_parser_consume_token (parser); 4849 continue; 4850 } 4851 } 4852 else 4853 { 4854 statement: 4855 last_label = false; 4856 last_stmt = true; 4857 mark_valid_location_for_stdc_pragma (false); 4858 c_parser_statement_after_labels (parser, NULL); 4859 } 4860 4861 parser->error = false; 4862 } 4863 if (last_label) 4864 error_at (label_loc, "label at end of compound statement"); 4865 c_parser_consume_token (parser); 4866 /* Restore the value we started with. */ 4867 mark_valid_location_for_stdc_pragma (save_valid_for_pragma); 4868 } 4869 4870 /* Parse all consecutive labels. */ 4871 4872 static void 4873 c_parser_all_labels (c_parser *parser) 4874 { 4875 while (c_parser_next_token_is_keyword (parser, RID_CASE) 4876 || c_parser_next_token_is_keyword (parser, RID_DEFAULT) 4877 || (c_parser_next_token_is (parser, CPP_NAME) 4878 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) 4879 c_parser_label (parser); 4880 } 4881 4882 /* Parse a label (C90 6.6.1, C99 6.8.1). 4883 4884 label: 4885 identifier : attributes[opt] 4886 case constant-expression : 4887 default : 4888 4889 GNU extensions: 4890 4891 label: 4892 case constant-expression ... constant-expression : 4893 4894 The use of attributes on labels is a GNU extension. The syntax in 4895 GNU C accepts any expressions without commas, non-constant 4896 expressions being rejected later. */ 4897 4898 static void 4899 c_parser_label (c_parser *parser) 4900 { 4901 location_t loc1 = c_parser_peek_token (parser)->location; 4902 tree label = NULL_TREE; 4903 if (c_parser_next_token_is_keyword (parser, RID_CASE)) 4904 { 4905 tree exp1, exp2; 4906 c_parser_consume_token (parser); 4907 exp1 = c_parser_expr_no_commas (parser, NULL).value; 4908 if (c_parser_next_token_is (parser, CPP_COLON)) 4909 { 4910 c_parser_consume_token (parser); 4911 label = do_case (loc1, exp1, NULL_TREE); 4912 } 4913 else if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) 4914 { 4915 c_parser_consume_token (parser); 4916 exp2 = c_parser_expr_no_commas (parser, NULL).value; 4917 if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) 4918 label = do_case (loc1, exp1, exp2); 4919 } 4920 else 4921 c_parser_error (parser, "expected %<:%> or %<...%>"); 4922 } 4923 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT)) 4924 { 4925 c_parser_consume_token (parser); 4926 if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) 4927 label = do_case (loc1, NULL_TREE, NULL_TREE); 4928 } 4929 else 4930 { 4931 tree name = c_parser_peek_token (parser)->value; 4932 tree tlab; 4933 tree attrs; 4934 location_t loc2 = c_parser_peek_token (parser)->location; 4935 gcc_assert (c_parser_next_token_is (parser, CPP_NAME)); 4936 c_parser_consume_token (parser); 4937 gcc_assert (c_parser_next_token_is (parser, CPP_COLON)); 4938 c_parser_consume_token (parser); 4939 attrs = c_parser_attributes (parser); 4940 tlab = define_label (loc2, name); 4941 if (tlab) 4942 { 4943 decl_attributes (&tlab, attrs, 0); 4944 label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab)); 4945 } 4946 } 4947 if (label) 4948 { 4949 if (c_parser_next_tokens_start_declaration (parser)) 4950 { 4951 error_at (c_parser_peek_token (parser)->location, 4952 "a label can only be part of a statement and " 4953 "a declaration is not a statement"); 4954 c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false, 4955 /*static_assert_ok*/ true, 4956 /*empty_ok*/ true, /*nested*/ true, 4957 /*start_attr_ok*/ true, NULL, 4958 vNULL); 4959 } 4960 } 4961 } 4962 4963 /* Parse a statement (C90 6.6, C99 6.8). 4964 4965 statement: 4966 labeled-statement 4967 compound-statement 4968 expression-statement 4969 selection-statement 4970 iteration-statement 4971 jump-statement 4972 4973 labeled-statement: 4974 label statement 4975 4976 expression-statement: 4977 expression[opt] ; 4978 4979 selection-statement: 4980 if-statement 4981 switch-statement 4982 4983 iteration-statement: 4984 while-statement 4985 do-statement 4986 for-statement 4987 4988 jump-statement: 4989 goto identifier ; 4990 continue ; 4991 break ; 4992 return expression[opt] ; 4993 4994 GNU extensions: 4995 4996 statement: 4997 asm-statement 4998 4999 jump-statement: 5000 goto * expression ; 5001 5002 Objective-C: 5003 5004 statement: 5005 objc-throw-statement 5006 objc-try-catch-statement 5007 objc-synchronized-statement 5008 5009 objc-throw-statement: 5010 @throw expression ; 5011 @throw ; 5012 5013 OpenACC: 5014 5015 statement: 5016 openacc-construct 5017 5018 openacc-construct: 5019 parallel-construct 5020 kernels-construct 5021 data-construct 5022 loop-construct 5023 5024 parallel-construct: 5025 parallel-directive structured-block 5026 5027 kernels-construct: 5028 kernels-directive structured-block 5029 5030 data-construct: 5031 data-directive structured-block 5032 5033 loop-construct: 5034 loop-directive structured-block 5035 5036 OpenMP: 5037 5038 statement: 5039 openmp-construct 5040 5041 openmp-construct: 5042 parallel-construct 5043 for-construct 5044 simd-construct 5045 for-simd-construct 5046 sections-construct 5047 single-construct 5048 parallel-for-construct 5049 parallel-for-simd-construct 5050 parallel-sections-construct 5051 master-construct 5052 critical-construct 5053 atomic-construct 5054 ordered-construct 5055 5056 parallel-construct: 5057 parallel-directive structured-block 5058 5059 for-construct: 5060 for-directive iteration-statement 5061 5062 simd-construct: 5063 simd-directive iteration-statements 5064 5065 for-simd-construct: 5066 for-simd-directive iteration-statements 5067 5068 sections-construct: 5069 sections-directive section-scope 5070 5071 single-construct: 5072 single-directive structured-block 5073 5074 parallel-for-construct: 5075 parallel-for-directive iteration-statement 5076 5077 parallel-for-simd-construct: 5078 parallel-for-simd-directive iteration-statement 5079 5080 parallel-sections-construct: 5081 parallel-sections-directive section-scope 5082 5083 master-construct: 5084 master-directive structured-block 5085 5086 critical-construct: 5087 critical-directive structured-block 5088 5089 atomic-construct: 5090 atomic-directive expression-statement 5091 5092 ordered-construct: 5093 ordered-directive structured-block 5094 5095 Transactional Memory: 5096 5097 statement: 5098 transaction-statement 5099 transaction-cancel-statement 5100 5101 IF_P is used to track whether there's a (possibly labeled) if statement 5102 which is not enclosed in braces and has an else clause. This is used to 5103 implement -Wparentheses. */ 5104 5105 static void 5106 c_parser_statement (c_parser *parser, bool *if_p) 5107 { 5108 c_parser_all_labels (parser); 5109 c_parser_statement_after_labels (parser, if_p, NULL); 5110 } 5111 5112 /* Parse a statement, other than a labeled statement. CHAIN is a vector 5113 of if-else-if conditions. 5114 5115 IF_P is used to track whether there's a (possibly labeled) if statement 5116 which is not enclosed in braces and has an else clause. This is used to 5117 implement -Wparentheses. */ 5118 5119 static void 5120 c_parser_statement_after_labels (c_parser *parser, bool *if_p, 5121 vec<tree> *chain) 5122 { 5123 location_t loc = c_parser_peek_token (parser)->location; 5124 tree stmt = NULL_TREE; 5125 bool in_if_block = parser->in_if_block; 5126 parser->in_if_block = false; 5127 if (if_p != NULL) 5128 *if_p = false; 5129 switch (c_parser_peek_token (parser)->type) 5130 { 5131 case CPP_OPEN_BRACE: 5132 add_stmt (c_parser_compound_statement (parser)); 5133 break; 5134 case CPP_KEYWORD: 5135 switch (c_parser_peek_token (parser)->keyword) 5136 { 5137 case RID_IF: 5138 c_parser_if_statement (parser, if_p, chain); 5139 break; 5140 case RID_SWITCH: 5141 c_parser_switch_statement (parser); 5142 break; 5143 case RID_WHILE: 5144 c_parser_while_statement (parser, false, if_p); 5145 break; 5146 case RID_DO: 5147 c_parser_do_statement (parser, false); 5148 break; 5149 case RID_FOR: 5150 c_parser_for_statement (parser, false, if_p); 5151 break; 5152 case RID_CILK_FOR: 5153 if (!flag_cilkplus) 5154 { 5155 error_at (c_parser_peek_token (parser)->location, 5156 "-fcilkplus must be enabled to use %<_Cilk_for%>"); 5157 c_parser_skip_to_end_of_block_or_statement (parser); 5158 } 5159 else 5160 c_parser_cilk_for (parser, integer_zero_node, if_p); 5161 break; 5162 case RID_CILK_SYNC: 5163 c_parser_consume_token (parser); 5164 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 5165 if (!flag_cilkplus) 5166 error_at (loc, "-fcilkplus must be enabled to use %<_Cilk_sync%>"); 5167 else 5168 add_stmt (build_cilk_sync ()); 5169 break; 5170 case RID_GOTO: 5171 c_parser_consume_token (parser); 5172 if (c_parser_next_token_is (parser, CPP_NAME)) 5173 { 5174 stmt = c_finish_goto_label (loc, 5175 c_parser_peek_token (parser)->value); 5176 c_parser_consume_token (parser); 5177 } 5178 else if (c_parser_next_token_is (parser, CPP_MULT)) 5179 { 5180 struct c_expr val; 5181 5182 c_parser_consume_token (parser); 5183 val = c_parser_expression (parser); 5184 if (check_no_cilk (val.value, 5185 "Cilk array notation cannot be used as a computed goto expression", 5186 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression", 5187 loc)) 5188 val.value = error_mark_node; 5189 val = convert_lvalue_to_rvalue (loc, val, false, true); 5190 stmt = c_finish_goto_ptr (loc, val.value); 5191 } 5192 else 5193 c_parser_error (parser, "expected identifier or %<*%>"); 5194 goto expect_semicolon; 5195 case RID_CONTINUE: 5196 c_parser_consume_token (parser); 5197 stmt = c_finish_bc_stmt (loc, &c_cont_label, false); 5198 goto expect_semicolon; 5199 case RID_BREAK: 5200 c_parser_consume_token (parser); 5201 stmt = c_finish_bc_stmt (loc, &c_break_label, true); 5202 goto expect_semicolon; 5203 case RID_RETURN: 5204 c_parser_consume_token (parser); 5205 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 5206 { 5207 stmt = c_finish_return (loc, NULL_TREE, NULL_TREE); 5208 c_parser_consume_token (parser); 5209 } 5210 else 5211 { 5212 location_t xloc = c_parser_peek_token (parser)->location; 5213 struct c_expr expr = c_parser_expression_conv (parser); 5214 mark_exp_read (expr.value); 5215 stmt = c_finish_return (EXPR_LOC_OR_LOC (expr.value, xloc), 5216 expr.value, expr.original_type); 5217 goto expect_semicolon; 5218 } 5219 break; 5220 case RID_ASM: 5221 stmt = c_parser_asm_statement (parser); 5222 break; 5223 case RID_TRANSACTION_ATOMIC: 5224 case RID_TRANSACTION_RELAXED: 5225 stmt = c_parser_transaction (parser, 5226 c_parser_peek_token (parser)->keyword); 5227 break; 5228 case RID_TRANSACTION_CANCEL: 5229 stmt = c_parser_transaction_cancel (parser); 5230 goto expect_semicolon; 5231 case RID_AT_THROW: 5232 gcc_assert (c_dialect_objc ()); 5233 c_parser_consume_token (parser); 5234 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 5235 { 5236 stmt = objc_build_throw_stmt (loc, NULL_TREE); 5237 c_parser_consume_token (parser); 5238 } 5239 else 5240 { 5241 struct c_expr expr = c_parser_expression (parser); 5242 expr = convert_lvalue_to_rvalue (loc, expr, false, false); 5243 if (check_no_cilk (expr.value, 5244 "Cilk array notation cannot be used for a throw expression", 5245 "%<_Cilk_spawn%> statement cannot be used for a throw expression")) 5246 expr.value = error_mark_node; 5247 else 5248 { 5249 expr.value = c_fully_fold (expr.value, false, NULL); 5250 stmt = objc_build_throw_stmt (loc, expr.value); 5251 } 5252 goto expect_semicolon; 5253 } 5254 break; 5255 case RID_AT_TRY: 5256 gcc_assert (c_dialect_objc ()); 5257 c_parser_objc_try_catch_finally_statement (parser); 5258 break; 5259 case RID_AT_SYNCHRONIZED: 5260 gcc_assert (c_dialect_objc ()); 5261 c_parser_objc_synchronized_statement (parser); 5262 break; 5263 default: 5264 goto expr_stmt; 5265 } 5266 break; 5267 case CPP_SEMICOLON: 5268 c_parser_consume_token (parser); 5269 break; 5270 case CPP_CLOSE_PAREN: 5271 case CPP_CLOSE_SQUARE: 5272 /* Avoid infinite loop in error recovery: 5273 c_parser_skip_until_found stops at a closing nesting 5274 delimiter without consuming it, but here we need to consume 5275 it to proceed further. */ 5276 c_parser_error (parser, "expected statement"); 5277 c_parser_consume_token (parser); 5278 break; 5279 case CPP_PRAGMA: 5280 c_parser_pragma (parser, pragma_stmt, if_p); 5281 break; 5282 default: 5283 expr_stmt: 5284 stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value); 5285 expect_semicolon: 5286 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 5287 break; 5288 } 5289 /* Two cases cannot and do not have line numbers associated: If stmt 5290 is degenerate, such as "2;", then stmt is an INTEGER_CST, which 5291 cannot hold line numbers. But that's OK because the statement 5292 will either be changed to a MODIFY_EXPR during gimplification of 5293 the statement expr, or discarded. If stmt was compound, but 5294 without new variables, we will have skipped the creation of a 5295 BIND and will have a bare STATEMENT_LIST. But that's OK because 5296 (recursively) all of the component statements should already have 5297 line numbers assigned. ??? Can we discard no-op statements 5298 earlier? */ 5299 if (EXPR_LOCATION (stmt) == UNKNOWN_LOCATION) 5300 protected_set_expr_location (stmt, loc); 5301 5302 parser->in_if_block = in_if_block; 5303 } 5304 5305 /* Parse the condition from an if, do, while or for statements. */ 5306 5307 static tree 5308 c_parser_condition (c_parser *parser) 5309 { 5310 location_t loc = c_parser_peek_token (parser)->location; 5311 tree cond; 5312 cond = c_parser_expression_conv (parser).value; 5313 cond = c_objc_common_truthvalue_conversion (loc, cond); 5314 cond = c_fully_fold (cond, false, NULL); 5315 if (warn_sequence_point) 5316 verify_sequence_points (cond); 5317 return cond; 5318 } 5319 5320 /* Parse a parenthesized condition from an if, do or while statement. 5321 5322 condition: 5323 ( expression ) 5324 */ 5325 static tree 5326 c_parser_paren_condition (c_parser *parser) 5327 { 5328 tree cond; 5329 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 5330 return error_mark_node; 5331 cond = c_parser_condition (parser); 5332 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 5333 return cond; 5334 } 5335 5336 /* Parse a statement which is a block in C99. 5337 5338 IF_P is used to track whether there's a (possibly labeled) if statement 5339 which is not enclosed in braces and has an else clause. This is used to 5340 implement -Wparentheses. */ 5341 5342 static tree 5343 c_parser_c99_block_statement (c_parser *parser, bool *if_p) 5344 { 5345 tree block = c_begin_compound_stmt (flag_isoc99); 5346 location_t loc = c_parser_peek_token (parser)->location; 5347 c_parser_statement (parser, if_p); 5348 return c_end_compound_stmt (loc, block, flag_isoc99); 5349 } 5350 5351 /* Parse the body of an if statement. This is just parsing a 5352 statement but (a) it is a block in C99, (b) we track whether the 5353 body is an if statement for the sake of -Wparentheses warnings, (c) 5354 we handle an empty body specially for the sake of -Wempty-body 5355 warnings, and (d) we call parser_compound_statement directly 5356 because c_parser_statement_after_labels resets 5357 parser->in_if_block. 5358 5359 IF_P is used to track whether there's a (possibly labeled) if statement 5360 which is not enclosed in braces and has an else clause. This is used to 5361 implement -Wparentheses. */ 5362 5363 static tree 5364 c_parser_if_body (c_parser *parser, bool *if_p, 5365 const token_indent_info &if_tinfo) 5366 { 5367 tree block = c_begin_compound_stmt (flag_isoc99); 5368 location_t body_loc = c_parser_peek_token (parser)->location; 5369 token_indent_info body_tinfo 5370 = get_token_indent_info (c_parser_peek_token (parser)); 5371 5372 c_parser_all_labels (parser); 5373 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 5374 { 5375 location_t loc = c_parser_peek_token (parser)->location; 5376 add_stmt (build_empty_stmt (loc)); 5377 c_parser_consume_token (parser); 5378 if (!c_parser_next_token_is_keyword (parser, RID_ELSE)) 5379 warning_at (loc, OPT_Wempty_body, 5380 "suggest braces around empty body in an %<if%> statement"); 5381 } 5382 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) 5383 add_stmt (c_parser_compound_statement (parser)); 5384 else 5385 c_parser_statement_after_labels (parser, if_p); 5386 5387 token_indent_info next_tinfo 5388 = get_token_indent_info (c_parser_peek_token (parser)); 5389 warn_for_misleading_indentation (if_tinfo, body_tinfo, next_tinfo); 5390 5391 return c_end_compound_stmt (body_loc, block, flag_isoc99); 5392 } 5393 5394 /* Parse the else body of an if statement. This is just parsing a 5395 statement but (a) it is a block in C99, (b) we handle an empty body 5396 specially for the sake of -Wempty-body warnings. CHAIN is a vector 5397 of if-else-if conditions. */ 5398 5399 static tree 5400 c_parser_else_body (c_parser *parser, const token_indent_info &else_tinfo, 5401 vec<tree> *chain) 5402 { 5403 location_t body_loc = c_parser_peek_token (parser)->location; 5404 tree block = c_begin_compound_stmt (flag_isoc99); 5405 token_indent_info body_tinfo 5406 = get_token_indent_info (c_parser_peek_token (parser)); 5407 5408 c_parser_all_labels (parser); 5409 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 5410 { 5411 location_t loc = c_parser_peek_token (parser)->location; 5412 warning_at (loc, 5413 OPT_Wempty_body, 5414 "suggest braces around empty body in an %<else%> statement"); 5415 add_stmt (build_empty_stmt (loc)); 5416 c_parser_consume_token (parser); 5417 } 5418 else 5419 c_parser_statement_after_labels (parser, NULL, chain); 5420 5421 token_indent_info next_tinfo 5422 = get_token_indent_info (c_parser_peek_token (parser)); 5423 warn_for_misleading_indentation (else_tinfo, body_tinfo, next_tinfo); 5424 5425 return c_end_compound_stmt (body_loc, block, flag_isoc99); 5426 } 5427 5428 /* Parse an if statement (C90 6.6.4, C99 6.8.4). 5429 5430 if-statement: 5431 if ( expression ) statement 5432 if ( expression ) statement else statement 5433 5434 CHAIN is a vector of if-else-if conditions. 5435 IF_P is used to track whether there's a (possibly labeled) if statement 5436 which is not enclosed in braces and has an else clause. This is used to 5437 implement -Wparentheses. */ 5438 5439 static void 5440 c_parser_if_statement (c_parser *parser, bool *if_p, vec<tree> *chain) 5441 { 5442 tree block; 5443 location_t loc; 5444 tree cond; 5445 bool nested_if = false; 5446 tree first_body, second_body; 5447 bool in_if_block; 5448 tree if_stmt; 5449 5450 gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF)); 5451 token_indent_info if_tinfo 5452 = get_token_indent_info (c_parser_peek_token (parser)); 5453 c_parser_consume_token (parser); 5454 block = c_begin_compound_stmt (flag_isoc99); 5455 loc = c_parser_peek_token (parser)->location; 5456 cond = c_parser_paren_condition (parser); 5457 if (flag_cilkplus && contains_cilk_spawn_stmt (cond)) 5458 { 5459 error_at (loc, "if statement cannot contain %<Cilk_spawn%>"); 5460 cond = error_mark_node; 5461 } 5462 in_if_block = parser->in_if_block; 5463 parser->in_if_block = true; 5464 first_body = c_parser_if_body (parser, &nested_if, if_tinfo); 5465 parser->in_if_block = in_if_block; 5466 5467 if (warn_duplicated_cond) 5468 warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond), cond, &chain); 5469 5470 if (c_parser_next_token_is_keyword (parser, RID_ELSE)) 5471 { 5472 token_indent_info else_tinfo 5473 = get_token_indent_info (c_parser_peek_token (parser)); 5474 c_parser_consume_token (parser); 5475 if (warn_duplicated_cond) 5476 { 5477 if (c_parser_next_token_is_keyword (parser, RID_IF) 5478 && chain == NULL) 5479 { 5480 /* We've got "if (COND) else if (COND2)". Start the 5481 condition chain and add COND as the first element. */ 5482 chain = new vec<tree> (); 5483 if (!CONSTANT_CLASS_P (cond) && !TREE_SIDE_EFFECTS (cond)) 5484 chain->safe_push (cond); 5485 } 5486 else if (!c_parser_next_token_is_keyword (parser, RID_IF)) 5487 { 5488 /* This is if-else without subsequent if. Zap the condition 5489 chain; we would have already warned at this point. */ 5490 delete chain; 5491 chain = NULL; 5492 } 5493 } 5494 second_body = c_parser_else_body (parser, else_tinfo, chain); 5495 /* Set IF_P to true to indicate that this if statement has an 5496 else clause. This may trigger the Wparentheses warning 5497 below when we get back up to the parent if statement. */ 5498 if (if_p != NULL) 5499 *if_p = true; 5500 } 5501 else 5502 { 5503 second_body = NULL_TREE; 5504 5505 /* Diagnose an ambiguous else if if-then-else is nested inside 5506 if-then. */ 5507 if (nested_if) 5508 warning_at (loc, OPT_Wparentheses, 5509 "suggest explicit braces to avoid ambiguous %<else%>"); 5510 5511 if (warn_duplicated_cond) 5512 { 5513 /* This if statement does not have an else clause. We don't 5514 need the condition chain anymore. */ 5515 delete chain; 5516 chain = NULL; 5517 } 5518 } 5519 c_finish_if_stmt (loc, cond, first_body, second_body); 5520 if_stmt = c_end_compound_stmt (loc, block, flag_isoc99); 5521 5522 /* If the if statement contains array notations, then we expand them. */ 5523 if (flag_cilkplus && contains_array_notation_expr (if_stmt)) 5524 if_stmt = fix_conditional_array_notations (if_stmt); 5525 add_stmt (if_stmt); 5526 } 5527 5528 /* Parse a switch statement (C90 6.6.4, C99 6.8.4). 5529 5530 switch-statement: 5531 switch (expression) statement 5532 */ 5533 5534 static void 5535 c_parser_switch_statement (c_parser *parser) 5536 { 5537 struct c_expr ce; 5538 tree block, expr, body, save_break; 5539 location_t switch_loc = c_parser_peek_token (parser)->location; 5540 location_t switch_cond_loc; 5541 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH)); 5542 c_parser_consume_token (parser); 5543 block = c_begin_compound_stmt (flag_isoc99); 5544 bool explicit_cast_p = false; 5545 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 5546 { 5547 switch_cond_loc = c_parser_peek_token (parser)->location; 5548 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) 5549 && c_token_starts_typename (c_parser_peek_2nd_token (parser))) 5550 explicit_cast_p = true; 5551 ce = c_parser_expression (parser); 5552 ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, false); 5553 expr = ce.value; 5554 /* ??? expr has no valid location? */ 5555 if (check_no_cilk (expr, 5556 "Cilk array notation cannot be used as a condition for switch statement", 5557 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement", 5558 switch_cond_loc)) 5559 expr = error_mark_node; 5560 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 5561 } 5562 else 5563 { 5564 switch_cond_loc = UNKNOWN_LOCATION; 5565 expr = error_mark_node; 5566 } 5567 c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p); 5568 save_break = c_break_label; 5569 c_break_label = NULL_TREE; 5570 body = c_parser_c99_block_statement (parser, NULL/*if??*/); 5571 c_finish_case (body, ce.original_type); 5572 if (c_break_label) 5573 { 5574 location_t here = c_parser_peek_token (parser)->location; 5575 tree t = build1 (LABEL_EXPR, void_type_node, c_break_label); 5576 SET_EXPR_LOCATION (t, here); 5577 add_stmt (t); 5578 } 5579 c_break_label = save_break; 5580 add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99)); 5581 } 5582 5583 /* Parse a while statement (C90 6.6.5, C99 6.8.5). 5584 5585 while-statement: 5586 while (expression) statement 5587 5588 IF_P is used to track whether there's a (possibly labeled) if statement 5589 which is not enclosed in braces and has an else clause. This is used to 5590 implement -Wparentheses. */ 5591 5592 static void 5593 c_parser_while_statement (c_parser *parser, bool ivdep, bool *if_p) 5594 { 5595 tree block, cond, body, save_break, save_cont; 5596 location_t loc; 5597 gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE)); 5598 token_indent_info while_tinfo 5599 = get_token_indent_info (c_parser_peek_token (parser)); 5600 c_parser_consume_token (parser); 5601 block = c_begin_compound_stmt (flag_isoc99); 5602 loc = c_parser_peek_token (parser)->location; 5603 cond = c_parser_paren_condition (parser); 5604 if (check_no_cilk (cond, 5605 "Cilk array notation cannot be used as a condition for while statement", 5606 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement")) 5607 cond = error_mark_node; 5608 if (ivdep && cond != error_mark_node) 5609 cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, 5610 build_int_cst (integer_type_node, 5611 annot_expr_ivdep_kind)); 5612 save_break = c_break_label; 5613 c_break_label = NULL_TREE; 5614 save_cont = c_cont_label; 5615 c_cont_label = NULL_TREE; 5616 5617 token_indent_info body_tinfo 5618 = get_token_indent_info (c_parser_peek_token (parser)); 5619 5620 body = c_parser_c99_block_statement (parser, if_p); 5621 c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true); 5622 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99)); 5623 5624 token_indent_info next_tinfo 5625 = get_token_indent_info (c_parser_peek_token (parser)); 5626 warn_for_misleading_indentation (while_tinfo, body_tinfo, next_tinfo); 5627 5628 c_break_label = save_break; 5629 c_cont_label = save_cont; 5630 } 5631 5632 /* Parse a do statement (C90 6.6.5, C99 6.8.5). 5633 5634 do-statement: 5635 do statement while ( expression ) ; 5636 */ 5637 5638 static void 5639 c_parser_do_statement (c_parser *parser, bool ivdep) 5640 { 5641 tree block, cond, body, save_break, save_cont, new_break, new_cont; 5642 location_t loc; 5643 gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO)); 5644 c_parser_consume_token (parser); 5645 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 5646 warning_at (c_parser_peek_token (parser)->location, 5647 OPT_Wempty_body, 5648 "suggest braces around empty body in %<do%> statement"); 5649 block = c_begin_compound_stmt (flag_isoc99); 5650 loc = c_parser_peek_token (parser)->location; 5651 save_break = c_break_label; 5652 c_break_label = NULL_TREE; 5653 save_cont = c_cont_label; 5654 c_cont_label = NULL_TREE; 5655 body = c_parser_c99_block_statement (parser, NULL); 5656 c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>"); 5657 new_break = c_break_label; 5658 c_break_label = save_break; 5659 new_cont = c_cont_label; 5660 c_cont_label = save_cont; 5661 cond = c_parser_paren_condition (parser); 5662 if (check_no_cilk (cond, 5663 "Cilk array notation cannot be used as a condition for a do-while statement", 5664 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement")) 5665 cond = error_mark_node; 5666 if (ivdep && cond != error_mark_node) 5667 cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, 5668 build_int_cst (integer_type_node, 5669 annot_expr_ivdep_kind)); 5670 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) 5671 c_parser_skip_to_end_of_block_or_statement (parser); 5672 c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false); 5673 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99)); 5674 } 5675 5676 /* Parse a for statement (C90 6.6.5, C99 6.8.5). 5677 5678 for-statement: 5679 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement 5680 for ( nested-declaration expression[opt] ; expression[opt] ) statement 5681 5682 The form with a declaration is new in C99. 5683 5684 ??? In accordance with the old parser, the declaration may be a 5685 nested function, which is then rejected in check_for_loop_decls, 5686 but does it make any sense for this to be included in the grammar? 5687 Note in particular that the nested function does not include a 5688 trailing ';', whereas the "declaration" production includes one. 5689 Also, can we reject bad declarations earlier and cheaper than 5690 check_for_loop_decls? 5691 5692 In Objective-C, there are two additional variants: 5693 5694 foreach-statement: 5695 for ( expression in expresssion ) statement 5696 for ( declaration in expression ) statement 5697 5698 This is inconsistent with C, because the second variant is allowed 5699 even if c99 is not enabled. 5700 5701 The rest of the comment documents these Objective-C foreach-statement. 5702 5703 Here is the canonical example of the first variant: 5704 for (object in array) { do something with object } 5705 we call the first expression ("object") the "object_expression" and 5706 the second expression ("array") the "collection_expression". 5707 object_expression must be an lvalue of type "id" (a generic Objective-C 5708 object) because the loop works by assigning to object_expression the 5709 various objects from the collection_expression. collection_expression 5710 must evaluate to something of type "id" which responds to the method 5711 countByEnumeratingWithState:objects:count:. 5712 5713 The canonical example of the second variant is: 5714 for (id object in array) { do something with object } 5715 which is completely equivalent to 5716 { 5717 id object; 5718 for (object in array) { do something with object } 5719 } 5720 Note that initizializing 'object' in some way (eg, "for ((object = 5721 xxx) in array) { do something with object }") is possibly 5722 technically valid, but completely pointless as 'object' will be 5723 assigned to something else as soon as the loop starts. We should 5724 most likely reject it (TODO). 5725 5726 The beginning of the Objective-C foreach-statement looks exactly 5727 like the beginning of the for-statement, and we can tell it is a 5728 foreach-statement only because the initial declaration or 5729 expression is terminated by 'in' instead of ';'. 5730 5731 IF_P is used to track whether there's a (possibly labeled) if statement 5732 which is not enclosed in braces and has an else clause. This is used to 5733 implement -Wparentheses. */ 5734 5735 static void 5736 c_parser_for_statement (c_parser *parser, bool ivdep, bool *if_p) 5737 { 5738 tree block, cond, incr, save_break, save_cont, body; 5739 /* The following are only used when parsing an ObjC foreach statement. */ 5740 tree object_expression; 5741 /* Silence the bogus uninitialized warning. */ 5742 tree collection_expression = NULL; 5743 location_t loc = c_parser_peek_token (parser)->location; 5744 location_t for_loc = c_parser_peek_token (parser)->location; 5745 bool is_foreach_statement = false; 5746 gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR)); 5747 token_indent_info for_tinfo 5748 = get_token_indent_info (c_parser_peek_token (parser)); 5749 c_parser_consume_token (parser); 5750 /* Open a compound statement in Objective-C as well, just in case this is 5751 as foreach expression. */ 5752 block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ()); 5753 cond = error_mark_node; 5754 incr = error_mark_node; 5755 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 5756 { 5757 /* Parse the initialization declaration or expression. */ 5758 object_expression = error_mark_node; 5759 parser->objc_could_be_foreach_context = c_dialect_objc (); 5760 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 5761 { 5762 parser->objc_could_be_foreach_context = false; 5763 c_parser_consume_token (parser); 5764 c_finish_expr_stmt (loc, NULL_TREE); 5765 } 5766 else if (c_parser_next_tokens_start_declaration (parser)) 5767 { 5768 c_parser_declaration_or_fndef (parser, true, true, true, true, true, 5769 &object_expression, vNULL); 5770 parser->objc_could_be_foreach_context = false; 5771 5772 if (c_parser_next_token_is_keyword (parser, RID_IN)) 5773 { 5774 c_parser_consume_token (parser); 5775 is_foreach_statement = true; 5776 if (check_for_loop_decls (for_loc, true) == NULL_TREE) 5777 c_parser_error (parser, "multiple iterating variables in fast enumeration"); 5778 } 5779 else 5780 check_for_loop_decls (for_loc, flag_isoc99); 5781 } 5782 else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION)) 5783 { 5784 /* __extension__ can start a declaration, but is also an 5785 unary operator that can start an expression. Consume all 5786 but the last of a possible series of __extension__ to 5787 determine which. */ 5788 while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD 5789 && (c_parser_peek_2nd_token (parser)->keyword 5790 == RID_EXTENSION)) 5791 c_parser_consume_token (parser); 5792 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser))) 5793 { 5794 int ext; 5795 ext = disable_extension_diagnostics (); 5796 c_parser_consume_token (parser); 5797 c_parser_declaration_or_fndef (parser, true, true, true, true, 5798 true, &object_expression, vNULL); 5799 parser->objc_could_be_foreach_context = false; 5800 5801 restore_extension_diagnostics (ext); 5802 if (c_parser_next_token_is_keyword (parser, RID_IN)) 5803 { 5804 c_parser_consume_token (parser); 5805 is_foreach_statement = true; 5806 if (check_for_loop_decls (for_loc, true) == NULL_TREE) 5807 c_parser_error (parser, "multiple iterating variables in fast enumeration"); 5808 } 5809 else 5810 check_for_loop_decls (for_loc, flag_isoc99); 5811 } 5812 else 5813 goto init_expr; 5814 } 5815 else 5816 { 5817 init_expr: 5818 { 5819 struct c_expr ce; 5820 tree init_expression; 5821 ce = c_parser_expression (parser); 5822 /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top 5823 level statement", but it works just fine, so allow it. */ 5824 init_expression = ce.value; 5825 parser->objc_could_be_foreach_context = false; 5826 if (c_parser_next_token_is_keyword (parser, RID_IN)) 5827 { 5828 c_parser_consume_token (parser); 5829 is_foreach_statement = true; 5830 if (! lvalue_p (init_expression)) 5831 c_parser_error (parser, "invalid iterating variable in fast enumeration"); 5832 object_expression = c_fully_fold (init_expression, false, NULL); 5833 } 5834 else 5835 { 5836 ce = convert_lvalue_to_rvalue (loc, ce, true, false); 5837 init_expression = ce.value; 5838 c_finish_expr_stmt (loc, init_expression); 5839 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 5840 } 5841 } 5842 } 5843 /* Parse the loop condition. In the case of a foreach 5844 statement, there is no loop condition. */ 5845 gcc_assert (!parser->objc_could_be_foreach_context); 5846 if (!is_foreach_statement) 5847 { 5848 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 5849 { 5850 if (ivdep) 5851 { 5852 c_parser_error (parser, "missing loop condition in loop with " 5853 "%<GCC ivdep%> pragma"); 5854 cond = error_mark_node; 5855 } 5856 else 5857 { 5858 c_parser_consume_token (parser); 5859 cond = NULL_TREE; 5860 } 5861 } 5862 else 5863 { 5864 cond = c_parser_condition (parser); 5865 if (check_no_cilk (cond, 5866 "Cilk array notation cannot be used in a condition for a for-loop", 5867 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop")) 5868 cond = error_mark_node; 5869 c_parser_skip_until_found (parser, CPP_SEMICOLON, 5870 "expected %<;%>"); 5871 } 5872 if (ivdep && cond != error_mark_node) 5873 cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, 5874 build_int_cst (integer_type_node, 5875 annot_expr_ivdep_kind)); 5876 } 5877 /* Parse the increment expression (the third expression in a 5878 for-statement). In the case of a foreach-statement, this is 5879 the expression that follows the 'in'. */ 5880 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 5881 { 5882 if (is_foreach_statement) 5883 { 5884 c_parser_error (parser, "missing collection in fast enumeration"); 5885 collection_expression = error_mark_node; 5886 } 5887 else 5888 incr = c_process_expr_stmt (loc, NULL_TREE); 5889 } 5890 else 5891 { 5892 if (is_foreach_statement) 5893 collection_expression = c_fully_fold (c_parser_expression (parser).value, 5894 false, NULL); 5895 else 5896 { 5897 struct c_expr ce = c_parser_expression (parser); 5898 ce = convert_lvalue_to_rvalue (loc, ce, true, false); 5899 incr = c_process_expr_stmt (loc, ce.value); 5900 } 5901 } 5902 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 5903 } 5904 save_break = c_break_label; 5905 c_break_label = NULL_TREE; 5906 save_cont = c_cont_label; 5907 c_cont_label = NULL_TREE; 5908 5909 token_indent_info body_tinfo 5910 = get_token_indent_info (c_parser_peek_token (parser)); 5911 5912 body = c_parser_c99_block_statement (parser, if_p); 5913 5914 if (is_foreach_statement) 5915 objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label); 5916 else 5917 c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true); 5918 add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ())); 5919 5920 /* We might need to reclassify any previously-lexed identifier, e.g. 5921 when we've left a for loop with an if-statement without else in the 5922 body - we might have used a wrong scope for the token. See PR67784. */ 5923 if (c_parser_next_token_is (parser, CPP_NAME)) 5924 { 5925 c_token *token = c_parser_peek_token (parser); 5926 5927 if (token->id_kind != C_ID_CLASSNAME) 5928 { 5929 tree decl = lookup_name (token->value); 5930 5931 token->id_kind = C_ID_ID; 5932 if (decl) 5933 { 5934 if (TREE_CODE (decl) == TYPE_DECL) 5935 token->id_kind = C_ID_TYPENAME; 5936 } 5937 else if (c_dialect_objc ()) 5938 { 5939 tree objc_interface_decl = objc_is_class_name (token->value); 5940 /* Objective-C class names are in the same namespace as 5941 variables and typedefs, and hence are shadowed by local 5942 declarations. */ 5943 if (objc_interface_decl) 5944 { 5945 token->value = objc_interface_decl; 5946 token->id_kind = C_ID_CLASSNAME; 5947 } 5948 } 5949 } 5950 } 5951 5952 token_indent_info next_tinfo 5953 = get_token_indent_info (c_parser_peek_token (parser)); 5954 warn_for_misleading_indentation (for_tinfo, body_tinfo, next_tinfo); 5955 5956 c_break_label = save_break; 5957 c_cont_label = save_cont; 5958 } 5959 5960 /* Parse an asm statement, a GNU extension. This is a full-blown asm 5961 statement with inputs, outputs, clobbers, and volatile tag 5962 allowed. 5963 5964 asm-statement: 5965 asm type-qualifier[opt] ( asm-argument ) ; 5966 asm type-qualifier[opt] goto ( asm-goto-argument ) ; 5967 5968 asm-argument: 5969 asm-string-literal 5970 asm-string-literal : asm-operands[opt] 5971 asm-string-literal : asm-operands[opt] : asm-operands[opt] 5972 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt] 5973 5974 asm-goto-argument: 5975 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \ 5976 : asm-goto-operands 5977 5978 Qualifiers other than volatile are accepted in the syntax but 5979 warned for. */ 5980 5981 static tree 5982 c_parser_asm_statement (c_parser *parser) 5983 { 5984 tree quals, str, outputs, inputs, clobbers, labels, ret; 5985 bool simple, is_goto; 5986 location_t asm_loc = c_parser_peek_token (parser)->location; 5987 int section, nsections; 5988 5989 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM)); 5990 c_parser_consume_token (parser); 5991 if (c_parser_next_token_is_keyword (parser, RID_VOLATILE)) 5992 { 5993 quals = c_parser_peek_token (parser)->value; 5994 c_parser_consume_token (parser); 5995 } 5996 else if (c_parser_next_token_is_keyword (parser, RID_CONST) 5997 || c_parser_next_token_is_keyword (parser, RID_RESTRICT)) 5998 { 5999 warning_at (c_parser_peek_token (parser)->location, 6000 0, 6001 "%E qualifier ignored on asm", 6002 c_parser_peek_token (parser)->value); 6003 quals = NULL_TREE; 6004 c_parser_consume_token (parser); 6005 } 6006 else 6007 quals = NULL_TREE; 6008 6009 is_goto = false; 6010 if (c_parser_next_token_is_keyword (parser, RID_GOTO)) 6011 { 6012 c_parser_consume_token (parser); 6013 is_goto = true; 6014 } 6015 6016 /* ??? Follow the C++ parser rather than using the 6017 lex_untranslated_string kludge. */ 6018 parser->lex_untranslated_string = true; 6019 ret = NULL; 6020 6021 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 6022 goto error; 6023 6024 str = c_parser_asm_string_literal (parser); 6025 if (str == NULL_TREE) 6026 goto error_close_paren; 6027 6028 simple = true; 6029 outputs = NULL_TREE; 6030 inputs = NULL_TREE; 6031 clobbers = NULL_TREE; 6032 labels = NULL_TREE; 6033 6034 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto) 6035 goto done_asm; 6036 6037 /* Parse each colon-delimited section of operands. */ 6038 nsections = 3 + is_goto; 6039 for (section = 0; section < nsections; ++section) 6040 { 6041 if (!c_parser_require (parser, CPP_COLON, 6042 is_goto 6043 ? "expected %<:%>" 6044 : "expected %<:%> or %<)%>")) 6045 goto error_close_paren; 6046 6047 /* Once past any colon, we're no longer a simple asm. */ 6048 simple = false; 6049 6050 if ((!c_parser_next_token_is (parser, CPP_COLON) 6051 && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 6052 || section == 3) 6053 switch (section) 6054 { 6055 case 0: 6056 /* For asm goto, we don't allow output operands, but reserve 6057 the slot for a future extension that does allow them. */ 6058 if (!is_goto) 6059 outputs = c_parser_asm_operands (parser); 6060 break; 6061 case 1: 6062 inputs = c_parser_asm_operands (parser); 6063 break; 6064 case 2: 6065 clobbers = c_parser_asm_clobbers (parser); 6066 break; 6067 case 3: 6068 labels = c_parser_asm_goto_operands (parser); 6069 break; 6070 default: 6071 gcc_unreachable (); 6072 } 6073 6074 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto) 6075 goto done_asm; 6076 } 6077 6078 done_asm: 6079 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) 6080 { 6081 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 6082 goto error; 6083 } 6084 6085 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) 6086 c_parser_skip_to_end_of_block_or_statement (parser); 6087 6088 ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs, 6089 clobbers, labels, simple)); 6090 6091 error: 6092 parser->lex_untranslated_string = false; 6093 return ret; 6094 6095 error_close_paren: 6096 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 6097 goto error; 6098 } 6099 6100 /* Parse asm operands, a GNU extension. 6101 6102 asm-operands: 6103 asm-operand 6104 asm-operands , asm-operand 6105 6106 asm-operand: 6107 asm-string-literal ( expression ) 6108 [ identifier ] asm-string-literal ( expression ) 6109 */ 6110 6111 static tree 6112 c_parser_asm_operands (c_parser *parser) 6113 { 6114 tree list = NULL_TREE; 6115 while (true) 6116 { 6117 tree name, str; 6118 struct c_expr expr; 6119 if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) 6120 { 6121 c_parser_consume_token (parser); 6122 if (c_parser_next_token_is (parser, CPP_NAME)) 6123 { 6124 tree id = c_parser_peek_token (parser)->value; 6125 c_parser_consume_token (parser); 6126 name = build_string (IDENTIFIER_LENGTH (id), 6127 IDENTIFIER_POINTER (id)); 6128 } 6129 else 6130 { 6131 c_parser_error (parser, "expected identifier"); 6132 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); 6133 return NULL_TREE; 6134 } 6135 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, 6136 "expected %<]%>"); 6137 } 6138 else 6139 name = NULL_TREE; 6140 str = c_parser_asm_string_literal (parser); 6141 if (str == NULL_TREE) 6142 return NULL_TREE; 6143 parser->lex_untranslated_string = false; 6144 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 6145 { 6146 parser->lex_untranslated_string = true; 6147 return NULL_TREE; 6148 } 6149 expr = c_parser_expression (parser); 6150 mark_exp_read (expr.value); 6151 parser->lex_untranslated_string = true; 6152 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) 6153 { 6154 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 6155 return NULL_TREE; 6156 } 6157 list = chainon (list, build_tree_list (build_tree_list (name, str), 6158 expr.value)); 6159 if (c_parser_next_token_is (parser, CPP_COMMA)) 6160 c_parser_consume_token (parser); 6161 else 6162 break; 6163 } 6164 return list; 6165 } 6166 6167 /* Parse asm clobbers, a GNU extension. 6168 6169 asm-clobbers: 6170 asm-string-literal 6171 asm-clobbers , asm-string-literal 6172 */ 6173 6174 static tree 6175 c_parser_asm_clobbers (c_parser *parser) 6176 { 6177 tree list = NULL_TREE; 6178 while (true) 6179 { 6180 tree str = c_parser_asm_string_literal (parser); 6181 if (str) 6182 list = tree_cons (NULL_TREE, str, list); 6183 else 6184 return NULL_TREE; 6185 if (c_parser_next_token_is (parser, CPP_COMMA)) 6186 c_parser_consume_token (parser); 6187 else 6188 break; 6189 } 6190 return list; 6191 } 6192 6193 /* Parse asm goto labels, a GNU extension. 6194 6195 asm-goto-operands: 6196 identifier 6197 asm-goto-operands , identifier 6198 */ 6199 6200 static tree 6201 c_parser_asm_goto_operands (c_parser *parser) 6202 { 6203 tree list = NULL_TREE; 6204 while (true) 6205 { 6206 tree name, label; 6207 6208 if (c_parser_next_token_is (parser, CPP_NAME)) 6209 { 6210 c_token *tok = c_parser_peek_token (parser); 6211 name = tok->value; 6212 label = lookup_label_for_goto (tok->location, name); 6213 c_parser_consume_token (parser); 6214 TREE_USED (label) = 1; 6215 } 6216 else 6217 { 6218 c_parser_error (parser, "expected identifier"); 6219 return NULL_TREE; 6220 } 6221 6222 name = build_string (IDENTIFIER_LENGTH (name), 6223 IDENTIFIER_POINTER (name)); 6224 list = tree_cons (name, label, list); 6225 if (c_parser_next_token_is (parser, CPP_COMMA)) 6226 c_parser_consume_token (parser); 6227 else 6228 return nreverse (list); 6229 } 6230 } 6231 6232 /* Parse an expression other than a compound expression; that is, an 6233 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not 6234 NULL then it is an Objective-C message expression which is the 6235 primary-expression starting the expression as an initializer. 6236 6237 assignment-expression: 6238 conditional-expression 6239 unary-expression assignment-operator assignment-expression 6240 6241 assignment-operator: one of 6242 = *= /= %= += -= <<= >>= &= ^= |= 6243 6244 In GNU C we accept any conditional expression on the LHS and 6245 diagnose the invalid lvalue rather than producing a syntax 6246 error. */ 6247 6248 static struct c_expr 6249 c_parser_expr_no_commas (c_parser *parser, struct c_expr *after, 6250 tree omp_atomic_lhs) 6251 { 6252 struct c_expr lhs, rhs, ret; 6253 enum tree_code code; 6254 location_t op_location, exp_location; 6255 gcc_assert (!after || c_dialect_objc ()); 6256 lhs = c_parser_conditional_expression (parser, after, omp_atomic_lhs); 6257 op_location = c_parser_peek_token (parser)->location; 6258 switch (c_parser_peek_token (parser)->type) 6259 { 6260 case CPP_EQ: 6261 code = NOP_EXPR; 6262 break; 6263 case CPP_MULT_EQ: 6264 code = MULT_EXPR; 6265 break; 6266 case CPP_DIV_EQ: 6267 code = TRUNC_DIV_EXPR; 6268 break; 6269 case CPP_MOD_EQ: 6270 code = TRUNC_MOD_EXPR; 6271 break; 6272 case CPP_PLUS_EQ: 6273 code = PLUS_EXPR; 6274 break; 6275 case CPP_MINUS_EQ: 6276 code = MINUS_EXPR; 6277 break; 6278 case CPP_LSHIFT_EQ: 6279 code = LSHIFT_EXPR; 6280 break; 6281 case CPP_RSHIFT_EQ: 6282 code = RSHIFT_EXPR; 6283 break; 6284 case CPP_AND_EQ: 6285 code = BIT_AND_EXPR; 6286 break; 6287 case CPP_XOR_EQ: 6288 code = BIT_XOR_EXPR; 6289 break; 6290 case CPP_OR_EQ: 6291 code = BIT_IOR_EXPR; 6292 break; 6293 default: 6294 return lhs; 6295 } 6296 c_parser_consume_token (parser); 6297 exp_location = c_parser_peek_token (parser)->location; 6298 rhs = c_parser_expr_no_commas (parser, NULL); 6299 rhs = convert_lvalue_to_rvalue (exp_location, rhs, true, true); 6300 6301 ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type, 6302 code, exp_location, rhs.value, 6303 rhs.original_type); 6304 set_c_expr_source_range (&ret, lhs.get_start (), rhs.get_finish ()); 6305 if (code == NOP_EXPR) 6306 ret.original_code = MODIFY_EXPR; 6307 else 6308 { 6309 TREE_NO_WARNING (ret.value) = 1; 6310 ret.original_code = ERROR_MARK; 6311 } 6312 ret.original_type = NULL; 6313 return ret; 6314 } 6315 6316 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER 6317 is not NULL then it is an Objective-C message expression which is 6318 the primary-expression starting the expression as an initializer. 6319 6320 conditional-expression: 6321 logical-OR-expression 6322 logical-OR-expression ? expression : conditional-expression 6323 6324 GNU extensions: 6325 6326 conditional-expression: 6327 logical-OR-expression ? : conditional-expression 6328 */ 6329 6330 static struct c_expr 6331 c_parser_conditional_expression (c_parser *parser, struct c_expr *after, 6332 tree omp_atomic_lhs) 6333 { 6334 struct c_expr cond, exp1, exp2, ret; 6335 location_t start, cond_loc, colon_loc, middle_loc; 6336 6337 gcc_assert (!after || c_dialect_objc ()); 6338 6339 cond = c_parser_binary_expression (parser, after, omp_atomic_lhs); 6340 6341 if (c_parser_next_token_is_not (parser, CPP_QUERY)) 6342 return cond; 6343 if (cond.value != error_mark_node) 6344 start = cond.get_start (); 6345 else 6346 start = UNKNOWN_LOCATION; 6347 cond_loc = c_parser_peek_token (parser)->location; 6348 cond = convert_lvalue_to_rvalue (cond_loc, cond, true, true); 6349 c_parser_consume_token (parser); 6350 if (c_parser_next_token_is (parser, CPP_COLON)) 6351 { 6352 tree eptype = NULL_TREE; 6353 6354 middle_loc = c_parser_peek_token (parser)->location; 6355 pedwarn (middle_loc, OPT_Wpedantic, 6356 "ISO C forbids omitting the middle term of a ?: expression"); 6357 warn_for_omitted_condop (middle_loc, cond.value); 6358 if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR) 6359 { 6360 eptype = TREE_TYPE (cond.value); 6361 cond.value = TREE_OPERAND (cond.value, 0); 6362 } 6363 /* Make sure first operand is calculated only once. */ 6364 exp1.value = c_save_expr (default_conversion (cond.value)); 6365 if (eptype) 6366 exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value); 6367 exp1.original_type = NULL; 6368 cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value); 6369 c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node; 6370 } 6371 else 6372 { 6373 cond.value 6374 = c_objc_common_truthvalue_conversion 6375 (cond_loc, default_conversion (cond.value)); 6376 c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node; 6377 exp1 = c_parser_expression_conv (parser); 6378 mark_exp_read (exp1.value); 6379 c_inhibit_evaluation_warnings += 6380 ((cond.value == truthvalue_true_node) 6381 - (cond.value == truthvalue_false_node)); 6382 } 6383 6384 colon_loc = c_parser_peek_token (parser)->location; 6385 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) 6386 { 6387 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node; 6388 ret.value = error_mark_node; 6389 ret.original_code = ERROR_MARK; 6390 ret.original_type = NULL; 6391 return ret; 6392 } 6393 { 6394 location_t exp2_loc = c_parser_peek_token (parser)->location; 6395 exp2 = c_parser_conditional_expression (parser, NULL, NULL_TREE); 6396 exp2 = convert_lvalue_to_rvalue (exp2_loc, exp2, true, true); 6397 } 6398 c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node; 6399 ret.value = build_conditional_expr (colon_loc, cond.value, 6400 cond.original_code == C_MAYBE_CONST_EXPR, 6401 exp1.value, exp1.original_type, 6402 exp2.value, exp2.original_type); 6403 ret.original_code = ERROR_MARK; 6404 if (exp1.value == error_mark_node || exp2.value == error_mark_node) 6405 ret.original_type = NULL; 6406 else 6407 { 6408 tree t1, t2; 6409 6410 /* If both sides are enum type, the default conversion will have 6411 made the type of the result be an integer type. We want to 6412 remember the enum types we started with. */ 6413 t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value); 6414 t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value); 6415 ret.original_type = ((t1 != error_mark_node 6416 && t2 != error_mark_node 6417 && (TYPE_MAIN_VARIANT (t1) 6418 == TYPE_MAIN_VARIANT (t2))) 6419 ? t1 6420 : NULL); 6421 } 6422 set_c_expr_source_range (&ret, start, exp2.get_finish ()); 6423 return ret; 6424 } 6425 6426 /* Parse a binary expression; that is, a logical-OR-expression (C90 6427 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is 6428 an Objective-C message expression which is the primary-expression 6429 starting the expression as an initializer. 6430 6431 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic, 6432 when it should be the unfolded lhs. In a valid OpenMP source, 6433 one of the operands of the toplevel binary expression must be equal 6434 to it. In that case, just return a build2 created binary operation 6435 rather than result of parser_build_binary_op. 6436 6437 multiplicative-expression: 6438 cast-expression 6439 multiplicative-expression * cast-expression 6440 multiplicative-expression / cast-expression 6441 multiplicative-expression % cast-expression 6442 6443 additive-expression: 6444 multiplicative-expression 6445 additive-expression + multiplicative-expression 6446 additive-expression - multiplicative-expression 6447 6448 shift-expression: 6449 additive-expression 6450 shift-expression << additive-expression 6451 shift-expression >> additive-expression 6452 6453 relational-expression: 6454 shift-expression 6455 relational-expression < shift-expression 6456 relational-expression > shift-expression 6457 relational-expression <= shift-expression 6458 relational-expression >= shift-expression 6459 6460 equality-expression: 6461 relational-expression 6462 equality-expression == relational-expression 6463 equality-expression != relational-expression 6464 6465 AND-expression: 6466 equality-expression 6467 AND-expression & equality-expression 6468 6469 exclusive-OR-expression: 6470 AND-expression 6471 exclusive-OR-expression ^ AND-expression 6472 6473 inclusive-OR-expression: 6474 exclusive-OR-expression 6475 inclusive-OR-expression | exclusive-OR-expression 6476 6477 logical-AND-expression: 6478 inclusive-OR-expression 6479 logical-AND-expression && inclusive-OR-expression 6480 6481 logical-OR-expression: 6482 logical-AND-expression 6483 logical-OR-expression || logical-AND-expression 6484 */ 6485 6486 static struct c_expr 6487 c_parser_binary_expression (c_parser *parser, struct c_expr *after, 6488 tree omp_atomic_lhs) 6489 { 6490 /* A binary expression is parsed using operator-precedence parsing, 6491 with the operands being cast expressions. All the binary 6492 operators are left-associative. Thus a binary expression is of 6493 form: 6494 6495 E0 op1 E1 op2 E2 ... 6496 6497 which we represent on a stack. On the stack, the precedence 6498 levels are strictly increasing. When a new operator is 6499 encountered of higher precedence than that at the top of the 6500 stack, it is pushed; its LHS is the top expression, and its RHS 6501 is everything parsed until it is popped. When a new operator is 6502 encountered with precedence less than or equal to that at the top 6503 of the stack, triples E[i-1] op[i] E[i] are popped and replaced 6504 by the result of the operation until the operator at the top of 6505 the stack has lower precedence than the new operator or there is 6506 only one element on the stack; then the top expression is the LHS 6507 of the new operator. In the case of logical AND and OR 6508 expressions, we also need to adjust c_inhibit_evaluation_warnings 6509 as appropriate when the operators are pushed and popped. */ 6510 6511 struct { 6512 /* The expression at this stack level. */ 6513 struct c_expr expr; 6514 /* The precedence of the operator on its left, PREC_NONE at the 6515 bottom of the stack. */ 6516 enum c_parser_prec prec; 6517 /* The operation on its left. */ 6518 enum tree_code op; 6519 /* The source location of this operation. */ 6520 location_t loc; 6521 } stack[NUM_PRECS]; 6522 int sp; 6523 /* Location of the binary operator. */ 6524 location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */ 6525 #define POP \ 6526 do { \ 6527 switch (stack[sp].op) \ 6528 { \ 6529 case TRUTH_ANDIF_EXPR: \ 6530 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \ 6531 == truthvalue_false_node); \ 6532 break; \ 6533 case TRUTH_ORIF_EXPR: \ 6534 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \ 6535 == truthvalue_true_node); \ 6536 break; \ 6537 default: \ 6538 break; \ 6539 } \ 6540 stack[sp - 1].expr \ 6541 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \ 6542 stack[sp - 1].expr, true, true); \ 6543 stack[sp].expr \ 6544 = convert_lvalue_to_rvalue (stack[sp].loc, \ 6545 stack[sp].expr, true, true); \ 6546 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \ 6547 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \ 6548 && ((1 << stack[sp].prec) \ 6549 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \ 6550 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \ 6551 && stack[sp].op != TRUNC_MOD_EXPR \ 6552 && stack[0].expr.value != error_mark_node \ 6553 && stack[1].expr.value != error_mark_node \ 6554 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \ 6555 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \ 6556 stack[0].expr.value \ 6557 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \ 6558 stack[0].expr.value, stack[1].expr.value); \ 6559 else \ 6560 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \ 6561 stack[sp].op, \ 6562 stack[sp - 1].expr, \ 6563 stack[sp].expr); \ 6564 sp--; \ 6565 } while (0) 6566 gcc_assert (!after || c_dialect_objc ()); 6567 stack[0].loc = c_parser_peek_token (parser)->location; 6568 stack[0].expr = c_parser_cast_expression (parser, after); 6569 stack[0].prec = PREC_NONE; 6570 sp = 0; 6571 while (true) 6572 { 6573 enum c_parser_prec oprec; 6574 enum tree_code ocode; 6575 source_range src_range; 6576 if (parser->error) 6577 goto out; 6578 switch (c_parser_peek_token (parser)->type) 6579 { 6580 case CPP_MULT: 6581 oprec = PREC_MULT; 6582 ocode = MULT_EXPR; 6583 break; 6584 case CPP_DIV: 6585 oprec = PREC_MULT; 6586 ocode = TRUNC_DIV_EXPR; 6587 break; 6588 case CPP_MOD: 6589 oprec = PREC_MULT; 6590 ocode = TRUNC_MOD_EXPR; 6591 break; 6592 case CPP_PLUS: 6593 oprec = PREC_ADD; 6594 ocode = PLUS_EXPR; 6595 break; 6596 case CPP_MINUS: 6597 oprec = PREC_ADD; 6598 ocode = MINUS_EXPR; 6599 break; 6600 case CPP_LSHIFT: 6601 oprec = PREC_SHIFT; 6602 ocode = LSHIFT_EXPR; 6603 break; 6604 case CPP_RSHIFT: 6605 oprec = PREC_SHIFT; 6606 ocode = RSHIFT_EXPR; 6607 break; 6608 case CPP_LESS: 6609 oprec = PREC_REL; 6610 ocode = LT_EXPR; 6611 break; 6612 case CPP_GREATER: 6613 oprec = PREC_REL; 6614 ocode = GT_EXPR; 6615 break; 6616 case CPP_LESS_EQ: 6617 oprec = PREC_REL; 6618 ocode = LE_EXPR; 6619 break; 6620 case CPP_GREATER_EQ: 6621 oprec = PREC_REL; 6622 ocode = GE_EXPR; 6623 break; 6624 case CPP_EQ_EQ: 6625 oprec = PREC_EQ; 6626 ocode = EQ_EXPR; 6627 break; 6628 case CPP_NOT_EQ: 6629 oprec = PREC_EQ; 6630 ocode = NE_EXPR; 6631 break; 6632 case CPP_AND: 6633 oprec = PREC_BITAND; 6634 ocode = BIT_AND_EXPR; 6635 break; 6636 case CPP_XOR: 6637 oprec = PREC_BITXOR; 6638 ocode = BIT_XOR_EXPR; 6639 break; 6640 case CPP_OR: 6641 oprec = PREC_BITOR; 6642 ocode = BIT_IOR_EXPR; 6643 break; 6644 case CPP_AND_AND: 6645 oprec = PREC_LOGAND; 6646 ocode = TRUTH_ANDIF_EXPR; 6647 break; 6648 case CPP_OR_OR: 6649 oprec = PREC_LOGOR; 6650 ocode = TRUTH_ORIF_EXPR; 6651 break; 6652 default: 6653 /* Not a binary operator, so end of the binary 6654 expression. */ 6655 goto out; 6656 } 6657 binary_loc = c_parser_peek_token (parser)->location; 6658 while (oprec <= stack[sp].prec) 6659 POP; 6660 c_parser_consume_token (parser); 6661 switch (ocode) 6662 { 6663 case TRUTH_ANDIF_EXPR: 6664 src_range = stack[sp].expr.src_range; 6665 stack[sp].expr 6666 = convert_lvalue_to_rvalue (stack[sp].loc, 6667 stack[sp].expr, true, true); 6668 stack[sp].expr.value = c_objc_common_truthvalue_conversion 6669 (stack[sp].loc, default_conversion (stack[sp].expr.value)); 6670 c_inhibit_evaluation_warnings += (stack[sp].expr.value 6671 == truthvalue_false_node); 6672 set_c_expr_source_range (&stack[sp].expr, src_range); 6673 break; 6674 case TRUTH_ORIF_EXPR: 6675 src_range = stack[sp].expr.src_range; 6676 stack[sp].expr 6677 = convert_lvalue_to_rvalue (stack[sp].loc, 6678 stack[sp].expr, true, true); 6679 stack[sp].expr.value = c_objc_common_truthvalue_conversion 6680 (stack[sp].loc, default_conversion (stack[sp].expr.value)); 6681 c_inhibit_evaluation_warnings += (stack[sp].expr.value 6682 == truthvalue_true_node); 6683 set_c_expr_source_range (&stack[sp].expr, src_range); 6684 break; 6685 default: 6686 break; 6687 } 6688 sp++; 6689 stack[sp].loc = binary_loc; 6690 stack[sp].expr = c_parser_cast_expression (parser, NULL); 6691 stack[sp].prec = oprec; 6692 stack[sp].op = ocode; 6693 } 6694 out: 6695 while (sp > 0) 6696 POP; 6697 return stack[0].expr; 6698 #undef POP 6699 } 6700 6701 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not 6702 NULL then it is an Objective-C message expression which is the 6703 primary-expression starting the expression as an initializer. 6704 6705 cast-expression: 6706 unary-expression 6707 ( type-name ) unary-expression 6708 */ 6709 6710 static struct c_expr 6711 c_parser_cast_expression (c_parser *parser, struct c_expr *after) 6712 { 6713 location_t cast_loc = c_parser_peek_token (parser)->location; 6714 gcc_assert (!after || c_dialect_objc ()); 6715 if (after) 6716 return c_parser_postfix_expression_after_primary (parser, 6717 cast_loc, *after); 6718 /* If the expression begins with a parenthesized type name, it may 6719 be either a cast or a compound literal; we need to see whether 6720 the next character is '{' to tell the difference. If not, it is 6721 an unary expression. Full detection of unknown typenames here 6722 would require a 3-token lookahead. */ 6723 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) 6724 && c_token_starts_typename (c_parser_peek_2nd_token (parser))) 6725 { 6726 struct c_type_name *type_name; 6727 struct c_expr ret; 6728 struct c_expr expr; 6729 c_parser_consume_token (parser); 6730 type_name = c_parser_type_name (parser); 6731 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 6732 if (type_name == NULL) 6733 { 6734 ret.value = error_mark_node; 6735 ret.original_code = ERROR_MARK; 6736 ret.original_type = NULL; 6737 return ret; 6738 } 6739 6740 /* Save casted types in the function's used types hash table. */ 6741 used_types_insert (type_name->specs->type); 6742 6743 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) 6744 return c_parser_postfix_expression_after_paren_type (parser, type_name, 6745 cast_loc); 6746 { 6747 location_t expr_loc = c_parser_peek_token (parser)->location; 6748 expr = c_parser_cast_expression (parser, NULL); 6749 expr = convert_lvalue_to_rvalue (expr_loc, expr, true, true); 6750 } 6751 ret.value = c_cast_expr (cast_loc, type_name, expr.value); 6752 if (ret.value && expr.value) 6753 set_c_expr_source_range (&ret, cast_loc, expr.get_finish ()); 6754 ret.original_code = ERROR_MARK; 6755 ret.original_type = NULL; 6756 return ret; 6757 } 6758 else 6759 return c_parser_unary_expression (parser); 6760 } 6761 6762 /* Parse an unary expression (C90 6.3.3, C99 6.5.3). 6763 6764 unary-expression: 6765 postfix-expression 6766 ++ unary-expression 6767 -- unary-expression 6768 unary-operator cast-expression 6769 sizeof unary-expression 6770 sizeof ( type-name ) 6771 6772 unary-operator: one of 6773 & * + - ~ ! 6774 6775 GNU extensions: 6776 6777 unary-expression: 6778 __alignof__ unary-expression 6779 __alignof__ ( type-name ) 6780 && identifier 6781 6782 (C11 permits _Alignof with type names only.) 6783 6784 unary-operator: one of 6785 __extension__ __real__ __imag__ 6786 6787 Transactional Memory: 6788 6789 unary-expression: 6790 transaction-expression 6791 6792 In addition, the GNU syntax treats ++ and -- as unary operators, so 6793 they may be applied to cast expressions with errors for non-lvalues 6794 given later. */ 6795 6796 static struct c_expr 6797 c_parser_unary_expression (c_parser *parser) 6798 { 6799 int ext; 6800 struct c_expr ret, op; 6801 location_t op_loc = c_parser_peek_token (parser)->location; 6802 location_t exp_loc; 6803 location_t finish; 6804 ret.original_code = ERROR_MARK; 6805 ret.original_type = NULL; 6806 switch (c_parser_peek_token (parser)->type) 6807 { 6808 case CPP_PLUS_PLUS: 6809 c_parser_consume_token (parser); 6810 exp_loc = c_parser_peek_token (parser)->location; 6811 op = c_parser_cast_expression (parser, NULL); 6812 6813 /* If there is array notations in op, we expand them. */ 6814 if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF) 6815 return fix_array_notation_expr (exp_loc, PREINCREMENT_EXPR, op); 6816 else 6817 { 6818 op = default_function_array_read_conversion (exp_loc, op); 6819 return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op); 6820 } 6821 case CPP_MINUS_MINUS: 6822 c_parser_consume_token (parser); 6823 exp_loc = c_parser_peek_token (parser)->location; 6824 op = c_parser_cast_expression (parser, NULL); 6825 6826 /* If there is array notations in op, we expand them. */ 6827 if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF) 6828 return fix_array_notation_expr (exp_loc, PREDECREMENT_EXPR, op); 6829 else 6830 { 6831 op = default_function_array_read_conversion (exp_loc, op); 6832 return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op); 6833 } 6834 case CPP_AND: 6835 c_parser_consume_token (parser); 6836 op = c_parser_cast_expression (parser, NULL); 6837 mark_exp_read (op.value); 6838 return parser_build_unary_op (op_loc, ADDR_EXPR, op); 6839 case CPP_MULT: 6840 { 6841 c_parser_consume_token (parser); 6842 exp_loc = c_parser_peek_token (parser)->location; 6843 op = c_parser_cast_expression (parser, NULL); 6844 finish = op.get_finish (); 6845 op = convert_lvalue_to_rvalue (exp_loc, op, true, true); 6846 location_t combined_loc = make_location (op_loc, op_loc, finish); 6847 ret.value = build_indirect_ref (combined_loc, op.value, RO_UNARY_STAR); 6848 ret.src_range.m_start = op_loc; 6849 ret.src_range.m_finish = finish; 6850 return ret; 6851 } 6852 case CPP_PLUS: 6853 if (!c_dialect_objc () && !in_system_header_at (input_location)) 6854 warning_at (op_loc, 6855 OPT_Wtraditional, 6856 "traditional C rejects the unary plus operator"); 6857 c_parser_consume_token (parser); 6858 exp_loc = c_parser_peek_token (parser)->location; 6859 op = c_parser_cast_expression (parser, NULL); 6860 op = convert_lvalue_to_rvalue (exp_loc, op, true, true); 6861 return parser_build_unary_op (op_loc, CONVERT_EXPR, op); 6862 case CPP_MINUS: 6863 c_parser_consume_token (parser); 6864 exp_loc = c_parser_peek_token (parser)->location; 6865 op = c_parser_cast_expression (parser, NULL); 6866 op = convert_lvalue_to_rvalue (exp_loc, op, true, true); 6867 return parser_build_unary_op (op_loc, NEGATE_EXPR, op); 6868 case CPP_COMPL: 6869 c_parser_consume_token (parser); 6870 exp_loc = c_parser_peek_token (parser)->location; 6871 op = c_parser_cast_expression (parser, NULL); 6872 op = convert_lvalue_to_rvalue (exp_loc, op, true, true); 6873 return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op); 6874 case CPP_NOT: 6875 c_parser_consume_token (parser); 6876 exp_loc = c_parser_peek_token (parser)->location; 6877 op = c_parser_cast_expression (parser, NULL); 6878 op = convert_lvalue_to_rvalue (exp_loc, op, true, true); 6879 return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op); 6880 case CPP_AND_AND: 6881 /* Refer to the address of a label as a pointer. */ 6882 c_parser_consume_token (parser); 6883 if (c_parser_next_token_is (parser, CPP_NAME)) 6884 { 6885 ret.value = finish_label_address_expr 6886 (c_parser_peek_token (parser)->value, op_loc); 6887 set_c_expr_source_range (&ret, op_loc, 6888 c_parser_peek_token (parser)->get_finish ()); 6889 c_parser_consume_token (parser); 6890 } 6891 else 6892 { 6893 c_parser_error (parser, "expected identifier"); 6894 ret.value = error_mark_node; 6895 } 6896 return ret; 6897 case CPP_KEYWORD: 6898 switch (c_parser_peek_token (parser)->keyword) 6899 { 6900 case RID_SIZEOF: 6901 return c_parser_sizeof_expression (parser); 6902 case RID_ALIGNOF: 6903 return c_parser_alignof_expression (parser); 6904 case RID_EXTENSION: 6905 c_parser_consume_token (parser); 6906 ext = disable_extension_diagnostics (); 6907 ret = c_parser_cast_expression (parser, NULL); 6908 restore_extension_diagnostics (ext); 6909 return ret; 6910 case RID_REALPART: 6911 c_parser_consume_token (parser); 6912 exp_loc = c_parser_peek_token (parser)->location; 6913 op = c_parser_cast_expression (parser, NULL); 6914 op = default_function_array_conversion (exp_loc, op); 6915 return parser_build_unary_op (op_loc, REALPART_EXPR, op); 6916 case RID_IMAGPART: 6917 c_parser_consume_token (parser); 6918 exp_loc = c_parser_peek_token (parser)->location; 6919 op = c_parser_cast_expression (parser, NULL); 6920 op = default_function_array_conversion (exp_loc, op); 6921 return parser_build_unary_op (op_loc, IMAGPART_EXPR, op); 6922 case RID_TRANSACTION_ATOMIC: 6923 case RID_TRANSACTION_RELAXED: 6924 return c_parser_transaction_expression (parser, 6925 c_parser_peek_token (parser)->keyword); 6926 default: 6927 return c_parser_postfix_expression (parser); 6928 } 6929 default: 6930 return c_parser_postfix_expression (parser); 6931 } 6932 } 6933 6934 /* Parse a sizeof expression. */ 6935 6936 static struct c_expr 6937 c_parser_sizeof_expression (c_parser *parser) 6938 { 6939 struct c_expr expr; 6940 struct c_expr result; 6941 location_t expr_loc; 6942 gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF)); 6943 6944 location_t start; 6945 location_t finish = UNKNOWN_LOCATION; 6946 6947 start = c_parser_peek_token (parser)->location; 6948 6949 c_parser_consume_token (parser); 6950 c_inhibit_evaluation_warnings++; 6951 in_sizeof++; 6952 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) 6953 && c_token_starts_typename (c_parser_peek_2nd_token (parser))) 6954 { 6955 /* Either sizeof ( type-name ) or sizeof unary-expression 6956 starting with a compound literal. */ 6957 struct c_type_name *type_name; 6958 c_parser_consume_token (parser); 6959 expr_loc = c_parser_peek_token (parser)->location; 6960 type_name = c_parser_type_name (parser); 6961 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 6962 finish = parser->tokens_buf[0].location; 6963 if (type_name == NULL) 6964 { 6965 struct c_expr ret; 6966 c_inhibit_evaluation_warnings--; 6967 in_sizeof--; 6968 ret.value = error_mark_node; 6969 ret.original_code = ERROR_MARK; 6970 ret.original_type = NULL; 6971 return ret; 6972 } 6973 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) 6974 { 6975 expr = c_parser_postfix_expression_after_paren_type (parser, 6976 type_name, 6977 expr_loc); 6978 finish = expr.get_finish (); 6979 goto sizeof_expr; 6980 } 6981 /* sizeof ( type-name ). */ 6982 c_inhibit_evaluation_warnings--; 6983 in_sizeof--; 6984 result = c_expr_sizeof_type (expr_loc, type_name); 6985 } 6986 else 6987 { 6988 expr_loc = c_parser_peek_token (parser)->location; 6989 expr = c_parser_unary_expression (parser); 6990 finish = expr.get_finish (); 6991 sizeof_expr: 6992 c_inhibit_evaluation_warnings--; 6993 in_sizeof--; 6994 mark_exp_read (expr.value); 6995 if (TREE_CODE (expr.value) == COMPONENT_REF 6996 && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1))) 6997 error_at (expr_loc, "%<sizeof%> applied to a bit-field"); 6998 result = c_expr_sizeof_expr (expr_loc, expr); 6999 } 7000 if (finish != UNKNOWN_LOCATION) 7001 set_c_expr_source_range (&result, start, finish); 7002 return result; 7003 } 7004 7005 /* Parse an alignof expression. */ 7006 7007 static struct c_expr 7008 c_parser_alignof_expression (c_parser *parser) 7009 { 7010 struct c_expr expr; 7011 location_t start_loc = c_parser_peek_token (parser)->location; 7012 location_t end_loc; 7013 tree alignof_spelling = c_parser_peek_token (parser)->value; 7014 gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF)); 7015 bool is_c11_alignof = strcmp (IDENTIFIER_POINTER (alignof_spelling), 7016 "_Alignof") == 0; 7017 /* A diagnostic is not required for the use of this identifier in 7018 the implementation namespace; only diagnose it for the C11 7019 spelling because of existing code using the other spellings. */ 7020 if (is_c11_alignof) 7021 { 7022 if (flag_isoc99) 7023 pedwarn_c99 (start_loc, OPT_Wpedantic, "ISO C99 does not support %qE", 7024 alignof_spelling); 7025 else 7026 pedwarn_c99 (start_loc, OPT_Wpedantic, "ISO C90 does not support %qE", 7027 alignof_spelling); 7028 } 7029 c_parser_consume_token (parser); 7030 c_inhibit_evaluation_warnings++; 7031 in_alignof++; 7032 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) 7033 && c_token_starts_typename (c_parser_peek_2nd_token (parser))) 7034 { 7035 /* Either __alignof__ ( type-name ) or __alignof__ 7036 unary-expression starting with a compound literal. */ 7037 location_t loc; 7038 struct c_type_name *type_name; 7039 struct c_expr ret; 7040 c_parser_consume_token (parser); 7041 loc = c_parser_peek_token (parser)->location; 7042 type_name = c_parser_type_name (parser); 7043 end_loc = c_parser_peek_token (parser)->location; 7044 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 7045 if (type_name == NULL) 7046 { 7047 struct c_expr ret; 7048 c_inhibit_evaluation_warnings--; 7049 in_alignof--; 7050 ret.value = error_mark_node; 7051 ret.original_code = ERROR_MARK; 7052 ret.original_type = NULL; 7053 return ret; 7054 } 7055 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) 7056 { 7057 expr = c_parser_postfix_expression_after_paren_type (parser, 7058 type_name, 7059 loc); 7060 goto alignof_expr; 7061 } 7062 /* alignof ( type-name ). */ 7063 c_inhibit_evaluation_warnings--; 7064 in_alignof--; 7065 ret.value = c_sizeof_or_alignof_type (loc, groktypename (type_name, 7066 NULL, NULL), 7067 false, is_c11_alignof, 1); 7068 ret.original_code = ERROR_MARK; 7069 ret.original_type = NULL; 7070 set_c_expr_source_range (&ret, start_loc, end_loc); 7071 return ret; 7072 } 7073 else 7074 { 7075 struct c_expr ret; 7076 expr = c_parser_unary_expression (parser); 7077 end_loc = expr.src_range.m_finish; 7078 alignof_expr: 7079 mark_exp_read (expr.value); 7080 c_inhibit_evaluation_warnings--; 7081 in_alignof--; 7082 pedwarn (start_loc, 7083 OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>", 7084 alignof_spelling); 7085 ret.value = c_alignof_expr (start_loc, expr.value); 7086 ret.original_code = ERROR_MARK; 7087 ret.original_type = NULL; 7088 set_c_expr_source_range (&ret, start_loc, end_loc); 7089 return ret; 7090 } 7091 } 7092 7093 /* Helper function to read arguments of builtins which are interfaces 7094 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and 7095 others. The name of the builtin is passed using BNAME parameter. 7096 Function returns true if there were no errors while parsing and 7097 stores the arguments in CEXPR_LIST. If it returns true, 7098 *OUT_CLOSE_PAREN_LOC is written to with the location of the closing 7099 parenthesis. */ 7100 static bool 7101 c_parser_get_builtin_args (c_parser *parser, const char *bname, 7102 vec<c_expr_t, va_gc> **ret_cexpr_list, 7103 bool choose_expr_p, 7104 location_t *out_close_paren_loc) 7105 { 7106 location_t loc = c_parser_peek_token (parser)->location; 7107 vec<c_expr_t, va_gc> *cexpr_list; 7108 c_expr_t expr; 7109 bool saved_force_folding_builtin_constant_p; 7110 7111 *ret_cexpr_list = NULL; 7112 if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN)) 7113 { 7114 error_at (loc, "cannot take address of %qs", bname); 7115 return false; 7116 } 7117 7118 c_parser_consume_token (parser); 7119 7120 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 7121 { 7122 *out_close_paren_loc = c_parser_peek_token (parser)->location; 7123 c_parser_consume_token (parser); 7124 return true; 7125 } 7126 7127 saved_force_folding_builtin_constant_p 7128 = force_folding_builtin_constant_p; 7129 force_folding_builtin_constant_p |= choose_expr_p; 7130 expr = c_parser_expr_no_commas (parser, NULL); 7131 force_folding_builtin_constant_p 7132 = saved_force_folding_builtin_constant_p; 7133 vec_alloc (cexpr_list, 1); 7134 vec_safe_push (cexpr_list, expr); 7135 while (c_parser_next_token_is (parser, CPP_COMMA)) 7136 { 7137 c_parser_consume_token (parser); 7138 expr = c_parser_expr_no_commas (parser, NULL); 7139 vec_safe_push (cexpr_list, expr); 7140 } 7141 7142 *out_close_paren_loc = c_parser_peek_token (parser)->location; 7143 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) 7144 return false; 7145 7146 *ret_cexpr_list = cexpr_list; 7147 return true; 7148 } 7149 7150 /* This represents a single generic-association. */ 7151 7152 struct c_generic_association 7153 { 7154 /* The location of the starting token of the type. */ 7155 location_t type_location; 7156 /* The association's type, or NULL_TREE for 'default'. */ 7157 tree type; 7158 /* The association's expression. */ 7159 struct c_expr expression; 7160 }; 7161 7162 /* Parse a generic-selection. (C11 6.5.1.1). 7163 7164 generic-selection: 7165 _Generic ( assignment-expression , generic-assoc-list ) 7166 7167 generic-assoc-list: 7168 generic-association 7169 generic-assoc-list , generic-association 7170 7171 generic-association: 7172 type-name : assignment-expression 7173 default : assignment-expression 7174 */ 7175 7176 static struct c_expr 7177 c_parser_generic_selection (c_parser *parser) 7178 { 7179 vec<c_generic_association> associations = vNULL; 7180 struct c_expr selector, error_expr; 7181 tree selector_type; 7182 struct c_generic_association matched_assoc; 7183 bool match_found = false; 7184 location_t generic_loc, selector_loc; 7185 7186 error_expr.original_code = ERROR_MARK; 7187 error_expr.original_type = NULL; 7188 error_expr.set_error (); 7189 matched_assoc.type_location = UNKNOWN_LOCATION; 7190 matched_assoc.type = NULL_TREE; 7191 matched_assoc.expression = error_expr; 7192 7193 gcc_assert (c_parser_next_token_is_keyword (parser, RID_GENERIC)); 7194 generic_loc = c_parser_peek_token (parser)->location; 7195 c_parser_consume_token (parser); 7196 if (flag_isoc99) 7197 pedwarn_c99 (generic_loc, OPT_Wpedantic, 7198 "ISO C99 does not support %<_Generic%>"); 7199 else 7200 pedwarn_c99 (generic_loc, OPT_Wpedantic, 7201 "ISO C90 does not support %<_Generic%>"); 7202 7203 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 7204 return error_expr; 7205 7206 c_inhibit_evaluation_warnings++; 7207 selector_loc = c_parser_peek_token (parser)->location; 7208 selector = c_parser_expr_no_commas (parser, NULL); 7209 selector = default_function_array_conversion (selector_loc, selector); 7210 c_inhibit_evaluation_warnings--; 7211 7212 if (selector.value == error_mark_node) 7213 { 7214 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 7215 return selector; 7216 } 7217 selector_type = TREE_TYPE (selector.value); 7218 /* In ISO C terms, rvalues (including the controlling expression of 7219 _Generic) do not have qualified types. */ 7220 if (TREE_CODE (selector_type) != ARRAY_TYPE) 7221 selector_type = TYPE_MAIN_VARIANT (selector_type); 7222 /* In ISO C terms, _Noreturn is not part of the type of expressions 7223 such as &abort, but in GCC it is represented internally as a type 7224 qualifier. */ 7225 if (FUNCTION_POINTER_TYPE_P (selector_type) 7226 && TYPE_QUALS (TREE_TYPE (selector_type)) != TYPE_UNQUALIFIED) 7227 selector_type 7228 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type))); 7229 7230 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) 7231 { 7232 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 7233 return error_expr; 7234 } 7235 7236 while (1) 7237 { 7238 struct c_generic_association assoc, *iter; 7239 unsigned int ix; 7240 c_token *token = c_parser_peek_token (parser); 7241 7242 assoc.type_location = token->location; 7243 if (token->type == CPP_KEYWORD && token->keyword == RID_DEFAULT) 7244 { 7245 c_parser_consume_token (parser); 7246 assoc.type = NULL_TREE; 7247 } 7248 else 7249 { 7250 struct c_type_name *type_name; 7251 7252 type_name = c_parser_type_name (parser); 7253 if (type_name == NULL) 7254 { 7255 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 7256 goto error_exit; 7257 } 7258 assoc.type = groktypename (type_name, NULL, NULL); 7259 if (assoc.type == error_mark_node) 7260 { 7261 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 7262 goto error_exit; 7263 } 7264 7265 if (TREE_CODE (assoc.type) == FUNCTION_TYPE) 7266 error_at (assoc.type_location, 7267 "%<_Generic%> association has function type"); 7268 else if (!COMPLETE_TYPE_P (assoc.type)) 7269 error_at (assoc.type_location, 7270 "%<_Generic%> association has incomplete type"); 7271 7272 if (variably_modified_type_p (assoc.type, NULL_TREE)) 7273 error_at (assoc.type_location, 7274 "%<_Generic%> association has " 7275 "variable length type"); 7276 } 7277 7278 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) 7279 { 7280 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 7281 goto error_exit; 7282 } 7283 7284 assoc.expression = c_parser_expr_no_commas (parser, NULL); 7285 if (assoc.expression.value == error_mark_node) 7286 { 7287 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 7288 goto error_exit; 7289 } 7290 7291 for (ix = 0; associations.iterate (ix, &iter); ++ix) 7292 { 7293 if (assoc.type == NULL_TREE) 7294 { 7295 if (iter->type == NULL_TREE) 7296 { 7297 error_at (assoc.type_location, 7298 "duplicate %<default%> case in %<_Generic%>"); 7299 inform (iter->type_location, "original %<default%> is here"); 7300 } 7301 } 7302 else if (iter->type != NULL_TREE) 7303 { 7304 if (comptypes (assoc.type, iter->type)) 7305 { 7306 error_at (assoc.type_location, 7307 "%<_Generic%> specifies two compatible types"); 7308 inform (iter->type_location, "compatible type is here"); 7309 } 7310 } 7311 } 7312 7313 if (assoc.type == NULL_TREE) 7314 { 7315 if (!match_found) 7316 { 7317 matched_assoc = assoc; 7318 match_found = true; 7319 } 7320 } 7321 else if (comptypes (assoc.type, selector_type)) 7322 { 7323 if (!match_found || matched_assoc.type == NULL_TREE) 7324 { 7325 matched_assoc = assoc; 7326 match_found = true; 7327 } 7328 else 7329 { 7330 error_at (assoc.type_location, 7331 "%<_Generic> selector matches multiple associations"); 7332 inform (matched_assoc.type_location, 7333 "other match is here"); 7334 } 7335 } 7336 7337 associations.safe_push (assoc); 7338 7339 if (c_parser_peek_token (parser)->type != CPP_COMMA) 7340 break; 7341 c_parser_consume_token (parser); 7342 } 7343 7344 associations.release (); 7345 7346 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) 7347 { 7348 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 7349 return error_expr; 7350 } 7351 7352 if (!match_found) 7353 { 7354 error_at (selector_loc, "%<_Generic%> selector of type %qT is not " 7355 "compatible with any association", 7356 selector_type); 7357 return error_expr; 7358 } 7359 7360 return matched_assoc.expression; 7361 7362 error_exit: 7363 associations.release (); 7364 return error_expr; 7365 } 7366 7367 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2). 7368 7369 postfix-expression: 7370 primary-expression 7371 postfix-expression [ expression ] 7372 postfix-expression ( argument-expression-list[opt] ) 7373 postfix-expression . identifier 7374 postfix-expression -> identifier 7375 postfix-expression ++ 7376 postfix-expression -- 7377 ( type-name ) { initializer-list } 7378 ( type-name ) { initializer-list , } 7379 7380 argument-expression-list: 7381 argument-expression 7382 argument-expression-list , argument-expression 7383 7384 primary-expression: 7385 identifier 7386 constant 7387 string-literal 7388 ( expression ) 7389 generic-selection 7390 7391 GNU extensions: 7392 7393 primary-expression: 7394 __func__ 7395 (treated as a keyword in GNU C) 7396 __FUNCTION__ 7397 __PRETTY_FUNCTION__ 7398 ( compound-statement ) 7399 __builtin_va_arg ( assignment-expression , type-name ) 7400 __builtin_offsetof ( type-name , offsetof-member-designator ) 7401 __builtin_choose_expr ( assignment-expression , 7402 assignment-expression , 7403 assignment-expression ) 7404 __builtin_types_compatible_p ( type-name , type-name ) 7405 __builtin_complex ( assignment-expression , assignment-expression ) 7406 __builtin_shuffle ( assignment-expression , assignment-expression ) 7407 __builtin_shuffle ( assignment-expression , 7408 assignment-expression , 7409 assignment-expression, ) 7410 7411 offsetof-member-designator: 7412 identifier 7413 offsetof-member-designator . identifier 7414 offsetof-member-designator [ expression ] 7415 7416 Objective-C: 7417 7418 primary-expression: 7419 [ objc-receiver objc-message-args ] 7420 @selector ( objc-selector-arg ) 7421 @protocol ( identifier ) 7422 @encode ( type-name ) 7423 objc-string-literal 7424 Classname . identifier 7425 */ 7426 7427 static struct c_expr 7428 c_parser_postfix_expression (c_parser *parser) 7429 { 7430 struct c_expr expr, e1; 7431 struct c_type_name *t1, *t2; 7432 location_t loc = c_parser_peek_token (parser)->location;; 7433 source_range tok_range = c_parser_peek_token (parser)->get_range (); 7434 expr.original_code = ERROR_MARK; 7435 expr.original_type = NULL; 7436 switch (c_parser_peek_token (parser)->type) 7437 { 7438 case CPP_NUMBER: 7439 expr.value = c_parser_peek_token (parser)->value; 7440 set_c_expr_source_range (&expr, tok_range); 7441 loc = c_parser_peek_token (parser)->location; 7442 c_parser_consume_token (parser); 7443 if (TREE_CODE (expr.value) == FIXED_CST 7444 && !targetm.fixed_point_supported_p ()) 7445 { 7446 error_at (loc, "fixed-point types not supported for this target"); 7447 expr.value = error_mark_node; 7448 } 7449 break; 7450 case CPP_CHAR: 7451 case CPP_CHAR16: 7452 case CPP_CHAR32: 7453 case CPP_WCHAR: 7454 expr.value = c_parser_peek_token (parser)->value; 7455 set_c_expr_source_range (&expr, tok_range); 7456 c_parser_consume_token (parser); 7457 break; 7458 case CPP_STRING: 7459 case CPP_STRING16: 7460 case CPP_STRING32: 7461 case CPP_WSTRING: 7462 case CPP_UTF8STRING: 7463 expr.value = c_parser_peek_token (parser)->value; 7464 set_c_expr_source_range (&expr, tok_range); 7465 expr.original_code = STRING_CST; 7466 c_parser_consume_token (parser); 7467 break; 7468 case CPP_OBJC_STRING: 7469 gcc_assert (c_dialect_objc ()); 7470 expr.value 7471 = objc_build_string_object (c_parser_peek_token (parser)->value); 7472 set_c_expr_source_range (&expr, tok_range); 7473 c_parser_consume_token (parser); 7474 break; 7475 case CPP_NAME: 7476 switch (c_parser_peek_token (parser)->id_kind) 7477 { 7478 case C_ID_ID: 7479 { 7480 tree id = c_parser_peek_token (parser)->value; 7481 c_parser_consume_token (parser); 7482 expr.value = build_external_ref (loc, id, 7483 (c_parser_peek_token (parser)->type 7484 == CPP_OPEN_PAREN), 7485 &expr.original_type); 7486 set_c_expr_source_range (&expr, tok_range); 7487 break; 7488 } 7489 case C_ID_CLASSNAME: 7490 { 7491 /* Here we parse the Objective-C 2.0 Class.name dot 7492 syntax. */ 7493 tree class_name = c_parser_peek_token (parser)->value; 7494 tree component; 7495 c_parser_consume_token (parser); 7496 gcc_assert (c_dialect_objc ()); 7497 if (!c_parser_require (parser, CPP_DOT, "expected %<.%>")) 7498 { 7499 expr.set_error (); 7500 break; 7501 } 7502 if (c_parser_next_token_is_not (parser, CPP_NAME)) 7503 { 7504 c_parser_error (parser, "expected identifier"); 7505 expr.set_error (); 7506 break; 7507 } 7508 c_token *component_tok = c_parser_peek_token (parser); 7509 component = component_tok->value; 7510 location_t end_loc = component_tok->get_finish (); 7511 c_parser_consume_token (parser); 7512 expr.value = objc_build_class_component_ref (class_name, 7513 component); 7514 set_c_expr_source_range (&expr, loc, end_loc); 7515 break; 7516 } 7517 default: 7518 c_parser_error (parser, "expected expression"); 7519 expr.set_error (); 7520 break; 7521 } 7522 break; 7523 case CPP_OPEN_PAREN: 7524 /* A parenthesized expression, statement expression or compound 7525 literal. */ 7526 if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE) 7527 { 7528 /* A statement expression. */ 7529 tree stmt; 7530 location_t brace_loc; 7531 c_parser_consume_token (parser); 7532 brace_loc = c_parser_peek_token (parser)->location; 7533 c_parser_consume_token (parser); 7534 if (!building_stmt_list_p ()) 7535 { 7536 error_at (loc, "braced-group within expression allowed " 7537 "only inside a function"); 7538 parser->error = true; 7539 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); 7540 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 7541 expr.set_error (); 7542 break; 7543 } 7544 stmt = c_begin_stmt_expr (); 7545 c_parser_compound_statement_nostart (parser); 7546 location_t close_loc = c_parser_peek_token (parser)->location; 7547 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 7548 "expected %<)%>"); 7549 pedwarn (loc, OPT_Wpedantic, 7550 "ISO C forbids braced-groups within expressions"); 7551 expr.value = c_finish_stmt_expr (brace_loc, stmt); 7552 set_c_expr_source_range (&expr, loc, close_loc); 7553 mark_exp_read (expr.value); 7554 } 7555 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser))) 7556 { 7557 /* A compound literal. ??? Can we actually get here rather 7558 than going directly to 7559 c_parser_postfix_expression_after_paren_type from 7560 elsewhere? */ 7561 location_t loc; 7562 struct c_type_name *type_name; 7563 c_parser_consume_token (parser); 7564 loc = c_parser_peek_token (parser)->location; 7565 type_name = c_parser_type_name (parser); 7566 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 7567 "expected %<)%>"); 7568 if (type_name == NULL) 7569 { 7570 expr.set_error (); 7571 } 7572 else 7573 expr = c_parser_postfix_expression_after_paren_type (parser, 7574 type_name, 7575 loc); 7576 } 7577 else 7578 { 7579 /* A parenthesized expression. */ 7580 location_t loc_open_paren = c_parser_peek_token (parser)->location; 7581 c_parser_consume_token (parser); 7582 expr = c_parser_expression (parser); 7583 if (TREE_CODE (expr.value) == MODIFY_EXPR) 7584 TREE_NO_WARNING (expr.value) = 1; 7585 if (expr.original_code != C_MAYBE_CONST_EXPR) 7586 expr.original_code = ERROR_MARK; 7587 /* Don't change EXPR.ORIGINAL_TYPE. */ 7588 location_t loc_close_paren = c_parser_peek_token (parser)->location; 7589 set_c_expr_source_range (&expr, loc_open_paren, loc_close_paren); 7590 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 7591 "expected %<)%>"); 7592 } 7593 break; 7594 case CPP_KEYWORD: 7595 switch (c_parser_peek_token (parser)->keyword) 7596 { 7597 case RID_FUNCTION_NAME: 7598 pedwarn (loc, OPT_Wpedantic, "ISO C does not support " 7599 "%<__FUNCTION__%> predefined identifier"); 7600 expr.value = fname_decl (loc, 7601 c_parser_peek_token (parser)->keyword, 7602 c_parser_peek_token (parser)->value); 7603 set_c_expr_source_range (&expr, loc, loc); 7604 c_parser_consume_token (parser); 7605 break; 7606 case RID_PRETTY_FUNCTION_NAME: 7607 pedwarn (loc, OPT_Wpedantic, "ISO C does not support " 7608 "%<__PRETTY_FUNCTION__%> predefined identifier"); 7609 expr.value = fname_decl (loc, 7610 c_parser_peek_token (parser)->keyword, 7611 c_parser_peek_token (parser)->value); 7612 set_c_expr_source_range (&expr, loc, loc); 7613 c_parser_consume_token (parser); 7614 break; 7615 case RID_C99_FUNCTION_NAME: 7616 pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not support " 7617 "%<__func__%> predefined identifier"); 7618 expr.value = fname_decl (loc, 7619 c_parser_peek_token (parser)->keyword, 7620 c_parser_peek_token (parser)->value); 7621 set_c_expr_source_range (&expr, loc, loc); 7622 c_parser_consume_token (parser); 7623 break; 7624 case RID_VA_ARG: 7625 { 7626 location_t start_loc = loc; 7627 c_parser_consume_token (parser); 7628 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 7629 { 7630 expr.set_error (); 7631 break; 7632 } 7633 e1 = c_parser_expr_no_commas (parser, NULL); 7634 mark_exp_read (e1.value); 7635 e1.value = c_fully_fold (e1.value, false, NULL); 7636 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) 7637 { 7638 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 7639 expr.set_error (); 7640 break; 7641 } 7642 loc = c_parser_peek_token (parser)->location; 7643 t1 = c_parser_type_name (parser); 7644 location_t end_loc = c_parser_peek_token (parser)->get_finish (); 7645 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 7646 "expected %<)%>"); 7647 if (t1 == NULL) 7648 { 7649 expr.set_error (); 7650 } 7651 else 7652 { 7653 tree type_expr = NULL_TREE; 7654 expr.value = c_build_va_arg (start_loc, e1.value, loc, 7655 groktypename (t1, &type_expr, NULL)); 7656 if (type_expr) 7657 { 7658 expr.value = build2 (C_MAYBE_CONST_EXPR, 7659 TREE_TYPE (expr.value), type_expr, 7660 expr.value); 7661 C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true; 7662 } 7663 set_c_expr_source_range (&expr, start_loc, end_loc); 7664 } 7665 } 7666 break; 7667 case RID_OFFSETOF: 7668 c_parser_consume_token (parser); 7669 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 7670 { 7671 expr.set_error (); 7672 break; 7673 } 7674 t1 = c_parser_type_name (parser); 7675 if (t1 == NULL) 7676 parser->error = true; 7677 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) 7678 gcc_assert (parser->error); 7679 if (parser->error) 7680 { 7681 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 7682 expr.set_error (); 7683 break; 7684 } 7685 7686 { 7687 tree type = groktypename (t1, NULL, NULL); 7688 tree offsetof_ref; 7689 if (type == error_mark_node) 7690 offsetof_ref = error_mark_node; 7691 else 7692 { 7693 offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node); 7694 SET_EXPR_LOCATION (offsetof_ref, loc); 7695 } 7696 /* Parse the second argument to __builtin_offsetof. We 7697 must have one identifier, and beyond that we want to 7698 accept sub structure and sub array references. */ 7699 if (c_parser_next_token_is (parser, CPP_NAME)) 7700 { 7701 offsetof_ref = build_component_ref 7702 (loc, offsetof_ref, c_parser_peek_token (parser)->value); 7703 c_parser_consume_token (parser); 7704 while (c_parser_next_token_is (parser, CPP_DOT) 7705 || c_parser_next_token_is (parser, 7706 CPP_OPEN_SQUARE) 7707 || c_parser_next_token_is (parser, 7708 CPP_DEREF)) 7709 { 7710 if (c_parser_next_token_is (parser, CPP_DEREF)) 7711 { 7712 loc = c_parser_peek_token (parser)->location; 7713 offsetof_ref = build_array_ref (loc, 7714 offsetof_ref, 7715 integer_zero_node); 7716 goto do_dot; 7717 } 7718 else if (c_parser_next_token_is (parser, CPP_DOT)) 7719 { 7720 do_dot: 7721 c_parser_consume_token (parser); 7722 if (c_parser_next_token_is_not (parser, 7723 CPP_NAME)) 7724 { 7725 c_parser_error (parser, "expected identifier"); 7726 break; 7727 } 7728 offsetof_ref = build_component_ref 7729 (loc, offsetof_ref, 7730 c_parser_peek_token (parser)->value); 7731 c_parser_consume_token (parser); 7732 } 7733 else 7734 { 7735 struct c_expr ce; 7736 tree idx; 7737 loc = c_parser_peek_token (parser)->location; 7738 c_parser_consume_token (parser); 7739 ce = c_parser_expression (parser); 7740 ce = convert_lvalue_to_rvalue (loc, ce, false, false); 7741 idx = ce.value; 7742 idx = c_fully_fold (idx, false, NULL); 7743 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, 7744 "expected %<]%>"); 7745 offsetof_ref = build_array_ref (loc, offsetof_ref, idx); 7746 } 7747 } 7748 } 7749 else 7750 c_parser_error (parser, "expected identifier"); 7751 location_t end_loc = c_parser_peek_token (parser)->get_finish (); 7752 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 7753 "expected %<)%>"); 7754 expr.value = fold_offsetof (offsetof_ref); 7755 set_c_expr_source_range (&expr, loc, end_loc); 7756 } 7757 break; 7758 case RID_CHOOSE_EXPR: 7759 { 7760 vec<c_expr_t, va_gc> *cexpr_list; 7761 c_expr_t *e1_p, *e2_p, *e3_p; 7762 tree c; 7763 location_t close_paren_loc; 7764 7765 c_parser_consume_token (parser); 7766 if (!c_parser_get_builtin_args (parser, 7767 "__builtin_choose_expr", 7768 &cexpr_list, true, 7769 &close_paren_loc)) 7770 { 7771 expr.set_error (); 7772 break; 7773 } 7774 7775 if (vec_safe_length (cexpr_list) != 3) 7776 { 7777 error_at (loc, "wrong number of arguments to " 7778 "%<__builtin_choose_expr%>"); 7779 expr.set_error (); 7780 break; 7781 } 7782 7783 e1_p = &(*cexpr_list)[0]; 7784 e2_p = &(*cexpr_list)[1]; 7785 e3_p = &(*cexpr_list)[2]; 7786 7787 c = e1_p->value; 7788 mark_exp_read (e2_p->value); 7789 mark_exp_read (e3_p->value); 7790 if (TREE_CODE (c) != INTEGER_CST 7791 || !INTEGRAL_TYPE_P (TREE_TYPE (c))) 7792 error_at (loc, 7793 "first argument to %<__builtin_choose_expr%> not" 7794 " a constant"); 7795 constant_expression_warning (c); 7796 expr = integer_zerop (c) ? *e3_p : *e2_p; 7797 set_c_expr_source_range (&expr, loc, close_paren_loc); 7798 break; 7799 } 7800 case RID_TYPES_COMPATIBLE_P: 7801 c_parser_consume_token (parser); 7802 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 7803 { 7804 expr.set_error (); 7805 break; 7806 } 7807 t1 = c_parser_type_name (parser); 7808 if (t1 == NULL) 7809 { 7810 expr.set_error (); 7811 break; 7812 } 7813 if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) 7814 { 7815 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 7816 expr.set_error (); 7817 break; 7818 } 7819 t2 = c_parser_type_name (parser); 7820 if (t2 == NULL) 7821 { 7822 expr.set_error (); 7823 break; 7824 } 7825 { 7826 location_t close_paren_loc = c_parser_peek_token (parser)->location; 7827 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 7828 "expected %<)%>"); 7829 tree e1, e2; 7830 e1 = groktypename (t1, NULL, NULL); 7831 e2 = groktypename (t2, NULL, NULL); 7832 if (e1 == error_mark_node || e2 == error_mark_node) 7833 { 7834 expr.set_error (); 7835 break; 7836 } 7837 7838 e1 = TYPE_MAIN_VARIANT (e1); 7839 e2 = TYPE_MAIN_VARIANT (e2); 7840 7841 expr.value 7842 = comptypes (e1, e2) ? integer_one_node : integer_zero_node; 7843 set_c_expr_source_range (&expr, loc, close_paren_loc); 7844 } 7845 break; 7846 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN: 7847 { 7848 vec<c_expr_t, va_gc> *cexpr_list; 7849 c_expr_t *e2_p; 7850 tree chain_value; 7851 location_t close_paren_loc; 7852 7853 c_parser_consume_token (parser); 7854 if (!c_parser_get_builtin_args (parser, 7855 "__builtin_call_with_static_chain", 7856 &cexpr_list, false, 7857 &close_paren_loc)) 7858 { 7859 expr.set_error (); 7860 break; 7861 } 7862 if (vec_safe_length (cexpr_list) != 2) 7863 { 7864 error_at (loc, "wrong number of arguments to " 7865 "%<__builtin_call_with_static_chain%>"); 7866 expr.set_error (); 7867 break; 7868 } 7869 7870 expr = (*cexpr_list)[0]; 7871 e2_p = &(*cexpr_list)[1]; 7872 *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true); 7873 chain_value = e2_p->value; 7874 mark_exp_read (chain_value); 7875 7876 if (TREE_CODE (expr.value) != CALL_EXPR) 7877 error_at (loc, "first argument to " 7878 "%<__builtin_call_with_static_chain%> " 7879 "must be a call expression"); 7880 else if (TREE_CODE (TREE_TYPE (chain_value)) != POINTER_TYPE) 7881 error_at (loc, "second argument to " 7882 "%<__builtin_call_with_static_chain%> " 7883 "must be a pointer type"); 7884 else 7885 CALL_EXPR_STATIC_CHAIN (expr.value) = chain_value; 7886 set_c_expr_source_range (&expr, loc, close_paren_loc); 7887 break; 7888 } 7889 case RID_BUILTIN_COMPLEX: 7890 { 7891 vec<c_expr_t, va_gc> *cexpr_list; 7892 c_expr_t *e1_p, *e2_p; 7893 location_t close_paren_loc; 7894 7895 c_parser_consume_token (parser); 7896 if (!c_parser_get_builtin_args (parser, 7897 "__builtin_complex", 7898 &cexpr_list, false, 7899 &close_paren_loc)) 7900 { 7901 expr.set_error (); 7902 break; 7903 } 7904 7905 if (vec_safe_length (cexpr_list) != 2) 7906 { 7907 error_at (loc, "wrong number of arguments to " 7908 "%<__builtin_complex%>"); 7909 expr.set_error (); 7910 break; 7911 } 7912 7913 e1_p = &(*cexpr_list)[0]; 7914 e2_p = &(*cexpr_list)[1]; 7915 7916 *e1_p = convert_lvalue_to_rvalue (loc, *e1_p, true, true); 7917 if (TREE_CODE (e1_p->value) == EXCESS_PRECISION_EXPR) 7918 e1_p->value = convert (TREE_TYPE (e1_p->value), 7919 TREE_OPERAND (e1_p->value, 0)); 7920 *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true); 7921 if (TREE_CODE (e2_p->value) == EXCESS_PRECISION_EXPR) 7922 e2_p->value = convert (TREE_TYPE (e2_p->value), 7923 TREE_OPERAND (e2_p->value, 0)); 7924 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p->value)) 7925 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p->value)) 7926 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p->value)) 7927 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p->value))) 7928 { 7929 error_at (loc, "%<__builtin_complex%> operand " 7930 "not of real binary floating-point type"); 7931 expr.set_error (); 7932 break; 7933 } 7934 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p->value)) 7935 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p->value))) 7936 { 7937 error_at (loc, 7938 "%<__builtin_complex%> operands of different types"); 7939 expr.set_error (); 7940 break; 7941 } 7942 pedwarn_c90 (loc, OPT_Wpedantic, 7943 "ISO C90 does not support complex types"); 7944 expr.value = build2_loc (loc, COMPLEX_EXPR, 7945 build_complex_type 7946 (TYPE_MAIN_VARIANT 7947 (TREE_TYPE (e1_p->value))), 7948 e1_p->value, e2_p->value); 7949 set_c_expr_source_range (&expr, loc, close_paren_loc); 7950 break; 7951 } 7952 case RID_BUILTIN_SHUFFLE: 7953 { 7954 vec<c_expr_t, va_gc> *cexpr_list; 7955 unsigned int i; 7956 c_expr_t *p; 7957 location_t close_paren_loc; 7958 7959 c_parser_consume_token (parser); 7960 if (!c_parser_get_builtin_args (parser, 7961 "__builtin_shuffle", 7962 &cexpr_list, false, 7963 &close_paren_loc)) 7964 { 7965 expr.set_error (); 7966 break; 7967 } 7968 7969 FOR_EACH_VEC_SAFE_ELT (cexpr_list, i, p) 7970 *p = convert_lvalue_to_rvalue (loc, *p, true, true); 7971 7972 if (vec_safe_length (cexpr_list) == 2) 7973 expr.value = 7974 c_build_vec_perm_expr 7975 (loc, (*cexpr_list)[0].value, 7976 NULL_TREE, (*cexpr_list)[1].value); 7977 7978 else if (vec_safe_length (cexpr_list) == 3) 7979 expr.value = 7980 c_build_vec_perm_expr 7981 (loc, (*cexpr_list)[0].value, 7982 (*cexpr_list)[1].value, 7983 (*cexpr_list)[2].value); 7984 else 7985 { 7986 error_at (loc, "wrong number of arguments to " 7987 "%<__builtin_shuffle%>"); 7988 expr.set_error (); 7989 } 7990 set_c_expr_source_range (&expr, loc, close_paren_loc); 7991 break; 7992 } 7993 case RID_AT_SELECTOR: 7994 gcc_assert (c_dialect_objc ()); 7995 c_parser_consume_token (parser); 7996 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 7997 { 7998 expr.set_error (); 7999 break; 8000 } 8001 { 8002 tree sel = c_parser_objc_selector_arg (parser); 8003 location_t close_loc = c_parser_peek_token (parser)->location; 8004 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 8005 "expected %<)%>"); 8006 expr.value = objc_build_selector_expr (loc, sel); 8007 set_c_expr_source_range (&expr, loc, close_loc); 8008 } 8009 break; 8010 case RID_AT_PROTOCOL: 8011 gcc_assert (c_dialect_objc ()); 8012 c_parser_consume_token (parser); 8013 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 8014 { 8015 expr.set_error (); 8016 break; 8017 } 8018 if (c_parser_next_token_is_not (parser, CPP_NAME)) 8019 { 8020 c_parser_error (parser, "expected identifier"); 8021 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 8022 expr.set_error (); 8023 break; 8024 } 8025 { 8026 tree id = c_parser_peek_token (parser)->value; 8027 c_parser_consume_token (parser); 8028 location_t close_loc = c_parser_peek_token (parser)->location; 8029 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 8030 "expected %<)%>"); 8031 expr.value = objc_build_protocol_expr (id); 8032 set_c_expr_source_range (&expr, loc, close_loc); 8033 } 8034 break; 8035 case RID_AT_ENCODE: 8036 /* Extension to support C-structures in the archiver. */ 8037 gcc_assert (c_dialect_objc ()); 8038 c_parser_consume_token (parser); 8039 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 8040 { 8041 expr.set_error (); 8042 break; 8043 } 8044 t1 = c_parser_type_name (parser); 8045 if (t1 == NULL) 8046 { 8047 expr.set_error (); 8048 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 8049 break; 8050 } 8051 { 8052 location_t close_loc = c_parser_peek_token (parser)->location; 8053 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 8054 "expected %<)%>"); 8055 tree type = groktypename (t1, NULL, NULL); 8056 expr.value = objc_build_encode_expr (type); 8057 set_c_expr_source_range (&expr, loc, close_loc); 8058 } 8059 break; 8060 case RID_GENERIC: 8061 expr = c_parser_generic_selection (parser); 8062 break; 8063 case RID_CILK_SPAWN: 8064 c_parser_consume_token (parser); 8065 if (!flag_cilkplus) 8066 { 8067 error_at (loc, "-fcilkplus must be enabled to use " 8068 "%<_Cilk_spawn%>"); 8069 expr = c_parser_cast_expression (parser, NULL); 8070 expr.set_error (); 8071 } 8072 else if (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN) 8073 { 8074 error_at (loc, "consecutive %<_Cilk_spawn%> keywords " 8075 "are not permitted"); 8076 /* Now flush out all the _Cilk_spawns. */ 8077 while (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN) 8078 c_parser_consume_token (parser); 8079 expr = c_parser_cast_expression (parser, NULL); 8080 } 8081 else 8082 { 8083 expr = c_parser_cast_expression (parser, NULL); 8084 expr.value = build_cilk_spawn (loc, expr.value); 8085 } 8086 break; 8087 default: 8088 c_parser_error (parser, "expected expression"); 8089 expr.set_error (); 8090 break; 8091 } 8092 break; 8093 case CPP_OPEN_SQUARE: 8094 if (c_dialect_objc ()) 8095 { 8096 tree receiver, args; 8097 c_parser_consume_token (parser); 8098 receiver = c_parser_objc_receiver (parser); 8099 args = c_parser_objc_message_args (parser); 8100 location_t close_loc = c_parser_peek_token (parser)->location; 8101 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, 8102 "expected %<]%>"); 8103 expr.value = objc_build_message_expr (receiver, args); 8104 set_c_expr_source_range (&expr, loc, close_loc); 8105 break; 8106 } 8107 /* Else fall through to report error. */ 8108 default: 8109 c_parser_error (parser, "expected expression"); 8110 expr.set_error (); 8111 break; 8112 } 8113 return c_parser_postfix_expression_after_primary 8114 (parser, EXPR_LOC_OR_LOC (expr.value, loc), expr); 8115 } 8116 8117 /* Parse a postfix expression after a parenthesized type name: the 8118 brace-enclosed initializer of a compound literal, possibly followed 8119 by some postfix operators. This is separate because it is not 8120 possible to tell until after the type name whether a cast 8121 expression has a cast or a compound literal, or whether the operand 8122 of sizeof is a parenthesized type name or starts with a compound 8123 literal. TYPE_LOC is the location where TYPE_NAME starts--the 8124 location of the first token after the parentheses around the type 8125 name. */ 8126 8127 static struct c_expr 8128 c_parser_postfix_expression_after_paren_type (c_parser *parser, 8129 struct c_type_name *type_name, 8130 location_t type_loc) 8131 { 8132 tree type; 8133 struct c_expr init; 8134 bool non_const; 8135 struct c_expr expr; 8136 location_t start_loc; 8137 tree type_expr = NULL_TREE; 8138 bool type_expr_const = true; 8139 check_compound_literal_type (type_loc, type_name); 8140 start_init (NULL_TREE, NULL, 0); 8141 type = groktypename (type_name, &type_expr, &type_expr_const); 8142 start_loc = c_parser_peek_token (parser)->location; 8143 if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type)) 8144 { 8145 error_at (type_loc, "compound literal has variable size"); 8146 type = error_mark_node; 8147 } 8148 init = c_parser_braced_init (parser, type, false, NULL); 8149 finish_init (); 8150 maybe_warn_string_init (type_loc, type, init); 8151 8152 if (type != error_mark_node 8153 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type)) 8154 && current_function_decl) 8155 { 8156 error ("compound literal qualified by address-space qualifier"); 8157 type = error_mark_node; 8158 } 8159 8160 pedwarn_c90 (start_loc, OPT_Wpedantic, "ISO C90 forbids compound literals"); 8161 non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR) 8162 ? CONSTRUCTOR_NON_CONST (init.value) 8163 : init.original_code == C_MAYBE_CONST_EXPR); 8164 non_const |= !type_expr_const; 8165 expr.value = build_compound_literal (start_loc, type, init.value, non_const); 8166 set_c_expr_source_range (&expr, init.src_range); 8167 expr.original_code = ERROR_MARK; 8168 expr.original_type = NULL; 8169 if (type != error_mark_node && type_expr) 8170 { 8171 if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR) 8172 { 8173 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE); 8174 C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr; 8175 } 8176 else 8177 { 8178 gcc_assert (!non_const); 8179 expr.value = build2 (C_MAYBE_CONST_EXPR, type, 8180 type_expr, expr.value); 8181 } 8182 } 8183 return c_parser_postfix_expression_after_primary (parser, start_loc, expr); 8184 } 8185 8186 /* Callback function for sizeof_pointer_memaccess_warning to compare 8187 types. */ 8188 8189 static bool 8190 sizeof_ptr_memacc_comptypes (tree type1, tree type2) 8191 { 8192 return comptypes (type1, type2) == 1; 8193 } 8194 8195 /* Parse a postfix expression after the initial primary or compound 8196 literal; that is, parse a series of postfix operators. 8197 8198 EXPR_LOC is the location of the primary expression. */ 8199 8200 static struct c_expr 8201 c_parser_postfix_expression_after_primary (c_parser *parser, 8202 location_t expr_loc, 8203 struct c_expr expr) 8204 { 8205 struct c_expr orig_expr; 8206 tree ident, idx; 8207 location_t sizeof_arg_loc[3]; 8208 tree sizeof_arg[3]; 8209 unsigned int literal_zero_mask; 8210 unsigned int i; 8211 vec<tree, va_gc> *exprlist; 8212 vec<tree, va_gc> *origtypes = NULL; 8213 vec<location_t> arg_loc = vNULL; 8214 location_t start; 8215 location_t finish; 8216 8217 while (true) 8218 { 8219 location_t op_loc = c_parser_peek_token (parser)->location; 8220 switch (c_parser_peek_token (parser)->type) 8221 { 8222 case CPP_OPEN_SQUARE: 8223 /* Array reference. */ 8224 c_parser_consume_token (parser); 8225 if (flag_cilkplus 8226 && c_parser_peek_token (parser)->type == CPP_COLON) 8227 /* If we are here, then we have something like this: 8228 Array [ : ] 8229 */ 8230 expr.value = c_parser_array_notation (expr_loc, parser, NULL_TREE, 8231 expr.value); 8232 else 8233 { 8234 idx = c_parser_expression (parser).value; 8235 /* Here we have 3 options: 8236 1. Array [EXPR] -- Normal Array call. 8237 2. Array [EXPR : EXPR] -- Array notation without stride. 8238 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride. 8239 8240 For 1, we just handle it just like a normal array expression. 8241 For 2 and 3 we handle it like we handle array notations. The 8242 idx value we have above becomes the initial/start index. 8243 */ 8244 if (flag_cilkplus 8245 && c_parser_peek_token (parser)->type == CPP_COLON) 8246 expr.value = c_parser_array_notation (expr_loc, parser, idx, 8247 expr.value); 8248 else 8249 { 8250 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, 8251 "expected %<]%>"); 8252 start = expr.get_start (); 8253 finish = parser->tokens_buf[0].location; 8254 expr.value = build_array_ref (op_loc, expr.value, idx); 8255 set_c_expr_source_range (&expr, start, finish); 8256 } 8257 } 8258 expr.original_code = ERROR_MARK; 8259 expr.original_type = NULL; 8260 break; 8261 case CPP_OPEN_PAREN: 8262 /* Function call. */ 8263 c_parser_consume_token (parser); 8264 for (i = 0; i < 3; i++) 8265 { 8266 sizeof_arg[i] = NULL_TREE; 8267 sizeof_arg_loc[i] = UNKNOWN_LOCATION; 8268 } 8269 literal_zero_mask = 0; 8270 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 8271 exprlist = NULL; 8272 else 8273 exprlist = c_parser_expr_list (parser, true, false, &origtypes, 8274 sizeof_arg_loc, sizeof_arg, 8275 &arg_loc, &literal_zero_mask); 8276 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 8277 "expected %<)%>"); 8278 orig_expr = expr; 8279 mark_exp_read (expr.value); 8280 if (warn_sizeof_pointer_memaccess) 8281 sizeof_pointer_memaccess_warning (sizeof_arg_loc, 8282 expr.value, exprlist, 8283 sizeof_arg, 8284 sizeof_ptr_memacc_comptypes); 8285 if (warn_memset_transposed_args 8286 && TREE_CODE (expr.value) == FUNCTION_DECL 8287 && DECL_BUILT_IN_CLASS (expr.value) == BUILT_IN_NORMAL 8288 && DECL_FUNCTION_CODE (expr.value) == BUILT_IN_MEMSET 8289 && vec_safe_length (exprlist) == 3 8290 && integer_zerop ((*exprlist)[2]) 8291 && (literal_zero_mask & (1 << 2)) != 0 8292 && (!integer_zerop ((*exprlist)[1]) 8293 || (literal_zero_mask & (1 << 1)) == 0)) 8294 warning_at (expr_loc, OPT_Wmemset_transposed_args, 8295 "%<memset%> used with constant zero length parameter; " 8296 "this could be due to transposed parameters"); 8297 8298 start = expr.get_start (); 8299 finish = parser->tokens_buf[0].get_finish (); 8300 expr.value 8301 = c_build_function_call_vec (expr_loc, arg_loc, expr.value, 8302 exprlist, origtypes); 8303 set_c_expr_source_range (&expr, start, finish); 8304 8305 expr.original_code = ERROR_MARK; 8306 if (TREE_CODE (expr.value) == INTEGER_CST 8307 && TREE_CODE (orig_expr.value) == FUNCTION_DECL 8308 && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL 8309 && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P) 8310 expr.original_code = C_MAYBE_CONST_EXPR; 8311 expr.original_type = NULL; 8312 if (exprlist) 8313 { 8314 release_tree_vector (exprlist); 8315 release_tree_vector (origtypes); 8316 } 8317 arg_loc.release (); 8318 break; 8319 case CPP_DOT: 8320 /* Structure element reference. */ 8321 c_parser_consume_token (parser); 8322 expr = default_function_array_conversion (expr_loc, expr); 8323 if (c_parser_next_token_is (parser, CPP_NAME)) 8324 ident = c_parser_peek_token (parser)->value; 8325 else 8326 { 8327 c_parser_error (parser, "expected identifier"); 8328 expr.set_error (); 8329 expr.original_code = ERROR_MARK; 8330 expr.original_type = NULL; 8331 return expr; 8332 } 8333 start = expr.get_start (); 8334 finish = c_parser_peek_token (parser)->get_finish (); 8335 c_parser_consume_token (parser); 8336 expr.value = build_component_ref (op_loc, expr.value, ident); 8337 set_c_expr_source_range (&expr, start, finish); 8338 expr.original_code = ERROR_MARK; 8339 if (TREE_CODE (expr.value) != COMPONENT_REF) 8340 expr.original_type = NULL; 8341 else 8342 { 8343 /* Remember the original type of a bitfield. */ 8344 tree field = TREE_OPERAND (expr.value, 1); 8345 if (TREE_CODE (field) != FIELD_DECL) 8346 expr.original_type = NULL; 8347 else 8348 expr.original_type = DECL_BIT_FIELD_TYPE (field); 8349 } 8350 break; 8351 case CPP_DEREF: 8352 /* Structure element reference. */ 8353 c_parser_consume_token (parser); 8354 expr = convert_lvalue_to_rvalue (expr_loc, expr, true, false); 8355 if (c_parser_next_token_is (parser, CPP_NAME)) 8356 ident = c_parser_peek_token (parser)->value; 8357 else 8358 { 8359 c_parser_error (parser, "expected identifier"); 8360 expr.set_error (); 8361 expr.original_code = ERROR_MARK; 8362 expr.original_type = NULL; 8363 return expr; 8364 } 8365 start = expr.get_start (); 8366 finish = c_parser_peek_token (parser)->get_finish (); 8367 c_parser_consume_token (parser); 8368 expr.value = build_component_ref (op_loc, 8369 build_indirect_ref (op_loc, 8370 expr.value, 8371 RO_ARROW), 8372 ident); 8373 set_c_expr_source_range (&expr, start, finish); 8374 expr.original_code = ERROR_MARK; 8375 if (TREE_CODE (expr.value) != COMPONENT_REF) 8376 expr.original_type = NULL; 8377 else 8378 { 8379 /* Remember the original type of a bitfield. */ 8380 tree field = TREE_OPERAND (expr.value, 1); 8381 if (TREE_CODE (field) != FIELD_DECL) 8382 expr.original_type = NULL; 8383 else 8384 expr.original_type = DECL_BIT_FIELD_TYPE (field); 8385 } 8386 break; 8387 case CPP_PLUS_PLUS: 8388 /* Postincrement. */ 8389 start = expr.get_start (); 8390 finish = c_parser_peek_token (parser)->get_finish (); 8391 c_parser_consume_token (parser); 8392 /* If the expressions have array notations, we expand them. */ 8393 if (flag_cilkplus 8394 && TREE_CODE (expr.value) == ARRAY_NOTATION_REF) 8395 expr = fix_array_notation_expr (expr_loc, POSTINCREMENT_EXPR, expr); 8396 else 8397 { 8398 expr = default_function_array_read_conversion (expr_loc, expr); 8399 expr.value = build_unary_op (op_loc, 8400 POSTINCREMENT_EXPR, expr.value, 0); 8401 } 8402 set_c_expr_source_range (&expr, start, finish); 8403 expr.original_code = ERROR_MARK; 8404 expr.original_type = NULL; 8405 break; 8406 case CPP_MINUS_MINUS: 8407 /* Postdecrement. */ 8408 start = expr.get_start (); 8409 finish = c_parser_peek_token (parser)->get_finish (); 8410 c_parser_consume_token (parser); 8411 /* If the expressions have array notations, we expand them. */ 8412 if (flag_cilkplus 8413 && TREE_CODE (expr.value) == ARRAY_NOTATION_REF) 8414 expr = fix_array_notation_expr (expr_loc, POSTDECREMENT_EXPR, expr); 8415 else 8416 { 8417 expr = default_function_array_read_conversion (expr_loc, expr); 8418 expr.value = build_unary_op (op_loc, 8419 POSTDECREMENT_EXPR, expr.value, 0); 8420 } 8421 set_c_expr_source_range (&expr, start, finish); 8422 expr.original_code = ERROR_MARK; 8423 expr.original_type = NULL; 8424 break; 8425 default: 8426 return expr; 8427 } 8428 } 8429 } 8430 8431 /* Parse an expression (C90 6.3.17, C99 6.5.17). 8432 8433 expression: 8434 assignment-expression 8435 expression , assignment-expression 8436 */ 8437 8438 static struct c_expr 8439 c_parser_expression (c_parser *parser) 8440 { 8441 location_t tloc = c_parser_peek_token (parser)->location; 8442 struct c_expr expr; 8443 expr = c_parser_expr_no_commas (parser, NULL); 8444 if (c_parser_next_token_is (parser, CPP_COMMA)) 8445 expr = convert_lvalue_to_rvalue (tloc, expr, true, false); 8446 while (c_parser_next_token_is (parser, CPP_COMMA)) 8447 { 8448 struct c_expr next; 8449 tree lhsval; 8450 location_t loc = c_parser_peek_token (parser)->location; 8451 location_t expr_loc; 8452 c_parser_consume_token (parser); 8453 expr_loc = c_parser_peek_token (parser)->location; 8454 lhsval = expr.value; 8455 while (TREE_CODE (lhsval) == COMPOUND_EXPR) 8456 lhsval = TREE_OPERAND (lhsval, 1); 8457 if (DECL_P (lhsval) || handled_component_p (lhsval)) 8458 mark_exp_read (lhsval); 8459 next = c_parser_expr_no_commas (parser, NULL); 8460 next = convert_lvalue_to_rvalue (expr_loc, next, true, false); 8461 expr.value = build_compound_expr (loc, expr.value, next.value); 8462 expr.original_code = COMPOUND_EXPR; 8463 expr.original_type = next.original_type; 8464 } 8465 return expr; 8466 } 8467 8468 /* Parse an expression and convert functions or arrays to pointers and 8469 lvalues to rvalues. */ 8470 8471 static struct c_expr 8472 c_parser_expression_conv (c_parser *parser) 8473 { 8474 struct c_expr expr; 8475 location_t loc = c_parser_peek_token (parser)->location; 8476 expr = c_parser_expression (parser); 8477 expr = convert_lvalue_to_rvalue (loc, expr, true, false); 8478 return expr; 8479 } 8480 8481 /* Helper function of c_parser_expr_list. Check if IDXth (0 based) 8482 argument is a literal zero alone and if so, set it in literal_zero_mask. */ 8483 8484 static inline void 8485 c_parser_check_literal_zero (c_parser *parser, unsigned *literal_zero_mask, 8486 unsigned int idx) 8487 { 8488 if (idx >= HOST_BITS_PER_INT) 8489 return; 8490 8491 c_token *tok = c_parser_peek_token (parser); 8492 switch (tok->type) 8493 { 8494 case CPP_NUMBER: 8495 case CPP_CHAR: 8496 case CPP_WCHAR: 8497 case CPP_CHAR16: 8498 case CPP_CHAR32: 8499 /* If a parameter is literal zero alone, remember it 8500 for -Wmemset-transposed-args warning. */ 8501 if (integer_zerop (tok->value) 8502 && !TREE_OVERFLOW (tok->value) 8503 && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA 8504 || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN)) 8505 *literal_zero_mask |= 1U << idx; 8506 default: 8507 break; 8508 } 8509 } 8510 8511 /* Parse a non-empty list of expressions. If CONVERT_P, convert 8512 functions and arrays to pointers and lvalues to rvalues. If 8513 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the 8514 locations of function arguments into this vector. 8515 8516 nonempty-expr-list: 8517 assignment-expression 8518 nonempty-expr-list , assignment-expression 8519 */ 8520 8521 static vec<tree, va_gc> * 8522 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p, 8523 vec<tree, va_gc> **p_orig_types, 8524 location_t *sizeof_arg_loc, tree *sizeof_arg, 8525 vec<location_t> *locations, 8526 unsigned int *literal_zero_mask) 8527 { 8528 vec<tree, va_gc> *ret; 8529 vec<tree, va_gc> *orig_types; 8530 struct c_expr expr; 8531 location_t loc = c_parser_peek_token (parser)->location; 8532 location_t cur_sizeof_arg_loc = UNKNOWN_LOCATION; 8533 unsigned int idx = 0; 8534 8535 ret = make_tree_vector (); 8536 if (p_orig_types == NULL) 8537 orig_types = NULL; 8538 else 8539 orig_types = make_tree_vector (); 8540 8541 if (sizeof_arg != NULL 8542 && c_parser_next_token_is_keyword (parser, RID_SIZEOF)) 8543 cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location; 8544 if (literal_zero_mask) 8545 c_parser_check_literal_zero (parser, literal_zero_mask, 0); 8546 expr = c_parser_expr_no_commas (parser, NULL); 8547 if (convert_p) 8548 expr = convert_lvalue_to_rvalue (loc, expr, true, true); 8549 if (fold_p) 8550 expr.value = c_fully_fold (expr.value, false, NULL); 8551 ret->quick_push (expr.value); 8552 if (orig_types) 8553 orig_types->quick_push (expr.original_type); 8554 if (locations) 8555 locations->safe_push (loc); 8556 if (sizeof_arg != NULL 8557 && cur_sizeof_arg_loc != UNKNOWN_LOCATION 8558 && expr.original_code == SIZEOF_EXPR) 8559 { 8560 sizeof_arg[0] = c_last_sizeof_arg; 8561 sizeof_arg_loc[0] = cur_sizeof_arg_loc; 8562 } 8563 while (c_parser_next_token_is (parser, CPP_COMMA)) 8564 { 8565 c_parser_consume_token (parser); 8566 loc = c_parser_peek_token (parser)->location; 8567 if (sizeof_arg != NULL 8568 && c_parser_next_token_is_keyword (parser, RID_SIZEOF)) 8569 cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location; 8570 else 8571 cur_sizeof_arg_loc = UNKNOWN_LOCATION; 8572 if (literal_zero_mask) 8573 c_parser_check_literal_zero (parser, literal_zero_mask, idx + 1); 8574 expr = c_parser_expr_no_commas (parser, NULL); 8575 if (convert_p) 8576 expr = convert_lvalue_to_rvalue (loc, expr, true, true); 8577 if (fold_p) 8578 expr.value = c_fully_fold (expr.value, false, NULL); 8579 vec_safe_push (ret, expr.value); 8580 if (orig_types) 8581 vec_safe_push (orig_types, expr.original_type); 8582 if (locations) 8583 locations->safe_push (loc); 8584 if (++idx < 3 8585 && sizeof_arg != NULL 8586 && cur_sizeof_arg_loc != UNKNOWN_LOCATION 8587 && expr.original_code == SIZEOF_EXPR) 8588 { 8589 sizeof_arg[idx] = c_last_sizeof_arg; 8590 sizeof_arg_loc[idx] = cur_sizeof_arg_loc; 8591 } 8592 } 8593 if (orig_types) 8594 *p_orig_types = orig_types; 8595 return ret; 8596 } 8597 8598 /* Parse Objective-C-specific constructs. */ 8599 8600 /* Parse an objc-class-definition. 8601 8602 objc-class-definition: 8603 @interface identifier objc-superclass[opt] objc-protocol-refs[opt] 8604 objc-class-instance-variables[opt] objc-methodprotolist @end 8605 @implementation identifier objc-superclass[opt] 8606 objc-class-instance-variables[opt] 8607 @interface identifier ( identifier ) objc-protocol-refs[opt] 8608 objc-methodprotolist @end 8609 @interface identifier ( ) objc-protocol-refs[opt] 8610 objc-methodprotolist @end 8611 @implementation identifier ( identifier ) 8612 8613 objc-superclass: 8614 : identifier 8615 8616 "@interface identifier (" must start "@interface identifier ( 8617 identifier ) ...": objc-methodprotolist in the first production may 8618 not start with a parenthesized identifier as a declarator of a data 8619 definition with no declaration specifiers if the objc-superclass, 8620 objc-protocol-refs and objc-class-instance-variables are omitted. */ 8621 8622 static void 8623 c_parser_objc_class_definition (c_parser *parser, tree attributes) 8624 { 8625 bool iface_p; 8626 tree id1; 8627 tree superclass; 8628 if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE)) 8629 iface_p = true; 8630 else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION)) 8631 iface_p = false; 8632 else 8633 gcc_unreachable (); 8634 8635 c_parser_consume_token (parser); 8636 if (c_parser_next_token_is_not (parser, CPP_NAME)) 8637 { 8638 c_parser_error (parser, "expected identifier"); 8639 return; 8640 } 8641 id1 = c_parser_peek_token (parser)->value; 8642 c_parser_consume_token (parser); 8643 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) 8644 { 8645 /* We have a category or class extension. */ 8646 tree id2; 8647 tree proto = NULL_TREE; 8648 c_parser_consume_token (parser); 8649 if (c_parser_next_token_is_not (parser, CPP_NAME)) 8650 { 8651 if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 8652 { 8653 /* We have a class extension. */ 8654 id2 = NULL_TREE; 8655 } 8656 else 8657 { 8658 c_parser_error (parser, "expected identifier or %<)%>"); 8659 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 8660 return; 8661 } 8662 } 8663 else 8664 { 8665 id2 = c_parser_peek_token (parser)->value; 8666 c_parser_consume_token (parser); 8667 } 8668 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 8669 if (!iface_p) 8670 { 8671 objc_start_category_implementation (id1, id2); 8672 return; 8673 } 8674 if (c_parser_next_token_is (parser, CPP_LESS)) 8675 proto = c_parser_objc_protocol_refs (parser); 8676 objc_start_category_interface (id1, id2, proto, attributes); 8677 c_parser_objc_methodprotolist (parser); 8678 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); 8679 objc_finish_interface (); 8680 return; 8681 } 8682 if (c_parser_next_token_is (parser, CPP_COLON)) 8683 { 8684 c_parser_consume_token (parser); 8685 if (c_parser_next_token_is_not (parser, CPP_NAME)) 8686 { 8687 c_parser_error (parser, "expected identifier"); 8688 return; 8689 } 8690 superclass = c_parser_peek_token (parser)->value; 8691 c_parser_consume_token (parser); 8692 } 8693 else 8694 superclass = NULL_TREE; 8695 if (iface_p) 8696 { 8697 tree proto = NULL_TREE; 8698 if (c_parser_next_token_is (parser, CPP_LESS)) 8699 proto = c_parser_objc_protocol_refs (parser); 8700 objc_start_class_interface (id1, superclass, proto, attributes); 8701 } 8702 else 8703 objc_start_class_implementation (id1, superclass); 8704 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) 8705 c_parser_objc_class_instance_variables (parser); 8706 if (iface_p) 8707 { 8708 objc_continue_interface (); 8709 c_parser_objc_methodprotolist (parser); 8710 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); 8711 objc_finish_interface (); 8712 } 8713 else 8714 { 8715 objc_continue_implementation (); 8716 return; 8717 } 8718 } 8719 8720 /* Parse objc-class-instance-variables. 8721 8722 objc-class-instance-variables: 8723 { objc-instance-variable-decl-list[opt] } 8724 8725 objc-instance-variable-decl-list: 8726 objc-visibility-spec 8727 objc-instance-variable-decl ; 8728 ; 8729 objc-instance-variable-decl-list objc-visibility-spec 8730 objc-instance-variable-decl-list objc-instance-variable-decl ; 8731 objc-instance-variable-decl-list ; 8732 8733 objc-visibility-spec: 8734 @private 8735 @protected 8736 @public 8737 8738 objc-instance-variable-decl: 8739 struct-declaration 8740 */ 8741 8742 static void 8743 c_parser_objc_class_instance_variables (c_parser *parser) 8744 { 8745 gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE)); 8746 c_parser_consume_token (parser); 8747 while (c_parser_next_token_is_not (parser, CPP_EOF)) 8748 { 8749 tree decls; 8750 /* Parse any stray semicolon. */ 8751 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 8752 { 8753 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, 8754 "extra semicolon"); 8755 c_parser_consume_token (parser); 8756 continue; 8757 } 8758 /* Stop if at the end of the instance variables. */ 8759 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) 8760 { 8761 c_parser_consume_token (parser); 8762 break; 8763 } 8764 /* Parse any objc-visibility-spec. */ 8765 if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE)) 8766 { 8767 c_parser_consume_token (parser); 8768 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE); 8769 continue; 8770 } 8771 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED)) 8772 { 8773 c_parser_consume_token (parser); 8774 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED); 8775 continue; 8776 } 8777 else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC)) 8778 { 8779 c_parser_consume_token (parser); 8780 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC); 8781 continue; 8782 } 8783 else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE)) 8784 { 8785 c_parser_consume_token (parser); 8786 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE); 8787 continue; 8788 } 8789 else if (c_parser_next_token_is (parser, CPP_PRAGMA)) 8790 { 8791 c_parser_pragma (parser, pragma_external, NULL); 8792 continue; 8793 } 8794 8795 /* Parse some comma-separated declarations. */ 8796 decls = c_parser_struct_declaration (parser); 8797 if (decls == NULL) 8798 { 8799 /* There is a syntax error. We want to skip the offending 8800 tokens up to the next ';' (included) or '}' 8801 (excluded). */ 8802 8803 /* First, skip manually a ')' or ']'. This is because they 8804 reduce the nesting level, so c_parser_skip_until_found() 8805 wouldn't be able to skip past them. */ 8806 c_token *token = c_parser_peek_token (parser); 8807 if (token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE) 8808 c_parser_consume_token (parser); 8809 8810 /* Then, do the standard skipping. */ 8811 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); 8812 8813 /* We hopefully recovered. Start normal parsing again. */ 8814 parser->error = false; 8815 continue; 8816 } 8817 else 8818 { 8819 /* Comma-separated instance variables are chained together 8820 in reverse order; add them one by one. */ 8821 tree ivar = nreverse (decls); 8822 for (; ivar; ivar = DECL_CHAIN (ivar)) 8823 objc_add_instance_variable (copy_node (ivar)); 8824 } 8825 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 8826 } 8827 } 8828 8829 /* Parse an objc-class-declaration. 8830 8831 objc-class-declaration: 8832 @class identifier-list ; 8833 */ 8834 8835 static void 8836 c_parser_objc_class_declaration (c_parser *parser) 8837 { 8838 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS)); 8839 c_parser_consume_token (parser); 8840 /* Any identifiers, including those declared as type names, are OK 8841 here. */ 8842 while (true) 8843 { 8844 tree id; 8845 if (c_parser_next_token_is_not (parser, CPP_NAME)) 8846 { 8847 c_parser_error (parser, "expected identifier"); 8848 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); 8849 parser->error = false; 8850 return; 8851 } 8852 id = c_parser_peek_token (parser)->value; 8853 objc_declare_class (id); 8854 c_parser_consume_token (parser); 8855 if (c_parser_next_token_is (parser, CPP_COMMA)) 8856 c_parser_consume_token (parser); 8857 else 8858 break; 8859 } 8860 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 8861 } 8862 8863 /* Parse an objc-alias-declaration. 8864 8865 objc-alias-declaration: 8866 @compatibility_alias identifier identifier ; 8867 */ 8868 8869 static void 8870 c_parser_objc_alias_declaration (c_parser *parser) 8871 { 8872 tree id1, id2; 8873 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS)); 8874 c_parser_consume_token (parser); 8875 if (c_parser_next_token_is_not (parser, CPP_NAME)) 8876 { 8877 c_parser_error (parser, "expected identifier"); 8878 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); 8879 return; 8880 } 8881 id1 = c_parser_peek_token (parser)->value; 8882 c_parser_consume_token (parser); 8883 if (c_parser_next_token_is_not (parser, CPP_NAME)) 8884 { 8885 c_parser_error (parser, "expected identifier"); 8886 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); 8887 return; 8888 } 8889 id2 = c_parser_peek_token (parser)->value; 8890 c_parser_consume_token (parser); 8891 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 8892 objc_declare_alias (id1, id2); 8893 } 8894 8895 /* Parse an objc-protocol-definition. 8896 8897 objc-protocol-definition: 8898 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end 8899 @protocol identifier-list ; 8900 8901 "@protocol identifier ;" should be resolved as "@protocol 8902 identifier-list ;": objc-methodprotolist may not start with a 8903 semicolon in the first alternative if objc-protocol-refs are 8904 omitted. */ 8905 8906 static void 8907 c_parser_objc_protocol_definition (c_parser *parser, tree attributes) 8908 { 8909 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL)); 8910 8911 c_parser_consume_token (parser); 8912 if (c_parser_next_token_is_not (parser, CPP_NAME)) 8913 { 8914 c_parser_error (parser, "expected identifier"); 8915 return; 8916 } 8917 if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA 8918 || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON) 8919 { 8920 /* Any identifiers, including those declared as type names, are 8921 OK here. */ 8922 while (true) 8923 { 8924 tree id; 8925 if (c_parser_next_token_is_not (parser, CPP_NAME)) 8926 { 8927 c_parser_error (parser, "expected identifier"); 8928 break; 8929 } 8930 id = c_parser_peek_token (parser)->value; 8931 objc_declare_protocol (id, attributes); 8932 c_parser_consume_token (parser); 8933 if (c_parser_next_token_is (parser, CPP_COMMA)) 8934 c_parser_consume_token (parser); 8935 else 8936 break; 8937 } 8938 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 8939 } 8940 else 8941 { 8942 tree id = c_parser_peek_token (parser)->value; 8943 tree proto = NULL_TREE; 8944 c_parser_consume_token (parser); 8945 if (c_parser_next_token_is (parser, CPP_LESS)) 8946 proto = c_parser_objc_protocol_refs (parser); 8947 parser->objc_pq_context = true; 8948 objc_start_protocol (id, proto, attributes); 8949 c_parser_objc_methodprotolist (parser); 8950 c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); 8951 parser->objc_pq_context = false; 8952 objc_finish_interface (); 8953 } 8954 } 8955 8956 /* Parse an objc-method-type. 8957 8958 objc-method-type: 8959 + 8960 - 8961 8962 Return true if it is a class method (+) and false if it is 8963 an instance method (-). 8964 */ 8965 static inline bool 8966 c_parser_objc_method_type (c_parser *parser) 8967 { 8968 switch (c_parser_peek_token (parser)->type) 8969 { 8970 case CPP_PLUS: 8971 c_parser_consume_token (parser); 8972 return true; 8973 case CPP_MINUS: 8974 c_parser_consume_token (parser); 8975 return false; 8976 default: 8977 gcc_unreachable (); 8978 } 8979 } 8980 8981 /* Parse an objc-method-definition. 8982 8983 objc-method-definition: 8984 objc-method-type objc-method-decl ;[opt] compound-statement 8985 */ 8986 8987 static void 8988 c_parser_objc_method_definition (c_parser *parser) 8989 { 8990 bool is_class_method = c_parser_objc_method_type (parser); 8991 tree decl, attributes = NULL_TREE, expr = NULL_TREE; 8992 parser->objc_pq_context = true; 8993 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes, 8994 &expr); 8995 if (decl == error_mark_node) 8996 return; /* Bail here. */ 8997 8998 if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 8999 { 9000 c_parser_consume_token (parser); 9001 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, 9002 "extra semicolon in method definition specified"); 9003 } 9004 9005 if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE)) 9006 { 9007 c_parser_error (parser, "expected %<{%>"); 9008 return; 9009 } 9010 9011 parser->objc_pq_context = false; 9012 if (objc_start_method_definition (is_class_method, decl, attributes, expr)) 9013 { 9014 add_stmt (c_parser_compound_statement (parser)); 9015 objc_finish_method_definition (current_function_decl); 9016 } 9017 else 9018 { 9019 /* This code is executed when we find a method definition 9020 outside of an @implementation context (or invalid for other 9021 reasons). Parse the method (to keep going) but do not emit 9022 any code. 9023 */ 9024 c_parser_compound_statement (parser); 9025 } 9026 } 9027 9028 /* Parse an objc-methodprotolist. 9029 9030 objc-methodprotolist: 9031 empty 9032 objc-methodprotolist objc-methodproto 9033 objc-methodprotolist declaration 9034 objc-methodprotolist ; 9035 @optional 9036 @required 9037 9038 The declaration is a data definition, which may be missing 9039 declaration specifiers under the same rules and diagnostics as 9040 other data definitions outside functions, and the stray semicolon 9041 is diagnosed the same way as a stray semicolon outside a 9042 function. */ 9043 9044 static void 9045 c_parser_objc_methodprotolist (c_parser *parser) 9046 { 9047 while (true) 9048 { 9049 /* The list is terminated by @end. */ 9050 switch (c_parser_peek_token (parser)->type) 9051 { 9052 case CPP_SEMICOLON: 9053 pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, 9054 "ISO C does not allow extra %<;%> outside of a function"); 9055 c_parser_consume_token (parser); 9056 break; 9057 case CPP_PLUS: 9058 case CPP_MINUS: 9059 c_parser_objc_methodproto (parser); 9060 break; 9061 case CPP_PRAGMA: 9062 c_parser_pragma (parser, pragma_external, NULL); 9063 break; 9064 case CPP_EOF: 9065 return; 9066 default: 9067 if (c_parser_next_token_is_keyword (parser, RID_AT_END)) 9068 return; 9069 else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY)) 9070 c_parser_objc_at_property_declaration (parser); 9071 else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL)) 9072 { 9073 objc_set_method_opt (true); 9074 c_parser_consume_token (parser); 9075 } 9076 else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED)) 9077 { 9078 objc_set_method_opt (false); 9079 c_parser_consume_token (parser); 9080 } 9081 else 9082 c_parser_declaration_or_fndef (parser, false, false, true, 9083 false, true, NULL, vNULL); 9084 break; 9085 } 9086 } 9087 } 9088 9089 /* Parse an objc-methodproto. 9090 9091 objc-methodproto: 9092 objc-method-type objc-method-decl ; 9093 */ 9094 9095 static void 9096 c_parser_objc_methodproto (c_parser *parser) 9097 { 9098 bool is_class_method = c_parser_objc_method_type (parser); 9099 tree decl, attributes = NULL_TREE; 9100 9101 /* Remember protocol qualifiers in prototypes. */ 9102 parser->objc_pq_context = true; 9103 decl = c_parser_objc_method_decl (parser, is_class_method, &attributes, 9104 NULL); 9105 /* Forget protocol qualifiers now. */ 9106 parser->objc_pq_context = false; 9107 9108 /* Do not allow the presence of attributes to hide an erroneous 9109 method implementation in the interface section. */ 9110 if (!c_parser_next_token_is (parser, CPP_SEMICOLON)) 9111 { 9112 c_parser_error (parser, "expected %<;%>"); 9113 return; 9114 } 9115 9116 if (decl != error_mark_node) 9117 objc_add_method_declaration (is_class_method, decl, attributes); 9118 9119 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 9120 } 9121 9122 /* If we are at a position that method attributes may be present, check that 9123 there are not any parsed already (a syntax error) and then collect any 9124 specified at the current location. Finally, if new attributes were present, 9125 check that the next token is legal ( ';' for decls and '{' for defs). */ 9126 9127 static bool 9128 c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes) 9129 { 9130 bool bad = false; 9131 if (*attributes) 9132 { 9133 c_parser_error (parser, 9134 "method attributes must be specified at the end only"); 9135 *attributes = NULL_TREE; 9136 bad = true; 9137 } 9138 9139 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) 9140 *attributes = c_parser_attributes (parser); 9141 9142 /* If there were no attributes here, just report any earlier error. */ 9143 if (*attributes == NULL_TREE || bad) 9144 return bad; 9145 9146 /* If the attributes are followed by a ; or {, then just report any earlier 9147 error. */ 9148 if (c_parser_next_token_is (parser, CPP_SEMICOLON) 9149 || c_parser_next_token_is (parser, CPP_OPEN_BRACE)) 9150 return bad; 9151 9152 /* We've got attributes, but not at the end. */ 9153 c_parser_error (parser, 9154 "expected %<;%> or %<{%> after method attribute definition"); 9155 return true; 9156 } 9157 9158 /* Parse an objc-method-decl. 9159 9160 objc-method-decl: 9161 ( objc-type-name ) objc-selector 9162 objc-selector 9163 ( objc-type-name ) objc-keyword-selector objc-optparmlist 9164 objc-keyword-selector objc-optparmlist 9165 attributes 9166 9167 objc-keyword-selector: 9168 objc-keyword-decl 9169 objc-keyword-selector objc-keyword-decl 9170 9171 objc-keyword-decl: 9172 objc-selector : ( objc-type-name ) identifier 9173 objc-selector : identifier 9174 : ( objc-type-name ) identifier 9175 : identifier 9176 9177 objc-optparmlist: 9178 objc-optparms objc-optellipsis 9179 9180 objc-optparms: 9181 empty 9182 objc-opt-parms , parameter-declaration 9183 9184 objc-optellipsis: 9185 empty 9186 , ... 9187 */ 9188 9189 static tree 9190 c_parser_objc_method_decl (c_parser *parser, bool is_class_method, 9191 tree *attributes, tree *expr) 9192 { 9193 tree type = NULL_TREE; 9194 tree sel; 9195 tree parms = NULL_TREE; 9196 bool ellipsis = false; 9197 bool attr_err = false; 9198 9199 *attributes = NULL_TREE; 9200 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) 9201 { 9202 c_parser_consume_token (parser); 9203 type = c_parser_objc_type_name (parser); 9204 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 9205 } 9206 sel = c_parser_objc_selector (parser); 9207 /* If there is no selector, or a colon follows, we have an 9208 objc-keyword-selector. If there is a selector, and a colon does 9209 not follow, that selector ends the objc-method-decl. */ 9210 if (!sel || c_parser_next_token_is (parser, CPP_COLON)) 9211 { 9212 tree tsel = sel; 9213 tree list = NULL_TREE; 9214 while (true) 9215 { 9216 tree atype = NULL_TREE, id, keyworddecl; 9217 tree param_attr = NULL_TREE; 9218 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) 9219 break; 9220 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) 9221 { 9222 c_parser_consume_token (parser); 9223 atype = c_parser_objc_type_name (parser); 9224 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 9225 "expected %<)%>"); 9226 } 9227 /* New ObjC allows attributes on method parameters. */ 9228 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) 9229 param_attr = c_parser_attributes (parser); 9230 if (c_parser_next_token_is_not (parser, CPP_NAME)) 9231 { 9232 c_parser_error (parser, "expected identifier"); 9233 return error_mark_node; 9234 } 9235 id = c_parser_peek_token (parser)->value; 9236 c_parser_consume_token (parser); 9237 keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr); 9238 list = chainon (list, keyworddecl); 9239 tsel = c_parser_objc_selector (parser); 9240 if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON)) 9241 break; 9242 } 9243 9244 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ; 9245 9246 /* Parse the optional parameter list. Optional Objective-C 9247 method parameters follow the C syntax, and may include '...' 9248 to denote a variable number of arguments. */ 9249 parms = make_node (TREE_LIST); 9250 while (c_parser_next_token_is (parser, CPP_COMMA)) 9251 { 9252 struct c_parm *parm; 9253 c_parser_consume_token (parser); 9254 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) 9255 { 9256 ellipsis = true; 9257 c_parser_consume_token (parser); 9258 attr_err |= c_parser_objc_maybe_method_attributes 9259 (parser, attributes) ; 9260 break; 9261 } 9262 parm = c_parser_parameter_declaration (parser, NULL_TREE); 9263 if (parm == NULL) 9264 break; 9265 parms = chainon (parms, 9266 build_tree_list (NULL_TREE, grokparm (parm, expr))); 9267 } 9268 sel = list; 9269 } 9270 else 9271 attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ; 9272 9273 if (sel == NULL) 9274 { 9275 c_parser_error (parser, "objective-c method declaration is expected"); 9276 return error_mark_node; 9277 } 9278 9279 if (attr_err) 9280 return error_mark_node; 9281 9282 return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis); 9283 } 9284 9285 /* Parse an objc-type-name. 9286 9287 objc-type-name: 9288 objc-type-qualifiers[opt] type-name 9289 objc-type-qualifiers[opt] 9290 9291 objc-type-qualifiers: 9292 objc-type-qualifier 9293 objc-type-qualifiers objc-type-qualifier 9294 9295 objc-type-qualifier: one of 9296 in out inout bycopy byref oneway 9297 */ 9298 9299 static tree 9300 c_parser_objc_type_name (c_parser *parser) 9301 { 9302 tree quals = NULL_TREE; 9303 struct c_type_name *type_name = NULL; 9304 tree type = NULL_TREE; 9305 while (true) 9306 { 9307 c_token *token = c_parser_peek_token (parser); 9308 if (token->type == CPP_KEYWORD 9309 && (token->keyword == RID_IN 9310 || token->keyword == RID_OUT 9311 || token->keyword == RID_INOUT 9312 || token->keyword == RID_BYCOPY 9313 || token->keyword == RID_BYREF 9314 || token->keyword == RID_ONEWAY)) 9315 { 9316 quals = chainon (build_tree_list (NULL_TREE, token->value), quals); 9317 c_parser_consume_token (parser); 9318 } 9319 else 9320 break; 9321 } 9322 if (c_parser_next_tokens_start_typename (parser, cla_prefer_type)) 9323 type_name = c_parser_type_name (parser); 9324 if (type_name) 9325 type = groktypename (type_name, NULL, NULL); 9326 9327 /* If the type is unknown, and error has already been produced and 9328 we need to recover from the error. In that case, use NULL_TREE 9329 for the type, as if no type had been specified; this will use the 9330 default type ('id') which is good for error recovery. */ 9331 if (type == error_mark_node) 9332 type = NULL_TREE; 9333 9334 return build_tree_list (quals, type); 9335 } 9336 9337 /* Parse objc-protocol-refs. 9338 9339 objc-protocol-refs: 9340 < identifier-list > 9341 */ 9342 9343 static tree 9344 c_parser_objc_protocol_refs (c_parser *parser) 9345 { 9346 tree list = NULL_TREE; 9347 gcc_assert (c_parser_next_token_is (parser, CPP_LESS)); 9348 c_parser_consume_token (parser); 9349 /* Any identifiers, including those declared as type names, are OK 9350 here. */ 9351 while (true) 9352 { 9353 tree id; 9354 if (c_parser_next_token_is_not (parser, CPP_NAME)) 9355 { 9356 c_parser_error (parser, "expected identifier"); 9357 break; 9358 } 9359 id = c_parser_peek_token (parser)->value; 9360 list = chainon (list, build_tree_list (NULL_TREE, id)); 9361 c_parser_consume_token (parser); 9362 if (c_parser_next_token_is (parser, CPP_COMMA)) 9363 c_parser_consume_token (parser); 9364 else 9365 break; 9366 } 9367 c_parser_require (parser, CPP_GREATER, "expected %<>%>"); 9368 return list; 9369 } 9370 9371 /* Parse an objc-try-catch-finally-statement. 9372 9373 objc-try-catch-finally-statement: 9374 @try compound-statement objc-catch-list[opt] 9375 @try compound-statement objc-catch-list[opt] @finally compound-statement 9376 9377 objc-catch-list: 9378 @catch ( objc-catch-parameter-declaration ) compound-statement 9379 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement 9380 9381 objc-catch-parameter-declaration: 9382 parameter-declaration 9383 '...' 9384 9385 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS. 9386 9387 PS: This function is identical to cp_parser_objc_try_catch_finally_statement 9388 for C++. Keep them in sync. */ 9389 9390 static void 9391 c_parser_objc_try_catch_finally_statement (c_parser *parser) 9392 { 9393 location_t location; 9394 tree stmt; 9395 9396 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY)); 9397 c_parser_consume_token (parser); 9398 location = c_parser_peek_token (parser)->location; 9399 objc_maybe_warn_exceptions (location); 9400 stmt = c_parser_compound_statement (parser); 9401 objc_begin_try_stmt (location, stmt); 9402 9403 while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH)) 9404 { 9405 struct c_parm *parm; 9406 tree parameter_declaration = error_mark_node; 9407 bool seen_open_paren = false; 9408 9409 c_parser_consume_token (parser); 9410 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 9411 seen_open_paren = true; 9412 if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) 9413 { 9414 /* We have "@catch (...)" (where the '...' are literally 9415 what is in the code). Skip the '...'. 9416 parameter_declaration is set to NULL_TREE, and 9417 objc_being_catch_clauses() knows that that means 9418 '...'. */ 9419 c_parser_consume_token (parser); 9420 parameter_declaration = NULL_TREE; 9421 } 9422 else 9423 { 9424 /* We have "@catch (NSException *exception)" or something 9425 like that. Parse the parameter declaration. */ 9426 parm = c_parser_parameter_declaration (parser, NULL_TREE); 9427 if (parm == NULL) 9428 parameter_declaration = error_mark_node; 9429 else 9430 parameter_declaration = grokparm (parm, NULL); 9431 } 9432 if (seen_open_paren) 9433 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 9434 else 9435 { 9436 /* If there was no open parenthesis, we are recovering from 9437 an error, and we are trying to figure out what mistake 9438 the user has made. */ 9439 9440 /* If there is an immediate closing parenthesis, the user 9441 probably forgot the opening one (ie, they typed "@catch 9442 NSException *e)". Parse the closing parenthesis and keep 9443 going. */ 9444 if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) 9445 c_parser_consume_token (parser); 9446 9447 /* If these is no immediate closing parenthesis, the user 9448 probably doesn't know that parenthesis are required at 9449 all (ie, they typed "@catch NSException *e"). So, just 9450 forget about the closing parenthesis and keep going. */ 9451 } 9452 objc_begin_catch_clause (parameter_declaration); 9453 if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) 9454 c_parser_compound_statement_nostart (parser); 9455 objc_finish_catch_clause (); 9456 } 9457 if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY)) 9458 { 9459 c_parser_consume_token (parser); 9460 location = c_parser_peek_token (parser)->location; 9461 stmt = c_parser_compound_statement (parser); 9462 objc_build_finally_clause (location, stmt); 9463 } 9464 objc_finish_try_stmt (); 9465 } 9466 9467 /* Parse an objc-synchronized-statement. 9468 9469 objc-synchronized-statement: 9470 @synchronized ( expression ) compound-statement 9471 */ 9472 9473 static void 9474 c_parser_objc_synchronized_statement (c_parser *parser) 9475 { 9476 location_t loc; 9477 tree expr, stmt; 9478 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED)); 9479 c_parser_consume_token (parser); 9480 loc = c_parser_peek_token (parser)->location; 9481 objc_maybe_warn_exceptions (loc); 9482 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 9483 { 9484 struct c_expr ce = c_parser_expression (parser); 9485 ce = convert_lvalue_to_rvalue (loc, ce, false, false); 9486 expr = ce.value; 9487 expr = c_fully_fold (expr, false, NULL); 9488 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 9489 } 9490 else 9491 expr = error_mark_node; 9492 stmt = c_parser_compound_statement (parser); 9493 objc_build_synchronized (loc, expr, stmt); 9494 } 9495 9496 /* Parse an objc-selector; return NULL_TREE without an error if the 9497 next token is not an objc-selector. 9498 9499 objc-selector: 9500 identifier 9501 one of 9502 enum struct union if else while do for switch case default 9503 break continue return goto asm sizeof typeof __alignof 9504 unsigned long const short volatile signed restrict _Complex 9505 in out inout bycopy byref oneway int char float double void _Bool 9506 _Atomic 9507 9508 ??? Why this selection of keywords but not, for example, storage 9509 class specifiers? */ 9510 9511 static tree 9512 c_parser_objc_selector (c_parser *parser) 9513 { 9514 c_token *token = c_parser_peek_token (parser); 9515 tree value = token->value; 9516 if (token->type == CPP_NAME) 9517 { 9518 c_parser_consume_token (parser); 9519 return value; 9520 } 9521 if (token->type != CPP_KEYWORD) 9522 return NULL_TREE; 9523 switch (token->keyword) 9524 { 9525 case RID_ENUM: 9526 case RID_STRUCT: 9527 case RID_UNION: 9528 case RID_IF: 9529 case RID_ELSE: 9530 case RID_WHILE: 9531 case RID_DO: 9532 case RID_FOR: 9533 case RID_SWITCH: 9534 case RID_CASE: 9535 case RID_DEFAULT: 9536 case RID_BREAK: 9537 case RID_CONTINUE: 9538 case RID_RETURN: 9539 case RID_GOTO: 9540 case RID_ASM: 9541 case RID_SIZEOF: 9542 case RID_TYPEOF: 9543 case RID_ALIGNOF: 9544 case RID_UNSIGNED: 9545 case RID_LONG: 9546 case RID_CONST: 9547 case RID_SHORT: 9548 case RID_VOLATILE: 9549 case RID_SIGNED: 9550 case RID_RESTRICT: 9551 case RID_COMPLEX: 9552 case RID_IN: 9553 case RID_OUT: 9554 case RID_INOUT: 9555 case RID_BYCOPY: 9556 case RID_BYREF: 9557 case RID_ONEWAY: 9558 case RID_INT: 9559 case RID_CHAR: 9560 case RID_FLOAT: 9561 case RID_DOUBLE: 9562 case RID_VOID: 9563 case RID_BOOL: 9564 case RID_ATOMIC: 9565 case RID_AUTO_TYPE: 9566 case RID_INT_N_0: 9567 case RID_INT_N_1: 9568 case RID_INT_N_2: 9569 case RID_INT_N_3: 9570 c_parser_consume_token (parser); 9571 return value; 9572 default: 9573 return NULL_TREE; 9574 } 9575 } 9576 9577 /* Parse an objc-selector-arg. 9578 9579 objc-selector-arg: 9580 objc-selector 9581 objc-keywordname-list 9582 9583 objc-keywordname-list: 9584 objc-keywordname 9585 objc-keywordname-list objc-keywordname 9586 9587 objc-keywordname: 9588 objc-selector : 9589 : 9590 */ 9591 9592 static tree 9593 c_parser_objc_selector_arg (c_parser *parser) 9594 { 9595 tree sel = c_parser_objc_selector (parser); 9596 tree list = NULL_TREE; 9597 if (sel && c_parser_next_token_is_not (parser, CPP_COLON)) 9598 return sel; 9599 while (true) 9600 { 9601 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) 9602 return list; 9603 list = chainon (list, build_tree_list (sel, NULL_TREE)); 9604 sel = c_parser_objc_selector (parser); 9605 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON)) 9606 break; 9607 } 9608 return list; 9609 } 9610 9611 /* Parse an objc-receiver. 9612 9613 objc-receiver: 9614 expression 9615 class-name 9616 type-name 9617 */ 9618 9619 static tree 9620 c_parser_objc_receiver (c_parser *parser) 9621 { 9622 location_t loc = c_parser_peek_token (parser)->location; 9623 9624 if (c_parser_peek_token (parser)->type == CPP_NAME 9625 && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME 9626 || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)) 9627 { 9628 tree id = c_parser_peek_token (parser)->value; 9629 c_parser_consume_token (parser); 9630 return objc_get_class_reference (id); 9631 } 9632 struct c_expr ce = c_parser_expression (parser); 9633 ce = convert_lvalue_to_rvalue (loc, ce, false, false); 9634 return c_fully_fold (ce.value, false, NULL); 9635 } 9636 9637 /* Parse objc-message-args. 9638 9639 objc-message-args: 9640 objc-selector 9641 objc-keywordarg-list 9642 9643 objc-keywordarg-list: 9644 objc-keywordarg 9645 objc-keywordarg-list objc-keywordarg 9646 9647 objc-keywordarg: 9648 objc-selector : objc-keywordexpr 9649 : objc-keywordexpr 9650 */ 9651 9652 static tree 9653 c_parser_objc_message_args (c_parser *parser) 9654 { 9655 tree sel = c_parser_objc_selector (parser); 9656 tree list = NULL_TREE; 9657 if (sel && c_parser_next_token_is_not (parser, CPP_COLON)) 9658 return sel; 9659 while (true) 9660 { 9661 tree keywordexpr; 9662 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) 9663 return error_mark_node; 9664 keywordexpr = c_parser_objc_keywordexpr (parser); 9665 list = chainon (list, build_tree_list (sel, keywordexpr)); 9666 sel = c_parser_objc_selector (parser); 9667 if (!sel && c_parser_next_token_is_not (parser, CPP_COLON)) 9668 break; 9669 } 9670 return list; 9671 } 9672 9673 /* Parse an objc-keywordexpr. 9674 9675 objc-keywordexpr: 9676 nonempty-expr-list 9677 */ 9678 9679 static tree 9680 c_parser_objc_keywordexpr (c_parser *parser) 9681 { 9682 tree ret; 9683 vec<tree, va_gc> *expr_list = c_parser_expr_list (parser, true, true, 9684 NULL, NULL, NULL, NULL); 9685 if (vec_safe_length (expr_list) == 1) 9686 { 9687 /* Just return the expression, remove a level of 9688 indirection. */ 9689 ret = (*expr_list)[0]; 9690 } 9691 else 9692 { 9693 /* We have a comma expression, we will collapse later. */ 9694 ret = build_tree_list_vec (expr_list); 9695 } 9696 release_tree_vector (expr_list); 9697 return ret; 9698 } 9699 9700 /* A check, needed in several places, that ObjC interface, implementation or 9701 method definitions are not prefixed by incorrect items. */ 9702 static bool 9703 c_parser_objc_diagnose_bad_element_prefix (c_parser *parser, 9704 struct c_declspecs *specs) 9705 { 9706 if (!specs->declspecs_seen_p || specs->non_sc_seen_p 9707 || specs->typespec_kind != ctsk_none) 9708 { 9709 c_parser_error (parser, 9710 "no type or storage class may be specified here,"); 9711 c_parser_skip_to_end_of_block_or_statement (parser); 9712 return true; 9713 } 9714 return false; 9715 } 9716 9717 /* Parse an Objective-C @property declaration. The syntax is: 9718 9719 objc-property-declaration: 9720 '@property' objc-property-attributes[opt] struct-declaration ; 9721 9722 objc-property-attributes: 9723 '(' objc-property-attribute-list ')' 9724 9725 objc-property-attribute-list: 9726 objc-property-attribute 9727 objc-property-attribute-list, objc-property-attribute 9728 9729 objc-property-attribute 9730 'getter' = identifier 9731 'setter' = identifier 9732 'readonly' 9733 'readwrite' 9734 'assign' 9735 'retain' 9736 'copy' 9737 'nonatomic' 9738 9739 For example: 9740 @property NSString *name; 9741 @property (readonly) id object; 9742 @property (retain, nonatomic, getter=getTheName) id name; 9743 @property int a, b, c; 9744 9745 PS: This function is identical to cp_parser_objc_at_propery_declaration 9746 for C++. Keep them in sync. */ 9747 static void 9748 c_parser_objc_at_property_declaration (c_parser *parser) 9749 { 9750 /* The following variables hold the attributes of the properties as 9751 parsed. They are 'false' or 'NULL_TREE' if the attribute was not 9752 seen. When we see an attribute, we set them to 'true' (if they 9753 are boolean properties) or to the identifier (if they have an 9754 argument, ie, for getter and setter). Note that here we only 9755 parse the list of attributes, check the syntax and accumulate the 9756 attributes that we find. objc_add_property_declaration() will 9757 then process the information. */ 9758 bool property_assign = false; 9759 bool property_copy = false; 9760 tree property_getter_ident = NULL_TREE; 9761 bool property_nonatomic = false; 9762 bool property_readonly = false; 9763 bool property_readwrite = false; 9764 bool property_retain = false; 9765 tree property_setter_ident = NULL_TREE; 9766 9767 /* 'properties' is the list of properties that we read. Usually a 9768 single one, but maybe more (eg, in "@property int a, b, c;" there 9769 are three). */ 9770 tree properties; 9771 location_t loc; 9772 9773 loc = c_parser_peek_token (parser)->location; 9774 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY)); 9775 9776 c_parser_consume_token (parser); /* Eat '@property'. */ 9777 9778 /* Parse the optional attribute list... */ 9779 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) 9780 { 9781 /* Eat the '(' */ 9782 c_parser_consume_token (parser); 9783 9784 /* Property attribute keywords are valid now. */ 9785 parser->objc_property_attr_context = true; 9786 9787 while (true) 9788 { 9789 bool syntax_error = false; 9790 c_token *token = c_parser_peek_token (parser); 9791 enum rid keyword; 9792 9793 if (token->type != CPP_KEYWORD) 9794 { 9795 if (token->type == CPP_CLOSE_PAREN) 9796 c_parser_error (parser, "expected identifier"); 9797 else 9798 { 9799 c_parser_consume_token (parser); 9800 c_parser_error (parser, "unknown property attribute"); 9801 } 9802 break; 9803 } 9804 keyword = token->keyword; 9805 c_parser_consume_token (parser); 9806 switch (keyword) 9807 { 9808 case RID_ASSIGN: property_assign = true; break; 9809 case RID_COPY: property_copy = true; break; 9810 case RID_NONATOMIC: property_nonatomic = true; break; 9811 case RID_READONLY: property_readonly = true; break; 9812 case RID_READWRITE: property_readwrite = true; break; 9813 case RID_RETAIN: property_retain = true; break; 9814 9815 case RID_GETTER: 9816 case RID_SETTER: 9817 if (c_parser_next_token_is_not (parser, CPP_EQ)) 9818 { 9819 if (keyword == RID_GETTER) 9820 c_parser_error (parser, 9821 "missing %<=%> (after %<getter%> attribute)"); 9822 else 9823 c_parser_error (parser, 9824 "missing %<=%> (after %<setter%> attribute)"); 9825 syntax_error = true; 9826 break; 9827 } 9828 c_parser_consume_token (parser); /* eat the = */ 9829 if (c_parser_next_token_is_not (parser, CPP_NAME)) 9830 { 9831 c_parser_error (parser, "expected identifier"); 9832 syntax_error = true; 9833 break; 9834 } 9835 if (keyword == RID_SETTER) 9836 { 9837 if (property_setter_ident != NULL_TREE) 9838 c_parser_error (parser, "the %<setter%> attribute may only be specified once"); 9839 else 9840 property_setter_ident = c_parser_peek_token (parser)->value; 9841 c_parser_consume_token (parser); 9842 if (c_parser_next_token_is_not (parser, CPP_COLON)) 9843 c_parser_error (parser, "setter name must terminate with %<:%>"); 9844 else 9845 c_parser_consume_token (parser); 9846 } 9847 else 9848 { 9849 if (property_getter_ident != NULL_TREE) 9850 c_parser_error (parser, "the %<getter%> attribute may only be specified once"); 9851 else 9852 property_getter_ident = c_parser_peek_token (parser)->value; 9853 c_parser_consume_token (parser); 9854 } 9855 break; 9856 default: 9857 c_parser_error (parser, "unknown property attribute"); 9858 syntax_error = true; 9859 break; 9860 } 9861 9862 if (syntax_error) 9863 break; 9864 9865 if (c_parser_next_token_is (parser, CPP_COMMA)) 9866 c_parser_consume_token (parser); 9867 else 9868 break; 9869 } 9870 parser->objc_property_attr_context = false; 9871 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 9872 } 9873 /* ... and the property declaration(s). */ 9874 properties = c_parser_struct_declaration (parser); 9875 9876 if (properties == error_mark_node) 9877 { 9878 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); 9879 parser->error = false; 9880 return; 9881 } 9882 9883 if (properties == NULL_TREE) 9884 c_parser_error (parser, "expected identifier"); 9885 else 9886 { 9887 /* Comma-separated properties are chained together in 9888 reverse order; add them one by one. */ 9889 properties = nreverse (properties); 9890 9891 for (; properties; properties = TREE_CHAIN (properties)) 9892 objc_add_property_declaration (loc, copy_node (properties), 9893 property_readonly, property_readwrite, 9894 property_assign, property_retain, 9895 property_copy, property_nonatomic, 9896 property_getter_ident, property_setter_ident); 9897 } 9898 9899 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 9900 parser->error = false; 9901 } 9902 9903 /* Parse an Objective-C @synthesize declaration. The syntax is: 9904 9905 objc-synthesize-declaration: 9906 @synthesize objc-synthesize-identifier-list ; 9907 9908 objc-synthesize-identifier-list: 9909 objc-synthesize-identifier 9910 objc-synthesize-identifier-list, objc-synthesize-identifier 9911 9912 objc-synthesize-identifier 9913 identifier 9914 identifier = identifier 9915 9916 For example: 9917 @synthesize MyProperty; 9918 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty; 9919 9920 PS: This function is identical to cp_parser_objc_at_synthesize_declaration 9921 for C++. Keep them in sync. 9922 */ 9923 static void 9924 c_parser_objc_at_synthesize_declaration (c_parser *parser) 9925 { 9926 tree list = NULL_TREE; 9927 location_t loc; 9928 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE)); 9929 loc = c_parser_peek_token (parser)->location; 9930 9931 c_parser_consume_token (parser); 9932 while (true) 9933 { 9934 tree property, ivar; 9935 if (c_parser_next_token_is_not (parser, CPP_NAME)) 9936 { 9937 c_parser_error (parser, "expected identifier"); 9938 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); 9939 /* Once we find the semicolon, we can resume normal parsing. 9940 We have to reset parser->error manually because 9941 c_parser_skip_until_found() won't reset it for us if the 9942 next token is precisely a semicolon. */ 9943 parser->error = false; 9944 return; 9945 } 9946 property = c_parser_peek_token (parser)->value; 9947 c_parser_consume_token (parser); 9948 if (c_parser_next_token_is (parser, CPP_EQ)) 9949 { 9950 c_parser_consume_token (parser); 9951 if (c_parser_next_token_is_not (parser, CPP_NAME)) 9952 { 9953 c_parser_error (parser, "expected identifier"); 9954 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); 9955 parser->error = false; 9956 return; 9957 } 9958 ivar = c_parser_peek_token (parser)->value; 9959 c_parser_consume_token (parser); 9960 } 9961 else 9962 ivar = NULL_TREE; 9963 list = chainon (list, build_tree_list (ivar, property)); 9964 if (c_parser_next_token_is (parser, CPP_COMMA)) 9965 c_parser_consume_token (parser); 9966 else 9967 break; 9968 } 9969 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 9970 objc_add_synthesize_declaration (loc, list); 9971 } 9972 9973 /* Parse an Objective-C @dynamic declaration. The syntax is: 9974 9975 objc-dynamic-declaration: 9976 @dynamic identifier-list ; 9977 9978 For example: 9979 @dynamic MyProperty; 9980 @dynamic MyProperty, AnotherProperty; 9981 9982 PS: This function is identical to cp_parser_objc_at_dynamic_declaration 9983 for C++. Keep them in sync. 9984 */ 9985 static void 9986 c_parser_objc_at_dynamic_declaration (c_parser *parser) 9987 { 9988 tree list = NULL_TREE; 9989 location_t loc; 9990 gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC)); 9991 loc = c_parser_peek_token (parser)->location; 9992 9993 c_parser_consume_token (parser); 9994 while (true) 9995 { 9996 tree property; 9997 if (c_parser_next_token_is_not (parser, CPP_NAME)) 9998 { 9999 c_parser_error (parser, "expected identifier"); 10000 c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); 10001 parser->error = false; 10002 return; 10003 } 10004 property = c_parser_peek_token (parser)->value; 10005 list = chainon (list, build_tree_list (NULL_TREE, property)); 10006 c_parser_consume_token (parser); 10007 if (c_parser_next_token_is (parser, CPP_COMMA)) 10008 c_parser_consume_token (parser); 10009 else 10010 break; 10011 } 10012 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 10013 objc_add_dynamic_declaration (loc, list); 10014 } 10015 10016 10017 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore 10018 should be considered, statements. ALLOW_STMT is true if we're within 10019 the context of a function and such pragmas are to be allowed. Returns 10020 true if we actually parsed such a pragma. */ 10021 10022 static bool 10023 c_parser_pragma (c_parser *parser, enum pragma_context context, bool *if_p) 10024 { 10025 unsigned int id; 10026 10027 id = c_parser_peek_token (parser)->pragma_kind; 10028 gcc_assert (id != PRAGMA_NONE); 10029 10030 switch (id) 10031 { 10032 case PRAGMA_OACC_DECLARE: 10033 c_parser_oacc_declare (parser); 10034 return false; 10035 10036 case PRAGMA_OACC_ENTER_DATA: 10037 c_parser_oacc_enter_exit_data (parser, true); 10038 return false; 10039 10040 case PRAGMA_OACC_EXIT_DATA: 10041 c_parser_oacc_enter_exit_data (parser, false); 10042 return false; 10043 10044 case PRAGMA_OACC_ROUTINE: 10045 c_parser_oacc_routine (parser, context); 10046 return false; 10047 10048 case PRAGMA_OACC_UPDATE: 10049 if (context != pragma_compound) 10050 { 10051 if (context == pragma_stmt) 10052 c_parser_error (parser, "%<#pragma acc update%> may only be " 10053 "used in compound statements"); 10054 goto bad_stmt; 10055 } 10056 c_parser_oacc_update (parser); 10057 return false; 10058 10059 case PRAGMA_OMP_BARRIER: 10060 if (context != pragma_compound) 10061 { 10062 if (context == pragma_stmt) 10063 c_parser_error (parser, "%<#pragma omp barrier%> may only be " 10064 "used in compound statements"); 10065 goto bad_stmt; 10066 } 10067 c_parser_omp_barrier (parser); 10068 return false; 10069 10070 case PRAGMA_OMP_FLUSH: 10071 if (context != pragma_compound) 10072 { 10073 if (context == pragma_stmt) 10074 c_parser_error (parser, "%<#pragma omp flush%> may only be " 10075 "used in compound statements"); 10076 goto bad_stmt; 10077 } 10078 c_parser_omp_flush (parser); 10079 return false; 10080 10081 case PRAGMA_OMP_TASKWAIT: 10082 if (context != pragma_compound) 10083 { 10084 if (context == pragma_stmt) 10085 c_parser_error (parser, "%<#pragma omp taskwait%> may only be " 10086 "used in compound statements"); 10087 goto bad_stmt; 10088 } 10089 c_parser_omp_taskwait (parser); 10090 return false; 10091 10092 case PRAGMA_OMP_TASKYIELD: 10093 if (context != pragma_compound) 10094 { 10095 if (context == pragma_stmt) 10096 c_parser_error (parser, "%<#pragma omp taskyield%> may only be " 10097 "used in compound statements"); 10098 goto bad_stmt; 10099 } 10100 c_parser_omp_taskyield (parser); 10101 return false; 10102 10103 case PRAGMA_OMP_CANCEL: 10104 if (context != pragma_compound) 10105 { 10106 if (context == pragma_stmt) 10107 c_parser_error (parser, "%<#pragma omp cancel%> may only be " 10108 "used in compound statements"); 10109 goto bad_stmt; 10110 } 10111 c_parser_omp_cancel (parser); 10112 return false; 10113 10114 case PRAGMA_OMP_CANCELLATION_POINT: 10115 if (context != pragma_compound) 10116 { 10117 if (context == pragma_stmt) 10118 c_parser_error (parser, "%<#pragma omp cancellation point%> may " 10119 "only be used in compound statements"); 10120 goto bad_stmt; 10121 } 10122 c_parser_omp_cancellation_point (parser); 10123 return false; 10124 10125 case PRAGMA_OMP_THREADPRIVATE: 10126 c_parser_omp_threadprivate (parser); 10127 return false; 10128 10129 case PRAGMA_OMP_TARGET: 10130 return c_parser_omp_target (parser, context, if_p); 10131 10132 case PRAGMA_OMP_END_DECLARE_TARGET: 10133 c_parser_omp_end_declare_target (parser); 10134 return false; 10135 10136 case PRAGMA_OMP_SECTION: 10137 error_at (c_parser_peek_token (parser)->location, 10138 "%<#pragma omp section%> may only be used in " 10139 "%<#pragma omp sections%> construct"); 10140 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); 10141 return false; 10142 10143 case PRAGMA_OMP_DECLARE_REDUCTION: 10144 c_parser_omp_declare (parser, context); 10145 return false; 10146 10147 case PRAGMA_OMP_ORDERED: 10148 return c_parser_omp_ordered (parser, context, if_p); 10149 10150 case PRAGMA_IVDEP: 10151 c_parser_consume_pragma (parser); 10152 c_parser_skip_to_pragma_eol (parser); 10153 if (!c_parser_next_token_is_keyword (parser, RID_FOR) 10154 && !c_parser_next_token_is_keyword (parser, RID_WHILE) 10155 && !c_parser_next_token_is_keyword (parser, RID_DO)) 10156 { 10157 c_parser_error (parser, "for, while or do statement expected"); 10158 return false; 10159 } 10160 if (c_parser_next_token_is_keyword (parser, RID_FOR)) 10161 c_parser_for_statement (parser, true, if_p); 10162 else if (c_parser_next_token_is_keyword (parser, RID_WHILE)) 10163 c_parser_while_statement (parser, true, if_p); 10164 else 10165 c_parser_do_statement (parser, true); 10166 return false; 10167 10168 case PRAGMA_GCC_PCH_PREPROCESS: 10169 c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first"); 10170 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); 10171 return false; 10172 10173 case PRAGMA_CILK_SIMD: 10174 if (!c_parser_cilk_verify_simd (parser, context)) 10175 return false; 10176 c_parser_consume_pragma (parser); 10177 c_parser_cilk_simd (parser, if_p); 10178 return false; 10179 case PRAGMA_CILK_GRAINSIZE: 10180 if (!flag_cilkplus) 10181 { 10182 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not" 10183 " enabled"); 10184 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); 10185 return false; 10186 } 10187 if (context == pragma_external) 10188 { 10189 error_at (c_parser_peek_token (parser)->location, 10190 "%<#pragma grainsize%> must be inside a function"); 10191 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); 10192 return false; 10193 } 10194 c_parser_cilk_grainsize (parser, if_p); 10195 return false; 10196 10197 default: 10198 if (id < PRAGMA_FIRST_EXTERNAL) 10199 { 10200 if (context != pragma_stmt && context != pragma_compound) 10201 { 10202 bad_stmt: 10203 c_parser_error (parser, "expected declaration specifiers"); 10204 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); 10205 return false; 10206 } 10207 c_parser_omp_construct (parser, if_p); 10208 return true; 10209 } 10210 break; 10211 } 10212 10213 c_parser_consume_pragma (parser); 10214 c_invoke_pragma_handler (id); 10215 10216 /* Skip to EOL, but suppress any error message. Those will have been 10217 generated by the handler routine through calling error, as opposed 10218 to calling c_parser_error. */ 10219 parser->error = true; 10220 c_parser_skip_to_pragma_eol (parser); 10221 10222 return false; 10223 } 10224 10225 /* The interface the pragma parsers have to the lexer. */ 10226 10227 enum cpp_ttype 10228 pragma_lex (tree *value, location_t *loc) 10229 { 10230 c_token *tok = c_parser_peek_token (the_parser); 10231 enum cpp_ttype ret = tok->type; 10232 10233 *value = tok->value; 10234 if (loc) 10235 *loc = tok->location; 10236 10237 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF) 10238 ret = CPP_EOF; 10239 else 10240 { 10241 if (ret == CPP_KEYWORD) 10242 ret = CPP_NAME; 10243 c_parser_consume_token (the_parser); 10244 } 10245 10246 return ret; 10247 } 10248 10249 static void 10250 c_parser_pragma_pch_preprocess (c_parser *parser) 10251 { 10252 tree name = NULL; 10253 10254 c_parser_consume_pragma (parser); 10255 if (c_parser_next_token_is (parser, CPP_STRING)) 10256 { 10257 name = c_parser_peek_token (parser)->value; 10258 c_parser_consume_token (parser); 10259 } 10260 else 10261 c_parser_error (parser, "expected string literal"); 10262 c_parser_skip_to_pragma_eol (parser); 10263 10264 if (name) 10265 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name)); 10266 } 10267 10268 /* OpenACC and OpenMP parsing routines. */ 10269 10270 /* Returns name of the next clause. 10271 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and 10272 the token is not consumed. Otherwise appropriate pragma_omp_clause is 10273 returned and the token is consumed. */ 10274 10275 static pragma_omp_clause 10276 c_parser_omp_clause_name (c_parser *parser) 10277 { 10278 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE; 10279 10280 if (c_parser_next_token_is_keyword (parser, RID_AUTO)) 10281 result = PRAGMA_OACC_CLAUSE_AUTO; 10282 else if (c_parser_next_token_is_keyword (parser, RID_IF)) 10283 result = PRAGMA_OMP_CLAUSE_IF; 10284 else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT)) 10285 result = PRAGMA_OMP_CLAUSE_DEFAULT; 10286 else if (c_parser_next_token_is_keyword (parser, RID_FOR)) 10287 result = PRAGMA_OMP_CLAUSE_FOR; 10288 else if (c_parser_next_token_is (parser, CPP_NAME)) 10289 { 10290 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 10291 10292 switch (p[0]) 10293 { 10294 case 'a': 10295 if (!strcmp ("aligned", p)) 10296 result = PRAGMA_OMP_CLAUSE_ALIGNED; 10297 else if (!strcmp ("async", p)) 10298 result = PRAGMA_OACC_CLAUSE_ASYNC; 10299 break; 10300 case 'c': 10301 if (!strcmp ("collapse", p)) 10302 result = PRAGMA_OMP_CLAUSE_COLLAPSE; 10303 else if (!strcmp ("copy", p)) 10304 result = PRAGMA_OACC_CLAUSE_COPY; 10305 else if (!strcmp ("copyin", p)) 10306 result = PRAGMA_OMP_CLAUSE_COPYIN; 10307 else if (!strcmp ("copyout", p)) 10308 result = PRAGMA_OACC_CLAUSE_COPYOUT; 10309 else if (!strcmp ("copyprivate", p)) 10310 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE; 10311 else if (!strcmp ("create", p)) 10312 result = PRAGMA_OACC_CLAUSE_CREATE; 10313 break; 10314 case 'd': 10315 if (!strcmp ("defaultmap", p)) 10316 result = PRAGMA_OMP_CLAUSE_DEFAULTMAP; 10317 else if (!strcmp ("delete", p)) 10318 result = PRAGMA_OACC_CLAUSE_DELETE; 10319 else if (!strcmp ("depend", p)) 10320 result = PRAGMA_OMP_CLAUSE_DEPEND; 10321 else if (!strcmp ("device", p)) 10322 result = PRAGMA_OMP_CLAUSE_DEVICE; 10323 else if (!strcmp ("deviceptr", p)) 10324 result = PRAGMA_OACC_CLAUSE_DEVICEPTR; 10325 else if (!strcmp ("device_resident", p)) 10326 result = PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT; 10327 else if (!strcmp ("dist_schedule", p)) 10328 result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE; 10329 break; 10330 case 'f': 10331 if (!strcmp ("final", p)) 10332 result = PRAGMA_OMP_CLAUSE_FINAL; 10333 else if (!strcmp ("firstprivate", p)) 10334 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE; 10335 else if (!strcmp ("from", p)) 10336 result = PRAGMA_OMP_CLAUSE_FROM; 10337 break; 10338 case 'g': 10339 if (!strcmp ("gang", p)) 10340 result = PRAGMA_OACC_CLAUSE_GANG; 10341 else if (!strcmp ("grainsize", p)) 10342 result = PRAGMA_OMP_CLAUSE_GRAINSIZE; 10343 break; 10344 case 'h': 10345 if (!strcmp ("hint", p)) 10346 result = PRAGMA_OMP_CLAUSE_HINT; 10347 else if (!strcmp ("host", p)) 10348 result = PRAGMA_OACC_CLAUSE_HOST; 10349 break; 10350 case 'i': 10351 if (!strcmp ("inbranch", p)) 10352 result = PRAGMA_OMP_CLAUSE_INBRANCH; 10353 else if (!strcmp ("independent", p)) 10354 result = PRAGMA_OACC_CLAUSE_INDEPENDENT; 10355 else if (!strcmp ("is_device_ptr", p)) 10356 result = PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR; 10357 break; 10358 case 'l': 10359 if (!strcmp ("lastprivate", p)) 10360 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE; 10361 else if (!strcmp ("linear", p)) 10362 result = PRAGMA_OMP_CLAUSE_LINEAR; 10363 else if (!strcmp ("link", p)) 10364 result = PRAGMA_OMP_CLAUSE_LINK; 10365 break; 10366 case 'm': 10367 if (!strcmp ("map", p)) 10368 result = PRAGMA_OMP_CLAUSE_MAP; 10369 else if (!strcmp ("mergeable", p)) 10370 result = PRAGMA_OMP_CLAUSE_MERGEABLE; 10371 else if (flag_cilkplus && !strcmp ("mask", p)) 10372 result = PRAGMA_CILK_CLAUSE_MASK; 10373 break; 10374 case 'n': 10375 if (!strcmp ("nogroup", p)) 10376 result = PRAGMA_OMP_CLAUSE_NOGROUP; 10377 else if (!strcmp ("notinbranch", p)) 10378 result = PRAGMA_OMP_CLAUSE_NOTINBRANCH; 10379 else if (!strcmp ("nowait", p)) 10380 result = PRAGMA_OMP_CLAUSE_NOWAIT; 10381 else if (!strcmp ("num_gangs", p)) 10382 result = PRAGMA_OACC_CLAUSE_NUM_GANGS; 10383 else if (!strcmp ("num_tasks", p)) 10384 result = PRAGMA_OMP_CLAUSE_NUM_TASKS; 10385 else if (!strcmp ("num_teams", p)) 10386 result = PRAGMA_OMP_CLAUSE_NUM_TEAMS; 10387 else if (!strcmp ("num_threads", p)) 10388 result = PRAGMA_OMP_CLAUSE_NUM_THREADS; 10389 else if (!strcmp ("num_workers", p)) 10390 result = PRAGMA_OACC_CLAUSE_NUM_WORKERS; 10391 else if (flag_cilkplus && !strcmp ("nomask", p)) 10392 result = PRAGMA_CILK_CLAUSE_NOMASK; 10393 break; 10394 case 'o': 10395 if (!strcmp ("ordered", p)) 10396 result = PRAGMA_OMP_CLAUSE_ORDERED; 10397 break; 10398 case 'p': 10399 if (!strcmp ("parallel", p)) 10400 result = PRAGMA_OMP_CLAUSE_PARALLEL; 10401 else if (!strcmp ("present", p)) 10402 result = PRAGMA_OACC_CLAUSE_PRESENT; 10403 else if (!strcmp ("present_or_copy", p) 10404 || !strcmp ("pcopy", p)) 10405 result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY; 10406 else if (!strcmp ("present_or_copyin", p) 10407 || !strcmp ("pcopyin", p)) 10408 result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN; 10409 else if (!strcmp ("present_or_copyout", p) 10410 || !strcmp ("pcopyout", p)) 10411 result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT; 10412 else if (!strcmp ("present_or_create", p) 10413 || !strcmp ("pcreate", p)) 10414 result = PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE; 10415 else if (!strcmp ("priority", p)) 10416 result = PRAGMA_OMP_CLAUSE_PRIORITY; 10417 else if (!strcmp ("private", p)) 10418 result = PRAGMA_OMP_CLAUSE_PRIVATE; 10419 else if (!strcmp ("proc_bind", p)) 10420 result = PRAGMA_OMP_CLAUSE_PROC_BIND; 10421 break; 10422 case 'r': 10423 if (!strcmp ("reduction", p)) 10424 result = PRAGMA_OMP_CLAUSE_REDUCTION; 10425 break; 10426 case 's': 10427 if (!strcmp ("safelen", p)) 10428 result = PRAGMA_OMP_CLAUSE_SAFELEN; 10429 else if (!strcmp ("schedule", p)) 10430 result = PRAGMA_OMP_CLAUSE_SCHEDULE; 10431 else if (!strcmp ("sections", p)) 10432 result = PRAGMA_OMP_CLAUSE_SECTIONS; 10433 else if (!strcmp ("seq", p)) 10434 result = PRAGMA_OACC_CLAUSE_SEQ; 10435 else if (!strcmp ("shared", p)) 10436 result = PRAGMA_OMP_CLAUSE_SHARED; 10437 else if (!strcmp ("simd", p)) 10438 result = PRAGMA_OMP_CLAUSE_SIMD; 10439 else if (!strcmp ("simdlen", p)) 10440 result = PRAGMA_OMP_CLAUSE_SIMDLEN; 10441 else if (!strcmp ("self", p)) 10442 result = PRAGMA_OACC_CLAUSE_SELF; 10443 break; 10444 case 't': 10445 if (!strcmp ("taskgroup", p)) 10446 result = PRAGMA_OMP_CLAUSE_TASKGROUP; 10447 else if (!strcmp ("thread_limit", p)) 10448 result = PRAGMA_OMP_CLAUSE_THREAD_LIMIT; 10449 else if (!strcmp ("threads", p)) 10450 result = PRAGMA_OMP_CLAUSE_THREADS; 10451 else if (!strcmp ("tile", p)) 10452 result = PRAGMA_OACC_CLAUSE_TILE; 10453 else if (!strcmp ("to", p)) 10454 result = PRAGMA_OMP_CLAUSE_TO; 10455 break; 10456 case 'u': 10457 if (!strcmp ("uniform", p)) 10458 result = PRAGMA_OMP_CLAUSE_UNIFORM; 10459 else if (!strcmp ("untied", p)) 10460 result = PRAGMA_OMP_CLAUSE_UNTIED; 10461 else if (!strcmp ("use_device", p)) 10462 result = PRAGMA_OACC_CLAUSE_USE_DEVICE; 10463 else if (!strcmp ("use_device_ptr", p)) 10464 result = PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR; 10465 break; 10466 case 'v': 10467 if (!strcmp ("vector", p)) 10468 result = PRAGMA_OACC_CLAUSE_VECTOR; 10469 else if (!strcmp ("vector_length", p)) 10470 result = PRAGMA_OACC_CLAUSE_VECTOR_LENGTH; 10471 else if (flag_cilkplus && !strcmp ("vectorlength", p)) 10472 result = PRAGMA_CILK_CLAUSE_VECTORLENGTH; 10473 break; 10474 case 'w': 10475 if (!strcmp ("wait", p)) 10476 result = PRAGMA_OACC_CLAUSE_WAIT; 10477 else if (!strcmp ("worker", p)) 10478 result = PRAGMA_OACC_CLAUSE_WORKER; 10479 break; 10480 } 10481 } 10482 10483 if (result != PRAGMA_OMP_CLAUSE_NONE) 10484 c_parser_consume_token (parser); 10485 10486 return result; 10487 } 10488 10489 /* Validate that a clause of the given type does not already exist. */ 10490 10491 static void 10492 check_no_duplicate_clause (tree clauses, enum omp_clause_code code, 10493 const char *name) 10494 { 10495 tree c; 10496 10497 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c)) 10498 if (OMP_CLAUSE_CODE (c) == code) 10499 { 10500 location_t loc = OMP_CLAUSE_LOCATION (c); 10501 error_at (loc, "too many %qs clauses", name); 10502 break; 10503 } 10504 } 10505 10506 /* OpenACC 2.0 10507 Parse wait clause or wait directive parameters. */ 10508 10509 static tree 10510 c_parser_oacc_wait_list (c_parser *parser, location_t clause_loc, tree list) 10511 { 10512 vec<tree, va_gc> *args; 10513 tree t, args_tree; 10514 10515 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 10516 return list; 10517 10518 args = c_parser_expr_list (parser, false, true, NULL, NULL, NULL, NULL); 10519 10520 if (args->length () == 0) 10521 { 10522 c_parser_error (parser, "expected integer expression before ')'"); 10523 release_tree_vector (args); 10524 return list; 10525 } 10526 10527 args_tree = build_tree_list_vec (args); 10528 10529 for (t = args_tree; t; t = TREE_CHAIN (t)) 10530 { 10531 tree targ = TREE_VALUE (t); 10532 10533 if (targ != error_mark_node) 10534 { 10535 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ))) 10536 { 10537 c_parser_error (parser, "expression must be integral"); 10538 targ = error_mark_node; 10539 } 10540 else 10541 { 10542 tree c = build_omp_clause (clause_loc, OMP_CLAUSE_WAIT); 10543 10544 OMP_CLAUSE_DECL (c) = targ; 10545 OMP_CLAUSE_CHAIN (c) = list; 10546 list = c; 10547 } 10548 } 10549 } 10550 10551 release_tree_vector (args); 10552 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 10553 return list; 10554 } 10555 10556 /* OpenACC 2.0, OpenMP 2.5: 10557 variable-list: 10558 identifier 10559 variable-list , identifier 10560 10561 If KIND is nonzero, create the appropriate node and install the 10562 decl in OMP_CLAUSE_DECL and add the node to the head of the list. 10563 If KIND is nonzero, CLAUSE_LOC is the location of the clause. 10564 10565 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE; 10566 return the list created. */ 10567 10568 static tree 10569 c_parser_omp_variable_list (c_parser *parser, 10570 location_t clause_loc, 10571 enum omp_clause_code kind, tree list) 10572 { 10573 if (c_parser_next_token_is_not (parser, CPP_NAME) 10574 || c_parser_peek_token (parser)->id_kind != C_ID_ID) 10575 c_parser_error (parser, "expected identifier"); 10576 10577 while (c_parser_next_token_is (parser, CPP_NAME) 10578 && c_parser_peek_token (parser)->id_kind == C_ID_ID) 10579 { 10580 tree t = lookup_name (c_parser_peek_token (parser)->value); 10581 10582 if (t == NULL_TREE) 10583 { 10584 undeclared_variable (c_parser_peek_token (parser)->location, 10585 c_parser_peek_token (parser)->value); 10586 t = error_mark_node; 10587 } 10588 10589 c_parser_consume_token (parser); 10590 10591 if (t == error_mark_node) 10592 ; 10593 else if (kind != 0) 10594 { 10595 switch (kind) 10596 { 10597 case OMP_CLAUSE__CACHE_: 10598 /* The OpenACC cache directive explicitly only allows "array 10599 elements or subarrays". */ 10600 if (c_parser_peek_token (parser)->type != CPP_OPEN_SQUARE) 10601 { 10602 c_parser_error (parser, "expected %<[%>"); 10603 t = error_mark_node; 10604 break; 10605 } 10606 /* FALLTHROUGH */ 10607 case OMP_CLAUSE_MAP: 10608 case OMP_CLAUSE_FROM: 10609 case OMP_CLAUSE_TO: 10610 while (c_parser_next_token_is (parser, CPP_DOT)) 10611 { 10612 location_t op_loc = c_parser_peek_token (parser)->location; 10613 c_parser_consume_token (parser); 10614 if (!c_parser_next_token_is (parser, CPP_NAME)) 10615 { 10616 c_parser_error (parser, "expected identifier"); 10617 t = error_mark_node; 10618 break; 10619 } 10620 tree ident = c_parser_peek_token (parser)->value; 10621 c_parser_consume_token (parser); 10622 t = build_component_ref (op_loc, t, ident); 10623 } 10624 /* FALLTHROUGH */ 10625 case OMP_CLAUSE_DEPEND: 10626 case OMP_CLAUSE_REDUCTION: 10627 while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) 10628 { 10629 tree low_bound = NULL_TREE, length = NULL_TREE; 10630 10631 c_parser_consume_token (parser); 10632 if (!c_parser_next_token_is (parser, CPP_COLON)) 10633 { 10634 low_bound = c_parser_expression (parser).value; 10635 mark_exp_read (low_bound); 10636 } 10637 if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) 10638 length = integer_one_node; 10639 else 10640 { 10641 /* Look for `:'. */ 10642 if (!c_parser_require (parser, CPP_COLON, 10643 "expected %<:%>")) 10644 { 10645 t = error_mark_node; 10646 break; 10647 } 10648 if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) 10649 { 10650 length = c_parser_expression (parser).value; 10651 mark_exp_read (length); 10652 } 10653 } 10654 /* Look for the closing `]'. */ 10655 if (!c_parser_require (parser, CPP_CLOSE_SQUARE, 10656 "expected %<]%>")) 10657 { 10658 t = error_mark_node; 10659 break; 10660 } 10661 10662 t = tree_cons (low_bound, length, t); 10663 } 10664 break; 10665 default: 10666 break; 10667 } 10668 10669 if (t != error_mark_node) 10670 { 10671 tree u = build_omp_clause (clause_loc, kind); 10672 OMP_CLAUSE_DECL (u) = t; 10673 OMP_CLAUSE_CHAIN (u) = list; 10674 list = u; 10675 } 10676 } 10677 else 10678 list = tree_cons (t, NULL_TREE, list); 10679 10680 if (c_parser_next_token_is_not (parser, CPP_COMMA)) 10681 break; 10682 10683 c_parser_consume_token (parser); 10684 } 10685 10686 return list; 10687 } 10688 10689 /* Similarly, but expect leading and trailing parenthesis. This is a very 10690 common case for OpenACC and OpenMP clauses. */ 10691 10692 static tree 10693 c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind, 10694 tree list) 10695 { 10696 /* The clauses location. */ 10697 location_t loc = c_parser_peek_token (parser)->location; 10698 10699 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 10700 { 10701 list = c_parser_omp_variable_list (parser, loc, kind, list); 10702 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 10703 } 10704 return list; 10705 } 10706 10707 /* OpenACC 2.0: 10708 copy ( variable-list ) 10709 copyin ( variable-list ) 10710 copyout ( variable-list ) 10711 create ( variable-list ) 10712 delete ( variable-list ) 10713 present ( variable-list ) 10714 present_or_copy ( variable-list ) 10715 pcopy ( variable-list ) 10716 present_or_copyin ( variable-list ) 10717 pcopyin ( variable-list ) 10718 present_or_copyout ( variable-list ) 10719 pcopyout ( variable-list ) 10720 present_or_create ( variable-list ) 10721 pcreate ( variable-list ) */ 10722 10723 static tree 10724 c_parser_oacc_data_clause (c_parser *parser, pragma_omp_clause c_kind, 10725 tree list) 10726 { 10727 enum gomp_map_kind kind; 10728 switch (c_kind) 10729 { 10730 case PRAGMA_OACC_CLAUSE_COPY: 10731 kind = GOMP_MAP_FORCE_TOFROM; 10732 break; 10733 case PRAGMA_OACC_CLAUSE_COPYIN: 10734 kind = GOMP_MAP_FORCE_TO; 10735 break; 10736 case PRAGMA_OACC_CLAUSE_COPYOUT: 10737 kind = GOMP_MAP_FORCE_FROM; 10738 break; 10739 case PRAGMA_OACC_CLAUSE_CREATE: 10740 kind = GOMP_MAP_FORCE_ALLOC; 10741 break; 10742 case PRAGMA_OACC_CLAUSE_DELETE: 10743 kind = GOMP_MAP_DELETE; 10744 break; 10745 case PRAGMA_OACC_CLAUSE_DEVICE: 10746 kind = GOMP_MAP_FORCE_TO; 10747 break; 10748 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT: 10749 kind = GOMP_MAP_DEVICE_RESIDENT; 10750 break; 10751 case PRAGMA_OACC_CLAUSE_HOST: 10752 case PRAGMA_OACC_CLAUSE_SELF: 10753 kind = GOMP_MAP_FORCE_FROM; 10754 break; 10755 case PRAGMA_OACC_CLAUSE_LINK: 10756 kind = GOMP_MAP_LINK; 10757 break; 10758 case PRAGMA_OACC_CLAUSE_PRESENT: 10759 kind = GOMP_MAP_FORCE_PRESENT; 10760 break; 10761 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY: 10762 kind = GOMP_MAP_TOFROM; 10763 break; 10764 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN: 10765 kind = GOMP_MAP_TO; 10766 break; 10767 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT: 10768 kind = GOMP_MAP_FROM; 10769 break; 10770 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE: 10771 kind = GOMP_MAP_ALLOC; 10772 break; 10773 default: 10774 gcc_unreachable (); 10775 } 10776 tree nl, c; 10777 nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_MAP, list); 10778 10779 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) 10780 OMP_CLAUSE_SET_MAP_KIND (c, kind); 10781 10782 return nl; 10783 } 10784 10785 /* OpenACC 2.0: 10786 deviceptr ( variable-list ) */ 10787 10788 static tree 10789 c_parser_oacc_data_clause_deviceptr (c_parser *parser, tree list) 10790 { 10791 location_t loc = c_parser_peek_token (parser)->location; 10792 tree vars, t; 10793 10794 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic 10795 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR, 10796 variable-list must only allow for pointer variables. */ 10797 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); 10798 for (t = vars; t && t; t = TREE_CHAIN (t)) 10799 { 10800 tree v = TREE_PURPOSE (t); 10801 10802 /* FIXME diagnostics: Ideally we should keep individual 10803 locations for all the variables in the var list to make the 10804 following errors more precise. Perhaps 10805 c_parser_omp_var_list_parens() should construct a list of 10806 locations to go along with the var list. */ 10807 10808 if (!VAR_P (v) && TREE_CODE (v) != PARM_DECL) 10809 error_at (loc, "%qD is not a variable", v); 10810 else if (TREE_TYPE (v) == error_mark_node) 10811 ; 10812 else if (!POINTER_TYPE_P (TREE_TYPE (v))) 10813 error_at (loc, "%qD is not a pointer variable", v); 10814 10815 tree u = build_omp_clause (loc, OMP_CLAUSE_MAP); 10816 OMP_CLAUSE_SET_MAP_KIND (u, GOMP_MAP_FORCE_DEVICEPTR); 10817 OMP_CLAUSE_DECL (u) = v; 10818 OMP_CLAUSE_CHAIN (u) = list; 10819 list = u; 10820 } 10821 10822 return list; 10823 } 10824 10825 /* OpenACC 2.0, OpenMP 3.0: 10826 collapse ( constant-expression ) */ 10827 10828 static tree 10829 c_parser_omp_clause_collapse (c_parser *parser, tree list) 10830 { 10831 tree c, num = error_mark_node; 10832 HOST_WIDE_INT n; 10833 location_t loc; 10834 10835 check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse"); 10836 10837 loc = c_parser_peek_token (parser)->location; 10838 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 10839 { 10840 num = c_parser_expr_no_commas (parser, NULL).value; 10841 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 10842 } 10843 if (num == error_mark_node) 10844 return list; 10845 mark_exp_read (num); 10846 num = c_fully_fold (num, false, NULL); 10847 if (!INTEGRAL_TYPE_P (TREE_TYPE (num)) 10848 || !tree_fits_shwi_p (num) 10849 || (n = tree_to_shwi (num)) <= 0 10850 || (int) n != n) 10851 { 10852 error_at (loc, 10853 "collapse argument needs positive constant integer expression"); 10854 return list; 10855 } 10856 c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE); 10857 OMP_CLAUSE_COLLAPSE_EXPR (c) = num; 10858 OMP_CLAUSE_CHAIN (c) = list; 10859 return c; 10860 } 10861 10862 /* OpenMP 2.5: 10863 copyin ( variable-list ) */ 10864 10865 static tree 10866 c_parser_omp_clause_copyin (c_parser *parser, tree list) 10867 { 10868 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list); 10869 } 10870 10871 /* OpenMP 2.5: 10872 copyprivate ( variable-list ) */ 10873 10874 static tree 10875 c_parser_omp_clause_copyprivate (c_parser *parser, tree list) 10876 { 10877 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list); 10878 } 10879 10880 /* OpenMP 2.5: 10881 default ( shared | none ) 10882 10883 OpenACC 2.0: 10884 default (none) */ 10885 10886 static tree 10887 c_parser_omp_clause_default (c_parser *parser, tree list, bool is_oacc) 10888 { 10889 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED; 10890 location_t loc = c_parser_peek_token (parser)->location; 10891 tree c; 10892 10893 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 10894 return list; 10895 if (c_parser_next_token_is (parser, CPP_NAME)) 10896 { 10897 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 10898 10899 switch (p[0]) 10900 { 10901 case 'n': 10902 if (strcmp ("none", p) != 0) 10903 goto invalid_kind; 10904 kind = OMP_CLAUSE_DEFAULT_NONE; 10905 break; 10906 10907 case 's': 10908 if (strcmp ("shared", p) != 0 || is_oacc) 10909 goto invalid_kind; 10910 kind = OMP_CLAUSE_DEFAULT_SHARED; 10911 break; 10912 10913 default: 10914 goto invalid_kind; 10915 } 10916 10917 c_parser_consume_token (parser); 10918 } 10919 else 10920 { 10921 invalid_kind: 10922 if (is_oacc) 10923 c_parser_error (parser, "expected %<none%>"); 10924 else 10925 c_parser_error (parser, "expected %<none%> or %<shared%>"); 10926 } 10927 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 10928 10929 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED) 10930 return list; 10931 10932 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default"); 10933 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT); 10934 OMP_CLAUSE_CHAIN (c) = list; 10935 OMP_CLAUSE_DEFAULT_KIND (c) = kind; 10936 10937 return c; 10938 } 10939 10940 /* OpenMP 2.5: 10941 firstprivate ( variable-list ) */ 10942 10943 static tree 10944 c_parser_omp_clause_firstprivate (c_parser *parser, tree list) 10945 { 10946 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list); 10947 } 10948 10949 /* OpenMP 3.1: 10950 final ( expression ) */ 10951 10952 static tree 10953 c_parser_omp_clause_final (c_parser *parser, tree list) 10954 { 10955 location_t loc = c_parser_peek_token (parser)->location; 10956 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) 10957 { 10958 tree t = c_parser_paren_condition (parser); 10959 tree c; 10960 10961 check_no_duplicate_clause (list, OMP_CLAUSE_FINAL, "final"); 10962 10963 c = build_omp_clause (loc, OMP_CLAUSE_FINAL); 10964 OMP_CLAUSE_FINAL_EXPR (c) = t; 10965 OMP_CLAUSE_CHAIN (c) = list; 10966 list = c; 10967 } 10968 else 10969 c_parser_error (parser, "expected %<(%>"); 10970 10971 return list; 10972 } 10973 10974 /* OpenACC, OpenMP 2.5: 10975 if ( expression ) 10976 10977 OpenMP 4.5: 10978 if ( directive-name-modifier : expression ) 10979 10980 directive-name-modifier: 10981 parallel | task | taskloop | target data | target | target update 10982 | target enter data | target exit data */ 10983 10984 static tree 10985 c_parser_omp_clause_if (c_parser *parser, tree list, bool is_omp) 10986 { 10987 location_t location = c_parser_peek_token (parser)->location; 10988 enum tree_code if_modifier = ERROR_MARK; 10989 10990 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 10991 return list; 10992 10993 if (is_omp && c_parser_next_token_is (parser, CPP_NAME)) 10994 { 10995 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 10996 int n = 2; 10997 if (strcmp (p, "parallel") == 0) 10998 if_modifier = OMP_PARALLEL; 10999 else if (strcmp (p, "task") == 0) 11000 if_modifier = OMP_TASK; 11001 else if (strcmp (p, "taskloop") == 0) 11002 if_modifier = OMP_TASKLOOP; 11003 else if (strcmp (p, "target") == 0) 11004 { 11005 if_modifier = OMP_TARGET; 11006 if (c_parser_peek_2nd_token (parser)->type == CPP_NAME) 11007 { 11008 p = IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser)->value); 11009 if (strcmp ("data", p) == 0) 11010 if_modifier = OMP_TARGET_DATA; 11011 else if (strcmp ("update", p) == 0) 11012 if_modifier = OMP_TARGET_UPDATE; 11013 else if (strcmp ("enter", p) == 0) 11014 if_modifier = OMP_TARGET_ENTER_DATA; 11015 else if (strcmp ("exit", p) == 0) 11016 if_modifier = OMP_TARGET_EXIT_DATA; 11017 if (if_modifier != OMP_TARGET) 11018 { 11019 n = 3; 11020 c_parser_consume_token (parser); 11021 } 11022 else 11023 { 11024 location_t loc = c_parser_peek_2nd_token (parser)->location; 11025 error_at (loc, "expected %<data%>, %<update%>, %<enter%> " 11026 "or %<exit%>"); 11027 if_modifier = ERROR_MARK; 11028 } 11029 if (if_modifier == OMP_TARGET_ENTER_DATA 11030 || if_modifier == OMP_TARGET_EXIT_DATA) 11031 { 11032 if (c_parser_peek_2nd_token (parser)->type == CPP_NAME) 11033 { 11034 p = IDENTIFIER_POINTER 11035 (c_parser_peek_2nd_token (parser)->value); 11036 if (strcmp ("data", p) == 0) 11037 n = 4; 11038 } 11039 if (n == 4) 11040 c_parser_consume_token (parser); 11041 else 11042 { 11043 location_t loc 11044 = c_parser_peek_2nd_token (parser)->location; 11045 error_at (loc, "expected %<data%>"); 11046 if_modifier = ERROR_MARK; 11047 } 11048 } 11049 } 11050 } 11051 if (if_modifier != ERROR_MARK) 11052 { 11053 if (c_parser_peek_2nd_token (parser)->type == CPP_COLON) 11054 { 11055 c_parser_consume_token (parser); 11056 c_parser_consume_token (parser); 11057 } 11058 else 11059 { 11060 if (n > 2) 11061 { 11062 location_t loc = c_parser_peek_2nd_token (parser)->location; 11063 error_at (loc, "expected %<:%>"); 11064 } 11065 if_modifier = ERROR_MARK; 11066 } 11067 } 11068 } 11069 11070 tree t = c_parser_condition (parser), c; 11071 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 11072 11073 for (c = list; c ; c = OMP_CLAUSE_CHAIN (c)) 11074 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IF) 11075 { 11076 if (if_modifier != ERROR_MARK 11077 && OMP_CLAUSE_IF_MODIFIER (c) == if_modifier) 11078 { 11079 const char *p = NULL; 11080 switch (if_modifier) 11081 { 11082 case OMP_PARALLEL: p = "parallel"; break; 11083 case OMP_TASK: p = "task"; break; 11084 case OMP_TASKLOOP: p = "taskloop"; break; 11085 case OMP_TARGET_DATA: p = "target data"; break; 11086 case OMP_TARGET: p = "target"; break; 11087 case OMP_TARGET_UPDATE: p = "target update"; break; 11088 case OMP_TARGET_ENTER_DATA: p = "enter data"; break; 11089 case OMP_TARGET_EXIT_DATA: p = "exit data"; break; 11090 default: gcc_unreachable (); 11091 } 11092 error_at (location, "too many %<if%> clauses with %qs modifier", 11093 p); 11094 return list; 11095 } 11096 else if (OMP_CLAUSE_IF_MODIFIER (c) == if_modifier) 11097 { 11098 if (!is_omp) 11099 error_at (location, "too many %<if%> clauses"); 11100 else 11101 error_at (location, "too many %<if%> clauses without modifier"); 11102 return list; 11103 } 11104 else if (if_modifier == ERROR_MARK 11105 || OMP_CLAUSE_IF_MODIFIER (c) == ERROR_MARK) 11106 { 11107 error_at (location, "if any %<if%> clause has modifier, then all " 11108 "%<if%> clauses have to use modifier"); 11109 return list; 11110 } 11111 } 11112 11113 c = build_omp_clause (location, OMP_CLAUSE_IF); 11114 OMP_CLAUSE_IF_MODIFIER (c) = if_modifier; 11115 OMP_CLAUSE_IF_EXPR (c) = t; 11116 OMP_CLAUSE_CHAIN (c) = list; 11117 return c; 11118 } 11119 11120 /* OpenMP 2.5: 11121 lastprivate ( variable-list ) */ 11122 11123 static tree 11124 c_parser_omp_clause_lastprivate (c_parser *parser, tree list) 11125 { 11126 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list); 11127 } 11128 11129 /* OpenMP 3.1: 11130 mergeable */ 11131 11132 static tree 11133 c_parser_omp_clause_mergeable (c_parser *parser ATTRIBUTE_UNUSED, tree list) 11134 { 11135 tree c; 11136 11137 /* FIXME: Should we allow duplicates? */ 11138 check_no_duplicate_clause (list, OMP_CLAUSE_MERGEABLE, "mergeable"); 11139 11140 c = build_omp_clause (c_parser_peek_token (parser)->location, 11141 OMP_CLAUSE_MERGEABLE); 11142 OMP_CLAUSE_CHAIN (c) = list; 11143 11144 return c; 11145 } 11146 11147 /* OpenMP 2.5: 11148 nowait */ 11149 11150 static tree 11151 c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list) 11152 { 11153 tree c; 11154 location_t loc = c_parser_peek_token (parser)->location; 11155 11156 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait"); 11157 11158 c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT); 11159 OMP_CLAUSE_CHAIN (c) = list; 11160 return c; 11161 } 11162 11163 /* OpenACC: 11164 num_gangs ( expression ) */ 11165 11166 static tree 11167 c_parser_omp_clause_num_gangs (c_parser *parser, tree list) 11168 { 11169 location_t num_gangs_loc = c_parser_peek_token (parser)->location; 11170 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 11171 { 11172 location_t expr_loc = c_parser_peek_token (parser)->location; 11173 tree c, t = c_parser_expression (parser).value; 11174 mark_exp_read (t); 11175 t = c_fully_fold (t, false, NULL); 11176 11177 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 11178 11179 if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) 11180 { 11181 c_parser_error (parser, "expected integer expression"); 11182 return list; 11183 } 11184 11185 /* Attempt to statically determine when the number isn't positive. */ 11186 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, 11187 build_int_cst (TREE_TYPE (t), 0)); 11188 protected_set_expr_location (c, expr_loc); 11189 if (c == boolean_true_node) 11190 { 11191 warning_at (expr_loc, 0, 11192 "%<num_gangs%> value must be positive"); 11193 t = integer_one_node; 11194 } 11195 11196 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_GANGS, "num_gangs"); 11197 11198 c = build_omp_clause (num_gangs_loc, OMP_CLAUSE_NUM_GANGS); 11199 OMP_CLAUSE_NUM_GANGS_EXPR (c) = t; 11200 OMP_CLAUSE_CHAIN (c) = list; 11201 list = c; 11202 } 11203 11204 return list; 11205 } 11206 11207 /* OpenMP 2.5: 11208 num_threads ( expression ) */ 11209 11210 static tree 11211 c_parser_omp_clause_num_threads (c_parser *parser, tree list) 11212 { 11213 location_t num_threads_loc = c_parser_peek_token (parser)->location; 11214 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 11215 { 11216 location_t expr_loc = c_parser_peek_token (parser)->location; 11217 tree c, t = c_parser_expression (parser).value; 11218 mark_exp_read (t); 11219 t = c_fully_fold (t, false, NULL); 11220 11221 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 11222 11223 if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) 11224 { 11225 c_parser_error (parser, "expected integer expression"); 11226 return list; 11227 } 11228 11229 /* Attempt to statically determine when the number isn't positive. */ 11230 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, 11231 build_int_cst (TREE_TYPE (t), 0)); 11232 protected_set_expr_location (c, expr_loc); 11233 if (c == boolean_true_node) 11234 { 11235 warning_at (expr_loc, 0, 11236 "%<num_threads%> value must be positive"); 11237 t = integer_one_node; 11238 } 11239 11240 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads"); 11241 11242 c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS); 11243 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t; 11244 OMP_CLAUSE_CHAIN (c) = list; 11245 list = c; 11246 } 11247 11248 return list; 11249 } 11250 11251 /* OpenMP 4.5: 11252 num_tasks ( expression ) */ 11253 11254 static tree 11255 c_parser_omp_clause_num_tasks (c_parser *parser, tree list) 11256 { 11257 location_t num_tasks_loc = c_parser_peek_token (parser)->location; 11258 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 11259 { 11260 location_t expr_loc = c_parser_peek_token (parser)->location; 11261 tree c, t = c_parser_expression (parser).value; 11262 mark_exp_read (t); 11263 t = c_fully_fold (t, false, NULL); 11264 11265 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 11266 11267 if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) 11268 { 11269 c_parser_error (parser, "expected integer expression"); 11270 return list; 11271 } 11272 11273 /* Attempt to statically determine when the number isn't positive. */ 11274 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, 11275 build_int_cst (TREE_TYPE (t), 0)); 11276 if (CAN_HAVE_LOCATION_P (c)) 11277 SET_EXPR_LOCATION (c, expr_loc); 11278 if (c == boolean_true_node) 11279 { 11280 warning_at (expr_loc, 0, "%<num_tasks%> value must be positive"); 11281 t = integer_one_node; 11282 } 11283 11284 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TASKS, "num_tasks"); 11285 11286 c = build_omp_clause (num_tasks_loc, OMP_CLAUSE_NUM_TASKS); 11287 OMP_CLAUSE_NUM_TASKS_EXPR (c) = t; 11288 OMP_CLAUSE_CHAIN (c) = list; 11289 list = c; 11290 } 11291 11292 return list; 11293 } 11294 11295 /* OpenMP 4.5: 11296 grainsize ( expression ) */ 11297 11298 static tree 11299 c_parser_omp_clause_grainsize (c_parser *parser, tree list) 11300 { 11301 location_t grainsize_loc = c_parser_peek_token (parser)->location; 11302 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 11303 { 11304 location_t expr_loc = c_parser_peek_token (parser)->location; 11305 tree c, t = c_parser_expression (parser).value; 11306 mark_exp_read (t); 11307 t = c_fully_fold (t, false, NULL); 11308 11309 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 11310 11311 if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) 11312 { 11313 c_parser_error (parser, "expected integer expression"); 11314 return list; 11315 } 11316 11317 /* Attempt to statically determine when the number isn't positive. */ 11318 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, 11319 build_int_cst (TREE_TYPE (t), 0)); 11320 if (CAN_HAVE_LOCATION_P (c)) 11321 SET_EXPR_LOCATION (c, expr_loc); 11322 if (c == boolean_true_node) 11323 { 11324 warning_at (expr_loc, 0, "%<grainsize%> value must be positive"); 11325 t = integer_one_node; 11326 } 11327 11328 check_no_duplicate_clause (list, OMP_CLAUSE_GRAINSIZE, "grainsize"); 11329 11330 c = build_omp_clause (grainsize_loc, OMP_CLAUSE_GRAINSIZE); 11331 OMP_CLAUSE_GRAINSIZE_EXPR (c) = t; 11332 OMP_CLAUSE_CHAIN (c) = list; 11333 list = c; 11334 } 11335 11336 return list; 11337 } 11338 11339 /* OpenMP 4.5: 11340 priority ( expression ) */ 11341 11342 static tree 11343 c_parser_omp_clause_priority (c_parser *parser, tree list) 11344 { 11345 location_t priority_loc = c_parser_peek_token (parser)->location; 11346 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 11347 { 11348 location_t expr_loc = c_parser_peek_token (parser)->location; 11349 tree c, t = c_parser_expression (parser).value; 11350 mark_exp_read (t); 11351 t = c_fully_fold (t, false, NULL); 11352 11353 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 11354 11355 if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) 11356 { 11357 c_parser_error (parser, "expected integer expression"); 11358 return list; 11359 } 11360 11361 /* Attempt to statically determine when the number isn't 11362 non-negative. */ 11363 c = fold_build2_loc (expr_loc, LT_EXPR, boolean_type_node, t, 11364 build_int_cst (TREE_TYPE (t), 0)); 11365 if (CAN_HAVE_LOCATION_P (c)) 11366 SET_EXPR_LOCATION (c, expr_loc); 11367 if (c == boolean_true_node) 11368 { 11369 warning_at (expr_loc, 0, "%<priority%> value must be non-negative"); 11370 t = integer_one_node; 11371 } 11372 11373 check_no_duplicate_clause (list, OMP_CLAUSE_PRIORITY, "priority"); 11374 11375 c = build_omp_clause (priority_loc, OMP_CLAUSE_PRIORITY); 11376 OMP_CLAUSE_PRIORITY_EXPR (c) = t; 11377 OMP_CLAUSE_CHAIN (c) = list; 11378 list = c; 11379 } 11380 11381 return list; 11382 } 11383 11384 /* OpenMP 4.5: 11385 hint ( expression ) */ 11386 11387 static tree 11388 c_parser_omp_clause_hint (c_parser *parser, tree list) 11389 { 11390 location_t hint_loc = c_parser_peek_token (parser)->location; 11391 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 11392 { 11393 tree c, t = c_parser_expression (parser).value; 11394 mark_exp_read (t); 11395 t = c_fully_fold (t, false, NULL); 11396 11397 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 11398 11399 if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) 11400 { 11401 c_parser_error (parser, "expected integer expression"); 11402 return list; 11403 } 11404 11405 check_no_duplicate_clause (list, OMP_CLAUSE_HINT, "hint"); 11406 11407 c = build_omp_clause (hint_loc, OMP_CLAUSE_HINT); 11408 OMP_CLAUSE_HINT_EXPR (c) = t; 11409 OMP_CLAUSE_CHAIN (c) = list; 11410 list = c; 11411 } 11412 11413 return list; 11414 } 11415 11416 /* OpenMP 4.5: 11417 defaultmap ( tofrom : scalar ) */ 11418 11419 static tree 11420 c_parser_omp_clause_defaultmap (c_parser *parser, tree list) 11421 { 11422 location_t loc = c_parser_peek_token (parser)->location; 11423 tree c; 11424 const char *p; 11425 11426 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 11427 return list; 11428 if (!c_parser_next_token_is (parser, CPP_NAME)) 11429 { 11430 c_parser_error (parser, "expected %<tofrom%>"); 11431 goto out_err; 11432 } 11433 p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 11434 if (strcmp (p, "tofrom") != 0) 11435 { 11436 c_parser_error (parser, "expected %<tofrom%>"); 11437 goto out_err; 11438 } 11439 c_parser_consume_token (parser); 11440 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) 11441 goto out_err; 11442 if (!c_parser_next_token_is (parser, CPP_NAME)) 11443 { 11444 c_parser_error (parser, "expected %<scalar%>"); 11445 goto out_err; 11446 } 11447 p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 11448 if (strcmp (p, "scalar") != 0) 11449 { 11450 c_parser_error (parser, "expected %<scalar%>"); 11451 goto out_err; 11452 } 11453 c_parser_consume_token (parser); 11454 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 11455 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULTMAP, "defaultmap"); 11456 c = build_omp_clause (loc, OMP_CLAUSE_DEFAULTMAP); 11457 OMP_CLAUSE_CHAIN (c) = list; 11458 return c; 11459 11460 out_err: 11461 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 11462 return list; 11463 } 11464 11465 /* OpenACC 2.0: 11466 use_device ( variable-list ) 11467 11468 OpenMP 4.5: 11469 use_device_ptr ( variable-list ) */ 11470 11471 static tree 11472 c_parser_omp_clause_use_device_ptr (c_parser *parser, tree list) 11473 { 11474 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_USE_DEVICE_PTR, 11475 list); 11476 } 11477 11478 /* OpenMP 4.5: 11479 is_device_ptr ( variable-list ) */ 11480 11481 static tree 11482 c_parser_omp_clause_is_device_ptr (c_parser *parser, tree list) 11483 { 11484 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_IS_DEVICE_PTR, list); 11485 } 11486 11487 /* OpenACC: 11488 num_workers ( expression ) */ 11489 11490 static tree 11491 c_parser_omp_clause_num_workers (c_parser *parser, tree list) 11492 { 11493 location_t num_workers_loc = c_parser_peek_token (parser)->location; 11494 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 11495 { 11496 location_t expr_loc = c_parser_peek_token (parser)->location; 11497 tree c, t = c_parser_expression (parser).value; 11498 mark_exp_read (t); 11499 t = c_fully_fold (t, false, NULL); 11500 11501 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 11502 11503 if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) 11504 { 11505 c_parser_error (parser, "expected integer expression"); 11506 return list; 11507 } 11508 11509 /* Attempt to statically determine when the number isn't positive. */ 11510 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, 11511 build_int_cst (TREE_TYPE (t), 0)); 11512 protected_set_expr_location (c, expr_loc); 11513 if (c == boolean_true_node) 11514 { 11515 warning_at (expr_loc, 0, 11516 "%<num_workers%> value must be positive"); 11517 t = integer_one_node; 11518 } 11519 11520 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_WORKERS, "num_workers"); 11521 11522 c = build_omp_clause (num_workers_loc, OMP_CLAUSE_NUM_WORKERS); 11523 OMP_CLAUSE_NUM_WORKERS_EXPR (c) = t; 11524 OMP_CLAUSE_CHAIN (c) = list; 11525 list = c; 11526 } 11527 11528 return list; 11529 } 11530 11531 /* OpenACC: 11532 11533 gang [( gang-arg-list )] 11534 worker [( [num:] int-expr )] 11535 vector [( [length:] int-expr )] 11536 11537 where gang-arg is one of: 11538 11539 [num:] int-expr 11540 static: size-expr 11541 11542 and size-expr may be: 11543 11544 * 11545 int-expr 11546 */ 11547 11548 static tree 11549 c_parser_oacc_shape_clause (c_parser *parser, omp_clause_code kind, 11550 const char *str, tree list) 11551 { 11552 const char *id = "num"; 11553 tree ops[2] = { NULL_TREE, NULL_TREE }, c; 11554 location_t loc = c_parser_peek_token (parser)->location; 11555 11556 if (kind == OMP_CLAUSE_VECTOR) 11557 id = "length"; 11558 11559 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) 11560 { 11561 c_parser_consume_token (parser); 11562 11563 do 11564 { 11565 c_token *next = c_parser_peek_token (parser); 11566 int idx = 0; 11567 11568 /* Gang static argument. */ 11569 if (kind == OMP_CLAUSE_GANG 11570 && c_parser_next_token_is_keyword (parser, RID_STATIC)) 11571 { 11572 c_parser_consume_token (parser); 11573 11574 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) 11575 goto cleanup_error; 11576 11577 idx = 1; 11578 if (ops[idx] != NULL_TREE) 11579 { 11580 c_parser_error (parser, "too many %<static%> arguments"); 11581 goto cleanup_error; 11582 } 11583 11584 /* Check for the '*' argument. */ 11585 if (c_parser_next_token_is (parser, CPP_MULT) 11586 && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA 11587 || c_parser_peek_2nd_token (parser)->type 11588 == CPP_CLOSE_PAREN)) 11589 { 11590 c_parser_consume_token (parser); 11591 ops[idx] = integer_minus_one_node; 11592 11593 if (c_parser_next_token_is (parser, CPP_COMMA)) 11594 { 11595 c_parser_consume_token (parser); 11596 continue; 11597 } 11598 else 11599 break; 11600 } 11601 } 11602 /* Worker num: argument and vector length: arguments. */ 11603 else if (c_parser_next_token_is (parser, CPP_NAME) 11604 && strcmp (id, IDENTIFIER_POINTER (next->value)) == 0 11605 && c_parser_peek_2nd_token (parser)->type == CPP_COLON) 11606 { 11607 c_parser_consume_token (parser); /* id */ 11608 c_parser_consume_token (parser); /* ':' */ 11609 } 11610 11611 /* Now collect the actual argument. */ 11612 if (ops[idx] != NULL_TREE) 11613 { 11614 c_parser_error (parser, "unexpected argument"); 11615 goto cleanup_error; 11616 } 11617 11618 location_t expr_loc = c_parser_peek_token (parser)->location; 11619 tree expr = c_parser_expr_no_commas (parser, NULL).value; 11620 if (expr == error_mark_node) 11621 goto cleanup_error; 11622 11623 mark_exp_read (expr); 11624 expr = c_fully_fold (expr, false, NULL); 11625 11626 /* Attempt to statically determine when the number isn't a 11627 positive integer. */ 11628 11629 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))) 11630 { 11631 c_parser_error (parser, "expected integer expression"); 11632 return list; 11633 } 11634 11635 tree c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, expr, 11636 build_int_cst (TREE_TYPE (expr), 0)); 11637 if (c == boolean_true_node) 11638 { 11639 warning_at (loc, 0, 11640 "%<%s%> value must be positive", str); 11641 expr = integer_one_node; 11642 } 11643 11644 ops[idx] = expr; 11645 11646 if (kind == OMP_CLAUSE_GANG 11647 && c_parser_next_token_is (parser, CPP_COMMA)) 11648 { 11649 c_parser_consume_token (parser); 11650 continue; 11651 } 11652 break; 11653 } 11654 while (1); 11655 11656 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) 11657 goto cleanup_error; 11658 } 11659 11660 check_no_duplicate_clause (list, kind, str); 11661 11662 c = build_omp_clause (loc, kind); 11663 11664 if (ops[1]) 11665 OMP_CLAUSE_OPERAND (c, 1) = ops[1]; 11666 11667 OMP_CLAUSE_OPERAND (c, 0) = ops[0]; 11668 OMP_CLAUSE_CHAIN (c) = list; 11669 11670 return c; 11671 11672 cleanup_error: 11673 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); 11674 return list; 11675 } 11676 11677 /* OpenACC: 11678 auto 11679 independent 11680 nohost 11681 seq */ 11682 11683 static tree 11684 c_parser_oacc_simple_clause (c_parser *parser, enum omp_clause_code code, 11685 tree list) 11686 { 11687 check_no_duplicate_clause (list, code, omp_clause_code_name[code]); 11688 11689 tree c = build_omp_clause (c_parser_peek_token (parser)->location, code); 11690 OMP_CLAUSE_CHAIN (c) = list; 11691 11692 return c; 11693 } 11694 11695 /* OpenACC: 11696 async [( int-expr )] */ 11697 11698 static tree 11699 c_parser_oacc_clause_async (c_parser *parser, tree list) 11700 { 11701 tree c, t; 11702 location_t loc = c_parser_peek_token (parser)->location; 11703 11704 t = build_int_cst (integer_type_node, GOMP_ASYNC_NOVAL); 11705 11706 if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN) 11707 { 11708 c_parser_consume_token (parser); 11709 11710 t = c_parser_expression (parser).value; 11711 if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) 11712 c_parser_error (parser, "expected integer expression"); 11713 else if (t == error_mark_node 11714 || !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) 11715 return list; 11716 } 11717 else 11718 t = c_fully_fold (t, false, NULL); 11719 11720 check_no_duplicate_clause (list, OMP_CLAUSE_ASYNC, "async"); 11721 11722 c = build_omp_clause (loc, OMP_CLAUSE_ASYNC); 11723 OMP_CLAUSE_ASYNC_EXPR (c) = t; 11724 OMP_CLAUSE_CHAIN (c) = list; 11725 list = c; 11726 11727 return list; 11728 } 11729 11730 /* OpenACC 2.0: 11731 tile ( size-expr-list ) */ 11732 11733 static tree 11734 c_parser_oacc_clause_tile (c_parser *parser, tree list) 11735 { 11736 tree c, expr = error_mark_node; 11737 location_t loc, expr_loc; 11738 tree tile = NULL_TREE; 11739 11740 check_no_duplicate_clause (list, OMP_CLAUSE_TILE, "tile"); 11741 11742 loc = c_parser_peek_token (parser)->location; 11743 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 11744 return list; 11745 11746 do 11747 { 11748 if (c_parser_next_token_is (parser, CPP_MULT) 11749 && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA 11750 || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN)) 11751 { 11752 c_parser_consume_token (parser); 11753 expr = integer_minus_one_node; 11754 } 11755 else 11756 { 11757 expr_loc = c_parser_peek_token (parser)->location; 11758 expr = c_parser_expr_no_commas (parser, NULL).value; 11759 11760 if (expr == error_mark_node) 11761 { 11762 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 11763 "expected %<)%>"); 11764 return list; 11765 } 11766 11767 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))) 11768 { 11769 c_parser_error (parser, "%<tile%> value must be integral"); 11770 return list; 11771 } 11772 11773 mark_exp_read (expr); 11774 expr = c_fully_fold (expr, false, NULL); 11775 11776 /* Attempt to statically determine when expr isn't positive. */ 11777 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, expr, 11778 build_int_cst (TREE_TYPE (expr), 0)); 11779 protected_set_expr_location (c, expr_loc); 11780 if (c == boolean_true_node) 11781 { 11782 warning_at (expr_loc, 0,"%<tile%> value must be positive"); 11783 expr = integer_one_node; 11784 } 11785 } 11786 11787 tile = tree_cons (NULL_TREE, expr, tile); 11788 if (c_parser_next_token_is (parser, CPP_COMMA)) 11789 c_parser_consume_token (parser); 11790 } 11791 while (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)); 11792 11793 /* Consume the trailing ')'. */ 11794 c_parser_consume_token (parser); 11795 11796 c = build_omp_clause (loc, OMP_CLAUSE_TILE); 11797 tile = nreverse (tile); 11798 OMP_CLAUSE_TILE_LIST (c) = tile; 11799 OMP_CLAUSE_CHAIN (c) = list; 11800 return c; 11801 } 11802 11803 /* OpenACC: 11804 wait ( int-expr-list ) */ 11805 11806 static tree 11807 c_parser_oacc_clause_wait (c_parser *parser, tree list) 11808 { 11809 location_t clause_loc = c_parser_peek_token (parser)->location; 11810 11811 if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN) 11812 list = c_parser_oacc_wait_list (parser, clause_loc, list); 11813 11814 return list; 11815 } 11816 11817 /* OpenMP 2.5: 11818 ordered 11819 11820 OpenMP 4.5: 11821 ordered ( constant-expression ) */ 11822 11823 static tree 11824 c_parser_omp_clause_ordered (c_parser *parser, tree list) 11825 { 11826 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered"); 11827 11828 tree c, num = NULL_TREE; 11829 HOST_WIDE_INT n; 11830 location_t loc = c_parser_peek_token (parser)->location; 11831 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) 11832 { 11833 c_parser_consume_token (parser); 11834 num = c_parser_expr_no_commas (parser, NULL).value; 11835 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 11836 } 11837 if (num == error_mark_node) 11838 return list; 11839 if (num) 11840 { 11841 mark_exp_read (num); 11842 num = c_fully_fold (num, false, NULL); 11843 if (!INTEGRAL_TYPE_P (TREE_TYPE (num)) 11844 || !tree_fits_shwi_p (num) 11845 || (n = tree_to_shwi (num)) <= 0 11846 || (int) n != n) 11847 { 11848 error_at (loc, "ordered argument needs positive " 11849 "constant integer expression"); 11850 return list; 11851 } 11852 } 11853 c = build_omp_clause (loc, OMP_CLAUSE_ORDERED); 11854 OMP_CLAUSE_ORDERED_EXPR (c) = num; 11855 OMP_CLAUSE_CHAIN (c) = list; 11856 return c; 11857 } 11858 11859 /* OpenMP 2.5: 11860 private ( variable-list ) */ 11861 11862 static tree 11863 c_parser_omp_clause_private (c_parser *parser, tree list) 11864 { 11865 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list); 11866 } 11867 11868 /* OpenMP 2.5: 11869 reduction ( reduction-operator : variable-list ) 11870 11871 reduction-operator: 11872 One of: + * - & ^ | && || 11873 11874 OpenMP 3.1: 11875 11876 reduction-operator: 11877 One of: + * - & ^ | && || max min 11878 11879 OpenMP 4.0: 11880 11881 reduction-operator: 11882 One of: + * - & ^ | && || 11883 identifier */ 11884 11885 static tree 11886 c_parser_omp_clause_reduction (c_parser *parser, tree list) 11887 { 11888 location_t clause_loc = c_parser_peek_token (parser)->location; 11889 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 11890 { 11891 enum tree_code code = ERROR_MARK; 11892 tree reduc_id = NULL_TREE; 11893 11894 switch (c_parser_peek_token (parser)->type) 11895 { 11896 case CPP_PLUS: 11897 code = PLUS_EXPR; 11898 break; 11899 case CPP_MULT: 11900 code = MULT_EXPR; 11901 break; 11902 case CPP_MINUS: 11903 code = MINUS_EXPR; 11904 break; 11905 case CPP_AND: 11906 code = BIT_AND_EXPR; 11907 break; 11908 case CPP_XOR: 11909 code = BIT_XOR_EXPR; 11910 break; 11911 case CPP_OR: 11912 code = BIT_IOR_EXPR; 11913 break; 11914 case CPP_AND_AND: 11915 code = TRUTH_ANDIF_EXPR; 11916 break; 11917 case CPP_OR_OR: 11918 code = TRUTH_ORIF_EXPR; 11919 break; 11920 case CPP_NAME: 11921 { 11922 const char *p 11923 = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 11924 if (strcmp (p, "min") == 0) 11925 { 11926 code = MIN_EXPR; 11927 break; 11928 } 11929 if (strcmp (p, "max") == 0) 11930 { 11931 code = MAX_EXPR; 11932 break; 11933 } 11934 reduc_id = c_parser_peek_token (parser)->value; 11935 break; 11936 } 11937 default: 11938 c_parser_error (parser, 11939 "expected %<+%>, %<*%>, %<-%>, %<&%>, " 11940 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>"); 11941 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); 11942 return list; 11943 } 11944 c_parser_consume_token (parser); 11945 reduc_id = c_omp_reduction_id (code, reduc_id); 11946 if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) 11947 { 11948 tree nl, c; 11949 11950 nl = c_parser_omp_variable_list (parser, clause_loc, 11951 OMP_CLAUSE_REDUCTION, list); 11952 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) 11953 { 11954 tree d = OMP_CLAUSE_DECL (c), type; 11955 if (TREE_CODE (d) != TREE_LIST) 11956 type = TREE_TYPE (d); 11957 else 11958 { 11959 int cnt = 0; 11960 tree t; 11961 for (t = d; TREE_CODE (t) == TREE_LIST; t = TREE_CHAIN (t)) 11962 cnt++; 11963 type = TREE_TYPE (t); 11964 while (cnt > 0) 11965 { 11966 if (TREE_CODE (type) != POINTER_TYPE 11967 && TREE_CODE (type) != ARRAY_TYPE) 11968 break; 11969 type = TREE_TYPE (type); 11970 cnt--; 11971 } 11972 } 11973 while (TREE_CODE (type) == ARRAY_TYPE) 11974 type = TREE_TYPE (type); 11975 OMP_CLAUSE_REDUCTION_CODE (c) = code; 11976 if (code == ERROR_MARK 11977 || !(INTEGRAL_TYPE_P (type) 11978 || TREE_CODE (type) == REAL_TYPE 11979 || TREE_CODE (type) == COMPLEX_TYPE)) 11980 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) 11981 = c_omp_reduction_lookup (reduc_id, 11982 TYPE_MAIN_VARIANT (type)); 11983 } 11984 11985 list = nl; 11986 } 11987 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 11988 } 11989 return list; 11990 } 11991 11992 /* OpenMP 2.5: 11993 schedule ( schedule-kind ) 11994 schedule ( schedule-kind , expression ) 11995 11996 schedule-kind: 11997 static | dynamic | guided | runtime | auto 11998 11999 OpenMP 4.5: 12000 schedule ( schedule-modifier : schedule-kind ) 12001 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression ) 12002 12003 schedule-modifier: 12004 simd 12005 monotonic 12006 nonmonotonic */ 12007 12008 static tree 12009 c_parser_omp_clause_schedule (c_parser *parser, tree list) 12010 { 12011 tree c, t; 12012 location_t loc = c_parser_peek_token (parser)->location; 12013 int modifiers = 0, nmodifiers = 0; 12014 12015 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 12016 return list; 12017 12018 c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE); 12019 12020 while (c_parser_next_token_is (parser, CPP_NAME)) 12021 { 12022 tree kind = c_parser_peek_token (parser)->value; 12023 const char *p = IDENTIFIER_POINTER (kind); 12024 if (strcmp ("simd", p) == 0) 12025 OMP_CLAUSE_SCHEDULE_SIMD (c) = 1; 12026 else if (strcmp ("monotonic", p) == 0) 12027 modifiers |= OMP_CLAUSE_SCHEDULE_MONOTONIC; 12028 else if (strcmp ("nonmonotonic", p) == 0) 12029 modifiers |= OMP_CLAUSE_SCHEDULE_NONMONOTONIC; 12030 else 12031 break; 12032 c_parser_consume_token (parser); 12033 if (nmodifiers++ == 0 12034 && c_parser_next_token_is (parser, CPP_COMMA)) 12035 c_parser_consume_token (parser); 12036 else 12037 { 12038 c_parser_require (parser, CPP_COLON, "expected %<:%>"); 12039 break; 12040 } 12041 } 12042 12043 if ((modifiers & (OMP_CLAUSE_SCHEDULE_MONOTONIC 12044 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC)) 12045 == (OMP_CLAUSE_SCHEDULE_MONOTONIC 12046 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC)) 12047 { 12048 error_at (loc, "both %<monotonic%> and %<nonmonotonic%> modifiers " 12049 "specified"); 12050 modifiers = 0; 12051 } 12052 12053 if (c_parser_next_token_is (parser, CPP_NAME)) 12054 { 12055 tree kind = c_parser_peek_token (parser)->value; 12056 const char *p = IDENTIFIER_POINTER (kind); 12057 12058 switch (p[0]) 12059 { 12060 case 'd': 12061 if (strcmp ("dynamic", p) != 0) 12062 goto invalid_kind; 12063 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC; 12064 break; 12065 12066 case 'g': 12067 if (strcmp ("guided", p) != 0) 12068 goto invalid_kind; 12069 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED; 12070 break; 12071 12072 case 'r': 12073 if (strcmp ("runtime", p) != 0) 12074 goto invalid_kind; 12075 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME; 12076 break; 12077 12078 default: 12079 goto invalid_kind; 12080 } 12081 } 12082 else if (c_parser_next_token_is_keyword (parser, RID_STATIC)) 12083 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC; 12084 else if (c_parser_next_token_is_keyword (parser, RID_AUTO)) 12085 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO; 12086 else 12087 goto invalid_kind; 12088 12089 c_parser_consume_token (parser); 12090 if (c_parser_next_token_is (parser, CPP_COMMA)) 12091 { 12092 location_t here; 12093 c_parser_consume_token (parser); 12094 12095 here = c_parser_peek_token (parser)->location; 12096 t = c_parser_expr_no_commas (parser, NULL).value; 12097 mark_exp_read (t); 12098 t = c_fully_fold (t, false, NULL); 12099 12100 if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME) 12101 error_at (here, "schedule %<runtime%> does not take " 12102 "a %<chunk_size%> parameter"); 12103 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO) 12104 error_at (here, 12105 "schedule %<auto%> does not take " 12106 "a %<chunk_size%> parameter"); 12107 else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE) 12108 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t; 12109 else 12110 c_parser_error (parser, "expected integer expression"); 12111 12112 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 12113 } 12114 else 12115 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 12116 "expected %<,%> or %<)%>"); 12117 12118 OMP_CLAUSE_SCHEDULE_KIND (c) 12119 = (enum omp_clause_schedule_kind) 12120 (OMP_CLAUSE_SCHEDULE_KIND (c) | modifiers); 12121 12122 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule"); 12123 OMP_CLAUSE_CHAIN (c) = list; 12124 return c; 12125 12126 invalid_kind: 12127 c_parser_error (parser, "invalid schedule kind"); 12128 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); 12129 return list; 12130 } 12131 12132 /* OpenMP 2.5: 12133 shared ( variable-list ) */ 12134 12135 static tree 12136 c_parser_omp_clause_shared (c_parser *parser, tree list) 12137 { 12138 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list); 12139 } 12140 12141 /* OpenMP 3.0: 12142 untied */ 12143 12144 static tree 12145 c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list) 12146 { 12147 tree c; 12148 12149 /* FIXME: Should we allow duplicates? */ 12150 check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied"); 12151 12152 c = build_omp_clause (c_parser_peek_token (parser)->location, 12153 OMP_CLAUSE_UNTIED); 12154 OMP_CLAUSE_CHAIN (c) = list; 12155 12156 return c; 12157 } 12158 12159 /* OpenACC: 12160 vector_length ( expression ) */ 12161 12162 static tree 12163 c_parser_omp_clause_vector_length (c_parser *parser, tree list) 12164 { 12165 location_t vector_length_loc = c_parser_peek_token (parser)->location; 12166 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 12167 { 12168 location_t expr_loc = c_parser_peek_token (parser)->location; 12169 tree c, t = c_parser_expression (parser).value; 12170 mark_exp_read (t); 12171 t = c_fully_fold (t, false, NULL); 12172 12173 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 12174 12175 if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) 12176 { 12177 c_parser_error (parser, "expected integer expression"); 12178 return list; 12179 } 12180 12181 /* Attempt to statically determine when the number isn't positive. */ 12182 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, 12183 build_int_cst (TREE_TYPE (t), 0)); 12184 protected_set_expr_location (c, expr_loc); 12185 if (c == boolean_true_node) 12186 { 12187 warning_at (expr_loc, 0, 12188 "%<vector_length%> value must be positive"); 12189 t = integer_one_node; 12190 } 12191 12192 check_no_duplicate_clause (list, OMP_CLAUSE_VECTOR_LENGTH, "vector_length"); 12193 12194 c = build_omp_clause (vector_length_loc, OMP_CLAUSE_VECTOR_LENGTH); 12195 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c) = t; 12196 OMP_CLAUSE_CHAIN (c) = list; 12197 list = c; 12198 } 12199 12200 return list; 12201 } 12202 12203 /* OpenMP 4.0: 12204 inbranch 12205 notinbranch */ 12206 12207 static tree 12208 c_parser_omp_clause_branch (c_parser *parser ATTRIBUTE_UNUSED, 12209 enum omp_clause_code code, tree list) 12210 { 12211 check_no_duplicate_clause (list, code, omp_clause_code_name[code]); 12212 12213 tree c = build_omp_clause (c_parser_peek_token (parser)->location, code); 12214 OMP_CLAUSE_CHAIN (c) = list; 12215 12216 return c; 12217 } 12218 12219 /* OpenMP 4.0: 12220 parallel 12221 for 12222 sections 12223 taskgroup */ 12224 12225 static tree 12226 c_parser_omp_clause_cancelkind (c_parser *parser ATTRIBUTE_UNUSED, 12227 enum omp_clause_code code, tree list) 12228 { 12229 tree c = build_omp_clause (c_parser_peek_token (parser)->location, code); 12230 OMP_CLAUSE_CHAIN (c) = list; 12231 12232 return c; 12233 } 12234 12235 /* OpenMP 4.5: 12236 nogroup */ 12237 12238 static tree 12239 c_parser_omp_clause_nogroup (c_parser *parser ATTRIBUTE_UNUSED, tree list) 12240 { 12241 check_no_duplicate_clause (list, OMP_CLAUSE_NOGROUP, "nogroup"); 12242 tree c = build_omp_clause (c_parser_peek_token (parser)->location, 12243 OMP_CLAUSE_NOGROUP); 12244 OMP_CLAUSE_CHAIN (c) = list; 12245 return c; 12246 } 12247 12248 /* OpenMP 4.5: 12249 simd 12250 threads */ 12251 12252 static tree 12253 c_parser_omp_clause_orderedkind (c_parser *parser ATTRIBUTE_UNUSED, 12254 enum omp_clause_code code, tree list) 12255 { 12256 check_no_duplicate_clause (list, code, omp_clause_code_name[code]); 12257 tree c = build_omp_clause (c_parser_peek_token (parser)->location, code); 12258 OMP_CLAUSE_CHAIN (c) = list; 12259 return c; 12260 } 12261 12262 /* OpenMP 4.0: 12263 num_teams ( expression ) */ 12264 12265 static tree 12266 c_parser_omp_clause_num_teams (c_parser *parser, tree list) 12267 { 12268 location_t num_teams_loc = c_parser_peek_token (parser)->location; 12269 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 12270 { 12271 location_t expr_loc = c_parser_peek_token (parser)->location; 12272 tree c, t = c_parser_expression (parser).value; 12273 mark_exp_read (t); 12274 t = c_fully_fold (t, false, NULL); 12275 12276 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 12277 12278 if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) 12279 { 12280 c_parser_error (parser, "expected integer expression"); 12281 return list; 12282 } 12283 12284 /* Attempt to statically determine when the number isn't positive. */ 12285 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, 12286 build_int_cst (TREE_TYPE (t), 0)); 12287 protected_set_expr_location (c, expr_loc); 12288 if (c == boolean_true_node) 12289 { 12290 warning_at (expr_loc, 0, "%<num_teams%> value must be positive"); 12291 t = integer_one_node; 12292 } 12293 12294 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TEAMS, "num_teams"); 12295 12296 c = build_omp_clause (num_teams_loc, OMP_CLAUSE_NUM_TEAMS); 12297 OMP_CLAUSE_NUM_TEAMS_EXPR (c) = t; 12298 OMP_CLAUSE_CHAIN (c) = list; 12299 list = c; 12300 } 12301 12302 return list; 12303 } 12304 12305 /* OpenMP 4.0: 12306 thread_limit ( expression ) */ 12307 12308 static tree 12309 c_parser_omp_clause_thread_limit (c_parser *parser, tree list) 12310 { 12311 location_t num_thread_limit_loc = c_parser_peek_token (parser)->location; 12312 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 12313 { 12314 location_t expr_loc = c_parser_peek_token (parser)->location; 12315 tree c, t = c_parser_expression (parser).value; 12316 mark_exp_read (t); 12317 t = c_fully_fold (t, false, NULL); 12318 12319 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 12320 12321 if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) 12322 { 12323 c_parser_error (parser, "expected integer expression"); 12324 return list; 12325 } 12326 12327 /* Attempt to statically determine when the number isn't positive. */ 12328 c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, 12329 build_int_cst (TREE_TYPE (t), 0)); 12330 protected_set_expr_location (c, expr_loc); 12331 if (c == boolean_true_node) 12332 { 12333 warning_at (expr_loc, 0, "%<thread_limit%> value must be positive"); 12334 t = integer_one_node; 12335 } 12336 12337 check_no_duplicate_clause (list, OMP_CLAUSE_THREAD_LIMIT, 12338 "thread_limit"); 12339 12340 c = build_omp_clause (num_thread_limit_loc, OMP_CLAUSE_THREAD_LIMIT); 12341 OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t; 12342 OMP_CLAUSE_CHAIN (c) = list; 12343 list = c; 12344 } 12345 12346 return list; 12347 } 12348 12349 /* OpenMP 4.0: 12350 aligned ( variable-list ) 12351 aligned ( variable-list : constant-expression ) */ 12352 12353 static tree 12354 c_parser_omp_clause_aligned (c_parser *parser, tree list) 12355 { 12356 location_t clause_loc = c_parser_peek_token (parser)->location; 12357 tree nl, c; 12358 12359 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 12360 return list; 12361 12362 nl = c_parser_omp_variable_list (parser, clause_loc, 12363 OMP_CLAUSE_ALIGNED, list); 12364 12365 if (c_parser_next_token_is (parser, CPP_COLON)) 12366 { 12367 c_parser_consume_token (parser); 12368 tree alignment = c_parser_expr_no_commas (parser, NULL).value; 12369 mark_exp_read (alignment); 12370 alignment = c_fully_fold (alignment, false, NULL); 12371 if (TREE_CODE (alignment) != INTEGER_CST 12372 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment)) 12373 || tree_int_cst_sgn (alignment) != 1) 12374 { 12375 error_at (clause_loc, "%<aligned%> clause alignment expression must " 12376 "be positive constant integer expression"); 12377 alignment = NULL_TREE; 12378 } 12379 12380 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) 12381 OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = alignment; 12382 } 12383 12384 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 12385 return nl; 12386 } 12387 12388 /* OpenMP 4.0: 12389 linear ( variable-list ) 12390 linear ( variable-list : expression ) 12391 12392 OpenMP 4.5: 12393 linear ( modifier ( variable-list ) ) 12394 linear ( modifier ( variable-list ) : expression ) */ 12395 12396 static tree 12397 c_parser_omp_clause_linear (c_parser *parser, tree list, bool is_cilk_simd_fn) 12398 { 12399 location_t clause_loc = c_parser_peek_token (parser)->location; 12400 tree nl, c, step; 12401 enum omp_clause_linear_kind kind = OMP_CLAUSE_LINEAR_DEFAULT; 12402 12403 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 12404 return list; 12405 12406 if (!is_cilk_simd_fn 12407 && c_parser_next_token_is (parser, CPP_NAME)) 12408 { 12409 c_token *tok = c_parser_peek_token (parser); 12410 const char *p = IDENTIFIER_POINTER (tok->value); 12411 if (strcmp ("val", p) == 0) 12412 kind = OMP_CLAUSE_LINEAR_VAL; 12413 if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN) 12414 kind = OMP_CLAUSE_LINEAR_DEFAULT; 12415 if (kind != OMP_CLAUSE_LINEAR_DEFAULT) 12416 { 12417 c_parser_consume_token (parser); 12418 c_parser_consume_token (parser); 12419 } 12420 } 12421 12422 nl = c_parser_omp_variable_list (parser, clause_loc, 12423 OMP_CLAUSE_LINEAR, list); 12424 12425 if (kind != OMP_CLAUSE_LINEAR_DEFAULT) 12426 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 12427 12428 if (c_parser_next_token_is (parser, CPP_COLON)) 12429 { 12430 c_parser_consume_token (parser); 12431 step = c_parser_expression (parser).value; 12432 mark_exp_read (step); 12433 step = c_fully_fold (step, false, NULL); 12434 if (is_cilk_simd_fn && TREE_CODE (step) == PARM_DECL) 12435 { 12436 sorry ("using parameters for %<linear%> step is not supported yet"); 12437 step = integer_one_node; 12438 } 12439 if (!INTEGRAL_TYPE_P (TREE_TYPE (step))) 12440 { 12441 error_at (clause_loc, "%<linear%> clause step expression must " 12442 "be integral"); 12443 step = integer_one_node; 12444 } 12445 12446 } 12447 else 12448 step = integer_one_node; 12449 12450 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) 12451 { 12452 OMP_CLAUSE_LINEAR_STEP (c) = step; 12453 OMP_CLAUSE_LINEAR_KIND (c) = kind; 12454 } 12455 12456 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 12457 return nl; 12458 } 12459 12460 /* OpenMP 4.0: 12461 safelen ( constant-expression ) */ 12462 12463 static tree 12464 c_parser_omp_clause_safelen (c_parser *parser, tree list) 12465 { 12466 location_t clause_loc = c_parser_peek_token (parser)->location; 12467 tree c, t; 12468 12469 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 12470 return list; 12471 12472 t = c_parser_expr_no_commas (parser, NULL).value; 12473 mark_exp_read (t); 12474 t = c_fully_fold (t, false, NULL); 12475 if (TREE_CODE (t) != INTEGER_CST 12476 || !INTEGRAL_TYPE_P (TREE_TYPE (t)) 12477 || tree_int_cst_sgn (t) != 1) 12478 { 12479 error_at (clause_loc, "%<safelen%> clause expression must " 12480 "be positive constant integer expression"); 12481 t = NULL_TREE; 12482 } 12483 12484 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 12485 if (t == NULL_TREE || t == error_mark_node) 12486 return list; 12487 12488 check_no_duplicate_clause (list, OMP_CLAUSE_SAFELEN, "safelen"); 12489 12490 c = build_omp_clause (clause_loc, OMP_CLAUSE_SAFELEN); 12491 OMP_CLAUSE_SAFELEN_EXPR (c) = t; 12492 OMP_CLAUSE_CHAIN (c) = list; 12493 return c; 12494 } 12495 12496 /* OpenMP 4.0: 12497 simdlen ( constant-expression ) */ 12498 12499 static tree 12500 c_parser_omp_clause_simdlen (c_parser *parser, tree list) 12501 { 12502 location_t clause_loc = c_parser_peek_token (parser)->location; 12503 tree c, t; 12504 12505 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 12506 return list; 12507 12508 t = c_parser_expr_no_commas (parser, NULL).value; 12509 mark_exp_read (t); 12510 t = c_fully_fold (t, false, NULL); 12511 if (TREE_CODE (t) != INTEGER_CST 12512 || !INTEGRAL_TYPE_P (TREE_TYPE (t)) 12513 || tree_int_cst_sgn (t) != 1) 12514 { 12515 error_at (clause_loc, "%<simdlen%> clause expression must " 12516 "be positive constant integer expression"); 12517 t = NULL_TREE; 12518 } 12519 12520 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 12521 if (t == NULL_TREE || t == error_mark_node) 12522 return list; 12523 12524 check_no_duplicate_clause (list, OMP_CLAUSE_SIMDLEN, "simdlen"); 12525 12526 c = build_omp_clause (clause_loc, OMP_CLAUSE_SIMDLEN); 12527 OMP_CLAUSE_SIMDLEN_EXPR (c) = t; 12528 OMP_CLAUSE_CHAIN (c) = list; 12529 return c; 12530 } 12531 12532 /* OpenMP 4.5: 12533 vec: 12534 identifier [+/- integer] 12535 vec , identifier [+/- integer] 12536 */ 12537 12538 static tree 12539 c_parser_omp_clause_depend_sink (c_parser *parser, location_t clause_loc, 12540 tree list) 12541 { 12542 tree vec = NULL; 12543 if (c_parser_next_token_is_not (parser, CPP_NAME) 12544 || c_parser_peek_token (parser)->id_kind != C_ID_ID) 12545 { 12546 c_parser_error (parser, "expected identifier"); 12547 return list; 12548 } 12549 12550 while (c_parser_next_token_is (parser, CPP_NAME) 12551 && c_parser_peek_token (parser)->id_kind == C_ID_ID) 12552 { 12553 tree t = lookup_name (c_parser_peek_token (parser)->value); 12554 tree addend = NULL; 12555 12556 if (t == NULL_TREE) 12557 { 12558 undeclared_variable (c_parser_peek_token (parser)->location, 12559 c_parser_peek_token (parser)->value); 12560 t = error_mark_node; 12561 } 12562 12563 c_parser_consume_token (parser); 12564 12565 bool neg = false; 12566 if (c_parser_next_token_is (parser, CPP_MINUS)) 12567 neg = true; 12568 else if (!c_parser_next_token_is (parser, CPP_PLUS)) 12569 { 12570 addend = integer_zero_node; 12571 neg = false; 12572 goto add_to_vector; 12573 } 12574 c_parser_consume_token (parser); 12575 12576 if (c_parser_next_token_is_not (parser, CPP_NUMBER)) 12577 { 12578 c_parser_error (parser, "expected integer"); 12579 return list; 12580 } 12581 12582 addend = c_parser_peek_token (parser)->value; 12583 if (TREE_CODE (addend) != INTEGER_CST) 12584 { 12585 c_parser_error (parser, "expected integer"); 12586 return list; 12587 } 12588 c_parser_consume_token (parser); 12589 12590 add_to_vector: 12591 if (t != error_mark_node) 12592 { 12593 vec = tree_cons (addend, t, vec); 12594 if (neg) 12595 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec) = 1; 12596 } 12597 12598 if (c_parser_next_token_is_not (parser, CPP_COMMA)) 12599 break; 12600 12601 c_parser_consume_token (parser); 12602 } 12603 12604 if (vec == NULL_TREE) 12605 return list; 12606 12607 tree u = build_omp_clause (clause_loc, OMP_CLAUSE_DEPEND); 12608 OMP_CLAUSE_DEPEND_KIND (u) = OMP_CLAUSE_DEPEND_SINK; 12609 OMP_CLAUSE_DECL (u) = nreverse (vec); 12610 OMP_CLAUSE_CHAIN (u) = list; 12611 return u; 12612 } 12613 12614 /* OpenMP 4.0: 12615 depend ( depend-kind: variable-list ) 12616 12617 depend-kind: 12618 in | out | inout 12619 12620 OpenMP 4.5: 12621 depend ( source ) 12622 12623 depend ( sink : vec ) */ 12624 12625 static tree 12626 c_parser_omp_clause_depend (c_parser *parser, tree list) 12627 { 12628 location_t clause_loc = c_parser_peek_token (parser)->location; 12629 enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INOUT; 12630 tree nl, c; 12631 12632 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 12633 return list; 12634 12635 if (c_parser_next_token_is (parser, CPP_NAME)) 12636 { 12637 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 12638 if (strcmp ("in", p) == 0) 12639 kind = OMP_CLAUSE_DEPEND_IN; 12640 else if (strcmp ("inout", p) == 0) 12641 kind = OMP_CLAUSE_DEPEND_INOUT; 12642 else if (strcmp ("out", p) == 0) 12643 kind = OMP_CLAUSE_DEPEND_OUT; 12644 else if (strcmp ("source", p) == 0) 12645 kind = OMP_CLAUSE_DEPEND_SOURCE; 12646 else if (strcmp ("sink", p) == 0) 12647 kind = OMP_CLAUSE_DEPEND_SINK; 12648 else 12649 goto invalid_kind; 12650 } 12651 else 12652 goto invalid_kind; 12653 12654 c_parser_consume_token (parser); 12655 12656 if (kind == OMP_CLAUSE_DEPEND_SOURCE) 12657 { 12658 c = build_omp_clause (clause_loc, OMP_CLAUSE_DEPEND); 12659 OMP_CLAUSE_DEPEND_KIND (c) = kind; 12660 OMP_CLAUSE_DECL (c) = NULL_TREE; 12661 OMP_CLAUSE_CHAIN (c) = list; 12662 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 12663 return c; 12664 } 12665 12666 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) 12667 goto resync_fail; 12668 12669 if (kind == OMP_CLAUSE_DEPEND_SINK) 12670 nl = c_parser_omp_clause_depend_sink (parser, clause_loc, list); 12671 else 12672 { 12673 nl = c_parser_omp_variable_list (parser, clause_loc, 12674 OMP_CLAUSE_DEPEND, list); 12675 12676 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) 12677 OMP_CLAUSE_DEPEND_KIND (c) = kind; 12678 } 12679 12680 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 12681 return nl; 12682 12683 invalid_kind: 12684 c_parser_error (parser, "invalid depend kind"); 12685 resync_fail: 12686 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 12687 return list; 12688 } 12689 12690 /* OpenMP 4.0: 12691 map ( map-kind: variable-list ) 12692 map ( variable-list ) 12693 12694 map-kind: 12695 alloc | to | from | tofrom 12696 12697 OpenMP 4.5: 12698 map-kind: 12699 alloc | to | from | tofrom | release | delete 12700 12701 map ( always [,] map-kind: variable-list ) */ 12702 12703 static tree 12704 c_parser_omp_clause_map (c_parser *parser, tree list) 12705 { 12706 location_t clause_loc = c_parser_peek_token (parser)->location; 12707 enum gomp_map_kind kind = GOMP_MAP_TOFROM; 12708 int always = 0; 12709 enum c_id_kind always_id_kind = C_ID_NONE; 12710 location_t always_loc = UNKNOWN_LOCATION; 12711 tree always_id = NULL_TREE; 12712 tree nl, c; 12713 12714 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 12715 return list; 12716 12717 if (c_parser_next_token_is (parser, CPP_NAME)) 12718 { 12719 c_token *tok = c_parser_peek_token (parser); 12720 const char *p = IDENTIFIER_POINTER (tok->value); 12721 always_id_kind = tok->id_kind; 12722 always_loc = tok->location; 12723 always_id = tok->value; 12724 if (strcmp ("always", p) == 0) 12725 { 12726 c_token *sectok = c_parser_peek_2nd_token (parser); 12727 if (sectok->type == CPP_COMMA) 12728 { 12729 c_parser_consume_token (parser); 12730 c_parser_consume_token (parser); 12731 always = 2; 12732 } 12733 else if (sectok->type == CPP_NAME) 12734 { 12735 p = IDENTIFIER_POINTER (sectok->value); 12736 if (strcmp ("alloc", p) == 0 12737 || strcmp ("to", p) == 0 12738 || strcmp ("from", p) == 0 12739 || strcmp ("tofrom", p) == 0 12740 || strcmp ("release", p) == 0 12741 || strcmp ("delete", p) == 0) 12742 { 12743 c_parser_consume_token (parser); 12744 always = 1; 12745 } 12746 } 12747 } 12748 } 12749 12750 if (c_parser_next_token_is (parser, CPP_NAME) 12751 && c_parser_peek_2nd_token (parser)->type == CPP_COLON) 12752 { 12753 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 12754 if (strcmp ("alloc", p) == 0) 12755 kind = GOMP_MAP_ALLOC; 12756 else if (strcmp ("to", p) == 0) 12757 kind = always ? GOMP_MAP_ALWAYS_TO : GOMP_MAP_TO; 12758 else if (strcmp ("from", p) == 0) 12759 kind = always ? GOMP_MAP_ALWAYS_FROM : GOMP_MAP_FROM; 12760 else if (strcmp ("tofrom", p) == 0) 12761 kind = always ? GOMP_MAP_ALWAYS_TOFROM : GOMP_MAP_TOFROM; 12762 else if (strcmp ("release", p) == 0) 12763 kind = GOMP_MAP_RELEASE; 12764 else if (strcmp ("delete", p) == 0) 12765 kind = GOMP_MAP_DELETE; 12766 else 12767 { 12768 c_parser_error (parser, "invalid map kind"); 12769 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 12770 "expected %<)%>"); 12771 return list; 12772 } 12773 c_parser_consume_token (parser); 12774 c_parser_consume_token (parser); 12775 } 12776 else if (always) 12777 { 12778 if (always_id_kind != C_ID_ID) 12779 { 12780 c_parser_error (parser, "expected identifier"); 12781 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 12782 return list; 12783 } 12784 12785 tree t = lookup_name (always_id); 12786 if (t == NULL_TREE) 12787 { 12788 undeclared_variable (always_loc, always_id); 12789 t = error_mark_node; 12790 } 12791 if (t != error_mark_node) 12792 { 12793 tree u = build_omp_clause (clause_loc, OMP_CLAUSE_MAP); 12794 OMP_CLAUSE_DECL (u) = t; 12795 OMP_CLAUSE_CHAIN (u) = list; 12796 OMP_CLAUSE_SET_MAP_KIND (u, kind); 12797 list = u; 12798 } 12799 if (always == 1) 12800 { 12801 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 12802 return list; 12803 } 12804 } 12805 12806 nl = c_parser_omp_variable_list (parser, clause_loc, OMP_CLAUSE_MAP, list); 12807 12808 for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) 12809 OMP_CLAUSE_SET_MAP_KIND (c, kind); 12810 12811 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 12812 return nl; 12813 } 12814 12815 /* OpenMP 4.0: 12816 device ( expression ) */ 12817 12818 static tree 12819 c_parser_omp_clause_device (c_parser *parser, tree list) 12820 { 12821 location_t clause_loc = c_parser_peek_token (parser)->location; 12822 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 12823 { 12824 tree c, t = c_parser_expr_no_commas (parser, NULL).value; 12825 mark_exp_read (t); 12826 t = c_fully_fold (t, false, NULL); 12827 12828 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 12829 12830 if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) 12831 { 12832 c_parser_error (parser, "expected integer expression"); 12833 return list; 12834 } 12835 12836 check_no_duplicate_clause (list, OMP_CLAUSE_DEVICE, "device"); 12837 12838 c = build_omp_clause (clause_loc, OMP_CLAUSE_DEVICE); 12839 OMP_CLAUSE_DEVICE_ID (c) = t; 12840 OMP_CLAUSE_CHAIN (c) = list; 12841 list = c; 12842 } 12843 12844 return list; 12845 } 12846 12847 /* OpenMP 4.0: 12848 dist_schedule ( static ) 12849 dist_schedule ( static , expression ) */ 12850 12851 static tree 12852 c_parser_omp_clause_dist_schedule (c_parser *parser, tree list) 12853 { 12854 tree c, t = NULL_TREE; 12855 location_t loc = c_parser_peek_token (parser)->location; 12856 12857 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 12858 return list; 12859 12860 if (!c_parser_next_token_is_keyword (parser, RID_STATIC)) 12861 { 12862 c_parser_error (parser, "invalid dist_schedule kind"); 12863 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 12864 "expected %<)%>"); 12865 return list; 12866 } 12867 12868 c_parser_consume_token (parser); 12869 if (c_parser_next_token_is (parser, CPP_COMMA)) 12870 { 12871 c_parser_consume_token (parser); 12872 12873 t = c_parser_expr_no_commas (parser, NULL).value; 12874 mark_exp_read (t); 12875 t = c_fully_fold (t, false, NULL); 12876 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 12877 } 12878 else 12879 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 12880 "expected %<,%> or %<)%>"); 12881 12882 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule"); 12883 if (t == error_mark_node) 12884 return list; 12885 12886 c = build_omp_clause (loc, OMP_CLAUSE_DIST_SCHEDULE); 12887 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t; 12888 OMP_CLAUSE_CHAIN (c) = list; 12889 return c; 12890 } 12891 12892 /* OpenMP 4.0: 12893 proc_bind ( proc-bind-kind ) 12894 12895 proc-bind-kind: 12896 master | close | spread */ 12897 12898 static tree 12899 c_parser_omp_clause_proc_bind (c_parser *parser, tree list) 12900 { 12901 location_t clause_loc = c_parser_peek_token (parser)->location; 12902 enum omp_clause_proc_bind_kind kind; 12903 tree c; 12904 12905 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 12906 return list; 12907 12908 if (c_parser_next_token_is (parser, CPP_NAME)) 12909 { 12910 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 12911 if (strcmp ("master", p) == 0) 12912 kind = OMP_CLAUSE_PROC_BIND_MASTER; 12913 else if (strcmp ("close", p) == 0) 12914 kind = OMP_CLAUSE_PROC_BIND_CLOSE; 12915 else if (strcmp ("spread", p) == 0) 12916 kind = OMP_CLAUSE_PROC_BIND_SPREAD; 12917 else 12918 goto invalid_kind; 12919 } 12920 else 12921 goto invalid_kind; 12922 12923 c_parser_consume_token (parser); 12924 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 12925 c = build_omp_clause (clause_loc, OMP_CLAUSE_PROC_BIND); 12926 OMP_CLAUSE_PROC_BIND_KIND (c) = kind; 12927 OMP_CLAUSE_CHAIN (c) = list; 12928 return c; 12929 12930 invalid_kind: 12931 c_parser_error (parser, "invalid proc_bind kind"); 12932 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 12933 return list; 12934 } 12935 12936 /* OpenMP 4.0: 12937 to ( variable-list ) */ 12938 12939 static tree 12940 c_parser_omp_clause_to (c_parser *parser, tree list) 12941 { 12942 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO, list); 12943 } 12944 12945 /* OpenMP 4.0: 12946 from ( variable-list ) */ 12947 12948 static tree 12949 c_parser_omp_clause_from (c_parser *parser, tree list) 12950 { 12951 return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FROM, list); 12952 } 12953 12954 /* OpenMP 4.0: 12955 uniform ( variable-list ) */ 12956 12957 static tree 12958 c_parser_omp_clause_uniform (c_parser *parser, tree list) 12959 { 12960 /* The clauses location. */ 12961 location_t loc = c_parser_peek_token (parser)->location; 12962 12963 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 12964 { 12965 list = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_UNIFORM, 12966 list); 12967 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 12968 } 12969 return list; 12970 } 12971 12972 /* Parse all OpenACC clauses. The set clauses allowed by the directive 12973 is a bitmask in MASK. Return the list of clauses found. */ 12974 12975 static tree 12976 c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask, 12977 const char *where, bool finish_p = true) 12978 { 12979 tree clauses = NULL; 12980 bool first = true; 12981 12982 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) 12983 { 12984 location_t here; 12985 pragma_omp_clause c_kind; 12986 const char *c_name; 12987 tree prev = clauses; 12988 12989 if (!first && c_parser_next_token_is (parser, CPP_COMMA)) 12990 c_parser_consume_token (parser); 12991 12992 here = c_parser_peek_token (parser)->location; 12993 c_kind = c_parser_omp_clause_name (parser); 12994 12995 switch (c_kind) 12996 { 12997 case PRAGMA_OACC_CLAUSE_ASYNC: 12998 clauses = c_parser_oacc_clause_async (parser, clauses); 12999 c_name = "async"; 13000 break; 13001 case PRAGMA_OACC_CLAUSE_AUTO: 13002 clauses = c_parser_oacc_simple_clause (parser, OMP_CLAUSE_AUTO, 13003 clauses); 13004 c_name = "auto"; 13005 break; 13006 case PRAGMA_OACC_CLAUSE_COLLAPSE: 13007 clauses = c_parser_omp_clause_collapse (parser, clauses); 13008 c_name = "collapse"; 13009 break; 13010 case PRAGMA_OACC_CLAUSE_COPY: 13011 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); 13012 c_name = "copy"; 13013 break; 13014 case PRAGMA_OACC_CLAUSE_COPYIN: 13015 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); 13016 c_name = "copyin"; 13017 break; 13018 case PRAGMA_OACC_CLAUSE_COPYOUT: 13019 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); 13020 c_name = "copyout"; 13021 break; 13022 case PRAGMA_OACC_CLAUSE_CREATE: 13023 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); 13024 c_name = "create"; 13025 break; 13026 case PRAGMA_OACC_CLAUSE_DELETE: 13027 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); 13028 c_name = "delete"; 13029 break; 13030 case PRAGMA_OMP_CLAUSE_DEFAULT: 13031 clauses = c_parser_omp_clause_default (parser, clauses, true); 13032 c_name = "default"; 13033 break; 13034 case PRAGMA_OACC_CLAUSE_DEVICE: 13035 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); 13036 c_name = "device"; 13037 break; 13038 case PRAGMA_OACC_CLAUSE_DEVICEPTR: 13039 clauses = c_parser_oacc_data_clause_deviceptr (parser, clauses); 13040 c_name = "deviceptr"; 13041 break; 13042 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT: 13043 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); 13044 c_name = "device_resident"; 13045 break; 13046 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE: 13047 clauses = c_parser_omp_clause_firstprivate (parser, clauses); 13048 c_name = "firstprivate"; 13049 break; 13050 case PRAGMA_OACC_CLAUSE_GANG: 13051 c_name = "gang"; 13052 clauses = c_parser_oacc_shape_clause (parser, OMP_CLAUSE_GANG, 13053 c_name, clauses); 13054 break; 13055 case PRAGMA_OACC_CLAUSE_HOST: 13056 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); 13057 c_name = "host"; 13058 break; 13059 case PRAGMA_OACC_CLAUSE_IF: 13060 clauses = c_parser_omp_clause_if (parser, clauses, false); 13061 c_name = "if"; 13062 break; 13063 case PRAGMA_OACC_CLAUSE_INDEPENDENT: 13064 clauses = c_parser_oacc_simple_clause (parser, OMP_CLAUSE_INDEPENDENT, 13065 clauses); 13066 c_name = "independent"; 13067 break; 13068 case PRAGMA_OACC_CLAUSE_LINK: 13069 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); 13070 c_name = "link"; 13071 break; 13072 case PRAGMA_OACC_CLAUSE_NUM_GANGS: 13073 clauses = c_parser_omp_clause_num_gangs (parser, clauses); 13074 c_name = "num_gangs"; 13075 break; 13076 case PRAGMA_OACC_CLAUSE_NUM_WORKERS: 13077 clauses = c_parser_omp_clause_num_workers (parser, clauses); 13078 c_name = "num_workers"; 13079 break; 13080 case PRAGMA_OACC_CLAUSE_PRESENT: 13081 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); 13082 c_name = "present"; 13083 break; 13084 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY: 13085 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); 13086 c_name = "present_or_copy"; 13087 break; 13088 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN: 13089 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); 13090 c_name = "present_or_copyin"; 13091 break; 13092 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT: 13093 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); 13094 c_name = "present_or_copyout"; 13095 break; 13096 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE: 13097 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); 13098 c_name = "present_or_create"; 13099 break; 13100 case PRAGMA_OACC_CLAUSE_PRIVATE: 13101 clauses = c_parser_omp_clause_private (parser, clauses); 13102 c_name = "private"; 13103 break; 13104 case PRAGMA_OACC_CLAUSE_REDUCTION: 13105 clauses = c_parser_omp_clause_reduction (parser, clauses); 13106 c_name = "reduction"; 13107 break; 13108 case PRAGMA_OACC_CLAUSE_SELF: 13109 clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); 13110 c_name = "self"; 13111 break; 13112 case PRAGMA_OACC_CLAUSE_SEQ: 13113 clauses = c_parser_oacc_simple_clause (parser, OMP_CLAUSE_SEQ, 13114 clauses); 13115 c_name = "seq"; 13116 break; 13117 case PRAGMA_OACC_CLAUSE_TILE: 13118 clauses = c_parser_oacc_clause_tile (parser, clauses); 13119 c_name = "tile"; 13120 break; 13121 case PRAGMA_OACC_CLAUSE_USE_DEVICE: 13122 clauses = c_parser_omp_clause_use_device_ptr (parser, clauses); 13123 c_name = "use_device"; 13124 break; 13125 case PRAGMA_OACC_CLAUSE_VECTOR: 13126 c_name = "vector"; 13127 clauses = c_parser_oacc_shape_clause (parser, OMP_CLAUSE_VECTOR, 13128 c_name, clauses); 13129 break; 13130 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH: 13131 clauses = c_parser_omp_clause_vector_length (parser, clauses); 13132 c_name = "vector_length"; 13133 break; 13134 case PRAGMA_OACC_CLAUSE_WAIT: 13135 clauses = c_parser_oacc_clause_wait (parser, clauses); 13136 c_name = "wait"; 13137 break; 13138 case PRAGMA_OACC_CLAUSE_WORKER: 13139 c_name = "worker"; 13140 clauses = c_parser_oacc_shape_clause (parser, OMP_CLAUSE_WORKER, 13141 c_name, clauses); 13142 break; 13143 default: 13144 c_parser_error (parser, "expected %<#pragma acc%> clause"); 13145 goto saw_error; 13146 } 13147 13148 first = false; 13149 13150 if (((mask >> c_kind) & 1) == 0) 13151 { 13152 /* Remove the invalid clause(s) from the list to avoid 13153 confusing the rest of the compiler. */ 13154 clauses = prev; 13155 error_at (here, "%qs is not valid for %qs", c_name, where); 13156 } 13157 } 13158 13159 saw_error: 13160 c_parser_skip_to_pragma_eol (parser); 13161 13162 if (finish_p) 13163 return c_finish_omp_clauses (clauses, false); 13164 13165 return clauses; 13166 } 13167 13168 /* Parse all OpenMP clauses. The set clauses allowed by the directive 13169 is a bitmask in MASK. Return the list of clauses found. */ 13170 13171 static tree 13172 c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask, 13173 const char *where, bool finish_p = true) 13174 { 13175 tree clauses = NULL; 13176 bool first = true, cilk_simd_fn = false; 13177 13178 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) 13179 { 13180 location_t here; 13181 pragma_omp_clause c_kind; 13182 const char *c_name; 13183 tree prev = clauses; 13184 13185 if (!first && c_parser_next_token_is (parser, CPP_COMMA)) 13186 c_parser_consume_token (parser); 13187 13188 here = c_parser_peek_token (parser)->location; 13189 c_kind = c_parser_omp_clause_name (parser); 13190 13191 switch (c_kind) 13192 { 13193 case PRAGMA_OMP_CLAUSE_COLLAPSE: 13194 clauses = c_parser_omp_clause_collapse (parser, clauses); 13195 c_name = "collapse"; 13196 break; 13197 case PRAGMA_OMP_CLAUSE_COPYIN: 13198 clauses = c_parser_omp_clause_copyin (parser, clauses); 13199 c_name = "copyin"; 13200 break; 13201 case PRAGMA_OMP_CLAUSE_COPYPRIVATE: 13202 clauses = c_parser_omp_clause_copyprivate (parser, clauses); 13203 c_name = "copyprivate"; 13204 break; 13205 case PRAGMA_OMP_CLAUSE_DEFAULT: 13206 clauses = c_parser_omp_clause_default (parser, clauses, false); 13207 c_name = "default"; 13208 break; 13209 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE: 13210 clauses = c_parser_omp_clause_firstprivate (parser, clauses); 13211 c_name = "firstprivate"; 13212 break; 13213 case PRAGMA_OMP_CLAUSE_FINAL: 13214 clauses = c_parser_omp_clause_final (parser, clauses); 13215 c_name = "final"; 13216 break; 13217 case PRAGMA_OMP_CLAUSE_GRAINSIZE: 13218 clauses = c_parser_omp_clause_grainsize (parser, clauses); 13219 c_name = "grainsize"; 13220 break; 13221 case PRAGMA_OMP_CLAUSE_HINT: 13222 clauses = c_parser_omp_clause_hint (parser, clauses); 13223 c_name = "hint"; 13224 break; 13225 case PRAGMA_OMP_CLAUSE_DEFAULTMAP: 13226 clauses = c_parser_omp_clause_defaultmap (parser, clauses); 13227 c_name = "defaultmap"; 13228 break; 13229 case PRAGMA_OMP_CLAUSE_IF: 13230 clauses = c_parser_omp_clause_if (parser, clauses, true); 13231 c_name = "if"; 13232 break; 13233 case PRAGMA_OMP_CLAUSE_LASTPRIVATE: 13234 clauses = c_parser_omp_clause_lastprivate (parser, clauses); 13235 c_name = "lastprivate"; 13236 break; 13237 case PRAGMA_OMP_CLAUSE_MERGEABLE: 13238 clauses = c_parser_omp_clause_mergeable (parser, clauses); 13239 c_name = "mergeable"; 13240 break; 13241 case PRAGMA_OMP_CLAUSE_NOWAIT: 13242 clauses = c_parser_omp_clause_nowait (parser, clauses); 13243 c_name = "nowait"; 13244 break; 13245 case PRAGMA_OMP_CLAUSE_NUM_TASKS: 13246 clauses = c_parser_omp_clause_num_tasks (parser, clauses); 13247 c_name = "num_tasks"; 13248 break; 13249 case PRAGMA_OMP_CLAUSE_NUM_THREADS: 13250 clauses = c_parser_omp_clause_num_threads (parser, clauses); 13251 c_name = "num_threads"; 13252 break; 13253 case PRAGMA_OMP_CLAUSE_ORDERED: 13254 clauses = c_parser_omp_clause_ordered (parser, clauses); 13255 c_name = "ordered"; 13256 break; 13257 case PRAGMA_OMP_CLAUSE_PRIORITY: 13258 clauses = c_parser_omp_clause_priority (parser, clauses); 13259 c_name = "priority"; 13260 break; 13261 case PRAGMA_OMP_CLAUSE_PRIVATE: 13262 clauses = c_parser_omp_clause_private (parser, clauses); 13263 c_name = "private"; 13264 break; 13265 case PRAGMA_OMP_CLAUSE_REDUCTION: 13266 clauses = c_parser_omp_clause_reduction (parser, clauses); 13267 c_name = "reduction"; 13268 break; 13269 case PRAGMA_OMP_CLAUSE_SCHEDULE: 13270 clauses = c_parser_omp_clause_schedule (parser, clauses); 13271 c_name = "schedule"; 13272 break; 13273 case PRAGMA_OMP_CLAUSE_SHARED: 13274 clauses = c_parser_omp_clause_shared (parser, clauses); 13275 c_name = "shared"; 13276 break; 13277 case PRAGMA_OMP_CLAUSE_UNTIED: 13278 clauses = c_parser_omp_clause_untied (parser, clauses); 13279 c_name = "untied"; 13280 break; 13281 case PRAGMA_OMP_CLAUSE_INBRANCH: 13282 case PRAGMA_CILK_CLAUSE_MASK: 13283 clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_INBRANCH, 13284 clauses); 13285 c_name = "inbranch"; 13286 break; 13287 case PRAGMA_OMP_CLAUSE_NOTINBRANCH: 13288 case PRAGMA_CILK_CLAUSE_NOMASK: 13289 clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_NOTINBRANCH, 13290 clauses); 13291 c_name = "notinbranch"; 13292 break; 13293 case PRAGMA_OMP_CLAUSE_PARALLEL: 13294 clauses 13295 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_PARALLEL, 13296 clauses); 13297 c_name = "parallel"; 13298 if (!first) 13299 { 13300 clause_not_first: 13301 error_at (here, "%qs must be the first clause of %qs", 13302 c_name, where); 13303 clauses = prev; 13304 } 13305 break; 13306 case PRAGMA_OMP_CLAUSE_FOR: 13307 clauses 13308 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_FOR, 13309 clauses); 13310 c_name = "for"; 13311 if (!first) 13312 goto clause_not_first; 13313 break; 13314 case PRAGMA_OMP_CLAUSE_SECTIONS: 13315 clauses 13316 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_SECTIONS, 13317 clauses); 13318 c_name = "sections"; 13319 if (!first) 13320 goto clause_not_first; 13321 break; 13322 case PRAGMA_OMP_CLAUSE_TASKGROUP: 13323 clauses 13324 = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_TASKGROUP, 13325 clauses); 13326 c_name = "taskgroup"; 13327 if (!first) 13328 goto clause_not_first; 13329 break; 13330 case PRAGMA_OMP_CLAUSE_LINK: 13331 clauses 13332 = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LINK, clauses); 13333 c_name = "link"; 13334 break; 13335 case PRAGMA_OMP_CLAUSE_TO: 13336 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK)) != 0) 13337 clauses 13338 = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO_DECLARE, 13339 clauses); 13340 else 13341 clauses = c_parser_omp_clause_to (parser, clauses); 13342 c_name = "to"; 13343 break; 13344 case PRAGMA_OMP_CLAUSE_FROM: 13345 clauses = c_parser_omp_clause_from (parser, clauses); 13346 c_name = "from"; 13347 break; 13348 case PRAGMA_OMP_CLAUSE_UNIFORM: 13349 clauses = c_parser_omp_clause_uniform (parser, clauses); 13350 c_name = "uniform"; 13351 break; 13352 case PRAGMA_OMP_CLAUSE_NUM_TEAMS: 13353 clauses = c_parser_omp_clause_num_teams (parser, clauses); 13354 c_name = "num_teams"; 13355 break; 13356 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT: 13357 clauses = c_parser_omp_clause_thread_limit (parser, clauses); 13358 c_name = "thread_limit"; 13359 break; 13360 case PRAGMA_OMP_CLAUSE_ALIGNED: 13361 clauses = c_parser_omp_clause_aligned (parser, clauses); 13362 c_name = "aligned"; 13363 break; 13364 case PRAGMA_OMP_CLAUSE_LINEAR: 13365 if (((mask >> PRAGMA_CILK_CLAUSE_VECTORLENGTH) & 1) != 0) 13366 cilk_simd_fn = true; 13367 clauses = c_parser_omp_clause_linear (parser, clauses, cilk_simd_fn); 13368 c_name = "linear"; 13369 break; 13370 case PRAGMA_OMP_CLAUSE_DEPEND: 13371 clauses = c_parser_omp_clause_depend (parser, clauses); 13372 c_name = "depend"; 13373 break; 13374 case PRAGMA_OMP_CLAUSE_MAP: 13375 clauses = c_parser_omp_clause_map (parser, clauses); 13376 c_name = "map"; 13377 break; 13378 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR: 13379 clauses = c_parser_omp_clause_use_device_ptr (parser, clauses); 13380 c_name = "use_device_ptr"; 13381 break; 13382 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR: 13383 clauses = c_parser_omp_clause_is_device_ptr (parser, clauses); 13384 c_name = "is_device_ptr"; 13385 break; 13386 case PRAGMA_OMP_CLAUSE_DEVICE: 13387 clauses = c_parser_omp_clause_device (parser, clauses); 13388 c_name = "device"; 13389 break; 13390 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE: 13391 clauses = c_parser_omp_clause_dist_schedule (parser, clauses); 13392 c_name = "dist_schedule"; 13393 break; 13394 case PRAGMA_OMP_CLAUSE_PROC_BIND: 13395 clauses = c_parser_omp_clause_proc_bind (parser, clauses); 13396 c_name = "proc_bind"; 13397 break; 13398 case PRAGMA_OMP_CLAUSE_SAFELEN: 13399 clauses = c_parser_omp_clause_safelen (parser, clauses); 13400 c_name = "safelen"; 13401 break; 13402 case PRAGMA_CILK_CLAUSE_VECTORLENGTH: 13403 clauses = c_parser_cilk_clause_vectorlength (parser, clauses, true); 13404 c_name = "simdlen"; 13405 break; 13406 case PRAGMA_OMP_CLAUSE_SIMDLEN: 13407 clauses = c_parser_omp_clause_simdlen (parser, clauses); 13408 c_name = "simdlen"; 13409 break; 13410 case PRAGMA_OMP_CLAUSE_NOGROUP: 13411 clauses = c_parser_omp_clause_nogroup (parser, clauses); 13412 c_name = "nogroup"; 13413 break; 13414 case PRAGMA_OMP_CLAUSE_THREADS: 13415 clauses 13416 = c_parser_omp_clause_orderedkind (parser, OMP_CLAUSE_THREADS, 13417 clauses); 13418 c_name = "threads"; 13419 break; 13420 case PRAGMA_OMP_CLAUSE_SIMD: 13421 clauses 13422 = c_parser_omp_clause_orderedkind (parser, OMP_CLAUSE_SIMD, 13423 clauses); 13424 c_name = "simd"; 13425 break; 13426 default: 13427 c_parser_error (parser, "expected %<#pragma omp%> clause"); 13428 goto saw_error; 13429 } 13430 13431 first = false; 13432 13433 if (((mask >> c_kind) & 1) == 0) 13434 { 13435 /* Remove the invalid clause(s) from the list to avoid 13436 confusing the rest of the compiler. */ 13437 clauses = prev; 13438 error_at (here, "%qs is not valid for %qs", c_name, where); 13439 } 13440 } 13441 13442 saw_error: 13443 c_parser_skip_to_pragma_eol (parser); 13444 13445 if (finish_p) 13446 { 13447 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM)) != 0) 13448 return c_finish_omp_clauses (clauses, true, true); 13449 return c_finish_omp_clauses (clauses, true); 13450 } 13451 13452 return clauses; 13453 } 13454 13455 /* OpenACC 2.0, OpenMP 2.5: 13456 structured-block: 13457 statement 13458 13459 In practice, we're also interested in adding the statement to an 13460 outer node. So it is convenient if we work around the fact that 13461 c_parser_statement calls add_stmt. */ 13462 13463 static tree 13464 c_parser_omp_structured_block (c_parser *parser, bool *if_p) 13465 { 13466 tree stmt = push_stmt_list (); 13467 c_parser_statement (parser, if_p); 13468 return pop_stmt_list (stmt); 13469 } 13470 13471 /* OpenACC 2.0: 13472 # pragma acc cache (variable-list) new-line 13473 13474 LOC is the location of the #pragma token. 13475 */ 13476 13477 static tree 13478 c_parser_oacc_cache (location_t loc, c_parser *parser) 13479 { 13480 tree stmt, clauses; 13481 13482 clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE__CACHE_, NULL); 13483 clauses = c_finish_omp_clauses (clauses, false); 13484 13485 c_parser_skip_to_pragma_eol (parser); 13486 13487 stmt = make_node (OACC_CACHE); 13488 TREE_TYPE (stmt) = void_type_node; 13489 OACC_CACHE_CLAUSES (stmt) = clauses; 13490 SET_EXPR_LOCATION (stmt, loc); 13491 add_stmt (stmt); 13492 13493 return stmt; 13494 } 13495 13496 /* OpenACC 2.0: 13497 # pragma acc data oacc-data-clause[optseq] new-line 13498 structured-block 13499 13500 LOC is the location of the #pragma token. 13501 */ 13502 13503 #define OACC_DATA_CLAUSE_MASK \ 13504 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \ 13505 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ 13506 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ 13507 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ 13508 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \ 13509 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ 13510 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ 13511 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \ 13512 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \ 13513 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \ 13514 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) ) 13515 13516 static tree 13517 c_parser_oacc_data (location_t loc, c_parser *parser, bool *if_p) 13518 { 13519 tree stmt, clauses, block; 13520 13521 clauses = c_parser_oacc_all_clauses (parser, OACC_DATA_CLAUSE_MASK, 13522 "#pragma acc data"); 13523 13524 block = c_begin_omp_parallel (); 13525 add_stmt (c_parser_omp_structured_block (parser, if_p)); 13526 13527 stmt = c_finish_oacc_data (loc, clauses, block); 13528 13529 return stmt; 13530 } 13531 13532 /* OpenACC 2.0: 13533 # pragma acc declare oacc-data-clause[optseq] new-line 13534 */ 13535 13536 #define OACC_DECLARE_CLAUSE_MASK \ 13537 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \ 13538 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ 13539 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ 13540 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ 13541 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \ 13542 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \ 13543 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \ 13544 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ 13545 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \ 13546 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \ 13547 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \ 13548 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) ) 13549 13550 static void 13551 c_parser_oacc_declare (c_parser *parser) 13552 { 13553 location_t pragma_loc = c_parser_peek_token (parser)->location; 13554 tree clauses, stmt, t, decl; 13555 13556 bool error = false; 13557 13558 c_parser_consume_pragma (parser); 13559 13560 clauses = c_parser_oacc_all_clauses (parser, OACC_DECLARE_CLAUSE_MASK, 13561 "#pragma acc declare"); 13562 if (!clauses) 13563 { 13564 error_at (pragma_loc, 13565 "no valid clauses specified in %<#pragma acc declare%>"); 13566 return; 13567 } 13568 13569 for (t = clauses; t; t = OMP_CLAUSE_CHAIN (t)) 13570 { 13571 location_t loc = OMP_CLAUSE_LOCATION (t); 13572 decl = OMP_CLAUSE_DECL (t); 13573 if (!DECL_P (decl)) 13574 { 13575 error_at (loc, "array section in %<#pragma acc declare%>"); 13576 error = true; 13577 continue; 13578 } 13579 13580 switch (OMP_CLAUSE_MAP_KIND (t)) 13581 { 13582 case GOMP_MAP_FORCE_ALLOC: 13583 case GOMP_MAP_FORCE_TO: 13584 case GOMP_MAP_FORCE_DEVICEPTR: 13585 case GOMP_MAP_DEVICE_RESIDENT: 13586 break; 13587 13588 case GOMP_MAP_POINTER: 13589 /* Generated by c_finish_omp_clauses from array sections; 13590 avoid spurious diagnostics. */ 13591 break; 13592 13593 case GOMP_MAP_LINK: 13594 if (!global_bindings_p () 13595 && (TREE_STATIC (decl) 13596 || !DECL_EXTERNAL (decl))) 13597 { 13598 error_at (loc, 13599 "%qD must be a global variable in" 13600 "%<#pragma acc declare link%>", 13601 decl); 13602 error = true; 13603 continue; 13604 } 13605 break; 13606 13607 default: 13608 if (global_bindings_p ()) 13609 { 13610 error_at (loc, "invalid OpenACC clause at file scope"); 13611 error = true; 13612 continue; 13613 } 13614 if (DECL_EXTERNAL (decl)) 13615 { 13616 error_at (loc, 13617 "invalid use of %<extern%> variable %qD " 13618 "in %<#pragma acc declare%>", decl); 13619 error = true; 13620 continue; 13621 } 13622 else if (TREE_PUBLIC (decl)) 13623 { 13624 error_at (loc, 13625 "invalid use of %<global%> variable %qD " 13626 "in %<#pragma acc declare%>", decl); 13627 error = true; 13628 continue; 13629 } 13630 break; 13631 } 13632 13633 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl)) 13634 || lookup_attribute ("omp declare target link", 13635 DECL_ATTRIBUTES (decl))) 13636 { 13637 error_at (loc, "variable %qD used more than once with " 13638 "%<#pragma acc declare%>", decl); 13639 error = true; 13640 continue; 13641 } 13642 13643 if (!error) 13644 { 13645 tree id; 13646 13647 if (OMP_CLAUSE_MAP_KIND (t) == GOMP_MAP_LINK) 13648 id = get_identifier ("omp declare target link"); 13649 else 13650 id = get_identifier ("omp declare target"); 13651 13652 DECL_ATTRIBUTES (decl) 13653 = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (decl)); 13654 13655 if (global_bindings_p ()) 13656 { 13657 symtab_node *node = symtab_node::get (decl); 13658 if (node != NULL) 13659 { 13660 node->offloadable = 1; 13661 if (ENABLE_OFFLOADING) 13662 { 13663 g->have_offload = true; 13664 if (is_a <varpool_node *> (node)) 13665 vec_safe_push (offload_vars, decl); 13666 } 13667 } 13668 } 13669 } 13670 } 13671 13672 if (error || global_bindings_p ()) 13673 return; 13674 13675 stmt = make_node (OACC_DECLARE); 13676 TREE_TYPE (stmt) = void_type_node; 13677 OACC_DECLARE_CLAUSES (stmt) = clauses; 13678 SET_EXPR_LOCATION (stmt, pragma_loc); 13679 13680 add_stmt (stmt); 13681 13682 return; 13683 } 13684 13685 /* OpenACC 2.0: 13686 # pragma acc enter data oacc-enter-data-clause[optseq] new-line 13687 13688 or 13689 13690 # pragma acc exit data oacc-exit-data-clause[optseq] new-line 13691 13692 13693 LOC is the location of the #pragma token. 13694 */ 13695 13696 #define OACC_ENTER_DATA_CLAUSE_MASK \ 13697 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ 13698 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ 13699 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ 13700 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ 13701 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \ 13702 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \ 13703 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) 13704 13705 #define OACC_EXIT_DATA_CLAUSE_MASK \ 13706 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ 13707 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ 13708 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ 13709 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \ 13710 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) 13711 13712 static void 13713 c_parser_oacc_enter_exit_data (c_parser *parser, bool enter) 13714 { 13715 location_t loc = c_parser_peek_token (parser)->location; 13716 tree clauses, stmt; 13717 13718 c_parser_consume_pragma (parser); 13719 13720 if (!c_parser_next_token_is (parser, CPP_NAME)) 13721 { 13722 c_parser_error (parser, enter 13723 ? "expected %<data%> in %<#pragma acc enter data%>" 13724 : "expected %<data%> in %<#pragma acc exit data%>"); 13725 c_parser_skip_to_pragma_eol (parser); 13726 return; 13727 } 13728 13729 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 13730 if (strcmp (p, "data") != 0) 13731 { 13732 c_parser_error (parser, "invalid pragma"); 13733 c_parser_skip_to_pragma_eol (parser); 13734 return; 13735 } 13736 13737 c_parser_consume_token (parser); 13738 13739 if (enter) 13740 clauses = c_parser_oacc_all_clauses (parser, OACC_ENTER_DATA_CLAUSE_MASK, 13741 "#pragma acc enter data"); 13742 else 13743 clauses = c_parser_oacc_all_clauses (parser, OACC_EXIT_DATA_CLAUSE_MASK, 13744 "#pragma acc exit data"); 13745 13746 if (find_omp_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE) 13747 { 13748 error_at (loc, enter 13749 ? "%<#pragma acc enter data%> has no data movement clause" 13750 : "%<#pragma acc exit data%> has no data movement clause"); 13751 return; 13752 } 13753 13754 stmt = enter ? make_node (OACC_ENTER_DATA) : make_node (OACC_EXIT_DATA); 13755 TREE_TYPE (stmt) = void_type_node; 13756 OMP_STANDALONE_CLAUSES (stmt) = clauses; 13757 SET_EXPR_LOCATION (stmt, loc); 13758 add_stmt (stmt); 13759 } 13760 13761 13762 /* OpenACC 2.0: 13763 # pragma acc host_data oacc-data-clause[optseq] new-line 13764 structured-block 13765 */ 13766 13767 #define OACC_HOST_DATA_CLAUSE_MASK \ 13768 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) ) 13769 13770 static tree 13771 c_parser_oacc_host_data (location_t loc, c_parser *parser, bool *if_p) 13772 { 13773 tree stmt, clauses, block; 13774 13775 clauses = c_parser_oacc_all_clauses (parser, OACC_HOST_DATA_CLAUSE_MASK, 13776 "#pragma acc host_data"); 13777 13778 block = c_begin_omp_parallel (); 13779 add_stmt (c_parser_omp_structured_block (parser, if_p)); 13780 stmt = c_finish_oacc_host_data (loc, clauses, block); 13781 return stmt; 13782 } 13783 13784 13785 /* OpenACC 2.0: 13786 13787 # pragma acc loop oacc-loop-clause[optseq] new-line 13788 structured-block 13789 13790 LOC is the location of the #pragma token. 13791 */ 13792 13793 #define OACC_LOOP_CLAUSE_MASK \ 13794 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \ 13795 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \ 13796 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \ 13797 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \ 13798 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \ 13799 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \ 13800 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \ 13801 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \ 13802 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \ 13803 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) ) 13804 static tree 13805 c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name, 13806 omp_clause_mask mask, tree *cclauses, bool *if_p) 13807 { 13808 bool is_parallel = ((mask >> PRAGMA_OACC_CLAUSE_REDUCTION) & 1) == 1; 13809 13810 strcat (p_name, " loop"); 13811 mask |= OACC_LOOP_CLAUSE_MASK; 13812 13813 tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name, 13814 cclauses == NULL); 13815 if (cclauses) 13816 { 13817 clauses = c_oacc_split_loop_clauses (clauses, cclauses, is_parallel); 13818 if (*cclauses) 13819 *cclauses = c_finish_omp_clauses (*cclauses, false); 13820 if (clauses) 13821 clauses = c_finish_omp_clauses (clauses, false); 13822 } 13823 13824 tree block = c_begin_compound_stmt (true); 13825 tree stmt = c_parser_omp_for_loop (loc, parser, OACC_LOOP, clauses, NULL, 13826 if_p); 13827 block = c_end_compound_stmt (loc, block, true); 13828 add_stmt (block); 13829 13830 return stmt; 13831 } 13832 13833 /* OpenACC 2.0: 13834 # pragma acc kernels oacc-kernels-clause[optseq] new-line 13835 structured-block 13836 13837 or 13838 13839 # pragma acc parallel oacc-parallel-clause[optseq] new-line 13840 structured-block 13841 13842 LOC is the location of the #pragma token. 13843 */ 13844 13845 #define OACC_KERNELS_CLAUSE_MASK \ 13846 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ 13847 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \ 13848 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ 13849 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ 13850 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ 13851 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \ 13852 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \ 13853 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ 13854 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ 13855 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \ 13856 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \ 13857 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \ 13858 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \ 13859 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) 13860 13861 #define OACC_PARALLEL_CLAUSE_MASK \ 13862 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ 13863 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \ 13864 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ 13865 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ 13866 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ 13867 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \ 13868 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \ 13869 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ 13870 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \ 13871 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \ 13872 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \ 13873 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \ 13874 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ 13875 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \ 13876 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \ 13877 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \ 13878 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \ 13879 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \ 13880 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \ 13881 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) 13882 13883 static tree 13884 c_parser_oacc_kernels_parallel (location_t loc, c_parser *parser, 13885 enum pragma_kind p_kind, char *p_name, 13886 bool *if_p) 13887 { 13888 omp_clause_mask mask; 13889 enum tree_code code; 13890 switch (p_kind) 13891 { 13892 case PRAGMA_OACC_KERNELS: 13893 strcat (p_name, " kernels"); 13894 mask = OACC_KERNELS_CLAUSE_MASK; 13895 code = OACC_KERNELS; 13896 break; 13897 case PRAGMA_OACC_PARALLEL: 13898 strcat (p_name, " parallel"); 13899 mask = OACC_PARALLEL_CLAUSE_MASK; 13900 code = OACC_PARALLEL; 13901 break; 13902 default: 13903 gcc_unreachable (); 13904 } 13905 13906 if (c_parser_next_token_is (parser, CPP_NAME)) 13907 { 13908 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 13909 if (strcmp (p, "loop") == 0) 13910 { 13911 c_parser_consume_token (parser); 13912 tree block = c_begin_omp_parallel (); 13913 tree clauses; 13914 c_parser_oacc_loop (loc, parser, p_name, mask, &clauses, if_p); 13915 return c_finish_omp_construct (loc, code, block, clauses); 13916 } 13917 } 13918 13919 tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name); 13920 13921 tree block = c_begin_omp_parallel (); 13922 add_stmt (c_parser_omp_structured_block (parser, if_p)); 13923 13924 return c_finish_omp_construct (loc, code, block, clauses); 13925 } 13926 13927 /* OpenACC 2.0: 13928 # pragma acc routine oacc-routine-clause[optseq] new-line 13929 function-definition 13930 13931 # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line 13932 */ 13933 13934 #define OACC_ROUTINE_CLAUSE_MASK \ 13935 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \ 13936 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \ 13937 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \ 13938 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) ) 13939 13940 /* Parse an OpenACC routine directive. For named directives, we apply 13941 immediately to the named function. For unnamed ones we then parse 13942 a declaration or definition, which must be for a function. */ 13943 13944 static void 13945 c_parser_oacc_routine (c_parser *parser, enum pragma_context context) 13946 { 13947 tree decl = NULL_TREE; 13948 /* Create a dummy claue, to record location. */ 13949 tree c_head = build_omp_clause (c_parser_peek_token (parser)->location, 13950 OMP_CLAUSE_SEQ); 13951 13952 if (context != pragma_external) 13953 c_parser_error (parser, "%<#pragma acc routine%> not at file scope"); 13954 13955 c_parser_consume_pragma (parser); 13956 13957 /* Scan for optional '( name )'. */ 13958 if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN) 13959 { 13960 c_parser_consume_token (parser); 13961 13962 c_token *token = c_parser_peek_token (parser); 13963 13964 if (token->type == CPP_NAME && (token->id_kind == C_ID_ID 13965 || token->id_kind == C_ID_TYPENAME)) 13966 { 13967 decl = lookup_name (token->value); 13968 if (!decl) 13969 { 13970 error_at (token->location, "%qE has not been declared", 13971 token->value); 13972 decl = error_mark_node; 13973 } 13974 } 13975 else 13976 c_parser_error (parser, "expected function name"); 13977 13978 if (token->type != CPP_CLOSE_PAREN) 13979 c_parser_consume_token (parser); 13980 13981 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); 13982 } 13983 13984 /* Build a chain of clauses. */ 13985 parser->in_pragma = true; 13986 tree clauses = c_parser_oacc_all_clauses 13987 (parser, OACC_ROUTINE_CLAUSE_MASK, "#pragma acc routine"); 13988 13989 /* Force clauses to be non-null, by attaching context to it. */ 13990 clauses = tree_cons (c_head, clauses, NULL_TREE); 13991 13992 if (decl) 13993 c_finish_oacc_routine (parser, decl, clauses, true, true, false); 13994 else if (c_parser_peek_token (parser)->type == CPP_PRAGMA) 13995 /* This will emit an error. */ 13996 c_finish_oacc_routine (parser, NULL_TREE, clauses, false, true, false); 13997 else 13998 c_parser_declaration_or_fndef (parser, true, false, false, false, 13999 true, NULL, vNULL, clauses); 14000 } 14001 14002 /* Finalize an OpenACC routine pragma, applying it to FNDECL. CLAUSES 14003 are the parsed clauses. IS_DEFN is true if we're applying it to 14004 the definition (so expect FNDEF to look somewhat defined. */ 14005 14006 static void 14007 c_finish_oacc_routine (c_parser *ARG_UNUSED (parser), tree fndecl, 14008 tree clauses, bool named, bool first, bool is_defn) 14009 { 14010 location_t loc = OMP_CLAUSE_LOCATION (TREE_PURPOSE (clauses)); 14011 14012 if (!fndecl || TREE_CODE (fndecl) != FUNCTION_DECL || !first) 14013 { 14014 if (fndecl != error_mark_node) 14015 error_at (loc, "%<#pragma acc routine%> %s", 14016 named ? "does not refer to a function" 14017 : "not followed by single function"); 14018 return; 14019 } 14020 14021 if (get_oacc_fn_attrib (fndecl)) 14022 error_at (loc, "%<#pragma acc routine%> already applied to %D", fndecl); 14023 14024 if (TREE_USED (fndecl) || (!is_defn && DECL_SAVED_TREE (fndecl))) 14025 error_at (loc, "%<#pragma acc routine%> must be applied before %s", 14026 TREE_USED (fndecl) ? "use" : "definition"); 14027 14028 /* Process for function attrib */ 14029 tree dims = build_oacc_routine_dims (TREE_VALUE (clauses)); 14030 replace_oacc_fn_attrib (fndecl, dims); 14031 14032 /* Also attach as a declare. */ 14033 DECL_ATTRIBUTES (fndecl) 14034 = tree_cons (get_identifier ("omp declare target"), 14035 clauses, DECL_ATTRIBUTES (fndecl)); 14036 } 14037 14038 /* OpenACC 2.0: 14039 # pragma acc update oacc-update-clause[optseq] new-line 14040 */ 14041 14042 #define OACC_UPDATE_CLAUSE_MASK \ 14043 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ 14044 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \ 14045 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \ 14046 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ 14047 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \ 14048 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) 14049 14050 static void 14051 c_parser_oacc_update (c_parser *parser) 14052 { 14053 location_t loc = c_parser_peek_token (parser)->location; 14054 14055 c_parser_consume_pragma (parser); 14056 14057 tree clauses = c_parser_oacc_all_clauses (parser, OACC_UPDATE_CLAUSE_MASK, 14058 "#pragma acc update"); 14059 if (find_omp_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE) 14060 { 14061 error_at (loc, 14062 "%<#pragma acc update%> must contain at least one " 14063 "%<device%> or %<host%> or %<self%> clause"); 14064 return; 14065 } 14066 14067 if (parser->error) 14068 return; 14069 14070 tree stmt = make_node (OACC_UPDATE); 14071 TREE_TYPE (stmt) = void_type_node; 14072 OACC_UPDATE_CLAUSES (stmt) = clauses; 14073 SET_EXPR_LOCATION (stmt, loc); 14074 add_stmt (stmt); 14075 } 14076 14077 /* OpenACC 2.0: 14078 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line 14079 14080 LOC is the location of the #pragma token. 14081 */ 14082 14083 #define OACC_WAIT_CLAUSE_MASK \ 14084 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) ) 14085 14086 static tree 14087 c_parser_oacc_wait (location_t loc, c_parser *parser, char *p_name) 14088 { 14089 tree clauses, list = NULL_TREE, stmt = NULL_TREE; 14090 14091 if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN) 14092 list = c_parser_oacc_wait_list (parser, loc, list); 14093 14094 strcpy (p_name, " wait"); 14095 clauses = c_parser_oacc_all_clauses (parser, OACC_WAIT_CLAUSE_MASK, p_name); 14096 stmt = c_finish_oacc_wait (loc, list, clauses); 14097 add_stmt (stmt); 14098 14099 return stmt; 14100 } 14101 14102 /* OpenMP 2.5: 14103 # pragma omp atomic new-line 14104 expression-stmt 14105 14106 expression-stmt: 14107 x binop= expr | x++ | ++x | x-- | --x 14108 binop: 14109 +, *, -, /, &, ^, |, <<, >> 14110 14111 where x is an lvalue expression with scalar type. 14112 14113 OpenMP 3.1: 14114 # pragma omp atomic new-line 14115 update-stmt 14116 14117 # pragma omp atomic read new-line 14118 read-stmt 14119 14120 # pragma omp atomic write new-line 14121 write-stmt 14122 14123 # pragma omp atomic update new-line 14124 update-stmt 14125 14126 # pragma omp atomic capture new-line 14127 capture-stmt 14128 14129 # pragma omp atomic capture new-line 14130 capture-block 14131 14132 read-stmt: 14133 v = x 14134 write-stmt: 14135 x = expr 14136 update-stmt: 14137 expression-stmt | x = x binop expr 14138 capture-stmt: 14139 v = expression-stmt 14140 capture-block: 14141 { v = x; update-stmt; } | { update-stmt; v = x; } 14142 14143 OpenMP 4.0: 14144 update-stmt: 14145 expression-stmt | x = x binop expr | x = expr binop x 14146 capture-stmt: 14147 v = update-stmt 14148 capture-block: 14149 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; } 14150 14151 where x and v are lvalue expressions with scalar type. 14152 14153 LOC is the location of the #pragma token. */ 14154 14155 static void 14156 c_parser_omp_atomic (location_t loc, c_parser *parser) 14157 { 14158 tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE; 14159 tree lhs1 = NULL_TREE, rhs1 = NULL_TREE; 14160 tree stmt, orig_lhs, unfolded_lhs = NULL_TREE, unfolded_lhs1 = NULL_TREE; 14161 enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR; 14162 struct c_expr expr; 14163 location_t eloc; 14164 bool structured_block = false; 14165 bool swapped = false; 14166 bool seq_cst = false; 14167 bool non_lvalue_p; 14168 14169 if (c_parser_next_token_is (parser, CPP_NAME)) 14170 { 14171 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 14172 if (!strcmp (p, "seq_cst")) 14173 { 14174 seq_cst = true; 14175 c_parser_consume_token (parser); 14176 if (c_parser_next_token_is (parser, CPP_COMMA) 14177 && c_parser_peek_2nd_token (parser)->type == CPP_NAME) 14178 c_parser_consume_token (parser); 14179 } 14180 } 14181 if (c_parser_next_token_is (parser, CPP_NAME)) 14182 { 14183 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 14184 14185 if (!strcmp (p, "read")) 14186 code = OMP_ATOMIC_READ; 14187 else if (!strcmp (p, "write")) 14188 code = NOP_EXPR; 14189 else if (!strcmp (p, "update")) 14190 code = OMP_ATOMIC; 14191 else if (!strcmp (p, "capture")) 14192 code = OMP_ATOMIC_CAPTURE_NEW; 14193 else 14194 p = NULL; 14195 if (p) 14196 c_parser_consume_token (parser); 14197 } 14198 if (!seq_cst) 14199 { 14200 if (c_parser_next_token_is (parser, CPP_COMMA) 14201 && c_parser_peek_2nd_token (parser)->type == CPP_NAME) 14202 c_parser_consume_token (parser); 14203 14204 if (c_parser_next_token_is (parser, CPP_NAME)) 14205 { 14206 const char *p 14207 = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 14208 if (!strcmp (p, "seq_cst")) 14209 { 14210 seq_cst = true; 14211 c_parser_consume_token (parser); 14212 } 14213 } 14214 } 14215 c_parser_skip_to_pragma_eol (parser); 14216 14217 switch (code) 14218 { 14219 case OMP_ATOMIC_READ: 14220 case NOP_EXPR: /* atomic write */ 14221 v = c_parser_cast_expression (parser, NULL).value; 14222 non_lvalue_p = !lvalue_p (v); 14223 v = c_fully_fold (v, false, NULL); 14224 if (v == error_mark_node) 14225 goto saw_error; 14226 if (non_lvalue_p) 14227 v = non_lvalue (v); 14228 loc = c_parser_peek_token (parser)->location; 14229 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) 14230 goto saw_error; 14231 if (code == NOP_EXPR) 14232 { 14233 lhs = c_parser_expression (parser).value; 14234 lhs = c_fully_fold (lhs, false, NULL); 14235 if (lhs == error_mark_node) 14236 goto saw_error; 14237 } 14238 else 14239 { 14240 lhs = c_parser_cast_expression (parser, NULL).value; 14241 non_lvalue_p = !lvalue_p (lhs); 14242 lhs = c_fully_fold (lhs, false, NULL); 14243 if (lhs == error_mark_node) 14244 goto saw_error; 14245 if (non_lvalue_p) 14246 lhs = non_lvalue (lhs); 14247 } 14248 if (code == NOP_EXPR) 14249 { 14250 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR 14251 opcode. */ 14252 code = OMP_ATOMIC; 14253 rhs = lhs; 14254 lhs = v; 14255 v = NULL_TREE; 14256 } 14257 goto done; 14258 case OMP_ATOMIC_CAPTURE_NEW: 14259 if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) 14260 { 14261 c_parser_consume_token (parser); 14262 structured_block = true; 14263 } 14264 else 14265 { 14266 v = c_parser_cast_expression (parser, NULL).value; 14267 non_lvalue_p = !lvalue_p (v); 14268 v = c_fully_fold (v, false, NULL); 14269 if (v == error_mark_node) 14270 goto saw_error; 14271 if (non_lvalue_p) 14272 v = non_lvalue (v); 14273 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) 14274 goto saw_error; 14275 } 14276 break; 14277 default: 14278 break; 14279 } 14280 14281 /* For structured_block case we don't know yet whether 14282 old or new x should be captured. */ 14283 restart: 14284 eloc = c_parser_peek_token (parser)->location; 14285 expr = c_parser_cast_expression (parser, NULL); 14286 lhs = expr.value; 14287 expr = default_function_array_conversion (eloc, expr); 14288 unfolded_lhs = expr.value; 14289 lhs = c_fully_fold (lhs, false, NULL); 14290 orig_lhs = lhs; 14291 switch (TREE_CODE (lhs)) 14292 { 14293 case ERROR_MARK: 14294 saw_error: 14295 c_parser_skip_to_end_of_block_or_statement (parser); 14296 if (structured_block) 14297 { 14298 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) 14299 c_parser_consume_token (parser); 14300 else if (code == OMP_ATOMIC_CAPTURE_NEW) 14301 { 14302 c_parser_skip_to_end_of_block_or_statement (parser); 14303 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) 14304 c_parser_consume_token (parser); 14305 } 14306 } 14307 return; 14308 14309 case POSTINCREMENT_EXPR: 14310 if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block) 14311 code = OMP_ATOMIC_CAPTURE_OLD; 14312 /* FALLTHROUGH */ 14313 case PREINCREMENT_EXPR: 14314 lhs = TREE_OPERAND (lhs, 0); 14315 unfolded_lhs = NULL_TREE; 14316 opcode = PLUS_EXPR; 14317 rhs = integer_one_node; 14318 break; 14319 14320 case POSTDECREMENT_EXPR: 14321 if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block) 14322 code = OMP_ATOMIC_CAPTURE_OLD; 14323 /* FALLTHROUGH */ 14324 case PREDECREMENT_EXPR: 14325 lhs = TREE_OPERAND (lhs, 0); 14326 unfolded_lhs = NULL_TREE; 14327 opcode = MINUS_EXPR; 14328 rhs = integer_one_node; 14329 break; 14330 14331 case COMPOUND_EXPR: 14332 if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR 14333 && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR 14334 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR 14335 && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0) 14336 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND 14337 (TREE_OPERAND (lhs, 1), 0), 0))) 14338 == BOOLEAN_TYPE) 14339 /* Undo effects of boolean_increment for post {in,de}crement. */ 14340 lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0); 14341 /* FALLTHRU */ 14342 case MODIFY_EXPR: 14343 if (TREE_CODE (lhs) == MODIFY_EXPR 14344 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE) 14345 { 14346 /* Undo effects of boolean_increment. */ 14347 if (integer_onep (TREE_OPERAND (lhs, 1))) 14348 { 14349 /* This is pre or post increment. */ 14350 rhs = TREE_OPERAND (lhs, 1); 14351 lhs = TREE_OPERAND (lhs, 0); 14352 unfolded_lhs = NULL_TREE; 14353 opcode = NOP_EXPR; 14354 if (code == OMP_ATOMIC_CAPTURE_NEW 14355 && !structured_block 14356 && TREE_CODE (orig_lhs) == COMPOUND_EXPR) 14357 code = OMP_ATOMIC_CAPTURE_OLD; 14358 break; 14359 } 14360 if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR 14361 && TREE_OPERAND (lhs, 0) 14362 == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) 14363 { 14364 /* This is pre or post decrement. */ 14365 rhs = TREE_OPERAND (lhs, 1); 14366 lhs = TREE_OPERAND (lhs, 0); 14367 unfolded_lhs = NULL_TREE; 14368 opcode = NOP_EXPR; 14369 if (code == OMP_ATOMIC_CAPTURE_NEW 14370 && !structured_block 14371 && TREE_CODE (orig_lhs) == COMPOUND_EXPR) 14372 code = OMP_ATOMIC_CAPTURE_OLD; 14373 break; 14374 } 14375 } 14376 /* FALLTHRU */ 14377 default: 14378 if (!lvalue_p (unfolded_lhs)) 14379 lhs = non_lvalue (lhs); 14380 switch (c_parser_peek_token (parser)->type) 14381 { 14382 case CPP_MULT_EQ: 14383 opcode = MULT_EXPR; 14384 break; 14385 case CPP_DIV_EQ: 14386 opcode = TRUNC_DIV_EXPR; 14387 break; 14388 case CPP_PLUS_EQ: 14389 opcode = PLUS_EXPR; 14390 break; 14391 case CPP_MINUS_EQ: 14392 opcode = MINUS_EXPR; 14393 break; 14394 case CPP_LSHIFT_EQ: 14395 opcode = LSHIFT_EXPR; 14396 break; 14397 case CPP_RSHIFT_EQ: 14398 opcode = RSHIFT_EXPR; 14399 break; 14400 case CPP_AND_EQ: 14401 opcode = BIT_AND_EXPR; 14402 break; 14403 case CPP_OR_EQ: 14404 opcode = BIT_IOR_EXPR; 14405 break; 14406 case CPP_XOR_EQ: 14407 opcode = BIT_XOR_EXPR; 14408 break; 14409 case CPP_EQ: 14410 c_parser_consume_token (parser); 14411 eloc = c_parser_peek_token (parser)->location; 14412 expr = c_parser_expr_no_commas (parser, NULL, unfolded_lhs); 14413 rhs1 = expr.value; 14414 switch (TREE_CODE (rhs1)) 14415 { 14416 case MULT_EXPR: 14417 case TRUNC_DIV_EXPR: 14418 case RDIV_EXPR: 14419 case PLUS_EXPR: 14420 case MINUS_EXPR: 14421 case LSHIFT_EXPR: 14422 case RSHIFT_EXPR: 14423 case BIT_AND_EXPR: 14424 case BIT_IOR_EXPR: 14425 case BIT_XOR_EXPR: 14426 if (c_tree_equal (TREE_OPERAND (rhs1, 0), unfolded_lhs)) 14427 { 14428 opcode = TREE_CODE (rhs1); 14429 rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL); 14430 rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL); 14431 goto stmt_done; 14432 } 14433 if (c_tree_equal (TREE_OPERAND (rhs1, 1), unfolded_lhs)) 14434 { 14435 opcode = TREE_CODE (rhs1); 14436 rhs = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL); 14437 rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL); 14438 swapped = !commutative_tree_code (opcode); 14439 goto stmt_done; 14440 } 14441 break; 14442 case ERROR_MARK: 14443 goto saw_error; 14444 default: 14445 break; 14446 } 14447 if (c_parser_peek_token (parser)->type == CPP_SEMICOLON) 14448 { 14449 if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW) 14450 { 14451 code = OMP_ATOMIC_CAPTURE_OLD; 14452 v = lhs; 14453 lhs = NULL_TREE; 14454 expr = default_function_array_read_conversion (eloc, expr); 14455 unfolded_lhs1 = expr.value; 14456 lhs1 = c_fully_fold (unfolded_lhs1, false, NULL); 14457 rhs1 = NULL_TREE; 14458 c_parser_consume_token (parser); 14459 goto restart; 14460 } 14461 if (structured_block) 14462 { 14463 opcode = NOP_EXPR; 14464 expr = default_function_array_read_conversion (eloc, expr); 14465 rhs = c_fully_fold (expr.value, false, NULL); 14466 rhs1 = NULL_TREE; 14467 goto stmt_done; 14468 } 14469 } 14470 c_parser_error (parser, "invalid form of %<#pragma omp atomic%>"); 14471 goto saw_error; 14472 default: 14473 c_parser_error (parser, 14474 "invalid operator for %<#pragma omp atomic%>"); 14475 goto saw_error; 14476 } 14477 14478 /* Arrange to pass the location of the assignment operator to 14479 c_finish_omp_atomic. */ 14480 loc = c_parser_peek_token (parser)->location; 14481 c_parser_consume_token (parser); 14482 eloc = c_parser_peek_token (parser)->location; 14483 expr = c_parser_expression (parser); 14484 expr = default_function_array_read_conversion (eloc, expr); 14485 rhs = expr.value; 14486 rhs = c_fully_fold (rhs, false, NULL); 14487 break; 14488 } 14489 stmt_done: 14490 if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW) 14491 { 14492 if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) 14493 goto saw_error; 14494 v = c_parser_cast_expression (parser, NULL).value; 14495 non_lvalue_p = !lvalue_p (v); 14496 v = c_fully_fold (v, false, NULL); 14497 if (v == error_mark_node) 14498 goto saw_error; 14499 if (non_lvalue_p) 14500 v = non_lvalue (v); 14501 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) 14502 goto saw_error; 14503 eloc = c_parser_peek_token (parser)->location; 14504 expr = c_parser_cast_expression (parser, NULL); 14505 lhs1 = expr.value; 14506 expr = default_function_array_read_conversion (eloc, expr); 14507 unfolded_lhs1 = expr.value; 14508 lhs1 = c_fully_fold (lhs1, false, NULL); 14509 if (lhs1 == error_mark_node) 14510 goto saw_error; 14511 if (!lvalue_p (unfolded_lhs1)) 14512 lhs1 = non_lvalue (lhs1); 14513 } 14514 if (structured_block) 14515 { 14516 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 14517 c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>"); 14518 } 14519 done: 14520 if (unfolded_lhs && unfolded_lhs1 14521 && !c_tree_equal (unfolded_lhs, unfolded_lhs1)) 14522 { 14523 error ("%<#pragma omp atomic capture%> uses two different " 14524 "expressions for memory"); 14525 stmt = error_mark_node; 14526 } 14527 else 14528 stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1, 14529 swapped, seq_cst); 14530 if (stmt != error_mark_node) 14531 add_stmt (stmt); 14532 14533 if (!structured_block) 14534 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 14535 } 14536 14537 14538 /* OpenMP 2.5: 14539 # pragma omp barrier new-line 14540 */ 14541 14542 static void 14543 c_parser_omp_barrier (c_parser *parser) 14544 { 14545 location_t loc = c_parser_peek_token (parser)->location; 14546 c_parser_consume_pragma (parser); 14547 c_parser_skip_to_pragma_eol (parser); 14548 14549 c_finish_omp_barrier (loc); 14550 } 14551 14552 /* OpenMP 2.5: 14553 # pragma omp critical [(name)] new-line 14554 structured-block 14555 14556 OpenMP 4.5: 14557 # pragma omp critical [(name) [hint(expression)]] new-line 14558 14559 LOC is the location of the #pragma itself. */ 14560 14561 #define OMP_CRITICAL_CLAUSE_MASK \ 14562 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) ) 14563 14564 static tree 14565 c_parser_omp_critical (location_t loc, c_parser *parser, bool *if_p) 14566 { 14567 tree stmt, name = NULL_TREE, clauses = NULL_TREE; 14568 14569 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) 14570 { 14571 c_parser_consume_token (parser); 14572 if (c_parser_next_token_is (parser, CPP_NAME)) 14573 { 14574 name = c_parser_peek_token (parser)->value; 14575 c_parser_consume_token (parser); 14576 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 14577 } 14578 else 14579 c_parser_error (parser, "expected identifier"); 14580 14581 clauses = c_parser_omp_all_clauses (parser, 14582 OMP_CRITICAL_CLAUSE_MASK, 14583 "#pragma omp critical"); 14584 } 14585 else 14586 { 14587 if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) 14588 c_parser_error (parser, "expected %<(%> or end of line"); 14589 c_parser_skip_to_pragma_eol (parser); 14590 } 14591 14592 stmt = c_parser_omp_structured_block (parser, if_p); 14593 return c_finish_omp_critical (loc, stmt, name, clauses); 14594 } 14595 14596 /* OpenMP 2.5: 14597 # pragma omp flush flush-vars[opt] new-line 14598 14599 flush-vars: 14600 ( variable-list ) */ 14601 14602 static void 14603 c_parser_omp_flush (c_parser *parser) 14604 { 14605 location_t loc = c_parser_peek_token (parser)->location; 14606 c_parser_consume_pragma (parser); 14607 if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) 14608 c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); 14609 else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) 14610 c_parser_error (parser, "expected %<(%> or end of line"); 14611 c_parser_skip_to_pragma_eol (parser); 14612 14613 c_finish_omp_flush (loc); 14614 } 14615 14616 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP. 14617 The real trick here is to determine the loop control variable early 14618 so that we can push a new decl if necessary to make it private. 14619 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp", 14620 respectively. */ 14621 14622 static tree 14623 c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code, 14624 tree clauses, tree *cclauses, bool *if_p) 14625 { 14626 tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl; 14627 tree declv, condv, incrv, initv, ret = NULL_TREE; 14628 tree pre_body = NULL_TREE, this_pre_body; 14629 tree ordered_cl = NULL_TREE; 14630 bool fail = false, open_brace_parsed = false; 14631 int i, collapse = 1, ordered = 0, count, nbraces = 0; 14632 location_t for_loc; 14633 vec<tree, va_gc> *for_block = make_tree_vector (); 14634 14635 for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl)) 14636 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE) 14637 collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl)); 14638 else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_ORDERED 14639 && OMP_CLAUSE_ORDERED_EXPR (cl)) 14640 { 14641 ordered_cl = cl; 14642 ordered = tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl)); 14643 } 14644 14645 if (ordered && ordered < collapse) 14646 { 14647 error_at (OMP_CLAUSE_LOCATION (ordered_cl), 14648 "%<ordered%> clause parameter is less than %<collapse%>"); 14649 OMP_CLAUSE_ORDERED_EXPR (ordered_cl) 14650 = build_int_cst (NULL_TREE, collapse); 14651 ordered = collapse; 14652 } 14653 if (ordered) 14654 { 14655 for (tree *pc = &clauses; *pc; ) 14656 if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_LINEAR) 14657 { 14658 error_at (OMP_CLAUSE_LOCATION (*pc), 14659 "%<linear%> clause may not be specified together " 14660 "with %<ordered%> clause with a parameter"); 14661 *pc = OMP_CLAUSE_CHAIN (*pc); 14662 } 14663 else 14664 pc = &OMP_CLAUSE_CHAIN (*pc); 14665 } 14666 14667 gcc_assert (collapse >= 1 && ordered >= 0); 14668 count = ordered ? ordered : collapse; 14669 14670 declv = make_tree_vec (count); 14671 initv = make_tree_vec (count); 14672 condv = make_tree_vec (count); 14673 incrv = make_tree_vec (count); 14674 14675 if (code != CILK_FOR 14676 && !c_parser_next_token_is_keyword (parser, RID_FOR)) 14677 { 14678 c_parser_error (parser, "for statement expected"); 14679 return NULL; 14680 } 14681 if (code == CILK_FOR 14682 && !c_parser_next_token_is_keyword (parser, RID_CILK_FOR)) 14683 { 14684 c_parser_error (parser, "_Cilk_for statement expected"); 14685 return NULL; 14686 } 14687 for_loc = c_parser_peek_token (parser)->location; 14688 c_parser_consume_token (parser); 14689 14690 for (i = 0; i < count; i++) 14691 { 14692 int bracecount = 0; 14693 14694 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 14695 goto pop_scopes; 14696 14697 /* Parse the initialization declaration or expression. */ 14698 if (c_parser_next_tokens_start_declaration (parser)) 14699 { 14700 if (i > 0) 14701 vec_safe_push (for_block, c_begin_compound_stmt (true)); 14702 this_pre_body = push_stmt_list (); 14703 c_parser_declaration_or_fndef (parser, true, true, true, true, true, 14704 NULL, vNULL); 14705 if (this_pre_body) 14706 { 14707 this_pre_body = pop_stmt_list (this_pre_body); 14708 if (pre_body) 14709 { 14710 tree t = pre_body; 14711 pre_body = push_stmt_list (); 14712 add_stmt (t); 14713 add_stmt (this_pre_body); 14714 pre_body = pop_stmt_list (pre_body); 14715 } 14716 else 14717 pre_body = this_pre_body; 14718 } 14719 decl = check_for_loop_decls (for_loc, flag_isoc99); 14720 if (decl == NULL) 14721 goto error_init; 14722 if (DECL_INITIAL (decl) == error_mark_node) 14723 decl = error_mark_node; 14724 init = decl; 14725 } 14726 else if (c_parser_next_token_is (parser, CPP_NAME) 14727 && c_parser_peek_2nd_token (parser)->type == CPP_EQ) 14728 { 14729 struct c_expr decl_exp; 14730 struct c_expr init_exp; 14731 location_t init_loc; 14732 14733 decl_exp = c_parser_postfix_expression (parser); 14734 decl = decl_exp.value; 14735 14736 c_parser_require (parser, CPP_EQ, "expected %<=%>"); 14737 14738 init_loc = c_parser_peek_token (parser)->location; 14739 init_exp = c_parser_expr_no_commas (parser, NULL); 14740 init_exp = default_function_array_read_conversion (init_loc, 14741 init_exp); 14742 init = build_modify_expr (init_loc, decl, decl_exp.original_type, 14743 NOP_EXPR, init_loc, init_exp.value, 14744 init_exp.original_type); 14745 init = c_process_expr_stmt (init_loc, init); 14746 14747 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 14748 } 14749 else 14750 { 14751 error_init: 14752 c_parser_error (parser, 14753 "expected iteration declaration or initialization"); 14754 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 14755 "expected %<)%>"); 14756 fail = true; 14757 goto parse_next; 14758 } 14759 14760 /* Parse the loop condition. */ 14761 cond = NULL_TREE; 14762 if (c_parser_next_token_is_not (parser, CPP_SEMICOLON)) 14763 { 14764 location_t cond_loc = c_parser_peek_token (parser)->location; 14765 struct c_expr cond_expr 14766 = c_parser_binary_expression (parser, NULL, NULL_TREE); 14767 14768 cond = cond_expr.value; 14769 cond = c_objc_common_truthvalue_conversion (cond_loc, cond); 14770 if (COMPARISON_CLASS_P (cond)) 14771 { 14772 tree op0 = TREE_OPERAND (cond, 0), op1 = TREE_OPERAND (cond, 1); 14773 op0 = c_fully_fold (op0, false, NULL); 14774 op1 = c_fully_fold (op1, false, NULL); 14775 TREE_OPERAND (cond, 0) = op0; 14776 TREE_OPERAND (cond, 1) = op1; 14777 } 14778 switch (cond_expr.original_code) 14779 { 14780 case GT_EXPR: 14781 case GE_EXPR: 14782 case LT_EXPR: 14783 case LE_EXPR: 14784 break; 14785 case NE_EXPR: 14786 if (code == CILK_SIMD || code == CILK_FOR) 14787 break; 14788 /* FALLTHRU. */ 14789 default: 14790 /* Can't be cond = error_mark_node, because we want to preserve 14791 the location until c_finish_omp_for. */ 14792 cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node); 14793 break; 14794 } 14795 protected_set_expr_location (cond, cond_loc); 14796 } 14797 c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); 14798 14799 /* Parse the increment expression. */ 14800 incr = NULL_TREE; 14801 if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)) 14802 { 14803 location_t incr_loc = c_parser_peek_token (parser)->location; 14804 14805 incr = c_process_expr_stmt (incr_loc, 14806 c_parser_expression (parser).value); 14807 } 14808 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 14809 14810 if (decl == NULL || decl == error_mark_node || init == error_mark_node) 14811 fail = true; 14812 else 14813 { 14814 TREE_VEC_ELT (declv, i) = decl; 14815 TREE_VEC_ELT (initv, i) = init; 14816 TREE_VEC_ELT (condv, i) = cond; 14817 TREE_VEC_ELT (incrv, i) = incr; 14818 } 14819 14820 parse_next: 14821 if (i == count - 1) 14822 break; 14823 14824 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed 14825 in between the collapsed for loops to be still considered perfectly 14826 nested. Hopefully the final version clarifies this. 14827 For now handle (multiple) {'s and empty statements. */ 14828 do 14829 { 14830 if (c_parser_next_token_is_keyword (parser, RID_FOR)) 14831 { 14832 c_parser_consume_token (parser); 14833 break; 14834 } 14835 else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) 14836 { 14837 c_parser_consume_token (parser); 14838 bracecount++; 14839 } 14840 else if (bracecount 14841 && c_parser_next_token_is (parser, CPP_SEMICOLON)) 14842 c_parser_consume_token (parser); 14843 else 14844 { 14845 c_parser_error (parser, "not enough perfectly nested loops"); 14846 if (bracecount) 14847 { 14848 open_brace_parsed = true; 14849 bracecount--; 14850 } 14851 fail = true; 14852 count = 0; 14853 break; 14854 } 14855 } 14856 while (1); 14857 14858 nbraces += bracecount; 14859 } 14860 14861 if (nbraces) 14862 if_p = NULL; 14863 14864 save_break = c_break_label; 14865 if (code == CILK_SIMD) 14866 c_break_label = build_int_cst (size_type_node, 2); 14867 else 14868 c_break_label = size_one_node; 14869 save_cont = c_cont_label; 14870 c_cont_label = NULL_TREE; 14871 body = push_stmt_list (); 14872 14873 if (open_brace_parsed) 14874 { 14875 location_t here = c_parser_peek_token (parser)->location; 14876 stmt = c_begin_compound_stmt (true); 14877 c_parser_compound_statement_nostart (parser); 14878 add_stmt (c_end_compound_stmt (here, stmt, true)); 14879 } 14880 else 14881 add_stmt (c_parser_c99_block_statement (parser, if_p)); 14882 if (c_cont_label) 14883 { 14884 tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label); 14885 SET_EXPR_LOCATION (t, loc); 14886 add_stmt (t); 14887 } 14888 14889 body = pop_stmt_list (body); 14890 c_break_label = save_break; 14891 c_cont_label = save_cont; 14892 14893 while (nbraces) 14894 { 14895 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) 14896 { 14897 c_parser_consume_token (parser); 14898 nbraces--; 14899 } 14900 else if (c_parser_next_token_is (parser, CPP_SEMICOLON)) 14901 c_parser_consume_token (parser); 14902 else 14903 { 14904 c_parser_error (parser, "collapsed loops not perfectly nested"); 14905 while (nbraces) 14906 { 14907 location_t here = c_parser_peek_token (parser)->location; 14908 stmt = c_begin_compound_stmt (true); 14909 add_stmt (body); 14910 c_parser_compound_statement_nostart (parser); 14911 body = c_end_compound_stmt (here, stmt, true); 14912 nbraces--; 14913 } 14914 goto pop_scopes; 14915 } 14916 } 14917 14918 /* Only bother calling c_finish_omp_for if we haven't already generated 14919 an error from the initialization parsing. */ 14920 if (!fail) 14921 { 14922 stmt = c_finish_omp_for (loc, code, declv, NULL, initv, condv, 14923 incrv, body, pre_body); 14924 14925 /* Check for iterators appearing in lb, b or incr expressions. */ 14926 if (stmt && !c_omp_check_loop_iv (stmt, declv, NULL)) 14927 stmt = NULL_TREE; 14928 14929 if (stmt) 14930 { 14931 add_stmt (stmt); 14932 14933 if (cclauses != NULL 14934 && cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] != NULL) 14935 { 14936 tree *c; 14937 for (c = &cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; *c ; ) 14938 if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE 14939 && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE) 14940 c = &OMP_CLAUSE_CHAIN (*c); 14941 else 14942 { 14943 for (i = 0; i < count; i++) 14944 if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c)) 14945 break; 14946 if (i == count) 14947 c = &OMP_CLAUSE_CHAIN (*c); 14948 else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE) 14949 { 14950 error_at (loc, 14951 "iteration variable %qD should not be firstprivate", 14952 OMP_CLAUSE_DECL (*c)); 14953 *c = OMP_CLAUSE_CHAIN (*c); 14954 } 14955 else 14956 { 14957 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */ 14958 tree l = *c; 14959 *c = OMP_CLAUSE_CHAIN (*c); 14960 if (code == OMP_SIMD) 14961 { 14962 OMP_CLAUSE_CHAIN (l) 14963 = cclauses[C_OMP_CLAUSE_SPLIT_FOR]; 14964 cclauses[C_OMP_CLAUSE_SPLIT_FOR] = l; 14965 } 14966 else 14967 { 14968 OMP_CLAUSE_CHAIN (l) = clauses; 14969 clauses = l; 14970 } 14971 } 14972 } 14973 } 14974 OMP_FOR_CLAUSES (stmt) = clauses; 14975 } 14976 ret = stmt; 14977 } 14978 pop_scopes: 14979 while (!for_block->is_empty ()) 14980 { 14981 /* FIXME diagnostics: LOC below should be the actual location of 14982 this particular for block. We need to build a list of 14983 locations to go along with FOR_BLOCK. */ 14984 stmt = c_end_compound_stmt (loc, for_block->pop (), true); 14985 add_stmt (stmt); 14986 } 14987 release_tree_vector (for_block); 14988 return ret; 14989 } 14990 14991 /* Helper function for OpenMP parsing, split clauses and call 14992 finish_omp_clauses on each of the set of clauses afterwards. */ 14993 14994 static void 14995 omp_split_clauses (location_t loc, enum tree_code code, 14996 omp_clause_mask mask, tree clauses, tree *cclauses) 14997 { 14998 int i; 14999 c_omp_split_clauses (loc, code, mask, clauses, cclauses); 15000 for (i = 0; i < C_OMP_CLAUSE_SPLIT_COUNT; i++) 15001 if (cclauses[i]) 15002 cclauses[i] = c_finish_omp_clauses (cclauses[i], true); 15003 } 15004 15005 /* OpenMP 4.0: 15006 #pragma omp simd simd-clause[optseq] new-line 15007 for-loop 15008 15009 LOC is the location of the #pragma token. 15010 */ 15011 15012 #define OMP_SIMD_CLAUSE_MASK \ 15013 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \ 15014 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \ 15015 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \ 15016 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \ 15017 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ 15018 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ 15019 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ 15020 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE)) 15021 15022 static tree 15023 c_parser_omp_simd (location_t loc, c_parser *parser, 15024 char *p_name, omp_clause_mask mask, tree *cclauses, 15025 bool *if_p) 15026 { 15027 tree block, clauses, ret; 15028 15029 strcat (p_name, " simd"); 15030 mask |= OMP_SIMD_CLAUSE_MASK; 15031 15032 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); 15033 if (cclauses) 15034 { 15035 omp_split_clauses (loc, OMP_SIMD, mask, clauses, cclauses); 15036 clauses = cclauses[C_OMP_CLAUSE_SPLIT_SIMD]; 15037 tree c = find_omp_clause (cclauses[C_OMP_CLAUSE_SPLIT_FOR], 15038 OMP_CLAUSE_ORDERED); 15039 if (c && OMP_CLAUSE_ORDERED_EXPR (c)) 15040 { 15041 error_at (OMP_CLAUSE_LOCATION (c), 15042 "%<ordered%> clause with parameter may not be specified " 15043 "on %qs construct", p_name); 15044 OMP_CLAUSE_ORDERED_EXPR (c) = NULL_TREE; 15045 } 15046 } 15047 15048 block = c_begin_compound_stmt (true); 15049 ret = c_parser_omp_for_loop (loc, parser, OMP_SIMD, clauses, cclauses, if_p); 15050 block = c_end_compound_stmt (loc, block, true); 15051 add_stmt (block); 15052 15053 return ret; 15054 } 15055 15056 /* OpenMP 2.5: 15057 #pragma omp for for-clause[optseq] new-line 15058 for-loop 15059 15060 OpenMP 4.0: 15061 #pragma omp for simd for-simd-clause[optseq] new-line 15062 for-loop 15063 15064 LOC is the location of the #pragma token. 15065 */ 15066 15067 #define OMP_FOR_CLAUSE_MASK \ 15068 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ 15069 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ 15070 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ 15071 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \ 15072 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ 15073 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \ 15074 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \ 15075 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \ 15076 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) 15077 15078 static tree 15079 c_parser_omp_for (location_t loc, c_parser *parser, 15080 char *p_name, omp_clause_mask mask, tree *cclauses, 15081 bool *if_p) 15082 { 15083 tree block, clauses, ret; 15084 15085 strcat (p_name, " for"); 15086 mask |= OMP_FOR_CLAUSE_MASK; 15087 /* parallel for{, simd} disallows nowait clause, but for 15088 target {teams distribute ,}parallel for{, simd} it should be accepted. */ 15089 if (cclauses && (mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) == 0) 15090 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT); 15091 /* Composite distribute parallel for{, simd} disallows ordered clause. */ 15092 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0) 15093 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED); 15094 15095 if (c_parser_next_token_is (parser, CPP_NAME)) 15096 { 15097 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 15098 15099 if (strcmp (p, "simd") == 0) 15100 { 15101 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; 15102 if (cclauses == NULL) 15103 cclauses = cclauses_buf; 15104 15105 c_parser_consume_token (parser); 15106 if (!flag_openmp) /* flag_openmp_simd */ 15107 return c_parser_omp_simd (loc, parser, p_name, mask, cclauses, 15108 if_p); 15109 block = c_begin_compound_stmt (true); 15110 ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses, if_p); 15111 block = c_end_compound_stmt (loc, block, true); 15112 if (ret == NULL_TREE) 15113 return ret; 15114 ret = make_node (OMP_FOR); 15115 TREE_TYPE (ret) = void_type_node; 15116 OMP_FOR_BODY (ret) = block; 15117 OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_FOR]; 15118 SET_EXPR_LOCATION (ret, loc); 15119 add_stmt (ret); 15120 return ret; 15121 } 15122 } 15123 if (!flag_openmp) /* flag_openmp_simd */ 15124 { 15125 c_parser_skip_to_pragma_eol (parser, false); 15126 return NULL_TREE; 15127 } 15128 15129 /* Composite distribute parallel for disallows linear clause. */ 15130 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0) 15131 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR); 15132 15133 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); 15134 if (cclauses) 15135 { 15136 omp_split_clauses (loc, OMP_FOR, mask, clauses, cclauses); 15137 clauses = cclauses[C_OMP_CLAUSE_SPLIT_FOR]; 15138 } 15139 15140 block = c_begin_compound_stmt (true); 15141 ret = c_parser_omp_for_loop (loc, parser, OMP_FOR, clauses, cclauses, if_p); 15142 block = c_end_compound_stmt (loc, block, true); 15143 add_stmt (block); 15144 15145 return ret; 15146 } 15147 15148 /* OpenMP 2.5: 15149 # pragma omp master new-line 15150 structured-block 15151 15152 LOC is the location of the #pragma token. 15153 */ 15154 15155 static tree 15156 c_parser_omp_master (location_t loc, c_parser *parser, bool *if_p) 15157 { 15158 c_parser_skip_to_pragma_eol (parser); 15159 return c_finish_omp_master (loc, c_parser_omp_structured_block (parser, 15160 if_p)); 15161 } 15162 15163 /* OpenMP 2.5: 15164 # pragma omp ordered new-line 15165 structured-block 15166 15167 OpenMP 4.5: 15168 # pragma omp ordered ordered-clauses new-line 15169 structured-block 15170 15171 # pragma omp ordered depend-clauses new-line */ 15172 15173 #define OMP_ORDERED_CLAUSE_MASK \ 15174 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \ 15175 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD)) 15176 15177 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \ 15178 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) 15179 15180 static bool 15181 c_parser_omp_ordered (c_parser *parser, enum pragma_context context, 15182 bool *if_p) 15183 { 15184 location_t loc = c_parser_peek_token (parser)->location; 15185 c_parser_consume_pragma (parser); 15186 15187 if (context != pragma_stmt && context != pragma_compound) 15188 { 15189 c_parser_error (parser, "expected declaration specifiers"); 15190 c_parser_skip_to_pragma_eol (parser, false); 15191 return false; 15192 } 15193 15194 if (c_parser_next_token_is (parser, CPP_NAME)) 15195 { 15196 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 15197 15198 if (!strcmp ("depend", p)) 15199 { 15200 if (context == pragma_stmt) 15201 { 15202 error_at (loc, 15203 "%<#pragma omp ordered%> with %<depend> clause may " 15204 "only be used in compound statements"); 15205 c_parser_skip_to_pragma_eol (parser, false); 15206 return false; 15207 } 15208 15209 tree clauses 15210 = c_parser_omp_all_clauses (parser, 15211 OMP_ORDERED_DEPEND_CLAUSE_MASK, 15212 "#pragma omp ordered"); 15213 c_finish_omp_ordered (loc, clauses, NULL_TREE); 15214 return false; 15215 } 15216 } 15217 15218 tree clauses = c_parser_omp_all_clauses (parser, OMP_ORDERED_CLAUSE_MASK, 15219 "#pragma omp ordered"); 15220 c_finish_omp_ordered (loc, clauses, 15221 c_parser_omp_structured_block (parser, if_p)); 15222 return true; 15223 } 15224 15225 /* OpenMP 2.5: 15226 15227 section-scope: 15228 { section-sequence } 15229 15230 section-sequence: 15231 section-directive[opt] structured-block 15232 section-sequence section-directive structured-block 15233 15234 SECTIONS_LOC is the location of the #pragma omp sections. */ 15235 15236 static tree 15237 c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser) 15238 { 15239 tree stmt, substmt; 15240 bool error_suppress = false; 15241 location_t loc; 15242 15243 loc = c_parser_peek_token (parser)->location; 15244 if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) 15245 { 15246 /* Avoid skipping until the end of the block. */ 15247 parser->error = false; 15248 return NULL_TREE; 15249 } 15250 15251 stmt = push_stmt_list (); 15252 15253 if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION) 15254 { 15255 substmt = c_parser_omp_structured_block (parser, NULL); 15256 substmt = build1 (OMP_SECTION, void_type_node, substmt); 15257 SET_EXPR_LOCATION (substmt, loc); 15258 add_stmt (substmt); 15259 } 15260 15261 while (1) 15262 { 15263 if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) 15264 break; 15265 if (c_parser_next_token_is (parser, CPP_EOF)) 15266 break; 15267 15268 loc = c_parser_peek_token (parser)->location; 15269 if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION) 15270 { 15271 c_parser_consume_pragma (parser); 15272 c_parser_skip_to_pragma_eol (parser); 15273 error_suppress = false; 15274 } 15275 else if (!error_suppress) 15276 { 15277 error_at (loc, "expected %<#pragma omp section%> or %<}%>"); 15278 error_suppress = true; 15279 } 15280 15281 substmt = c_parser_omp_structured_block (parser, NULL); 15282 substmt = build1 (OMP_SECTION, void_type_node, substmt); 15283 SET_EXPR_LOCATION (substmt, loc); 15284 add_stmt (substmt); 15285 } 15286 c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, 15287 "expected %<#pragma omp section%> or %<}%>"); 15288 15289 substmt = pop_stmt_list (stmt); 15290 15291 stmt = make_node (OMP_SECTIONS); 15292 SET_EXPR_LOCATION (stmt, sections_loc); 15293 TREE_TYPE (stmt) = void_type_node; 15294 OMP_SECTIONS_BODY (stmt) = substmt; 15295 15296 return add_stmt (stmt); 15297 } 15298 15299 /* OpenMP 2.5: 15300 # pragma omp sections sections-clause[optseq] newline 15301 sections-scope 15302 15303 LOC is the location of the #pragma token. 15304 */ 15305 15306 #define OMP_SECTIONS_CLAUSE_MASK \ 15307 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ 15308 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ 15309 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ 15310 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ 15311 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) 15312 15313 static tree 15314 c_parser_omp_sections (location_t loc, c_parser *parser, 15315 char *p_name, omp_clause_mask mask, tree *cclauses) 15316 { 15317 tree block, clauses, ret; 15318 15319 strcat (p_name, " sections"); 15320 mask |= OMP_SECTIONS_CLAUSE_MASK; 15321 if (cclauses) 15322 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT); 15323 15324 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); 15325 if (cclauses) 15326 { 15327 omp_split_clauses (loc, OMP_SECTIONS, mask, clauses, cclauses); 15328 clauses = cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS]; 15329 } 15330 15331 block = c_begin_compound_stmt (true); 15332 ret = c_parser_omp_sections_scope (loc, parser); 15333 if (ret) 15334 OMP_SECTIONS_CLAUSES (ret) = clauses; 15335 block = c_end_compound_stmt (loc, block, true); 15336 add_stmt (block); 15337 15338 return ret; 15339 } 15340 15341 /* OpenMP 2.5: 15342 # pragma omp parallel parallel-clause[optseq] new-line 15343 structured-block 15344 # pragma omp parallel for parallel-for-clause[optseq] new-line 15345 structured-block 15346 # pragma omp parallel sections parallel-sections-clause[optseq] new-line 15347 structured-block 15348 15349 OpenMP 4.0: 15350 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line 15351 structured-block 15352 15353 LOC is the location of the #pragma token. 15354 */ 15355 15356 #define OMP_PARALLEL_CLAUSE_MASK \ 15357 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ 15358 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ 15359 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ 15360 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \ 15361 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ 15362 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \ 15363 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ 15364 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \ 15365 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND)) 15366 15367 static tree 15368 c_parser_omp_parallel (location_t loc, c_parser *parser, 15369 char *p_name, omp_clause_mask mask, tree *cclauses, 15370 bool *if_p) 15371 { 15372 tree stmt, clauses, block; 15373 15374 strcat (p_name, " parallel"); 15375 mask |= OMP_PARALLEL_CLAUSE_MASK; 15376 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */ 15377 if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) != 0 15378 && (mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) == 0) 15379 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN); 15380 15381 if (c_parser_next_token_is_keyword (parser, RID_FOR)) 15382 { 15383 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; 15384 if (cclauses == NULL) 15385 cclauses = cclauses_buf; 15386 15387 c_parser_consume_token (parser); 15388 if (!flag_openmp) /* flag_openmp_simd */ 15389 return c_parser_omp_for (loc, parser, p_name, mask, cclauses, if_p); 15390 block = c_begin_omp_parallel (); 15391 tree ret = c_parser_omp_for (loc, parser, p_name, mask, cclauses, if_p); 15392 stmt 15393 = c_finish_omp_parallel (loc, cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL], 15394 block); 15395 if (ret == NULL_TREE) 15396 return ret; 15397 OMP_PARALLEL_COMBINED (stmt) = 1; 15398 return stmt; 15399 } 15400 /* When combined with distribute, parallel has to be followed by for. 15401 #pragma omp target parallel is allowed though. */ 15402 else if (cclauses 15403 && (mask & (OMP_CLAUSE_MASK_1 15404 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0) 15405 { 15406 error_at (loc, "expected %<for%> after %qs", p_name); 15407 c_parser_skip_to_pragma_eol (parser); 15408 return NULL_TREE; 15409 } 15410 else if (!flag_openmp) /* flag_openmp_simd */ 15411 { 15412 c_parser_skip_to_pragma_eol (parser, false); 15413 return NULL_TREE; 15414 } 15415 else if (cclauses == NULL && c_parser_next_token_is (parser, CPP_NAME)) 15416 { 15417 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 15418 if (strcmp (p, "sections") == 0) 15419 { 15420 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; 15421 if (cclauses == NULL) 15422 cclauses = cclauses_buf; 15423 15424 c_parser_consume_token (parser); 15425 block = c_begin_omp_parallel (); 15426 c_parser_omp_sections (loc, parser, p_name, mask, cclauses); 15427 stmt = c_finish_omp_parallel (loc, 15428 cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL], 15429 block); 15430 OMP_PARALLEL_COMBINED (stmt) = 1; 15431 return stmt; 15432 } 15433 } 15434 15435 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); 15436 if (cclauses) 15437 { 15438 omp_split_clauses (loc, OMP_PARALLEL, mask, clauses, cclauses); 15439 clauses = cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; 15440 } 15441 15442 block = c_begin_omp_parallel (); 15443 c_parser_statement (parser, if_p); 15444 stmt = c_finish_omp_parallel (loc, clauses, block); 15445 15446 return stmt; 15447 } 15448 15449 /* OpenMP 2.5: 15450 # pragma omp single single-clause[optseq] new-line 15451 structured-block 15452 15453 LOC is the location of the #pragma. 15454 */ 15455 15456 #define OMP_SINGLE_CLAUSE_MASK \ 15457 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ 15458 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ 15459 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \ 15460 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) 15461 15462 static tree 15463 c_parser_omp_single (location_t loc, c_parser *parser, bool *if_p) 15464 { 15465 tree stmt = make_node (OMP_SINGLE); 15466 SET_EXPR_LOCATION (stmt, loc); 15467 TREE_TYPE (stmt) = void_type_node; 15468 15469 OMP_SINGLE_CLAUSES (stmt) 15470 = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK, 15471 "#pragma omp single"); 15472 OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser, if_p); 15473 15474 return add_stmt (stmt); 15475 } 15476 15477 /* OpenMP 3.0: 15478 # pragma omp task task-clause[optseq] new-line 15479 15480 LOC is the location of the #pragma. 15481 */ 15482 15483 #define OMP_TASK_CLAUSE_MASK \ 15484 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ 15485 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \ 15486 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \ 15487 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ 15488 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ 15489 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ 15490 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \ 15491 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \ 15492 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ 15493 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY)) 15494 15495 static tree 15496 c_parser_omp_task (location_t loc, c_parser *parser, bool *if_p) 15497 { 15498 tree clauses, block; 15499 15500 clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK, 15501 "#pragma omp task"); 15502 15503 block = c_begin_omp_task (); 15504 c_parser_statement (parser, if_p); 15505 return c_finish_omp_task (loc, clauses, block); 15506 } 15507 15508 /* OpenMP 3.0: 15509 # pragma omp taskwait new-line 15510 */ 15511 15512 static void 15513 c_parser_omp_taskwait (c_parser *parser) 15514 { 15515 location_t loc = c_parser_peek_token (parser)->location; 15516 c_parser_consume_pragma (parser); 15517 c_parser_skip_to_pragma_eol (parser); 15518 15519 c_finish_omp_taskwait (loc); 15520 } 15521 15522 /* OpenMP 3.1: 15523 # pragma omp taskyield new-line 15524 */ 15525 15526 static void 15527 c_parser_omp_taskyield (c_parser *parser) 15528 { 15529 location_t loc = c_parser_peek_token (parser)->location; 15530 c_parser_consume_pragma (parser); 15531 c_parser_skip_to_pragma_eol (parser); 15532 15533 c_finish_omp_taskyield (loc); 15534 } 15535 15536 /* OpenMP 4.0: 15537 # pragma omp taskgroup new-line 15538 */ 15539 15540 static tree 15541 c_parser_omp_taskgroup (c_parser *parser, bool *if_p) 15542 { 15543 location_t loc = c_parser_peek_token (parser)->location; 15544 c_parser_skip_to_pragma_eol (parser); 15545 return c_finish_omp_taskgroup (loc, c_parser_omp_structured_block (parser, 15546 if_p)); 15547 } 15548 15549 /* OpenMP 4.0: 15550 # pragma omp cancel cancel-clause[optseq] new-line 15551 15552 LOC is the location of the #pragma. 15553 */ 15554 15555 #define OMP_CANCEL_CLAUSE_MASK \ 15556 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \ 15557 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \ 15558 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \ 15559 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \ 15560 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)) 15561 15562 static void 15563 c_parser_omp_cancel (c_parser *parser) 15564 { 15565 location_t loc = c_parser_peek_token (parser)->location; 15566 15567 c_parser_consume_pragma (parser); 15568 tree clauses = c_parser_omp_all_clauses (parser, OMP_CANCEL_CLAUSE_MASK, 15569 "#pragma omp cancel"); 15570 15571 c_finish_omp_cancel (loc, clauses); 15572 } 15573 15574 /* OpenMP 4.0: 15575 # pragma omp cancellation point cancelpt-clause[optseq] new-line 15576 15577 LOC is the location of the #pragma. 15578 */ 15579 15580 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \ 15581 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \ 15582 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \ 15583 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \ 15584 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP)) 15585 15586 static void 15587 c_parser_omp_cancellation_point (c_parser *parser) 15588 { 15589 location_t loc = c_parser_peek_token (parser)->location; 15590 tree clauses; 15591 bool point_seen = false; 15592 15593 c_parser_consume_pragma (parser); 15594 if (c_parser_next_token_is (parser, CPP_NAME)) 15595 { 15596 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 15597 if (strcmp (p, "point") == 0) 15598 { 15599 c_parser_consume_token (parser); 15600 point_seen = true; 15601 } 15602 } 15603 if (!point_seen) 15604 { 15605 c_parser_error (parser, "expected %<point%>"); 15606 c_parser_skip_to_pragma_eol (parser); 15607 return; 15608 } 15609 15610 clauses 15611 = c_parser_omp_all_clauses (parser, OMP_CANCELLATION_POINT_CLAUSE_MASK, 15612 "#pragma omp cancellation point"); 15613 15614 c_finish_omp_cancellation_point (loc, clauses); 15615 } 15616 15617 /* OpenMP 4.0: 15618 #pragma omp distribute distribute-clause[optseq] new-line 15619 for-loop */ 15620 15621 #define OMP_DISTRIBUTE_CLAUSE_MASK \ 15622 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ 15623 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ 15624 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ 15625 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\ 15626 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE)) 15627 15628 static tree 15629 c_parser_omp_distribute (location_t loc, c_parser *parser, 15630 char *p_name, omp_clause_mask mask, tree *cclauses, 15631 bool *if_p) 15632 { 15633 tree clauses, block, ret; 15634 15635 strcat (p_name, " distribute"); 15636 mask |= OMP_DISTRIBUTE_CLAUSE_MASK; 15637 15638 if (c_parser_next_token_is (parser, CPP_NAME)) 15639 { 15640 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 15641 bool simd = false; 15642 bool parallel = false; 15643 15644 if (strcmp (p, "simd") == 0) 15645 simd = true; 15646 else 15647 parallel = strcmp (p, "parallel") == 0; 15648 if (parallel || simd) 15649 { 15650 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; 15651 if (cclauses == NULL) 15652 cclauses = cclauses_buf; 15653 c_parser_consume_token (parser); 15654 if (!flag_openmp) /* flag_openmp_simd */ 15655 { 15656 if (simd) 15657 return c_parser_omp_simd (loc, parser, p_name, mask, cclauses, 15658 if_p); 15659 else 15660 return c_parser_omp_parallel (loc, parser, p_name, mask, 15661 cclauses, if_p); 15662 } 15663 block = c_begin_compound_stmt (true); 15664 if (simd) 15665 ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses, 15666 if_p); 15667 else 15668 ret = c_parser_omp_parallel (loc, parser, p_name, mask, cclauses, 15669 if_p); 15670 block = c_end_compound_stmt (loc, block, true); 15671 if (ret == NULL) 15672 return ret; 15673 ret = make_node (OMP_DISTRIBUTE); 15674 TREE_TYPE (ret) = void_type_node; 15675 OMP_FOR_BODY (ret) = block; 15676 OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE]; 15677 SET_EXPR_LOCATION (ret, loc); 15678 add_stmt (ret); 15679 return ret; 15680 } 15681 } 15682 if (!flag_openmp) /* flag_openmp_simd */ 15683 { 15684 c_parser_skip_to_pragma_eol (parser, false); 15685 return NULL_TREE; 15686 } 15687 15688 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); 15689 if (cclauses) 15690 { 15691 omp_split_clauses (loc, OMP_DISTRIBUTE, mask, clauses, cclauses); 15692 clauses = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE]; 15693 } 15694 15695 block = c_begin_compound_stmt (true); 15696 ret = c_parser_omp_for_loop (loc, parser, OMP_DISTRIBUTE, clauses, NULL, 15697 if_p); 15698 block = c_end_compound_stmt (loc, block, true); 15699 add_stmt (block); 15700 15701 return ret; 15702 } 15703 15704 /* OpenMP 4.0: 15705 # pragma omp teams teams-clause[optseq] new-line 15706 structured-block */ 15707 15708 #define OMP_TEAMS_CLAUSE_MASK \ 15709 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ 15710 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ 15711 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ 15712 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ 15713 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \ 15714 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \ 15715 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT)) 15716 15717 static tree 15718 c_parser_omp_teams (location_t loc, c_parser *parser, 15719 char *p_name, omp_clause_mask mask, tree *cclauses, 15720 bool *if_p) 15721 { 15722 tree clauses, block, ret; 15723 15724 strcat (p_name, " teams"); 15725 mask |= OMP_TEAMS_CLAUSE_MASK; 15726 15727 if (c_parser_next_token_is (parser, CPP_NAME)) 15728 { 15729 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 15730 if (strcmp (p, "distribute") == 0) 15731 { 15732 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; 15733 if (cclauses == NULL) 15734 cclauses = cclauses_buf; 15735 15736 c_parser_consume_token (parser); 15737 if (!flag_openmp) /* flag_openmp_simd */ 15738 return c_parser_omp_distribute (loc, parser, p_name, mask, 15739 cclauses, if_p); 15740 block = c_begin_compound_stmt (true); 15741 ret = c_parser_omp_distribute (loc, parser, p_name, mask, cclauses, 15742 if_p); 15743 block = c_end_compound_stmt (loc, block, true); 15744 if (ret == NULL) 15745 return ret; 15746 clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS]; 15747 ret = make_node (OMP_TEAMS); 15748 TREE_TYPE (ret) = void_type_node; 15749 OMP_TEAMS_CLAUSES (ret) = clauses; 15750 OMP_TEAMS_BODY (ret) = block; 15751 OMP_TEAMS_COMBINED (ret) = 1; 15752 return add_stmt (ret); 15753 } 15754 } 15755 if (!flag_openmp) /* flag_openmp_simd */ 15756 { 15757 c_parser_skip_to_pragma_eol (parser, false); 15758 return NULL_TREE; 15759 } 15760 15761 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); 15762 if (cclauses) 15763 { 15764 omp_split_clauses (loc, OMP_TEAMS, mask, clauses, cclauses); 15765 clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS]; 15766 } 15767 15768 tree stmt = make_node (OMP_TEAMS); 15769 TREE_TYPE (stmt) = void_type_node; 15770 OMP_TEAMS_CLAUSES (stmt) = clauses; 15771 OMP_TEAMS_BODY (stmt) = c_parser_omp_structured_block (parser, if_p); 15772 15773 return add_stmt (stmt); 15774 } 15775 15776 /* OpenMP 4.0: 15777 # pragma omp target data target-data-clause[optseq] new-line 15778 structured-block */ 15779 15780 #define OMP_TARGET_DATA_CLAUSE_MASK \ 15781 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ 15782 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \ 15783 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ 15784 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR)) 15785 15786 static tree 15787 c_parser_omp_target_data (location_t loc, c_parser *parser, bool *if_p) 15788 { 15789 tree clauses 15790 = c_parser_omp_all_clauses (parser, OMP_TARGET_DATA_CLAUSE_MASK, 15791 "#pragma omp target data"); 15792 int map_seen = 0; 15793 for (tree *pc = &clauses; *pc;) 15794 { 15795 if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP) 15796 switch (OMP_CLAUSE_MAP_KIND (*pc)) 15797 { 15798 case GOMP_MAP_TO: 15799 case GOMP_MAP_ALWAYS_TO: 15800 case GOMP_MAP_FROM: 15801 case GOMP_MAP_ALWAYS_FROM: 15802 case GOMP_MAP_TOFROM: 15803 case GOMP_MAP_ALWAYS_TOFROM: 15804 case GOMP_MAP_ALLOC: 15805 map_seen = 3; 15806 break; 15807 case GOMP_MAP_FIRSTPRIVATE_POINTER: 15808 case GOMP_MAP_ALWAYS_POINTER: 15809 break; 15810 default: 15811 map_seen |= 1; 15812 error_at (OMP_CLAUSE_LOCATION (*pc), 15813 "%<#pragma omp target data%> with map-type other " 15814 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> " 15815 "on %<map%> clause"); 15816 *pc = OMP_CLAUSE_CHAIN (*pc); 15817 continue; 15818 } 15819 pc = &OMP_CLAUSE_CHAIN (*pc); 15820 } 15821 15822 if (map_seen != 3) 15823 { 15824 if (map_seen == 0) 15825 error_at (loc, 15826 "%<#pragma omp target data%> must contain at least " 15827 "one %<map%> clause"); 15828 return NULL_TREE; 15829 } 15830 15831 tree stmt = make_node (OMP_TARGET_DATA); 15832 TREE_TYPE (stmt) = void_type_node; 15833 OMP_TARGET_DATA_CLAUSES (stmt) = clauses; 15834 keep_next_level (); 15835 tree block = c_begin_compound_stmt (true); 15836 add_stmt (c_parser_omp_structured_block (parser, if_p)); 15837 OMP_TARGET_DATA_BODY (stmt) = c_end_compound_stmt (loc, block, true); 15838 15839 SET_EXPR_LOCATION (stmt, loc); 15840 return add_stmt (stmt); 15841 } 15842 15843 /* OpenMP 4.0: 15844 # pragma omp target update target-update-clause[optseq] new-line */ 15845 15846 #define OMP_TARGET_UPDATE_CLAUSE_MASK \ 15847 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \ 15848 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \ 15849 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ 15850 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ 15851 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ 15852 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) 15853 15854 static bool 15855 c_parser_omp_target_update (location_t loc, c_parser *parser, 15856 enum pragma_context context) 15857 { 15858 if (context == pragma_stmt) 15859 { 15860 error_at (loc, 15861 "%<#pragma omp target update%> may only be " 15862 "used in compound statements"); 15863 c_parser_skip_to_pragma_eol (parser, false); 15864 return false; 15865 } 15866 15867 tree clauses 15868 = c_parser_omp_all_clauses (parser, OMP_TARGET_UPDATE_CLAUSE_MASK, 15869 "#pragma omp target update"); 15870 if (find_omp_clause (clauses, OMP_CLAUSE_TO) == NULL_TREE 15871 && find_omp_clause (clauses, OMP_CLAUSE_FROM) == NULL_TREE) 15872 { 15873 error_at (loc, 15874 "%<#pragma omp target update%> must contain at least one " 15875 "%<from%> or %<to%> clauses"); 15876 return false; 15877 } 15878 15879 tree stmt = make_node (OMP_TARGET_UPDATE); 15880 TREE_TYPE (stmt) = void_type_node; 15881 OMP_TARGET_UPDATE_CLAUSES (stmt) = clauses; 15882 SET_EXPR_LOCATION (stmt, loc); 15883 add_stmt (stmt); 15884 return false; 15885 } 15886 15887 /* OpenMP 4.5: 15888 # pragma omp target enter data target-data-clause[optseq] new-line */ 15889 15890 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \ 15891 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ 15892 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \ 15893 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ 15894 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ 15895 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) 15896 15897 static tree 15898 c_parser_omp_target_enter_data (location_t loc, c_parser *parser, 15899 enum pragma_context context) 15900 { 15901 bool data_seen = false; 15902 if (c_parser_next_token_is (parser, CPP_NAME)) 15903 { 15904 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 15905 if (strcmp (p, "data") == 0) 15906 { 15907 c_parser_consume_token (parser); 15908 data_seen = true; 15909 } 15910 } 15911 if (!data_seen) 15912 { 15913 c_parser_error (parser, "expected %<data%>"); 15914 c_parser_skip_to_pragma_eol (parser); 15915 return NULL_TREE; 15916 } 15917 15918 if (context == pragma_stmt) 15919 { 15920 error_at (loc, 15921 "%<#pragma omp target enter data%> may only be " 15922 "used in compound statements"); 15923 c_parser_skip_to_pragma_eol (parser, false); 15924 return NULL_TREE; 15925 } 15926 15927 tree clauses 15928 = c_parser_omp_all_clauses (parser, OMP_TARGET_ENTER_DATA_CLAUSE_MASK, 15929 "#pragma omp target enter data"); 15930 int map_seen = 0; 15931 for (tree *pc = &clauses; *pc;) 15932 { 15933 if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP) 15934 switch (OMP_CLAUSE_MAP_KIND (*pc)) 15935 { 15936 case GOMP_MAP_TO: 15937 case GOMP_MAP_ALWAYS_TO: 15938 case GOMP_MAP_ALLOC: 15939 map_seen = 3; 15940 break; 15941 case GOMP_MAP_FIRSTPRIVATE_POINTER: 15942 case GOMP_MAP_ALWAYS_POINTER: 15943 break; 15944 default: 15945 map_seen |= 1; 15946 error_at (OMP_CLAUSE_LOCATION (*pc), 15947 "%<#pragma omp target enter data%> with map-type other " 15948 "than %<to%> or %<alloc%> on %<map%> clause"); 15949 *pc = OMP_CLAUSE_CHAIN (*pc); 15950 continue; 15951 } 15952 pc = &OMP_CLAUSE_CHAIN (*pc); 15953 } 15954 15955 if (map_seen != 3) 15956 { 15957 if (map_seen == 0) 15958 error_at (loc, 15959 "%<#pragma omp target enter data%> must contain at least " 15960 "one %<map%> clause"); 15961 return NULL_TREE; 15962 } 15963 15964 tree stmt = make_node (OMP_TARGET_ENTER_DATA); 15965 TREE_TYPE (stmt) = void_type_node; 15966 OMP_TARGET_ENTER_DATA_CLAUSES (stmt) = clauses; 15967 SET_EXPR_LOCATION (stmt, loc); 15968 add_stmt (stmt); 15969 return stmt; 15970 } 15971 15972 /* OpenMP 4.5: 15973 # pragma omp target exit data target-data-clause[optseq] new-line */ 15974 15975 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \ 15976 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ 15977 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \ 15978 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ 15979 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ 15980 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) 15981 15982 static tree 15983 c_parser_omp_target_exit_data (location_t loc, c_parser *parser, 15984 enum pragma_context context) 15985 { 15986 bool data_seen = false; 15987 if (c_parser_next_token_is (parser, CPP_NAME)) 15988 { 15989 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 15990 if (strcmp (p, "data") == 0) 15991 { 15992 c_parser_consume_token (parser); 15993 data_seen = true; 15994 } 15995 } 15996 if (!data_seen) 15997 { 15998 c_parser_error (parser, "expected %<data%>"); 15999 c_parser_skip_to_pragma_eol (parser); 16000 return NULL_TREE; 16001 } 16002 16003 if (context == pragma_stmt) 16004 { 16005 error_at (loc, 16006 "%<#pragma omp target exit data%> may only be " 16007 "used in compound statements"); 16008 c_parser_skip_to_pragma_eol (parser, false); 16009 return NULL_TREE; 16010 } 16011 16012 tree clauses 16013 = c_parser_omp_all_clauses (parser, OMP_TARGET_EXIT_DATA_CLAUSE_MASK, 16014 "#pragma omp target exit data"); 16015 16016 int map_seen = 0; 16017 for (tree *pc = &clauses; *pc;) 16018 { 16019 if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP) 16020 switch (OMP_CLAUSE_MAP_KIND (*pc)) 16021 { 16022 case GOMP_MAP_FROM: 16023 case GOMP_MAP_ALWAYS_FROM: 16024 case GOMP_MAP_RELEASE: 16025 case GOMP_MAP_DELETE: 16026 map_seen = 3; 16027 break; 16028 case GOMP_MAP_FIRSTPRIVATE_POINTER: 16029 case GOMP_MAP_ALWAYS_POINTER: 16030 break; 16031 default: 16032 map_seen |= 1; 16033 error_at (OMP_CLAUSE_LOCATION (*pc), 16034 "%<#pragma omp target exit data%> with map-type other " 16035 "than %<from%>, %<release> or %<delete%> on %<map%>" 16036 " clause"); 16037 *pc = OMP_CLAUSE_CHAIN (*pc); 16038 continue; 16039 } 16040 pc = &OMP_CLAUSE_CHAIN (*pc); 16041 } 16042 16043 if (map_seen != 3) 16044 { 16045 if (map_seen == 0) 16046 error_at (loc, 16047 "%<#pragma omp target exit data%> must contain at least one " 16048 "%<map%> clause"); 16049 return NULL_TREE; 16050 } 16051 16052 tree stmt = make_node (OMP_TARGET_EXIT_DATA); 16053 TREE_TYPE (stmt) = void_type_node; 16054 OMP_TARGET_EXIT_DATA_CLAUSES (stmt) = clauses; 16055 SET_EXPR_LOCATION (stmt, loc); 16056 add_stmt (stmt); 16057 return stmt; 16058 } 16059 16060 /* OpenMP 4.0: 16061 # pragma omp target target-clause[optseq] new-line 16062 structured-block */ 16063 16064 #define OMP_TARGET_CLAUSE_MASK \ 16065 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ 16066 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \ 16067 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ 16068 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ 16069 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \ 16070 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ 16071 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ 16072 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \ 16073 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR)) 16074 16075 static bool 16076 c_parser_omp_target (c_parser *parser, enum pragma_context context, bool *if_p) 16077 { 16078 location_t loc = c_parser_peek_token (parser)->location; 16079 c_parser_consume_pragma (parser); 16080 tree *pc = NULL, stmt, block; 16081 16082 if (context != pragma_stmt && context != pragma_compound) 16083 { 16084 c_parser_error (parser, "expected declaration specifiers"); 16085 c_parser_skip_to_pragma_eol (parser); 16086 return false; 16087 } 16088 16089 if (c_parser_next_token_is (parser, CPP_NAME)) 16090 { 16091 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 16092 enum tree_code ccode = ERROR_MARK; 16093 16094 if (strcmp (p, "teams") == 0) 16095 ccode = OMP_TEAMS; 16096 else if (strcmp (p, "parallel") == 0) 16097 ccode = OMP_PARALLEL; 16098 else if (strcmp (p, "simd") == 0) 16099 ccode = OMP_SIMD; 16100 if (ccode != ERROR_MARK) 16101 { 16102 tree cclauses[C_OMP_CLAUSE_SPLIT_COUNT]; 16103 char p_name[sizeof ("#pragma omp target teams distribute " 16104 "parallel for simd")]; 16105 16106 c_parser_consume_token (parser); 16107 strcpy (p_name, "#pragma omp target"); 16108 if (!flag_openmp) /* flag_openmp_simd */ 16109 { 16110 tree stmt; 16111 switch (ccode) 16112 { 16113 case OMP_TEAMS: 16114 stmt = c_parser_omp_teams (loc, parser, p_name, 16115 OMP_TARGET_CLAUSE_MASK, 16116 cclauses, if_p); 16117 break; 16118 case OMP_PARALLEL: 16119 stmt = c_parser_omp_parallel (loc, parser, p_name, 16120 OMP_TARGET_CLAUSE_MASK, 16121 cclauses, if_p); 16122 break; 16123 case OMP_SIMD: 16124 stmt = c_parser_omp_simd (loc, parser, p_name, 16125 OMP_TARGET_CLAUSE_MASK, 16126 cclauses, if_p); 16127 break; 16128 default: 16129 gcc_unreachable (); 16130 } 16131 return stmt != NULL_TREE; 16132 } 16133 keep_next_level (); 16134 tree block = c_begin_compound_stmt (true), ret; 16135 switch (ccode) 16136 { 16137 case OMP_TEAMS: 16138 ret = c_parser_omp_teams (loc, parser, p_name, 16139 OMP_TARGET_CLAUSE_MASK, cclauses, 16140 if_p); 16141 break; 16142 case OMP_PARALLEL: 16143 ret = c_parser_omp_parallel (loc, parser, p_name, 16144 OMP_TARGET_CLAUSE_MASK, cclauses, 16145 if_p); 16146 break; 16147 case OMP_SIMD: 16148 ret = c_parser_omp_simd (loc, parser, p_name, 16149 OMP_TARGET_CLAUSE_MASK, cclauses, 16150 if_p); 16151 break; 16152 default: 16153 gcc_unreachable (); 16154 } 16155 block = c_end_compound_stmt (loc, block, true); 16156 if (ret == NULL_TREE) 16157 return false; 16158 if (ccode == OMP_TEAMS) 16159 { 16160 /* For combined target teams, ensure the num_teams and 16161 thread_limit clause expressions are evaluated on the host, 16162 before entering the target construct. */ 16163 tree c; 16164 for (c = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS]; 16165 c; c = OMP_CLAUSE_CHAIN (c)) 16166 if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS 16167 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_THREAD_LIMIT) 16168 && TREE_CODE (OMP_CLAUSE_OPERAND (c, 0)) != INTEGER_CST) 16169 { 16170 tree expr = OMP_CLAUSE_OPERAND (c, 0); 16171 tree tmp = create_tmp_var_raw (TREE_TYPE (expr)); 16172 expr = build4 (TARGET_EXPR, TREE_TYPE (expr), tmp, 16173 expr, NULL_TREE, NULL_TREE); 16174 add_stmt (expr); 16175 OMP_CLAUSE_OPERAND (c, 0) = expr; 16176 tree tc = build_omp_clause (OMP_CLAUSE_LOCATION (c), 16177 OMP_CLAUSE_FIRSTPRIVATE); 16178 OMP_CLAUSE_DECL (tc) = tmp; 16179 OMP_CLAUSE_CHAIN (tc) 16180 = cclauses[C_OMP_CLAUSE_SPLIT_TARGET]; 16181 cclauses[C_OMP_CLAUSE_SPLIT_TARGET] = tc; 16182 } 16183 } 16184 tree stmt = make_node (OMP_TARGET); 16185 TREE_TYPE (stmt) = void_type_node; 16186 OMP_TARGET_CLAUSES (stmt) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET]; 16187 OMP_TARGET_BODY (stmt) = block; 16188 OMP_TARGET_COMBINED (stmt) = 1; 16189 add_stmt (stmt); 16190 pc = &OMP_TARGET_CLAUSES (stmt); 16191 goto check_clauses; 16192 } 16193 else if (!flag_openmp) /* flag_openmp_simd */ 16194 { 16195 c_parser_skip_to_pragma_eol (parser, false); 16196 return false; 16197 } 16198 else if (strcmp (p, "data") == 0) 16199 { 16200 c_parser_consume_token (parser); 16201 c_parser_omp_target_data (loc, parser, if_p); 16202 return true; 16203 } 16204 else if (strcmp (p, "enter") == 0) 16205 { 16206 c_parser_consume_token (parser); 16207 c_parser_omp_target_enter_data (loc, parser, context); 16208 return false; 16209 } 16210 else if (strcmp (p, "exit") == 0) 16211 { 16212 c_parser_consume_token (parser); 16213 c_parser_omp_target_exit_data (loc, parser, context); 16214 return false; 16215 } 16216 else if (strcmp (p, "update") == 0) 16217 { 16218 c_parser_consume_token (parser); 16219 return c_parser_omp_target_update (loc, parser, context); 16220 } 16221 } 16222 if (!flag_openmp) /* flag_openmp_simd */ 16223 { 16224 c_parser_skip_to_pragma_eol (parser, false); 16225 return false; 16226 } 16227 16228 stmt = make_node (OMP_TARGET); 16229 TREE_TYPE (stmt) = void_type_node; 16230 16231 OMP_TARGET_CLAUSES (stmt) 16232 = c_parser_omp_all_clauses (parser, OMP_TARGET_CLAUSE_MASK, 16233 "#pragma omp target"); 16234 pc = &OMP_TARGET_CLAUSES (stmt); 16235 keep_next_level (); 16236 block = c_begin_compound_stmt (true); 16237 add_stmt (c_parser_omp_structured_block (parser, if_p)); 16238 OMP_TARGET_BODY (stmt) = c_end_compound_stmt (loc, block, true); 16239 16240 SET_EXPR_LOCATION (stmt, loc); 16241 add_stmt (stmt); 16242 16243 check_clauses: 16244 while (*pc) 16245 { 16246 if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP) 16247 switch (OMP_CLAUSE_MAP_KIND (*pc)) 16248 { 16249 case GOMP_MAP_TO: 16250 case GOMP_MAP_ALWAYS_TO: 16251 case GOMP_MAP_FROM: 16252 case GOMP_MAP_ALWAYS_FROM: 16253 case GOMP_MAP_TOFROM: 16254 case GOMP_MAP_ALWAYS_TOFROM: 16255 case GOMP_MAP_ALLOC: 16256 case GOMP_MAP_FIRSTPRIVATE_POINTER: 16257 case GOMP_MAP_ALWAYS_POINTER: 16258 break; 16259 default: 16260 error_at (OMP_CLAUSE_LOCATION (*pc), 16261 "%<#pragma omp target%> with map-type other " 16262 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> " 16263 "on %<map%> clause"); 16264 *pc = OMP_CLAUSE_CHAIN (*pc); 16265 continue; 16266 } 16267 pc = &OMP_CLAUSE_CHAIN (*pc); 16268 } 16269 return true; 16270 } 16271 16272 /* OpenMP 4.0: 16273 # pragma omp declare simd declare-simd-clauses[optseq] new-line */ 16274 16275 #define OMP_DECLARE_SIMD_CLAUSE_MASK \ 16276 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \ 16277 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \ 16278 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \ 16279 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \ 16280 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \ 16281 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH)) 16282 16283 static void 16284 c_parser_omp_declare_simd (c_parser *parser, enum pragma_context context) 16285 { 16286 vec<c_token> clauses = vNULL; 16287 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) 16288 { 16289 c_token *token = c_parser_peek_token (parser); 16290 if (token->type == CPP_EOF) 16291 { 16292 c_parser_skip_to_pragma_eol (parser); 16293 clauses.release (); 16294 return; 16295 } 16296 clauses.safe_push (*token); 16297 c_parser_consume_token (parser); 16298 } 16299 clauses.safe_push (*c_parser_peek_token (parser)); 16300 c_parser_skip_to_pragma_eol (parser); 16301 16302 while (c_parser_next_token_is (parser, CPP_PRAGMA)) 16303 { 16304 if (c_parser_peek_token (parser)->pragma_kind 16305 != PRAGMA_OMP_DECLARE_REDUCTION 16306 || c_parser_peek_2nd_token (parser)->type != CPP_NAME 16307 || strcmp (IDENTIFIER_POINTER 16308 (c_parser_peek_2nd_token (parser)->value), 16309 "simd") != 0) 16310 { 16311 c_parser_error (parser, 16312 "%<#pragma omp declare simd%> must be followed by " 16313 "function declaration or definition or another " 16314 "%<#pragma omp declare simd%>"); 16315 clauses.release (); 16316 return; 16317 } 16318 c_parser_consume_pragma (parser); 16319 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) 16320 { 16321 c_token *token = c_parser_peek_token (parser); 16322 if (token->type == CPP_EOF) 16323 { 16324 c_parser_skip_to_pragma_eol (parser); 16325 clauses.release (); 16326 return; 16327 } 16328 clauses.safe_push (*token); 16329 c_parser_consume_token (parser); 16330 } 16331 clauses.safe_push (*c_parser_peek_token (parser)); 16332 c_parser_skip_to_pragma_eol (parser); 16333 } 16334 16335 /* Make sure nothing tries to read past the end of the tokens. */ 16336 c_token eof_token; 16337 memset (&eof_token, 0, sizeof (eof_token)); 16338 eof_token.type = CPP_EOF; 16339 clauses.safe_push (eof_token); 16340 clauses.safe_push (eof_token); 16341 16342 switch (context) 16343 { 16344 case pragma_external: 16345 if (c_parser_next_token_is (parser, CPP_KEYWORD) 16346 && c_parser_peek_token (parser)->keyword == RID_EXTENSION) 16347 { 16348 int ext = disable_extension_diagnostics (); 16349 do 16350 c_parser_consume_token (parser); 16351 while (c_parser_next_token_is (parser, CPP_KEYWORD) 16352 && c_parser_peek_token (parser)->keyword == RID_EXTENSION); 16353 c_parser_declaration_or_fndef (parser, true, true, true, false, true, 16354 NULL, clauses); 16355 restore_extension_diagnostics (ext); 16356 } 16357 else 16358 c_parser_declaration_or_fndef (parser, true, true, true, false, true, 16359 NULL, clauses); 16360 break; 16361 case pragma_struct: 16362 case pragma_param: 16363 c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by " 16364 "function declaration or definition"); 16365 break; 16366 case pragma_compound: 16367 case pragma_stmt: 16368 if (c_parser_next_token_is (parser, CPP_KEYWORD) 16369 && c_parser_peek_token (parser)->keyword == RID_EXTENSION) 16370 { 16371 int ext = disable_extension_diagnostics (); 16372 do 16373 c_parser_consume_token (parser); 16374 while (c_parser_next_token_is (parser, CPP_KEYWORD) 16375 && c_parser_peek_token (parser)->keyword == RID_EXTENSION); 16376 if (c_parser_next_tokens_start_declaration (parser)) 16377 { 16378 c_parser_declaration_or_fndef (parser, true, true, true, true, 16379 true, NULL, clauses); 16380 restore_extension_diagnostics (ext); 16381 break; 16382 } 16383 restore_extension_diagnostics (ext); 16384 } 16385 else if (c_parser_next_tokens_start_declaration (parser)) 16386 { 16387 c_parser_declaration_or_fndef (parser, true, true, true, true, true, 16388 NULL, clauses); 16389 break; 16390 } 16391 c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by " 16392 "function declaration or definition"); 16393 break; 16394 default: 16395 gcc_unreachable (); 16396 } 16397 clauses.release (); 16398 } 16399 16400 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed, 16401 and put that into "omp declare simd" attribute. */ 16402 16403 static void 16404 c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms, 16405 vec<c_token> clauses) 16406 { 16407 if (flag_cilkplus 16408 && (clauses.exists () 16409 || lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl))) 16410 && !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) 16411 { 16412 error ("%<#pragma omp declare simd%> or %<simd%> attribute cannot be " 16413 "used in the same function marked as a Cilk Plus SIMD-enabled " 16414 "function"); 16415 vec_free (parser->cilk_simd_fn_tokens); 16416 return; 16417 } 16418 16419 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates 16420 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd 16421 has already processed the tokens. */ 16422 if (clauses.exists () && clauses[0].type == CPP_EOF) 16423 return; 16424 if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL) 16425 { 16426 error ("%<#pragma omp declare simd%> not immediately followed by " 16427 "a function declaration or definition"); 16428 clauses[0].type = CPP_EOF; 16429 return; 16430 } 16431 if (clauses.exists () && clauses[0].type != CPP_NAME) 16432 { 16433 error_at (DECL_SOURCE_LOCATION (fndecl), 16434 "%<#pragma omp declare simd%> not immediately followed by " 16435 "a single function declaration or definition"); 16436 clauses[0].type = CPP_EOF; 16437 return; 16438 } 16439 16440 if (parms == NULL_TREE) 16441 parms = DECL_ARGUMENTS (fndecl); 16442 16443 unsigned int tokens_avail = parser->tokens_avail; 16444 gcc_assert (parser->tokens == &parser->tokens_buf[0]); 16445 bool is_cilkplus_cilk_simd_fn = false; 16446 16447 if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) 16448 { 16449 parser->tokens = parser->cilk_simd_fn_tokens->address (); 16450 parser->tokens_avail = vec_safe_length (parser->cilk_simd_fn_tokens); 16451 is_cilkplus_cilk_simd_fn = true; 16452 16453 if (lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl)) != NULL) 16454 { 16455 error_at (DECL_SOURCE_LOCATION (fndecl), 16456 "%<__simd__%> attribute cannot be used in the same " 16457 "function marked as a Cilk Plus SIMD-enabled function"); 16458 vec_free (parser->cilk_simd_fn_tokens); 16459 return; 16460 } 16461 16462 } 16463 else 16464 { 16465 parser->tokens = clauses.address (); 16466 parser->tokens_avail = clauses.length (); 16467 } 16468 16469 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */ 16470 while (parser->tokens_avail > 3) 16471 { 16472 c_token *token = c_parser_peek_token (parser); 16473 if (!is_cilkplus_cilk_simd_fn) 16474 gcc_assert (token->type == CPP_NAME 16475 && strcmp (IDENTIFIER_POINTER (token->value), "simd") == 0); 16476 else 16477 gcc_assert (token->type == CPP_NAME 16478 && is_cilkplus_vector_p (token->value)); 16479 c_parser_consume_token (parser); 16480 parser->in_pragma = true; 16481 16482 tree c = NULL_TREE; 16483 if (is_cilkplus_cilk_simd_fn) 16484 c = c_parser_omp_all_clauses (parser, CILK_SIMD_FN_CLAUSE_MASK, 16485 "SIMD-enabled functions attribute"); 16486 else 16487 c = c_parser_omp_all_clauses (parser, OMP_DECLARE_SIMD_CLAUSE_MASK, 16488 "#pragma omp declare simd"); 16489 c = c_omp_declare_simd_clauses_to_numbers (parms, c); 16490 if (c != NULL_TREE) 16491 c = tree_cons (NULL_TREE, c, NULL_TREE); 16492 if (is_cilkplus_cilk_simd_fn) 16493 { 16494 tree k = build_tree_list (get_identifier ("cilk simd function"), 16495 NULL_TREE); 16496 TREE_CHAIN (k) = DECL_ATTRIBUTES (fndecl); 16497 DECL_ATTRIBUTES (fndecl) = k; 16498 } 16499 c = build_tree_list (get_identifier ("omp declare simd"), c); 16500 TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl); 16501 DECL_ATTRIBUTES (fndecl) = c; 16502 } 16503 16504 parser->tokens = &parser->tokens_buf[0]; 16505 parser->tokens_avail = tokens_avail; 16506 if (clauses.exists ()) 16507 clauses[0].type = CPP_PRAGMA; 16508 16509 if (!vec_safe_is_empty (parser->cilk_simd_fn_tokens)) 16510 vec_free (parser->cilk_simd_fn_tokens); 16511 } 16512 16513 16514 /* OpenMP 4.0: 16515 # pragma omp declare target new-line 16516 declarations and definitions 16517 # pragma omp end declare target new-line 16518 16519 OpenMP 4.5: 16520 # pragma omp declare target ( extended-list ) new-line 16521 16522 # pragma omp declare target declare-target-clauses[seq] new-line */ 16523 16524 #define OMP_DECLARE_TARGET_CLAUSE_MASK \ 16525 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \ 16526 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK)) 16527 16528 static void 16529 c_parser_omp_declare_target (c_parser *parser) 16530 { 16531 location_t loc = c_parser_peek_token (parser)->location; 16532 tree clauses = NULL_TREE; 16533 if (c_parser_next_token_is (parser, CPP_NAME)) 16534 clauses = c_parser_omp_all_clauses (parser, OMP_DECLARE_TARGET_CLAUSE_MASK, 16535 "#pragma omp declare target"); 16536 else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) 16537 { 16538 clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO_DECLARE, 16539 clauses); 16540 clauses = c_finish_omp_clauses (clauses, true); 16541 c_parser_skip_to_pragma_eol (parser); 16542 } 16543 else 16544 { 16545 c_parser_skip_to_pragma_eol (parser); 16546 current_omp_declare_target_attribute++; 16547 return; 16548 } 16549 if (current_omp_declare_target_attribute) 16550 error_at (loc, "%<#pragma omp declare target%> with clauses in between " 16551 "%<#pragma omp declare target%> without clauses and " 16552 "%<#pragma omp end declare target%>"); 16553 for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c)) 16554 { 16555 tree t = OMP_CLAUSE_DECL (c), id; 16556 tree at1 = lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t)); 16557 tree at2 = lookup_attribute ("omp declare target link", 16558 DECL_ATTRIBUTES (t)); 16559 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINK) 16560 { 16561 id = get_identifier ("omp declare target link"); 16562 std::swap (at1, at2); 16563 } 16564 else 16565 id = get_identifier ("omp declare target"); 16566 if (at2) 16567 { 16568 error_at (OMP_CLAUSE_LOCATION (c), 16569 "%qD specified both in declare target %<link%> and %<to%>" 16570 " clauses", t); 16571 continue; 16572 } 16573 if (!at1) 16574 { 16575 DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t)); 16576 if (TREE_CODE (t) != FUNCTION_DECL && !is_global_var (t)) 16577 continue; 16578 16579 symtab_node *node = symtab_node::get (t); 16580 if (node != NULL) 16581 { 16582 node->offloadable = 1; 16583 if (ENABLE_OFFLOADING) 16584 { 16585 g->have_offload = true; 16586 if (is_a <varpool_node *> (node)) 16587 vec_safe_push (offload_vars, t); 16588 } 16589 } 16590 } 16591 } 16592 } 16593 16594 static void 16595 c_parser_omp_end_declare_target (c_parser *parser) 16596 { 16597 location_t loc = c_parser_peek_token (parser)->location; 16598 c_parser_consume_pragma (parser); 16599 if (c_parser_next_token_is (parser, CPP_NAME) 16600 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value), 16601 "declare") == 0) 16602 { 16603 c_parser_consume_token (parser); 16604 if (c_parser_next_token_is (parser, CPP_NAME) 16605 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value), 16606 "target") == 0) 16607 c_parser_consume_token (parser); 16608 else 16609 { 16610 c_parser_error (parser, "expected %<target%>"); 16611 c_parser_skip_to_pragma_eol (parser); 16612 return; 16613 } 16614 } 16615 else 16616 { 16617 c_parser_error (parser, "expected %<declare%>"); 16618 c_parser_skip_to_pragma_eol (parser); 16619 return; 16620 } 16621 c_parser_skip_to_pragma_eol (parser); 16622 if (!current_omp_declare_target_attribute) 16623 error_at (loc, "%<#pragma omp end declare target%> without corresponding " 16624 "%<#pragma omp declare target%>"); 16625 else 16626 current_omp_declare_target_attribute--; 16627 } 16628 16629 16630 /* OpenMP 4.0 16631 #pragma omp declare reduction (reduction-id : typename-list : expression) \ 16632 initializer-clause[opt] new-line 16633 16634 initializer-clause: 16635 initializer (omp_priv = initializer) 16636 initializer (function-name (argument-list)) */ 16637 16638 static void 16639 c_parser_omp_declare_reduction (c_parser *parser, enum pragma_context context) 16640 { 16641 unsigned int tokens_avail = 0, i; 16642 vec<tree> types = vNULL; 16643 vec<c_token> clauses = vNULL; 16644 enum tree_code reduc_code = ERROR_MARK; 16645 tree reduc_id = NULL_TREE; 16646 tree type; 16647 location_t rloc = c_parser_peek_token (parser)->location; 16648 16649 if (context == pragma_struct || context == pragma_param) 16650 { 16651 error ("%<#pragma omp declare reduction%> not at file or block scope"); 16652 goto fail; 16653 } 16654 16655 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 16656 goto fail; 16657 16658 switch (c_parser_peek_token (parser)->type) 16659 { 16660 case CPP_PLUS: 16661 reduc_code = PLUS_EXPR; 16662 break; 16663 case CPP_MULT: 16664 reduc_code = MULT_EXPR; 16665 break; 16666 case CPP_MINUS: 16667 reduc_code = MINUS_EXPR; 16668 break; 16669 case CPP_AND: 16670 reduc_code = BIT_AND_EXPR; 16671 break; 16672 case CPP_XOR: 16673 reduc_code = BIT_XOR_EXPR; 16674 break; 16675 case CPP_OR: 16676 reduc_code = BIT_IOR_EXPR; 16677 break; 16678 case CPP_AND_AND: 16679 reduc_code = TRUTH_ANDIF_EXPR; 16680 break; 16681 case CPP_OR_OR: 16682 reduc_code = TRUTH_ORIF_EXPR; 16683 break; 16684 case CPP_NAME: 16685 const char *p; 16686 p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 16687 if (strcmp (p, "min") == 0) 16688 { 16689 reduc_code = MIN_EXPR; 16690 break; 16691 } 16692 if (strcmp (p, "max") == 0) 16693 { 16694 reduc_code = MAX_EXPR; 16695 break; 16696 } 16697 reduc_id = c_parser_peek_token (parser)->value; 16698 break; 16699 default: 16700 c_parser_error (parser, 16701 "expected %<+%>, %<*%>, %<-%>, %<&%>, " 16702 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier"); 16703 goto fail; 16704 } 16705 16706 tree orig_reduc_id, reduc_decl; 16707 orig_reduc_id = reduc_id; 16708 reduc_id = c_omp_reduction_id (reduc_code, reduc_id); 16709 reduc_decl = c_omp_reduction_decl (reduc_id); 16710 c_parser_consume_token (parser); 16711 16712 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) 16713 goto fail; 16714 16715 while (true) 16716 { 16717 location_t loc = c_parser_peek_token (parser)->location; 16718 struct c_type_name *ctype = c_parser_type_name (parser); 16719 if (ctype != NULL) 16720 { 16721 type = groktypename (ctype, NULL, NULL); 16722 if (type == error_mark_node) 16723 ; 16724 else if ((INTEGRAL_TYPE_P (type) 16725 || TREE_CODE (type) == REAL_TYPE 16726 || TREE_CODE (type) == COMPLEX_TYPE) 16727 && orig_reduc_id == NULL_TREE) 16728 error_at (loc, "predeclared arithmetic type in " 16729 "%<#pragma omp declare reduction%>"); 16730 else if (TREE_CODE (type) == FUNCTION_TYPE 16731 || TREE_CODE (type) == ARRAY_TYPE) 16732 error_at (loc, "function or array type in " 16733 "%<#pragma omp declare reduction%>"); 16734 else if (TYPE_QUALS_NO_ADDR_SPACE (type)) 16735 error_at (loc, "const, volatile or restrict qualified type in " 16736 "%<#pragma omp declare reduction%>"); 16737 else 16738 { 16739 tree t; 16740 for (t = DECL_INITIAL (reduc_decl); t; t = TREE_CHAIN (t)) 16741 if (comptypes (TREE_PURPOSE (t), type)) 16742 { 16743 error_at (loc, "redeclaration of %qs " 16744 "%<#pragma omp declare reduction%> for " 16745 "type %qT", 16746 IDENTIFIER_POINTER (reduc_id) 16747 + sizeof ("omp declare reduction ") - 1, 16748 type); 16749 location_t ploc 16750 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t), 16751 0)); 16752 error_at (ploc, "previous %<#pragma omp declare " 16753 "reduction%>"); 16754 break; 16755 } 16756 if (t == NULL_TREE) 16757 types.safe_push (type); 16758 } 16759 if (c_parser_next_token_is (parser, CPP_COMMA)) 16760 c_parser_consume_token (parser); 16761 else 16762 break; 16763 } 16764 else 16765 break; 16766 } 16767 16768 if (!c_parser_require (parser, CPP_COLON, "expected %<:%>") 16769 || types.is_empty ()) 16770 { 16771 fail: 16772 clauses.release (); 16773 types.release (); 16774 while (true) 16775 { 16776 c_token *token = c_parser_peek_token (parser); 16777 if (token->type == CPP_EOF || token->type == CPP_PRAGMA_EOL) 16778 break; 16779 c_parser_consume_token (parser); 16780 } 16781 c_parser_skip_to_pragma_eol (parser); 16782 return; 16783 } 16784 16785 if (types.length () > 1) 16786 { 16787 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) 16788 { 16789 c_token *token = c_parser_peek_token (parser); 16790 if (token->type == CPP_EOF) 16791 goto fail; 16792 clauses.safe_push (*token); 16793 c_parser_consume_token (parser); 16794 } 16795 clauses.safe_push (*c_parser_peek_token (parser)); 16796 c_parser_skip_to_pragma_eol (parser); 16797 16798 /* Make sure nothing tries to read past the end of the tokens. */ 16799 c_token eof_token; 16800 memset (&eof_token, 0, sizeof (eof_token)); 16801 eof_token.type = CPP_EOF; 16802 clauses.safe_push (eof_token); 16803 clauses.safe_push (eof_token); 16804 } 16805 16806 int errs = errorcount; 16807 FOR_EACH_VEC_ELT (types, i, type) 16808 { 16809 tokens_avail = parser->tokens_avail; 16810 gcc_assert (parser->tokens == &parser->tokens_buf[0]); 16811 if (!clauses.is_empty ()) 16812 { 16813 parser->tokens = clauses.address (); 16814 parser->tokens_avail = clauses.length (); 16815 parser->in_pragma = true; 16816 } 16817 16818 bool nested = current_function_decl != NULL_TREE; 16819 if (nested) 16820 c_push_function_context (); 16821 tree fndecl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL, 16822 reduc_id, default_function_type); 16823 current_function_decl = fndecl; 16824 allocate_struct_function (fndecl, true); 16825 push_scope (); 16826 tree stmt = push_stmt_list (); 16827 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't 16828 warn about these. */ 16829 tree omp_out = build_decl (BUILTINS_LOCATION, VAR_DECL, 16830 get_identifier ("omp_out"), type); 16831 DECL_ARTIFICIAL (omp_out) = 1; 16832 DECL_CONTEXT (omp_out) = fndecl; 16833 pushdecl (omp_out); 16834 tree omp_in = build_decl (BUILTINS_LOCATION, VAR_DECL, 16835 get_identifier ("omp_in"), type); 16836 DECL_ARTIFICIAL (omp_in) = 1; 16837 DECL_CONTEXT (omp_in) = fndecl; 16838 pushdecl (omp_in); 16839 struct c_expr combiner = c_parser_expression (parser); 16840 struct c_expr initializer; 16841 tree omp_priv = NULL_TREE, omp_orig = NULL_TREE; 16842 bool bad = false; 16843 initializer.value = error_mark_node; 16844 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) 16845 bad = true; 16846 else if (c_parser_next_token_is (parser, CPP_NAME) 16847 && strcmp (IDENTIFIER_POINTER 16848 (c_parser_peek_token (parser)->value), 16849 "initializer") == 0) 16850 { 16851 c_parser_consume_token (parser); 16852 pop_scope (); 16853 push_scope (); 16854 omp_priv = build_decl (BUILTINS_LOCATION, VAR_DECL, 16855 get_identifier ("omp_priv"), type); 16856 DECL_ARTIFICIAL (omp_priv) = 1; 16857 DECL_INITIAL (omp_priv) = error_mark_node; 16858 DECL_CONTEXT (omp_priv) = fndecl; 16859 pushdecl (omp_priv); 16860 omp_orig = build_decl (BUILTINS_LOCATION, VAR_DECL, 16861 get_identifier ("omp_orig"), type); 16862 DECL_ARTIFICIAL (omp_orig) = 1; 16863 DECL_CONTEXT (omp_orig) = fndecl; 16864 pushdecl (omp_orig); 16865 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 16866 bad = true; 16867 else if (!c_parser_next_token_is (parser, CPP_NAME)) 16868 { 16869 c_parser_error (parser, "expected %<omp_priv%> or " 16870 "function-name"); 16871 bad = true; 16872 } 16873 else if (strcmp (IDENTIFIER_POINTER 16874 (c_parser_peek_token (parser)->value), 16875 "omp_priv") != 0) 16876 { 16877 if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN 16878 || c_parser_peek_token (parser)->id_kind != C_ID_ID) 16879 { 16880 c_parser_error (parser, "expected function-name %<(%>"); 16881 bad = true; 16882 } 16883 else 16884 initializer = c_parser_postfix_expression (parser); 16885 if (initializer.value 16886 && TREE_CODE (initializer.value) == CALL_EXPR) 16887 { 16888 int j; 16889 tree c = initializer.value; 16890 for (j = 0; j < call_expr_nargs (c); j++) 16891 { 16892 tree a = CALL_EXPR_ARG (c, j); 16893 STRIP_NOPS (a); 16894 if (TREE_CODE (a) == ADDR_EXPR 16895 && TREE_OPERAND (a, 0) == omp_priv) 16896 break; 16897 } 16898 if (j == call_expr_nargs (c)) 16899 error ("one of the initializer call arguments should be " 16900 "%<&omp_priv%>"); 16901 } 16902 } 16903 else 16904 { 16905 c_parser_consume_token (parser); 16906 if (!c_parser_require (parser, CPP_EQ, "expected %<=%>")) 16907 bad = true; 16908 else 16909 { 16910 tree st = push_stmt_list (); 16911 start_init (omp_priv, NULL_TREE, 0); 16912 location_t loc = c_parser_peek_token (parser)->location; 16913 struct c_expr init = c_parser_initializer (parser); 16914 finish_init (); 16915 finish_decl (omp_priv, loc, init.value, 16916 init.original_type, NULL_TREE); 16917 pop_stmt_list (st); 16918 } 16919 } 16920 if (!bad 16921 && !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) 16922 bad = true; 16923 } 16924 16925 if (!bad) 16926 { 16927 c_parser_skip_to_pragma_eol (parser); 16928 16929 tree t = tree_cons (type, make_tree_vec (omp_priv ? 6 : 3), 16930 DECL_INITIAL (reduc_decl)); 16931 DECL_INITIAL (reduc_decl) = t; 16932 DECL_SOURCE_LOCATION (omp_out) = rloc; 16933 TREE_VEC_ELT (TREE_VALUE (t), 0) = omp_out; 16934 TREE_VEC_ELT (TREE_VALUE (t), 1) = omp_in; 16935 TREE_VEC_ELT (TREE_VALUE (t), 2) = combiner.value; 16936 walk_tree (&combiner.value, c_check_omp_declare_reduction_r, 16937 &TREE_VEC_ELT (TREE_VALUE (t), 0), NULL); 16938 if (omp_priv) 16939 { 16940 DECL_SOURCE_LOCATION (omp_priv) = rloc; 16941 TREE_VEC_ELT (TREE_VALUE (t), 3) = omp_priv; 16942 TREE_VEC_ELT (TREE_VALUE (t), 4) = omp_orig; 16943 TREE_VEC_ELT (TREE_VALUE (t), 5) = initializer.value; 16944 walk_tree (&initializer.value, c_check_omp_declare_reduction_r, 16945 &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL); 16946 walk_tree (&DECL_INITIAL (omp_priv), 16947 c_check_omp_declare_reduction_r, 16948 &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL); 16949 } 16950 } 16951 16952 pop_stmt_list (stmt); 16953 pop_scope (); 16954 if (cfun->language != NULL) 16955 { 16956 ggc_free (cfun->language); 16957 cfun->language = NULL; 16958 } 16959 set_cfun (NULL); 16960 current_function_decl = NULL_TREE; 16961 if (nested) 16962 c_pop_function_context (); 16963 16964 if (!clauses.is_empty ()) 16965 { 16966 parser->tokens = &parser->tokens_buf[0]; 16967 parser->tokens_avail = tokens_avail; 16968 } 16969 if (bad) 16970 goto fail; 16971 if (errs != errorcount) 16972 break; 16973 } 16974 16975 clauses.release (); 16976 types.release (); 16977 } 16978 16979 16980 /* OpenMP 4.0 16981 #pragma omp declare simd declare-simd-clauses[optseq] new-line 16982 #pragma omp declare reduction (reduction-id : typename-list : expression) \ 16983 initializer-clause[opt] new-line 16984 #pragma omp declare target new-line */ 16985 16986 static void 16987 c_parser_omp_declare (c_parser *parser, enum pragma_context context) 16988 { 16989 c_parser_consume_pragma (parser); 16990 if (c_parser_next_token_is (parser, CPP_NAME)) 16991 { 16992 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 16993 if (strcmp (p, "simd") == 0) 16994 { 16995 /* c_parser_consume_token (parser); done in 16996 c_parser_omp_declare_simd. */ 16997 c_parser_omp_declare_simd (parser, context); 16998 return; 16999 } 17000 if (strcmp (p, "reduction") == 0) 17001 { 17002 c_parser_consume_token (parser); 17003 c_parser_omp_declare_reduction (parser, context); 17004 return; 17005 } 17006 if (!flag_openmp) /* flag_openmp_simd */ 17007 { 17008 c_parser_skip_to_pragma_eol (parser, false); 17009 return; 17010 } 17011 if (strcmp (p, "target") == 0) 17012 { 17013 c_parser_consume_token (parser); 17014 c_parser_omp_declare_target (parser); 17015 return; 17016 } 17017 } 17018 17019 c_parser_error (parser, "expected %<simd%> or %<reduction%> " 17020 "or %<target%>"); 17021 c_parser_skip_to_pragma_eol (parser); 17022 } 17023 17024 /* OpenMP 4.5: 17025 #pragma omp taskloop taskloop-clause[optseq] new-line 17026 for-loop 17027 17028 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line 17029 for-loop */ 17030 17031 #define OMP_TASKLOOP_CLAUSE_MASK \ 17032 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ 17033 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ 17034 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ 17035 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ 17036 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \ 17037 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \ 17038 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \ 17039 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \ 17040 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \ 17041 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ 17042 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \ 17043 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \ 17044 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \ 17045 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY)) 17046 17047 static tree 17048 c_parser_omp_taskloop (location_t loc, c_parser *parser, 17049 char *p_name, omp_clause_mask mask, tree *cclauses, 17050 bool *if_p) 17051 { 17052 tree clauses, block, ret; 17053 17054 strcat (p_name, " taskloop"); 17055 mask |= OMP_TASKLOOP_CLAUSE_MASK; 17056 17057 if (c_parser_next_token_is (parser, CPP_NAME)) 17058 { 17059 const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); 17060 17061 if (strcmp (p, "simd") == 0) 17062 { 17063 tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; 17064 if (cclauses == NULL) 17065 cclauses = cclauses_buf; 17066 mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION); 17067 c_parser_consume_token (parser); 17068 if (!flag_openmp) /* flag_openmp_simd */ 17069 return c_parser_omp_simd (loc, parser, p_name, mask, cclauses, 17070 if_p); 17071 block = c_begin_compound_stmt (true); 17072 ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses, if_p); 17073 block = c_end_compound_stmt (loc, block, true); 17074 if (ret == NULL) 17075 return ret; 17076 ret = make_node (OMP_TASKLOOP); 17077 TREE_TYPE (ret) = void_type_node; 17078 OMP_FOR_BODY (ret) = block; 17079 OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP]; 17080 SET_EXPR_LOCATION (ret, loc); 17081 add_stmt (ret); 17082 return ret; 17083 } 17084 } 17085 if (!flag_openmp) /* flag_openmp_simd */ 17086 { 17087 c_parser_skip_to_pragma_eol (parser, false); 17088 return NULL_TREE; 17089 } 17090 17091 clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); 17092 if (cclauses) 17093 { 17094 omp_split_clauses (loc, OMP_TASKLOOP, mask, clauses, cclauses); 17095 clauses = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP]; 17096 } 17097 17098 block = c_begin_compound_stmt (true); 17099 ret = c_parser_omp_for_loop (loc, parser, OMP_TASKLOOP, clauses, NULL, if_p); 17100 block = c_end_compound_stmt (loc, block, true); 17101 add_stmt (block); 17102 17103 return ret; 17104 } 17105 17106 /* Main entry point to parsing most OpenMP pragmas. */ 17107 17108 static void 17109 c_parser_omp_construct (c_parser *parser, bool *if_p) 17110 { 17111 enum pragma_kind p_kind; 17112 location_t loc; 17113 tree stmt; 17114 char p_name[sizeof "#pragma omp teams distribute parallel for simd"]; 17115 omp_clause_mask mask (0); 17116 17117 loc = c_parser_peek_token (parser)->location; 17118 p_kind = c_parser_peek_token (parser)->pragma_kind; 17119 c_parser_consume_pragma (parser); 17120 17121 switch (p_kind) 17122 { 17123 case PRAGMA_OACC_ATOMIC: 17124 c_parser_omp_atomic (loc, parser); 17125 return; 17126 case PRAGMA_OACC_CACHE: 17127 strcpy (p_name, "#pragma acc"); 17128 stmt = c_parser_oacc_cache (loc, parser); 17129 break; 17130 case PRAGMA_OACC_DATA: 17131 stmt = c_parser_oacc_data (loc, parser, if_p); 17132 break; 17133 case PRAGMA_OACC_HOST_DATA: 17134 stmt = c_parser_oacc_host_data (loc, parser, if_p); 17135 break; 17136 case PRAGMA_OACC_KERNELS: 17137 case PRAGMA_OACC_PARALLEL: 17138 strcpy (p_name, "#pragma acc"); 17139 stmt = c_parser_oacc_kernels_parallel (loc, parser, p_kind, p_name, 17140 if_p); 17141 break; 17142 case PRAGMA_OACC_LOOP: 17143 strcpy (p_name, "#pragma acc"); 17144 stmt = c_parser_oacc_loop (loc, parser, p_name, mask, NULL, if_p); 17145 break; 17146 case PRAGMA_OACC_WAIT: 17147 strcpy (p_name, "#pragma wait"); 17148 stmt = c_parser_oacc_wait (loc, parser, p_name); 17149 break; 17150 case PRAGMA_OMP_ATOMIC: 17151 c_parser_omp_atomic (loc, parser); 17152 return; 17153 case PRAGMA_OMP_CRITICAL: 17154 stmt = c_parser_omp_critical (loc, parser, if_p); 17155 break; 17156 case PRAGMA_OMP_DISTRIBUTE: 17157 strcpy (p_name, "#pragma omp"); 17158 stmt = c_parser_omp_distribute (loc, parser, p_name, mask, NULL, if_p); 17159 break; 17160 case PRAGMA_OMP_FOR: 17161 strcpy (p_name, "#pragma omp"); 17162 stmt = c_parser_omp_for (loc, parser, p_name, mask, NULL, if_p); 17163 break; 17164 case PRAGMA_OMP_MASTER: 17165 stmt = c_parser_omp_master (loc, parser, if_p); 17166 break; 17167 case PRAGMA_OMP_PARALLEL: 17168 strcpy (p_name, "#pragma omp"); 17169 stmt = c_parser_omp_parallel (loc, parser, p_name, mask, NULL, if_p); 17170 break; 17171 case PRAGMA_OMP_SECTIONS: 17172 strcpy (p_name, "#pragma omp"); 17173 stmt = c_parser_omp_sections (loc, parser, p_name, mask, NULL); 17174 break; 17175 case PRAGMA_OMP_SIMD: 17176 strcpy (p_name, "#pragma omp"); 17177 stmt = c_parser_omp_simd (loc, parser, p_name, mask, NULL, if_p); 17178 break; 17179 case PRAGMA_OMP_SINGLE: 17180 stmt = c_parser_omp_single (loc, parser, if_p); 17181 break; 17182 case PRAGMA_OMP_TASK: 17183 stmt = c_parser_omp_task (loc, parser, if_p); 17184 break; 17185 case PRAGMA_OMP_TASKGROUP: 17186 stmt = c_parser_omp_taskgroup (parser, if_p); 17187 break; 17188 case PRAGMA_OMP_TASKLOOP: 17189 strcpy (p_name, "#pragma omp"); 17190 stmt = c_parser_omp_taskloop (loc, parser, p_name, mask, NULL, if_p); 17191 break; 17192 case PRAGMA_OMP_TEAMS: 17193 strcpy (p_name, "#pragma omp"); 17194 stmt = c_parser_omp_teams (loc, parser, p_name, mask, NULL, if_p); 17195 break; 17196 default: 17197 gcc_unreachable (); 17198 } 17199 17200 if (stmt) 17201 gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION); 17202 } 17203 17204 17205 /* OpenMP 2.5: 17206 # pragma omp threadprivate (variable-list) */ 17207 17208 static void 17209 c_parser_omp_threadprivate (c_parser *parser) 17210 { 17211 tree vars, t; 17212 location_t loc; 17213 17214 c_parser_consume_pragma (parser); 17215 loc = c_parser_peek_token (parser)->location; 17216 vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); 17217 17218 /* Mark every variable in VARS to be assigned thread local storage. */ 17219 for (t = vars; t; t = TREE_CHAIN (t)) 17220 { 17221 tree v = TREE_PURPOSE (t); 17222 17223 /* FIXME diagnostics: Ideally we should keep individual 17224 locations for all the variables in the var list to make the 17225 following errors more precise. Perhaps 17226 c_parser_omp_var_list_parens() should construct a list of 17227 locations to go along with the var list. */ 17228 17229 /* If V had already been marked threadprivate, it doesn't matter 17230 whether it had been used prior to this point. */ 17231 if (!VAR_P (v)) 17232 error_at (loc, "%qD is not a variable", v); 17233 else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v)) 17234 error_at (loc, "%qE declared %<threadprivate%> after first use", v); 17235 else if (! is_global_var (v)) 17236 error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v); 17237 else if (TREE_TYPE (v) == error_mark_node) 17238 ; 17239 else if (! COMPLETE_TYPE_P (TREE_TYPE (v))) 17240 error_at (loc, "%<threadprivate%> %qE has incomplete type", v); 17241 else 17242 { 17243 if (! DECL_THREAD_LOCAL_P (v)) 17244 { 17245 set_decl_tls_model (v, decl_default_tls_model (v)); 17246 /* If rtl has been already set for this var, call 17247 make_decl_rtl once again, so that encode_section_info 17248 has a chance to look at the new decl flags. */ 17249 if (DECL_RTL_SET_P (v)) 17250 make_decl_rtl (v); 17251 } 17252 C_DECL_THREADPRIVATE_P (v) = 1; 17253 } 17254 } 17255 17256 c_parser_skip_to_pragma_eol (parser); 17257 } 17258 17259 /* Cilk Plus <#pragma simd> parsing routines. */ 17260 17261 /* Helper function for c_parser_pragma. Perform some sanity checking 17262 for <#pragma simd> constructs. Returns FALSE if there was a 17263 problem. */ 17264 17265 static bool 17266 c_parser_cilk_verify_simd (c_parser *parser, 17267 enum pragma_context context) 17268 { 17269 if (!flag_cilkplus) 17270 { 17271 warning (0, "pragma simd ignored because -fcilkplus is not enabled"); 17272 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); 17273 return false; 17274 } 17275 if (context == pragma_external) 17276 { 17277 c_parser_error (parser,"pragma simd must be inside a function"); 17278 c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); 17279 return false; 17280 } 17281 return true; 17282 } 17283 17284 /* Cilk Plus: 17285 This function is shared by SIMD-enabled functions and #pragma simd. 17286 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and 17287 CLAUSES is unused. The main purpose of this function is to parse a 17288 vectorlength attribute or clause and check for parse errors. 17289 When IS_SIMD_FN is true then the function is merely caching the tokens 17290 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token 17291 cache is cleared since there is no reason to continue. 17292 Syntax: 17293 vectorlength ( constant-expression ) */ 17294 17295 static tree 17296 c_parser_cilk_clause_vectorlength (c_parser *parser, tree clauses, 17297 bool is_simd_fn) 17298 { 17299 if (is_simd_fn) 17300 check_no_duplicate_clause (clauses, OMP_CLAUSE_SIMDLEN, "vectorlength"); 17301 else 17302 /* The vectorlength clause behaves exactly like OpenMP's safelen 17303 clause. Represent it in OpenMP terms. */ 17304 check_no_duplicate_clause (clauses, OMP_CLAUSE_SAFELEN, "vectorlength"); 17305 17306 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 17307 return clauses; 17308 17309 location_t loc = c_parser_peek_token (parser)->location; 17310 tree expr = c_parser_expr_no_commas (parser, NULL).value; 17311 expr = c_fully_fold (expr, false, NULL); 17312 17313 /* If expr is an error_mark_node then the above function would have 17314 emitted an error. No reason to do it twice. */ 17315 if (expr == error_mark_node) 17316 ; 17317 else if (!TREE_TYPE (expr) 17318 || !TREE_CONSTANT (expr) 17319 || !INTEGRAL_TYPE_P (TREE_TYPE (expr))) 17320 17321 error_at (loc, "vectorlength must be an integer constant"); 17322 else if (wi::exact_log2 (expr) == -1) 17323 error_at (loc, "vectorlength must be a power of 2"); 17324 else 17325 { 17326 if (is_simd_fn) 17327 { 17328 tree u = build_omp_clause (loc, OMP_CLAUSE_SIMDLEN); 17329 OMP_CLAUSE_SIMDLEN_EXPR (u) = expr; 17330 OMP_CLAUSE_CHAIN (u) = clauses; 17331 clauses = u; 17332 } 17333 else 17334 { 17335 tree u = build_omp_clause (loc, OMP_CLAUSE_SAFELEN); 17336 OMP_CLAUSE_SAFELEN_EXPR (u) = expr; 17337 OMP_CLAUSE_CHAIN (u) = clauses; 17338 clauses = u; 17339 } 17340 } 17341 17342 c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 17343 17344 return clauses; 17345 } 17346 17347 /* Cilk Plus: 17348 linear ( simd-linear-variable-list ) 17349 17350 simd-linear-variable-list: 17351 simd-linear-variable 17352 simd-linear-variable-list , simd-linear-variable 17353 17354 simd-linear-variable: 17355 id-expression 17356 id-expression : simd-linear-step 17357 17358 simd-linear-step: 17359 conditional-expression */ 17360 17361 static tree 17362 c_parser_cilk_clause_linear (c_parser *parser, tree clauses) 17363 { 17364 if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 17365 return clauses; 17366 17367 location_t loc = c_parser_peek_token (parser)->location; 17368 17369 if (c_parser_next_token_is_not (parser, CPP_NAME) 17370 || c_parser_peek_token (parser)->id_kind != C_ID_ID) 17371 c_parser_error (parser, "expected identifier"); 17372 17373 while (c_parser_next_token_is (parser, CPP_NAME) 17374 && c_parser_peek_token (parser)->id_kind == C_ID_ID) 17375 { 17376 tree var = lookup_name (c_parser_peek_token (parser)->value); 17377 17378 if (var == NULL) 17379 { 17380 undeclared_variable (c_parser_peek_token (parser)->location, 17381 c_parser_peek_token (parser)->value); 17382 c_parser_consume_token (parser); 17383 } 17384 else if (var == error_mark_node) 17385 c_parser_consume_token (parser); 17386 else 17387 { 17388 tree step = integer_one_node; 17389 17390 /* Parse the linear step if present. */ 17391 if (c_parser_peek_2nd_token (parser)->type == CPP_COLON) 17392 { 17393 c_parser_consume_token (parser); 17394 c_parser_consume_token (parser); 17395 17396 tree expr = c_parser_expr_no_commas (parser, NULL).value; 17397 expr = c_fully_fold (expr, false, NULL); 17398 17399 if (TREE_TYPE (expr) 17400 && INTEGRAL_TYPE_P (TREE_TYPE (expr)) 17401 && (TREE_CONSTANT (expr) 17402 || DECL_P (expr))) 17403 step = expr; 17404 else 17405 c_parser_error (parser, 17406 "step size must be an integer constant " 17407 "expression or an integer variable"); 17408 } 17409 else 17410 c_parser_consume_token (parser); 17411 17412 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */ 17413 tree u = build_omp_clause (loc, OMP_CLAUSE_LINEAR); 17414 OMP_CLAUSE_DECL (u) = var; 17415 OMP_CLAUSE_LINEAR_STEP (u) = step; 17416 OMP_CLAUSE_CHAIN (u) = clauses; 17417 clauses = u; 17418 } 17419 17420 if (c_parser_next_token_is_not (parser, CPP_COMMA)) 17421 break; 17422 17423 c_parser_consume_token (parser); 17424 } 17425 17426 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); 17427 17428 return clauses; 17429 } 17430 17431 /* Returns the name of the next clause. If the clause is not 17432 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is 17433 not consumed. Otherwise, the appropriate pragma_simd_clause is 17434 returned and the token is consumed. */ 17435 17436 static pragma_omp_clause 17437 c_parser_cilk_clause_name (c_parser *parser) 17438 { 17439 pragma_omp_clause result; 17440 c_token *token = c_parser_peek_token (parser); 17441 17442 if (!token->value || token->type != CPP_NAME) 17443 return PRAGMA_CILK_CLAUSE_NONE; 17444 17445 const char *p = IDENTIFIER_POINTER (token->value); 17446 17447 if (!strcmp (p, "vectorlength")) 17448 result = PRAGMA_CILK_CLAUSE_VECTORLENGTH; 17449 else if (!strcmp (p, "linear")) 17450 result = PRAGMA_CILK_CLAUSE_LINEAR; 17451 else if (!strcmp (p, "private")) 17452 result = PRAGMA_CILK_CLAUSE_PRIVATE; 17453 else if (!strcmp (p, "firstprivate")) 17454 result = PRAGMA_CILK_CLAUSE_FIRSTPRIVATE; 17455 else if (!strcmp (p, "lastprivate")) 17456 result = PRAGMA_CILK_CLAUSE_LASTPRIVATE; 17457 else if (!strcmp (p, "reduction")) 17458 result = PRAGMA_CILK_CLAUSE_REDUCTION; 17459 else 17460 return PRAGMA_CILK_CLAUSE_NONE; 17461 17462 c_parser_consume_token (parser); 17463 return result; 17464 } 17465 17466 /* Parse all #<pragma simd> clauses. Return the list of clauses 17467 found. */ 17468 17469 static tree 17470 c_parser_cilk_all_clauses (c_parser *parser) 17471 { 17472 tree clauses = NULL; 17473 17474 while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) 17475 { 17476 pragma_omp_clause c_kind; 17477 17478 c_kind = c_parser_cilk_clause_name (parser); 17479 17480 switch (c_kind) 17481 { 17482 case PRAGMA_CILK_CLAUSE_VECTORLENGTH: 17483 clauses = c_parser_cilk_clause_vectorlength (parser, clauses, false); 17484 break; 17485 case PRAGMA_CILK_CLAUSE_LINEAR: 17486 clauses = c_parser_cilk_clause_linear (parser, clauses); 17487 break; 17488 case PRAGMA_CILK_CLAUSE_PRIVATE: 17489 /* Use the OpenMP counterpart. */ 17490 clauses = c_parser_omp_clause_private (parser, clauses); 17491 break; 17492 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE: 17493 /* Use the OpenMP counterpart. */ 17494 clauses = c_parser_omp_clause_firstprivate (parser, clauses); 17495 break; 17496 case PRAGMA_CILK_CLAUSE_LASTPRIVATE: 17497 /* Use the OpenMP counterpart. */ 17498 clauses = c_parser_omp_clause_lastprivate (parser, clauses); 17499 break; 17500 case PRAGMA_CILK_CLAUSE_REDUCTION: 17501 /* Use the OpenMP counterpart. */ 17502 clauses = c_parser_omp_clause_reduction (parser, clauses); 17503 break; 17504 default: 17505 c_parser_error (parser, "expected %<#pragma simd%> clause"); 17506 goto saw_error; 17507 } 17508 } 17509 17510 saw_error: 17511 c_parser_skip_to_pragma_eol (parser); 17512 return c_finish_cilk_clauses (clauses); 17513 } 17514 17515 /* This function helps parse the grainsize pragma for a _Cilk_for statement. 17516 Here is the correct syntax of this pragma: 17517 #pragma cilk grainsize = <EXP> 17518 */ 17519 17520 static void 17521 c_parser_cilk_grainsize (c_parser *parser, bool *if_p) 17522 { 17523 extern tree convert_to_integer (tree, tree); 17524 17525 /* consume the 'grainsize' keyword. */ 17526 c_parser_consume_pragma (parser); 17527 17528 if (c_parser_require (parser, CPP_EQ, "expected %<=%>") != 0) 17529 { 17530 struct c_expr g_expr = c_parser_binary_expression (parser, NULL, NULL); 17531 if (g_expr.value == error_mark_node) 17532 { 17533 c_parser_skip_to_pragma_eol (parser); 17534 return; 17535 } 17536 tree grain = convert_to_integer (long_integer_type_node, 17537 c_fully_fold (g_expr.value, false, 17538 NULL)); 17539 c_parser_skip_to_pragma_eol (parser); 17540 c_token *token = c_parser_peek_token (parser); 17541 if (token && token->type == CPP_KEYWORD 17542 && token->keyword == RID_CILK_FOR) 17543 { 17544 if (grain == NULL_TREE || grain == error_mark_node) 17545 grain = integer_zero_node; 17546 c_parser_cilk_for (parser, grain, if_p); 17547 } 17548 else 17549 warning (0, "%<#pragma cilk grainsize%> is not followed by " 17550 "%<_Cilk_for%>"); 17551 } 17552 else 17553 c_parser_skip_to_pragma_eol (parser); 17554 } 17555 17556 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */ 17557 17558 static void 17559 c_parser_cilk_simd (c_parser *parser, bool *if_p) 17560 { 17561 tree clauses = c_parser_cilk_all_clauses (parser); 17562 tree block = c_begin_compound_stmt (true); 17563 location_t loc = c_parser_peek_token (parser)->location; 17564 c_parser_omp_for_loop (loc, parser, CILK_SIMD, clauses, NULL, if_p); 17565 block = c_end_compound_stmt (loc, block, true); 17566 add_stmt (block); 17567 } 17568 17569 /* Create an artificial decl with TYPE and emit initialization of it with 17570 INIT. */ 17571 17572 static tree 17573 c_get_temp_regvar (tree type, tree init) 17574 { 17575 location_t loc = EXPR_LOCATION (init); 17576 tree decl = build_decl (loc, VAR_DECL, NULL_TREE, type); 17577 DECL_ARTIFICIAL (decl) = 1; 17578 DECL_IGNORED_P (decl) = 1; 17579 pushdecl (decl); 17580 tree t = build2 (INIT_EXPR, type, decl, init); 17581 add_stmt (t); 17582 return decl; 17583 } 17584 17585 /* Main entry point for parsing Cilk Plus _Cilk_for loops. 17586 GRAIN is the grain value passed in through pragma or 0. */ 17587 17588 static void 17589 c_parser_cilk_for (c_parser *parser, tree grain, bool *if_p) 17590 { 17591 tree clauses = build_omp_clause (EXPR_LOCATION (grain), OMP_CLAUSE_SCHEDULE); 17592 OMP_CLAUSE_SCHEDULE_KIND (clauses) = OMP_CLAUSE_SCHEDULE_CILKFOR; 17593 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses) = grain; 17594 clauses = c_finish_omp_clauses (clauses, false); 17595 17596 tree block = c_begin_compound_stmt (true); 17597 tree sb = push_stmt_list (); 17598 location_t loc = c_parser_peek_token (parser)->location; 17599 tree omp_for = c_parser_omp_for_loop (loc, parser, CILK_FOR, clauses, NULL, 17600 if_p); 17601 sb = pop_stmt_list (sb); 17602 17603 if (omp_for) 17604 { 17605 tree omp_par = make_node (OMP_PARALLEL); 17606 TREE_TYPE (omp_par) = void_type_node; 17607 OMP_PARALLEL_CLAUSES (omp_par) = NULL_TREE; 17608 tree bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL); 17609 TREE_SIDE_EFFECTS (bind) = 1; 17610 BIND_EXPR_BODY (bind) = sb; 17611 OMP_PARALLEL_BODY (omp_par) = bind; 17612 if (OMP_FOR_PRE_BODY (omp_for)) 17613 { 17614 add_stmt (OMP_FOR_PRE_BODY (omp_for)); 17615 OMP_FOR_PRE_BODY (omp_for) = NULL_TREE; 17616 } 17617 tree init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0); 17618 tree decl = TREE_OPERAND (init, 0); 17619 tree cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), 0); 17620 tree incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0); 17621 tree t = TREE_OPERAND (cond, 1), c, clauses = NULL_TREE; 17622 if (TREE_CODE (t) != INTEGER_CST) 17623 { 17624 TREE_OPERAND (cond, 1) = c_get_temp_regvar (TREE_TYPE (t), t); 17625 c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); 17626 OMP_CLAUSE_DECL (c) = TREE_OPERAND (cond, 1); 17627 OMP_CLAUSE_CHAIN (c) = clauses; 17628 clauses = c; 17629 } 17630 if (TREE_CODE (incr) == MODIFY_EXPR) 17631 { 17632 t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1); 17633 if (TREE_CODE (t) != INTEGER_CST) 17634 { 17635 TREE_OPERAND (TREE_OPERAND (incr, 1), 1) 17636 = c_get_temp_regvar (TREE_TYPE (t), t); 17637 c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); 17638 OMP_CLAUSE_DECL (c) = TREE_OPERAND (TREE_OPERAND (incr, 1), 1); 17639 OMP_CLAUSE_CHAIN (c) = clauses; 17640 clauses = c; 17641 } 17642 } 17643 t = TREE_OPERAND (init, 1); 17644 if (TREE_CODE (t) != INTEGER_CST) 17645 { 17646 TREE_OPERAND (init, 1) = c_get_temp_regvar (TREE_TYPE (t), t); 17647 c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); 17648 OMP_CLAUSE_DECL (c) = TREE_OPERAND (init, 1); 17649 OMP_CLAUSE_CHAIN (c) = clauses; 17650 clauses = c; 17651 } 17652 c = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE); 17653 OMP_CLAUSE_DECL (c) = decl; 17654 OMP_CLAUSE_CHAIN (c) = clauses; 17655 clauses = c; 17656 c = build_omp_clause (input_location, OMP_CLAUSE__CILK_FOR_COUNT_); 17657 OMP_CLAUSE_OPERAND (c, 0) 17658 = cilk_for_number_of_iterations (omp_for); 17659 OMP_CLAUSE_CHAIN (c) = clauses; 17660 OMP_PARALLEL_CLAUSES (omp_par) = c_finish_omp_clauses (c, true); 17661 add_stmt (omp_par); 17662 } 17663 17664 block = c_end_compound_stmt (loc, block, true); 17665 add_stmt (block); 17666 } 17667 17668 17669 /* Parse a transaction attribute (GCC Extension). 17670 17671 transaction-attribute: 17672 attributes 17673 [ [ any-word ] ] 17674 17675 The transactional memory language description is written for C++, 17676 and uses the C++0x attribute syntax. For compatibility, allow the 17677 bracket style for transactions in C as well. */ 17678 17679 static tree 17680 c_parser_transaction_attributes (c_parser *parser) 17681 { 17682 tree attr_name, attr = NULL; 17683 17684 if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) 17685 return c_parser_attributes (parser); 17686 17687 if (!c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) 17688 return NULL_TREE; 17689 c_parser_consume_token (parser); 17690 if (!c_parser_require (parser, CPP_OPEN_SQUARE, "expected %<[%>")) 17691 goto error1; 17692 17693 attr_name = c_parser_attribute_any_word (parser); 17694 if (attr_name) 17695 { 17696 c_parser_consume_token (parser); 17697 attr = build_tree_list (attr_name, NULL_TREE); 17698 } 17699 else 17700 c_parser_error (parser, "expected identifier"); 17701 17702 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); 17703 error1: 17704 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); 17705 return attr; 17706 } 17707 17708 /* Parse a __transaction_atomic or __transaction_relaxed statement 17709 (GCC Extension). 17710 17711 transaction-statement: 17712 __transaction_atomic transaction-attribute[opt] compound-statement 17713 __transaction_relaxed compound-statement 17714 17715 Note that the only valid attribute is: "outer". 17716 */ 17717 17718 static tree 17719 c_parser_transaction (c_parser *parser, enum rid keyword) 17720 { 17721 unsigned int old_in = parser->in_transaction; 17722 unsigned int this_in = 1, new_in; 17723 location_t loc = c_parser_peek_token (parser)->location; 17724 tree stmt, attrs; 17725 17726 gcc_assert ((keyword == RID_TRANSACTION_ATOMIC 17727 || keyword == RID_TRANSACTION_RELAXED) 17728 && c_parser_next_token_is_keyword (parser, keyword)); 17729 c_parser_consume_token (parser); 17730 17731 if (keyword == RID_TRANSACTION_RELAXED) 17732 this_in |= TM_STMT_ATTR_RELAXED; 17733 else 17734 { 17735 attrs = c_parser_transaction_attributes (parser); 17736 if (attrs) 17737 this_in |= parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER); 17738 } 17739 17740 /* Keep track if we're in the lexical scope of an outer transaction. */ 17741 new_in = this_in | (old_in & TM_STMT_ATTR_OUTER); 17742 17743 parser->in_transaction = new_in; 17744 stmt = c_parser_compound_statement (parser); 17745 parser->in_transaction = old_in; 17746 17747 if (flag_tm) 17748 stmt = c_finish_transaction (loc, stmt, this_in); 17749 else 17750 error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ? 17751 "%<__transaction_atomic%> without transactional memory support enabled" 17752 : "%<__transaction_relaxed %> " 17753 "without transactional memory support enabled")); 17754 17755 return stmt; 17756 } 17757 17758 /* Parse a __transaction_atomic or __transaction_relaxed expression 17759 (GCC Extension). 17760 17761 transaction-expression: 17762 __transaction_atomic ( expression ) 17763 __transaction_relaxed ( expression ) 17764 */ 17765 17766 static struct c_expr 17767 c_parser_transaction_expression (c_parser *parser, enum rid keyword) 17768 { 17769 struct c_expr ret; 17770 unsigned int old_in = parser->in_transaction; 17771 unsigned int this_in = 1; 17772 location_t loc = c_parser_peek_token (parser)->location; 17773 tree attrs; 17774 17775 gcc_assert ((keyword == RID_TRANSACTION_ATOMIC 17776 || keyword == RID_TRANSACTION_RELAXED) 17777 && c_parser_next_token_is_keyword (parser, keyword)); 17778 c_parser_consume_token (parser); 17779 17780 if (keyword == RID_TRANSACTION_RELAXED) 17781 this_in |= TM_STMT_ATTR_RELAXED; 17782 else 17783 { 17784 attrs = c_parser_transaction_attributes (parser); 17785 if (attrs) 17786 this_in |= parse_tm_stmt_attr (attrs, 0); 17787 } 17788 17789 parser->in_transaction = this_in; 17790 if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) 17791 { 17792 tree expr = c_parser_expression (parser).value; 17793 ret.original_type = TREE_TYPE (expr); 17794 ret.value = build1 (TRANSACTION_EXPR, ret.original_type, expr); 17795 if (this_in & TM_STMT_ATTR_RELAXED) 17796 TRANSACTION_EXPR_RELAXED (ret.value) = 1; 17797 SET_EXPR_LOCATION (ret.value, loc); 17798 ret.original_code = TRANSACTION_EXPR; 17799 if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) 17800 { 17801 c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); 17802 goto error; 17803 } 17804 } 17805 else 17806 { 17807 error: 17808 ret.value = error_mark_node; 17809 ret.original_code = ERROR_MARK; 17810 ret.original_type = NULL; 17811 } 17812 parser->in_transaction = old_in; 17813 17814 if (!flag_tm) 17815 error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ? 17816 "%<__transaction_atomic%> without transactional memory support enabled" 17817 : "%<__transaction_relaxed %> " 17818 "without transactional memory support enabled")); 17819 17820 set_c_expr_source_range (&ret, loc, loc); 17821 17822 return ret; 17823 } 17824 17825 /* Parse a __transaction_cancel statement (GCC Extension). 17826 17827 transaction-cancel-statement: 17828 __transaction_cancel transaction-attribute[opt] ; 17829 17830 Note that the only valid attribute is "outer". 17831 */ 17832 17833 static tree 17834 c_parser_transaction_cancel (c_parser *parser) 17835 { 17836 location_t loc = c_parser_peek_token (parser)->location; 17837 tree attrs; 17838 bool is_outer = false; 17839 17840 gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRANSACTION_CANCEL)); 17841 c_parser_consume_token (parser); 17842 17843 attrs = c_parser_transaction_attributes (parser); 17844 if (attrs) 17845 is_outer = (parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER) != 0); 17846 17847 if (!flag_tm) 17848 { 17849 error_at (loc, "%<__transaction_cancel%> without " 17850 "transactional memory support enabled"); 17851 goto ret_error; 17852 } 17853 else if (parser->in_transaction & TM_STMT_ATTR_RELAXED) 17854 { 17855 error_at (loc, "%<__transaction_cancel%> within a " 17856 "%<__transaction_relaxed%>"); 17857 goto ret_error; 17858 } 17859 else if (is_outer) 17860 { 17861 if ((parser->in_transaction & TM_STMT_ATTR_OUTER) == 0 17862 && !is_tm_may_cancel_outer (current_function_decl)) 17863 { 17864 error_at (loc, "outer %<__transaction_cancel%> not " 17865 "within outer %<__transaction_atomic%>"); 17866 error_at (loc, " or a %<transaction_may_cancel_outer%> function"); 17867 goto ret_error; 17868 } 17869 } 17870 else if (parser->in_transaction == 0) 17871 { 17872 error_at (loc, "%<__transaction_cancel%> not within " 17873 "%<__transaction_atomic%>"); 17874 goto ret_error; 17875 } 17876 17877 return add_stmt (build_tm_abort_call (loc, is_outer)); 17878 17879 ret_error: 17880 return build1 (NOP_EXPR, void_type_node, error_mark_node); 17881 } 17882 17883 /* Parse a single source file. */ 17884 17885 void 17886 c_parse_file (void) 17887 { 17888 /* Use local storage to begin. If the first token is a pragma, parse it. 17889 If it is #pragma GCC pch_preprocess, then this will load a PCH file 17890 which will cause garbage collection. */ 17891 c_parser tparser; 17892 17893 memset (&tparser, 0, sizeof tparser); 17894 tparser.tokens = &tparser.tokens_buf[0]; 17895 the_parser = &tparser; 17896 17897 if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS) 17898 c_parser_pragma_pch_preprocess (&tparser); 17899 17900 the_parser = ggc_alloc<c_parser> (); 17901 *the_parser = tparser; 17902 if (tparser.tokens == &tparser.tokens_buf[0]) 17903 the_parser->tokens = &the_parser->tokens_buf[0]; 17904 17905 /* Initialize EH, if we've been told to do so. */ 17906 if (flag_exceptions) 17907 using_eh_for_cleanups (); 17908 17909 c_parser_translation_unit (the_parser); 17910 the_parser = NULL; 17911 } 17912 17913 /* This function parses Cilk Plus array notation. The starting index is 17914 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The 17915 return value of this function is a tree_node called VALUE_TREE of type 17916 ARRAY_NOTATION_REF. */ 17917 17918 static tree 17919 c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index, 17920 tree array_value) 17921 { 17922 c_token *token = NULL; 17923 tree start_index = NULL_TREE, end_index = NULL_TREE, stride = NULL_TREE; 17924 tree value_tree = NULL_TREE, type = NULL_TREE, array_type = NULL_TREE; 17925 tree array_type_domain = NULL_TREE; 17926 17927 if (array_value == error_mark_node || initial_index == error_mark_node) 17928 { 17929 /* No need to continue. If either of these 2 were true, then an error 17930 must be emitted already. Thus, no need to emit them twice. */ 17931 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); 17932 return error_mark_node; 17933 } 17934 17935 array_type = TREE_TYPE (array_value); 17936 gcc_assert (array_type); 17937 if (TREE_CODE (array_type) != ARRAY_TYPE 17938 && TREE_CODE (array_type) != POINTER_TYPE) 17939 { 17940 error_at (loc, "base of array section must be pointer or array type"); 17941 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); 17942 return error_mark_node; 17943 } 17944 type = TREE_TYPE (array_type); 17945 token = c_parser_peek_token (parser); 17946 17947 if (token->type == CPP_EOF) 17948 { 17949 c_parser_error (parser, "expected %<:%> or numeral"); 17950 return value_tree; 17951 } 17952 else if (token->type == CPP_COLON) 17953 { 17954 if (!initial_index) 17955 { 17956 /* If we are here, then we have a case like this A[:]. */ 17957 c_parser_consume_token (parser); 17958 if (TREE_CODE (array_type) == POINTER_TYPE) 17959 { 17960 error_at (loc, "start-index and length fields necessary for " 17961 "using array notations in pointers"); 17962 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); 17963 return error_mark_node; 17964 } 17965 if (TREE_CODE (array_type) == FUNCTION_TYPE) 17966 { 17967 error_at (loc, "array notations cannot be used with function " 17968 "type"); 17969 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); 17970 return error_mark_node; 17971 } 17972 array_type_domain = TYPE_DOMAIN (array_type); 17973 17974 if (!array_type_domain) 17975 { 17976 error_at (loc, "start-index and length fields necessary for " 17977 "using array notations in dimensionless arrays"); 17978 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); 17979 return error_mark_node; 17980 } 17981 17982 start_index = TYPE_MINVAL (array_type_domain); 17983 start_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, 17984 start_index); 17985 if (!TYPE_MAXVAL (array_type_domain) 17986 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain))) 17987 { 17988 error_at (loc, "start-index and length fields necessary for " 17989 "using array notations in variable-length arrays"); 17990 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); 17991 return error_mark_node; 17992 } 17993 end_index = TYPE_MAXVAL (array_type_domain); 17994 end_index = fold_build2 (PLUS_EXPR, TREE_TYPE (end_index), 17995 end_index, integer_one_node); 17996 end_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, end_index); 17997 stride = build_int_cst (integer_type_node, 1); 17998 stride = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, stride); 17999 } 18000 else if (initial_index != error_mark_node) 18001 { 18002 /* If we are here, then there should be 2 possibilities: 18003 1. Array [EXPR : EXPR] 18004 2. Array [EXPR : EXPR : EXPR] 18005 */ 18006 start_index = initial_index; 18007 18008 if (TREE_CODE (array_type) == FUNCTION_TYPE) 18009 { 18010 error_at (loc, "array notations cannot be used with function " 18011 "type"); 18012 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); 18013 return error_mark_node; 18014 } 18015 c_parser_consume_token (parser); /* consume the ':' */ 18016 struct c_expr ce = c_parser_expression (parser); 18017 ce = convert_lvalue_to_rvalue (loc, ce, false, false); 18018 end_index = ce.value; 18019 if (!end_index || end_index == error_mark_node) 18020 { 18021 c_parser_skip_to_end_of_block_or_statement (parser); 18022 return error_mark_node; 18023 } 18024 if (c_parser_peek_token (parser)->type == CPP_COLON) 18025 { 18026 c_parser_consume_token (parser); 18027 ce = c_parser_expression (parser); 18028 ce = convert_lvalue_to_rvalue (loc, ce, false, false); 18029 stride = ce.value; 18030 if (!stride || stride == error_mark_node) 18031 { 18032 c_parser_skip_to_end_of_block_or_statement (parser); 18033 return error_mark_node; 18034 } 18035 } 18036 } 18037 else 18038 c_parser_error (parser, "expected array notation expression"); 18039 } 18040 else 18041 c_parser_error (parser, "expected array notation expression"); 18042 18043 c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); 18044 18045 value_tree = build_array_notation_ref (loc, array_value, start_index, 18046 end_index, stride, type); 18047 if (value_tree != error_mark_node) 18048 SET_EXPR_LOCATION (value_tree, loc); 18049 return value_tree; 18050 } 18051 18052 #include "gt-c-c-parser.h" 18053