1 /* Perform the semantic phase of parsing, i.e., the process of 2 building tree structure, checking semantic consistency, and 3 building RTL. These routines are used both during actual parsing 4 and during the instantiation of template functions. 5 6 Copyright (C) 1998-2019 Free Software Foundation, Inc. 7 Written by Mark Mitchell (mmitchell@usa.net) based on code found 8 formerly in parse.y and pt.c. 9 10 This file is part of GCC. 11 12 GCC is free software; you can redistribute it and/or modify it 13 under the terms of the GNU General Public License as published by 14 the Free Software Foundation; either version 3, or (at your option) 15 any later version. 16 17 GCC is distributed in the hope that it will be useful, but 18 WITHOUT ANY WARRANTY; without even the implied warranty of 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 General Public License for more details. 21 22 You should have received a copy of the GNU General Public License 23 along with GCC; see the file COPYING3. If not see 24 <http://www.gnu.org/licenses/>. */ 25 26 #include "config.h" 27 #include "system.h" 28 #include "coretypes.h" 29 #include "target.h" 30 #include "bitmap.h" 31 #include "cp-tree.h" 32 #include "stringpool.h" 33 #include "cgraph.h" 34 #include "stmt.h" 35 #include "varasm.h" 36 #include "stor-layout.h" 37 #include "c-family/c-objc.h" 38 #include "tree-inline.h" 39 #include "intl.h" 40 #include "tree-iterator.h" 41 #include "omp-general.h" 42 #include "convert.h" 43 #include "stringpool.h" 44 #include "attribs.h" 45 #include "gomp-constants.h" 46 #include "predict.h" 47 #include "memmodel.h" 48 49 /* There routines provide a modular interface to perform many parsing 50 operations. They may therefore be used during actual parsing, or 51 during template instantiation, which may be regarded as a 52 degenerate form of parsing. */ 53 54 static tree maybe_convert_cond (tree); 55 static tree finalize_nrv_r (tree *, int *, void *); 56 static tree capture_decltype (tree); 57 58 /* Used for OpenMP non-static data member privatization. */ 59 60 static hash_map<tree, tree> *omp_private_member_map; 61 static vec<tree> omp_private_member_vec; 62 static bool omp_private_member_ignore_next; 63 64 65 /* Deferred Access Checking Overview 66 --------------------------------- 67 68 Most C++ expressions and declarations require access checking 69 to be performed during parsing. However, in several cases, 70 this has to be treated differently. 71 72 For member declarations, access checking has to be deferred 73 until more information about the declaration is known. For 74 example: 75 76 class A { 77 typedef int X; 78 public: 79 X f(); 80 }; 81 82 A::X A::f(); 83 A::X g(); 84 85 When we are parsing the function return type `A::X', we don't 86 really know if this is allowed until we parse the function name. 87 88 Furthermore, some contexts require that access checking is 89 never performed at all. These include class heads, and template 90 instantiations. 91 92 Typical use of access checking functions is described here: 93 94 1. When we enter a context that requires certain access checking 95 mode, the function `push_deferring_access_checks' is called with 96 DEFERRING argument specifying the desired mode. Access checking 97 may be performed immediately (dk_no_deferred), deferred 98 (dk_deferred), or not performed (dk_no_check). 99 100 2. When a declaration such as a type, or a variable, is encountered, 101 the function `perform_or_defer_access_check' is called. It 102 maintains a vector of all deferred checks. 103 104 3. The global `current_class_type' or `current_function_decl' is then 105 setup by the parser. `enforce_access' relies on these information 106 to check access. 107 108 4. Upon exiting the context mentioned in step 1, 109 `perform_deferred_access_checks' is called to check all declaration 110 stored in the vector. `pop_deferring_access_checks' is then 111 called to restore the previous access checking mode. 112 113 In case of parsing error, we simply call `pop_deferring_access_checks' 114 without `perform_deferred_access_checks'. */ 115 116 struct GTY(()) deferred_access { 117 /* A vector representing name-lookups for which we have deferred 118 checking access controls. We cannot check the accessibility of 119 names used in a decl-specifier-seq until we know what is being 120 declared because code like: 121 122 class A { 123 class B {}; 124 B* f(); 125 } 126 127 A::B* A::f() { return 0; } 128 129 is valid, even though `A::B' is not generally accessible. */ 130 vec<deferred_access_check, va_gc> * GTY(()) deferred_access_checks; 131 132 /* The current mode of access checks. */ 133 enum deferring_kind deferring_access_checks_kind; 134 135 }; 136 137 /* Data for deferred access checking. */ 138 static GTY(()) vec<deferred_access, va_gc> *deferred_access_stack; 139 static GTY(()) unsigned deferred_access_no_check; 140 141 /* Save the current deferred access states and start deferred 142 access checking iff DEFER_P is true. */ 143 144 void 145 push_deferring_access_checks (deferring_kind deferring) 146 { 147 /* For context like template instantiation, access checking 148 disabling applies to all nested context. */ 149 if (deferred_access_no_check || deferring == dk_no_check) 150 deferred_access_no_check++; 151 else 152 { 153 deferred_access e = {NULL, deferring}; 154 vec_safe_push (deferred_access_stack, e); 155 } 156 } 157 158 /* Save the current deferred access states and start deferred access 159 checking, continuing the set of deferred checks in CHECKS. */ 160 161 void 162 reopen_deferring_access_checks (vec<deferred_access_check, va_gc> * checks) 163 { 164 push_deferring_access_checks (dk_deferred); 165 if (!deferred_access_no_check) 166 deferred_access_stack->last().deferred_access_checks = checks; 167 } 168 169 /* Resume deferring access checks again after we stopped doing 170 this previously. */ 171 172 void 173 resume_deferring_access_checks (void) 174 { 175 if (!deferred_access_no_check) 176 deferred_access_stack->last().deferring_access_checks_kind = dk_deferred; 177 } 178 179 /* Stop deferring access checks. */ 180 181 void 182 stop_deferring_access_checks (void) 183 { 184 if (!deferred_access_no_check) 185 deferred_access_stack->last().deferring_access_checks_kind = dk_no_deferred; 186 } 187 188 /* Discard the current deferred access checks and restore the 189 previous states. */ 190 191 void 192 pop_deferring_access_checks (void) 193 { 194 if (deferred_access_no_check) 195 deferred_access_no_check--; 196 else 197 deferred_access_stack->pop (); 198 } 199 200 /* Returns a TREE_LIST representing the deferred checks. 201 The TREE_PURPOSE of each node is the type through which the 202 access occurred; the TREE_VALUE is the declaration named. 203 */ 204 205 vec<deferred_access_check, va_gc> * 206 get_deferred_access_checks (void) 207 { 208 if (deferred_access_no_check) 209 return NULL; 210 else 211 return (deferred_access_stack->last().deferred_access_checks); 212 } 213 214 /* Take current deferred checks and combine with the 215 previous states if we also defer checks previously. 216 Otherwise perform checks now. */ 217 218 void 219 pop_to_parent_deferring_access_checks (void) 220 { 221 if (deferred_access_no_check) 222 deferred_access_no_check--; 223 else 224 { 225 vec<deferred_access_check, va_gc> *checks; 226 deferred_access *ptr; 227 228 checks = (deferred_access_stack->last ().deferred_access_checks); 229 230 deferred_access_stack->pop (); 231 ptr = &deferred_access_stack->last (); 232 if (ptr->deferring_access_checks_kind == dk_no_deferred) 233 { 234 /* Check access. */ 235 perform_access_checks (checks, tf_warning_or_error); 236 } 237 else 238 { 239 /* Merge with parent. */ 240 int i, j; 241 deferred_access_check *chk, *probe; 242 243 FOR_EACH_VEC_SAFE_ELT (checks, i, chk) 244 { 245 FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, j, probe) 246 { 247 if (probe->binfo == chk->binfo && 248 probe->decl == chk->decl && 249 probe->diag_decl == chk->diag_decl) 250 goto found; 251 } 252 /* Insert into parent's checks. */ 253 vec_safe_push (ptr->deferred_access_checks, *chk); 254 found:; 255 } 256 } 257 } 258 } 259 260 /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node 261 is the BINFO indicating the qualifying scope used to access the 262 DECL node stored in the TREE_VALUE of the node. If CHECKS is empty 263 or we aren't in SFINAE context or all the checks succeed return TRUE, 264 otherwise FALSE. */ 265 266 bool 267 perform_access_checks (vec<deferred_access_check, va_gc> *checks, 268 tsubst_flags_t complain) 269 { 270 int i; 271 deferred_access_check *chk; 272 location_t loc = input_location; 273 bool ok = true; 274 275 if (!checks) 276 return true; 277 278 FOR_EACH_VEC_SAFE_ELT (checks, i, chk) 279 { 280 input_location = chk->loc; 281 ok &= enforce_access (chk->binfo, chk->decl, chk->diag_decl, complain); 282 } 283 284 input_location = loc; 285 return (complain & tf_error) ? true : ok; 286 } 287 288 /* Perform the deferred access checks. 289 290 After performing the checks, we still have to keep the list 291 `deferred_access_stack->deferred_access_checks' since we may want 292 to check access for them again later in a different context. 293 For example: 294 295 class A { 296 typedef int X; 297 static X a; 298 }; 299 A::X A::a, x; // No error for `A::a', error for `x' 300 301 We have to perform deferred access of `A::X', first with `A::a', 302 next with `x'. Return value like perform_access_checks above. */ 303 304 bool 305 perform_deferred_access_checks (tsubst_flags_t complain) 306 { 307 return perform_access_checks (get_deferred_access_checks (), complain); 308 } 309 310 /* Defer checking the accessibility of DECL, when looked up in 311 BINFO. DIAG_DECL is the declaration to use to print diagnostics. 312 Return value like perform_access_checks above. 313 If non-NULL, report failures to AFI. */ 314 315 bool 316 perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl, 317 tsubst_flags_t complain, 318 access_failure_info *afi) 319 { 320 int i; 321 deferred_access *ptr; 322 deferred_access_check *chk; 323 324 325 /* Exit if we are in a context that no access checking is performed. 326 */ 327 if (deferred_access_no_check) 328 return true; 329 330 gcc_assert (TREE_CODE (binfo) == TREE_BINFO); 331 332 ptr = &deferred_access_stack->last (); 333 334 /* If we are not supposed to defer access checks, just check now. */ 335 if (ptr->deferring_access_checks_kind == dk_no_deferred) 336 { 337 bool ok = enforce_access (binfo, decl, diag_decl, complain, afi); 338 return (complain & tf_error) ? true : ok; 339 } 340 341 /* See if we are already going to perform this check. */ 342 FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, i, chk) 343 { 344 if (chk->decl == decl && chk->binfo == binfo && 345 chk->diag_decl == diag_decl) 346 { 347 return true; 348 } 349 } 350 /* If not, record the check. */ 351 deferred_access_check new_access = {binfo, decl, diag_decl, input_location}; 352 vec_safe_push (ptr->deferred_access_checks, new_access); 353 354 return true; 355 } 356 357 /* Returns nonzero if the current statement is a full expression, 358 i.e. temporaries created during that statement should be destroyed 359 at the end of the statement. */ 360 361 int 362 stmts_are_full_exprs_p (void) 363 { 364 return current_stmt_tree ()->stmts_are_full_exprs_p; 365 } 366 367 /* T is a statement. Add it to the statement-tree. This is the C++ 368 version. The C/ObjC frontends have a slightly different version of 369 this function. */ 370 371 tree 372 add_stmt (tree t) 373 { 374 enum tree_code code = TREE_CODE (t); 375 376 if (EXPR_P (t) && code != LABEL_EXPR) 377 { 378 if (!EXPR_HAS_LOCATION (t)) 379 SET_EXPR_LOCATION (t, input_location); 380 381 /* When we expand a statement-tree, we must know whether or not the 382 statements are full-expressions. We record that fact here. */ 383 STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p (); 384 } 385 386 if (code == LABEL_EXPR || code == CASE_LABEL_EXPR) 387 STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1; 388 389 /* Add T to the statement-tree. Non-side-effect statements need to be 390 recorded during statement expressions. */ 391 gcc_checking_assert (!stmt_list_stack->is_empty ()); 392 append_to_statement_list_force (t, &cur_stmt_list); 393 394 return t; 395 } 396 397 /* Returns the stmt_tree to which statements are currently being added. */ 398 399 stmt_tree 400 current_stmt_tree (void) 401 { 402 return (cfun 403 ? &cfun->language->base.x_stmt_tree 404 : &scope_chain->x_stmt_tree); 405 } 406 407 /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */ 408 409 static tree 410 maybe_cleanup_point_expr (tree expr) 411 { 412 if (!processing_template_decl && stmts_are_full_exprs_p ()) 413 expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr); 414 return expr; 415 } 416 417 /* Like maybe_cleanup_point_expr except have the type of the new expression be 418 void so we don't need to create a temporary variable to hold the inner 419 expression. The reason why we do this is because the original type might be 420 an aggregate and we cannot create a temporary variable for that type. */ 421 422 tree 423 maybe_cleanup_point_expr_void (tree expr) 424 { 425 if (!processing_template_decl && stmts_are_full_exprs_p ()) 426 expr = fold_build_cleanup_point_expr (void_type_node, expr); 427 return expr; 428 } 429 430 431 432 /* Create a declaration statement for the declaration given by the DECL. */ 433 434 void 435 add_decl_expr (tree decl) 436 { 437 tree r = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl); 438 if (DECL_INITIAL (decl) 439 || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl)))) 440 r = maybe_cleanup_point_expr_void (r); 441 add_stmt (r); 442 } 443 444 /* Finish a scope. */ 445 446 tree 447 do_poplevel (tree stmt_list) 448 { 449 tree block = NULL; 450 451 if (stmts_are_full_exprs_p ()) 452 block = poplevel (kept_level_p (), 1, 0); 453 454 stmt_list = pop_stmt_list (stmt_list); 455 456 if (!processing_template_decl) 457 { 458 stmt_list = c_build_bind_expr (input_location, block, stmt_list); 459 /* ??? See c_end_compound_stmt re statement expressions. */ 460 } 461 462 return stmt_list; 463 } 464 465 /* Begin a new scope. */ 466 467 static tree 468 do_pushlevel (scope_kind sk) 469 { 470 tree ret = push_stmt_list (); 471 if (stmts_are_full_exprs_p ()) 472 begin_scope (sk, NULL); 473 return ret; 474 } 475 476 /* Queue a cleanup. CLEANUP is an expression/statement to be executed 477 when the current scope is exited. EH_ONLY is true when this is not 478 meant to apply to normal control flow transfer. */ 479 480 void 481 push_cleanup (tree decl, tree cleanup, bool eh_only) 482 { 483 tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl); 484 CLEANUP_EH_ONLY (stmt) = eh_only; 485 add_stmt (stmt); 486 CLEANUP_BODY (stmt) = push_stmt_list (); 487 } 488 489 /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all 490 the current loops, represented by 'NULL_TREE' if we've seen a possible 491 exit, and 'error_mark_node' if not. This is currently used only to 492 suppress the warning about a function with no return statements, and 493 therefore we don't bother noting returns as possible exits. We also 494 don't bother with gotos. */ 495 496 static void 497 begin_maybe_infinite_loop (tree cond) 498 { 499 /* Only track this while parsing a function, not during instantiation. */ 500 if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl) 501 && !processing_template_decl)) 502 return; 503 bool maybe_infinite = true; 504 if (cond) 505 { 506 cond = fold_non_dependent_expr (cond); 507 maybe_infinite = integer_nonzerop (cond); 508 } 509 vec_safe_push (cp_function_chain->infinite_loops, 510 maybe_infinite ? error_mark_node : NULL_TREE); 511 512 } 513 514 /* A break is a possible exit for the current loop. */ 515 516 void 517 break_maybe_infinite_loop (void) 518 { 519 if (!cfun) 520 return; 521 cp_function_chain->infinite_loops->last() = NULL_TREE; 522 } 523 524 /* If we reach the end of the loop without seeing a possible exit, we have 525 an infinite loop. */ 526 527 static void 528 end_maybe_infinite_loop (tree cond) 529 { 530 if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl) 531 && !processing_template_decl)) 532 return; 533 tree current = cp_function_chain->infinite_loops->pop(); 534 if (current != NULL_TREE) 535 { 536 cond = fold_non_dependent_expr (cond); 537 if (integer_nonzerop (cond)) 538 current_function_infinite_loop = 1; 539 } 540 } 541 542 543 /* Begin a conditional that might contain a declaration. When generating 544 normal code, we want the declaration to appear before the statement 545 containing the conditional. When generating template code, we want the 546 conditional to be rendered as the raw DECL_EXPR. */ 547 548 static void 549 begin_cond (tree *cond_p) 550 { 551 if (processing_template_decl) 552 *cond_p = push_stmt_list (); 553 } 554 555 /* Finish such a conditional. */ 556 557 static void 558 finish_cond (tree *cond_p, tree expr) 559 { 560 if (processing_template_decl) 561 { 562 tree cond = pop_stmt_list (*cond_p); 563 564 if (expr == NULL_TREE) 565 /* Empty condition in 'for'. */ 566 gcc_assert (empty_expr_stmt_p (cond)); 567 else if (check_for_bare_parameter_packs (expr)) 568 expr = error_mark_node; 569 else if (!empty_expr_stmt_p (cond)) 570 expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr); 571 } 572 *cond_p = expr; 573 } 574 575 /* If *COND_P specifies a conditional with a declaration, transform the 576 loop such that 577 while (A x = 42) { } 578 for (; A x = 42;) { } 579 becomes 580 while (true) { A x = 42; if (!x) break; } 581 for (;;) { A x = 42; if (!x) break; } 582 The statement list for BODY will be empty if the conditional did 583 not declare anything. */ 584 585 static void 586 simplify_loop_decl_cond (tree *cond_p, tree body) 587 { 588 tree cond, if_stmt; 589 590 if (!TREE_SIDE_EFFECTS (body)) 591 return; 592 593 cond = *cond_p; 594 *cond_p = boolean_true_node; 595 596 if_stmt = begin_if_stmt (); 597 cond = cp_build_unary_op (TRUTH_NOT_EXPR, cond, false, tf_warning_or_error); 598 finish_if_stmt_cond (cond, if_stmt); 599 finish_break_stmt (); 600 finish_then_clause (if_stmt); 601 finish_if_stmt (if_stmt); 602 } 603 604 /* Finish a goto-statement. */ 605 606 tree 607 finish_goto_stmt (tree destination) 608 { 609 if (identifier_p (destination)) 610 destination = lookup_label (destination); 611 612 /* We warn about unused labels with -Wunused. That means we have to 613 mark the used labels as used. */ 614 if (TREE_CODE (destination) == LABEL_DECL) 615 TREE_USED (destination) = 1; 616 else 617 { 618 destination = mark_rvalue_use (destination); 619 if (!processing_template_decl) 620 { 621 destination = cp_convert (ptr_type_node, destination, 622 tf_warning_or_error); 623 if (error_operand_p (destination)) 624 return NULL_TREE; 625 destination 626 = fold_build_cleanup_point_expr (TREE_TYPE (destination), 627 destination); 628 } 629 } 630 631 check_goto (destination); 632 633 add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN)); 634 return add_stmt (build_stmt (input_location, GOTO_EXPR, destination)); 635 } 636 637 /* COND is the condition-expression for an if, while, etc., 638 statement. Convert it to a boolean value, if appropriate. 639 In addition, verify sequence points if -Wsequence-point is enabled. */ 640 641 static tree 642 maybe_convert_cond (tree cond) 643 { 644 /* Empty conditions remain empty. */ 645 if (!cond) 646 return NULL_TREE; 647 648 /* Wait until we instantiate templates before doing conversion. */ 649 if (type_dependent_expression_p (cond)) 650 return cond; 651 652 if (warn_sequence_point && !processing_template_decl) 653 verify_sequence_points (cond); 654 655 /* Do the conversion. */ 656 cond = convert_from_reference (cond); 657 658 if (TREE_CODE (cond) == MODIFY_EXPR 659 && !TREE_NO_WARNING (cond) 660 && warn_parentheses 661 && warning_at (cp_expr_loc_or_loc (cond, input_location), 662 OPT_Wparentheses, "suggest parentheses around " 663 "assignment used as truth value")) 664 TREE_NO_WARNING (cond) = 1; 665 666 return condition_conversion (cond); 667 } 668 669 /* Finish an expression-statement, whose EXPRESSION is as indicated. */ 670 671 tree 672 finish_expr_stmt (tree expr) 673 { 674 tree r = NULL_TREE; 675 location_t loc = EXPR_LOCATION (expr); 676 677 if (expr != NULL_TREE) 678 { 679 /* If we ran into a problem, make sure we complained. */ 680 gcc_assert (expr != error_mark_node || seen_error ()); 681 682 if (!processing_template_decl) 683 { 684 if (warn_sequence_point) 685 verify_sequence_points (expr); 686 expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error); 687 } 688 else if (!type_dependent_expression_p (expr)) 689 convert_to_void (build_non_dependent_expr (expr), ICV_STATEMENT, 690 tf_warning_or_error); 691 692 if (check_for_bare_parameter_packs (expr)) 693 expr = error_mark_node; 694 695 /* Simplification of inner statement expressions, compound exprs, 696 etc can result in us already having an EXPR_STMT. */ 697 if (TREE_CODE (expr) != CLEANUP_POINT_EXPR) 698 { 699 if (TREE_CODE (expr) != EXPR_STMT) 700 expr = build_stmt (loc, EXPR_STMT, expr); 701 expr = maybe_cleanup_point_expr_void (expr); 702 } 703 704 r = add_stmt (expr); 705 } 706 707 return r; 708 } 709 710 711 /* Begin an if-statement. Returns a newly created IF_STMT if 712 appropriate. */ 713 714 tree 715 begin_if_stmt (void) 716 { 717 tree r, scope; 718 scope = do_pushlevel (sk_cond); 719 r = build_stmt (input_location, IF_STMT, NULL_TREE, 720 NULL_TREE, NULL_TREE, scope); 721 current_binding_level->this_entity = r; 722 begin_cond (&IF_COND (r)); 723 return r; 724 } 725 726 /* Process the COND of an if-statement, which may be given by 727 IF_STMT. */ 728 729 tree 730 finish_if_stmt_cond (tree cond, tree if_stmt) 731 { 732 cond = maybe_convert_cond (cond); 733 if (IF_STMT_CONSTEXPR_P (if_stmt) 734 && !type_dependent_expression_p (cond) 735 && require_constant_expression (cond) 736 && !instantiation_dependent_expression_p (cond) 737 /* Wait until instantiation time, since only then COND has been 738 converted to bool. */ 739 && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node) 740 { 741 cond = instantiate_non_dependent_expr (cond); 742 cond = cxx_constant_value (cond, NULL_TREE); 743 } 744 finish_cond (&IF_COND (if_stmt), cond); 745 add_stmt (if_stmt); 746 THEN_CLAUSE (if_stmt) = push_stmt_list (); 747 return cond; 748 } 749 750 /* Finish the then-clause of an if-statement, which may be given by 751 IF_STMT. */ 752 753 tree 754 finish_then_clause (tree if_stmt) 755 { 756 THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt)); 757 return if_stmt; 758 } 759 760 /* Begin the else-clause of an if-statement. */ 761 762 void 763 begin_else_clause (tree if_stmt) 764 { 765 ELSE_CLAUSE (if_stmt) = push_stmt_list (); 766 } 767 768 /* Finish the else-clause of an if-statement, which may be given by 769 IF_STMT. */ 770 771 void 772 finish_else_clause (tree if_stmt) 773 { 774 ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt)); 775 } 776 777 /* Finish an if-statement. */ 778 779 void 780 finish_if_stmt (tree if_stmt) 781 { 782 tree scope = IF_SCOPE (if_stmt); 783 IF_SCOPE (if_stmt) = NULL; 784 add_stmt (do_poplevel (scope)); 785 } 786 787 /* Begin a while-statement. Returns a newly created WHILE_STMT if 788 appropriate. */ 789 790 tree 791 begin_while_stmt (void) 792 { 793 tree r; 794 r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE); 795 add_stmt (r); 796 WHILE_BODY (r) = do_pushlevel (sk_block); 797 begin_cond (&WHILE_COND (r)); 798 return r; 799 } 800 801 /* Process the COND of a while-statement, which may be given by 802 WHILE_STMT. */ 803 804 void 805 finish_while_stmt_cond (tree cond, tree while_stmt, bool ivdep, 806 unsigned short unroll) 807 { 808 cond = maybe_convert_cond (cond); 809 finish_cond (&WHILE_COND (while_stmt), cond); 810 begin_maybe_infinite_loop (cond); 811 if (ivdep && cond != error_mark_node) 812 WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR, 813 TREE_TYPE (WHILE_COND (while_stmt)), 814 WHILE_COND (while_stmt), 815 build_int_cst (integer_type_node, 816 annot_expr_ivdep_kind), 817 integer_zero_node); 818 if (unroll && cond != error_mark_node) 819 WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR, 820 TREE_TYPE (WHILE_COND (while_stmt)), 821 WHILE_COND (while_stmt), 822 build_int_cst (integer_type_node, 823 annot_expr_unroll_kind), 824 build_int_cst (integer_type_node, 825 unroll)); 826 simplify_loop_decl_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt)); 827 } 828 829 /* Finish a while-statement, which may be given by WHILE_STMT. */ 830 831 void 832 finish_while_stmt (tree while_stmt) 833 { 834 end_maybe_infinite_loop (boolean_true_node); 835 WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt)); 836 } 837 838 /* Begin a do-statement. Returns a newly created DO_STMT if 839 appropriate. */ 840 841 tree 842 begin_do_stmt (void) 843 { 844 tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE); 845 begin_maybe_infinite_loop (boolean_true_node); 846 add_stmt (r); 847 DO_BODY (r) = push_stmt_list (); 848 return r; 849 } 850 851 /* Finish the body of a do-statement, which may be given by DO_STMT. */ 852 853 void 854 finish_do_body (tree do_stmt) 855 { 856 tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt)); 857 858 if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body)) 859 body = STATEMENT_LIST_TAIL (body)->stmt; 860 861 if (IS_EMPTY_STMT (body)) 862 warning (OPT_Wempty_body, 863 "suggest explicit braces around empty body in %<do%> statement"); 864 } 865 866 /* Finish a do-statement, which may be given by DO_STMT, and whose 867 COND is as indicated. */ 868 869 void 870 finish_do_stmt (tree cond, tree do_stmt, bool ivdep, unsigned short unroll) 871 { 872 cond = maybe_convert_cond (cond); 873 end_maybe_infinite_loop (cond); 874 if (ivdep && cond != error_mark_node) 875 cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, 876 build_int_cst (integer_type_node, annot_expr_ivdep_kind), 877 integer_zero_node); 878 if (unroll && cond != error_mark_node) 879 cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, 880 build_int_cst (integer_type_node, annot_expr_unroll_kind), 881 build_int_cst (integer_type_node, unroll)); 882 DO_COND (do_stmt) = cond; 883 } 884 885 /* Finish a return-statement. The EXPRESSION returned, if any, is as 886 indicated. */ 887 888 tree 889 finish_return_stmt (tree expr) 890 { 891 tree r; 892 bool no_warning; 893 894 expr = check_return_expr (expr, &no_warning); 895 896 if (error_operand_p (expr) 897 || (flag_openmp && !check_omp_return ())) 898 { 899 /* Suppress -Wreturn-type for this function. */ 900 if (warn_return_type) 901 TREE_NO_WARNING (current_function_decl) = true; 902 return error_mark_node; 903 } 904 905 if (!processing_template_decl) 906 { 907 if (warn_sequence_point) 908 verify_sequence_points (expr); 909 910 if (DECL_DESTRUCTOR_P (current_function_decl) 911 || (DECL_CONSTRUCTOR_P (current_function_decl) 912 && targetm.cxx.cdtor_returns_this ())) 913 { 914 /* Similarly, all destructors must run destructors for 915 base-classes before returning. So, all returns in a 916 destructor get sent to the DTOR_LABEL; finish_function emits 917 code to return a value there. */ 918 return finish_goto_stmt (cdtor_label); 919 } 920 } 921 922 r = build_stmt (input_location, RETURN_EXPR, expr); 923 TREE_NO_WARNING (r) |= no_warning; 924 r = maybe_cleanup_point_expr_void (r); 925 r = add_stmt (r); 926 927 return r; 928 } 929 930 /* Begin the scope of a for-statement or a range-for-statement. 931 Both the returned trees are to be used in a call to 932 begin_for_stmt or begin_range_for_stmt. */ 933 934 tree 935 begin_for_scope (tree *init) 936 { 937 tree scope = do_pushlevel (sk_for); 938 939 if (processing_template_decl) 940 *init = push_stmt_list (); 941 else 942 *init = NULL_TREE; 943 944 return scope; 945 } 946 947 /* Begin a for-statement. Returns a new FOR_STMT. 948 SCOPE and INIT should be the return of begin_for_scope, 949 or both NULL_TREE */ 950 951 tree 952 begin_for_stmt (tree scope, tree init) 953 { 954 tree r; 955 956 r = build_stmt (input_location, FOR_STMT, NULL_TREE, NULL_TREE, 957 NULL_TREE, NULL_TREE, NULL_TREE); 958 959 if (scope == NULL_TREE) 960 { 961 gcc_assert (!init); 962 scope = begin_for_scope (&init); 963 } 964 965 FOR_INIT_STMT (r) = init; 966 FOR_SCOPE (r) = scope; 967 968 return r; 969 } 970 971 /* Finish the init-statement of a for-statement, which may be 972 given by FOR_STMT. */ 973 974 void 975 finish_init_stmt (tree for_stmt) 976 { 977 if (processing_template_decl) 978 FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt)); 979 add_stmt (for_stmt); 980 FOR_BODY (for_stmt) = do_pushlevel (sk_block); 981 begin_cond (&FOR_COND (for_stmt)); 982 } 983 984 /* Finish the COND of a for-statement, which may be given by 985 FOR_STMT. */ 986 987 void 988 finish_for_cond (tree cond, tree for_stmt, bool ivdep, unsigned short unroll) 989 { 990 cond = maybe_convert_cond (cond); 991 finish_cond (&FOR_COND (for_stmt), cond); 992 begin_maybe_infinite_loop (cond); 993 if (ivdep && cond != error_mark_node) 994 FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR, 995 TREE_TYPE (FOR_COND (for_stmt)), 996 FOR_COND (for_stmt), 997 build_int_cst (integer_type_node, 998 annot_expr_ivdep_kind), 999 integer_zero_node); 1000 if (unroll && cond != error_mark_node) 1001 FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR, 1002 TREE_TYPE (FOR_COND (for_stmt)), 1003 FOR_COND (for_stmt), 1004 build_int_cst (integer_type_node, 1005 annot_expr_unroll_kind), 1006 build_int_cst (integer_type_node, 1007 unroll)); 1008 simplify_loop_decl_cond (&FOR_COND (for_stmt), FOR_BODY (for_stmt)); 1009 } 1010 1011 /* Finish the increment-EXPRESSION in a for-statement, which may be 1012 given by FOR_STMT. */ 1013 1014 void 1015 finish_for_expr (tree expr, tree for_stmt) 1016 { 1017 if (!expr) 1018 return; 1019 /* If EXPR is an overloaded function, issue an error; there is no 1020 context available to use to perform overload resolution. */ 1021 if (type_unknown_p (expr)) 1022 { 1023 cxx_incomplete_type_error (expr, TREE_TYPE (expr)); 1024 expr = error_mark_node; 1025 } 1026 if (!processing_template_decl) 1027 { 1028 if (warn_sequence_point) 1029 verify_sequence_points (expr); 1030 expr = convert_to_void (expr, ICV_THIRD_IN_FOR, 1031 tf_warning_or_error); 1032 } 1033 else if (!type_dependent_expression_p (expr)) 1034 convert_to_void (build_non_dependent_expr (expr), ICV_THIRD_IN_FOR, 1035 tf_warning_or_error); 1036 expr = maybe_cleanup_point_expr_void (expr); 1037 if (check_for_bare_parameter_packs (expr)) 1038 expr = error_mark_node; 1039 FOR_EXPR (for_stmt) = expr; 1040 } 1041 1042 /* Finish the body of a for-statement, which may be given by 1043 FOR_STMT. The increment-EXPR for the loop must be 1044 provided. 1045 It can also finish RANGE_FOR_STMT. */ 1046 1047 void 1048 finish_for_stmt (tree for_stmt) 1049 { 1050 end_maybe_infinite_loop (boolean_true_node); 1051 1052 if (TREE_CODE (for_stmt) == RANGE_FOR_STMT) 1053 RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt)); 1054 else 1055 FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt)); 1056 1057 /* Pop the scope for the body of the loop. */ 1058 tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT 1059 ? &RANGE_FOR_SCOPE (for_stmt) 1060 : &FOR_SCOPE (for_stmt)); 1061 tree scope = *scope_ptr; 1062 *scope_ptr = NULL; 1063 1064 /* During parsing of the body, range for uses "__for_{range,begin,end} " 1065 decl names to make those unaccessible by code in the body. 1066 Change it to ones with underscore instead of space, so that it can 1067 be inspected in the debugger. */ 1068 tree range_for_decl[3] = { NULL_TREE, NULL_TREE, NULL_TREE }; 1069 gcc_assert (CPTI_FOR_BEGIN__IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 1 1070 && CPTI_FOR_END__IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 2 1071 && CPTI_FOR_RANGE_IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 3 1072 && CPTI_FOR_BEGIN_IDENTIFIER == CPTI_FOR_BEGIN__IDENTIFIER + 3 1073 && CPTI_FOR_END_IDENTIFIER == CPTI_FOR_END__IDENTIFIER + 3); 1074 for (int i = 0; i < 3; i++) 1075 { 1076 tree id = cp_global_trees[CPTI_FOR_RANGE__IDENTIFIER + i]; 1077 if (IDENTIFIER_BINDING (id) 1078 && IDENTIFIER_BINDING (id)->scope == current_binding_level) 1079 { 1080 range_for_decl[i] = IDENTIFIER_BINDING (id)->value; 1081 gcc_assert (VAR_P (range_for_decl[i]) 1082 && DECL_ARTIFICIAL (range_for_decl[i])); 1083 } 1084 } 1085 1086 add_stmt (do_poplevel (scope)); 1087 1088 for (int i = 0; i < 3; i++) 1089 if (range_for_decl[i]) 1090 DECL_NAME (range_for_decl[i]) 1091 = cp_global_trees[CPTI_FOR_RANGE_IDENTIFIER + i]; 1092 } 1093 1094 /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT. 1095 SCOPE and INIT should be the return of begin_for_scope, 1096 or both NULL_TREE . 1097 To finish it call finish_for_stmt(). */ 1098 1099 tree 1100 begin_range_for_stmt (tree scope, tree init) 1101 { 1102 begin_maybe_infinite_loop (boolean_false_node); 1103 1104 tree r = build_stmt (input_location, RANGE_FOR_STMT, NULL_TREE, NULL_TREE, 1105 NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE); 1106 1107 if (scope == NULL_TREE) 1108 { 1109 gcc_assert (!init); 1110 scope = begin_for_scope (&init); 1111 } 1112 1113 /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it. */ 1114 RANGE_FOR_INIT_STMT (r) = init; 1115 RANGE_FOR_SCOPE (r) = scope; 1116 1117 return r; 1118 } 1119 1120 /* Finish the head of a range-based for statement, which may 1121 be given by RANGE_FOR_STMT. DECL must be the declaration 1122 and EXPR must be the loop expression. */ 1123 1124 void 1125 finish_range_for_decl (tree range_for_stmt, tree decl, tree expr) 1126 { 1127 if (processing_template_decl) 1128 RANGE_FOR_INIT_STMT (range_for_stmt) 1129 = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt)); 1130 RANGE_FOR_DECL (range_for_stmt) = decl; 1131 RANGE_FOR_EXPR (range_for_stmt) = expr; 1132 add_stmt (range_for_stmt); 1133 RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block); 1134 } 1135 1136 /* Finish a break-statement. */ 1137 1138 tree 1139 finish_break_stmt (void) 1140 { 1141 /* In switch statements break is sometimes stylistically used after 1142 a return statement. This can lead to spurious warnings about 1143 control reaching the end of a non-void function when it is 1144 inlined. Note that we are calling block_may_fallthru with 1145 language specific tree nodes; this works because 1146 block_may_fallthru returns true when given something it does not 1147 understand. */ 1148 if (!block_may_fallthru (cur_stmt_list)) 1149 return void_node; 1150 note_break_stmt (); 1151 return add_stmt (build_stmt (input_location, BREAK_STMT)); 1152 } 1153 1154 /* Finish a continue-statement. */ 1155 1156 tree 1157 finish_continue_stmt (void) 1158 { 1159 return add_stmt (build_stmt (input_location, CONTINUE_STMT)); 1160 } 1161 1162 /* Begin a switch-statement. Returns a new SWITCH_STMT if 1163 appropriate. */ 1164 1165 tree 1166 begin_switch_stmt (void) 1167 { 1168 tree r, scope; 1169 1170 scope = do_pushlevel (sk_cond); 1171 r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE, scope); 1172 1173 begin_cond (&SWITCH_STMT_COND (r)); 1174 1175 return r; 1176 } 1177 1178 /* Finish the cond of a switch-statement. */ 1179 1180 void 1181 finish_switch_cond (tree cond, tree switch_stmt) 1182 { 1183 tree orig_type = NULL; 1184 1185 if (!processing_template_decl) 1186 { 1187 /* Convert the condition to an integer or enumeration type. */ 1188 cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true); 1189 if (cond == NULL_TREE) 1190 { 1191 error ("switch quantity not an integer"); 1192 cond = error_mark_node; 1193 } 1194 /* We want unlowered type here to handle enum bit-fields. */ 1195 orig_type = unlowered_expr_type (cond); 1196 if (TREE_CODE (orig_type) != ENUMERAL_TYPE) 1197 orig_type = TREE_TYPE (cond); 1198 if (cond != error_mark_node) 1199 { 1200 /* [stmt.switch] 1201 1202 Integral promotions are performed. */ 1203 cond = perform_integral_promotions (cond); 1204 cond = maybe_cleanup_point_expr (cond); 1205 } 1206 } 1207 if (check_for_bare_parameter_packs (cond)) 1208 cond = error_mark_node; 1209 else if (!processing_template_decl && warn_sequence_point) 1210 verify_sequence_points (cond); 1211 1212 finish_cond (&SWITCH_STMT_COND (switch_stmt), cond); 1213 SWITCH_STMT_TYPE (switch_stmt) = orig_type; 1214 add_stmt (switch_stmt); 1215 push_switch (switch_stmt); 1216 SWITCH_STMT_BODY (switch_stmt) = push_stmt_list (); 1217 } 1218 1219 /* Finish the body of a switch-statement, which may be given by 1220 SWITCH_STMT. The COND to switch on is indicated. */ 1221 1222 void 1223 finish_switch_stmt (tree switch_stmt) 1224 { 1225 tree scope; 1226 1227 SWITCH_STMT_BODY (switch_stmt) = 1228 pop_stmt_list (SWITCH_STMT_BODY (switch_stmt)); 1229 pop_switch (); 1230 1231 scope = SWITCH_STMT_SCOPE (switch_stmt); 1232 SWITCH_STMT_SCOPE (switch_stmt) = NULL; 1233 add_stmt (do_poplevel (scope)); 1234 } 1235 1236 /* Begin a try-block. Returns a newly-created TRY_BLOCK if 1237 appropriate. */ 1238 1239 tree 1240 begin_try_block (void) 1241 { 1242 tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE); 1243 add_stmt (r); 1244 TRY_STMTS (r) = push_stmt_list (); 1245 return r; 1246 } 1247 1248 /* Likewise, for a function-try-block. The block returned in 1249 *COMPOUND_STMT is an artificial outer scope, containing the 1250 function-try-block. */ 1251 1252 tree 1253 begin_function_try_block (tree *compound_stmt) 1254 { 1255 tree r; 1256 /* This outer scope does not exist in the C++ standard, but we need 1257 a place to put __FUNCTION__ and similar variables. */ 1258 *compound_stmt = begin_compound_stmt (0); 1259 r = begin_try_block (); 1260 FN_TRY_BLOCK_P (r) = 1; 1261 return r; 1262 } 1263 1264 /* Finish a try-block, which may be given by TRY_BLOCK. */ 1265 1266 void 1267 finish_try_block (tree try_block) 1268 { 1269 TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block)); 1270 TRY_HANDLERS (try_block) = push_stmt_list (); 1271 } 1272 1273 /* Finish the body of a cleanup try-block, which may be given by 1274 TRY_BLOCK. */ 1275 1276 void 1277 finish_cleanup_try_block (tree try_block) 1278 { 1279 TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block)); 1280 } 1281 1282 /* Finish an implicitly generated try-block, with a cleanup is given 1283 by CLEANUP. */ 1284 1285 void 1286 finish_cleanup (tree cleanup, tree try_block) 1287 { 1288 TRY_HANDLERS (try_block) = cleanup; 1289 CLEANUP_P (try_block) = 1; 1290 } 1291 1292 /* Likewise, for a function-try-block. */ 1293 1294 void 1295 finish_function_try_block (tree try_block) 1296 { 1297 finish_try_block (try_block); 1298 /* FIXME : something queer about CTOR_INITIALIZER somehow following 1299 the try block, but moving it inside. */ 1300 in_function_try_handler = 1; 1301 } 1302 1303 /* Finish a handler-sequence for a try-block, which may be given by 1304 TRY_BLOCK. */ 1305 1306 void 1307 finish_handler_sequence (tree try_block) 1308 { 1309 TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block)); 1310 check_handlers (TRY_HANDLERS (try_block)); 1311 } 1312 1313 /* Finish the handler-seq for a function-try-block, given by 1314 TRY_BLOCK. COMPOUND_STMT is the outer block created by 1315 begin_function_try_block. */ 1316 1317 void 1318 finish_function_handler_sequence (tree try_block, tree compound_stmt) 1319 { 1320 in_function_try_handler = 0; 1321 finish_handler_sequence (try_block); 1322 finish_compound_stmt (compound_stmt); 1323 } 1324 1325 /* Begin a handler. Returns a HANDLER if appropriate. */ 1326 1327 tree 1328 begin_handler (void) 1329 { 1330 tree r; 1331 1332 r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE); 1333 add_stmt (r); 1334 1335 /* Create a binding level for the eh_info and the exception object 1336 cleanup. */ 1337 HANDLER_BODY (r) = do_pushlevel (sk_catch); 1338 1339 return r; 1340 } 1341 1342 /* Finish the handler-parameters for a handler, which may be given by 1343 HANDLER. DECL is the declaration for the catch parameter, or NULL 1344 if this is a `catch (...)' clause. */ 1345 1346 void 1347 finish_handler_parms (tree decl, tree handler) 1348 { 1349 tree type = NULL_TREE; 1350 if (processing_template_decl) 1351 { 1352 if (decl) 1353 { 1354 decl = pushdecl (decl); 1355 decl = push_template_decl (decl); 1356 HANDLER_PARMS (handler) = decl; 1357 type = TREE_TYPE (decl); 1358 } 1359 } 1360 else 1361 { 1362 type = expand_start_catch_block (decl); 1363 if (warn_catch_value 1364 && type != NULL_TREE 1365 && type != error_mark_node 1366 && !TYPE_REF_P (TREE_TYPE (decl))) 1367 { 1368 tree orig_type = TREE_TYPE (decl); 1369 if (CLASS_TYPE_P (orig_type)) 1370 { 1371 if (TYPE_POLYMORPHIC_P (orig_type)) 1372 warning (OPT_Wcatch_value_, 1373 "catching polymorphic type %q#T by value", orig_type); 1374 else if (warn_catch_value > 1) 1375 warning (OPT_Wcatch_value_, 1376 "catching type %q#T by value", orig_type); 1377 } 1378 else if (warn_catch_value > 2) 1379 warning (OPT_Wcatch_value_, 1380 "catching non-reference type %q#T", orig_type); 1381 } 1382 } 1383 HANDLER_TYPE (handler) = type; 1384 } 1385 1386 /* Finish a handler, which may be given by HANDLER. The BLOCKs are 1387 the return value from the matching call to finish_handler_parms. */ 1388 1389 void 1390 finish_handler (tree handler) 1391 { 1392 if (!processing_template_decl) 1393 expand_end_catch_block (); 1394 HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler)); 1395 } 1396 1397 /* Begin a compound statement. FLAGS contains some bits that control the 1398 behavior and context. If BCS_NO_SCOPE is set, the compound statement 1399 does not define a scope. If BCS_FN_BODY is set, this is the outermost 1400 block of a function. If BCS_TRY_BLOCK is set, this is the block 1401 created on behalf of a TRY statement. Returns a token to be passed to 1402 finish_compound_stmt. */ 1403 1404 tree 1405 begin_compound_stmt (unsigned int flags) 1406 { 1407 tree r; 1408 1409 if (flags & BCS_NO_SCOPE) 1410 { 1411 r = push_stmt_list (); 1412 STATEMENT_LIST_NO_SCOPE (r) = 1; 1413 1414 /* Normally, we try hard to keep the BLOCK for a statement-expression. 1415 But, if it's a statement-expression with a scopeless block, there's 1416 nothing to keep, and we don't want to accidentally keep a block 1417 *inside* the scopeless block. */ 1418 keep_next_level (false); 1419 } 1420 else 1421 { 1422 scope_kind sk = sk_block; 1423 if (flags & BCS_TRY_BLOCK) 1424 sk = sk_try; 1425 else if (flags & BCS_TRANSACTION) 1426 sk = sk_transaction; 1427 r = do_pushlevel (sk); 1428 } 1429 1430 /* When processing a template, we need to remember where the braces were, 1431 so that we can set up identical scopes when instantiating the template 1432 later. BIND_EXPR is a handy candidate for this. 1433 Note that do_poplevel won't create a BIND_EXPR itself here (and thus 1434 result in nested BIND_EXPRs), since we don't build BLOCK nodes when 1435 processing templates. */ 1436 if (processing_template_decl) 1437 { 1438 r = build3 (BIND_EXPR, NULL, NULL, r, NULL); 1439 BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0; 1440 BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0; 1441 TREE_SIDE_EFFECTS (r) = 1; 1442 } 1443 1444 return r; 1445 } 1446 1447 /* Finish a compound-statement, which is given by STMT. */ 1448 1449 void 1450 finish_compound_stmt (tree stmt) 1451 { 1452 if (TREE_CODE (stmt) == BIND_EXPR) 1453 { 1454 tree body = do_poplevel (BIND_EXPR_BODY (stmt)); 1455 /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special, 1456 discard the BIND_EXPR so it can be merged with the containing 1457 STATEMENT_LIST. */ 1458 if (TREE_CODE (body) == STATEMENT_LIST 1459 && STATEMENT_LIST_HEAD (body) == NULL 1460 && !BIND_EXPR_BODY_BLOCK (stmt) 1461 && !BIND_EXPR_TRY_BLOCK (stmt)) 1462 stmt = body; 1463 else 1464 BIND_EXPR_BODY (stmt) = body; 1465 } 1466 else if (STATEMENT_LIST_NO_SCOPE (stmt)) 1467 stmt = pop_stmt_list (stmt); 1468 else 1469 { 1470 /* Destroy any ObjC "super" receivers that may have been 1471 created. */ 1472 objc_clear_super_receiver (); 1473 1474 stmt = do_poplevel (stmt); 1475 } 1476 1477 /* ??? See c_end_compound_stmt wrt statement expressions. */ 1478 add_stmt (stmt); 1479 } 1480 1481 /* Finish an asm-statement, whose components are a STRING, some 1482 OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some 1483 LABELS. Also note whether the asm-statement should be 1484 considered volatile, and whether it is asm inline. */ 1485 1486 tree 1487 finish_asm_stmt (int volatile_p, tree string, tree output_operands, 1488 tree input_operands, tree clobbers, tree labels, bool inline_p) 1489 { 1490 tree r; 1491 tree t; 1492 int ninputs = list_length (input_operands); 1493 int noutputs = list_length (output_operands); 1494 1495 if (!processing_template_decl) 1496 { 1497 const char *constraint; 1498 const char **oconstraints; 1499 bool allows_mem, allows_reg, is_inout; 1500 tree operand; 1501 int i; 1502 1503 oconstraints = XALLOCAVEC (const char *, noutputs); 1504 1505 string = resolve_asm_operand_names (string, output_operands, 1506 input_operands, labels); 1507 1508 for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i) 1509 { 1510 operand = TREE_VALUE (t); 1511 1512 /* ??? Really, this should not be here. Users should be using a 1513 proper lvalue, dammit. But there's a long history of using 1514 casts in the output operands. In cases like longlong.h, this 1515 becomes a primitive form of typechecking -- if the cast can be 1516 removed, then the output operand had a type of the proper width; 1517 otherwise we'll get an error. Gross, but ... */ 1518 STRIP_NOPS (operand); 1519 1520 operand = mark_lvalue_use (operand); 1521 1522 if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error)) 1523 operand = error_mark_node; 1524 1525 if (operand != error_mark_node 1526 && (TREE_READONLY (operand) 1527 || CP_TYPE_CONST_P (TREE_TYPE (operand)) 1528 /* Functions are not modifiable, even though they are 1529 lvalues. */ 1530 || TREE_CODE (TREE_TYPE (operand)) == FUNCTION_TYPE 1531 || TREE_CODE (TREE_TYPE (operand)) == METHOD_TYPE 1532 /* If it's an aggregate and any field is const, then it is 1533 effectively const. */ 1534 || (CLASS_TYPE_P (TREE_TYPE (operand)) 1535 && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand))))) 1536 cxx_readonly_error (input_location, operand, lv_asm); 1537 1538 tree *op = &operand; 1539 while (TREE_CODE (*op) == COMPOUND_EXPR) 1540 op = &TREE_OPERAND (*op, 1); 1541 switch (TREE_CODE (*op)) 1542 { 1543 case PREINCREMENT_EXPR: 1544 case PREDECREMENT_EXPR: 1545 case MODIFY_EXPR: 1546 *op = genericize_compound_lvalue (*op); 1547 op = &TREE_OPERAND (*op, 1); 1548 break; 1549 default: 1550 break; 1551 } 1552 1553 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))); 1554 oconstraints[i] = constraint; 1555 1556 if (parse_output_constraint (&constraint, i, ninputs, noutputs, 1557 &allows_mem, &allows_reg, &is_inout)) 1558 { 1559 /* If the operand is going to end up in memory, 1560 mark it addressable. */ 1561 if (!allows_reg && !cxx_mark_addressable (*op)) 1562 operand = error_mark_node; 1563 } 1564 else 1565 operand = error_mark_node; 1566 1567 TREE_VALUE (t) = operand; 1568 } 1569 1570 for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t)) 1571 { 1572 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))); 1573 bool constraint_parsed 1574 = parse_input_constraint (&constraint, i, ninputs, noutputs, 0, 1575 oconstraints, &allows_mem, &allows_reg); 1576 /* If the operand is going to end up in memory, don't call 1577 decay_conversion. */ 1578 if (constraint_parsed && !allows_reg && allows_mem) 1579 operand = mark_lvalue_use (TREE_VALUE (t)); 1580 else 1581 operand = decay_conversion (TREE_VALUE (t), tf_warning_or_error); 1582 1583 /* If the type of the operand hasn't been determined (e.g., 1584 because it involves an overloaded function), then issue 1585 an error message. There's no context available to 1586 resolve the overloading. */ 1587 if (TREE_TYPE (operand) == unknown_type_node) 1588 { 1589 error ("type of asm operand %qE could not be determined", 1590 TREE_VALUE (t)); 1591 operand = error_mark_node; 1592 } 1593 1594 if (constraint_parsed) 1595 { 1596 /* If the operand is going to end up in memory, 1597 mark it addressable. */ 1598 if (!allows_reg && allows_mem) 1599 { 1600 /* Strip the nops as we allow this case. FIXME, this really 1601 should be rejected or made deprecated. */ 1602 STRIP_NOPS (operand); 1603 1604 tree *op = &operand; 1605 while (TREE_CODE (*op) == COMPOUND_EXPR) 1606 op = &TREE_OPERAND (*op, 1); 1607 switch (TREE_CODE (*op)) 1608 { 1609 case PREINCREMENT_EXPR: 1610 case PREDECREMENT_EXPR: 1611 case MODIFY_EXPR: 1612 *op = genericize_compound_lvalue (*op); 1613 op = &TREE_OPERAND (*op, 1); 1614 break; 1615 default: 1616 break; 1617 } 1618 1619 if (!cxx_mark_addressable (*op)) 1620 operand = error_mark_node; 1621 } 1622 else if (!allows_reg && !allows_mem) 1623 { 1624 /* If constraint allows neither register nor memory, 1625 try harder to get a constant. */ 1626 tree constop = maybe_constant_value (operand); 1627 if (TREE_CONSTANT (constop)) 1628 operand = constop; 1629 } 1630 } 1631 else 1632 operand = error_mark_node; 1633 1634 TREE_VALUE (t) = operand; 1635 } 1636 } 1637 1638 r = build_stmt (input_location, ASM_EXPR, string, 1639 output_operands, input_operands, 1640 clobbers, labels); 1641 ASM_VOLATILE_P (r) = volatile_p || noutputs == 0; 1642 ASM_INLINE_P (r) = inline_p; 1643 r = maybe_cleanup_point_expr_void (r); 1644 return add_stmt (r); 1645 } 1646 1647 /* Finish a label with the indicated NAME. Returns the new label. */ 1648 1649 tree 1650 finish_label_stmt (tree name) 1651 { 1652 tree decl = define_label (input_location, name); 1653 1654 if (decl == error_mark_node) 1655 return error_mark_node; 1656 1657 add_stmt (build_stmt (input_location, LABEL_EXPR, decl)); 1658 1659 return decl; 1660 } 1661 1662 /* Finish a series of declarations for local labels. G++ allows users 1663 to declare "local" labels, i.e., labels with scope. This extension 1664 is useful when writing code involving statement-expressions. */ 1665 1666 void 1667 finish_label_decl (tree name) 1668 { 1669 if (!at_function_scope_p ()) 1670 { 1671 error ("__label__ declarations are only allowed in function scopes"); 1672 return; 1673 } 1674 1675 add_decl_expr (declare_local_label (name)); 1676 } 1677 1678 /* When DECL goes out of scope, make sure that CLEANUP is executed. */ 1679 1680 void 1681 finish_decl_cleanup (tree decl, tree cleanup) 1682 { 1683 push_cleanup (decl, cleanup, false); 1684 } 1685 1686 /* If the current scope exits with an exception, run CLEANUP. */ 1687 1688 void 1689 finish_eh_cleanup (tree cleanup) 1690 { 1691 push_cleanup (NULL, cleanup, true); 1692 } 1693 1694 /* The MEM_INITS is a list of mem-initializers, in reverse of the 1695 order they were written by the user. Each node is as for 1696 emit_mem_initializers. */ 1697 1698 void 1699 finish_mem_initializers (tree mem_inits) 1700 { 1701 /* Reorder the MEM_INITS so that they are in the order they appeared 1702 in the source program. */ 1703 mem_inits = nreverse (mem_inits); 1704 1705 if (processing_template_decl) 1706 { 1707 tree mem; 1708 1709 for (mem = mem_inits; mem; mem = TREE_CHAIN (mem)) 1710 { 1711 /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the 1712 check for bare parameter packs in the TREE_VALUE, because 1713 any parameter packs in the TREE_VALUE have already been 1714 bound as part of the TREE_PURPOSE. See 1715 make_pack_expansion for more information. */ 1716 if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION 1717 && check_for_bare_parameter_packs (TREE_VALUE (mem))) 1718 TREE_VALUE (mem) = error_mark_node; 1719 } 1720 1721 add_stmt (build_min_nt_loc (UNKNOWN_LOCATION, 1722 CTOR_INITIALIZER, mem_inits)); 1723 } 1724 else 1725 emit_mem_initializers (mem_inits); 1726 } 1727 1728 /* Obfuscate EXPR if it looks like an id-expression or member access so 1729 that the call to finish_decltype in do_auto_deduction will give the 1730 right result. */ 1731 1732 tree 1733 force_paren_expr (tree expr) 1734 { 1735 /* This is only needed for decltype(auto) in C++14. */ 1736 if (cxx_dialect < cxx14) 1737 return expr; 1738 1739 /* If we're in unevaluated context, we can't be deducing a 1740 return/initializer type, so we don't need to mess with this. */ 1741 if (cp_unevaluated_operand) 1742 return expr; 1743 1744 if (!DECL_P (tree_strip_any_location_wrapper (expr)) 1745 && TREE_CODE (expr) != COMPONENT_REF 1746 && TREE_CODE (expr) != SCOPE_REF) 1747 return expr; 1748 1749 if (TREE_CODE (expr) == COMPONENT_REF 1750 || TREE_CODE (expr) == SCOPE_REF) 1751 REF_PARENTHESIZED_P (expr) = true; 1752 else if (processing_template_decl) 1753 expr = build1 (PAREN_EXPR, TREE_TYPE (expr), expr); 1754 else 1755 { 1756 expr = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (expr), expr); 1757 REF_PARENTHESIZED_P (expr) = true; 1758 } 1759 1760 return expr; 1761 } 1762 1763 /* If T is an id-expression obfuscated by force_paren_expr, undo the 1764 obfuscation and return the underlying id-expression. Otherwise 1765 return T. */ 1766 1767 tree 1768 maybe_undo_parenthesized_ref (tree t) 1769 { 1770 if (cxx_dialect < cxx14) 1771 return t; 1772 1773 if (INDIRECT_REF_P (t) && REF_PARENTHESIZED_P (t)) 1774 { 1775 t = TREE_OPERAND (t, 0); 1776 while (TREE_CODE (t) == NON_LVALUE_EXPR 1777 || TREE_CODE (t) == NOP_EXPR) 1778 t = TREE_OPERAND (t, 0); 1779 1780 gcc_assert (TREE_CODE (t) == ADDR_EXPR 1781 || TREE_CODE (t) == STATIC_CAST_EXPR); 1782 t = TREE_OPERAND (t, 0); 1783 } 1784 else if (TREE_CODE (t) == PAREN_EXPR) 1785 t = TREE_OPERAND (t, 0); 1786 else if (TREE_CODE (t) == VIEW_CONVERT_EXPR 1787 && REF_PARENTHESIZED_P (t)) 1788 t = TREE_OPERAND (t, 0); 1789 1790 return t; 1791 } 1792 1793 /* Finish a parenthesized expression EXPR. */ 1794 1795 cp_expr 1796 finish_parenthesized_expr (cp_expr expr) 1797 { 1798 if (EXPR_P (expr)) 1799 /* This inhibits warnings in c_common_truthvalue_conversion. */ 1800 TREE_NO_WARNING (expr) = 1; 1801 1802 if (TREE_CODE (expr) == OFFSET_REF 1803 || TREE_CODE (expr) == SCOPE_REF) 1804 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be 1805 enclosed in parentheses. */ 1806 PTRMEM_OK_P (expr) = 0; 1807 1808 tree stripped_expr = tree_strip_any_location_wrapper (expr); 1809 if (TREE_CODE (stripped_expr) == STRING_CST) 1810 PAREN_STRING_LITERAL_P (stripped_expr) = 1; 1811 1812 expr = cp_expr (force_paren_expr (expr), expr.get_location ()); 1813 1814 return expr; 1815 } 1816 1817 /* Finish a reference to a non-static data member (DECL) that is not 1818 preceded by `.' or `->'. */ 1819 1820 tree 1821 finish_non_static_data_member (tree decl, tree object, tree qualifying_scope) 1822 { 1823 gcc_assert (TREE_CODE (decl) == FIELD_DECL); 1824 bool try_omp_private = !object && omp_private_member_map; 1825 tree ret; 1826 1827 if (!object) 1828 { 1829 tree scope = qualifying_scope; 1830 if (scope == NULL_TREE) 1831 { 1832 scope = context_for_name_lookup (decl); 1833 if (!TYPE_P (scope)) 1834 { 1835 /* Can happen during error recovery (c++/85014). */ 1836 gcc_assert (seen_error ()); 1837 return error_mark_node; 1838 } 1839 } 1840 object = maybe_dummy_object (scope, NULL); 1841 } 1842 1843 object = maybe_resolve_dummy (object, true); 1844 if (object == error_mark_node) 1845 return error_mark_node; 1846 1847 /* DR 613/850: Can use non-static data members without an associated 1848 object in sizeof/decltype/alignof. */ 1849 if (is_dummy_object (object) && cp_unevaluated_operand == 0 1850 && (!processing_template_decl || !current_class_ref)) 1851 { 1852 if (current_function_decl 1853 && DECL_STATIC_FUNCTION_P (current_function_decl)) 1854 error ("invalid use of member %qD in static member function", decl); 1855 else 1856 error ("invalid use of non-static data member %qD", decl); 1857 inform (DECL_SOURCE_LOCATION (decl), "declared here"); 1858 1859 return error_mark_node; 1860 } 1861 1862 if (current_class_ptr) 1863 TREE_USED (current_class_ptr) = 1; 1864 if (processing_template_decl) 1865 { 1866 tree type = TREE_TYPE (decl); 1867 1868 if (TYPE_REF_P (type)) 1869 /* Quals on the object don't matter. */; 1870 else if (PACK_EXPANSION_P (type)) 1871 /* Don't bother trying to represent this. */ 1872 type = NULL_TREE; 1873 else 1874 { 1875 /* Set the cv qualifiers. */ 1876 int quals = cp_type_quals (TREE_TYPE (object)); 1877 1878 if (DECL_MUTABLE_P (decl)) 1879 quals &= ~TYPE_QUAL_CONST; 1880 1881 quals |= cp_type_quals (TREE_TYPE (decl)); 1882 type = cp_build_qualified_type (type, quals); 1883 } 1884 1885 if (qualifying_scope) 1886 /* Wrap this in a SCOPE_REF for now. */ 1887 ret = build_qualified_name (type, qualifying_scope, decl, 1888 /*template_p=*/false); 1889 else 1890 ret = (convert_from_reference 1891 (build_min (COMPONENT_REF, type, object, decl, NULL_TREE))); 1892 } 1893 /* If PROCESSING_TEMPLATE_DECL is nonzero here, then 1894 QUALIFYING_SCOPE is also non-null. */ 1895 else 1896 { 1897 tree access_type = TREE_TYPE (object); 1898 1899 perform_or_defer_access_check (TYPE_BINFO (access_type), decl, 1900 decl, tf_warning_or_error); 1901 1902 /* If the data member was named `C::M', convert `*this' to `C' 1903 first. */ 1904 if (qualifying_scope) 1905 { 1906 tree binfo = NULL_TREE; 1907 object = build_scoped_ref (object, qualifying_scope, 1908 &binfo); 1909 } 1910 1911 ret = build_class_member_access_expr (object, decl, 1912 /*access_path=*/NULL_TREE, 1913 /*preserve_reference=*/false, 1914 tf_warning_or_error); 1915 } 1916 if (try_omp_private) 1917 { 1918 tree *v = omp_private_member_map->get (decl); 1919 if (v) 1920 ret = convert_from_reference (*v); 1921 } 1922 return ret; 1923 } 1924 1925 /* If we are currently parsing a template and we encountered a typedef 1926 TYPEDEF_DECL that is being accessed though CONTEXT, this function 1927 adds the typedef to a list tied to the current template. 1928 At template instantiation time, that list is walked and access check 1929 performed for each typedef. 1930 LOCATION is the location of the usage point of TYPEDEF_DECL. */ 1931 1932 void 1933 add_typedef_to_current_template_for_access_check (tree typedef_decl, 1934 tree context, 1935 location_t location) 1936 { 1937 tree template_info = NULL; 1938 tree cs = current_scope (); 1939 1940 if (!is_typedef_decl (typedef_decl) 1941 || !context 1942 || !CLASS_TYPE_P (context) 1943 || !cs) 1944 return; 1945 1946 if (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL) 1947 template_info = get_template_info (cs); 1948 1949 if (template_info 1950 && TI_TEMPLATE (template_info) 1951 && !currently_open_class (context)) 1952 append_type_to_template_for_access_check (cs, typedef_decl, 1953 context, location); 1954 } 1955 1956 /* DECL was the declaration to which a qualified-id resolved. Issue 1957 an error message if it is not accessible. If OBJECT_TYPE is 1958 non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the 1959 type of `*x', or `x', respectively. If the DECL was named as 1960 `A::B' then NESTED_NAME_SPECIFIER is `A'. */ 1961 1962 void 1963 check_accessibility_of_qualified_id (tree decl, 1964 tree object_type, 1965 tree nested_name_specifier) 1966 { 1967 tree scope; 1968 tree qualifying_type = NULL_TREE; 1969 1970 /* If we are parsing a template declaration and if decl is a typedef, 1971 add it to a list tied to the template. 1972 At template instantiation time, that list will be walked and 1973 access check performed. */ 1974 add_typedef_to_current_template_for_access_check (decl, 1975 nested_name_specifier 1976 ? nested_name_specifier 1977 : DECL_CONTEXT (decl), 1978 input_location); 1979 1980 /* If we're not checking, return immediately. */ 1981 if (deferred_access_no_check) 1982 return; 1983 1984 /* Determine the SCOPE of DECL. */ 1985 scope = context_for_name_lookup (decl); 1986 /* If the SCOPE is not a type, then DECL is not a member. */ 1987 if (!TYPE_P (scope)) 1988 return; 1989 /* Compute the scope through which DECL is being accessed. */ 1990 if (object_type 1991 /* OBJECT_TYPE might not be a class type; consider: 1992 1993 class A { typedef int I; }; 1994 I *p; 1995 p->A::I::~I(); 1996 1997 In this case, we will have "A::I" as the DECL, but "I" as the 1998 OBJECT_TYPE. */ 1999 && CLASS_TYPE_P (object_type) 2000 && DERIVED_FROM_P (scope, object_type)) 2001 /* If we are processing a `->' or `.' expression, use the type of the 2002 left-hand side. */ 2003 qualifying_type = object_type; 2004 else if (nested_name_specifier) 2005 { 2006 /* If the reference is to a non-static member of the 2007 current class, treat it as if it were referenced through 2008 `this'. */ 2009 tree ct; 2010 if (DECL_NONSTATIC_MEMBER_P (decl) 2011 && current_class_ptr 2012 && DERIVED_FROM_P (scope, ct = current_nonlambda_class_type ())) 2013 qualifying_type = ct; 2014 /* Otherwise, use the type indicated by the 2015 nested-name-specifier. */ 2016 else 2017 qualifying_type = nested_name_specifier; 2018 } 2019 else 2020 /* Otherwise, the name must be from the current class or one of 2021 its bases. */ 2022 qualifying_type = currently_open_derived_class (scope); 2023 2024 if (qualifying_type 2025 /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM 2026 or similar in a default argument value. */ 2027 && CLASS_TYPE_P (qualifying_type) 2028 && !dependent_type_p (qualifying_type)) 2029 perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl, 2030 decl, tf_warning_or_error); 2031 } 2032 2033 /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the 2034 class named to the left of the "::" operator. DONE is true if this 2035 expression is a complete postfix-expression; it is false if this 2036 expression is followed by '->', '[', '(', etc. ADDRESS_P is true 2037 iff this expression is the operand of '&'. TEMPLATE_P is true iff 2038 the qualified-id was of the form "A::template B". TEMPLATE_ARG_P 2039 is true iff this qualified name appears as a template argument. */ 2040 2041 tree 2042 finish_qualified_id_expr (tree qualifying_class, 2043 tree expr, 2044 bool done, 2045 bool address_p, 2046 bool template_p, 2047 bool template_arg_p, 2048 tsubst_flags_t complain) 2049 { 2050 gcc_assert (TYPE_P (qualifying_class)); 2051 2052 if (error_operand_p (expr)) 2053 return error_mark_node; 2054 2055 if ((DECL_P (expr) || BASELINK_P (expr)) 2056 && !mark_used (expr, complain)) 2057 return error_mark_node; 2058 2059 if (template_p) 2060 { 2061 if (TREE_CODE (expr) == UNBOUND_CLASS_TEMPLATE) 2062 { 2063 /* cp_parser_lookup_name thought we were looking for a type, 2064 but we're actually looking for a declaration. */ 2065 qualifying_class = TYPE_CONTEXT (expr); 2066 expr = TYPE_IDENTIFIER (expr); 2067 } 2068 else 2069 check_template_keyword (expr); 2070 } 2071 2072 /* If EXPR occurs as the operand of '&', use special handling that 2073 permits a pointer-to-member. */ 2074 if (address_p && done) 2075 { 2076 if (TREE_CODE (expr) == SCOPE_REF) 2077 expr = TREE_OPERAND (expr, 1); 2078 expr = build_offset_ref (qualifying_class, expr, 2079 /*address_p=*/true, complain); 2080 return expr; 2081 } 2082 2083 /* No need to check access within an enum. */ 2084 if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE 2085 && TREE_CODE (expr) != IDENTIFIER_NODE) 2086 return expr; 2087 2088 /* Within the scope of a class, turn references to non-static 2089 members into expression of the form "this->...". */ 2090 if (template_arg_p) 2091 /* But, within a template argument, we do not want make the 2092 transformation, as there is no "this" pointer. */ 2093 ; 2094 else if (TREE_CODE (expr) == FIELD_DECL) 2095 { 2096 push_deferring_access_checks (dk_no_check); 2097 expr = finish_non_static_data_member (expr, NULL_TREE, 2098 qualifying_class); 2099 pop_deferring_access_checks (); 2100 } 2101 else if (BASELINK_P (expr)) 2102 { 2103 /* See if any of the functions are non-static members. */ 2104 /* If so, the expression may be relative to 'this'. */ 2105 if ((type_dependent_expression_p (expr) 2106 || !shared_member_p (expr)) 2107 && current_class_ptr 2108 && DERIVED_FROM_P (qualifying_class, 2109 current_nonlambda_class_type ())) 2110 expr = (build_class_member_access_expr 2111 (maybe_dummy_object (qualifying_class, NULL), 2112 expr, 2113 BASELINK_ACCESS_BINFO (expr), 2114 /*preserve_reference=*/false, 2115 complain)); 2116 else if (done) 2117 /* The expression is a qualified name whose address is not 2118 being taken. */ 2119 expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false, 2120 complain); 2121 } 2122 else if (!template_p 2123 && TREE_CODE (expr) == TEMPLATE_DECL 2124 && !DECL_FUNCTION_TEMPLATE_P (expr)) 2125 { 2126 if (complain & tf_error) 2127 error ("%qE missing template arguments", expr); 2128 return error_mark_node; 2129 } 2130 else 2131 { 2132 /* In a template, return a SCOPE_REF for most qualified-ids 2133 so that we can check access at instantiation time. But if 2134 we're looking at a member of the current instantiation, we 2135 know we have access and building up the SCOPE_REF confuses 2136 non-type template argument handling. */ 2137 if (processing_template_decl 2138 && (!currently_open_class (qualifying_class) 2139 || TREE_CODE (expr) == IDENTIFIER_NODE 2140 || TREE_CODE (expr) == TEMPLATE_ID_EXPR 2141 || TREE_CODE (expr) == BIT_NOT_EXPR)) 2142 expr = build_qualified_name (TREE_TYPE (expr), 2143 qualifying_class, expr, 2144 template_p); 2145 else if (tree wrap = maybe_get_tls_wrapper_call (expr)) 2146 expr = wrap; 2147 2148 expr = convert_from_reference (expr); 2149 } 2150 2151 return expr; 2152 } 2153 2154 /* Begin a statement-expression. The value returned must be passed to 2155 finish_stmt_expr. */ 2156 2157 tree 2158 begin_stmt_expr (void) 2159 { 2160 return push_stmt_list (); 2161 } 2162 2163 /* Process the final expression of a statement expression. EXPR can be 2164 NULL, if the final expression is empty. Return a STATEMENT_LIST 2165 containing all the statements in the statement-expression, or 2166 ERROR_MARK_NODE if there was an error. */ 2167 2168 tree 2169 finish_stmt_expr_expr (tree expr, tree stmt_expr) 2170 { 2171 if (error_operand_p (expr)) 2172 { 2173 /* The type of the statement-expression is the type of the last 2174 expression. */ 2175 TREE_TYPE (stmt_expr) = error_mark_node; 2176 return error_mark_node; 2177 } 2178 2179 /* If the last statement does not have "void" type, then the value 2180 of the last statement is the value of the entire expression. */ 2181 if (expr) 2182 { 2183 tree type = TREE_TYPE (expr); 2184 2185 if (type && type_unknown_p (type)) 2186 { 2187 error ("a statement expression is an insufficient context" 2188 " for overload resolution"); 2189 TREE_TYPE (stmt_expr) = error_mark_node; 2190 return error_mark_node; 2191 } 2192 else if (processing_template_decl) 2193 { 2194 expr = build_stmt (input_location, EXPR_STMT, expr); 2195 expr = add_stmt (expr); 2196 /* Mark the last statement so that we can recognize it as such at 2197 template-instantiation time. */ 2198 EXPR_STMT_STMT_EXPR_RESULT (expr) = 1; 2199 } 2200 else if (VOID_TYPE_P (type)) 2201 { 2202 /* Just treat this like an ordinary statement. */ 2203 expr = finish_expr_stmt (expr); 2204 } 2205 else 2206 { 2207 /* It actually has a value we need to deal with. First, force it 2208 to be an rvalue so that we won't need to build up a copy 2209 constructor call later when we try to assign it to something. */ 2210 expr = force_rvalue (expr, tf_warning_or_error); 2211 if (error_operand_p (expr)) 2212 return error_mark_node; 2213 2214 /* Update for array-to-pointer decay. */ 2215 type = TREE_TYPE (expr); 2216 2217 /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a 2218 normal statement, but don't convert to void or actually add 2219 the EXPR_STMT. */ 2220 if (TREE_CODE (expr) != CLEANUP_POINT_EXPR) 2221 expr = maybe_cleanup_point_expr (expr); 2222 add_stmt (expr); 2223 } 2224 2225 /* The type of the statement-expression is the type of the last 2226 expression. */ 2227 TREE_TYPE (stmt_expr) = type; 2228 } 2229 2230 return stmt_expr; 2231 } 2232 2233 /* Finish a statement-expression. EXPR should be the value returned 2234 by the previous begin_stmt_expr. Returns an expression 2235 representing the statement-expression. */ 2236 2237 tree 2238 finish_stmt_expr (tree stmt_expr, bool has_no_scope) 2239 { 2240 tree type; 2241 tree result; 2242 2243 if (error_operand_p (stmt_expr)) 2244 { 2245 pop_stmt_list (stmt_expr); 2246 return error_mark_node; 2247 } 2248 2249 gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST); 2250 2251 type = TREE_TYPE (stmt_expr); 2252 result = pop_stmt_list (stmt_expr); 2253 TREE_TYPE (result) = type; 2254 2255 if (processing_template_decl) 2256 { 2257 result = build_min (STMT_EXPR, type, result); 2258 TREE_SIDE_EFFECTS (result) = 1; 2259 STMT_EXPR_NO_SCOPE (result) = has_no_scope; 2260 } 2261 else if (CLASS_TYPE_P (type)) 2262 { 2263 /* Wrap the statement-expression in a TARGET_EXPR so that the 2264 temporary object created by the final expression is destroyed at 2265 the end of the full-expression containing the 2266 statement-expression. */ 2267 result = force_target_expr (type, result, tf_warning_or_error); 2268 } 2269 2270 return result; 2271 } 2272 2273 /* Returns the expression which provides the value of STMT_EXPR. */ 2274 2275 tree 2276 stmt_expr_value_expr (tree stmt_expr) 2277 { 2278 tree t = STMT_EXPR_STMT (stmt_expr); 2279 2280 if (TREE_CODE (t) == BIND_EXPR) 2281 t = BIND_EXPR_BODY (t); 2282 2283 if (TREE_CODE (t) == STATEMENT_LIST && STATEMENT_LIST_TAIL (t)) 2284 t = STATEMENT_LIST_TAIL (t)->stmt; 2285 2286 if (TREE_CODE (t) == EXPR_STMT) 2287 t = EXPR_STMT_EXPR (t); 2288 2289 return t; 2290 } 2291 2292 /* Return TRUE iff EXPR_STMT is an empty list of 2293 expression statements. */ 2294 2295 bool 2296 empty_expr_stmt_p (tree expr_stmt) 2297 { 2298 tree body = NULL_TREE; 2299 2300 if (expr_stmt == void_node) 2301 return true; 2302 2303 if (expr_stmt) 2304 { 2305 if (TREE_CODE (expr_stmt) == EXPR_STMT) 2306 body = EXPR_STMT_EXPR (expr_stmt); 2307 else if (TREE_CODE (expr_stmt) == STATEMENT_LIST) 2308 body = expr_stmt; 2309 } 2310 2311 if (body) 2312 { 2313 if (TREE_CODE (body) == STATEMENT_LIST) 2314 return tsi_end_p (tsi_start (body)); 2315 else 2316 return empty_expr_stmt_p (body); 2317 } 2318 return false; 2319 } 2320 2321 /* Perform Koenig lookup. FN_EXPR is the postfix-expression representing 2322 the function (or functions) to call; ARGS are the arguments to the 2323 call. Returns the functions to be considered by overload resolution. */ 2324 2325 cp_expr 2326 perform_koenig_lookup (cp_expr fn_expr, vec<tree, va_gc> *args, 2327 tsubst_flags_t complain) 2328 { 2329 tree identifier = NULL_TREE; 2330 tree functions = NULL_TREE; 2331 tree tmpl_args = NULL_TREE; 2332 bool template_id = false; 2333 location_t loc = fn_expr.get_location (); 2334 tree fn = fn_expr.get_value (); 2335 2336 STRIP_ANY_LOCATION_WRAPPER (fn); 2337 2338 if (TREE_CODE (fn) == TEMPLATE_ID_EXPR) 2339 { 2340 /* Use a separate flag to handle null args. */ 2341 template_id = true; 2342 tmpl_args = TREE_OPERAND (fn, 1); 2343 fn = TREE_OPERAND (fn, 0); 2344 } 2345 2346 /* Find the name of the overloaded function. */ 2347 if (identifier_p (fn)) 2348 identifier = fn; 2349 else 2350 { 2351 functions = fn; 2352 identifier = OVL_NAME (functions); 2353 } 2354 2355 /* A call to a namespace-scope function using an unqualified name. 2356 2357 Do Koenig lookup -- unless any of the arguments are 2358 type-dependent. */ 2359 if (!any_type_dependent_arguments_p (args) 2360 && !any_dependent_template_arguments_p (tmpl_args)) 2361 { 2362 fn = lookup_arg_dependent (identifier, functions, args); 2363 if (!fn) 2364 { 2365 /* The unqualified name could not be resolved. */ 2366 if (complain & tf_error) 2367 fn = unqualified_fn_lookup_error (cp_expr (identifier, loc)); 2368 else 2369 fn = identifier; 2370 } 2371 } 2372 2373 if (fn && template_id && fn != error_mark_node) 2374 fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args); 2375 2376 return cp_expr (fn, loc); 2377 } 2378 2379 /* Generate an expression for `FN (ARGS)'. This may change the 2380 contents of ARGS. 2381 2382 If DISALLOW_VIRTUAL is true, the call to FN will be not generated 2383 as a virtual call, even if FN is virtual. (This flag is set when 2384 encountering an expression where the function name is explicitly 2385 qualified. For example a call to `X::f' never generates a virtual 2386 call.) 2387 2388 Returns code for the call. */ 2389 2390 tree 2391 finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual, 2392 bool koenig_p, tsubst_flags_t complain) 2393 { 2394 tree result; 2395 tree orig_fn; 2396 vec<tree, va_gc> *orig_args = *args; 2397 2398 if (fn == error_mark_node) 2399 return error_mark_node; 2400 2401 gcc_assert (!TYPE_P (fn)); 2402 2403 /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo 2404 it so that we can tell this is a call to a known function. */ 2405 fn = maybe_undo_parenthesized_ref (fn); 2406 2407 STRIP_ANY_LOCATION_WRAPPER (fn); 2408 2409 orig_fn = fn; 2410 2411 if (processing_template_decl) 2412 { 2413 /* If FN is a local extern declaration or set thereof, look them up 2414 again at instantiation time. */ 2415 if (is_overloaded_fn (fn)) 2416 { 2417 tree ifn = get_first_fn (fn); 2418 if (TREE_CODE (ifn) == FUNCTION_DECL 2419 && DECL_LOCAL_FUNCTION_P (ifn)) 2420 orig_fn = DECL_NAME (ifn); 2421 } 2422 2423 /* If the call expression is dependent, build a CALL_EXPR node 2424 with no type; type_dependent_expression_p recognizes 2425 expressions with no type as being dependent. */ 2426 if (type_dependent_expression_p (fn) 2427 || any_type_dependent_arguments_p (*args)) 2428 { 2429 result = build_min_nt_call_vec (orig_fn, *args); 2430 SET_EXPR_LOCATION (result, cp_expr_loc_or_loc (fn, input_location)); 2431 KOENIG_LOOKUP_P (result) = koenig_p; 2432 if (is_overloaded_fn (fn)) 2433 fn = get_fns (fn); 2434 2435 if (cfun) 2436 { 2437 bool abnormal = true; 2438 for (lkp_iterator iter (fn); abnormal && iter; ++iter) 2439 { 2440 tree fndecl = *iter; 2441 if (TREE_CODE (fndecl) != FUNCTION_DECL 2442 || !TREE_THIS_VOLATILE (fndecl)) 2443 abnormal = false; 2444 } 2445 /* FIXME: Stop warning about falling off end of non-void 2446 function. But this is wrong. Even if we only see 2447 no-return fns at this point, we could select a 2448 future-defined return fn during instantiation. Or 2449 vice-versa. */ 2450 if (abnormal) 2451 current_function_returns_abnormally = 1; 2452 } 2453 return result; 2454 } 2455 orig_args = make_tree_vector_copy (*args); 2456 if (!BASELINK_P (fn) 2457 && TREE_CODE (fn) != PSEUDO_DTOR_EXPR 2458 && TREE_TYPE (fn) != unknown_type_node) 2459 fn = build_non_dependent_expr (fn); 2460 make_args_non_dependent (*args); 2461 } 2462 2463 if (TREE_CODE (fn) == COMPONENT_REF) 2464 { 2465 tree member = TREE_OPERAND (fn, 1); 2466 if (BASELINK_P (member)) 2467 { 2468 tree object = TREE_OPERAND (fn, 0); 2469 return build_new_method_call (object, member, 2470 args, NULL_TREE, 2471 (disallow_virtual 2472 ? LOOKUP_NORMAL | LOOKUP_NONVIRTUAL 2473 : LOOKUP_NORMAL), 2474 /*fn_p=*/NULL, 2475 complain); 2476 } 2477 } 2478 2479 /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */ 2480 if (TREE_CODE (fn) == ADDR_EXPR 2481 && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD) 2482 fn = TREE_OPERAND (fn, 0); 2483 2484 if (is_overloaded_fn (fn)) 2485 fn = baselink_for_fns (fn); 2486 2487 result = NULL_TREE; 2488 if (BASELINK_P (fn)) 2489 { 2490 tree object; 2491 2492 /* A call to a member function. From [over.call.func]: 2493 2494 If the keyword this is in scope and refers to the class of 2495 that member function, or a derived class thereof, then the 2496 function call is transformed into a qualified function call 2497 using (*this) as the postfix-expression to the left of the 2498 . operator.... [Otherwise] a contrived object of type T 2499 becomes the implied object argument. 2500 2501 In this situation: 2502 2503 struct A { void f(); }; 2504 struct B : public A {}; 2505 struct C : public A { void g() { B::f(); }}; 2506 2507 "the class of that member function" refers to `A'. But 11.2 2508 [class.access.base] says that we need to convert 'this' to B* as 2509 part of the access, so we pass 'B' to maybe_dummy_object. */ 2510 2511 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn))) 2512 { 2513 /* A constructor call always uses a dummy object. (This constructor 2514 call which has the form A::A () is actually invalid and we are 2515 going to reject it later in build_new_method_call.) */ 2516 object = build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn))); 2517 } 2518 else 2519 object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)), 2520 NULL); 2521 2522 result = build_new_method_call (object, fn, args, NULL_TREE, 2523 (disallow_virtual 2524 ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL 2525 : LOOKUP_NORMAL), 2526 /*fn_p=*/NULL, 2527 complain); 2528 } 2529 else if (is_overloaded_fn (fn)) 2530 { 2531 /* If the function is an overloaded builtin, resolve it. */ 2532 if (TREE_CODE (fn) == FUNCTION_DECL 2533 && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL 2534 || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD)) 2535 result = resolve_overloaded_builtin (input_location, fn, *args); 2536 2537 if (!result) 2538 { 2539 if (warn_sizeof_pointer_memaccess 2540 && (complain & tf_warning) 2541 && !vec_safe_is_empty (*args) 2542 && !processing_template_decl) 2543 { 2544 location_t sizeof_arg_loc[3]; 2545 tree sizeof_arg[3]; 2546 unsigned int i; 2547 for (i = 0; i < 3; i++) 2548 { 2549 tree t; 2550 2551 sizeof_arg_loc[i] = UNKNOWN_LOCATION; 2552 sizeof_arg[i] = NULL_TREE; 2553 if (i >= (*args)->length ()) 2554 continue; 2555 t = (**args)[i]; 2556 if (TREE_CODE (t) != SIZEOF_EXPR) 2557 continue; 2558 if (SIZEOF_EXPR_TYPE_P (t)) 2559 sizeof_arg[i] = TREE_TYPE (TREE_OPERAND (t, 0)); 2560 else 2561 sizeof_arg[i] = TREE_OPERAND (t, 0); 2562 sizeof_arg_loc[i] = EXPR_LOCATION (t); 2563 } 2564 sizeof_pointer_memaccess_warning 2565 (sizeof_arg_loc, fn, *args, 2566 sizeof_arg, same_type_ignoring_top_level_qualifiers_p); 2567 } 2568 2569 if ((complain & tf_warning) 2570 && TREE_CODE (fn) == FUNCTION_DECL 2571 && fndecl_built_in_p (fn, BUILT_IN_MEMSET) 2572 && vec_safe_length (*args) == 3 2573 && !any_type_dependent_arguments_p (*args)) 2574 { 2575 tree arg0 = (*orig_args)[0]; 2576 tree arg1 = (*orig_args)[1]; 2577 tree arg2 = (*orig_args)[2]; 2578 int literal_mask = ((literal_integer_zerop (arg1) << 1) 2579 | (literal_integer_zerop (arg2) << 2)); 2580 warn_for_memset (input_location, arg0, arg2, literal_mask); 2581 } 2582 2583 /* A call to a namespace-scope function. */ 2584 result = build_new_function_call (fn, args, complain); 2585 } 2586 } 2587 else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR) 2588 { 2589 if (!vec_safe_is_empty (*args)) 2590 error ("arguments to destructor are not allowed"); 2591 /* Mark the pseudo-destructor call as having side-effects so 2592 that we do not issue warnings about its use. */ 2593 result = build1 (NOP_EXPR, 2594 void_type_node, 2595 TREE_OPERAND (fn, 0)); 2596 TREE_SIDE_EFFECTS (result) = 1; 2597 } 2598 else if (CLASS_TYPE_P (TREE_TYPE (fn))) 2599 /* If the "function" is really an object of class type, it might 2600 have an overloaded `operator ()'. */ 2601 result = build_op_call (fn, args, complain); 2602 2603 if (!result) 2604 /* A call where the function is unknown. */ 2605 result = cp_build_function_call_vec (fn, args, complain); 2606 2607 if (processing_template_decl && result != error_mark_node) 2608 { 2609 if (INDIRECT_REF_P (result)) 2610 result = TREE_OPERAND (result, 0); 2611 result = build_call_vec (TREE_TYPE (result), orig_fn, orig_args); 2612 SET_EXPR_LOCATION (result, input_location); 2613 KOENIG_LOOKUP_P (result) = koenig_p; 2614 release_tree_vector (orig_args); 2615 result = convert_from_reference (result); 2616 } 2617 2618 return result; 2619 } 2620 2621 /* Finish a call to a postfix increment or decrement or EXPR. (Which 2622 is indicated by CODE, which should be POSTINCREMENT_EXPR or 2623 POSTDECREMENT_EXPR.) */ 2624 2625 cp_expr 2626 finish_increment_expr (cp_expr expr, enum tree_code code) 2627 { 2628 /* input_location holds the location of the trailing operator token. 2629 Build a location of the form: 2630 expr++ 2631 ~~~~^~ 2632 with the caret at the operator token, ranging from the start 2633 of EXPR to the end of the operator token. */ 2634 location_t combined_loc = make_location (input_location, 2635 expr.get_start (), 2636 get_finish (input_location)); 2637 cp_expr result = build_x_unary_op (combined_loc, code, expr, 2638 tf_warning_or_error); 2639 /* TODO: build_x_unary_op doesn't honor the location, so set it here. */ 2640 result.set_location (combined_loc); 2641 return result; 2642 } 2643 2644 /* Finish a use of `this'. Returns an expression for `this'. */ 2645 2646 tree 2647 finish_this_expr (void) 2648 { 2649 tree result = NULL_TREE; 2650 2651 if (current_class_ptr) 2652 { 2653 tree type = TREE_TYPE (current_class_ref); 2654 2655 /* In a lambda expression, 'this' refers to the captured 'this'. */ 2656 if (LAMBDA_TYPE_P (type)) 2657 result = lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type), true); 2658 else 2659 result = current_class_ptr; 2660 } 2661 2662 if (result) 2663 /* The keyword 'this' is a prvalue expression. */ 2664 return rvalue (result); 2665 2666 tree fn = current_nonlambda_function (); 2667 if (fn && DECL_STATIC_FUNCTION_P (fn)) 2668 error ("%<this%> is unavailable for static member functions"); 2669 else if (fn) 2670 error ("invalid use of %<this%> in non-member function"); 2671 else 2672 error ("invalid use of %<this%> at top level"); 2673 return error_mark_node; 2674 } 2675 2676 /* Finish a pseudo-destructor expression. If SCOPE is NULL, the 2677 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is 2678 the TYPE for the type given. If SCOPE is non-NULL, the expression 2679 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */ 2680 2681 tree 2682 finish_pseudo_destructor_expr (tree object, tree scope, tree destructor, 2683 location_t loc) 2684 { 2685 if (object == error_mark_node || destructor == error_mark_node) 2686 return error_mark_node; 2687 2688 gcc_assert (TYPE_P (destructor)); 2689 2690 if (!processing_template_decl) 2691 { 2692 if (scope == error_mark_node) 2693 { 2694 error_at (loc, "invalid qualifying scope in pseudo-destructor name"); 2695 return error_mark_node; 2696 } 2697 if (is_auto (destructor)) 2698 destructor = TREE_TYPE (object); 2699 if (scope && TYPE_P (scope) && !check_dtor_name (scope, destructor)) 2700 { 2701 error_at (loc, 2702 "qualified type %qT does not match destructor name ~%qT", 2703 scope, destructor); 2704 return error_mark_node; 2705 } 2706 2707 2708 /* [expr.pseudo] says both: 2709 2710 The type designated by the pseudo-destructor-name shall be 2711 the same as the object type. 2712 2713 and: 2714 2715 The cv-unqualified versions of the object type and of the 2716 type designated by the pseudo-destructor-name shall be the 2717 same type. 2718 2719 We implement the more generous second sentence, since that is 2720 what most other compilers do. */ 2721 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object), 2722 destructor)) 2723 { 2724 error_at (loc, "%qE is not of type %qT", object, destructor); 2725 return error_mark_node; 2726 } 2727 } 2728 2729 return build3_loc (loc, PSEUDO_DTOR_EXPR, void_type_node, object, 2730 scope, destructor); 2731 } 2732 2733 /* Finish an expression of the form CODE EXPR. */ 2734 2735 cp_expr 2736 finish_unary_op_expr (location_t op_loc, enum tree_code code, cp_expr expr, 2737 tsubst_flags_t complain) 2738 { 2739 /* Build a location of the form: 2740 ++expr 2741 ^~~~~~ 2742 with the caret at the operator token, ranging from the start 2743 of the operator token to the end of EXPR. */ 2744 location_t combined_loc = make_location (op_loc, 2745 op_loc, expr.get_finish ()); 2746 cp_expr result = build_x_unary_op (combined_loc, code, expr, complain); 2747 /* TODO: build_x_unary_op doesn't always honor the location. */ 2748 result.set_location (combined_loc); 2749 2750 if (result == error_mark_node) 2751 return result; 2752 2753 if (!(complain & tf_warning)) 2754 return result; 2755 2756 tree result_ovl = result; 2757 tree expr_ovl = expr; 2758 2759 if (!processing_template_decl) 2760 expr_ovl = cp_fully_fold (expr_ovl); 2761 2762 if (!CONSTANT_CLASS_P (expr_ovl) 2763 || TREE_OVERFLOW_P (expr_ovl)) 2764 return result; 2765 2766 if (!processing_template_decl) 2767 result_ovl = cp_fully_fold (result_ovl); 2768 2769 if (CONSTANT_CLASS_P (result_ovl) && TREE_OVERFLOW_P (result_ovl)) 2770 overflow_warning (combined_loc, result_ovl); 2771 2772 return result; 2773 } 2774 2775 /* Finish a compound-literal expression or C++11 functional cast with aggregate 2776 initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL 2777 is being cast. */ 2778 2779 tree 2780 finish_compound_literal (tree type, tree compound_literal, 2781 tsubst_flags_t complain, 2782 fcl_t fcl_context) 2783 { 2784 if (type == error_mark_node) 2785 return error_mark_node; 2786 2787 if (TYPE_REF_P (type)) 2788 { 2789 compound_literal 2790 = finish_compound_literal (TREE_TYPE (type), compound_literal, 2791 complain, fcl_context); 2792 /* The prvalue is then used to direct-initialize the reference. */ 2793 tree r = (perform_implicit_conversion_flags 2794 (type, compound_literal, complain, LOOKUP_NORMAL)); 2795 return convert_from_reference (r); 2796 } 2797 2798 if (!TYPE_OBJ_P (type)) 2799 { 2800 if (complain & tf_error) 2801 error ("compound literal of non-object type %qT", type); 2802 return error_mark_node; 2803 } 2804 2805 if (tree anode = type_uses_auto (type)) 2806 if (CLASS_PLACEHOLDER_TEMPLATE (anode)) 2807 { 2808 type = do_auto_deduction (type, compound_literal, anode, complain, 2809 adc_variable_type); 2810 if (type == error_mark_node) 2811 return error_mark_node; 2812 } 2813 2814 /* Used to hold a copy of the compound literal in a template. */ 2815 tree orig_cl = NULL_TREE; 2816 2817 if (processing_template_decl) 2818 { 2819 const bool dependent_p 2820 = (instantiation_dependent_expression_p (compound_literal) 2821 || dependent_type_p (type)); 2822 if (dependent_p) 2823 /* We're about to return, no need to copy. */ 2824 orig_cl = compound_literal; 2825 else 2826 /* We're going to need a copy. */ 2827 orig_cl = unshare_constructor (compound_literal); 2828 TREE_TYPE (orig_cl) = type; 2829 /* Mark the expression as a compound literal. */ 2830 TREE_HAS_CONSTRUCTOR (orig_cl) = 1; 2831 /* And as instantiation-dependent. */ 2832 CONSTRUCTOR_IS_DEPENDENT (orig_cl) = dependent_p; 2833 if (fcl_context == fcl_c99) 2834 CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl) = 1; 2835 /* If the compound literal is dependent, we're done for now. */ 2836 if (dependent_p) 2837 return orig_cl; 2838 /* Otherwise, do go on to e.g. check narrowing. */ 2839 } 2840 2841 type = complete_type (type); 2842 2843 if (TYPE_NON_AGGREGATE_CLASS (type)) 2844 { 2845 /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST 2846 everywhere that deals with function arguments would be a pain, so 2847 just wrap it in a TREE_LIST. The parser set a flag so we know 2848 that it came from T{} rather than T({}). */ 2849 CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1; 2850 compound_literal = build_tree_list (NULL_TREE, compound_literal); 2851 return build_functional_cast (type, compound_literal, complain); 2852 } 2853 2854 if (TREE_CODE (type) == ARRAY_TYPE 2855 && check_array_initializer (NULL_TREE, type, compound_literal)) 2856 return error_mark_node; 2857 compound_literal = reshape_init (type, compound_literal, complain); 2858 if (SCALAR_TYPE_P (type) 2859 && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)) 2860 { 2861 tree t = instantiate_non_dependent_expr_sfinae (compound_literal, 2862 complain); 2863 if (!check_narrowing (type, t, complain)) 2864 return error_mark_node; 2865 } 2866 if (TREE_CODE (type) == ARRAY_TYPE 2867 && TYPE_DOMAIN (type) == NULL_TREE) 2868 { 2869 cp_complete_array_type_or_error (&type, compound_literal, 2870 false, complain); 2871 if (type == error_mark_node) 2872 return error_mark_node; 2873 } 2874 compound_literal = digest_init_flags (type, compound_literal, 2875 LOOKUP_NORMAL | LOOKUP_NO_NARROWING, 2876 complain); 2877 if (compound_literal == error_mark_node) 2878 return error_mark_node; 2879 2880 /* If we're in a template, return the original compound literal. */ 2881 if (orig_cl) 2882 { 2883 if (!VECTOR_TYPE_P (type)) 2884 return get_target_expr_sfinae (orig_cl, complain); 2885 else 2886 return orig_cl; 2887 } 2888 2889 if (TREE_CODE (compound_literal) == CONSTRUCTOR) 2890 { 2891 TREE_HAS_CONSTRUCTOR (compound_literal) = true; 2892 if (fcl_context == fcl_c99) 2893 CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal) = 1; 2894 } 2895 2896 /* Put static/constant array temporaries in static variables. */ 2897 /* FIXME all C99 compound literals should be variables rather than C++ 2898 temporaries, unless they are used as an aggregate initializer. */ 2899 if ((!at_function_scope_p () || CP_TYPE_CONST_P (type)) 2900 && fcl_context == fcl_c99 2901 && TREE_CODE (type) == ARRAY_TYPE 2902 && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type) 2903 && initializer_constant_valid_p (compound_literal, type)) 2904 { 2905 tree decl = create_temporary_var (type); 2906 DECL_INITIAL (decl) = compound_literal; 2907 TREE_STATIC (decl) = 1; 2908 if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type)) 2909 { 2910 /* 5.19 says that a constant expression can include an 2911 lvalue-rvalue conversion applied to "a glvalue of literal type 2912 that refers to a non-volatile temporary object initialized 2913 with a constant expression". Rather than try to communicate 2914 that this VAR_DECL is a temporary, just mark it constexpr. */ 2915 DECL_DECLARED_CONSTEXPR_P (decl) = true; 2916 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true; 2917 TREE_CONSTANT (decl) = true; 2918 } 2919 cp_apply_type_quals_to_decl (cp_type_quals (type), decl); 2920 decl = pushdecl_top_level (decl); 2921 DECL_NAME (decl) = make_anon_name (); 2922 SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl)); 2923 /* Make sure the destructor is callable. */ 2924 tree clean = cxx_maybe_build_cleanup (decl, complain); 2925 if (clean == error_mark_node) 2926 return error_mark_node; 2927 return decl; 2928 } 2929 2930 /* Represent other compound literals with TARGET_EXPR so we produce 2931 an lvalue, but can elide copies. */ 2932 if (!VECTOR_TYPE_P (type)) 2933 compound_literal = get_target_expr_sfinae (compound_literal, complain); 2934 2935 return compound_literal; 2936 } 2937 2938 /* Return the declaration for the function-name variable indicated by 2939 ID. */ 2940 2941 tree 2942 finish_fname (tree id) 2943 { 2944 tree decl; 2945 2946 decl = fname_decl (input_location, C_RID_CODE (id), id); 2947 if (processing_template_decl && current_function_decl 2948 && decl != error_mark_node) 2949 decl = DECL_NAME (decl); 2950 return decl; 2951 } 2952 2953 /* Finish a translation unit. */ 2954 2955 void 2956 finish_translation_unit (void) 2957 { 2958 /* In case there were missing closebraces, 2959 get us back to the global binding level. */ 2960 pop_everything (); 2961 while (current_namespace != global_namespace) 2962 pop_namespace (); 2963 2964 /* Do file scope __FUNCTION__ et al. */ 2965 finish_fname_decls (); 2966 } 2967 2968 /* Finish a template type parameter, specified as AGGR IDENTIFIER. 2969 Returns the parameter. */ 2970 2971 tree 2972 finish_template_type_parm (tree aggr, tree identifier) 2973 { 2974 if (aggr != class_type_node) 2975 { 2976 permerror (input_location, "template type parameters must use the keyword %<class%> or %<typename%>"); 2977 aggr = class_type_node; 2978 } 2979 2980 return build_tree_list (aggr, identifier); 2981 } 2982 2983 /* Finish a template template parameter, specified as AGGR IDENTIFIER. 2984 Returns the parameter. */ 2985 2986 tree 2987 finish_template_template_parm (tree aggr, tree identifier) 2988 { 2989 tree decl = build_decl (input_location, 2990 TYPE_DECL, identifier, NULL_TREE); 2991 2992 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE); 2993 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms; 2994 DECL_TEMPLATE_RESULT (tmpl) = decl; 2995 DECL_ARTIFICIAL (decl) = 1; 2996 2997 // Associate the constraints with the underlying declaration, 2998 // not the template. 2999 tree reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms); 3000 tree constr = build_constraints (reqs, NULL_TREE); 3001 set_constraints (decl, constr); 3002 3003 end_template_decl (); 3004 3005 gcc_assert (DECL_TEMPLATE_PARMS (tmpl)); 3006 3007 check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl), 3008 /*is_primary=*/true, /*is_partial=*/false, 3009 /*is_friend=*/0); 3010 3011 return finish_template_type_parm (aggr, tmpl); 3012 } 3013 3014 /* ARGUMENT is the default-argument value for a template template 3015 parameter. If ARGUMENT is invalid, issue error messages and return 3016 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */ 3017 3018 tree 3019 check_template_template_default_arg (tree argument) 3020 { 3021 if (TREE_CODE (argument) != TEMPLATE_DECL 3022 && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM 3023 && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE) 3024 { 3025 if (TREE_CODE (argument) == TYPE_DECL) 3026 error ("invalid use of type %qT as a default value for a template " 3027 "template-parameter", TREE_TYPE (argument)); 3028 else 3029 error ("invalid default argument for a template template parameter"); 3030 return error_mark_node; 3031 } 3032 3033 return argument; 3034 } 3035 3036 /* Begin a class definition, as indicated by T. */ 3037 3038 tree 3039 begin_class_definition (tree t) 3040 { 3041 if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t))) 3042 return error_mark_node; 3043 3044 if (processing_template_parmlist && !LAMBDA_TYPE_P (t)) 3045 { 3046 error ("definition of %q#T inside template parameter list", t); 3047 return error_mark_node; 3048 } 3049 3050 /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733 3051 are passed the same as decimal scalar types. */ 3052 if (TREE_CODE (t) == RECORD_TYPE 3053 && !processing_template_decl) 3054 { 3055 tree ns = TYPE_CONTEXT (t); 3056 if (ns && TREE_CODE (ns) == NAMESPACE_DECL 3057 && DECL_CONTEXT (ns) == std_node 3058 && DECL_NAME (ns) 3059 && id_equal (DECL_NAME (ns), "decimal")) 3060 { 3061 const char *n = TYPE_NAME_STRING (t); 3062 if ((strcmp (n, "decimal32") == 0) 3063 || (strcmp (n, "decimal64") == 0) 3064 || (strcmp (n, "decimal128") == 0)) 3065 TYPE_TRANSPARENT_AGGR (t) = 1; 3066 } 3067 } 3068 3069 /* A non-implicit typename comes from code like: 3070 3071 template <typename T> struct A { 3072 template <typename U> struct A<T>::B ... 3073 3074 This is erroneous. */ 3075 else if (TREE_CODE (t) == TYPENAME_TYPE) 3076 { 3077 error ("invalid definition of qualified type %qT", t); 3078 t = error_mark_node; 3079 } 3080 3081 if (t == error_mark_node || ! MAYBE_CLASS_TYPE_P (t)) 3082 { 3083 t = make_class_type (RECORD_TYPE); 3084 pushtag (make_anon_name (), t, /*tag_scope=*/ts_current); 3085 } 3086 3087 if (TYPE_BEING_DEFINED (t)) 3088 { 3089 t = make_class_type (TREE_CODE (t)); 3090 pushtag (TYPE_IDENTIFIER (t), t, /*tag_scope=*/ts_current); 3091 } 3092 maybe_process_partial_specialization (t); 3093 pushclass (t); 3094 TYPE_BEING_DEFINED (t) = 1; 3095 class_binding_level->defining_class_p = 1; 3096 3097 if (flag_pack_struct) 3098 { 3099 tree v; 3100 TYPE_PACKED (t) = 1; 3101 /* Even though the type is being defined for the first time 3102 here, there might have been a forward declaration, so there 3103 might be cv-qualified variants of T. */ 3104 for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v)) 3105 TYPE_PACKED (v) = 1; 3106 } 3107 /* Reset the interface data, at the earliest possible 3108 moment, as it might have been set via a class foo; 3109 before. */ 3110 if (! TYPE_UNNAMED_P (t)) 3111 { 3112 struct c_fileinfo *finfo = \ 3113 get_fileinfo (LOCATION_FILE (input_location)); 3114 CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only; 3115 SET_CLASSTYPE_INTERFACE_UNKNOWN_X 3116 (t, finfo->interface_unknown); 3117 } 3118 reset_specialization(); 3119 3120 /* Make a declaration for this class in its own scope. */ 3121 build_self_reference (); 3122 3123 return t; 3124 } 3125 3126 /* Finish the member declaration given by DECL. */ 3127 3128 void 3129 finish_member_declaration (tree decl) 3130 { 3131 if (decl == error_mark_node || decl == NULL_TREE) 3132 return; 3133 3134 if (decl == void_type_node) 3135 /* The COMPONENT was a friend, not a member, and so there's 3136 nothing for us to do. */ 3137 return; 3138 3139 /* We should see only one DECL at a time. */ 3140 gcc_assert (DECL_CHAIN (decl) == NULL_TREE); 3141 3142 /* Don't add decls after definition. */ 3143 gcc_assert (TYPE_BEING_DEFINED (current_class_type) 3144 /* We can add lambda types when late parsing default 3145 arguments. */ 3146 || LAMBDA_TYPE_P (TREE_TYPE (decl))); 3147 3148 /* Set up access control for DECL. */ 3149 TREE_PRIVATE (decl) 3150 = (current_access_specifier == access_private_node); 3151 TREE_PROTECTED (decl) 3152 = (current_access_specifier == access_protected_node); 3153 if (TREE_CODE (decl) == TEMPLATE_DECL) 3154 { 3155 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl); 3156 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl); 3157 } 3158 3159 /* Mark the DECL as a member of the current class, unless it's 3160 a member of an enumeration. */ 3161 if (TREE_CODE (decl) != CONST_DECL) 3162 DECL_CONTEXT (decl) = current_class_type; 3163 3164 if (TREE_CODE (decl) == USING_DECL) 3165 /* For now, ignore class-scope USING_DECLS, so that debugging 3166 backends do not see them. */ 3167 DECL_IGNORED_P (decl) = 1; 3168 3169 /* Check for bare parameter packs in the non-static data member 3170 declaration. */ 3171 if (TREE_CODE (decl) == FIELD_DECL) 3172 { 3173 if (check_for_bare_parameter_packs (TREE_TYPE (decl))) 3174 TREE_TYPE (decl) = error_mark_node; 3175 if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl))) 3176 DECL_ATTRIBUTES (decl) = NULL_TREE; 3177 } 3178 3179 /* [dcl.link] 3180 3181 A C language linkage is ignored for the names of class members 3182 and the member function type of class member functions. */ 3183 if (DECL_LANG_SPECIFIC (decl)) 3184 SET_DECL_LANGUAGE (decl, lang_cplusplus); 3185 3186 bool add = false; 3187 3188 /* Functions and non-functions are added differently. */ 3189 if (DECL_DECLARES_FUNCTION_P (decl)) 3190 add = add_method (current_class_type, decl, false); 3191 /* Enter the DECL into the scope of the class, if the class 3192 isn't a closure (whose fields are supposed to be unnamed). */ 3193 else if (CLASSTYPE_LAMBDA_EXPR (current_class_type) 3194 || pushdecl_class_level (decl)) 3195 add = true; 3196 3197 if (add) 3198 { 3199 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields 3200 go at the beginning. The reason is that 3201 legacy_nonfn_member_lookup searches the list in order, and we 3202 want a field name to override a type name so that the "struct 3203 stat hack" will work. In particular: 3204 3205 struct S { enum E { }; static const int E = 5; int ary[S::E]; } s; 3206 3207 is valid. */ 3208 3209 if (TREE_CODE (decl) == TYPE_DECL) 3210 TYPE_FIELDS (current_class_type) 3211 = chainon (TYPE_FIELDS (current_class_type), decl); 3212 else 3213 { 3214 DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type); 3215 TYPE_FIELDS (current_class_type) = decl; 3216 } 3217 3218 maybe_add_class_template_decl_list (current_class_type, decl, 3219 /*friend_p=*/0); 3220 } 3221 } 3222 3223 /* Finish processing a complete template declaration. The PARMS are 3224 the template parameters. */ 3225 3226 void 3227 finish_template_decl (tree parms) 3228 { 3229 if (parms) 3230 end_template_decl (); 3231 else 3232 end_specialization (); 3233 } 3234 3235 // Returns the template type of the class scope being entered. If we're 3236 // entering a constrained class scope. TYPE is the class template 3237 // scope being entered and we may need to match the intended type with 3238 // a constrained specialization. For example: 3239 // 3240 // template<Object T> 3241 // struct S { void f(); }; #1 3242 // 3243 // template<Object T> 3244 // void S<T>::f() { } #2 3245 // 3246 // We check, in #2, that S<T> refers precisely to the type declared by 3247 // #1 (i.e., that the constraints match). Note that the following should 3248 // be an error since there is no specialization of S<T> that is 3249 // unconstrained, but this is not diagnosed here. 3250 // 3251 // template<typename T> 3252 // void S<T>::f() { } 3253 // 3254 // We cannot diagnose this problem here since this function also matches 3255 // qualified template names that are not part of a definition. For example: 3256 // 3257 // template<Integral T, Floating_point U> 3258 // typename pair<T, U>::first_type void f(T, U); 3259 // 3260 // Here, it is unlikely that there is a partial specialization of 3261 // pair constrained for for Integral and Floating_point arguments. 3262 // 3263 // The general rule is: if a constrained specialization with matching 3264 // constraints is found return that type. Also note that if TYPE is not a 3265 // class-type (e.g. a typename type), then no fixup is needed. 3266 3267 static tree 3268 fixup_template_type (tree type) 3269 { 3270 // Find the template parameter list at the a depth appropriate to 3271 // the scope we're trying to enter. 3272 tree parms = current_template_parms; 3273 int depth = template_class_depth (type); 3274 for (int n = processing_template_decl; n > depth && parms; --n) 3275 parms = TREE_CHAIN (parms); 3276 if (!parms) 3277 return type; 3278 tree cur_reqs = TEMPLATE_PARMS_CONSTRAINTS (parms); 3279 tree cur_constr = build_constraints (cur_reqs, NULL_TREE); 3280 3281 // Search for a specialization whose type and constraints match. 3282 tree tmpl = CLASSTYPE_TI_TEMPLATE (type); 3283 tree specs = DECL_TEMPLATE_SPECIALIZATIONS (tmpl); 3284 while (specs) 3285 { 3286 tree spec_constr = get_constraints (TREE_VALUE (specs)); 3287 3288 // If the type and constraints match a specialization, then we 3289 // are entering that type. 3290 if (same_type_p (type, TREE_TYPE (specs)) 3291 && equivalent_constraints (cur_constr, spec_constr)) 3292 return TREE_TYPE (specs); 3293 specs = TREE_CHAIN (specs); 3294 } 3295 3296 // If no specialization matches, then must return the type 3297 // previously found. 3298 return type; 3299 } 3300 3301 /* Finish processing a template-id (which names a type) of the form 3302 NAME < ARGS >. Return the TYPE_DECL for the type named by the 3303 template-id. If ENTERING_SCOPE is nonzero we are about to enter 3304 the scope of template-id indicated. */ 3305 3306 tree 3307 finish_template_type (tree name, tree args, int entering_scope) 3308 { 3309 tree type; 3310 3311 type = lookup_template_class (name, args, 3312 NULL_TREE, NULL_TREE, entering_scope, 3313 tf_warning_or_error | tf_user); 3314 3315 /* If we might be entering the scope of a partial specialization, 3316 find the one with the right constraints. */ 3317 if (flag_concepts 3318 && entering_scope 3319 && CLASS_TYPE_P (type) 3320 && CLASSTYPE_TEMPLATE_INFO (type) 3321 && dependent_type_p (type) 3322 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type))) 3323 type = fixup_template_type (type); 3324 3325 if (type == error_mark_node) 3326 return type; 3327 else if (CLASS_TYPE_P (type) && !alias_type_or_template_p (type)) 3328 return TYPE_STUB_DECL (type); 3329 else 3330 return TYPE_NAME (type); 3331 } 3332 3333 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER. 3334 Return a TREE_LIST containing the ACCESS_SPECIFIER and the 3335 BASE_CLASS, or NULL_TREE if an error occurred. The 3336 ACCESS_SPECIFIER is one of 3337 access_{default,public,protected_private}_node. For a virtual base 3338 we set TREE_TYPE. */ 3339 3340 tree 3341 finish_base_specifier (tree base, tree access, bool virtual_p) 3342 { 3343 tree result; 3344 3345 if (base == error_mark_node) 3346 { 3347 error ("invalid base-class specification"); 3348 result = NULL_TREE; 3349 } 3350 else if (! MAYBE_CLASS_TYPE_P (base)) 3351 { 3352 error ("%qT is not a class type", base); 3353 result = NULL_TREE; 3354 } 3355 else 3356 { 3357 if (cp_type_quals (base) != 0) 3358 { 3359 /* DR 484: Can a base-specifier name a cv-qualified 3360 class type? */ 3361 base = TYPE_MAIN_VARIANT (base); 3362 } 3363 result = build_tree_list (access, base); 3364 if (virtual_p) 3365 TREE_TYPE (result) = integer_type_node; 3366 } 3367 3368 return result; 3369 } 3370 3371 /* If FNS is a member function, a set of member functions, or a 3372 template-id referring to one or more member functions, return a 3373 BASELINK for FNS, incorporating the current access context. 3374 Otherwise, return FNS unchanged. */ 3375 3376 tree 3377 baselink_for_fns (tree fns) 3378 { 3379 tree scope; 3380 tree cl; 3381 3382 if (BASELINK_P (fns) 3383 || error_operand_p (fns)) 3384 return fns; 3385 3386 scope = ovl_scope (fns); 3387 if (!CLASS_TYPE_P (scope)) 3388 return fns; 3389 3390 cl = currently_open_derived_class (scope); 3391 if (!cl) 3392 cl = scope; 3393 cl = TYPE_BINFO (cl); 3394 return build_baselink (cl, cl, fns, /*optype=*/NULL_TREE); 3395 } 3396 3397 /* Returns true iff DECL is a variable from a function outside 3398 the current one. */ 3399 3400 static bool 3401 outer_var_p (tree decl) 3402 { 3403 return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL) 3404 && DECL_FUNCTION_SCOPE_P (decl) 3405 /* Don't get confused by temporaries. */ 3406 && DECL_NAME (decl) 3407 && (DECL_CONTEXT (decl) != current_function_decl 3408 || parsing_nsdmi ())); 3409 } 3410 3411 /* As above, but also checks that DECL is automatic. */ 3412 3413 bool 3414 outer_automatic_var_p (tree decl) 3415 { 3416 return (outer_var_p (decl) 3417 && !TREE_STATIC (decl)); 3418 } 3419 3420 /* DECL satisfies outer_automatic_var_p. Possibly complain about it or 3421 rewrite it for lambda capture. 3422 3423 If ODR_USE is true, we're being called from mark_use, and we complain about 3424 use of constant variables. If ODR_USE is false, we're being called for the 3425 id-expression, and we do lambda capture. */ 3426 3427 tree 3428 process_outer_var_ref (tree decl, tsubst_flags_t complain, bool odr_use) 3429 { 3430 if (cp_unevaluated_operand) 3431 /* It's not a use (3.2) if we're in an unevaluated context. */ 3432 return decl; 3433 if (decl == error_mark_node) 3434 return decl; 3435 3436 tree context = DECL_CONTEXT (decl); 3437 tree containing_function = current_function_decl; 3438 tree lambda_stack = NULL_TREE; 3439 tree lambda_expr = NULL_TREE; 3440 tree initializer = convert_from_reference (decl); 3441 3442 /* Mark it as used now even if the use is ill-formed. */ 3443 if (!mark_used (decl, complain)) 3444 return error_mark_node; 3445 3446 if (parsing_nsdmi ()) 3447 containing_function = NULL_TREE; 3448 3449 if (containing_function && LAMBDA_FUNCTION_P (containing_function)) 3450 { 3451 /* Check whether we've already built a proxy. */ 3452 tree var = decl; 3453 while (is_normal_capture_proxy (var)) 3454 var = DECL_CAPTURED_VARIABLE (var); 3455 tree d = retrieve_local_specialization (var); 3456 3457 if (d && d != decl && is_capture_proxy (d)) 3458 { 3459 if (DECL_CONTEXT (d) == containing_function) 3460 /* We already have an inner proxy. */ 3461 return d; 3462 else 3463 /* We need to capture an outer proxy. */ 3464 return process_outer_var_ref (d, complain, odr_use); 3465 } 3466 } 3467 3468 /* If we are in a lambda function, we can move out until we hit 3469 1. the context, 3470 2. a non-lambda function, or 3471 3. a non-default capturing lambda function. */ 3472 while (context != containing_function 3473 /* containing_function can be null with invalid generic lambdas. */ 3474 && containing_function 3475 && LAMBDA_FUNCTION_P (containing_function)) 3476 { 3477 tree closure = DECL_CONTEXT (containing_function); 3478 lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure); 3479 3480 if (TYPE_CLASS_SCOPE_P (closure)) 3481 /* A lambda in an NSDMI (c++/64496). */ 3482 break; 3483 3484 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) 3485 == CPLD_NONE) 3486 break; 3487 3488 lambda_stack = tree_cons (NULL_TREE, 3489 lambda_expr, 3490 lambda_stack); 3491 3492 containing_function 3493 = decl_function_context (containing_function); 3494 } 3495 3496 /* In a lambda within a template, wait until instantiation time to implicitly 3497 capture a parameter pack. We want to wait because we don't know if we're 3498 capturing the whole pack or a single element, and it's OK to wait because 3499 find_parameter_packs_r walks into the lambda body. */ 3500 if (context == containing_function 3501 && DECL_PACK_P (decl)) 3502 return decl; 3503 3504 if (lambda_expr && VAR_P (decl) 3505 && DECL_ANON_UNION_VAR_P (decl)) 3506 { 3507 if (complain & tf_error) 3508 error ("cannot capture member %qD of anonymous union", decl); 3509 return error_mark_node; 3510 } 3511 /* Do lambda capture when processing the id-expression, not when 3512 odr-using a variable. */ 3513 if (!odr_use && context == containing_function) 3514 { 3515 decl = add_default_capture (lambda_stack, 3516 /*id=*/DECL_NAME (decl), 3517 initializer); 3518 } 3519 /* Only an odr-use of an outer automatic variable causes an 3520 error, and a constant variable can decay to a prvalue 3521 constant without odr-use. So don't complain yet. */ 3522 else if (!odr_use && decl_constant_var_p (decl)) 3523 return decl; 3524 else if (lambda_expr) 3525 { 3526 if (complain & tf_error) 3527 { 3528 error ("%qD is not captured", decl); 3529 tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr); 3530 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) 3531 == CPLD_NONE) 3532 inform (location_of (closure), 3533 "the lambda has no capture-default"); 3534 else if (TYPE_CLASS_SCOPE_P (closure)) 3535 inform (UNKNOWN_LOCATION, "lambda in local class %q+T cannot " 3536 "capture variables from the enclosing context", 3537 TYPE_CONTEXT (closure)); 3538 inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl); 3539 } 3540 return error_mark_node; 3541 } 3542 else 3543 { 3544 if (complain & tf_error) 3545 { 3546 error (VAR_P (decl) 3547 ? G_("use of local variable with automatic storage from " 3548 "containing function") 3549 : G_("use of parameter from containing function")); 3550 inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl); 3551 } 3552 return error_mark_node; 3553 } 3554 return decl; 3555 } 3556 3557 /* ID_EXPRESSION is a representation of parsed, but unprocessed, 3558 id-expression. (See cp_parser_id_expression for details.) SCOPE, 3559 if non-NULL, is the type or namespace used to explicitly qualify 3560 ID_EXPRESSION. DECL is the entity to which that name has been 3561 resolved. 3562 3563 *CONSTANT_EXPRESSION_P is true if we are presently parsing a 3564 constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will 3565 be set to true if this expression isn't permitted in a 3566 constant-expression, but it is otherwise not set by this function. 3567 *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a 3568 constant-expression, but a non-constant expression is also 3569 permissible. 3570 3571 DONE is true if this expression is a complete postfix-expression; 3572 it is false if this expression is followed by '->', '[', '(', etc. 3573 ADDRESS_P is true iff this expression is the operand of '&'. 3574 TEMPLATE_P is true iff the qualified-id was of the form 3575 "A::template B". TEMPLATE_ARG_P is true iff this qualified name 3576 appears as a template argument. 3577 3578 If an error occurs, and it is the kind of error that might cause 3579 the parser to abort a tentative parse, *ERROR_MSG is filled in. It 3580 is the caller's responsibility to issue the message. *ERROR_MSG 3581 will be a string with static storage duration, so the caller need 3582 not "free" it. 3583 3584 Return an expression for the entity, after issuing appropriate 3585 diagnostics. This function is also responsible for transforming a 3586 reference to a non-static member into a COMPONENT_REF that makes 3587 the use of "this" explicit. 3588 3589 Upon return, *IDK will be filled in appropriately. */ 3590 static cp_expr 3591 finish_id_expression_1 (tree id_expression, 3592 tree decl, 3593 tree scope, 3594 cp_id_kind *idk, 3595 bool integral_constant_expression_p, 3596 bool allow_non_integral_constant_expression_p, 3597 bool *non_integral_constant_expression_p, 3598 bool template_p, 3599 bool done, 3600 bool address_p, 3601 bool template_arg_p, 3602 const char **error_msg, 3603 location_t location) 3604 { 3605 decl = strip_using_decl (decl); 3606 3607 /* Initialize the output parameters. */ 3608 *idk = CP_ID_KIND_NONE; 3609 *error_msg = NULL; 3610 3611 if (id_expression == error_mark_node) 3612 return error_mark_node; 3613 /* If we have a template-id, then no further lookup is 3614 required. If the template-id was for a template-class, we 3615 will sometimes have a TYPE_DECL at this point. */ 3616 else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR 3617 || TREE_CODE (decl) == TYPE_DECL) 3618 ; 3619 /* Look up the name. */ 3620 else 3621 { 3622 if (decl == error_mark_node) 3623 { 3624 /* Name lookup failed. */ 3625 if (scope 3626 && (!TYPE_P (scope) 3627 || (!dependent_type_p (scope) 3628 && !(identifier_p (id_expression) 3629 && IDENTIFIER_CONV_OP_P (id_expression) 3630 && dependent_type_p (TREE_TYPE (id_expression)))))) 3631 { 3632 /* If the qualifying type is non-dependent (and the name 3633 does not name a conversion operator to a dependent 3634 type), issue an error. */ 3635 qualified_name_lookup_error (scope, id_expression, decl, location); 3636 return error_mark_node; 3637 } 3638 else if (!scope) 3639 { 3640 /* It may be resolved via Koenig lookup. */ 3641 *idk = CP_ID_KIND_UNQUALIFIED; 3642 return id_expression; 3643 } 3644 else 3645 decl = id_expression; 3646 } 3647 3648 /* Remember that the name was used in the definition of 3649 the current class so that we can check later to see if 3650 the meaning would have been different after the class 3651 was entirely defined. */ 3652 if (!scope && decl != error_mark_node && identifier_p (id_expression)) 3653 maybe_note_name_used_in_class (id_expression, decl); 3654 3655 /* A use in unevaluated operand might not be instantiated appropriately 3656 if tsubst_copy builds a dummy parm, or if we never instantiate a 3657 generic lambda, so mark it now. */ 3658 if (processing_template_decl && cp_unevaluated_operand) 3659 mark_type_use (decl); 3660 3661 /* Disallow uses of local variables from containing functions, except 3662 within lambda-expressions. */ 3663 if (outer_automatic_var_p (decl)) 3664 { 3665 decl = process_outer_var_ref (decl, tf_warning_or_error); 3666 if (decl == error_mark_node) 3667 return error_mark_node; 3668 } 3669 3670 /* Also disallow uses of function parameters outside the function 3671 body, except inside an unevaluated context (i.e. decltype). */ 3672 if (TREE_CODE (decl) == PARM_DECL 3673 && DECL_CONTEXT (decl) == NULL_TREE 3674 && !cp_unevaluated_operand) 3675 { 3676 *error_msg = G_("use of parameter outside function body"); 3677 return error_mark_node; 3678 } 3679 } 3680 3681 /* If we didn't find anything, or what we found was a type, 3682 then this wasn't really an id-expression. */ 3683 if (TREE_CODE (decl) == TEMPLATE_DECL 3684 && !DECL_FUNCTION_TEMPLATE_P (decl)) 3685 { 3686 *error_msg = G_("missing template arguments"); 3687 return error_mark_node; 3688 } 3689 else if (TREE_CODE (decl) == TYPE_DECL 3690 || TREE_CODE (decl) == NAMESPACE_DECL) 3691 { 3692 *error_msg = G_("expected primary-expression"); 3693 return error_mark_node; 3694 } 3695 3696 /* If the name resolved to a template parameter, there is no 3697 need to look it up again later. */ 3698 if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl)) 3699 || TREE_CODE (decl) == TEMPLATE_PARM_INDEX) 3700 { 3701 tree r; 3702 3703 *idk = CP_ID_KIND_NONE; 3704 if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX) 3705 decl = TEMPLATE_PARM_DECL (decl); 3706 r = DECL_INITIAL (decl); 3707 if (CLASS_TYPE_P (TREE_TYPE (r)) && !CP_TYPE_CONST_P (TREE_TYPE (r))) 3708 { 3709 /* If the entity is a template parameter object for a template 3710 parameter of type T, the type of the expression is const T. */ 3711 tree ctype = TREE_TYPE (r); 3712 ctype = cp_build_qualified_type (ctype, (cp_type_quals (ctype) 3713 | TYPE_QUAL_CONST)); 3714 r = build1 (VIEW_CONVERT_EXPR, ctype, r); 3715 } 3716 r = convert_from_reference (r); 3717 if (integral_constant_expression_p 3718 && !dependent_type_p (TREE_TYPE (decl)) 3719 && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r)))) 3720 { 3721 if (!allow_non_integral_constant_expression_p) 3722 error ("template parameter %qD of type %qT is not allowed in " 3723 "an integral constant expression because it is not of " 3724 "integral or enumeration type", decl, TREE_TYPE (decl)); 3725 *non_integral_constant_expression_p = true; 3726 } 3727 return r; 3728 } 3729 else 3730 { 3731 bool dependent_p = type_dependent_expression_p (decl); 3732 3733 /* If the declaration was explicitly qualified indicate 3734 that. The semantics of `A::f(3)' are different than 3735 `f(3)' if `f' is virtual. */ 3736 *idk = (scope 3737 ? CP_ID_KIND_QUALIFIED 3738 : (TREE_CODE (decl) == TEMPLATE_ID_EXPR 3739 ? CP_ID_KIND_TEMPLATE_ID 3740 : (dependent_p 3741 ? CP_ID_KIND_UNQUALIFIED_DEPENDENT 3742 : CP_ID_KIND_UNQUALIFIED))); 3743 3744 if (dependent_p 3745 && DECL_P (decl) 3746 && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl))) 3747 /* Dependent type attributes on the decl mean that the TREE_TYPE is 3748 wrong, so just return the identifier. */ 3749 return id_expression; 3750 3751 if (TREE_CODE (decl) == NAMESPACE_DECL) 3752 { 3753 error ("use of namespace %qD as expression", decl); 3754 return error_mark_node; 3755 } 3756 else if (DECL_CLASS_TEMPLATE_P (decl)) 3757 { 3758 error ("use of class template %qT as expression", decl); 3759 return error_mark_node; 3760 } 3761 else if (TREE_CODE (decl) == TREE_LIST) 3762 { 3763 /* Ambiguous reference to base members. */ 3764 error ("request for member %qD is ambiguous in " 3765 "multiple inheritance lattice", id_expression); 3766 print_candidates (decl); 3767 return error_mark_node; 3768 } 3769 3770 /* Mark variable-like entities as used. Functions are similarly 3771 marked either below or after overload resolution. */ 3772 if ((VAR_P (decl) 3773 || TREE_CODE (decl) == PARM_DECL 3774 || TREE_CODE (decl) == CONST_DECL 3775 || TREE_CODE (decl) == RESULT_DECL) 3776 && !mark_used (decl)) 3777 return error_mark_node; 3778 3779 /* Only certain kinds of names are allowed in constant 3780 expression. Template parameters have already 3781 been handled above. */ 3782 if (! error_operand_p (decl) 3783 && !dependent_p 3784 && integral_constant_expression_p 3785 && ! decl_constant_var_p (decl) 3786 && TREE_CODE (decl) != CONST_DECL 3787 && ! builtin_valid_in_constant_expr_p (decl)) 3788 { 3789 if (!allow_non_integral_constant_expression_p) 3790 { 3791 error ("%qD cannot appear in a constant-expression", decl); 3792 return error_mark_node; 3793 } 3794 *non_integral_constant_expression_p = true; 3795 } 3796 3797 if (tree wrap = maybe_get_tls_wrapper_call (decl)) 3798 /* Replace an evaluated use of the thread_local variable with 3799 a call to its wrapper. */ 3800 decl = wrap; 3801 else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR 3802 && !dependent_p 3803 && variable_template_p (TREE_OPERAND (decl, 0))) 3804 { 3805 decl = finish_template_variable (decl); 3806 mark_used (decl); 3807 decl = convert_from_reference (decl); 3808 } 3809 else if (scope) 3810 { 3811 if (TREE_CODE (decl) == SCOPE_REF) 3812 { 3813 gcc_assert (same_type_p (scope, TREE_OPERAND (decl, 0))); 3814 decl = TREE_OPERAND (decl, 1); 3815 } 3816 3817 decl = (adjust_result_of_qualified_name_lookup 3818 (decl, scope, current_nonlambda_class_type())); 3819 3820 if (TREE_CODE (decl) == FUNCTION_DECL) 3821 mark_used (decl); 3822 3823 if (TYPE_P (scope)) 3824 decl = finish_qualified_id_expr (scope, 3825 decl, 3826 done, 3827 address_p, 3828 template_p, 3829 template_arg_p, 3830 tf_warning_or_error); 3831 else 3832 decl = convert_from_reference (decl); 3833 } 3834 else if (TREE_CODE (decl) == FIELD_DECL) 3835 { 3836 /* Since SCOPE is NULL here, this is an unqualified name. 3837 Access checking has been performed during name lookup 3838 already. Turn off checking to avoid duplicate errors. */ 3839 push_deferring_access_checks (dk_no_check); 3840 decl = finish_non_static_data_member (decl, NULL_TREE, 3841 /*qualifying_scope=*/NULL_TREE); 3842 pop_deferring_access_checks (); 3843 } 3844 else if (is_overloaded_fn (decl)) 3845 { 3846 tree first_fn = get_first_fn (decl); 3847 3848 if (TREE_CODE (first_fn) == TEMPLATE_DECL) 3849 first_fn = DECL_TEMPLATE_RESULT (first_fn); 3850 3851 /* [basic.def.odr]: "A function whose name appears as a 3852 potentially-evaluated expression is odr-used if it is the unique 3853 lookup result". 3854 3855 But only mark it if it's a complete postfix-expression; in a call, 3856 ADL might select a different function, and we'll call mark_used in 3857 build_over_call. */ 3858 if (done 3859 && !really_overloaded_fn (decl) 3860 && !mark_used (first_fn)) 3861 return error_mark_node; 3862 3863 if (!template_arg_p 3864 && (TREE_CODE (first_fn) == USING_DECL 3865 || (TREE_CODE (first_fn) == FUNCTION_DECL 3866 && DECL_FUNCTION_MEMBER_P (first_fn) 3867 && !shared_member_p (decl)))) 3868 { 3869 /* A set of member functions. */ 3870 decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0); 3871 return finish_class_member_access_expr (decl, id_expression, 3872 /*template_p=*/false, 3873 tf_warning_or_error); 3874 } 3875 3876 decl = baselink_for_fns (decl); 3877 } 3878 else 3879 { 3880 if (DECL_P (decl) && DECL_NONLOCAL (decl) 3881 && DECL_CLASS_SCOPE_P (decl)) 3882 { 3883 tree context = context_for_name_lookup (decl); 3884 if (context != current_class_type) 3885 { 3886 tree path = currently_open_derived_class (context); 3887 perform_or_defer_access_check (TYPE_BINFO (path), 3888 decl, decl, 3889 tf_warning_or_error); 3890 } 3891 } 3892 3893 decl = convert_from_reference (decl); 3894 } 3895 } 3896 3897 return cp_expr (decl, location); 3898 } 3899 3900 /* As per finish_id_expression_1, but adding a wrapper node 3901 around the result if needed to express LOCATION. */ 3902 3903 cp_expr 3904 finish_id_expression (tree id_expression, 3905 tree decl, 3906 tree scope, 3907 cp_id_kind *idk, 3908 bool integral_constant_expression_p, 3909 bool allow_non_integral_constant_expression_p, 3910 bool *non_integral_constant_expression_p, 3911 bool template_p, 3912 bool done, 3913 bool address_p, 3914 bool template_arg_p, 3915 const char **error_msg, 3916 location_t location) 3917 { 3918 cp_expr result 3919 = finish_id_expression_1 (id_expression, decl, scope, idk, 3920 integral_constant_expression_p, 3921 allow_non_integral_constant_expression_p, 3922 non_integral_constant_expression_p, 3923 template_p, done, address_p, template_arg_p, 3924 error_msg, location); 3925 return result.maybe_add_location_wrapper (); 3926 } 3927 3928 /* Implement the __typeof keyword: Return the type of EXPR, suitable for 3929 use as a type-specifier. */ 3930 3931 tree 3932 finish_typeof (tree expr) 3933 { 3934 tree type; 3935 3936 if (type_dependent_expression_p (expr)) 3937 { 3938 type = cxx_make_type (TYPEOF_TYPE); 3939 TYPEOF_TYPE_EXPR (type) = expr; 3940 SET_TYPE_STRUCTURAL_EQUALITY (type); 3941 3942 return type; 3943 } 3944 3945 expr = mark_type_use (expr); 3946 3947 type = unlowered_expr_type (expr); 3948 3949 if (!type || type == unknown_type_node) 3950 { 3951 error ("type of %qE is unknown", expr); 3952 return error_mark_node; 3953 } 3954 3955 return type; 3956 } 3957 3958 /* Implement the __underlying_type keyword: Return the underlying 3959 type of TYPE, suitable for use as a type-specifier. */ 3960 3961 tree 3962 finish_underlying_type (tree type) 3963 { 3964 tree underlying_type; 3965 3966 if (processing_template_decl) 3967 { 3968 underlying_type = cxx_make_type (UNDERLYING_TYPE); 3969 UNDERLYING_TYPE_TYPE (underlying_type) = type; 3970 SET_TYPE_STRUCTURAL_EQUALITY (underlying_type); 3971 3972 return underlying_type; 3973 } 3974 3975 if (!complete_type_or_else (type, NULL_TREE)) 3976 return error_mark_node; 3977 3978 if (TREE_CODE (type) != ENUMERAL_TYPE) 3979 { 3980 error ("%qT is not an enumeration type", type); 3981 return error_mark_node; 3982 } 3983 3984 underlying_type = ENUM_UNDERLYING_TYPE (type); 3985 3986 /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE 3987 includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information. 3988 See finish_enum_value_list for details. */ 3989 if (!ENUM_FIXED_UNDERLYING_TYPE_P (type)) 3990 underlying_type 3991 = c_common_type_for_mode (TYPE_MODE (underlying_type), 3992 TYPE_UNSIGNED (underlying_type)); 3993 3994 return underlying_type; 3995 } 3996 3997 /* Implement the __direct_bases keyword: Return the direct base classes 3998 of type. */ 3999 4000 tree 4001 calculate_direct_bases (tree type, tsubst_flags_t complain) 4002 { 4003 if (!complete_type_or_maybe_complain (type, NULL_TREE, complain) 4004 || !NON_UNION_CLASS_TYPE_P (type)) 4005 return make_tree_vec (0); 4006 4007 vec<tree, va_gc> *vector = make_tree_vector (); 4008 vec<tree, va_gc> *base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type)); 4009 tree binfo; 4010 unsigned i; 4011 4012 /* Virtual bases are initialized first */ 4013 for (i = 0; base_binfos->iterate (i, &binfo); i++) 4014 if (BINFO_VIRTUAL_P (binfo)) 4015 vec_safe_push (vector, binfo); 4016 4017 /* Now non-virtuals */ 4018 for (i = 0; base_binfos->iterate (i, &binfo); i++) 4019 if (!BINFO_VIRTUAL_P (binfo)) 4020 vec_safe_push (vector, binfo); 4021 4022 tree bases_vec = make_tree_vec (vector->length ()); 4023 4024 for (i = 0; i < vector->length (); ++i) 4025 TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE ((*vector)[i]); 4026 4027 release_tree_vector (vector); 4028 return bases_vec; 4029 } 4030 4031 /* Implement the __bases keyword: Return the base classes 4032 of type */ 4033 4034 /* Find morally non-virtual base classes by walking binfo hierarchy */ 4035 /* Virtual base classes are handled separately in finish_bases */ 4036 4037 static tree 4038 dfs_calculate_bases_pre (tree binfo, void * /*data_*/) 4039 { 4040 /* Don't walk bases of virtual bases */ 4041 return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE; 4042 } 4043 4044 static tree 4045 dfs_calculate_bases_post (tree binfo, void *data_) 4046 { 4047 vec<tree, va_gc> **data = ((vec<tree, va_gc> **) data_); 4048 if (!BINFO_VIRTUAL_P (binfo)) 4049 vec_safe_push (*data, BINFO_TYPE (binfo)); 4050 return NULL_TREE; 4051 } 4052 4053 /* Calculates the morally non-virtual base classes of a class */ 4054 static vec<tree, va_gc> * 4055 calculate_bases_helper (tree type) 4056 { 4057 vec<tree, va_gc> *vector = make_tree_vector (); 4058 4059 /* Now add non-virtual base classes in order of construction */ 4060 if (TYPE_BINFO (type)) 4061 dfs_walk_all (TYPE_BINFO (type), 4062 dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector); 4063 return vector; 4064 } 4065 4066 tree 4067 calculate_bases (tree type, tsubst_flags_t complain) 4068 { 4069 if (!complete_type_or_maybe_complain (type, NULL_TREE, complain) 4070 || !NON_UNION_CLASS_TYPE_P (type)) 4071 return make_tree_vec (0); 4072 4073 vec<tree, va_gc> *vector = make_tree_vector (); 4074 tree bases_vec = NULL_TREE; 4075 unsigned i; 4076 vec<tree, va_gc> *vbases; 4077 vec<tree, va_gc> *nonvbases; 4078 tree binfo; 4079 4080 /* First go through virtual base classes */ 4081 for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0; 4082 vec_safe_iterate (vbases, i, &binfo); i++) 4083 { 4084 vec<tree, va_gc> *vbase_bases 4085 = calculate_bases_helper (BINFO_TYPE (binfo)); 4086 vec_safe_splice (vector, vbase_bases); 4087 release_tree_vector (vbase_bases); 4088 } 4089 4090 /* Now for the non-virtual bases */ 4091 nonvbases = calculate_bases_helper (type); 4092 vec_safe_splice (vector, nonvbases); 4093 release_tree_vector (nonvbases); 4094 4095 /* Note that during error recovery vector->length can even be zero. */ 4096 if (vector->length () > 1) 4097 { 4098 /* Last element is entire class, so don't copy */ 4099 bases_vec = make_tree_vec (vector->length () - 1); 4100 4101 for (i = 0; i < vector->length () - 1; ++i) 4102 TREE_VEC_ELT (bases_vec, i) = (*vector)[i]; 4103 } 4104 else 4105 bases_vec = make_tree_vec (0); 4106 4107 release_tree_vector (vector); 4108 return bases_vec; 4109 } 4110 4111 tree 4112 finish_bases (tree type, bool direct) 4113 { 4114 tree bases = NULL_TREE; 4115 4116 if (!processing_template_decl) 4117 { 4118 /* Parameter packs can only be used in templates */ 4119 error ("Parameter pack __bases only valid in template declaration"); 4120 return error_mark_node; 4121 } 4122 4123 bases = cxx_make_type (BASES); 4124 BASES_TYPE (bases) = type; 4125 BASES_DIRECT (bases) = direct; 4126 SET_TYPE_STRUCTURAL_EQUALITY (bases); 4127 4128 return bases; 4129 } 4130 4131 /* Perform C++-specific checks for __builtin_offsetof before calling 4132 fold_offsetof. */ 4133 4134 tree 4135 finish_offsetof (tree object_ptr, tree expr, location_t loc) 4136 { 4137 /* If we're processing a template, we can't finish the semantics yet. 4138 Otherwise we can fold the entire expression now. */ 4139 if (processing_template_decl) 4140 { 4141 expr = build2 (OFFSETOF_EXPR, size_type_node, expr, object_ptr); 4142 SET_EXPR_LOCATION (expr, loc); 4143 return expr; 4144 } 4145 4146 if (expr == error_mark_node) 4147 return error_mark_node; 4148 4149 if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR) 4150 { 4151 error ("cannot apply %<offsetof%> to destructor %<~%T%>", 4152 TREE_OPERAND (expr, 2)); 4153 return error_mark_node; 4154 } 4155 if (TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE 4156 || TREE_CODE (TREE_TYPE (expr)) == METHOD_TYPE 4157 || TREE_TYPE (expr) == unknown_type_node) 4158 { 4159 while (TREE_CODE (expr) == COMPONENT_REF 4160 || TREE_CODE (expr) == COMPOUND_EXPR) 4161 expr = TREE_OPERAND (expr, 1); 4162 4163 if (DECL_P (expr)) 4164 { 4165 error ("cannot apply %<offsetof%> to member function %qD", expr); 4166 inform (DECL_SOURCE_LOCATION (expr), "declared here"); 4167 } 4168 else 4169 error ("cannot apply %<offsetof%> to member function"); 4170 return error_mark_node; 4171 } 4172 if (TREE_CODE (expr) == CONST_DECL) 4173 { 4174 error ("cannot apply %<offsetof%> to an enumerator %qD", expr); 4175 return error_mark_node; 4176 } 4177 if (REFERENCE_REF_P (expr)) 4178 expr = TREE_OPERAND (expr, 0); 4179 if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr)), object_ptr)) 4180 return error_mark_node; 4181 if (warn_invalid_offsetof 4182 && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr))) 4183 && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr))) 4184 && cp_unevaluated_operand == 0) 4185 warning_at (loc, OPT_Winvalid_offsetof, "offsetof within " 4186 "non-standard-layout type %qT is conditionally-supported", 4187 TREE_TYPE (TREE_TYPE (object_ptr))); 4188 return fold_offsetof (expr); 4189 } 4190 4191 /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This 4192 function is broken out from the above for the benefit of the tree-ssa 4193 project. */ 4194 4195 void 4196 simplify_aggr_init_expr (tree *tp) 4197 { 4198 tree aggr_init_expr = *tp; 4199 4200 /* Form an appropriate CALL_EXPR. */ 4201 tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr); 4202 tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr); 4203 tree type = TREE_TYPE (slot); 4204 4205 tree call_expr; 4206 enum style_t { ctor, arg, pcc } style; 4207 4208 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr)) 4209 style = ctor; 4210 #ifdef PCC_STATIC_STRUCT_RETURN 4211 else if (1) 4212 style = pcc; 4213 #endif 4214 else 4215 { 4216 gcc_assert (TREE_ADDRESSABLE (type)); 4217 style = arg; 4218 } 4219 4220 call_expr = build_call_array_loc (input_location, 4221 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))), 4222 fn, 4223 aggr_init_expr_nargs (aggr_init_expr), 4224 AGGR_INIT_EXPR_ARGP (aggr_init_expr)); 4225 TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr); 4226 CALL_FROM_THUNK_P (call_expr) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr); 4227 CALL_EXPR_OPERATOR_SYNTAX (call_expr) 4228 = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr); 4229 CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr); 4230 CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr); 4231 4232 if (style == ctor) 4233 { 4234 /* Replace the first argument to the ctor with the address of the 4235 slot. */ 4236 cxx_mark_addressable (slot); 4237 CALL_EXPR_ARG (call_expr, 0) = 4238 build1 (ADDR_EXPR, build_pointer_type (type), slot); 4239 } 4240 else if (style == arg) 4241 { 4242 /* Just mark it addressable here, and leave the rest to 4243 expand_call{,_inline}. */ 4244 cxx_mark_addressable (slot); 4245 CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true; 4246 call_expr = build2 (INIT_EXPR, TREE_TYPE (call_expr), slot, call_expr); 4247 } 4248 else if (style == pcc) 4249 { 4250 /* If we're using the non-reentrant PCC calling convention, then we 4251 need to copy the returned value out of the static buffer into the 4252 SLOT. */ 4253 push_deferring_access_checks (dk_no_check); 4254 call_expr = build_aggr_init (slot, call_expr, 4255 DIRECT_BIND | LOOKUP_ONLYCONVERTING, 4256 tf_warning_or_error); 4257 pop_deferring_access_checks (); 4258 call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot); 4259 } 4260 4261 if (AGGR_INIT_ZERO_FIRST (aggr_init_expr)) 4262 { 4263 tree init = build_zero_init (type, NULL_TREE, 4264 /*static_storage_p=*/false); 4265 init = build2 (INIT_EXPR, void_type_node, slot, init); 4266 call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr), 4267 init, call_expr); 4268 } 4269 4270 *tp = call_expr; 4271 } 4272 4273 /* Emit all thunks to FN that should be emitted when FN is emitted. */ 4274 4275 void 4276 emit_associated_thunks (tree fn) 4277 { 4278 /* When we use vcall offsets, we emit thunks with the virtual 4279 functions to which they thunk. The whole point of vcall offsets 4280 is so that you can know statically the entire set of thunks that 4281 will ever be needed for a given virtual function, thereby 4282 enabling you to output all the thunks with the function itself. */ 4283 if (DECL_VIRTUAL_P (fn) 4284 /* Do not emit thunks for extern template instantiations. */ 4285 && ! DECL_REALLY_EXTERN (fn)) 4286 { 4287 tree thunk; 4288 4289 for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk)) 4290 { 4291 if (!THUNK_ALIAS (thunk)) 4292 { 4293 use_thunk (thunk, /*emit_p=*/1); 4294 if (DECL_RESULT_THUNK_P (thunk)) 4295 { 4296 tree probe; 4297 4298 for (probe = DECL_THUNKS (thunk); 4299 probe; probe = DECL_CHAIN (probe)) 4300 use_thunk (probe, /*emit_p=*/1); 4301 } 4302 } 4303 else 4304 gcc_assert (!DECL_THUNKS (thunk)); 4305 } 4306 } 4307 } 4308 4309 /* Generate RTL for FN. */ 4310 4311 bool 4312 expand_or_defer_fn_1 (tree fn) 4313 { 4314 /* When the parser calls us after finishing the body of a template 4315 function, we don't really want to expand the body. */ 4316 if (processing_template_decl) 4317 { 4318 /* Normally, collection only occurs in rest_of_compilation. So, 4319 if we don't collect here, we never collect junk generated 4320 during the processing of templates until we hit a 4321 non-template function. It's not safe to do this inside a 4322 nested class, though, as the parser may have local state that 4323 is not a GC root. */ 4324 if (!function_depth) 4325 ggc_collect (); 4326 return false; 4327 } 4328 4329 gcc_assert (DECL_SAVED_TREE (fn)); 4330 4331 /* We make a decision about linkage for these functions at the end 4332 of the compilation. Until that point, we do not want the back 4333 end to output them -- but we do want it to see the bodies of 4334 these functions so that it can inline them as appropriate. */ 4335 if (DECL_DECLARED_INLINE_P (fn) || DECL_IMPLICIT_INSTANTIATION (fn)) 4336 { 4337 if (DECL_INTERFACE_KNOWN (fn)) 4338 /* We've already made a decision as to how this function will 4339 be handled. */; 4340 else if (!at_eof || DECL_OMP_DECLARE_REDUCTION_P (fn)) 4341 tentative_decl_linkage (fn); 4342 else 4343 import_export_decl (fn); 4344 4345 /* If the user wants us to keep all inline functions, then mark 4346 this function as needed so that finish_file will make sure to 4347 output it later. Similarly, all dllexport'd functions must 4348 be emitted; there may be callers in other DLLs. */ 4349 if (DECL_DECLARED_INLINE_P (fn) 4350 && !DECL_REALLY_EXTERN (fn) 4351 && !DECL_OMP_DECLARE_REDUCTION_P (fn) 4352 && (flag_keep_inline_functions 4353 || (flag_keep_inline_dllexport 4354 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn))))) 4355 { 4356 mark_needed (fn); 4357 DECL_EXTERNAL (fn) = 0; 4358 } 4359 } 4360 4361 /* If this is a constructor or destructor body, we have to clone 4362 it. */ 4363 if (maybe_clone_body (fn)) 4364 { 4365 /* We don't want to process FN again, so pretend we've written 4366 it out, even though we haven't. */ 4367 TREE_ASM_WRITTEN (fn) = 1; 4368 /* If this is a constexpr function, keep DECL_SAVED_TREE. */ 4369 if (!DECL_DECLARED_CONSTEXPR_P (fn)) 4370 DECL_SAVED_TREE (fn) = NULL_TREE; 4371 return false; 4372 } 4373 4374 /* There's no reason to do any of the work here if we're only doing 4375 semantic analysis; this code just generates RTL. */ 4376 if (flag_syntax_only) 4377 { 4378 /* Pretend that this function has been written out so that we don't try 4379 to expand it again. */ 4380 TREE_ASM_WRITTEN (fn) = 1; 4381 return false; 4382 } 4383 4384 if (DECL_OMP_DECLARE_REDUCTION_P (fn)) 4385 return false; 4386 4387 return true; 4388 } 4389 4390 void 4391 expand_or_defer_fn (tree fn) 4392 { 4393 if (expand_or_defer_fn_1 (fn)) 4394 { 4395 function_depth++; 4396 4397 /* Expand or defer, at the whim of the compilation unit manager. */ 4398 cgraph_node::finalize_function (fn, function_depth > 1); 4399 emit_associated_thunks (fn); 4400 4401 function_depth--; 4402 } 4403 } 4404 4405 struct nrv_data 4406 { 4407 nrv_data () : visited (37) {} 4408 4409 tree var; 4410 tree result; 4411 hash_table<nofree_ptr_hash <tree_node> > visited; 4412 }; 4413 4414 /* Helper function for walk_tree, used by finalize_nrv below. */ 4415 4416 static tree 4417 finalize_nrv_r (tree* tp, int* walk_subtrees, void* data) 4418 { 4419 struct nrv_data *dp = (struct nrv_data *)data; 4420 tree_node **slot; 4421 4422 /* No need to walk into types. There wouldn't be any need to walk into 4423 non-statements, except that we have to consider STMT_EXPRs. */ 4424 if (TYPE_P (*tp)) 4425 *walk_subtrees = 0; 4426 /* Change all returns to just refer to the RESULT_DECL; this is a nop, 4427 but differs from using NULL_TREE in that it indicates that we care 4428 about the value of the RESULT_DECL. */ 4429 else if (TREE_CODE (*tp) == RETURN_EXPR) 4430 TREE_OPERAND (*tp, 0) = dp->result; 4431 /* Change all cleanups for the NRV to only run when an exception is 4432 thrown. */ 4433 else if (TREE_CODE (*tp) == CLEANUP_STMT 4434 && CLEANUP_DECL (*tp) == dp->var) 4435 CLEANUP_EH_ONLY (*tp) = 1; 4436 /* Replace the DECL_EXPR for the NRV with an initialization of the 4437 RESULT_DECL, if needed. */ 4438 else if (TREE_CODE (*tp) == DECL_EXPR 4439 && DECL_EXPR_DECL (*tp) == dp->var) 4440 { 4441 tree init; 4442 if (DECL_INITIAL (dp->var) 4443 && DECL_INITIAL (dp->var) != error_mark_node) 4444 init = build2 (INIT_EXPR, void_type_node, dp->result, 4445 DECL_INITIAL (dp->var)); 4446 else 4447 init = build_empty_stmt (EXPR_LOCATION (*tp)); 4448 DECL_INITIAL (dp->var) = NULL_TREE; 4449 SET_EXPR_LOCATION (init, EXPR_LOCATION (*tp)); 4450 *tp = init; 4451 } 4452 /* And replace all uses of the NRV with the RESULT_DECL. */ 4453 else if (*tp == dp->var) 4454 *tp = dp->result; 4455 4456 /* Avoid walking into the same tree more than once. Unfortunately, we 4457 can't just use walk_tree_without duplicates because it would only call 4458 us for the first occurrence of dp->var in the function body. */ 4459 slot = dp->visited.find_slot (*tp, INSERT); 4460 if (*slot) 4461 *walk_subtrees = 0; 4462 else 4463 *slot = *tp; 4464 4465 /* Keep iterating. */ 4466 return NULL_TREE; 4467 } 4468 4469 /* Called from finish_function to implement the named return value 4470 optimization by overriding all the RETURN_EXPRs and pertinent 4471 CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the 4472 RESULT_DECL for the function. */ 4473 4474 void 4475 finalize_nrv (tree *tp, tree var, tree result) 4476 { 4477 struct nrv_data data; 4478 4479 /* Copy name from VAR to RESULT. */ 4480 DECL_NAME (result) = DECL_NAME (var); 4481 /* Don't forget that we take its address. */ 4482 TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var); 4483 /* Finally set DECL_VALUE_EXPR to avoid assigning 4484 a stack slot at -O0 for the original var and debug info 4485 uses RESULT location for VAR. */ 4486 SET_DECL_VALUE_EXPR (var, result); 4487 DECL_HAS_VALUE_EXPR_P (var) = 1; 4488 4489 data.var = var; 4490 data.result = result; 4491 cp_walk_tree (tp, finalize_nrv_r, &data, 0); 4492 } 4493 4494 /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */ 4495 4496 bool 4497 cxx_omp_create_clause_info (tree c, tree type, bool need_default_ctor, 4498 bool need_copy_ctor, bool need_copy_assignment, 4499 bool need_dtor) 4500 { 4501 int save_errorcount = errorcount; 4502 tree info, t; 4503 4504 /* Always allocate 3 elements for simplicity. These are the 4505 function decls for the ctor, dtor, and assignment op. 4506 This layout is known to the three lang hooks, 4507 cxx_omp_clause_default_init, cxx_omp_clause_copy_init, 4508 and cxx_omp_clause_assign_op. */ 4509 info = make_tree_vec (3); 4510 CP_OMP_CLAUSE_INFO (c) = info; 4511 4512 if (need_default_ctor || need_copy_ctor) 4513 { 4514 if (need_default_ctor) 4515 t = get_default_ctor (type); 4516 else 4517 t = get_copy_ctor (type, tf_warning_or_error); 4518 4519 if (t && !trivial_fn_p (t)) 4520 TREE_VEC_ELT (info, 0) = t; 4521 } 4522 4523 if (need_dtor && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)) 4524 TREE_VEC_ELT (info, 1) = get_dtor (type, tf_warning_or_error); 4525 4526 if (need_copy_assignment) 4527 { 4528 t = get_copy_assign (type); 4529 4530 if (t && !trivial_fn_p (t)) 4531 TREE_VEC_ELT (info, 2) = t; 4532 } 4533 4534 return errorcount != save_errorcount; 4535 } 4536 4537 /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding 4538 FIELD_DECL, otherwise return DECL itself. */ 4539 4540 static tree 4541 omp_clause_decl_field (tree decl) 4542 { 4543 if (VAR_P (decl) 4544 && DECL_HAS_VALUE_EXPR_P (decl) 4545 && DECL_ARTIFICIAL (decl) 4546 && DECL_LANG_SPECIFIC (decl) 4547 && DECL_OMP_PRIVATIZED_MEMBER (decl)) 4548 { 4549 tree f = DECL_VALUE_EXPR (decl); 4550 if (INDIRECT_REF_P (f)) 4551 f = TREE_OPERAND (f, 0); 4552 if (TREE_CODE (f) == COMPONENT_REF) 4553 { 4554 f = TREE_OPERAND (f, 1); 4555 gcc_assert (TREE_CODE (f) == FIELD_DECL); 4556 return f; 4557 } 4558 } 4559 return NULL_TREE; 4560 } 4561 4562 /* Adjust DECL if needed for printing using %qE. */ 4563 4564 static tree 4565 omp_clause_printable_decl (tree decl) 4566 { 4567 tree t = omp_clause_decl_field (decl); 4568 if (t) 4569 return t; 4570 return decl; 4571 } 4572 4573 /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER 4574 VAR_DECL T that doesn't need a DECL_EXPR added, record it for 4575 privatization. */ 4576 4577 static void 4578 omp_note_field_privatization (tree f, tree t) 4579 { 4580 if (!omp_private_member_map) 4581 omp_private_member_map = new hash_map<tree, tree>; 4582 tree &v = omp_private_member_map->get_or_insert (f); 4583 if (v == NULL_TREE) 4584 { 4585 v = t; 4586 omp_private_member_vec.safe_push (f); 4587 /* Signal that we don't want to create DECL_EXPR for this dummy var. */ 4588 omp_private_member_vec.safe_push (integer_zero_node); 4589 } 4590 } 4591 4592 /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER 4593 dummy VAR_DECL. */ 4594 4595 tree 4596 omp_privatize_field (tree t, bool shared) 4597 { 4598 tree m = finish_non_static_data_member (t, NULL_TREE, NULL_TREE); 4599 if (m == error_mark_node) 4600 return error_mark_node; 4601 if (!omp_private_member_map && !shared) 4602 omp_private_member_map = new hash_map<tree, tree>; 4603 if (TYPE_REF_P (TREE_TYPE (t))) 4604 { 4605 gcc_assert (INDIRECT_REF_P (m)); 4606 m = TREE_OPERAND (m, 0); 4607 } 4608 tree vb = NULL_TREE; 4609 tree &v = shared ? vb : omp_private_member_map->get_or_insert (t); 4610 if (v == NULL_TREE) 4611 { 4612 v = create_temporary_var (TREE_TYPE (m)); 4613 retrofit_lang_decl (v); 4614 DECL_OMP_PRIVATIZED_MEMBER (v) = 1; 4615 SET_DECL_VALUE_EXPR (v, m); 4616 DECL_HAS_VALUE_EXPR_P (v) = 1; 4617 if (!shared) 4618 omp_private_member_vec.safe_push (t); 4619 } 4620 return v; 4621 } 4622 4623 /* Helper function for handle_omp_array_sections. Called recursively 4624 to handle multiple array-section-subscripts. C is the clause, 4625 T current expression (initially OMP_CLAUSE_DECL), which is either 4626 a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound 4627 expression if specified, TREE_VALUE length expression if specified, 4628 TREE_CHAIN is what it has been specified after, or some decl. 4629 TYPES vector is populated with array section types, MAYBE_ZERO_LEN 4630 set to true if any of the array-section-subscript could have length 4631 of zero (explicit or implicit), FIRST_NON_ONE is the index of the 4632 first array-section-subscript which is known not to have length 4633 of one. Given say: 4634 map(a[:b][2:1][:c][:2][:d][e:f][2:5]) 4635 FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c] 4636 all are or may have length of 1, array-section-subscript [:2] is the 4637 first one known not to have length 1. For array-section-subscript 4638 <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't 4639 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we 4640 can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above 4641 case though, as some lengths could be zero. */ 4642 4643 static tree 4644 handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types, 4645 bool &maybe_zero_len, unsigned int &first_non_one, 4646 enum c_omp_region_type ort) 4647 { 4648 tree ret, low_bound, length, type; 4649 if (TREE_CODE (t) != TREE_LIST) 4650 { 4651 if (error_operand_p (t)) 4652 return error_mark_node; 4653 if (REFERENCE_REF_P (t) 4654 && TREE_CODE (TREE_OPERAND (t, 0)) == COMPONENT_REF) 4655 t = TREE_OPERAND (t, 0); 4656 ret = t; 4657 if (TREE_CODE (t) == COMPONENT_REF 4658 && ort == C_ORT_OMP 4659 && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP 4660 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO 4661 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM) 4662 && !type_dependent_expression_p (t)) 4663 { 4664 if (TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL 4665 && DECL_BIT_FIELD (TREE_OPERAND (t, 1))) 4666 { 4667 error_at (OMP_CLAUSE_LOCATION (c), 4668 "bit-field %qE in %qs clause", 4669 t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 4670 return error_mark_node; 4671 } 4672 while (TREE_CODE (t) == COMPONENT_REF) 4673 { 4674 if (TREE_TYPE (TREE_OPERAND (t, 0)) 4675 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == UNION_TYPE) 4676 { 4677 error_at (OMP_CLAUSE_LOCATION (c), 4678 "%qE is a member of a union", t); 4679 return error_mark_node; 4680 } 4681 t = TREE_OPERAND (t, 0); 4682 } 4683 if (REFERENCE_REF_P (t)) 4684 t = TREE_OPERAND (t, 0); 4685 } 4686 if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) 4687 { 4688 if (processing_template_decl && TREE_CODE (t) != OVERLOAD) 4689 return NULL_TREE; 4690 if (DECL_P (t)) 4691 error_at (OMP_CLAUSE_LOCATION (c), 4692 "%qD is not a variable in %qs clause", t, 4693 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 4694 else 4695 error_at (OMP_CLAUSE_LOCATION (c), 4696 "%qE is not a variable in %qs clause", t, 4697 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 4698 return error_mark_node; 4699 } 4700 else if (ort == C_ORT_OMP 4701 && TREE_CODE (t) == PARM_DECL 4702 && DECL_ARTIFICIAL (t) 4703 && DECL_NAME (t) == this_identifier) 4704 { 4705 error_at (OMP_CLAUSE_LOCATION (c), 4706 "%<this%> allowed in OpenMP only in %<declare simd%>" 4707 " clauses"); 4708 return error_mark_node; 4709 } 4710 else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND 4711 && VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t)) 4712 { 4713 error_at (OMP_CLAUSE_LOCATION (c), 4714 "%qD is threadprivate variable in %qs clause", t, 4715 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 4716 return error_mark_node; 4717 } 4718 if (type_dependent_expression_p (ret)) 4719 return NULL_TREE; 4720 ret = convert_from_reference (ret); 4721 return ret; 4722 } 4723 4724 if (ort == C_ORT_OMP 4725 && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION 4726 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION 4727 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) 4728 && TREE_CODE (TREE_CHAIN (t)) == FIELD_DECL) 4729 TREE_CHAIN (t) = omp_privatize_field (TREE_CHAIN (t), false); 4730 ret = handle_omp_array_sections_1 (c, TREE_CHAIN (t), types, 4731 maybe_zero_len, first_non_one, ort); 4732 if (ret == error_mark_node || ret == NULL_TREE) 4733 return ret; 4734 4735 type = TREE_TYPE (ret); 4736 low_bound = TREE_PURPOSE (t); 4737 length = TREE_VALUE (t); 4738 if ((low_bound && type_dependent_expression_p (low_bound)) 4739 || (length && type_dependent_expression_p (length))) 4740 return NULL_TREE; 4741 4742 if (low_bound == error_mark_node || length == error_mark_node) 4743 return error_mark_node; 4744 4745 if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound))) 4746 { 4747 error_at (OMP_CLAUSE_LOCATION (c), 4748 "low bound %qE of array section does not have integral type", 4749 low_bound); 4750 return error_mark_node; 4751 } 4752 if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length))) 4753 { 4754 error_at (OMP_CLAUSE_LOCATION (c), 4755 "length %qE of array section does not have integral type", 4756 length); 4757 return error_mark_node; 4758 } 4759 if (low_bound) 4760 low_bound = mark_rvalue_use (low_bound); 4761 if (length) 4762 length = mark_rvalue_use (length); 4763 /* We need to reduce to real constant-values for checks below. */ 4764 if (length) 4765 length = fold_simple (length); 4766 if (low_bound) 4767 low_bound = fold_simple (low_bound); 4768 if (low_bound 4769 && TREE_CODE (low_bound) == INTEGER_CST 4770 && TYPE_PRECISION (TREE_TYPE (low_bound)) 4771 > TYPE_PRECISION (sizetype)) 4772 low_bound = fold_convert (sizetype, low_bound); 4773 if (length 4774 && TREE_CODE (length) == INTEGER_CST 4775 && TYPE_PRECISION (TREE_TYPE (length)) 4776 > TYPE_PRECISION (sizetype)) 4777 length = fold_convert (sizetype, length); 4778 if (low_bound == NULL_TREE) 4779 low_bound = integer_zero_node; 4780 4781 if (length != NULL_TREE) 4782 { 4783 if (!integer_nonzerop (length)) 4784 { 4785 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND 4786 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION 4787 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION 4788 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) 4789 { 4790 if (integer_zerop (length)) 4791 { 4792 error_at (OMP_CLAUSE_LOCATION (c), 4793 "zero length array section in %qs clause", 4794 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 4795 return error_mark_node; 4796 } 4797 } 4798 else 4799 maybe_zero_len = true; 4800 } 4801 if (first_non_one == types.length () 4802 && (TREE_CODE (length) != INTEGER_CST || integer_onep (length))) 4803 first_non_one++; 4804 } 4805 if (TREE_CODE (type) == ARRAY_TYPE) 4806 { 4807 if (length == NULL_TREE 4808 && (TYPE_DOMAIN (type) == NULL_TREE 4809 || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE)) 4810 { 4811 error_at (OMP_CLAUSE_LOCATION (c), 4812 "for unknown bound array type length expression must " 4813 "be specified"); 4814 return error_mark_node; 4815 } 4816 if (TREE_CODE (low_bound) == INTEGER_CST 4817 && tree_int_cst_sgn (low_bound) == -1) 4818 { 4819 error_at (OMP_CLAUSE_LOCATION (c), 4820 "negative low bound in array section in %qs clause", 4821 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 4822 return error_mark_node; 4823 } 4824 if (length != NULL_TREE 4825 && TREE_CODE (length) == INTEGER_CST 4826 && tree_int_cst_sgn (length) == -1) 4827 { 4828 error_at (OMP_CLAUSE_LOCATION (c), 4829 "negative length in array section in %qs clause", 4830 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 4831 return error_mark_node; 4832 } 4833 if (TYPE_DOMAIN (type) 4834 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) 4835 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) 4836 == INTEGER_CST) 4837 { 4838 tree size 4839 = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type))); 4840 size = size_binop (PLUS_EXPR, size, size_one_node); 4841 if (TREE_CODE (low_bound) == INTEGER_CST) 4842 { 4843 if (tree_int_cst_lt (size, low_bound)) 4844 { 4845 error_at (OMP_CLAUSE_LOCATION (c), 4846 "low bound %qE above array section size " 4847 "in %qs clause", low_bound, 4848 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 4849 return error_mark_node; 4850 } 4851 if (tree_int_cst_equal (size, low_bound)) 4852 { 4853 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND 4854 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION 4855 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION 4856 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) 4857 { 4858 error_at (OMP_CLAUSE_LOCATION (c), 4859 "zero length array section in %qs clause", 4860 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 4861 return error_mark_node; 4862 } 4863 maybe_zero_len = true; 4864 } 4865 else if (length == NULL_TREE 4866 && first_non_one == types.length () 4867 && tree_int_cst_equal 4868 (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 4869 low_bound)) 4870 first_non_one++; 4871 } 4872 else if (length == NULL_TREE) 4873 { 4874 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND 4875 && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION 4876 && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION 4877 && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION) 4878 maybe_zero_len = true; 4879 if (first_non_one == types.length ()) 4880 first_non_one++; 4881 } 4882 if (length && TREE_CODE (length) == INTEGER_CST) 4883 { 4884 if (tree_int_cst_lt (size, length)) 4885 { 4886 error_at (OMP_CLAUSE_LOCATION (c), 4887 "length %qE above array section size " 4888 "in %qs clause", length, 4889 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 4890 return error_mark_node; 4891 } 4892 if (TREE_CODE (low_bound) == INTEGER_CST) 4893 { 4894 tree lbpluslen 4895 = size_binop (PLUS_EXPR, 4896 fold_convert (sizetype, low_bound), 4897 fold_convert (sizetype, length)); 4898 if (TREE_CODE (lbpluslen) == INTEGER_CST 4899 && tree_int_cst_lt (size, lbpluslen)) 4900 { 4901 error_at (OMP_CLAUSE_LOCATION (c), 4902 "high bound %qE above array section size " 4903 "in %qs clause", lbpluslen, 4904 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 4905 return error_mark_node; 4906 } 4907 } 4908 } 4909 } 4910 else if (length == NULL_TREE) 4911 { 4912 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND 4913 && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION 4914 && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION 4915 && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION) 4916 maybe_zero_len = true; 4917 if (first_non_one == types.length ()) 4918 first_non_one++; 4919 } 4920 4921 /* For [lb:] we will need to evaluate lb more than once. */ 4922 if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND) 4923 { 4924 tree lb = cp_save_expr (low_bound); 4925 if (lb != low_bound) 4926 { 4927 TREE_PURPOSE (t) = lb; 4928 low_bound = lb; 4929 } 4930 } 4931 } 4932 else if (TYPE_PTR_P (type)) 4933 { 4934 if (length == NULL_TREE) 4935 { 4936 error_at (OMP_CLAUSE_LOCATION (c), 4937 "for pointer type length expression must be specified"); 4938 return error_mark_node; 4939 } 4940 if (length != NULL_TREE 4941 && TREE_CODE (length) == INTEGER_CST 4942 && tree_int_cst_sgn (length) == -1) 4943 { 4944 error_at (OMP_CLAUSE_LOCATION (c), 4945 "negative length in array section in %qs clause", 4946 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 4947 return error_mark_node; 4948 } 4949 /* If there is a pointer type anywhere but in the very first 4950 array-section-subscript, the array section can't be contiguous. */ 4951 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND 4952 && TREE_CODE (TREE_CHAIN (t)) == TREE_LIST) 4953 { 4954 error_at (OMP_CLAUSE_LOCATION (c), 4955 "array section is not contiguous in %qs clause", 4956 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 4957 return error_mark_node; 4958 } 4959 } 4960 else 4961 { 4962 error_at (OMP_CLAUSE_LOCATION (c), 4963 "%qE does not have pointer or array type", ret); 4964 return error_mark_node; 4965 } 4966 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND) 4967 types.safe_push (TREE_TYPE (ret)); 4968 /* We will need to evaluate lb more than once. */ 4969 tree lb = cp_save_expr (low_bound); 4970 if (lb != low_bound) 4971 { 4972 TREE_PURPOSE (t) = lb; 4973 low_bound = lb; 4974 } 4975 ret = grok_array_decl (OMP_CLAUSE_LOCATION (c), ret, low_bound, false); 4976 return ret; 4977 } 4978 4979 /* Handle array sections for clause C. */ 4980 4981 static bool 4982 handle_omp_array_sections (tree c, enum c_omp_region_type ort) 4983 { 4984 bool maybe_zero_len = false; 4985 unsigned int first_non_one = 0; 4986 auto_vec<tree, 10> types; 4987 tree *tp = &OMP_CLAUSE_DECL (c); 4988 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND 4989 && TREE_CODE (*tp) == TREE_LIST 4990 && TREE_PURPOSE (*tp) 4991 && TREE_CODE (TREE_PURPOSE (*tp)) == TREE_VEC) 4992 tp = &TREE_VALUE (*tp); 4993 tree first = handle_omp_array_sections_1 (c, *tp, types, 4994 maybe_zero_len, first_non_one, 4995 ort); 4996 if (first == error_mark_node) 4997 return true; 4998 if (first == NULL_TREE) 4999 return false; 5000 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND) 5001 { 5002 tree t = *tp; 5003 tree tem = NULL_TREE; 5004 if (processing_template_decl) 5005 return false; 5006 /* Need to evaluate side effects in the length expressions 5007 if any. */ 5008 while (TREE_CODE (t) == TREE_LIST) 5009 { 5010 if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t))) 5011 { 5012 if (tem == NULL_TREE) 5013 tem = TREE_VALUE (t); 5014 else 5015 tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem), 5016 TREE_VALUE (t), tem); 5017 } 5018 t = TREE_CHAIN (t); 5019 } 5020 if (tem) 5021 first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first); 5022 *tp = first; 5023 } 5024 else 5025 { 5026 unsigned int num = types.length (), i; 5027 tree t, side_effects = NULL_TREE, size = NULL_TREE; 5028 tree condition = NULL_TREE; 5029 5030 if (int_size_in_bytes (TREE_TYPE (first)) <= 0) 5031 maybe_zero_len = true; 5032 if (processing_template_decl && maybe_zero_len) 5033 return false; 5034 5035 for (i = num, t = OMP_CLAUSE_DECL (c); i > 0; 5036 t = TREE_CHAIN (t)) 5037 { 5038 tree low_bound = TREE_PURPOSE (t); 5039 tree length = TREE_VALUE (t); 5040 5041 i--; 5042 if (low_bound 5043 && TREE_CODE (low_bound) == INTEGER_CST 5044 && TYPE_PRECISION (TREE_TYPE (low_bound)) 5045 > TYPE_PRECISION (sizetype)) 5046 low_bound = fold_convert (sizetype, low_bound); 5047 if (length 5048 && TREE_CODE (length) == INTEGER_CST 5049 && TYPE_PRECISION (TREE_TYPE (length)) 5050 > TYPE_PRECISION (sizetype)) 5051 length = fold_convert (sizetype, length); 5052 if (low_bound == NULL_TREE) 5053 low_bound = integer_zero_node; 5054 if (!maybe_zero_len && i > first_non_one) 5055 { 5056 if (integer_nonzerop (low_bound)) 5057 goto do_warn_noncontiguous; 5058 if (length != NULL_TREE 5059 && TREE_CODE (length) == INTEGER_CST 5060 && TYPE_DOMAIN (types[i]) 5061 && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])) 5062 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))) 5063 == INTEGER_CST) 5064 { 5065 tree size; 5066 size = size_binop (PLUS_EXPR, 5067 TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])), 5068 size_one_node); 5069 if (!tree_int_cst_equal (length, size)) 5070 { 5071 do_warn_noncontiguous: 5072 error_at (OMP_CLAUSE_LOCATION (c), 5073 "array section is not contiguous in %qs " 5074 "clause", 5075 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 5076 return true; 5077 } 5078 } 5079 if (!processing_template_decl 5080 && length != NULL_TREE 5081 && TREE_SIDE_EFFECTS (length)) 5082 { 5083 if (side_effects == NULL_TREE) 5084 side_effects = length; 5085 else 5086 side_effects = build2 (COMPOUND_EXPR, 5087 TREE_TYPE (side_effects), 5088 length, side_effects); 5089 } 5090 } 5091 else if (processing_template_decl) 5092 continue; 5093 else 5094 { 5095 tree l; 5096 5097 if (i > first_non_one 5098 && ((length && integer_nonzerop (length)) 5099 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION 5100 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION 5101 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)) 5102 continue; 5103 if (length) 5104 l = fold_convert (sizetype, length); 5105 else 5106 { 5107 l = size_binop (PLUS_EXPR, 5108 TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])), 5109 size_one_node); 5110 l = size_binop (MINUS_EXPR, l, 5111 fold_convert (sizetype, low_bound)); 5112 } 5113 if (i > first_non_one) 5114 { 5115 l = fold_build2 (NE_EXPR, boolean_type_node, l, 5116 size_zero_node); 5117 if (condition == NULL_TREE) 5118 condition = l; 5119 else 5120 condition = fold_build2 (BIT_AND_EXPR, boolean_type_node, 5121 l, condition); 5122 } 5123 else if (size == NULL_TREE) 5124 { 5125 size = size_in_bytes (TREE_TYPE (types[i])); 5126 tree eltype = TREE_TYPE (types[num - 1]); 5127 while (TREE_CODE (eltype) == ARRAY_TYPE) 5128 eltype = TREE_TYPE (eltype); 5129 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION 5130 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION 5131 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) 5132 size = size_binop (EXACT_DIV_EXPR, size, 5133 size_in_bytes (eltype)); 5134 size = size_binop (MULT_EXPR, size, l); 5135 if (condition) 5136 size = fold_build3 (COND_EXPR, sizetype, condition, 5137 size, size_zero_node); 5138 } 5139 else 5140 size = size_binop (MULT_EXPR, size, l); 5141 } 5142 } 5143 if (!processing_template_decl) 5144 { 5145 if (side_effects) 5146 size = build2 (COMPOUND_EXPR, sizetype, side_effects, size); 5147 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION 5148 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION 5149 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) 5150 { 5151 size = size_binop (MINUS_EXPR, size, size_one_node); 5152 size = save_expr (size); 5153 tree index_type = build_index_type (size); 5154 tree eltype = TREE_TYPE (first); 5155 while (TREE_CODE (eltype) == ARRAY_TYPE) 5156 eltype = TREE_TYPE (eltype); 5157 tree type = build_array_type (eltype, index_type); 5158 tree ptype = build_pointer_type (eltype); 5159 if (TYPE_REF_P (TREE_TYPE (t)) 5160 && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t)))) 5161 t = convert_from_reference (t); 5162 else if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) 5163 t = build_fold_addr_expr (t); 5164 tree t2 = build_fold_addr_expr (first); 5165 t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c), 5166 ptrdiff_type_node, t2); 5167 t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR, 5168 ptrdiff_type_node, t2, 5169 fold_convert_loc (OMP_CLAUSE_LOCATION (c), 5170 ptrdiff_type_node, t)); 5171 if (tree_fits_shwi_p (t2)) 5172 t = build2 (MEM_REF, type, t, 5173 build_int_cst (ptype, tree_to_shwi (t2))); 5174 else 5175 { 5176 t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c), 5177 sizetype, t2); 5178 t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR, 5179 TREE_TYPE (t), t, t2); 5180 t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0)); 5181 } 5182 OMP_CLAUSE_DECL (c) = t; 5183 return false; 5184 } 5185 OMP_CLAUSE_DECL (c) = first; 5186 OMP_CLAUSE_SIZE (c) = size; 5187 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP 5188 || (TREE_CODE (t) == COMPONENT_REF 5189 && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)) 5190 return false; 5191 if (ort == C_ORT_OMP || ort == C_ORT_ACC) 5192 switch (OMP_CLAUSE_MAP_KIND (c)) 5193 { 5194 case GOMP_MAP_ALLOC: 5195 case GOMP_MAP_TO: 5196 case GOMP_MAP_FROM: 5197 case GOMP_MAP_TOFROM: 5198 case GOMP_MAP_ALWAYS_TO: 5199 case GOMP_MAP_ALWAYS_FROM: 5200 case GOMP_MAP_ALWAYS_TOFROM: 5201 case GOMP_MAP_RELEASE: 5202 case GOMP_MAP_DELETE: 5203 case GOMP_MAP_FORCE_TO: 5204 case GOMP_MAP_FORCE_FROM: 5205 case GOMP_MAP_FORCE_TOFROM: 5206 case GOMP_MAP_FORCE_PRESENT: 5207 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1; 5208 break; 5209 default: 5210 break; 5211 } 5212 tree c2 = build_omp_clause (OMP_CLAUSE_LOCATION (c), 5213 OMP_CLAUSE_MAP); 5214 if ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP && ort != C_ORT_ACC) 5215 OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_POINTER); 5216 else if (TREE_CODE (t) == COMPONENT_REF) 5217 OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ALWAYS_POINTER); 5218 else if (REFERENCE_REF_P (t) 5219 && TREE_CODE (TREE_OPERAND (t, 0)) == COMPONENT_REF) 5220 { 5221 t = TREE_OPERAND (t, 0); 5222 OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ALWAYS_POINTER); 5223 } 5224 else 5225 OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER); 5226 if (OMP_CLAUSE_MAP_KIND (c2) != GOMP_MAP_FIRSTPRIVATE_POINTER 5227 && !cxx_mark_addressable (t)) 5228 return false; 5229 OMP_CLAUSE_DECL (c2) = t; 5230 t = build_fold_addr_expr (first); 5231 t = fold_convert_loc (OMP_CLAUSE_LOCATION (c), 5232 ptrdiff_type_node, t); 5233 tree ptr = OMP_CLAUSE_DECL (c2); 5234 ptr = convert_from_reference (ptr); 5235 if (!INDIRECT_TYPE_P (TREE_TYPE (ptr))) 5236 ptr = build_fold_addr_expr (ptr); 5237 t = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR, 5238 ptrdiff_type_node, t, 5239 fold_convert_loc (OMP_CLAUSE_LOCATION (c), 5240 ptrdiff_type_node, ptr)); 5241 OMP_CLAUSE_SIZE (c2) = t; 5242 OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (c); 5243 OMP_CLAUSE_CHAIN (c) = c2; 5244 ptr = OMP_CLAUSE_DECL (c2); 5245 if (OMP_CLAUSE_MAP_KIND (c2) != GOMP_MAP_FIRSTPRIVATE_POINTER 5246 && TYPE_REF_P (TREE_TYPE (ptr)) 5247 && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (ptr)))) 5248 { 5249 tree c3 = build_omp_clause (OMP_CLAUSE_LOCATION (c), 5250 OMP_CLAUSE_MAP); 5251 OMP_CLAUSE_SET_MAP_KIND (c3, OMP_CLAUSE_MAP_KIND (c2)); 5252 OMP_CLAUSE_DECL (c3) = ptr; 5253 if (OMP_CLAUSE_MAP_KIND (c2) == GOMP_MAP_ALWAYS_POINTER) 5254 OMP_CLAUSE_DECL (c2) = build_simple_mem_ref (ptr); 5255 else 5256 OMP_CLAUSE_DECL (c2) = convert_from_reference (ptr); 5257 OMP_CLAUSE_SIZE (c3) = size_zero_node; 5258 OMP_CLAUSE_CHAIN (c3) = OMP_CLAUSE_CHAIN (c2); 5259 OMP_CLAUSE_CHAIN (c2) = c3; 5260 } 5261 } 5262 } 5263 return false; 5264 } 5265 5266 /* Return identifier to look up for omp declare reduction. */ 5267 5268 tree 5269 omp_reduction_id (enum tree_code reduction_code, tree reduction_id, tree type) 5270 { 5271 const char *p = NULL; 5272 const char *m = NULL; 5273 switch (reduction_code) 5274 { 5275 case PLUS_EXPR: 5276 case MULT_EXPR: 5277 case MINUS_EXPR: 5278 case BIT_AND_EXPR: 5279 case BIT_XOR_EXPR: 5280 case BIT_IOR_EXPR: 5281 case TRUTH_ANDIF_EXPR: 5282 case TRUTH_ORIF_EXPR: 5283 reduction_id = ovl_op_identifier (false, reduction_code); 5284 break; 5285 case MIN_EXPR: 5286 p = "min"; 5287 break; 5288 case MAX_EXPR: 5289 p = "max"; 5290 break; 5291 default: 5292 break; 5293 } 5294 5295 if (p == NULL) 5296 { 5297 if (TREE_CODE (reduction_id) != IDENTIFIER_NODE) 5298 return error_mark_node; 5299 p = IDENTIFIER_POINTER (reduction_id); 5300 } 5301 5302 if (type != NULL_TREE) 5303 m = mangle_type_string (TYPE_MAIN_VARIANT (type)); 5304 5305 const char prefix[] = "omp declare reduction "; 5306 size_t lenp = sizeof (prefix); 5307 if (strncmp (p, prefix, lenp - 1) == 0) 5308 lenp = 1; 5309 size_t len = strlen (p); 5310 size_t lenm = m ? strlen (m) + 1 : 0; 5311 char *name = XALLOCAVEC (char, lenp + len + lenm); 5312 if (lenp > 1) 5313 memcpy (name, prefix, lenp - 1); 5314 memcpy (name + lenp - 1, p, len + 1); 5315 if (m) 5316 { 5317 name[lenp + len - 1] = '~'; 5318 memcpy (name + lenp + len, m, lenm); 5319 } 5320 return get_identifier (name); 5321 } 5322 5323 /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial 5324 FUNCTION_DECL or NULL_TREE if not found. */ 5325 5326 static tree 5327 omp_reduction_lookup (location_t loc, tree id, tree type, tree *baselinkp, 5328 vec<tree> *ambiguousp) 5329 { 5330 tree orig_id = id; 5331 tree baselink = NULL_TREE; 5332 if (identifier_p (id)) 5333 { 5334 cp_id_kind idk; 5335 bool nonint_cst_expression_p; 5336 const char *error_msg; 5337 id = omp_reduction_id (ERROR_MARK, id, type); 5338 tree decl = lookup_name (id); 5339 if (decl == NULL_TREE) 5340 decl = error_mark_node; 5341 id = finish_id_expression (id, decl, NULL_TREE, &idk, false, true, 5342 &nonint_cst_expression_p, false, true, false, 5343 false, &error_msg, loc); 5344 if (idk == CP_ID_KIND_UNQUALIFIED 5345 && identifier_p (id)) 5346 { 5347 vec<tree, va_gc> *args = NULL; 5348 vec_safe_push (args, build_reference_type (type)); 5349 id = perform_koenig_lookup (id, args, tf_none); 5350 } 5351 } 5352 else if (TREE_CODE (id) == SCOPE_REF) 5353 id = lookup_qualified_name (TREE_OPERAND (id, 0), 5354 omp_reduction_id (ERROR_MARK, 5355 TREE_OPERAND (id, 1), 5356 type), 5357 false, false); 5358 tree fns = id; 5359 id = NULL_TREE; 5360 if (fns && is_overloaded_fn (fns)) 5361 { 5362 for (lkp_iterator iter (get_fns (fns)); iter; ++iter) 5363 { 5364 tree fndecl = *iter; 5365 if (TREE_CODE (fndecl) == FUNCTION_DECL) 5366 { 5367 tree argtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl))); 5368 if (same_type_p (TREE_TYPE (argtype), type)) 5369 { 5370 id = fndecl; 5371 break; 5372 } 5373 } 5374 } 5375 5376 if (id && BASELINK_P (fns)) 5377 { 5378 if (baselinkp) 5379 *baselinkp = fns; 5380 else 5381 baselink = fns; 5382 } 5383 } 5384 5385 if (!id && CLASS_TYPE_P (type) && TYPE_BINFO (type)) 5386 { 5387 vec<tree> ambiguous = vNULL; 5388 tree binfo = TYPE_BINFO (type), base_binfo, ret = NULL_TREE; 5389 unsigned int ix; 5390 if (ambiguousp == NULL) 5391 ambiguousp = &ambiguous; 5392 for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++) 5393 { 5394 id = omp_reduction_lookup (loc, orig_id, BINFO_TYPE (base_binfo), 5395 baselinkp ? baselinkp : &baselink, 5396 ambiguousp); 5397 if (id == NULL_TREE) 5398 continue; 5399 if (!ambiguousp->is_empty ()) 5400 ambiguousp->safe_push (id); 5401 else if (ret != NULL_TREE) 5402 { 5403 ambiguousp->safe_push (ret); 5404 ambiguousp->safe_push (id); 5405 ret = NULL_TREE; 5406 } 5407 else 5408 ret = id; 5409 } 5410 if (ambiguousp != &ambiguous) 5411 return ret; 5412 if (!ambiguous.is_empty ()) 5413 { 5414 const char *str = _("candidates are:"); 5415 unsigned int idx; 5416 tree udr; 5417 error_at (loc, "user defined reduction lookup is ambiguous"); 5418 FOR_EACH_VEC_ELT (ambiguous, idx, udr) 5419 { 5420 inform (DECL_SOURCE_LOCATION (udr), "%s %#qD", str, udr); 5421 if (idx == 0) 5422 str = get_spaces (str); 5423 } 5424 ambiguous.release (); 5425 ret = error_mark_node; 5426 baselink = NULL_TREE; 5427 } 5428 id = ret; 5429 } 5430 if (id && baselink) 5431 perform_or_defer_access_check (BASELINK_BINFO (baselink), 5432 id, id, tf_warning_or_error); 5433 return id; 5434 } 5435 5436 /* Helper function for cp_parser_omp_declare_reduction_exprs 5437 and tsubst_omp_udr. 5438 Remove CLEANUP_STMT for data (omp_priv variable). 5439 Also append INIT_EXPR for DECL_INITIAL of omp_priv after its 5440 DECL_EXPR. */ 5441 5442 tree 5443 cp_remove_omp_priv_cleanup_stmt (tree *tp, int *walk_subtrees, void *data) 5444 { 5445 if (TYPE_P (*tp)) 5446 *walk_subtrees = 0; 5447 else if (TREE_CODE (*tp) == CLEANUP_STMT && CLEANUP_DECL (*tp) == (tree) data) 5448 *tp = CLEANUP_BODY (*tp); 5449 else if (TREE_CODE (*tp) == DECL_EXPR) 5450 { 5451 tree decl = DECL_EXPR_DECL (*tp); 5452 if (!processing_template_decl 5453 && decl == (tree) data 5454 && DECL_INITIAL (decl) 5455 && DECL_INITIAL (decl) != error_mark_node) 5456 { 5457 tree list = NULL_TREE; 5458 append_to_statement_list_force (*tp, &list); 5459 tree init_expr = build2 (INIT_EXPR, void_type_node, 5460 decl, DECL_INITIAL (decl)); 5461 DECL_INITIAL (decl) = NULL_TREE; 5462 append_to_statement_list_force (init_expr, &list); 5463 *tp = list; 5464 } 5465 } 5466 return NULL_TREE; 5467 } 5468 5469 /* Data passed from cp_check_omp_declare_reduction to 5470 cp_check_omp_declare_reduction_r. */ 5471 5472 struct cp_check_omp_declare_reduction_data 5473 { 5474 location_t loc; 5475 tree stmts[7]; 5476 bool combiner_p; 5477 }; 5478 5479 /* Helper function for cp_check_omp_declare_reduction, called via 5480 cp_walk_tree. */ 5481 5482 static tree 5483 cp_check_omp_declare_reduction_r (tree *tp, int *, void *data) 5484 { 5485 struct cp_check_omp_declare_reduction_data *udr_data 5486 = (struct cp_check_omp_declare_reduction_data *) data; 5487 if (SSA_VAR_P (*tp) 5488 && !DECL_ARTIFICIAL (*tp) 5489 && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 0 : 3]) 5490 && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 1 : 4])) 5491 { 5492 location_t loc = udr_data->loc; 5493 if (udr_data->combiner_p) 5494 error_at (loc, "%<#pragma omp declare reduction%> combiner refers to " 5495 "variable %qD which is not %<omp_out%> nor %<omp_in%>", 5496 *tp); 5497 else 5498 error_at (loc, "%<#pragma omp declare reduction%> initializer refers " 5499 "to variable %qD which is not %<omp_priv%> nor " 5500 "%<omp_orig%>", 5501 *tp); 5502 return *tp; 5503 } 5504 return NULL_TREE; 5505 } 5506 5507 /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */ 5508 5509 void 5510 cp_check_omp_declare_reduction (tree udr) 5511 { 5512 tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr))); 5513 gcc_assert (TYPE_REF_P (type)); 5514 type = TREE_TYPE (type); 5515 int i; 5516 location_t loc = DECL_SOURCE_LOCATION (udr); 5517 5518 if (type == error_mark_node) 5519 return; 5520 if (ARITHMETIC_TYPE_P (type)) 5521 { 5522 static enum tree_code predef_codes[] 5523 = { PLUS_EXPR, MULT_EXPR, MINUS_EXPR, BIT_AND_EXPR, BIT_XOR_EXPR, 5524 BIT_IOR_EXPR, TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR }; 5525 for (i = 0; i < 8; i++) 5526 { 5527 tree id = omp_reduction_id (predef_codes[i], NULL_TREE, NULL_TREE); 5528 const char *n1 = IDENTIFIER_POINTER (DECL_NAME (udr)); 5529 const char *n2 = IDENTIFIER_POINTER (id); 5530 if (strncmp (n1, n2, IDENTIFIER_LENGTH (id)) == 0 5531 && (n1[IDENTIFIER_LENGTH (id)] == '~' 5532 || n1[IDENTIFIER_LENGTH (id)] == '\0')) 5533 break; 5534 } 5535 5536 if (i == 8 5537 && TREE_CODE (type) != COMPLEX_EXPR) 5538 { 5539 const char prefix_minmax[] = "omp declare reduction m"; 5540 size_t prefix_size = sizeof (prefix_minmax) - 1; 5541 const char *n = IDENTIFIER_POINTER (DECL_NAME (udr)); 5542 if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr)), 5543 prefix_minmax, prefix_size) == 0 5544 && ((n[prefix_size] == 'i' && n[prefix_size + 1] == 'n') 5545 || (n[prefix_size] == 'a' && n[prefix_size + 1] == 'x')) 5546 && (n[prefix_size + 2] == '~' || n[prefix_size + 2] == '\0')) 5547 i = 0; 5548 } 5549 if (i < 8) 5550 { 5551 error_at (loc, "predeclared arithmetic type %qT in " 5552 "%<#pragma omp declare reduction%>", type); 5553 return; 5554 } 5555 } 5556 else if (TREE_CODE (type) == FUNCTION_TYPE 5557 || TREE_CODE (type) == METHOD_TYPE 5558 || TREE_CODE (type) == ARRAY_TYPE) 5559 { 5560 error_at (loc, "function or array type %qT in " 5561 "%<#pragma omp declare reduction%>", type); 5562 return; 5563 } 5564 else if (TYPE_REF_P (type)) 5565 { 5566 error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>", 5567 type); 5568 return; 5569 } 5570 else if (TYPE_QUALS_NO_ADDR_SPACE (type)) 5571 { 5572 error_at (loc, "const, volatile or __restrict qualified type %qT in " 5573 "%<#pragma omp declare reduction%>", type); 5574 return; 5575 } 5576 5577 tree body = DECL_SAVED_TREE (udr); 5578 if (body == NULL_TREE || TREE_CODE (body) != STATEMENT_LIST) 5579 return; 5580 5581 tree_stmt_iterator tsi; 5582 struct cp_check_omp_declare_reduction_data data; 5583 memset (data.stmts, 0, sizeof data.stmts); 5584 for (i = 0, tsi = tsi_start (body); 5585 i < 7 && !tsi_end_p (tsi); 5586 i++, tsi_next (&tsi)) 5587 data.stmts[i] = tsi_stmt (tsi); 5588 data.loc = loc; 5589 gcc_assert (tsi_end_p (tsi)); 5590 if (i >= 3) 5591 { 5592 gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR 5593 && TREE_CODE (data.stmts[1]) == DECL_EXPR); 5594 if (TREE_NO_WARNING (DECL_EXPR_DECL (data.stmts[0]))) 5595 return; 5596 data.combiner_p = true; 5597 if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r, 5598 &data, NULL)) 5599 TREE_NO_WARNING (DECL_EXPR_DECL (data.stmts[0])) = 1; 5600 } 5601 if (i >= 6) 5602 { 5603 gcc_assert (TREE_CODE (data.stmts[3]) == DECL_EXPR 5604 && TREE_CODE (data.stmts[4]) == DECL_EXPR); 5605 data.combiner_p = false; 5606 if (cp_walk_tree (&data.stmts[5], cp_check_omp_declare_reduction_r, 5607 &data, NULL) 5608 || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])), 5609 cp_check_omp_declare_reduction_r, &data, NULL)) 5610 TREE_NO_WARNING (DECL_EXPR_DECL (data.stmts[0])) = 1; 5611 if (i == 7) 5612 gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR); 5613 } 5614 } 5615 5616 /* Helper function of finish_omp_clauses. Clone STMT as if we were making 5617 an inline call. But, remap 5618 the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER 5619 and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */ 5620 5621 static tree 5622 clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2, 5623 tree decl, tree placeholder) 5624 { 5625 copy_body_data id; 5626 hash_map<tree, tree> decl_map; 5627 5628 decl_map.put (omp_decl1, placeholder); 5629 decl_map.put (omp_decl2, decl); 5630 memset (&id, 0, sizeof (id)); 5631 id.src_fn = DECL_CONTEXT (omp_decl1); 5632 id.dst_fn = current_function_decl; 5633 id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn); 5634 id.decl_map = &decl_map; 5635 5636 id.copy_decl = copy_decl_no_change; 5637 id.transform_call_graph_edges = CB_CGE_DUPLICATE; 5638 id.transform_new_cfg = true; 5639 id.transform_return_to_modify = false; 5640 id.transform_lang_insert_block = NULL; 5641 id.eh_lp_nr = 0; 5642 walk_tree (&stmt, copy_tree_body_r, &id, NULL); 5643 return stmt; 5644 } 5645 5646 /* Helper function of finish_omp_clauses, called via cp_walk_tree. 5647 Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */ 5648 5649 static tree 5650 find_omp_placeholder_r (tree *tp, int *, void *data) 5651 { 5652 if (*tp == (tree) data) 5653 return *tp; 5654 return NULL_TREE; 5655 } 5656 5657 /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C. 5658 Return true if there is some error and the clause should be removed. */ 5659 5660 static bool 5661 finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor) 5662 { 5663 tree t = OMP_CLAUSE_DECL (c); 5664 bool predefined = false; 5665 if (TREE_CODE (t) == TREE_LIST) 5666 { 5667 gcc_assert (processing_template_decl); 5668 return false; 5669 } 5670 tree type = TREE_TYPE (t); 5671 if (TREE_CODE (t) == MEM_REF) 5672 type = TREE_TYPE (type); 5673 if (TYPE_REF_P (type)) 5674 type = TREE_TYPE (type); 5675 if (TREE_CODE (type) == ARRAY_TYPE) 5676 { 5677 tree oatype = type; 5678 gcc_assert (TREE_CODE (t) != MEM_REF); 5679 while (TREE_CODE (type) == ARRAY_TYPE) 5680 type = TREE_TYPE (type); 5681 if (!processing_template_decl) 5682 { 5683 t = require_complete_type (t); 5684 if (t == error_mark_node) 5685 return true; 5686 tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype), 5687 TYPE_SIZE_UNIT (type)); 5688 if (integer_zerop (size)) 5689 { 5690 error_at (OMP_CLAUSE_LOCATION (c), 5691 "%qE in %<reduction%> clause is a zero size array", 5692 omp_clause_printable_decl (t)); 5693 return true; 5694 } 5695 size = size_binop (MINUS_EXPR, size, size_one_node); 5696 size = save_expr (size); 5697 tree index_type = build_index_type (size); 5698 tree atype = build_array_type (type, index_type); 5699 tree ptype = build_pointer_type (type); 5700 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) 5701 t = build_fold_addr_expr (t); 5702 t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0)); 5703 OMP_CLAUSE_DECL (c) = t; 5704 } 5705 } 5706 if (type == error_mark_node) 5707 return true; 5708 else if (ARITHMETIC_TYPE_P (type)) 5709 switch (OMP_CLAUSE_REDUCTION_CODE (c)) 5710 { 5711 case PLUS_EXPR: 5712 case MULT_EXPR: 5713 case MINUS_EXPR: 5714 predefined = true; 5715 break; 5716 case MIN_EXPR: 5717 case MAX_EXPR: 5718 if (TREE_CODE (type) == COMPLEX_TYPE) 5719 break; 5720 predefined = true; 5721 break; 5722 case BIT_AND_EXPR: 5723 case BIT_IOR_EXPR: 5724 case BIT_XOR_EXPR: 5725 if (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE) 5726 break; 5727 predefined = true; 5728 break; 5729 case TRUTH_ANDIF_EXPR: 5730 case TRUTH_ORIF_EXPR: 5731 if (FLOAT_TYPE_P (type)) 5732 break; 5733 predefined = true; 5734 break; 5735 default: 5736 break; 5737 } 5738 else if (TYPE_READONLY (type)) 5739 { 5740 error_at (OMP_CLAUSE_LOCATION (c), 5741 "%qE has const type for %<reduction%>", 5742 omp_clause_printable_decl (t)); 5743 return true; 5744 } 5745 else if (!processing_template_decl) 5746 { 5747 t = require_complete_type (t); 5748 if (t == error_mark_node) 5749 return true; 5750 OMP_CLAUSE_DECL (c) = t; 5751 } 5752 5753 if (predefined) 5754 { 5755 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE; 5756 return false; 5757 } 5758 else if (processing_template_decl) 5759 { 5760 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node) 5761 return true; 5762 return false; 5763 } 5764 5765 tree id = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c); 5766 5767 type = TYPE_MAIN_VARIANT (type); 5768 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE; 5769 if (id == NULL_TREE) 5770 id = omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c), 5771 NULL_TREE, NULL_TREE); 5772 id = omp_reduction_lookup (OMP_CLAUSE_LOCATION (c), id, type, NULL, NULL); 5773 if (id) 5774 { 5775 if (id == error_mark_node) 5776 return true; 5777 mark_used (id); 5778 tree body = DECL_SAVED_TREE (id); 5779 if (!body) 5780 return true; 5781 if (TREE_CODE (body) == STATEMENT_LIST) 5782 { 5783 tree_stmt_iterator tsi; 5784 tree placeholder = NULL_TREE, decl_placeholder = NULL_TREE; 5785 int i; 5786 tree stmts[7]; 5787 tree atype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id))); 5788 atype = TREE_TYPE (atype); 5789 bool need_static_cast = !same_type_p (type, atype); 5790 memset (stmts, 0, sizeof stmts); 5791 for (i = 0, tsi = tsi_start (body); 5792 i < 7 && !tsi_end_p (tsi); 5793 i++, tsi_next (&tsi)) 5794 stmts[i] = tsi_stmt (tsi); 5795 gcc_assert (tsi_end_p (tsi)); 5796 5797 if (i >= 3) 5798 { 5799 gcc_assert (TREE_CODE (stmts[0]) == DECL_EXPR 5800 && TREE_CODE (stmts[1]) == DECL_EXPR); 5801 placeholder = build_lang_decl (VAR_DECL, NULL_TREE, type); 5802 DECL_ARTIFICIAL (placeholder) = 1; 5803 DECL_IGNORED_P (placeholder) = 1; 5804 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder; 5805 if (TREE_CODE (t) == MEM_REF) 5806 { 5807 decl_placeholder = build_lang_decl (VAR_DECL, NULL_TREE, 5808 type); 5809 DECL_ARTIFICIAL (decl_placeholder) = 1; 5810 DECL_IGNORED_P (decl_placeholder) = 1; 5811 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder; 5812 } 5813 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0]))) 5814 cxx_mark_addressable (placeholder); 5815 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1])) 5816 && (decl_placeholder 5817 || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c))))) 5818 cxx_mark_addressable (decl_placeholder ? decl_placeholder 5819 : OMP_CLAUSE_DECL (c)); 5820 tree omp_out = placeholder; 5821 tree omp_in = decl_placeholder ? decl_placeholder 5822 : convert_from_reference (OMP_CLAUSE_DECL (c)); 5823 if (need_static_cast) 5824 { 5825 tree rtype = build_reference_type (atype); 5826 omp_out = build_static_cast (rtype, omp_out, 5827 tf_warning_or_error); 5828 omp_in = build_static_cast (rtype, omp_in, 5829 tf_warning_or_error); 5830 if (omp_out == error_mark_node || omp_in == error_mark_node) 5831 return true; 5832 omp_out = convert_from_reference (omp_out); 5833 omp_in = convert_from_reference (omp_in); 5834 } 5835 OMP_CLAUSE_REDUCTION_MERGE (c) 5836 = clone_omp_udr (stmts[2], DECL_EXPR_DECL (stmts[0]), 5837 DECL_EXPR_DECL (stmts[1]), omp_in, omp_out); 5838 } 5839 if (i >= 6) 5840 { 5841 gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR 5842 && TREE_CODE (stmts[4]) == DECL_EXPR); 5843 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3])) 5844 && (decl_placeholder 5845 || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c))))) 5846 cxx_mark_addressable (decl_placeholder ? decl_placeholder 5847 : OMP_CLAUSE_DECL (c)); 5848 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4]))) 5849 cxx_mark_addressable (placeholder); 5850 tree omp_priv = decl_placeholder ? decl_placeholder 5851 : convert_from_reference (OMP_CLAUSE_DECL (c)); 5852 tree omp_orig = placeholder; 5853 if (need_static_cast) 5854 { 5855 if (i == 7) 5856 { 5857 error_at (OMP_CLAUSE_LOCATION (c), 5858 "user defined reduction with constructor " 5859 "initializer for base class %qT", atype); 5860 return true; 5861 } 5862 tree rtype = build_reference_type (atype); 5863 omp_priv = build_static_cast (rtype, omp_priv, 5864 tf_warning_or_error); 5865 omp_orig = build_static_cast (rtype, omp_orig, 5866 tf_warning_or_error); 5867 if (omp_priv == error_mark_node 5868 || omp_orig == error_mark_node) 5869 return true; 5870 omp_priv = convert_from_reference (omp_priv); 5871 omp_orig = convert_from_reference (omp_orig); 5872 } 5873 if (i == 6) 5874 *need_default_ctor = true; 5875 OMP_CLAUSE_REDUCTION_INIT (c) 5876 = clone_omp_udr (stmts[5], DECL_EXPR_DECL (stmts[4]), 5877 DECL_EXPR_DECL (stmts[3]), 5878 omp_priv, omp_orig); 5879 if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c), 5880 find_omp_placeholder_r, placeholder, NULL)) 5881 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1; 5882 } 5883 else if (i >= 3) 5884 { 5885 if (CLASS_TYPE_P (type) && !pod_type_p (type)) 5886 *need_default_ctor = true; 5887 else 5888 { 5889 tree init; 5890 tree v = decl_placeholder ? decl_placeholder 5891 : convert_from_reference (t); 5892 if (AGGREGATE_TYPE_P (TREE_TYPE (v))) 5893 init = build_constructor (TREE_TYPE (v), NULL); 5894 else 5895 init = fold_convert (TREE_TYPE (v), integer_zero_node); 5896 OMP_CLAUSE_REDUCTION_INIT (c) 5897 = build2 (INIT_EXPR, TREE_TYPE (v), v, init); 5898 } 5899 } 5900 } 5901 } 5902 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)) 5903 *need_dtor = true; 5904 else 5905 { 5906 error_at (OMP_CLAUSE_LOCATION (c), 5907 "user defined reduction not found for %qE", 5908 omp_clause_printable_decl (t)); 5909 return true; 5910 } 5911 if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF) 5912 gcc_assert (TYPE_SIZE_UNIT (type) 5913 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST); 5914 return false; 5915 } 5916 5917 /* Called from finish_struct_1. linear(this) or linear(this:step) 5918 clauses might not be finalized yet because the class has been incomplete 5919 when parsing #pragma omp declare simd methods. Fix those up now. */ 5920 5921 void 5922 finish_omp_declare_simd_methods (tree t) 5923 { 5924 if (processing_template_decl) 5925 return; 5926 5927 for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x)) 5928 { 5929 if (TREE_CODE (x) == USING_DECL 5930 || !DECL_NONSTATIC_MEMBER_FUNCTION_P (x)) 5931 continue; 5932 tree ods = lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x)); 5933 if (!ods || !TREE_VALUE (ods)) 5934 continue; 5935 for (tree c = TREE_VALUE (TREE_VALUE (ods)); c; c = OMP_CLAUSE_CHAIN (c)) 5936 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR 5937 && integer_zerop (OMP_CLAUSE_DECL (c)) 5938 && OMP_CLAUSE_LINEAR_STEP (c) 5939 && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c)))) 5940 { 5941 tree s = OMP_CLAUSE_LINEAR_STEP (c); 5942 s = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, s); 5943 s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MULT_EXPR, 5944 sizetype, s, TYPE_SIZE_UNIT (t)); 5945 OMP_CLAUSE_LINEAR_STEP (c) = s; 5946 } 5947 } 5948 } 5949 5950 /* Adjust sink depend clause to take into account pointer offsets. 5951 5952 Return TRUE if there was a problem processing the offset, and the 5953 whole clause should be removed. */ 5954 5955 static bool 5956 cp_finish_omp_clause_depend_sink (tree sink_clause) 5957 { 5958 tree t = OMP_CLAUSE_DECL (sink_clause); 5959 gcc_assert (TREE_CODE (t) == TREE_LIST); 5960 5961 /* Make sure we don't adjust things twice for templates. */ 5962 if (processing_template_decl) 5963 return false; 5964 5965 for (; t; t = TREE_CHAIN (t)) 5966 { 5967 tree decl = TREE_VALUE (t); 5968 if (TYPE_PTR_P (TREE_TYPE (decl))) 5969 { 5970 tree offset = TREE_PURPOSE (t); 5971 bool neg = wi::neg_p (wi::to_wide (offset)); 5972 offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset); 5973 decl = mark_rvalue_use (decl); 5974 decl = convert_from_reference (decl); 5975 tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause), 5976 neg ? MINUS_EXPR : PLUS_EXPR, 5977 decl, offset); 5978 t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause), 5979 MINUS_EXPR, sizetype, 5980 fold_convert (sizetype, t2), 5981 fold_convert (sizetype, decl)); 5982 if (t2 == error_mark_node) 5983 return true; 5984 TREE_PURPOSE (t) = t2; 5985 } 5986 } 5987 return false; 5988 } 5989 5990 /* Finish OpenMP iterators ITER. Return true if they are errorneous 5991 and clauses containing them should be removed. */ 5992 5993 static bool 5994 cp_omp_finish_iterators (tree iter) 5995 { 5996 bool ret = false; 5997 for (tree it = iter; it; it = TREE_CHAIN (it)) 5998 { 5999 tree var = TREE_VEC_ELT (it, 0); 6000 tree begin = TREE_VEC_ELT (it, 1); 6001 tree end = TREE_VEC_ELT (it, 2); 6002 tree step = TREE_VEC_ELT (it, 3); 6003 tree orig_step; 6004 tree type = TREE_TYPE (var); 6005 location_t loc = DECL_SOURCE_LOCATION (var); 6006 if (type == error_mark_node) 6007 { 6008 ret = true; 6009 continue; 6010 } 6011 if (type_dependent_expression_p (var)) 6012 continue; 6013 if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type)) 6014 { 6015 error_at (loc, "iterator %qD has neither integral nor pointer type", 6016 var); 6017 ret = true; 6018 continue; 6019 } 6020 else if (TYPE_READONLY (type)) 6021 { 6022 error_at (loc, "iterator %qD has const qualified type", var); 6023 ret = true; 6024 continue; 6025 } 6026 if (type_dependent_expression_p (begin) 6027 || type_dependent_expression_p (end) 6028 || type_dependent_expression_p (step)) 6029 continue; 6030 else if (error_operand_p (step)) 6031 { 6032 ret = true; 6033 continue; 6034 } 6035 else if (!INTEGRAL_TYPE_P (TREE_TYPE (step))) 6036 { 6037 error_at (EXPR_LOC_OR_LOC (step, loc), 6038 "iterator step with non-integral type"); 6039 ret = true; 6040 continue; 6041 } 6042 6043 begin = mark_rvalue_use (begin); 6044 end = mark_rvalue_use (end); 6045 step = mark_rvalue_use (step); 6046 begin = cp_build_c_cast (type, begin, tf_warning_or_error); 6047 end = cp_build_c_cast (type, end, tf_warning_or_error); 6048 orig_step = step; 6049 if (!processing_template_decl) 6050 step = orig_step = save_expr (step); 6051 tree stype = POINTER_TYPE_P (type) ? sizetype : type; 6052 step = cp_build_c_cast (stype, step, tf_warning_or_error); 6053 if (POINTER_TYPE_P (type) && !processing_template_decl) 6054 { 6055 begin = save_expr (begin); 6056 step = pointer_int_sum (loc, PLUS_EXPR, begin, step); 6057 step = fold_build2_loc (loc, MINUS_EXPR, sizetype, 6058 fold_convert (sizetype, step), 6059 fold_convert (sizetype, begin)); 6060 step = fold_convert (ssizetype, step); 6061 } 6062 if (!processing_template_decl) 6063 { 6064 begin = maybe_constant_value (begin); 6065 end = maybe_constant_value (end); 6066 step = maybe_constant_value (step); 6067 orig_step = maybe_constant_value (orig_step); 6068 } 6069 if (integer_zerop (step)) 6070 { 6071 error_at (loc, "iterator %qD has zero step", var); 6072 ret = true; 6073 continue; 6074 } 6075 6076 if (begin == error_mark_node 6077 || end == error_mark_node 6078 || step == error_mark_node 6079 || orig_step == error_mark_node) 6080 { 6081 ret = true; 6082 continue; 6083 } 6084 6085 if (!processing_template_decl) 6086 { 6087 begin = fold_build_cleanup_point_expr (TREE_TYPE (begin), begin); 6088 end = fold_build_cleanup_point_expr (TREE_TYPE (end), end); 6089 step = fold_build_cleanup_point_expr (TREE_TYPE (step), step); 6090 orig_step = fold_build_cleanup_point_expr (TREE_TYPE (orig_step), 6091 orig_step); 6092 } 6093 hash_set<tree> pset; 6094 tree it2; 6095 for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2)) 6096 { 6097 tree var2 = TREE_VEC_ELT (it2, 0); 6098 tree begin2 = TREE_VEC_ELT (it2, 1); 6099 tree end2 = TREE_VEC_ELT (it2, 2); 6100 tree step2 = TREE_VEC_ELT (it2, 3); 6101 location_t loc2 = DECL_SOURCE_LOCATION (var2); 6102 if (cp_walk_tree (&begin2, find_omp_placeholder_r, var, &pset)) 6103 { 6104 error_at (EXPR_LOC_OR_LOC (begin2, loc2), 6105 "begin expression refers to outer iterator %qD", var); 6106 break; 6107 } 6108 else if (cp_walk_tree (&end2, find_omp_placeholder_r, var, &pset)) 6109 { 6110 error_at (EXPR_LOC_OR_LOC (end2, loc2), 6111 "end expression refers to outer iterator %qD", var); 6112 break; 6113 } 6114 else if (cp_walk_tree (&step2, find_omp_placeholder_r, var, &pset)) 6115 { 6116 error_at (EXPR_LOC_OR_LOC (step2, loc2), 6117 "step expression refers to outer iterator %qD", var); 6118 break; 6119 } 6120 } 6121 if (it2) 6122 { 6123 ret = true; 6124 continue; 6125 } 6126 TREE_VEC_ELT (it, 1) = begin; 6127 TREE_VEC_ELT (it, 2) = end; 6128 if (processing_template_decl) 6129 TREE_VEC_ELT (it, 3) = orig_step; 6130 else 6131 { 6132 TREE_VEC_ELT (it, 3) = step; 6133 TREE_VEC_ELT (it, 4) = orig_step; 6134 } 6135 } 6136 return ret; 6137 } 6138 6139 /* For all elements of CLAUSES, validate them vs OpenMP constraints. 6140 Remove any elements from the list that are invalid. */ 6141 6142 tree 6143 finish_omp_clauses (tree clauses, enum c_omp_region_type ort) 6144 { 6145 bitmap_head generic_head, firstprivate_head, lastprivate_head; 6146 bitmap_head aligned_head, map_head, map_field_head, oacc_reduction_head; 6147 tree c, t, *pc; 6148 tree safelen = NULL_TREE; 6149 bool branch_seen = false; 6150 bool copyprivate_seen = false; 6151 bool ordered_seen = false; 6152 bool oacc_async = false; 6153 tree last_iterators = NULL_TREE; 6154 bool last_iterators_remove = false; 6155 bool reduction_seen = false; 6156 6157 bitmap_obstack_initialize (NULL); 6158 bitmap_initialize (&generic_head, &bitmap_default_obstack); 6159 bitmap_initialize (&firstprivate_head, &bitmap_default_obstack); 6160 bitmap_initialize (&lastprivate_head, &bitmap_default_obstack); 6161 bitmap_initialize (&aligned_head, &bitmap_default_obstack); 6162 /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */ 6163 bitmap_initialize (&map_head, &bitmap_default_obstack); 6164 bitmap_initialize (&map_field_head, &bitmap_default_obstack); 6165 /* If ort == C_ORT_OMP used as nontemporal_head instead. */ 6166 bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack); 6167 6168 if (ort & C_ORT_ACC) 6169 for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c)) 6170 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC) 6171 { 6172 oacc_async = true; 6173 break; 6174 } 6175 6176 for (pc = &clauses, c = clauses; c ; c = *pc) 6177 { 6178 bool remove = false; 6179 bool field_ok = false; 6180 6181 switch (OMP_CLAUSE_CODE (c)) 6182 { 6183 case OMP_CLAUSE_SHARED: 6184 field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP); 6185 goto check_dup_generic; 6186 case OMP_CLAUSE_PRIVATE: 6187 field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP); 6188 goto check_dup_generic; 6189 case OMP_CLAUSE_REDUCTION: 6190 reduction_seen = true; 6191 /* FALLTHRU */ 6192 case OMP_CLAUSE_IN_REDUCTION: 6193 case OMP_CLAUSE_TASK_REDUCTION: 6194 field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP); 6195 t = OMP_CLAUSE_DECL (c); 6196 if (TREE_CODE (t) == TREE_LIST) 6197 { 6198 if (handle_omp_array_sections (c, ort)) 6199 { 6200 remove = true; 6201 break; 6202 } 6203 if (TREE_CODE (t) == TREE_LIST) 6204 { 6205 while (TREE_CODE (t) == TREE_LIST) 6206 t = TREE_CHAIN (t); 6207 } 6208 else 6209 { 6210 gcc_assert (TREE_CODE (t) == MEM_REF); 6211 t = TREE_OPERAND (t, 0); 6212 if (TREE_CODE (t) == POINTER_PLUS_EXPR) 6213 t = TREE_OPERAND (t, 0); 6214 if (TREE_CODE (t) == ADDR_EXPR 6215 || INDIRECT_REF_P (t)) 6216 t = TREE_OPERAND (t, 0); 6217 } 6218 tree n = omp_clause_decl_field (t); 6219 if (n) 6220 t = n; 6221 goto check_dup_generic_t; 6222 } 6223 if (oacc_async) 6224 cxx_mark_addressable (t); 6225 goto check_dup_generic; 6226 case OMP_CLAUSE_COPYPRIVATE: 6227 copyprivate_seen = true; 6228 field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP); 6229 goto check_dup_generic; 6230 case OMP_CLAUSE_COPYIN: 6231 goto check_dup_generic; 6232 case OMP_CLAUSE_LINEAR: 6233 field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP); 6234 t = OMP_CLAUSE_DECL (c); 6235 if (ort != C_ORT_OMP_DECLARE_SIMD 6236 && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT) 6237 { 6238 error_at (OMP_CLAUSE_LOCATION (c), 6239 "modifier should not be specified in %<linear%> " 6240 "clause on %<simd%> or %<for%> constructs"); 6241 OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT; 6242 } 6243 if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL) 6244 && !type_dependent_expression_p (t)) 6245 { 6246 tree type = TREE_TYPE (t); 6247 if ((OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF 6248 || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL) 6249 && !TYPE_REF_P (type)) 6250 { 6251 error_at (OMP_CLAUSE_LOCATION (c), 6252 "linear clause with %qs modifier applied to " 6253 "non-reference variable with %qT type", 6254 OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF 6255 ? "ref" : "uval", TREE_TYPE (t)); 6256 remove = true; 6257 break; 6258 } 6259 if (TYPE_REF_P (type)) 6260 type = TREE_TYPE (type); 6261 if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_REF) 6262 { 6263 if (!INTEGRAL_TYPE_P (type) 6264 && !TYPE_PTR_P (type)) 6265 { 6266 error_at (OMP_CLAUSE_LOCATION (c), 6267 "linear clause applied to non-integral " 6268 "non-pointer variable with %qT type", 6269 TREE_TYPE (t)); 6270 remove = true; 6271 break; 6272 } 6273 } 6274 } 6275 t = OMP_CLAUSE_LINEAR_STEP (c); 6276 if (t == NULL_TREE) 6277 t = integer_one_node; 6278 if (t == error_mark_node) 6279 { 6280 remove = true; 6281 break; 6282 } 6283 else if (!type_dependent_expression_p (t) 6284 && !INTEGRAL_TYPE_P (TREE_TYPE (t)) 6285 && (ort != C_ORT_OMP_DECLARE_SIMD 6286 || TREE_CODE (t) != PARM_DECL 6287 || !TYPE_REF_P (TREE_TYPE (t)) 6288 || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t))))) 6289 { 6290 error_at (OMP_CLAUSE_LOCATION (c), 6291 "linear step expression must be integral"); 6292 remove = true; 6293 break; 6294 } 6295 else 6296 { 6297 t = mark_rvalue_use (t); 6298 if (ort == C_ORT_OMP_DECLARE_SIMD && TREE_CODE (t) == PARM_DECL) 6299 { 6300 OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1; 6301 goto check_dup_generic; 6302 } 6303 if (!processing_template_decl 6304 && (VAR_P (OMP_CLAUSE_DECL (c)) 6305 || TREE_CODE (OMP_CLAUSE_DECL (c)) == PARM_DECL)) 6306 { 6307 if (ort == C_ORT_OMP_DECLARE_SIMD) 6308 { 6309 t = maybe_constant_value (t); 6310 if (TREE_CODE (t) != INTEGER_CST) 6311 { 6312 error_at (OMP_CLAUSE_LOCATION (c), 6313 "%<linear%> clause step %qE is neither " 6314 "constant nor a parameter", t); 6315 remove = true; 6316 break; 6317 } 6318 } 6319 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 6320 tree type = TREE_TYPE (OMP_CLAUSE_DECL (c)); 6321 if (TYPE_REF_P (type)) 6322 type = TREE_TYPE (type); 6323 if (OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF) 6324 { 6325 type = build_pointer_type (type); 6326 tree d = fold_convert (type, OMP_CLAUSE_DECL (c)); 6327 t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR, 6328 d, t); 6329 t = fold_build2_loc (OMP_CLAUSE_LOCATION (c), 6330 MINUS_EXPR, sizetype, 6331 fold_convert (sizetype, t), 6332 fold_convert (sizetype, d)); 6333 if (t == error_mark_node) 6334 { 6335 remove = true; 6336 break; 6337 } 6338 } 6339 else if (TYPE_PTR_P (type) 6340 /* Can't multiply the step yet if *this 6341 is still incomplete type. */ 6342 && (ort != C_ORT_OMP_DECLARE_SIMD 6343 || TREE_CODE (OMP_CLAUSE_DECL (c)) != PARM_DECL 6344 || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c)) 6345 || DECL_NAME (OMP_CLAUSE_DECL (c)) 6346 != this_identifier 6347 || !TYPE_BEING_DEFINED (TREE_TYPE (type)))) 6348 { 6349 tree d = convert_from_reference (OMP_CLAUSE_DECL (c)); 6350 t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR, 6351 d, t); 6352 t = fold_build2_loc (OMP_CLAUSE_LOCATION (c), 6353 MINUS_EXPR, sizetype, 6354 fold_convert (sizetype, t), 6355 fold_convert (sizetype, d)); 6356 if (t == error_mark_node) 6357 { 6358 remove = true; 6359 break; 6360 } 6361 } 6362 else 6363 t = fold_convert (type, t); 6364 } 6365 OMP_CLAUSE_LINEAR_STEP (c) = t; 6366 } 6367 goto check_dup_generic; 6368 check_dup_generic: 6369 t = omp_clause_decl_field (OMP_CLAUSE_DECL (c)); 6370 if (t) 6371 { 6372 if (!remove && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED) 6373 omp_note_field_privatization (t, OMP_CLAUSE_DECL (c)); 6374 } 6375 else 6376 t = OMP_CLAUSE_DECL (c); 6377 check_dup_generic_t: 6378 if (t == current_class_ptr 6379 && (ort != C_ORT_OMP_DECLARE_SIMD 6380 || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR 6381 && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM))) 6382 { 6383 error_at (OMP_CLAUSE_LOCATION (c), 6384 "%<this%> allowed in OpenMP only in %<declare simd%>" 6385 " clauses"); 6386 remove = true; 6387 break; 6388 } 6389 if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL 6390 && (!field_ok || TREE_CODE (t) != FIELD_DECL)) 6391 { 6392 if (processing_template_decl && TREE_CODE (t) != OVERLOAD) 6393 break; 6394 if (DECL_P (t)) 6395 error_at (OMP_CLAUSE_LOCATION (c), 6396 "%qD is not a variable in clause %qs", t, 6397 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 6398 else 6399 error_at (OMP_CLAUSE_LOCATION (c), 6400 "%qE is not a variable in clause %qs", t, 6401 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 6402 remove = true; 6403 } 6404 else if (ort == C_ORT_ACC 6405 && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) 6406 { 6407 if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t))) 6408 { 6409 error_at (OMP_CLAUSE_LOCATION (c), 6410 "%qD appears more than once in reduction clauses", 6411 t); 6412 remove = true; 6413 } 6414 else 6415 bitmap_set_bit (&oacc_reduction_head, DECL_UID (t)); 6416 } 6417 else if (bitmap_bit_p (&generic_head, DECL_UID (t)) 6418 || bitmap_bit_p (&firstprivate_head, DECL_UID (t)) 6419 || bitmap_bit_p (&lastprivate_head, DECL_UID (t))) 6420 { 6421 error_at (OMP_CLAUSE_LOCATION (c), 6422 "%qD appears more than once in data clauses", t); 6423 remove = true; 6424 } 6425 else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE 6426 && bitmap_bit_p (&map_head, DECL_UID (t))) 6427 { 6428 if (ort == C_ORT_ACC) 6429 error_at (OMP_CLAUSE_LOCATION (c), 6430 "%qD appears more than once in data clauses", t); 6431 else 6432 error_at (OMP_CLAUSE_LOCATION (c), 6433 "%qD appears both in data and map clauses", t); 6434 remove = true; 6435 } 6436 else 6437 bitmap_set_bit (&generic_head, DECL_UID (t)); 6438 if (!field_ok) 6439 break; 6440 handle_field_decl: 6441 if (!remove 6442 && TREE_CODE (t) == FIELD_DECL 6443 && t == OMP_CLAUSE_DECL (c) 6444 && ort != C_ORT_ACC) 6445 { 6446 OMP_CLAUSE_DECL (c) 6447 = omp_privatize_field (t, (OMP_CLAUSE_CODE (c) 6448 == OMP_CLAUSE_SHARED)); 6449 if (OMP_CLAUSE_DECL (c) == error_mark_node) 6450 remove = true; 6451 } 6452 break; 6453 6454 case OMP_CLAUSE_FIRSTPRIVATE: 6455 t = omp_clause_decl_field (OMP_CLAUSE_DECL (c)); 6456 if (t) 6457 omp_note_field_privatization (t, OMP_CLAUSE_DECL (c)); 6458 else 6459 t = OMP_CLAUSE_DECL (c); 6460 if (ort != C_ORT_ACC && t == current_class_ptr) 6461 { 6462 error_at (OMP_CLAUSE_LOCATION (c), 6463 "%<this%> allowed in OpenMP only in %<declare simd%>" 6464 " clauses"); 6465 remove = true; 6466 break; 6467 } 6468 if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL 6469 && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP 6470 || TREE_CODE (t) != FIELD_DECL)) 6471 { 6472 if (processing_template_decl && TREE_CODE (t) != OVERLOAD) 6473 break; 6474 if (DECL_P (t)) 6475 error_at (OMP_CLAUSE_LOCATION (c), 6476 "%qD is not a variable in clause %<firstprivate%>", 6477 t); 6478 else 6479 error_at (OMP_CLAUSE_LOCATION (c), 6480 "%qE is not a variable in clause %<firstprivate%>", 6481 t); 6482 remove = true; 6483 } 6484 else if (bitmap_bit_p (&generic_head, DECL_UID (t)) 6485 || bitmap_bit_p (&firstprivate_head, DECL_UID (t))) 6486 { 6487 error_at (OMP_CLAUSE_LOCATION (c), 6488 "%qD appears more than once in data clauses", t); 6489 remove = true; 6490 } 6491 else if (bitmap_bit_p (&map_head, DECL_UID (t))) 6492 { 6493 if (ort == C_ORT_ACC) 6494 error_at (OMP_CLAUSE_LOCATION (c), 6495 "%qD appears more than once in data clauses", t); 6496 else 6497 error_at (OMP_CLAUSE_LOCATION (c), 6498 "%qD appears both in data and map clauses", t); 6499 remove = true; 6500 } 6501 else 6502 bitmap_set_bit (&firstprivate_head, DECL_UID (t)); 6503 goto handle_field_decl; 6504 6505 case OMP_CLAUSE_LASTPRIVATE: 6506 t = omp_clause_decl_field (OMP_CLAUSE_DECL (c)); 6507 if (t) 6508 omp_note_field_privatization (t, OMP_CLAUSE_DECL (c)); 6509 else 6510 t = OMP_CLAUSE_DECL (c); 6511 if (t == current_class_ptr) 6512 { 6513 error_at (OMP_CLAUSE_LOCATION (c), 6514 "%<this%> allowed in OpenMP only in %<declare simd%>" 6515 " clauses"); 6516 remove = true; 6517 break; 6518 } 6519 if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL 6520 && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP 6521 || TREE_CODE (t) != FIELD_DECL)) 6522 { 6523 if (processing_template_decl && TREE_CODE (t) != OVERLOAD) 6524 break; 6525 if (DECL_P (t)) 6526 error_at (OMP_CLAUSE_LOCATION (c), 6527 "%qD is not a variable in clause %<lastprivate%>", 6528 t); 6529 else 6530 error_at (OMP_CLAUSE_LOCATION (c), 6531 "%qE is not a variable in clause %<lastprivate%>", 6532 t); 6533 remove = true; 6534 } 6535 else if (bitmap_bit_p (&generic_head, DECL_UID (t)) 6536 || bitmap_bit_p (&lastprivate_head, DECL_UID (t))) 6537 { 6538 error_at (OMP_CLAUSE_LOCATION (c), 6539 "%qD appears more than once in data clauses", t); 6540 remove = true; 6541 } 6542 else 6543 bitmap_set_bit (&lastprivate_head, DECL_UID (t)); 6544 goto handle_field_decl; 6545 6546 case OMP_CLAUSE_IF: 6547 t = OMP_CLAUSE_IF_EXPR (c); 6548 t = maybe_convert_cond (t); 6549 if (t == error_mark_node) 6550 remove = true; 6551 else if (!processing_template_decl) 6552 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 6553 OMP_CLAUSE_IF_EXPR (c) = t; 6554 break; 6555 6556 case OMP_CLAUSE_FINAL: 6557 t = OMP_CLAUSE_FINAL_EXPR (c); 6558 t = maybe_convert_cond (t); 6559 if (t == error_mark_node) 6560 remove = true; 6561 else if (!processing_template_decl) 6562 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 6563 OMP_CLAUSE_FINAL_EXPR (c) = t; 6564 break; 6565 6566 case OMP_CLAUSE_GANG: 6567 /* Operand 1 is the gang static: argument. */ 6568 t = OMP_CLAUSE_OPERAND (c, 1); 6569 if (t != NULL_TREE) 6570 { 6571 if (t == error_mark_node) 6572 remove = true; 6573 else if (!type_dependent_expression_p (t) 6574 && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 6575 { 6576 error_at (OMP_CLAUSE_LOCATION (c), 6577 "%<gang%> static expression must be integral"); 6578 remove = true; 6579 } 6580 else 6581 { 6582 t = mark_rvalue_use (t); 6583 if (!processing_template_decl) 6584 { 6585 t = maybe_constant_value (t); 6586 if (TREE_CODE (t) == INTEGER_CST 6587 && tree_int_cst_sgn (t) != 1 6588 && t != integer_minus_one_node) 6589 { 6590 warning_at (OMP_CLAUSE_LOCATION (c), 0, 6591 "%<gang%> static value must be " 6592 "positive"); 6593 t = integer_one_node; 6594 } 6595 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 6596 } 6597 } 6598 OMP_CLAUSE_OPERAND (c, 1) = t; 6599 } 6600 /* Check operand 0, the num argument. */ 6601 /* FALLTHRU */ 6602 6603 case OMP_CLAUSE_WORKER: 6604 case OMP_CLAUSE_VECTOR: 6605 if (OMP_CLAUSE_OPERAND (c, 0) == NULL_TREE) 6606 break; 6607 /* FALLTHRU */ 6608 6609 case OMP_CLAUSE_NUM_TASKS: 6610 case OMP_CLAUSE_NUM_TEAMS: 6611 case OMP_CLAUSE_NUM_THREADS: 6612 case OMP_CLAUSE_NUM_GANGS: 6613 case OMP_CLAUSE_NUM_WORKERS: 6614 case OMP_CLAUSE_VECTOR_LENGTH: 6615 t = OMP_CLAUSE_OPERAND (c, 0); 6616 if (t == error_mark_node) 6617 remove = true; 6618 else if (!type_dependent_expression_p (t) 6619 && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 6620 { 6621 switch (OMP_CLAUSE_CODE (c)) 6622 { 6623 case OMP_CLAUSE_GANG: 6624 error_at (OMP_CLAUSE_LOCATION (c), 6625 "%<gang%> num expression must be integral"); break; 6626 case OMP_CLAUSE_VECTOR: 6627 error_at (OMP_CLAUSE_LOCATION (c), 6628 "%<vector%> length expression must be integral"); 6629 break; 6630 case OMP_CLAUSE_WORKER: 6631 error_at (OMP_CLAUSE_LOCATION (c), 6632 "%<worker%> num expression must be integral"); 6633 break; 6634 default: 6635 error_at (OMP_CLAUSE_LOCATION (c), 6636 "%qs expression must be integral", 6637 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 6638 } 6639 remove = true; 6640 } 6641 else 6642 { 6643 t = mark_rvalue_use (t); 6644 if (!processing_template_decl) 6645 { 6646 t = maybe_constant_value (t); 6647 if (TREE_CODE (t) == INTEGER_CST 6648 && tree_int_cst_sgn (t) != 1) 6649 { 6650 switch (OMP_CLAUSE_CODE (c)) 6651 { 6652 case OMP_CLAUSE_GANG: 6653 warning_at (OMP_CLAUSE_LOCATION (c), 0, 6654 "%<gang%> num value must be positive"); 6655 break; 6656 case OMP_CLAUSE_VECTOR: 6657 warning_at (OMP_CLAUSE_LOCATION (c), 0, 6658 "%<vector%> length value must be " 6659 "positive"); 6660 break; 6661 case OMP_CLAUSE_WORKER: 6662 warning_at (OMP_CLAUSE_LOCATION (c), 0, 6663 "%<worker%> num value must be " 6664 "positive"); 6665 break; 6666 default: 6667 warning_at (OMP_CLAUSE_LOCATION (c), 0, 6668 "%qs value must be positive", 6669 omp_clause_code_name 6670 [OMP_CLAUSE_CODE (c)]); 6671 } 6672 t = integer_one_node; 6673 } 6674 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 6675 } 6676 OMP_CLAUSE_OPERAND (c, 0) = t; 6677 } 6678 break; 6679 6680 case OMP_CLAUSE_SCHEDULE: 6681 t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c); 6682 if (t == NULL) 6683 ; 6684 else if (t == error_mark_node) 6685 remove = true; 6686 else if (!type_dependent_expression_p (t) 6687 && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 6688 { 6689 error_at (OMP_CLAUSE_LOCATION (c), 6690 "schedule chunk size expression must be integral"); 6691 remove = true; 6692 } 6693 else 6694 { 6695 t = mark_rvalue_use (t); 6696 if (!processing_template_decl) 6697 { 6698 t = maybe_constant_value (t); 6699 if (TREE_CODE (t) == INTEGER_CST 6700 && tree_int_cst_sgn (t) != 1) 6701 { 6702 warning_at (OMP_CLAUSE_LOCATION (c), 0, 6703 "chunk size value must be positive"); 6704 t = integer_one_node; 6705 } 6706 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 6707 } 6708 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t; 6709 } 6710 break; 6711 6712 case OMP_CLAUSE_SIMDLEN: 6713 case OMP_CLAUSE_SAFELEN: 6714 t = OMP_CLAUSE_OPERAND (c, 0); 6715 if (t == error_mark_node) 6716 remove = true; 6717 else if (!type_dependent_expression_p (t) 6718 && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 6719 { 6720 error_at (OMP_CLAUSE_LOCATION (c), 6721 "%qs length expression must be integral", 6722 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 6723 remove = true; 6724 } 6725 else 6726 { 6727 t = mark_rvalue_use (t); 6728 if (!processing_template_decl) 6729 { 6730 t = maybe_constant_value (t); 6731 if (TREE_CODE (t) != INTEGER_CST 6732 || tree_int_cst_sgn (t) != 1) 6733 { 6734 error_at (OMP_CLAUSE_LOCATION (c), 6735 "%qs length expression must be positive " 6736 "constant integer expression", 6737 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 6738 remove = true; 6739 } 6740 } 6741 OMP_CLAUSE_OPERAND (c, 0) = t; 6742 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SAFELEN) 6743 safelen = c; 6744 } 6745 break; 6746 6747 case OMP_CLAUSE_ASYNC: 6748 t = OMP_CLAUSE_ASYNC_EXPR (c); 6749 if (t == error_mark_node) 6750 remove = true; 6751 else if (!type_dependent_expression_p (t) 6752 && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 6753 { 6754 error_at (OMP_CLAUSE_LOCATION (c), 6755 "%<async%> expression must be integral"); 6756 remove = true; 6757 } 6758 else 6759 { 6760 t = mark_rvalue_use (t); 6761 if (!processing_template_decl) 6762 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 6763 OMP_CLAUSE_ASYNC_EXPR (c) = t; 6764 } 6765 break; 6766 6767 case OMP_CLAUSE_WAIT: 6768 t = OMP_CLAUSE_WAIT_EXPR (c); 6769 if (t == error_mark_node) 6770 remove = true; 6771 else if (!processing_template_decl) 6772 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 6773 OMP_CLAUSE_WAIT_EXPR (c) = t; 6774 break; 6775 6776 case OMP_CLAUSE_THREAD_LIMIT: 6777 t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c); 6778 if (t == error_mark_node) 6779 remove = true; 6780 else if (!type_dependent_expression_p (t) 6781 && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 6782 { 6783 error_at (OMP_CLAUSE_LOCATION (c), 6784 "%<thread_limit%> expression must be integral"); 6785 remove = true; 6786 } 6787 else 6788 { 6789 t = mark_rvalue_use (t); 6790 if (!processing_template_decl) 6791 { 6792 t = maybe_constant_value (t); 6793 if (TREE_CODE (t) == INTEGER_CST 6794 && tree_int_cst_sgn (t) != 1) 6795 { 6796 warning_at (OMP_CLAUSE_LOCATION (c), 0, 6797 "%<thread_limit%> value must be positive"); 6798 t = integer_one_node; 6799 } 6800 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 6801 } 6802 OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t; 6803 } 6804 break; 6805 6806 case OMP_CLAUSE_DEVICE: 6807 t = OMP_CLAUSE_DEVICE_ID (c); 6808 if (t == error_mark_node) 6809 remove = true; 6810 else if (!type_dependent_expression_p (t) 6811 && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 6812 { 6813 error_at (OMP_CLAUSE_LOCATION (c), 6814 "%<device%> id must be integral"); 6815 remove = true; 6816 } 6817 else 6818 { 6819 t = mark_rvalue_use (t); 6820 if (!processing_template_decl) 6821 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 6822 OMP_CLAUSE_DEVICE_ID (c) = t; 6823 } 6824 break; 6825 6826 case OMP_CLAUSE_DIST_SCHEDULE: 6827 t = OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c); 6828 if (t == NULL) 6829 ; 6830 else if (t == error_mark_node) 6831 remove = true; 6832 else if (!type_dependent_expression_p (t) 6833 && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 6834 { 6835 error_at (OMP_CLAUSE_LOCATION (c), 6836 "%<dist_schedule%> chunk size expression must be " 6837 "integral"); 6838 remove = true; 6839 } 6840 else 6841 { 6842 t = mark_rvalue_use (t); 6843 if (!processing_template_decl) 6844 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 6845 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t; 6846 } 6847 break; 6848 6849 case OMP_CLAUSE_ALIGNED: 6850 t = OMP_CLAUSE_DECL (c); 6851 if (t == current_class_ptr && ort != C_ORT_OMP_DECLARE_SIMD) 6852 { 6853 error_at (OMP_CLAUSE_LOCATION (c), 6854 "%<this%> allowed in OpenMP only in %<declare simd%>" 6855 " clauses"); 6856 remove = true; 6857 break; 6858 } 6859 if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) 6860 { 6861 if (processing_template_decl && TREE_CODE (t) != OVERLOAD) 6862 break; 6863 if (DECL_P (t)) 6864 error_at (OMP_CLAUSE_LOCATION (c), 6865 "%qD is not a variable in %<aligned%> clause", t); 6866 else 6867 error_at (OMP_CLAUSE_LOCATION (c), 6868 "%qE is not a variable in %<aligned%> clause", t); 6869 remove = true; 6870 } 6871 else if (!type_dependent_expression_p (t) 6872 && !TYPE_PTR_P (TREE_TYPE (t)) 6873 && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE 6874 && (!TYPE_REF_P (TREE_TYPE (t)) 6875 || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t))) 6876 && (TREE_CODE (TREE_TYPE (TREE_TYPE (t))) 6877 != ARRAY_TYPE)))) 6878 { 6879 error_at (OMP_CLAUSE_LOCATION (c), 6880 "%qE in %<aligned%> clause is neither a pointer nor " 6881 "an array nor a reference to pointer or array", t); 6882 remove = true; 6883 } 6884 else if (bitmap_bit_p (&aligned_head, DECL_UID (t))) 6885 { 6886 error_at (OMP_CLAUSE_LOCATION (c), 6887 "%qD appears more than once in %<aligned%> clauses", 6888 t); 6889 remove = true; 6890 } 6891 else 6892 bitmap_set_bit (&aligned_head, DECL_UID (t)); 6893 t = OMP_CLAUSE_ALIGNED_ALIGNMENT (c); 6894 if (t == error_mark_node) 6895 remove = true; 6896 else if (t == NULL_TREE) 6897 break; 6898 else if (!type_dependent_expression_p (t) 6899 && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 6900 { 6901 error_at (OMP_CLAUSE_LOCATION (c), 6902 "%<aligned%> clause alignment expression must " 6903 "be integral"); 6904 remove = true; 6905 } 6906 else 6907 { 6908 t = mark_rvalue_use (t); 6909 if (!processing_template_decl) 6910 { 6911 t = maybe_constant_value (t); 6912 if (TREE_CODE (t) != INTEGER_CST 6913 || tree_int_cst_sgn (t) != 1) 6914 { 6915 error_at (OMP_CLAUSE_LOCATION (c), 6916 "%<aligned%> clause alignment expression must " 6917 "be positive constant integer expression"); 6918 remove = true; 6919 } 6920 else 6921 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 6922 } 6923 OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t; 6924 } 6925 break; 6926 6927 case OMP_CLAUSE_NONTEMPORAL: 6928 t = OMP_CLAUSE_DECL (c); 6929 if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) 6930 { 6931 if (processing_template_decl && TREE_CODE (t) != OVERLOAD) 6932 break; 6933 if (DECL_P (t)) 6934 error_at (OMP_CLAUSE_LOCATION (c), 6935 "%qD is not a variable in %<nontemporal%> clause", 6936 t); 6937 else 6938 error_at (OMP_CLAUSE_LOCATION (c), 6939 "%qE is not a variable in %<nontemporal%> clause", 6940 t); 6941 remove = true; 6942 } 6943 else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t))) 6944 { 6945 error_at (OMP_CLAUSE_LOCATION (c), 6946 "%qD appears more than once in %<nontemporal%> " 6947 "clauses", t); 6948 remove = true; 6949 } 6950 else 6951 bitmap_set_bit (&oacc_reduction_head, DECL_UID (t)); 6952 break; 6953 6954 case OMP_CLAUSE_DEPEND: 6955 t = OMP_CLAUSE_DECL (c); 6956 if (t == NULL_TREE) 6957 { 6958 gcc_assert (OMP_CLAUSE_DEPEND_KIND (c) 6959 == OMP_CLAUSE_DEPEND_SOURCE); 6960 break; 6961 } 6962 if (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_SINK) 6963 { 6964 if (cp_finish_omp_clause_depend_sink (c)) 6965 remove = true; 6966 break; 6967 } 6968 if (TREE_CODE (t) == TREE_LIST 6969 && TREE_PURPOSE (t) 6970 && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC) 6971 { 6972 if (TREE_PURPOSE (t) != last_iterators) 6973 last_iterators_remove 6974 = cp_omp_finish_iterators (TREE_PURPOSE (t)); 6975 last_iterators = TREE_PURPOSE (t); 6976 t = TREE_VALUE (t); 6977 if (last_iterators_remove) 6978 t = error_mark_node; 6979 } 6980 else 6981 last_iterators = NULL_TREE; 6982 6983 if (TREE_CODE (t) == TREE_LIST) 6984 { 6985 if (handle_omp_array_sections (c, ort)) 6986 remove = true; 6987 else if (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ) 6988 { 6989 error_at (OMP_CLAUSE_LOCATION (c), 6990 "%<depend%> clause with %<depobj%> dependence " 6991 "type on array section"); 6992 remove = true; 6993 } 6994 break; 6995 } 6996 if (t == error_mark_node) 6997 remove = true; 6998 else if (t == current_class_ptr) 6999 { 7000 error_at (OMP_CLAUSE_LOCATION (c), 7001 "%<this%> allowed in OpenMP only in %<declare simd%>" 7002 " clauses"); 7003 remove = true; 7004 } 7005 else if (processing_template_decl && TREE_CODE (t) != OVERLOAD) 7006 break; 7007 else if (!lvalue_p (t)) 7008 { 7009 if (DECL_P (t)) 7010 error_at (OMP_CLAUSE_LOCATION (c), 7011 "%qD is not lvalue expression nor array section " 7012 "in %<depend%> clause", t); 7013 else 7014 error_at (OMP_CLAUSE_LOCATION (c), 7015 "%qE is not lvalue expression nor array section " 7016 "in %<depend%> clause", t); 7017 remove = true; 7018 } 7019 else if (TREE_CODE (t) == COMPONENT_REF 7020 && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL 7021 && DECL_BIT_FIELD (TREE_OPERAND (t, 1))) 7022 { 7023 error_at (OMP_CLAUSE_LOCATION (c), 7024 "bit-field %qE in %qs clause", t, "depend"); 7025 remove = true; 7026 } 7027 else if (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ) 7028 { 7029 if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t)) 7030 ? TREE_TYPE (TREE_TYPE (t)) 7031 : TREE_TYPE (t))) 7032 { 7033 error_at (OMP_CLAUSE_LOCATION (c), 7034 "%qE does not have %<omp_depend_t%> type in " 7035 "%<depend%> clause with %<depobj%> dependence " 7036 "type", t); 7037 remove = true; 7038 } 7039 } 7040 else if (c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t)) 7041 ? TREE_TYPE (TREE_TYPE (t)) 7042 : TREE_TYPE (t))) 7043 { 7044 error_at (OMP_CLAUSE_LOCATION (c), 7045 "%qE should not have %<omp_depend_t%> type in " 7046 "%<depend%> clause with dependence type other than " 7047 "%<depobj%>", t); 7048 remove = true; 7049 } 7050 if (!remove) 7051 { 7052 tree addr = cp_build_addr_expr (t, tf_warning_or_error); 7053 if (addr == error_mark_node) 7054 remove = true; 7055 else 7056 { 7057 t = cp_build_indirect_ref (addr, RO_UNARY_STAR, 7058 tf_warning_or_error); 7059 if (t == error_mark_node) 7060 remove = true; 7061 else if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST 7062 && TREE_PURPOSE (OMP_CLAUSE_DECL (c)) 7063 && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c))) 7064 == TREE_VEC)) 7065 TREE_VALUE (OMP_CLAUSE_DECL (c)) = t; 7066 else 7067 OMP_CLAUSE_DECL (c) = t; 7068 } 7069 } 7070 break; 7071 7072 case OMP_CLAUSE_MAP: 7073 case OMP_CLAUSE_TO: 7074 case OMP_CLAUSE_FROM: 7075 case OMP_CLAUSE__CACHE_: 7076 t = OMP_CLAUSE_DECL (c); 7077 if (TREE_CODE (t) == TREE_LIST) 7078 { 7079 if (handle_omp_array_sections (c, ort)) 7080 remove = true; 7081 else 7082 { 7083 t = OMP_CLAUSE_DECL (c); 7084 if (TREE_CODE (t) != TREE_LIST 7085 && !type_dependent_expression_p (t) 7086 && !cp_omp_mappable_type (TREE_TYPE (t))) 7087 { 7088 error_at (OMP_CLAUSE_LOCATION (c), 7089 "array section does not have mappable type " 7090 "in %qs clause", 7091 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7092 remove = true; 7093 } 7094 while (TREE_CODE (t) == ARRAY_REF) 7095 t = TREE_OPERAND (t, 0); 7096 if (TREE_CODE (t) == COMPONENT_REF 7097 && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) 7098 { 7099 while (TREE_CODE (t) == COMPONENT_REF) 7100 t = TREE_OPERAND (t, 0); 7101 if (REFERENCE_REF_P (t)) 7102 t = TREE_OPERAND (t, 0); 7103 if (bitmap_bit_p (&map_field_head, DECL_UID (t))) 7104 break; 7105 if (bitmap_bit_p (&map_head, DECL_UID (t))) 7106 { 7107 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) 7108 error_at (OMP_CLAUSE_LOCATION (c), 7109 "%qD appears more than once in motion" 7110 " clauses", t); 7111 else if (ort == C_ORT_ACC) 7112 error_at (OMP_CLAUSE_LOCATION (c), 7113 "%qD appears more than once in data" 7114 " clauses", t); 7115 else 7116 error_at (OMP_CLAUSE_LOCATION (c), 7117 "%qD appears more than once in map" 7118 " clauses", t); 7119 remove = true; 7120 } 7121 else 7122 { 7123 bitmap_set_bit (&map_head, DECL_UID (t)); 7124 bitmap_set_bit (&map_field_head, DECL_UID (t)); 7125 } 7126 } 7127 } 7128 break; 7129 } 7130 if (t == error_mark_node) 7131 { 7132 remove = true; 7133 break; 7134 } 7135 if (REFERENCE_REF_P (t) 7136 && TREE_CODE (TREE_OPERAND (t, 0)) == COMPONENT_REF) 7137 { 7138 t = TREE_OPERAND (t, 0); 7139 OMP_CLAUSE_DECL (c) = t; 7140 } 7141 if (TREE_CODE (t) == COMPONENT_REF 7142 && (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP 7143 && OMP_CLAUSE_CODE (c) != OMP_CLAUSE__CACHE_) 7144 { 7145 if (type_dependent_expression_p (t)) 7146 break; 7147 if (TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL 7148 && DECL_BIT_FIELD (TREE_OPERAND (t, 1))) 7149 { 7150 error_at (OMP_CLAUSE_LOCATION (c), 7151 "bit-field %qE in %qs clause", 7152 t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7153 remove = true; 7154 } 7155 else if (!cp_omp_mappable_type (TREE_TYPE (t))) 7156 { 7157 error_at (OMP_CLAUSE_LOCATION (c), 7158 "%qE does not have a mappable type in %qs clause", 7159 t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7160 remove = true; 7161 } 7162 while (TREE_CODE (t) == COMPONENT_REF) 7163 { 7164 if (TREE_TYPE (TREE_OPERAND (t, 0)) 7165 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) 7166 == UNION_TYPE)) 7167 { 7168 error_at (OMP_CLAUSE_LOCATION (c), 7169 "%qE is a member of a union", t); 7170 remove = true; 7171 break; 7172 } 7173 t = TREE_OPERAND (t, 0); 7174 } 7175 if (remove) 7176 break; 7177 if (REFERENCE_REF_P (t)) 7178 t = TREE_OPERAND (t, 0); 7179 if (VAR_P (t) || TREE_CODE (t) == PARM_DECL) 7180 { 7181 if (bitmap_bit_p (&map_field_head, DECL_UID (t))) 7182 goto handle_map_references; 7183 } 7184 } 7185 if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) 7186 { 7187 if (processing_template_decl && TREE_CODE (t) != OVERLOAD) 7188 break; 7189 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP 7190 && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER 7191 || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER)) 7192 break; 7193 if (DECL_P (t)) 7194 error_at (OMP_CLAUSE_LOCATION (c), 7195 "%qD is not a variable in %qs clause", t, 7196 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7197 else 7198 error_at (OMP_CLAUSE_LOCATION (c), 7199 "%qE is not a variable in %qs clause", t, 7200 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7201 remove = true; 7202 } 7203 else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t)) 7204 { 7205 error_at (OMP_CLAUSE_LOCATION (c), 7206 "%qD is threadprivate variable in %qs clause", t, 7207 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7208 remove = true; 7209 } 7210 else if (ort != C_ORT_ACC && t == current_class_ptr) 7211 { 7212 error_at (OMP_CLAUSE_LOCATION (c), 7213 "%<this%> allowed in OpenMP only in %<declare simd%>" 7214 " clauses"); 7215 remove = true; 7216 break; 7217 } 7218 else if (!processing_template_decl 7219 && !TYPE_REF_P (TREE_TYPE (t)) 7220 && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP 7221 || (OMP_CLAUSE_MAP_KIND (c) 7222 != GOMP_MAP_FIRSTPRIVATE_POINTER)) 7223 && !cxx_mark_addressable (t)) 7224 remove = true; 7225 else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP 7226 && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER 7227 || (OMP_CLAUSE_MAP_KIND (c) 7228 == GOMP_MAP_FIRSTPRIVATE_POINTER))) 7229 && t == OMP_CLAUSE_DECL (c) 7230 && !type_dependent_expression_p (t) 7231 && !cp_omp_mappable_type (TYPE_REF_P (TREE_TYPE (t)) 7232 ? TREE_TYPE (TREE_TYPE (t)) 7233 : TREE_TYPE (t))) 7234 { 7235 error_at (OMP_CLAUSE_LOCATION (c), 7236 "%qD does not have a mappable type in %qs clause", t, 7237 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7238 remove = true; 7239 } 7240 else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP 7241 && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR 7242 && !type_dependent_expression_p (t) 7243 && !INDIRECT_TYPE_P (TREE_TYPE (t))) 7244 { 7245 error_at (OMP_CLAUSE_LOCATION (c), 7246 "%qD is not a pointer variable", t); 7247 remove = true; 7248 } 7249 else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP 7250 && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER) 7251 { 7252 if (bitmap_bit_p (&generic_head, DECL_UID (t)) 7253 || bitmap_bit_p (&firstprivate_head, DECL_UID (t))) 7254 { 7255 error_at (OMP_CLAUSE_LOCATION (c), 7256 "%qD appears more than once in data clauses", t); 7257 remove = true; 7258 } 7259 else if (bitmap_bit_p (&map_head, DECL_UID (t))) 7260 { 7261 if (ort == C_ORT_ACC) 7262 error_at (OMP_CLAUSE_LOCATION (c), 7263 "%qD appears more than once in data clauses", t); 7264 else 7265 error_at (OMP_CLAUSE_LOCATION (c), 7266 "%qD appears both in data and map clauses", t); 7267 remove = true; 7268 } 7269 else 7270 bitmap_set_bit (&generic_head, DECL_UID (t)); 7271 } 7272 else if (bitmap_bit_p (&map_head, DECL_UID (t))) 7273 { 7274 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) 7275 error_at (OMP_CLAUSE_LOCATION (c), 7276 "%qD appears more than once in motion clauses", t); 7277 if (ort == C_ORT_ACC) 7278 error_at (OMP_CLAUSE_LOCATION (c), 7279 "%qD appears more than once in data clauses", t); 7280 else 7281 error_at (OMP_CLAUSE_LOCATION (c), 7282 "%qD appears more than once in map clauses", t); 7283 remove = true; 7284 } 7285 else if (bitmap_bit_p (&generic_head, DECL_UID (t)) 7286 || bitmap_bit_p (&firstprivate_head, DECL_UID (t))) 7287 { 7288 if (ort == C_ORT_ACC) 7289 error_at (OMP_CLAUSE_LOCATION (c), 7290 "%qD appears more than once in data clauses", t); 7291 else 7292 error_at (OMP_CLAUSE_LOCATION (c), 7293 "%qD appears both in data and map clauses", t); 7294 remove = true; 7295 } 7296 else 7297 { 7298 bitmap_set_bit (&map_head, DECL_UID (t)); 7299 if (t != OMP_CLAUSE_DECL (c) 7300 && TREE_CODE (OMP_CLAUSE_DECL (c)) == COMPONENT_REF) 7301 bitmap_set_bit (&map_field_head, DECL_UID (t)); 7302 } 7303 handle_map_references: 7304 if (!remove 7305 && !processing_template_decl 7306 && ort != C_ORT_DECLARE_SIMD 7307 && TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))) 7308 { 7309 t = OMP_CLAUSE_DECL (c); 7310 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) 7311 { 7312 OMP_CLAUSE_DECL (c) = build_simple_mem_ref (t); 7313 if (OMP_CLAUSE_SIZE (c) == NULL_TREE) 7314 OMP_CLAUSE_SIZE (c) 7315 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))); 7316 } 7317 else if (OMP_CLAUSE_MAP_KIND (c) 7318 != GOMP_MAP_FIRSTPRIVATE_POINTER 7319 && (OMP_CLAUSE_MAP_KIND (c) 7320 != GOMP_MAP_FIRSTPRIVATE_REFERENCE) 7321 && (OMP_CLAUSE_MAP_KIND (c) 7322 != GOMP_MAP_ALWAYS_POINTER)) 7323 { 7324 tree c2 = build_omp_clause (OMP_CLAUSE_LOCATION (c), 7325 OMP_CLAUSE_MAP); 7326 if (TREE_CODE (t) == COMPONENT_REF) 7327 OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ALWAYS_POINTER); 7328 else 7329 OMP_CLAUSE_SET_MAP_KIND (c2, 7330 GOMP_MAP_FIRSTPRIVATE_REFERENCE); 7331 OMP_CLAUSE_DECL (c2) = t; 7332 OMP_CLAUSE_SIZE (c2) = size_zero_node; 7333 OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (c); 7334 OMP_CLAUSE_CHAIN (c) = c2; 7335 OMP_CLAUSE_DECL (c) = build_simple_mem_ref (t); 7336 if (OMP_CLAUSE_SIZE (c) == NULL_TREE) 7337 OMP_CLAUSE_SIZE (c) 7338 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))); 7339 c = c2; 7340 } 7341 } 7342 break; 7343 7344 case OMP_CLAUSE_TO_DECLARE: 7345 case OMP_CLAUSE_LINK: 7346 t = OMP_CLAUSE_DECL (c); 7347 if (TREE_CODE (t) == FUNCTION_DECL 7348 && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO_DECLARE) 7349 ; 7350 else if (!VAR_P (t)) 7351 { 7352 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO_DECLARE) 7353 { 7354 if (TREE_CODE (t) == TEMPLATE_ID_EXPR) 7355 error_at (OMP_CLAUSE_LOCATION (c), 7356 "template %qE in clause %qs", t, 7357 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7358 else if (really_overloaded_fn (t)) 7359 error_at (OMP_CLAUSE_LOCATION (c), 7360 "overloaded function name %qE in clause %qs", t, 7361 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7362 else 7363 error_at (OMP_CLAUSE_LOCATION (c), 7364 "%qE is neither a variable nor a function name " 7365 "in clause %qs", t, 7366 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7367 } 7368 else 7369 error_at (OMP_CLAUSE_LOCATION (c), 7370 "%qE is not a variable in clause %qs", t, 7371 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7372 remove = true; 7373 } 7374 else if (DECL_THREAD_LOCAL_P (t)) 7375 { 7376 error_at (OMP_CLAUSE_LOCATION (c), 7377 "%qD is threadprivate variable in %qs clause", t, 7378 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7379 remove = true; 7380 } 7381 else if (!cp_omp_mappable_type (TREE_TYPE (t))) 7382 { 7383 error_at (OMP_CLAUSE_LOCATION (c), 7384 "%qD does not have a mappable type in %qs clause", t, 7385 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7386 remove = true; 7387 } 7388 if (remove) 7389 break; 7390 if (bitmap_bit_p (&generic_head, DECL_UID (t))) 7391 { 7392 error_at (OMP_CLAUSE_LOCATION (c), 7393 "%qE appears more than once on the same " 7394 "%<declare target%> directive", t); 7395 remove = true; 7396 } 7397 else 7398 bitmap_set_bit (&generic_head, DECL_UID (t)); 7399 break; 7400 7401 case OMP_CLAUSE_UNIFORM: 7402 t = OMP_CLAUSE_DECL (c); 7403 if (TREE_CODE (t) != PARM_DECL) 7404 { 7405 if (processing_template_decl) 7406 break; 7407 if (DECL_P (t)) 7408 error_at (OMP_CLAUSE_LOCATION (c), 7409 "%qD is not an argument in %<uniform%> clause", t); 7410 else 7411 error_at (OMP_CLAUSE_LOCATION (c), 7412 "%qE is not an argument in %<uniform%> clause", t); 7413 remove = true; 7414 break; 7415 } 7416 /* map_head bitmap is used as uniform_head if declare_simd. */ 7417 bitmap_set_bit (&map_head, DECL_UID (t)); 7418 goto check_dup_generic; 7419 7420 case OMP_CLAUSE_GRAINSIZE: 7421 t = OMP_CLAUSE_GRAINSIZE_EXPR (c); 7422 if (t == error_mark_node) 7423 remove = true; 7424 else if (!type_dependent_expression_p (t) 7425 && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 7426 { 7427 error_at (OMP_CLAUSE_LOCATION (c), 7428 "%<grainsize%> expression must be integral"); 7429 remove = true; 7430 } 7431 else 7432 { 7433 t = mark_rvalue_use (t); 7434 if (!processing_template_decl) 7435 { 7436 t = maybe_constant_value (t); 7437 if (TREE_CODE (t) == INTEGER_CST 7438 && tree_int_cst_sgn (t) != 1) 7439 { 7440 warning_at (OMP_CLAUSE_LOCATION (c), 0, 7441 "%<grainsize%> value must be positive"); 7442 t = integer_one_node; 7443 } 7444 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 7445 } 7446 OMP_CLAUSE_GRAINSIZE_EXPR (c) = t; 7447 } 7448 break; 7449 7450 case OMP_CLAUSE_PRIORITY: 7451 t = OMP_CLAUSE_PRIORITY_EXPR (c); 7452 if (t == error_mark_node) 7453 remove = true; 7454 else if (!type_dependent_expression_p (t) 7455 && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 7456 { 7457 error_at (OMP_CLAUSE_LOCATION (c), 7458 "%<priority%> expression must be integral"); 7459 remove = true; 7460 } 7461 else 7462 { 7463 t = mark_rvalue_use (t); 7464 if (!processing_template_decl) 7465 { 7466 t = maybe_constant_value (t); 7467 if (TREE_CODE (t) == INTEGER_CST 7468 && tree_int_cst_sgn (t) == -1) 7469 { 7470 warning_at (OMP_CLAUSE_LOCATION (c), 0, 7471 "%<priority%> value must be non-negative"); 7472 t = integer_one_node; 7473 } 7474 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 7475 } 7476 OMP_CLAUSE_PRIORITY_EXPR (c) = t; 7477 } 7478 break; 7479 7480 case OMP_CLAUSE_HINT: 7481 t = OMP_CLAUSE_HINT_EXPR (c); 7482 if (t == error_mark_node) 7483 remove = true; 7484 else if (!type_dependent_expression_p (t) 7485 && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 7486 { 7487 error_at (OMP_CLAUSE_LOCATION (c), 7488 "%<hint%> expression must be integral"); 7489 remove = true; 7490 } 7491 else 7492 { 7493 t = mark_rvalue_use (t); 7494 if (!processing_template_decl) 7495 { 7496 t = maybe_constant_value (t); 7497 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 7498 if (TREE_CODE (t) != INTEGER_CST) 7499 { 7500 error_at (OMP_CLAUSE_LOCATION (c), 7501 "%<hint%> expression must be constant integer " 7502 "expression"); 7503 remove = true; 7504 } 7505 } 7506 OMP_CLAUSE_HINT_EXPR (c) = t; 7507 } 7508 break; 7509 7510 case OMP_CLAUSE_IS_DEVICE_PTR: 7511 case OMP_CLAUSE_USE_DEVICE_PTR: 7512 field_ok = (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP; 7513 t = OMP_CLAUSE_DECL (c); 7514 if (!type_dependent_expression_p (t)) 7515 { 7516 tree type = TREE_TYPE (t); 7517 if (!TYPE_PTR_P (type) 7518 && TREE_CODE (type) != ARRAY_TYPE 7519 && (!TYPE_REF_P (type) 7520 || (!TYPE_PTR_P (TREE_TYPE (type)) 7521 && TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))) 7522 { 7523 error_at (OMP_CLAUSE_LOCATION (c), 7524 "%qs variable is neither a pointer, nor an array " 7525 "nor reference to pointer or array", 7526 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7527 remove = true; 7528 } 7529 } 7530 goto check_dup_generic; 7531 7532 case OMP_CLAUSE_NOWAIT: 7533 case OMP_CLAUSE_DEFAULT: 7534 case OMP_CLAUSE_UNTIED: 7535 case OMP_CLAUSE_COLLAPSE: 7536 case OMP_CLAUSE_MERGEABLE: 7537 case OMP_CLAUSE_PARALLEL: 7538 case OMP_CLAUSE_FOR: 7539 case OMP_CLAUSE_SECTIONS: 7540 case OMP_CLAUSE_TASKGROUP: 7541 case OMP_CLAUSE_PROC_BIND: 7542 case OMP_CLAUSE_NOGROUP: 7543 case OMP_CLAUSE_THREADS: 7544 case OMP_CLAUSE_SIMD: 7545 case OMP_CLAUSE_DEFAULTMAP: 7546 case OMP_CLAUSE_AUTO: 7547 case OMP_CLAUSE_INDEPENDENT: 7548 case OMP_CLAUSE_SEQ: 7549 case OMP_CLAUSE_IF_PRESENT: 7550 case OMP_CLAUSE_FINALIZE: 7551 break; 7552 7553 case OMP_CLAUSE_TILE: 7554 for (tree list = OMP_CLAUSE_TILE_LIST (c); !remove && list; 7555 list = TREE_CHAIN (list)) 7556 { 7557 t = TREE_VALUE (list); 7558 7559 if (t == error_mark_node) 7560 remove = true; 7561 else if (!type_dependent_expression_p (t) 7562 && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 7563 { 7564 error_at (OMP_CLAUSE_LOCATION (c), 7565 "%<tile%> argument needs integral type"); 7566 remove = true; 7567 } 7568 else 7569 { 7570 t = mark_rvalue_use (t); 7571 if (!processing_template_decl) 7572 { 7573 /* Zero is used to indicate '*', we permit you 7574 to get there via an ICE of value zero. */ 7575 t = maybe_constant_value (t); 7576 if (!tree_fits_shwi_p (t) 7577 || tree_to_shwi (t) < 0) 7578 { 7579 error_at (OMP_CLAUSE_LOCATION (c), 7580 "%<tile%> argument needs positive " 7581 "integral constant"); 7582 remove = true; 7583 } 7584 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 7585 } 7586 } 7587 7588 /* Update list item. */ 7589 TREE_VALUE (list) = t; 7590 } 7591 break; 7592 7593 case OMP_CLAUSE_ORDERED: 7594 ordered_seen = true; 7595 break; 7596 7597 case OMP_CLAUSE_INBRANCH: 7598 case OMP_CLAUSE_NOTINBRANCH: 7599 if (branch_seen) 7600 { 7601 error_at (OMP_CLAUSE_LOCATION (c), 7602 "%<inbranch%> clause is incompatible with " 7603 "%<notinbranch%>"); 7604 remove = true; 7605 } 7606 branch_seen = true; 7607 break; 7608 7609 default: 7610 gcc_unreachable (); 7611 } 7612 7613 if (remove) 7614 *pc = OMP_CLAUSE_CHAIN (c); 7615 else 7616 pc = &OMP_CLAUSE_CHAIN (c); 7617 } 7618 7619 for (pc = &clauses, c = clauses; c ; c = *pc) 7620 { 7621 enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c); 7622 bool remove = false; 7623 bool need_complete_type = false; 7624 bool need_default_ctor = false; 7625 bool need_copy_ctor = false; 7626 bool need_copy_assignment = false; 7627 bool need_implicitly_determined = false; 7628 bool need_dtor = false; 7629 tree type, inner_type; 7630 7631 switch (c_kind) 7632 { 7633 case OMP_CLAUSE_SHARED: 7634 need_implicitly_determined = true; 7635 break; 7636 case OMP_CLAUSE_PRIVATE: 7637 need_complete_type = true; 7638 need_default_ctor = true; 7639 need_dtor = true; 7640 need_implicitly_determined = true; 7641 break; 7642 case OMP_CLAUSE_FIRSTPRIVATE: 7643 need_complete_type = true; 7644 need_copy_ctor = true; 7645 need_dtor = true; 7646 need_implicitly_determined = true; 7647 break; 7648 case OMP_CLAUSE_LASTPRIVATE: 7649 need_complete_type = true; 7650 need_copy_assignment = true; 7651 need_implicitly_determined = true; 7652 break; 7653 case OMP_CLAUSE_REDUCTION: 7654 case OMP_CLAUSE_IN_REDUCTION: 7655 case OMP_CLAUSE_TASK_REDUCTION: 7656 need_implicitly_determined = true; 7657 break; 7658 case OMP_CLAUSE_LINEAR: 7659 if (ort != C_ORT_OMP_DECLARE_SIMD) 7660 need_implicitly_determined = true; 7661 else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) 7662 && !bitmap_bit_p (&map_head, 7663 DECL_UID (OMP_CLAUSE_LINEAR_STEP (c)))) 7664 { 7665 error_at (OMP_CLAUSE_LOCATION (c), 7666 "%<linear%> clause step is a parameter %qD not " 7667 "specified in %<uniform%> clause", 7668 OMP_CLAUSE_LINEAR_STEP (c)); 7669 *pc = OMP_CLAUSE_CHAIN (c); 7670 continue; 7671 } 7672 break; 7673 case OMP_CLAUSE_COPYPRIVATE: 7674 need_copy_assignment = true; 7675 break; 7676 case OMP_CLAUSE_COPYIN: 7677 need_copy_assignment = true; 7678 break; 7679 case OMP_CLAUSE_SIMDLEN: 7680 if (safelen 7681 && !processing_template_decl 7682 && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen), 7683 OMP_CLAUSE_SIMDLEN_EXPR (c))) 7684 { 7685 error_at (OMP_CLAUSE_LOCATION (c), 7686 "%<simdlen%> clause value is bigger than " 7687 "%<safelen%> clause value"); 7688 OMP_CLAUSE_SIMDLEN_EXPR (c) 7689 = OMP_CLAUSE_SAFELEN_EXPR (safelen); 7690 } 7691 pc = &OMP_CLAUSE_CHAIN (c); 7692 continue; 7693 case OMP_CLAUSE_SCHEDULE: 7694 if (ordered_seen 7695 && (OMP_CLAUSE_SCHEDULE_KIND (c) 7696 & OMP_CLAUSE_SCHEDULE_NONMONOTONIC)) 7697 { 7698 error_at (OMP_CLAUSE_LOCATION (c), 7699 "%<nonmonotonic%> schedule modifier specified " 7700 "together with %<ordered%> clause"); 7701 OMP_CLAUSE_SCHEDULE_KIND (c) 7702 = (enum omp_clause_schedule_kind) 7703 (OMP_CLAUSE_SCHEDULE_KIND (c) 7704 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC); 7705 } 7706 pc = &OMP_CLAUSE_CHAIN (c); 7707 continue; 7708 case OMP_CLAUSE_NOGROUP: 7709 if (reduction_seen) 7710 { 7711 error_at (OMP_CLAUSE_LOCATION (c), 7712 "%<nogroup%> clause must not be used together with " 7713 "%<reduction%> clause"); 7714 *pc = OMP_CLAUSE_CHAIN (c); 7715 continue; 7716 } 7717 pc = &OMP_CLAUSE_CHAIN (c); 7718 continue; 7719 case OMP_CLAUSE_NOWAIT: 7720 if (copyprivate_seen) 7721 { 7722 error_at (OMP_CLAUSE_LOCATION (c), 7723 "%<nowait%> clause must not be used together " 7724 "with %<copyprivate%>"); 7725 *pc = OMP_CLAUSE_CHAIN (c); 7726 continue; 7727 } 7728 /* FALLTHRU */ 7729 default: 7730 pc = &OMP_CLAUSE_CHAIN (c); 7731 continue; 7732 } 7733 7734 t = OMP_CLAUSE_DECL (c); 7735 if (processing_template_decl 7736 && !VAR_P (t) && TREE_CODE (t) != PARM_DECL) 7737 { 7738 pc = &OMP_CLAUSE_CHAIN (c); 7739 continue; 7740 } 7741 7742 switch (c_kind) 7743 { 7744 case OMP_CLAUSE_LASTPRIVATE: 7745 if (!bitmap_bit_p (&firstprivate_head, DECL_UID (t))) 7746 { 7747 need_default_ctor = true; 7748 need_dtor = true; 7749 } 7750 break; 7751 7752 case OMP_CLAUSE_REDUCTION: 7753 case OMP_CLAUSE_IN_REDUCTION: 7754 case OMP_CLAUSE_TASK_REDUCTION: 7755 if (finish_omp_reduction_clause (c, &need_default_ctor, 7756 &need_dtor)) 7757 remove = true; 7758 else 7759 t = OMP_CLAUSE_DECL (c); 7760 break; 7761 7762 case OMP_CLAUSE_COPYIN: 7763 if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t)) 7764 { 7765 error_at (OMP_CLAUSE_LOCATION (c), 7766 "%qE must be %<threadprivate%> for %<copyin%>", t); 7767 remove = true; 7768 } 7769 break; 7770 7771 default: 7772 break; 7773 } 7774 7775 if (need_complete_type || need_copy_assignment) 7776 { 7777 t = require_complete_type (t); 7778 if (t == error_mark_node) 7779 remove = true; 7780 else if (!processing_template_decl 7781 && TYPE_REF_P (TREE_TYPE (t)) 7782 && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t)) 7783 remove = true; 7784 } 7785 if (need_implicitly_determined) 7786 { 7787 const char *share_name = NULL; 7788 7789 if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t)) 7790 share_name = "threadprivate"; 7791 else switch (cxx_omp_predetermined_sharing_1 (t)) 7792 { 7793 case OMP_CLAUSE_DEFAULT_UNSPECIFIED: 7794 break; 7795 case OMP_CLAUSE_DEFAULT_SHARED: 7796 if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED 7797 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE) 7798 && c_omp_predefined_variable (t)) 7799 /* The __func__ variable and similar function-local predefined 7800 variables may be listed in a shared or firstprivate 7801 clause. */ 7802 break; 7803 if (VAR_P (t) 7804 && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE 7805 && TREE_STATIC (t) 7806 && cxx_omp_const_qual_no_mutable (t)) 7807 { 7808 tree ctx = CP_DECL_CONTEXT (t); 7809 /* const qualified static data members without mutable 7810 member may be specified in firstprivate clause. */ 7811 if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx)) 7812 break; 7813 } 7814 share_name = "shared"; 7815 break; 7816 case OMP_CLAUSE_DEFAULT_PRIVATE: 7817 share_name = "private"; 7818 break; 7819 default: 7820 gcc_unreachable (); 7821 } 7822 if (share_name) 7823 { 7824 error_at (OMP_CLAUSE_LOCATION (c), 7825 "%qE is predetermined %qs for %qs", 7826 omp_clause_printable_decl (t), share_name, 7827 omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7828 remove = true; 7829 } 7830 else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED 7831 && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE 7832 && cxx_omp_const_qual_no_mutable (t)) 7833 { 7834 error_at (OMP_CLAUSE_LOCATION (c), 7835 "%<const%> qualified %qE without %<mutable%> member " 7836 "may appear only in %<shared%> or %<firstprivate%> " 7837 "clauses", omp_clause_printable_decl (t)); 7838 remove = true; 7839 } 7840 } 7841 7842 /* We're interested in the base element, not arrays. */ 7843 inner_type = type = TREE_TYPE (t); 7844 if ((need_complete_type 7845 || need_copy_assignment 7846 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION 7847 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION 7848 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) 7849 && TYPE_REF_P (inner_type)) 7850 inner_type = TREE_TYPE (inner_type); 7851 while (TREE_CODE (inner_type) == ARRAY_TYPE) 7852 inner_type = TREE_TYPE (inner_type); 7853 7854 /* Check for special function availability by building a call to one. 7855 Save the results, because later we won't be in the right context 7856 for making these queries. */ 7857 if (CLASS_TYPE_P (inner_type) 7858 && COMPLETE_TYPE_P (inner_type) 7859 && (need_default_ctor || need_copy_ctor 7860 || need_copy_assignment || need_dtor) 7861 && !type_dependent_expression_p (t) 7862 && cxx_omp_create_clause_info (c, inner_type, need_default_ctor, 7863 need_copy_ctor, need_copy_assignment, 7864 need_dtor)) 7865 remove = true; 7866 7867 if (!remove 7868 && c_kind == OMP_CLAUSE_SHARED 7869 && processing_template_decl) 7870 { 7871 t = omp_clause_decl_field (OMP_CLAUSE_DECL (c)); 7872 if (t) 7873 OMP_CLAUSE_DECL (c) = t; 7874 } 7875 7876 if (remove) 7877 *pc = OMP_CLAUSE_CHAIN (c); 7878 else 7879 pc = &OMP_CLAUSE_CHAIN (c); 7880 } 7881 7882 bitmap_obstack_release (NULL); 7883 return clauses; 7884 } 7885 7886 /* Start processing OpenMP clauses that can include any 7887 privatization clauses for non-static data members. */ 7888 7889 tree 7890 push_omp_privatization_clauses (bool ignore_next) 7891 { 7892 if (omp_private_member_ignore_next) 7893 { 7894 omp_private_member_ignore_next = ignore_next; 7895 return NULL_TREE; 7896 } 7897 omp_private_member_ignore_next = ignore_next; 7898 if (omp_private_member_map) 7899 omp_private_member_vec.safe_push (error_mark_node); 7900 return push_stmt_list (); 7901 } 7902 7903 /* Revert remapping of any non-static data members since 7904 the last push_omp_privatization_clauses () call. */ 7905 7906 void 7907 pop_omp_privatization_clauses (tree stmt) 7908 { 7909 if (stmt == NULL_TREE) 7910 return; 7911 stmt = pop_stmt_list (stmt); 7912 if (omp_private_member_map) 7913 { 7914 while (!omp_private_member_vec.is_empty ()) 7915 { 7916 tree t = omp_private_member_vec.pop (); 7917 if (t == error_mark_node) 7918 { 7919 add_stmt (stmt); 7920 return; 7921 } 7922 bool no_decl_expr = t == integer_zero_node; 7923 if (no_decl_expr) 7924 t = omp_private_member_vec.pop (); 7925 tree *v = omp_private_member_map->get (t); 7926 gcc_assert (v); 7927 if (!no_decl_expr) 7928 add_decl_expr (*v); 7929 omp_private_member_map->remove (t); 7930 } 7931 delete omp_private_member_map; 7932 omp_private_member_map = NULL; 7933 } 7934 add_stmt (stmt); 7935 } 7936 7937 /* Remember OpenMP privatization clauses mapping and clear it. 7938 Used for lambdas. */ 7939 7940 void 7941 save_omp_privatization_clauses (vec<tree> &save) 7942 { 7943 save = vNULL; 7944 if (omp_private_member_ignore_next) 7945 save.safe_push (integer_one_node); 7946 omp_private_member_ignore_next = false; 7947 if (!omp_private_member_map) 7948 return; 7949 7950 while (!omp_private_member_vec.is_empty ()) 7951 { 7952 tree t = omp_private_member_vec.pop (); 7953 if (t == error_mark_node) 7954 { 7955 save.safe_push (t); 7956 continue; 7957 } 7958 tree n = t; 7959 if (t == integer_zero_node) 7960 t = omp_private_member_vec.pop (); 7961 tree *v = omp_private_member_map->get (t); 7962 gcc_assert (v); 7963 save.safe_push (*v); 7964 save.safe_push (t); 7965 if (n != t) 7966 save.safe_push (n); 7967 } 7968 delete omp_private_member_map; 7969 omp_private_member_map = NULL; 7970 } 7971 7972 /* Restore OpenMP privatization clauses mapping saved by the 7973 above function. */ 7974 7975 void 7976 restore_omp_privatization_clauses (vec<tree> &save) 7977 { 7978 gcc_assert (omp_private_member_vec.is_empty ()); 7979 omp_private_member_ignore_next = false; 7980 if (save.is_empty ()) 7981 return; 7982 if (save.length () == 1 && save[0] == integer_one_node) 7983 { 7984 omp_private_member_ignore_next = true; 7985 save.release (); 7986 return; 7987 } 7988 7989 omp_private_member_map = new hash_map <tree, tree>; 7990 while (!save.is_empty ()) 7991 { 7992 tree t = save.pop (); 7993 tree n = t; 7994 if (t != error_mark_node) 7995 { 7996 if (t == integer_one_node) 7997 { 7998 omp_private_member_ignore_next = true; 7999 gcc_assert (save.is_empty ()); 8000 break; 8001 } 8002 if (t == integer_zero_node) 8003 t = save.pop (); 8004 tree &v = omp_private_member_map->get_or_insert (t); 8005 v = save.pop (); 8006 } 8007 omp_private_member_vec.safe_push (t); 8008 if (n != t) 8009 omp_private_member_vec.safe_push (n); 8010 } 8011 save.release (); 8012 } 8013 8014 /* For all variables in the tree_list VARS, mark them as thread local. */ 8015 8016 void 8017 finish_omp_threadprivate (tree vars) 8018 { 8019 tree t; 8020 8021 /* Mark every variable in VARS to be assigned thread local storage. */ 8022 for (t = vars; t; t = TREE_CHAIN (t)) 8023 { 8024 tree v = TREE_PURPOSE (t); 8025 8026 if (error_operand_p (v)) 8027 ; 8028 else if (!VAR_P (v)) 8029 error ("%<threadprivate%> %qD is not file, namespace " 8030 "or block scope variable", v); 8031 /* If V had already been marked threadprivate, it doesn't matter 8032 whether it had been used prior to this point. */ 8033 else if (TREE_USED (v) 8034 && (DECL_LANG_SPECIFIC (v) == NULL 8035 || !CP_DECL_THREADPRIVATE_P (v))) 8036 error ("%qE declared %<threadprivate%> after first use", v); 8037 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v)) 8038 error ("automatic variable %qE cannot be %<threadprivate%>", v); 8039 else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v)))) 8040 error ("%<threadprivate%> %qE has incomplete type", v); 8041 else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v)) 8042 && CP_DECL_CONTEXT (v) != current_class_type) 8043 error ("%<threadprivate%> %qE directive not " 8044 "in %qT definition", v, CP_DECL_CONTEXT (v)); 8045 else 8046 { 8047 /* Allocate a LANG_SPECIFIC structure for V, if needed. */ 8048 if (DECL_LANG_SPECIFIC (v) == NULL) 8049 retrofit_lang_decl (v); 8050 8051 if (! CP_DECL_THREAD_LOCAL_P (v)) 8052 { 8053 CP_DECL_THREAD_LOCAL_P (v) = true; 8054 set_decl_tls_model (v, decl_default_tls_model (v)); 8055 /* If rtl has been already set for this var, call 8056 make_decl_rtl once again, so that encode_section_info 8057 has a chance to look at the new decl flags. */ 8058 if (DECL_RTL_SET_P (v)) 8059 make_decl_rtl (v); 8060 } 8061 CP_DECL_THREADPRIVATE_P (v) = 1; 8062 } 8063 } 8064 } 8065 8066 /* Build an OpenMP structured block. */ 8067 8068 tree 8069 begin_omp_structured_block (void) 8070 { 8071 return do_pushlevel (sk_omp); 8072 } 8073 8074 tree 8075 finish_omp_structured_block (tree block) 8076 { 8077 return do_poplevel (block); 8078 } 8079 8080 /* Similarly, except force the retention of the BLOCK. */ 8081 8082 tree 8083 begin_omp_parallel (void) 8084 { 8085 keep_next_level (true); 8086 return begin_omp_structured_block (); 8087 } 8088 8089 /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound 8090 statement. */ 8091 8092 tree 8093 finish_oacc_data (tree clauses, tree block) 8094 { 8095 tree stmt; 8096 8097 block = finish_omp_structured_block (block); 8098 8099 stmt = make_node (OACC_DATA); 8100 TREE_TYPE (stmt) = void_type_node; 8101 OACC_DATA_CLAUSES (stmt) = clauses; 8102 OACC_DATA_BODY (stmt) = block; 8103 8104 return add_stmt (stmt); 8105 } 8106 8107 /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound 8108 statement. */ 8109 8110 tree 8111 finish_oacc_host_data (tree clauses, tree block) 8112 { 8113 tree stmt; 8114 8115 block = finish_omp_structured_block (block); 8116 8117 stmt = make_node (OACC_HOST_DATA); 8118 TREE_TYPE (stmt) = void_type_node; 8119 OACC_HOST_DATA_CLAUSES (stmt) = clauses; 8120 OACC_HOST_DATA_BODY (stmt) = block; 8121 8122 return add_stmt (stmt); 8123 } 8124 8125 /* Generate OMP construct CODE, with BODY and CLAUSES as its compound 8126 statement. */ 8127 8128 tree 8129 finish_omp_construct (enum tree_code code, tree body, tree clauses) 8130 { 8131 body = finish_omp_structured_block (body); 8132 8133 tree stmt = make_node (code); 8134 TREE_TYPE (stmt) = void_type_node; 8135 OMP_BODY (stmt) = body; 8136 OMP_CLAUSES (stmt) = clauses; 8137 8138 return add_stmt (stmt); 8139 } 8140 8141 tree 8142 finish_omp_parallel (tree clauses, tree body) 8143 { 8144 tree stmt; 8145 8146 body = finish_omp_structured_block (body); 8147 8148 stmt = make_node (OMP_PARALLEL); 8149 TREE_TYPE (stmt) = void_type_node; 8150 OMP_PARALLEL_CLAUSES (stmt) = clauses; 8151 OMP_PARALLEL_BODY (stmt) = body; 8152 8153 return add_stmt (stmt); 8154 } 8155 8156 tree 8157 begin_omp_task (void) 8158 { 8159 keep_next_level (true); 8160 return begin_omp_structured_block (); 8161 } 8162 8163 tree 8164 finish_omp_task (tree clauses, tree body) 8165 { 8166 tree stmt; 8167 8168 body = finish_omp_structured_block (body); 8169 8170 stmt = make_node (OMP_TASK); 8171 TREE_TYPE (stmt) = void_type_node; 8172 OMP_TASK_CLAUSES (stmt) = clauses; 8173 OMP_TASK_BODY (stmt) = body; 8174 8175 return add_stmt (stmt); 8176 } 8177 8178 /* Helper function for finish_omp_for. Convert Ith random access iterator 8179 into integral iterator. Return FALSE if successful. */ 8180 8181 static bool 8182 handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code, 8183 tree declv, tree orig_declv, tree initv, 8184 tree condv, tree incrv, tree *body, 8185 tree *pre_body, tree &clauses, 8186 int collapse, int ordered) 8187 { 8188 tree diff, iter_init, iter_incr = NULL, last; 8189 tree incr_var = NULL, orig_pre_body, orig_body, c; 8190 tree decl = TREE_VEC_ELT (declv, i); 8191 tree init = TREE_VEC_ELT (initv, i); 8192 tree cond = TREE_VEC_ELT (condv, i); 8193 tree incr = TREE_VEC_ELT (incrv, i); 8194 tree iter = decl; 8195 location_t elocus = locus; 8196 8197 if (init && EXPR_HAS_LOCATION (init)) 8198 elocus = EXPR_LOCATION (init); 8199 8200 switch (TREE_CODE (cond)) 8201 { 8202 case GT_EXPR: 8203 case GE_EXPR: 8204 case LT_EXPR: 8205 case LE_EXPR: 8206 case NE_EXPR: 8207 if (TREE_OPERAND (cond, 1) == iter) 8208 cond = build2 (swap_tree_comparison (TREE_CODE (cond)), 8209 TREE_TYPE (cond), iter, TREE_OPERAND (cond, 0)); 8210 if (TREE_OPERAND (cond, 0) != iter) 8211 cond = error_mark_node; 8212 else 8213 { 8214 tree tem = build_x_binary_op (EXPR_LOCATION (cond), 8215 TREE_CODE (cond), 8216 iter, ERROR_MARK, 8217 TREE_OPERAND (cond, 1), ERROR_MARK, 8218 NULL, tf_warning_or_error); 8219 if (error_operand_p (tem)) 8220 return true; 8221 } 8222 break; 8223 default: 8224 cond = error_mark_node; 8225 break; 8226 } 8227 if (cond == error_mark_node) 8228 { 8229 error_at (elocus, "invalid controlling predicate"); 8230 return true; 8231 } 8232 diff = build_x_binary_op (elocus, MINUS_EXPR, TREE_OPERAND (cond, 1), 8233 ERROR_MARK, iter, ERROR_MARK, NULL, 8234 tf_warning_or_error); 8235 diff = cp_fully_fold (diff); 8236 if (error_operand_p (diff)) 8237 return true; 8238 if (TREE_CODE (TREE_TYPE (diff)) != INTEGER_TYPE) 8239 { 8240 error_at (elocus, "difference between %qE and %qD does not have integer type", 8241 TREE_OPERAND (cond, 1), iter); 8242 return true; 8243 } 8244 if (!c_omp_check_loop_iv_exprs (locus, orig_declv, 8245 TREE_VEC_ELT (declv, i), NULL_TREE, 8246 cond, cp_walk_subtrees)) 8247 return true; 8248 8249 switch (TREE_CODE (incr)) 8250 { 8251 case PREINCREMENT_EXPR: 8252 case PREDECREMENT_EXPR: 8253 case POSTINCREMENT_EXPR: 8254 case POSTDECREMENT_EXPR: 8255 if (TREE_OPERAND (incr, 0) != iter) 8256 { 8257 incr = error_mark_node; 8258 break; 8259 } 8260 iter_incr = build_x_unary_op (EXPR_LOCATION (incr), 8261 TREE_CODE (incr), iter, 8262 tf_warning_or_error); 8263 if (error_operand_p (iter_incr)) 8264 return true; 8265 else if (TREE_CODE (incr) == PREINCREMENT_EXPR 8266 || TREE_CODE (incr) == POSTINCREMENT_EXPR) 8267 incr = integer_one_node; 8268 else 8269 incr = integer_minus_one_node; 8270 break; 8271 case MODIFY_EXPR: 8272 if (TREE_OPERAND (incr, 0) != iter) 8273 incr = error_mark_node; 8274 else if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR 8275 || TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR) 8276 { 8277 tree rhs = TREE_OPERAND (incr, 1); 8278 if (TREE_OPERAND (rhs, 0) == iter) 8279 { 8280 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 1))) 8281 != INTEGER_TYPE) 8282 incr = error_mark_node; 8283 else 8284 { 8285 iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs), 8286 iter, TREE_CODE (rhs), 8287 TREE_OPERAND (rhs, 1), 8288 tf_warning_or_error); 8289 if (error_operand_p (iter_incr)) 8290 return true; 8291 incr = TREE_OPERAND (rhs, 1); 8292 incr = cp_convert (TREE_TYPE (diff), incr, 8293 tf_warning_or_error); 8294 if (TREE_CODE (rhs) == MINUS_EXPR) 8295 { 8296 incr = build1 (NEGATE_EXPR, TREE_TYPE (diff), incr); 8297 incr = fold_simple (incr); 8298 } 8299 if (TREE_CODE (incr) != INTEGER_CST 8300 && (TREE_CODE (incr) != NOP_EXPR 8301 || (TREE_CODE (TREE_OPERAND (incr, 0)) 8302 != INTEGER_CST))) 8303 iter_incr = NULL; 8304 } 8305 } 8306 else if (TREE_OPERAND (rhs, 1) == iter) 8307 { 8308 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) != INTEGER_TYPE 8309 || TREE_CODE (rhs) != PLUS_EXPR) 8310 incr = error_mark_node; 8311 else 8312 { 8313 iter_incr = build_x_binary_op (EXPR_LOCATION (rhs), 8314 PLUS_EXPR, 8315 TREE_OPERAND (rhs, 0), 8316 ERROR_MARK, iter, 8317 ERROR_MARK, NULL, 8318 tf_warning_or_error); 8319 if (error_operand_p (iter_incr)) 8320 return true; 8321 iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs), 8322 iter, NOP_EXPR, 8323 iter_incr, 8324 tf_warning_or_error); 8325 if (error_operand_p (iter_incr)) 8326 return true; 8327 incr = TREE_OPERAND (rhs, 0); 8328 iter_incr = NULL; 8329 } 8330 } 8331 else 8332 incr = error_mark_node; 8333 } 8334 else 8335 incr = error_mark_node; 8336 break; 8337 default: 8338 incr = error_mark_node; 8339 break; 8340 } 8341 8342 if (incr == error_mark_node) 8343 { 8344 error_at (elocus, "invalid increment expression"); 8345 return true; 8346 } 8347 8348 incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error); 8349 incr = cp_fully_fold (incr); 8350 bool taskloop_iv_seen = false; 8351 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c)) 8352 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE 8353 && OMP_CLAUSE_DECL (c) == iter) 8354 { 8355 if (code == OMP_TASKLOOP) 8356 { 8357 taskloop_iv_seen = true; 8358 OMP_CLAUSE_LASTPRIVATE_TASKLOOP_IV (c) = 1; 8359 } 8360 break; 8361 } 8362 else if (code == OMP_TASKLOOP 8363 && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE 8364 && OMP_CLAUSE_DECL (c) == iter) 8365 { 8366 taskloop_iv_seen = true; 8367 OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c) = 1; 8368 } 8369 8370 decl = create_temporary_var (TREE_TYPE (diff)); 8371 pushdecl (decl); 8372 add_decl_expr (decl); 8373 last = create_temporary_var (TREE_TYPE (diff)); 8374 pushdecl (last); 8375 add_decl_expr (last); 8376 if (c && iter_incr == NULL && TREE_CODE (incr) != INTEGER_CST 8377 && (!ordered || (i < collapse && collapse > 1))) 8378 { 8379 incr_var = create_temporary_var (TREE_TYPE (diff)); 8380 pushdecl (incr_var); 8381 add_decl_expr (incr_var); 8382 } 8383 gcc_assert (stmts_are_full_exprs_p ()); 8384 tree diffvar = NULL_TREE; 8385 if (code == OMP_TASKLOOP) 8386 { 8387 if (!taskloop_iv_seen) 8388 { 8389 tree ivc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE); 8390 OMP_CLAUSE_DECL (ivc) = iter; 8391 cxx_omp_finish_clause (ivc, NULL); 8392 OMP_CLAUSE_CHAIN (ivc) = clauses; 8393 clauses = ivc; 8394 } 8395 tree lvc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE); 8396 OMP_CLAUSE_DECL (lvc) = last; 8397 OMP_CLAUSE_CHAIN (lvc) = clauses; 8398 clauses = lvc; 8399 diffvar = create_temporary_var (TREE_TYPE (diff)); 8400 pushdecl (diffvar); 8401 add_decl_expr (diffvar); 8402 } 8403 8404 orig_pre_body = *pre_body; 8405 *pre_body = push_stmt_list (); 8406 if (orig_pre_body) 8407 add_stmt (orig_pre_body); 8408 if (init != NULL) 8409 finish_expr_stmt (build_x_modify_expr (elocus, 8410 iter, NOP_EXPR, init, 8411 tf_warning_or_error)); 8412 init = build_int_cst (TREE_TYPE (diff), 0); 8413 if (c && iter_incr == NULL 8414 && (!ordered || (i < collapse && collapse > 1))) 8415 { 8416 if (incr_var) 8417 { 8418 finish_expr_stmt (build_x_modify_expr (elocus, 8419 incr_var, NOP_EXPR, 8420 incr, tf_warning_or_error)); 8421 incr = incr_var; 8422 } 8423 iter_incr = build_x_modify_expr (elocus, 8424 iter, PLUS_EXPR, incr, 8425 tf_warning_or_error); 8426 } 8427 if (c && ordered && i < collapse && collapse > 1) 8428 iter_incr = incr; 8429 finish_expr_stmt (build_x_modify_expr (elocus, 8430 last, NOP_EXPR, init, 8431 tf_warning_or_error)); 8432 if (diffvar) 8433 { 8434 finish_expr_stmt (build_x_modify_expr (elocus, 8435 diffvar, NOP_EXPR, 8436 diff, tf_warning_or_error)); 8437 diff = diffvar; 8438 } 8439 *pre_body = pop_stmt_list (*pre_body); 8440 8441 cond = cp_build_binary_op (elocus, 8442 TREE_CODE (cond), decl, diff, 8443 tf_warning_or_error); 8444 incr = build_modify_expr (elocus, decl, NULL_TREE, PLUS_EXPR, 8445 elocus, incr, NULL_TREE); 8446 8447 orig_body = *body; 8448 *body = push_stmt_list (); 8449 iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last); 8450 iter_init = build_x_modify_expr (elocus, 8451 iter, PLUS_EXPR, iter_init, 8452 tf_warning_or_error); 8453 if (iter_init != error_mark_node) 8454 iter_init = build1 (NOP_EXPR, void_type_node, iter_init); 8455 finish_expr_stmt (iter_init); 8456 finish_expr_stmt (build_x_modify_expr (elocus, 8457 last, NOP_EXPR, decl, 8458 tf_warning_or_error)); 8459 add_stmt (orig_body); 8460 *body = pop_stmt_list (*body); 8461 8462 if (c) 8463 { 8464 OMP_CLAUSE_LASTPRIVATE_STMT (c) = push_stmt_list (); 8465 if (!ordered) 8466 finish_expr_stmt (iter_incr); 8467 else 8468 { 8469 iter_init = decl; 8470 if (i < collapse && collapse > 1 && !error_operand_p (iter_incr)) 8471 iter_init = build2 (PLUS_EXPR, TREE_TYPE (diff), 8472 iter_init, iter_incr); 8473 iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), iter_init, last); 8474 iter_init = build_x_modify_expr (elocus, 8475 iter, PLUS_EXPR, iter_init, 8476 tf_warning_or_error); 8477 if (iter_init != error_mark_node) 8478 iter_init = build1 (NOP_EXPR, void_type_node, iter_init); 8479 finish_expr_stmt (iter_init); 8480 } 8481 OMP_CLAUSE_LASTPRIVATE_STMT (c) 8482 = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c)); 8483 } 8484 8485 if (TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST) 8486 { 8487 tree t = TREE_VEC_ELT (orig_declv, i); 8488 gcc_assert (TREE_PURPOSE (t) == NULL_TREE 8489 && TREE_VALUE (t) == NULL_TREE 8490 && TREE_CODE (TREE_CHAIN (t)) == TREE_VEC); 8491 TREE_PURPOSE (t) = TREE_VEC_ELT (declv, i); 8492 TREE_VALUE (t) = last; 8493 } 8494 else 8495 TREE_VEC_ELT (orig_declv, i) 8496 = tree_cons (TREE_VEC_ELT (declv, i), last, NULL_TREE); 8497 TREE_VEC_ELT (declv, i) = decl; 8498 TREE_VEC_ELT (initv, i) = init; 8499 TREE_VEC_ELT (condv, i) = cond; 8500 TREE_VEC_ELT (incrv, i) = incr; 8501 8502 return false; 8503 } 8504 8505 /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR 8506 are directly for their associated operands in the statement. DECL 8507 and INIT are a combo; if DECL is NULL then INIT ought to be a 8508 MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are 8509 optional statements that need to go before the loop into its 8510 sk_omp scope. */ 8511 8512 tree 8513 finish_omp_for (location_t locus, enum tree_code code, tree declv, 8514 tree orig_declv, tree initv, tree condv, tree incrv, 8515 tree body, tree pre_body, vec<tree> *orig_inits, tree clauses) 8516 { 8517 tree omp_for = NULL, orig_incr = NULL; 8518 tree decl = NULL, init, cond, incr; 8519 location_t elocus; 8520 int i; 8521 int collapse = 1; 8522 int ordered = 0; 8523 8524 gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv)); 8525 gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv)); 8526 gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv)); 8527 if (TREE_VEC_LENGTH (declv) > 1) 8528 { 8529 tree c; 8530 8531 c = omp_find_clause (clauses, OMP_CLAUSE_TILE); 8532 if (c) 8533 collapse = list_length (OMP_CLAUSE_TILE_LIST (c)); 8534 else 8535 { 8536 c = omp_find_clause (clauses, OMP_CLAUSE_COLLAPSE); 8537 if (c) 8538 collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c)); 8539 if (collapse != TREE_VEC_LENGTH (declv)) 8540 ordered = TREE_VEC_LENGTH (declv); 8541 } 8542 } 8543 for (i = 0; i < TREE_VEC_LENGTH (declv); i++) 8544 { 8545 decl = TREE_VEC_ELT (declv, i); 8546 init = TREE_VEC_ELT (initv, i); 8547 cond = TREE_VEC_ELT (condv, i); 8548 incr = TREE_VEC_ELT (incrv, i); 8549 elocus = locus; 8550 8551 if (decl == NULL) 8552 { 8553 if (init != NULL) 8554 switch (TREE_CODE (init)) 8555 { 8556 case MODIFY_EXPR: 8557 decl = TREE_OPERAND (init, 0); 8558 init = TREE_OPERAND (init, 1); 8559 break; 8560 case MODOP_EXPR: 8561 if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR) 8562 { 8563 decl = TREE_OPERAND (init, 0); 8564 init = TREE_OPERAND (init, 2); 8565 } 8566 break; 8567 default: 8568 break; 8569 } 8570 8571 if (decl == NULL) 8572 { 8573 error_at (locus, 8574 "expected iteration declaration or initialization"); 8575 return NULL; 8576 } 8577 } 8578 8579 if (init && EXPR_HAS_LOCATION (init)) 8580 elocus = EXPR_LOCATION (init); 8581 8582 if (cond == global_namespace) 8583 continue; 8584 8585 if (cond == NULL) 8586 { 8587 error_at (elocus, "missing controlling predicate"); 8588 return NULL; 8589 } 8590 8591 if (incr == NULL) 8592 { 8593 error_at (elocus, "missing increment expression"); 8594 return NULL; 8595 } 8596 8597 TREE_VEC_ELT (declv, i) = decl; 8598 TREE_VEC_ELT (initv, i) = init; 8599 } 8600 8601 if (orig_inits) 8602 { 8603 bool fail = false; 8604 tree orig_init; 8605 FOR_EACH_VEC_ELT (*orig_inits, i, orig_init) 8606 if (orig_init 8607 && !c_omp_check_loop_iv_exprs (locus, orig_declv 8608 ? orig_declv : declv, 8609 TREE_VEC_ELT (declv, i), orig_init, 8610 NULL_TREE, cp_walk_subtrees)) 8611 fail = true; 8612 if (fail) 8613 return NULL; 8614 } 8615 8616 if (dependent_omp_for_p (declv, initv, condv, incrv)) 8617 { 8618 tree stmt; 8619 8620 stmt = make_node (code); 8621 8622 for (i = 0; i < TREE_VEC_LENGTH (declv); i++) 8623 { 8624 /* This is really just a place-holder. We'll be decomposing this 8625 again and going through the cp_build_modify_expr path below when 8626 we instantiate the thing. */ 8627 TREE_VEC_ELT (initv, i) 8628 = build2 (MODIFY_EXPR, void_type_node, TREE_VEC_ELT (declv, i), 8629 TREE_VEC_ELT (initv, i)); 8630 } 8631 8632 TREE_TYPE (stmt) = void_type_node; 8633 OMP_FOR_INIT (stmt) = initv; 8634 OMP_FOR_COND (stmt) = condv; 8635 OMP_FOR_INCR (stmt) = incrv; 8636 OMP_FOR_BODY (stmt) = body; 8637 OMP_FOR_PRE_BODY (stmt) = pre_body; 8638 OMP_FOR_CLAUSES (stmt) = clauses; 8639 8640 SET_EXPR_LOCATION (stmt, locus); 8641 return add_stmt (stmt); 8642 } 8643 8644 if (!orig_declv) 8645 orig_declv = copy_node (declv); 8646 8647 if (processing_template_decl) 8648 orig_incr = make_tree_vec (TREE_VEC_LENGTH (incrv)); 8649 8650 for (i = 0; i < TREE_VEC_LENGTH (declv); ) 8651 { 8652 decl = TREE_VEC_ELT (declv, i); 8653 init = TREE_VEC_ELT (initv, i); 8654 cond = TREE_VEC_ELT (condv, i); 8655 incr = TREE_VEC_ELT (incrv, i); 8656 if (orig_incr) 8657 TREE_VEC_ELT (orig_incr, i) = incr; 8658 elocus = locus; 8659 8660 if (init && EXPR_HAS_LOCATION (init)) 8661 elocus = EXPR_LOCATION (init); 8662 8663 if (!DECL_P (decl)) 8664 { 8665 error_at (elocus, "expected iteration declaration or initialization"); 8666 return NULL; 8667 } 8668 8669 if (incr && TREE_CODE (incr) == MODOP_EXPR) 8670 { 8671 if (orig_incr) 8672 TREE_VEC_ELT (orig_incr, i) = incr; 8673 incr = cp_build_modify_expr (elocus, TREE_OPERAND (incr, 0), 8674 TREE_CODE (TREE_OPERAND (incr, 1)), 8675 TREE_OPERAND (incr, 2), 8676 tf_warning_or_error); 8677 } 8678 8679 if (CLASS_TYPE_P (TREE_TYPE (decl))) 8680 { 8681 if (code == OMP_SIMD) 8682 { 8683 error_at (elocus, "%<#pragma omp simd%> used with class " 8684 "iteration variable %qE", decl); 8685 return NULL; 8686 } 8687 if (handle_omp_for_class_iterator (i, locus, code, declv, orig_declv, 8688 initv, condv, incrv, &body, 8689 &pre_body, clauses, 8690 collapse, ordered)) 8691 return NULL; 8692 continue; 8693 } 8694 8695 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl)) 8696 && !TYPE_PTR_P (TREE_TYPE (decl))) 8697 { 8698 error_at (elocus, "invalid type for iteration variable %qE", decl); 8699 return NULL; 8700 } 8701 8702 if (!processing_template_decl) 8703 { 8704 init = fold_build_cleanup_point_expr (TREE_TYPE (init), init); 8705 init = cp_build_modify_expr (elocus, decl, NOP_EXPR, init, 8706 tf_warning_or_error); 8707 } 8708 else 8709 init = build2 (MODIFY_EXPR, void_type_node, decl, init); 8710 if (cond 8711 && TREE_SIDE_EFFECTS (cond) 8712 && COMPARISON_CLASS_P (cond) 8713 && !processing_template_decl) 8714 { 8715 tree t = TREE_OPERAND (cond, 0); 8716 if (TREE_SIDE_EFFECTS (t) 8717 && t != decl 8718 && (TREE_CODE (t) != NOP_EXPR 8719 || TREE_OPERAND (t, 0) != decl)) 8720 TREE_OPERAND (cond, 0) 8721 = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 8722 8723 t = TREE_OPERAND (cond, 1); 8724 if (TREE_SIDE_EFFECTS (t) 8725 && t != decl 8726 && (TREE_CODE (t) != NOP_EXPR 8727 || TREE_OPERAND (t, 0) != decl)) 8728 TREE_OPERAND (cond, 1) 8729 = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 8730 } 8731 if (decl == error_mark_node || init == error_mark_node) 8732 return NULL; 8733 8734 TREE_VEC_ELT (declv, i) = decl; 8735 TREE_VEC_ELT (initv, i) = init; 8736 TREE_VEC_ELT (condv, i) = cond; 8737 TREE_VEC_ELT (incrv, i) = incr; 8738 i++; 8739 } 8740 8741 if (pre_body && IS_EMPTY_STMT (pre_body)) 8742 pre_body = NULL; 8743 8744 omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv, 8745 incrv, body, pre_body, 8746 !processing_template_decl); 8747 8748 /* Check for iterators appearing in lb, b or incr expressions. */ 8749 if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees)) 8750 omp_for = NULL_TREE; 8751 8752 if (omp_for == NULL) 8753 { 8754 return NULL; 8755 } 8756 8757 add_stmt (omp_for); 8758 8759 for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++) 8760 { 8761 decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i), 0); 8762 incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i); 8763 8764 if (TREE_CODE (incr) != MODIFY_EXPR) 8765 continue; 8766 8767 if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1)) 8768 && BINARY_CLASS_P (TREE_OPERAND (incr, 1)) 8769 && !processing_template_decl) 8770 { 8771 tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0); 8772 if (TREE_SIDE_EFFECTS (t) 8773 && t != decl 8774 && (TREE_CODE (t) != NOP_EXPR 8775 || TREE_OPERAND (t, 0) != decl)) 8776 TREE_OPERAND (TREE_OPERAND (incr, 1), 0) 8777 = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 8778 8779 t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1); 8780 if (TREE_SIDE_EFFECTS (t) 8781 && t != decl 8782 && (TREE_CODE (t) != NOP_EXPR 8783 || TREE_OPERAND (t, 0) != decl)) 8784 TREE_OPERAND (TREE_OPERAND (incr, 1), 1) 8785 = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 8786 } 8787 8788 if (orig_incr) 8789 TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i) = TREE_VEC_ELT (orig_incr, i); 8790 } 8791 OMP_FOR_CLAUSES (omp_for) = clauses; 8792 8793 /* For simd loops with non-static data member iterators, we could have added 8794 OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the 8795 step at this point, fill it in. */ 8796 if (code == OMP_SIMD && !processing_template_decl 8797 && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)) == 1) 8798 for (tree c = omp_find_clause (clauses, OMP_CLAUSE_LINEAR); c; 8799 c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_LINEAR)) 8800 if (OMP_CLAUSE_LINEAR_STEP (c) == NULL_TREE) 8801 { 8802 decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0), 0); 8803 gcc_assert (decl == OMP_CLAUSE_DECL (c)); 8804 incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0); 8805 tree step, stept; 8806 switch (TREE_CODE (incr)) 8807 { 8808 case PREINCREMENT_EXPR: 8809 case POSTINCREMENT_EXPR: 8810 /* c_omp_for_incr_canonicalize_ptr() should have been 8811 called to massage things appropriately. */ 8812 gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl))); 8813 OMP_CLAUSE_LINEAR_STEP (c) = build_int_cst (TREE_TYPE (decl), 1); 8814 break; 8815 case PREDECREMENT_EXPR: 8816 case POSTDECREMENT_EXPR: 8817 /* c_omp_for_incr_canonicalize_ptr() should have been 8818 called to massage things appropriately. */ 8819 gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl))); 8820 OMP_CLAUSE_LINEAR_STEP (c) 8821 = build_int_cst (TREE_TYPE (decl), -1); 8822 break; 8823 case MODIFY_EXPR: 8824 gcc_assert (TREE_OPERAND (incr, 0) == decl); 8825 incr = TREE_OPERAND (incr, 1); 8826 switch (TREE_CODE (incr)) 8827 { 8828 case PLUS_EXPR: 8829 if (TREE_OPERAND (incr, 1) == decl) 8830 step = TREE_OPERAND (incr, 0); 8831 else 8832 step = TREE_OPERAND (incr, 1); 8833 break; 8834 case MINUS_EXPR: 8835 case POINTER_PLUS_EXPR: 8836 gcc_assert (TREE_OPERAND (incr, 0) == decl); 8837 step = TREE_OPERAND (incr, 1); 8838 break; 8839 default: 8840 gcc_unreachable (); 8841 } 8842 stept = TREE_TYPE (decl); 8843 if (INDIRECT_TYPE_P (stept)) 8844 stept = sizetype; 8845 step = fold_convert (stept, step); 8846 if (TREE_CODE (incr) == MINUS_EXPR) 8847 step = fold_build1 (NEGATE_EXPR, stept, step); 8848 OMP_CLAUSE_LINEAR_STEP (c) = step; 8849 break; 8850 default: 8851 gcc_unreachable (); 8852 } 8853 } 8854 8855 return omp_for; 8856 } 8857 8858 /* Fix up range for decls. Those decls were pushed into BIND's BIND_EXPR_VARS 8859 and need to be moved into the BIND_EXPR inside of the OMP_FOR's body. */ 8860 8861 tree 8862 finish_omp_for_block (tree bind, tree omp_for) 8863 { 8864 if (omp_for == NULL_TREE 8865 || !OMP_FOR_ORIG_DECLS (omp_for) 8866 || bind == NULL_TREE 8867 || TREE_CODE (bind) != BIND_EXPR) 8868 return bind; 8869 tree b = NULL_TREE; 8870 for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for)); i++) 8871 if (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)) == TREE_LIST 8872 && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i))) 8873 { 8874 tree v = TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)); 8875 gcc_assert (BIND_EXPR_BLOCK (bind) 8876 && (BIND_EXPR_VARS (bind) 8877 == BLOCK_VARS (BIND_EXPR_BLOCK (bind)))); 8878 for (int j = 2; j < TREE_VEC_LENGTH (v); j++) 8879 for (tree *p = &BIND_EXPR_VARS (bind); *p; p = &DECL_CHAIN (*p)) 8880 { 8881 if (*p == TREE_VEC_ELT (v, j)) 8882 { 8883 tree var = *p; 8884 *p = DECL_CHAIN (*p); 8885 if (b == NULL_TREE) 8886 { 8887 b = make_node (BLOCK); 8888 b = build3 (BIND_EXPR, void_type_node, NULL_TREE, 8889 OMP_FOR_BODY (omp_for), b); 8890 TREE_SIDE_EFFECTS (b) = 1; 8891 OMP_FOR_BODY (omp_for) = b; 8892 } 8893 DECL_CHAIN (var) = BIND_EXPR_VARS (b); 8894 BIND_EXPR_VARS (b) = var; 8895 BLOCK_VARS (BIND_EXPR_BLOCK (b)) = var; 8896 } 8897 } 8898 BLOCK_VARS (BIND_EXPR_BLOCK (bind)) = BIND_EXPR_VARS (bind); 8899 } 8900 return bind; 8901 } 8902 8903 void 8904 finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode, 8905 tree lhs, tree rhs, tree v, tree lhs1, tree rhs1, 8906 tree clauses, enum omp_memory_order mo) 8907 { 8908 tree orig_lhs; 8909 tree orig_rhs; 8910 tree orig_v; 8911 tree orig_lhs1; 8912 tree orig_rhs1; 8913 bool dependent_p; 8914 tree stmt; 8915 8916 orig_lhs = lhs; 8917 orig_rhs = rhs; 8918 orig_v = v; 8919 orig_lhs1 = lhs1; 8920 orig_rhs1 = rhs1; 8921 dependent_p = false; 8922 stmt = NULL_TREE; 8923 8924 /* Even in a template, we can detect invalid uses of the atomic 8925 pragma if neither LHS nor RHS is type-dependent. */ 8926 if (processing_template_decl) 8927 { 8928 dependent_p = (type_dependent_expression_p (lhs) 8929 || (rhs && type_dependent_expression_p (rhs)) 8930 || (v && type_dependent_expression_p (v)) 8931 || (lhs1 && type_dependent_expression_p (lhs1)) 8932 || (rhs1 && type_dependent_expression_p (rhs1))); 8933 if (clauses) 8934 { 8935 gcc_assert (TREE_CODE (clauses) == OMP_CLAUSE 8936 && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_HINT 8937 && OMP_CLAUSE_CHAIN (clauses) == NULL_TREE); 8938 if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses)) 8939 || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses)) != INTEGER_CST) 8940 dependent_p = true; 8941 } 8942 if (!dependent_p) 8943 { 8944 lhs = build_non_dependent_expr (lhs); 8945 if (rhs) 8946 rhs = build_non_dependent_expr (rhs); 8947 if (v) 8948 v = build_non_dependent_expr (v); 8949 if (lhs1) 8950 lhs1 = build_non_dependent_expr (lhs1); 8951 if (rhs1) 8952 rhs1 = build_non_dependent_expr (rhs1); 8953 } 8954 } 8955 if (!dependent_p) 8956 { 8957 bool swapped = false; 8958 if (rhs1 && cp_tree_equal (lhs, rhs)) 8959 { 8960 std::swap (rhs, rhs1); 8961 swapped = !commutative_tree_code (opcode); 8962 } 8963 if (rhs1 && !cp_tree_equal (lhs, rhs1)) 8964 { 8965 if (code == OMP_ATOMIC) 8966 error ("%<#pragma omp atomic update%> uses two different " 8967 "expressions for memory"); 8968 else 8969 error ("%<#pragma omp atomic capture%> uses two different " 8970 "expressions for memory"); 8971 return; 8972 } 8973 if (lhs1 && !cp_tree_equal (lhs, lhs1)) 8974 { 8975 if (code == OMP_ATOMIC) 8976 error ("%<#pragma omp atomic update%> uses two different " 8977 "expressions for memory"); 8978 else 8979 error ("%<#pragma omp atomic capture%> uses two different " 8980 "expressions for memory"); 8981 return; 8982 } 8983 stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, 8984 v, lhs1, rhs1, swapped, mo, 8985 processing_template_decl != 0); 8986 if (stmt == error_mark_node) 8987 return; 8988 } 8989 if (processing_template_decl) 8990 { 8991 if (code == OMP_ATOMIC_READ) 8992 { 8993 stmt = build_min_nt_loc (loc, OMP_ATOMIC_READ, orig_lhs); 8994 OMP_ATOMIC_MEMORY_ORDER (stmt) = mo; 8995 stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt); 8996 } 8997 else 8998 { 8999 if (opcode == NOP_EXPR) 9000 stmt = build2 (MODIFY_EXPR, void_type_node, orig_lhs, orig_rhs); 9001 else 9002 stmt = build2 (opcode, void_type_node, orig_lhs, orig_rhs); 9003 if (orig_rhs1) 9004 stmt = build_min_nt_loc (EXPR_LOCATION (orig_rhs1), 9005 COMPOUND_EXPR, orig_rhs1, stmt); 9006 if (code != OMP_ATOMIC) 9007 { 9008 stmt = build_min_nt_loc (loc, code, orig_lhs1, stmt); 9009 OMP_ATOMIC_MEMORY_ORDER (stmt) = mo; 9010 stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt); 9011 } 9012 } 9013 stmt = build2 (OMP_ATOMIC, void_type_node, 9014 clauses ? clauses : integer_zero_node, stmt); 9015 OMP_ATOMIC_MEMORY_ORDER (stmt) = mo; 9016 SET_EXPR_LOCATION (stmt, loc); 9017 } 9018 9019 /* Avoid -Wunused-value warnings here, the whole construct has side-effects 9020 and even if it might be wrapped from fold-const.c or c-omp.c wrapped 9021 in some tree that appears to be unused, the value is not unused. */ 9022 warning_sentinel w (warn_unused_value); 9023 finish_expr_stmt (stmt); 9024 } 9025 9026 void 9027 finish_omp_barrier (void) 9028 { 9029 tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER); 9030 vec<tree, va_gc> *vec = make_tree_vector (); 9031 tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); 9032 release_tree_vector (vec); 9033 finish_expr_stmt (stmt); 9034 } 9035 9036 void 9037 finish_omp_depobj (location_t loc, tree depobj, 9038 enum omp_clause_depend_kind kind, tree clause) 9039 { 9040 if (!error_operand_p (depobj) && !type_dependent_expression_p (depobj)) 9041 { 9042 if (!lvalue_p (depobj)) 9043 { 9044 error_at (EXPR_LOC_OR_LOC (depobj, loc), 9045 "%<depobj%> expression is not lvalue expression"); 9046 depobj = error_mark_node; 9047 } 9048 } 9049 9050 if (processing_template_decl) 9051 { 9052 if (clause == NULL_TREE) 9053 clause = build_int_cst (integer_type_node, kind); 9054 add_stmt (build_min_nt_loc (loc, OMP_DEPOBJ, depobj, clause)); 9055 return; 9056 } 9057 9058 if (!error_operand_p (depobj)) 9059 { 9060 tree addr = cp_build_addr_expr (depobj, tf_warning_or_error); 9061 if (addr == error_mark_node) 9062 depobj = error_mark_node; 9063 else 9064 depobj = cp_build_indirect_ref (addr, RO_UNARY_STAR, 9065 tf_warning_or_error); 9066 } 9067 9068 c_finish_omp_depobj (loc, depobj, kind, clause); 9069 } 9070 9071 void 9072 finish_omp_flush (int mo) 9073 { 9074 tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE); 9075 vec<tree, va_gc> *vec = make_tree_vector (); 9076 if (mo != MEMMODEL_LAST) 9077 { 9078 fn = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE); 9079 vec->quick_push (build_int_cst (integer_type_node, mo)); 9080 } 9081 tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); 9082 release_tree_vector (vec); 9083 finish_expr_stmt (stmt); 9084 } 9085 9086 void 9087 finish_omp_taskwait (void) 9088 { 9089 tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT); 9090 vec<tree, va_gc> *vec = make_tree_vector (); 9091 tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); 9092 release_tree_vector (vec); 9093 finish_expr_stmt (stmt); 9094 } 9095 9096 void 9097 finish_omp_taskyield (void) 9098 { 9099 tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD); 9100 vec<tree, va_gc> *vec = make_tree_vector (); 9101 tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); 9102 release_tree_vector (vec); 9103 finish_expr_stmt (stmt); 9104 } 9105 9106 void 9107 finish_omp_cancel (tree clauses) 9108 { 9109 tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL); 9110 int mask = 0; 9111 if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL)) 9112 mask = 1; 9113 else if (omp_find_clause (clauses, OMP_CLAUSE_FOR)) 9114 mask = 2; 9115 else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS)) 9116 mask = 4; 9117 else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP)) 9118 mask = 8; 9119 else 9120 { 9121 error ("%<#pragma omp cancel%> must specify one of " 9122 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses"); 9123 return; 9124 } 9125 vec<tree, va_gc> *vec = make_tree_vector (); 9126 tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF); 9127 if (ifc != NULL_TREE) 9128 { 9129 if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK 9130 && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST) 9131 error_at (OMP_CLAUSE_LOCATION (ifc), 9132 "expected %<cancel%> %<if%> clause modifier"); 9133 else 9134 { 9135 tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF); 9136 if (ifc2 != NULL_TREE) 9137 { 9138 gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST 9139 && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK 9140 && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST); 9141 error_at (OMP_CLAUSE_LOCATION (ifc2), 9142 "expected %<cancel%> %<if%> clause modifier"); 9143 } 9144 } 9145 9146 if (!processing_template_decl) 9147 ifc = maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc)); 9148 else 9149 ifc = build_x_binary_op (OMP_CLAUSE_LOCATION (ifc), NE_EXPR, 9150 OMP_CLAUSE_IF_EXPR (ifc), ERROR_MARK, 9151 integer_zero_node, ERROR_MARK, 9152 NULL, tf_warning_or_error); 9153 } 9154 else 9155 ifc = boolean_true_node; 9156 vec->quick_push (build_int_cst (integer_type_node, mask)); 9157 vec->quick_push (ifc); 9158 tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); 9159 release_tree_vector (vec); 9160 finish_expr_stmt (stmt); 9161 } 9162 9163 void 9164 finish_omp_cancellation_point (tree clauses) 9165 { 9166 tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT); 9167 int mask = 0; 9168 if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL)) 9169 mask = 1; 9170 else if (omp_find_clause (clauses, OMP_CLAUSE_FOR)) 9171 mask = 2; 9172 else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS)) 9173 mask = 4; 9174 else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP)) 9175 mask = 8; 9176 else 9177 { 9178 error ("%<#pragma omp cancellation point%> must specify one of " 9179 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses"); 9180 return; 9181 } 9182 vec<tree, va_gc> *vec 9183 = make_tree_vector_single (build_int_cst (integer_type_node, mask)); 9184 tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); 9185 release_tree_vector (vec); 9186 finish_expr_stmt (stmt); 9187 } 9188 9189 /* Begin a __transaction_atomic or __transaction_relaxed statement. 9190 If PCOMPOUND is non-null, this is for a function-transaction-block, and we 9191 should create an extra compound stmt. */ 9192 9193 tree 9194 begin_transaction_stmt (location_t loc, tree *pcompound, int flags) 9195 { 9196 tree r; 9197 9198 if (pcompound) 9199 *pcompound = begin_compound_stmt (0); 9200 9201 r = build_stmt (loc, TRANSACTION_EXPR, NULL_TREE); 9202 9203 /* Only add the statement to the function if support enabled. */ 9204 if (flag_tm) 9205 add_stmt (r); 9206 else 9207 error_at (loc, ((flags & TM_STMT_ATTR_RELAXED) != 0 9208 ? G_("%<__transaction_relaxed%> without " 9209 "transactional memory support enabled") 9210 : G_("%<__transaction_atomic%> without " 9211 "transactional memory support enabled"))); 9212 9213 TRANSACTION_EXPR_BODY (r) = push_stmt_list (); 9214 TREE_SIDE_EFFECTS (r) = 1; 9215 return r; 9216 } 9217 9218 /* End a __transaction_atomic or __transaction_relaxed statement. 9219 If COMPOUND_STMT is non-null, this is for a function-transaction-block, 9220 and we should end the compound. If NOEX is non-NULL, we wrap the body in 9221 a MUST_NOT_THROW_EXPR with NOEX as condition. */ 9222 9223 void 9224 finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex) 9225 { 9226 TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt)); 9227 TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0; 9228 TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0; 9229 TRANSACTION_EXPR_IS_STMT (stmt) = 1; 9230 9231 /* noexcept specifications are not allowed for function transactions. */ 9232 gcc_assert (!(noex && compound_stmt)); 9233 if (noex) 9234 { 9235 tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt), 9236 noex); 9237 protected_set_expr_location 9238 (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt))); 9239 TREE_SIDE_EFFECTS (body) = 1; 9240 TRANSACTION_EXPR_BODY (stmt) = body; 9241 } 9242 9243 if (compound_stmt) 9244 finish_compound_stmt (compound_stmt); 9245 } 9246 9247 /* Build a __transaction_atomic or __transaction_relaxed expression. If 9248 NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as 9249 condition. */ 9250 9251 tree 9252 build_transaction_expr (location_t loc, tree expr, int flags, tree noex) 9253 { 9254 tree ret; 9255 if (noex) 9256 { 9257 expr = build_must_not_throw_expr (expr, noex); 9258 protected_set_expr_location (expr, loc); 9259 TREE_SIDE_EFFECTS (expr) = 1; 9260 } 9261 ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr); 9262 if (flags & TM_STMT_ATTR_RELAXED) 9263 TRANSACTION_EXPR_RELAXED (ret) = 1; 9264 TREE_SIDE_EFFECTS (ret) = 1; 9265 SET_EXPR_LOCATION (ret, loc); 9266 return ret; 9267 } 9268 9269 void 9270 init_cp_semantics (void) 9271 { 9272 } 9273 9274 /* Build a STATIC_ASSERT for a static assertion with the condition 9275 CONDITION and the message text MESSAGE. LOCATION is the location 9276 of the static assertion in the source code. When MEMBER_P, this 9277 static assertion is a member of a class. */ 9278 void 9279 finish_static_assert (tree condition, tree message, location_t location, 9280 bool member_p) 9281 { 9282 tsubst_flags_t complain = tf_warning_or_error; 9283 9284 if (message == NULL_TREE 9285 || message == error_mark_node 9286 || condition == NULL_TREE 9287 || condition == error_mark_node) 9288 return; 9289 9290 if (check_for_bare_parameter_packs (condition)) 9291 condition = error_mark_node; 9292 9293 if (instantiation_dependent_expression_p (condition)) 9294 { 9295 /* We're in a template; build a STATIC_ASSERT and put it in 9296 the right place. */ 9297 tree assertion; 9298 9299 assertion = make_node (STATIC_ASSERT); 9300 STATIC_ASSERT_CONDITION (assertion) = condition; 9301 STATIC_ASSERT_MESSAGE (assertion) = message; 9302 STATIC_ASSERT_SOURCE_LOCATION (assertion) = location; 9303 9304 if (member_p) 9305 maybe_add_class_template_decl_list (current_class_type, 9306 assertion, 9307 /*friend_p=*/0); 9308 else 9309 add_stmt (assertion); 9310 9311 return; 9312 } 9313 9314 /* Fold the expression and convert it to a boolean value. */ 9315 condition = perform_implicit_conversion_flags (boolean_type_node, condition, 9316 complain, LOOKUP_NORMAL); 9317 condition = fold_non_dependent_expr (condition, complain, 9318 /*manifestly_const_eval=*/true); 9319 9320 if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition)) 9321 /* Do nothing; the condition is satisfied. */ 9322 ; 9323 else 9324 { 9325 location_t saved_loc = input_location; 9326 9327 input_location = location; 9328 if (TREE_CODE (condition) == INTEGER_CST 9329 && integer_zerop (condition)) 9330 { 9331 int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT 9332 (TREE_TYPE (TREE_TYPE (message)))); 9333 int len = TREE_STRING_LENGTH (message) / sz - 1; 9334 /* Report the error. */ 9335 if (len == 0) 9336 error ("static assertion failed"); 9337 else 9338 error ("static assertion failed: %s", 9339 TREE_STRING_POINTER (message)); 9340 } 9341 else if (condition && condition != error_mark_node) 9342 { 9343 error ("non-constant condition for static assertion"); 9344 if (require_rvalue_constant_expression (condition)) 9345 cxx_constant_value (condition); 9346 } 9347 input_location = saved_loc; 9348 } 9349 } 9350 9351 /* Implements the C++0x decltype keyword. Returns the type of EXPR, 9352 suitable for use as a type-specifier. 9353 9354 ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an 9355 id-expression or a class member access, FALSE when it was parsed as 9356 a full expression. */ 9357 9358 tree 9359 finish_decltype_type (tree expr, bool id_expression_or_member_access_p, 9360 tsubst_flags_t complain) 9361 { 9362 tree type = NULL_TREE; 9363 9364 if (!expr || error_operand_p (expr)) 9365 return error_mark_node; 9366 9367 if (TYPE_P (expr) 9368 || TREE_CODE (expr) == TYPE_DECL 9369 || (TREE_CODE (expr) == BIT_NOT_EXPR 9370 && TYPE_P (TREE_OPERAND (expr, 0)))) 9371 { 9372 if (complain & tf_error) 9373 error ("argument to decltype must be an expression"); 9374 return error_mark_node; 9375 } 9376 9377 /* Depending on the resolution of DR 1172, we may later need to distinguish 9378 instantiation-dependent but not type-dependent expressions so that, say, 9379 A<decltype(sizeof(T))>::U doesn't require 'typename'. */ 9380 if (instantiation_dependent_uneval_expression_p (expr)) 9381 { 9382 type = cxx_make_type (DECLTYPE_TYPE); 9383 DECLTYPE_TYPE_EXPR (type) = expr; 9384 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type) 9385 = id_expression_or_member_access_p; 9386 SET_TYPE_STRUCTURAL_EQUALITY (type); 9387 9388 return type; 9389 } 9390 9391 /* The type denoted by decltype(e) is defined as follows: */ 9392 9393 expr = resolve_nondeduced_context (expr, complain); 9394 9395 if (invalid_nonstatic_memfn_p (input_location, expr, complain)) 9396 return error_mark_node; 9397 9398 if (type_unknown_p (expr)) 9399 { 9400 if (complain & tf_error) 9401 error ("decltype cannot resolve address of overloaded function"); 9402 return error_mark_node; 9403 } 9404 9405 /* To get the size of a static data member declared as an array of 9406 unknown bound, we need to instantiate it. */ 9407 if (VAR_P (expr) 9408 && VAR_HAD_UNKNOWN_BOUND (expr) 9409 && DECL_TEMPLATE_INSTANTIATION (expr)) 9410 instantiate_decl (expr, /*defer_ok*/true, /*expl_inst_mem*/false); 9411 9412 if (id_expression_or_member_access_p) 9413 { 9414 /* If e is an id-expression or a class member access (5.2.5 9415 [expr.ref]), decltype(e) is defined as the type of the entity 9416 named by e. If there is no such entity, or e names a set of 9417 overloaded functions, the program is ill-formed. */ 9418 if (identifier_p (expr)) 9419 expr = lookup_name (expr); 9420 9421 if (INDIRECT_REF_P (expr) 9422 || TREE_CODE (expr) == VIEW_CONVERT_EXPR) 9423 /* This can happen when the expression is, e.g., "a.b". Just 9424 look at the underlying operand. */ 9425 expr = TREE_OPERAND (expr, 0); 9426 9427 if (TREE_CODE (expr) == OFFSET_REF 9428 || TREE_CODE (expr) == MEMBER_REF 9429 || TREE_CODE (expr) == SCOPE_REF) 9430 /* We're only interested in the field itself. If it is a 9431 BASELINK, we will need to see through it in the next 9432 step. */ 9433 expr = TREE_OPERAND (expr, 1); 9434 9435 if (BASELINK_P (expr)) 9436 /* See through BASELINK nodes to the underlying function. */ 9437 expr = BASELINK_FUNCTIONS (expr); 9438 9439 /* decltype of a decomposition name drops references in the tuple case 9440 (unlike decltype of a normal variable) and keeps cv-qualifiers from 9441 the containing object in the other cases (unlike decltype of a member 9442 access expression). */ 9443 if (DECL_DECOMPOSITION_P (expr)) 9444 { 9445 if (DECL_HAS_VALUE_EXPR_P (expr)) 9446 /* Expr is an array or struct subobject proxy, handle 9447 bit-fields properly. */ 9448 return unlowered_expr_type (expr); 9449 else 9450 /* Expr is a reference variable for the tuple case. */ 9451 return lookup_decomp_type (expr); 9452 } 9453 9454 switch (TREE_CODE (expr)) 9455 { 9456 case FIELD_DECL: 9457 if (DECL_BIT_FIELD_TYPE (expr)) 9458 { 9459 type = DECL_BIT_FIELD_TYPE (expr); 9460 break; 9461 } 9462 /* Fall through for fields that aren't bitfields. */ 9463 gcc_fallthrough (); 9464 9465 case FUNCTION_DECL: 9466 case VAR_DECL: 9467 case CONST_DECL: 9468 case PARM_DECL: 9469 case RESULT_DECL: 9470 case TEMPLATE_PARM_INDEX: 9471 expr = mark_type_use (expr); 9472 type = TREE_TYPE (expr); 9473 break; 9474 9475 case ERROR_MARK: 9476 type = error_mark_node; 9477 break; 9478 9479 case COMPONENT_REF: 9480 case COMPOUND_EXPR: 9481 mark_type_use (expr); 9482 type = is_bitfield_expr_with_lowered_type (expr); 9483 if (!type) 9484 type = TREE_TYPE (TREE_OPERAND (expr, 1)); 9485 break; 9486 9487 case BIT_FIELD_REF: 9488 gcc_unreachable (); 9489 9490 case INTEGER_CST: 9491 case PTRMEM_CST: 9492 /* We can get here when the id-expression refers to an 9493 enumerator or non-type template parameter. */ 9494 type = TREE_TYPE (expr); 9495 break; 9496 9497 default: 9498 /* Handle instantiated template non-type arguments. */ 9499 type = TREE_TYPE (expr); 9500 break; 9501 } 9502 } 9503 else 9504 { 9505 /* Within a lambda-expression: 9506 9507 Every occurrence of decltype((x)) where x is a possibly 9508 parenthesized id-expression that names an entity of 9509 automatic storage duration is treated as if x were 9510 transformed into an access to a corresponding data member 9511 of the closure type that would have been declared if x 9512 were a use of the denoted entity. */ 9513 if (outer_automatic_var_p (expr) 9514 && current_function_decl 9515 && LAMBDA_FUNCTION_P (current_function_decl)) 9516 type = capture_decltype (expr); 9517 else if (error_operand_p (expr)) 9518 type = error_mark_node; 9519 else if (expr == current_class_ptr) 9520 /* If the expression is just "this", we want the 9521 cv-unqualified pointer for the "this" type. */ 9522 type = TYPE_MAIN_VARIANT (TREE_TYPE (expr)); 9523 else 9524 { 9525 /* Otherwise, where T is the type of e, if e is an lvalue, 9526 decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */ 9527 cp_lvalue_kind clk = lvalue_kind (expr); 9528 type = unlowered_expr_type (expr); 9529 gcc_assert (!TYPE_REF_P (type)); 9530 9531 /* For vector types, pick a non-opaque variant. */ 9532 if (VECTOR_TYPE_P (type)) 9533 type = strip_typedefs (type); 9534 9535 if (clk != clk_none && !(clk & clk_class)) 9536 type = cp_build_reference_type (type, (clk & clk_rvalueref)); 9537 } 9538 } 9539 9540 return type; 9541 } 9542 9543 /* Called from trait_expr_value to evaluate either __has_nothrow_assign or 9544 __has_nothrow_copy, depending on assign_p. Returns true iff all 9545 the copy {ctor,assign} fns are nothrow. */ 9546 9547 static bool 9548 classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p) 9549 { 9550 tree fns = NULL_TREE; 9551 9552 if (assign_p || TYPE_HAS_COPY_CTOR (type)) 9553 fns = get_class_binding (type, assign_p ? assign_op_identifier 9554 : ctor_identifier); 9555 9556 bool saw_copy = false; 9557 for (ovl_iterator iter (fns); iter; ++iter) 9558 { 9559 tree fn = *iter; 9560 9561 if (copy_fn_p (fn) > 0) 9562 { 9563 saw_copy = true; 9564 if (!maybe_instantiate_noexcept (fn) 9565 || !TYPE_NOTHROW_P (TREE_TYPE (fn))) 9566 return false; 9567 } 9568 } 9569 9570 return saw_copy; 9571 } 9572 9573 /* Actually evaluates the trait. */ 9574 9575 static bool 9576 trait_expr_value (cp_trait_kind kind, tree type1, tree type2) 9577 { 9578 enum tree_code type_code1; 9579 tree t; 9580 9581 type_code1 = TREE_CODE (type1); 9582 9583 switch (kind) 9584 { 9585 case CPTK_HAS_NOTHROW_ASSIGN: 9586 type1 = strip_array_types (type1); 9587 return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE 9588 && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2) 9589 || (CLASS_TYPE_P (type1) 9590 && classtype_has_nothrow_assign_or_copy_p (type1, 9591 true)))); 9592 9593 case CPTK_HAS_TRIVIAL_ASSIGN: 9594 /* ??? The standard seems to be missing the "or array of such a class 9595 type" wording for this trait. */ 9596 type1 = strip_array_types (type1); 9597 return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE 9598 && (trivial_type_p (type1) 9599 || (CLASS_TYPE_P (type1) 9600 && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1)))); 9601 9602 case CPTK_HAS_NOTHROW_CONSTRUCTOR: 9603 type1 = strip_array_types (type1); 9604 return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2) 9605 || (CLASS_TYPE_P (type1) 9606 && (t = locate_ctor (type1)) 9607 && maybe_instantiate_noexcept (t) 9608 && TYPE_NOTHROW_P (TREE_TYPE (t)))); 9609 9610 case CPTK_HAS_TRIVIAL_CONSTRUCTOR: 9611 type1 = strip_array_types (type1); 9612 return (trivial_type_p (type1) 9613 || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1))); 9614 9615 case CPTK_HAS_NOTHROW_COPY: 9616 type1 = strip_array_types (type1); 9617 return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2) 9618 || (CLASS_TYPE_P (type1) 9619 && classtype_has_nothrow_assign_or_copy_p (type1, false))); 9620 9621 case CPTK_HAS_TRIVIAL_COPY: 9622 /* ??? The standard seems to be missing the "or array of such a class 9623 type" wording for this trait. */ 9624 type1 = strip_array_types (type1); 9625 return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE 9626 || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1))); 9627 9628 case CPTK_HAS_TRIVIAL_DESTRUCTOR: 9629 type1 = strip_array_types (type1); 9630 return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE 9631 || (CLASS_TYPE_P (type1) 9632 && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1))); 9633 9634 case CPTK_HAS_VIRTUAL_DESTRUCTOR: 9635 return type_has_virtual_destructor (type1); 9636 9637 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS: 9638 return type_has_unique_obj_representations (type1); 9639 9640 case CPTK_IS_ABSTRACT: 9641 return ABSTRACT_CLASS_TYPE_P (type1); 9642 9643 case CPTK_IS_AGGREGATE: 9644 return CP_AGGREGATE_TYPE_P (type1); 9645 9646 case CPTK_IS_BASE_OF: 9647 return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2) 9648 && (same_type_ignoring_top_level_qualifiers_p (type1, type2) 9649 || DERIVED_FROM_P (type1, type2))); 9650 9651 case CPTK_IS_CLASS: 9652 return NON_UNION_CLASS_TYPE_P (type1); 9653 9654 case CPTK_IS_EMPTY: 9655 return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1); 9656 9657 case CPTK_IS_ENUM: 9658 return type_code1 == ENUMERAL_TYPE; 9659 9660 case CPTK_IS_FINAL: 9661 return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1); 9662 9663 case CPTK_IS_LITERAL_TYPE: 9664 return literal_type_p (type1); 9665 9666 case CPTK_IS_POD: 9667 return pod_type_p (type1); 9668 9669 case CPTK_IS_POLYMORPHIC: 9670 return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1); 9671 9672 case CPTK_IS_SAME_AS: 9673 return same_type_p (type1, type2); 9674 9675 case CPTK_IS_STD_LAYOUT: 9676 return std_layout_type_p (type1); 9677 9678 case CPTK_IS_TRIVIAL: 9679 return trivial_type_p (type1); 9680 9681 case CPTK_IS_TRIVIALLY_ASSIGNABLE: 9682 return is_trivially_xible (MODIFY_EXPR, type1, type2); 9683 9684 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: 9685 return is_trivially_xible (INIT_EXPR, type1, type2); 9686 9687 case CPTK_IS_TRIVIALLY_COPYABLE: 9688 return trivially_copyable_p (type1); 9689 9690 case CPTK_IS_UNION: 9691 return type_code1 == UNION_TYPE; 9692 9693 case CPTK_IS_ASSIGNABLE: 9694 return is_xible (MODIFY_EXPR, type1, type2); 9695 9696 case CPTK_IS_CONSTRUCTIBLE: 9697 return is_xible (INIT_EXPR, type1, type2); 9698 9699 default: 9700 gcc_unreachable (); 9701 return false; 9702 } 9703 } 9704 9705 /* If TYPE is an array of unknown bound, or (possibly cv-qualified) 9706 void, or a complete type, returns true, otherwise false. */ 9707 9708 static bool 9709 check_trait_type (tree type) 9710 { 9711 if (type == NULL_TREE) 9712 return true; 9713 9714 if (TREE_CODE (type) == TREE_LIST) 9715 return (check_trait_type (TREE_VALUE (type)) 9716 && check_trait_type (TREE_CHAIN (type))); 9717 9718 if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type) 9719 && COMPLETE_TYPE_P (TREE_TYPE (type))) 9720 return true; 9721 9722 if (VOID_TYPE_P (type)) 9723 return true; 9724 9725 return !!complete_type_or_else (strip_array_types (type), NULL_TREE); 9726 } 9727 9728 /* Process a trait expression. */ 9729 9730 tree 9731 finish_trait_expr (cp_trait_kind kind, tree type1, tree type2) 9732 { 9733 if (type1 == error_mark_node 9734 || type2 == error_mark_node) 9735 return error_mark_node; 9736 9737 if (processing_template_decl) 9738 { 9739 tree trait_expr = make_node (TRAIT_EXPR); 9740 TREE_TYPE (trait_expr) = boolean_type_node; 9741 TRAIT_EXPR_TYPE1 (trait_expr) = type1; 9742 TRAIT_EXPR_TYPE2 (trait_expr) = type2; 9743 TRAIT_EXPR_KIND (trait_expr) = kind; 9744 return trait_expr; 9745 } 9746 9747 switch (kind) 9748 { 9749 case CPTK_HAS_NOTHROW_ASSIGN: 9750 case CPTK_HAS_TRIVIAL_ASSIGN: 9751 case CPTK_HAS_NOTHROW_CONSTRUCTOR: 9752 case CPTK_HAS_TRIVIAL_CONSTRUCTOR: 9753 case CPTK_HAS_NOTHROW_COPY: 9754 case CPTK_HAS_TRIVIAL_COPY: 9755 case CPTK_HAS_TRIVIAL_DESTRUCTOR: 9756 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS: 9757 case CPTK_HAS_VIRTUAL_DESTRUCTOR: 9758 case CPTK_IS_ABSTRACT: 9759 case CPTK_IS_AGGREGATE: 9760 case CPTK_IS_EMPTY: 9761 case CPTK_IS_FINAL: 9762 case CPTK_IS_LITERAL_TYPE: 9763 case CPTK_IS_POD: 9764 case CPTK_IS_POLYMORPHIC: 9765 case CPTK_IS_STD_LAYOUT: 9766 case CPTK_IS_TRIVIAL: 9767 case CPTK_IS_TRIVIALLY_COPYABLE: 9768 if (!check_trait_type (type1)) 9769 return error_mark_node; 9770 break; 9771 9772 case CPTK_IS_ASSIGNABLE: 9773 case CPTK_IS_CONSTRUCTIBLE: 9774 break; 9775 9776 case CPTK_IS_TRIVIALLY_ASSIGNABLE: 9777 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: 9778 if (!check_trait_type (type1) 9779 || !check_trait_type (type2)) 9780 return error_mark_node; 9781 break; 9782 9783 case CPTK_IS_BASE_OF: 9784 if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2) 9785 && !same_type_ignoring_top_level_qualifiers_p (type1, type2) 9786 && !complete_type_or_else (type2, NULL_TREE)) 9787 /* We already issued an error. */ 9788 return error_mark_node; 9789 break; 9790 9791 case CPTK_IS_CLASS: 9792 case CPTK_IS_ENUM: 9793 case CPTK_IS_UNION: 9794 case CPTK_IS_SAME_AS: 9795 break; 9796 9797 default: 9798 gcc_unreachable (); 9799 } 9800 9801 return (trait_expr_value (kind, type1, type2) 9802 ? boolean_true_node : boolean_false_node); 9803 } 9804 9805 /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64, 9806 which is ignored for C++. */ 9807 9808 void 9809 set_float_const_decimal64 (void) 9810 { 9811 } 9812 9813 void 9814 clear_float_const_decimal64 (void) 9815 { 9816 } 9817 9818 bool 9819 float_const_decimal64_p (void) 9820 { 9821 return 0; 9822 } 9823 9824 9825 /* Return true if T designates the implied `this' parameter. */ 9826 9827 bool 9828 is_this_parameter (tree t) 9829 { 9830 if (!DECL_P (t) || DECL_NAME (t) != this_identifier) 9831 return false; 9832 gcc_assert (TREE_CODE (t) == PARM_DECL || is_capture_proxy (t) 9833 || (cp_binding_oracle && TREE_CODE (t) == VAR_DECL)); 9834 return true; 9835 } 9836 9837 /* Insert the deduced return type for an auto function. */ 9838 9839 void 9840 apply_deduced_return_type (tree fco, tree return_type) 9841 { 9842 tree result; 9843 9844 if (return_type == error_mark_node) 9845 return; 9846 9847 if (DECL_CONV_FN_P (fco)) 9848 DECL_NAME (fco) = make_conv_op_name (return_type); 9849 9850 TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco)); 9851 9852 result = DECL_RESULT (fco); 9853 if (result == NULL_TREE) 9854 return; 9855 if (TREE_TYPE (result) == return_type) 9856 return; 9857 9858 if (!processing_template_decl && !VOID_TYPE_P (return_type) 9859 && !complete_type_or_else (return_type, NULL_TREE)) 9860 return; 9861 9862 /* We already have a DECL_RESULT from start_preparsed_function. 9863 Now we need to redo the work it and allocate_struct_function 9864 did to reflect the new type. */ 9865 gcc_assert (current_function_decl == fco); 9866 result = build_decl (input_location, RESULT_DECL, NULL_TREE, 9867 TYPE_MAIN_VARIANT (return_type)); 9868 DECL_ARTIFICIAL (result) = 1; 9869 DECL_IGNORED_P (result) = 1; 9870 cp_apply_type_quals_to_decl (cp_type_quals (return_type), 9871 result); 9872 9873 DECL_RESULT (fco) = result; 9874 9875 if (!processing_template_decl) 9876 { 9877 bool aggr = aggregate_value_p (result, fco); 9878 #ifdef PCC_STATIC_STRUCT_RETURN 9879 cfun->returns_pcc_struct = aggr; 9880 #endif 9881 cfun->returns_struct = aggr; 9882 } 9883 9884 } 9885 9886 /* DECL is a local variable or parameter from the surrounding scope of a 9887 lambda-expression. Returns the decltype for a use of the capture field 9888 for DECL even if it hasn't been captured yet. */ 9889 9890 static tree 9891 capture_decltype (tree decl) 9892 { 9893 tree lam = CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl)); 9894 tree cap = lookup_name_real (DECL_NAME (decl), /*type*/0, /*nonclass*/1, 9895 /*block_p=*/true, /*ns*/0, LOOKUP_HIDDEN); 9896 tree type; 9897 9898 if (cap && is_capture_proxy (cap)) 9899 type = TREE_TYPE (cap); 9900 else 9901 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam)) 9902 { 9903 case CPLD_NONE: 9904 error ("%qD is not captured", decl); 9905 return error_mark_node; 9906 9907 case CPLD_COPY: 9908 type = TREE_TYPE (decl); 9909 if (TYPE_REF_P (type) 9910 && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE) 9911 type = TREE_TYPE (type); 9912 break; 9913 9914 case CPLD_REFERENCE: 9915 type = TREE_TYPE (decl); 9916 if (!TYPE_REF_P (type)) 9917 type = build_reference_type (TREE_TYPE (decl)); 9918 break; 9919 9920 default: 9921 gcc_unreachable (); 9922 } 9923 9924 if (!TYPE_REF_P (type)) 9925 { 9926 if (!LAMBDA_EXPR_MUTABLE_P (lam)) 9927 type = cp_build_qualified_type (type, (cp_type_quals (type) 9928 |TYPE_QUAL_CONST)); 9929 type = build_reference_type (type); 9930 } 9931 return type; 9932 } 9933 9934 /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true, 9935 this is a right unary fold. Otherwise it is a left unary fold. */ 9936 9937 static tree 9938 finish_unary_fold_expr (tree expr, int op, tree_code dir) 9939 { 9940 // Build a pack expansion (assuming expr has pack type). 9941 if (!uses_parameter_packs (expr)) 9942 { 9943 error_at (location_of (expr), "operand of fold expression has no " 9944 "unexpanded parameter packs"); 9945 return error_mark_node; 9946 } 9947 tree pack = make_pack_expansion (expr); 9948 9949 // Build the fold expression. 9950 tree code = build_int_cstu (integer_type_node, abs (op)); 9951 tree fold = build_min_nt_loc (UNKNOWN_LOCATION, dir, code, pack); 9952 FOLD_EXPR_MODIFY_P (fold) = (op < 0); 9953 return fold; 9954 } 9955 9956 tree 9957 finish_left_unary_fold_expr (tree expr, int op) 9958 { 9959 return finish_unary_fold_expr (expr, op, UNARY_LEFT_FOLD_EXPR); 9960 } 9961 9962 tree 9963 finish_right_unary_fold_expr (tree expr, int op) 9964 { 9965 return finish_unary_fold_expr (expr, op, UNARY_RIGHT_FOLD_EXPR); 9966 } 9967 9968 /* Build a binary fold expression over EXPR1 and EXPR2. The 9969 associativity of the fold is determined by EXPR1 and EXPR2 (whichever 9970 has an unexpanded parameter pack). */ 9971 9972 tree 9973 finish_binary_fold_expr (tree pack, tree init, int op, tree_code dir) 9974 { 9975 pack = make_pack_expansion (pack); 9976 tree code = build_int_cstu (integer_type_node, abs (op)); 9977 tree fold = build_min_nt_loc (UNKNOWN_LOCATION, dir, code, pack, init); 9978 FOLD_EXPR_MODIFY_P (fold) = (op < 0); 9979 return fold; 9980 } 9981 9982 tree 9983 finish_binary_fold_expr (tree expr1, tree expr2, int op) 9984 { 9985 // Determine which expr has an unexpanded parameter pack and 9986 // set the pack and initial term. 9987 bool pack1 = uses_parameter_packs (expr1); 9988 bool pack2 = uses_parameter_packs (expr2); 9989 if (pack1 && !pack2) 9990 return finish_binary_fold_expr (expr1, expr2, op, BINARY_RIGHT_FOLD_EXPR); 9991 else if (pack2 && !pack1) 9992 return finish_binary_fold_expr (expr2, expr1, op, BINARY_LEFT_FOLD_EXPR); 9993 else 9994 { 9995 if (pack1) 9996 error ("both arguments in binary fold have unexpanded parameter packs"); 9997 else 9998 error ("no unexpanded parameter packs in binary fold"); 9999 } 10000 return error_mark_node; 10001 } 10002 10003 /* Finish __builtin_launder (arg). */ 10004 10005 tree 10006 finish_builtin_launder (location_t loc, tree arg, tsubst_flags_t complain) 10007 { 10008 tree orig_arg = arg; 10009 if (!type_dependent_expression_p (arg)) 10010 arg = decay_conversion (arg, complain); 10011 if (error_operand_p (arg)) 10012 return error_mark_node; 10013 if (!type_dependent_expression_p (arg) 10014 && !TYPE_PTR_P (TREE_TYPE (arg))) 10015 { 10016 error_at (loc, "non-pointer argument to %<__builtin_launder%>"); 10017 return error_mark_node; 10018 } 10019 if (processing_template_decl) 10020 arg = orig_arg; 10021 return build_call_expr_internal_loc (loc, IFN_LAUNDER, 10022 TREE_TYPE (arg), 1, arg); 10023 } 10024 10025 /* Finish __builtin_convertvector (arg, type). */ 10026 10027 tree 10028 cp_build_vec_convert (tree arg, location_t loc, tree type, 10029 tsubst_flags_t complain) 10030 { 10031 if (error_operand_p (type)) 10032 return error_mark_node; 10033 if (error_operand_p (arg)) 10034 return error_mark_node; 10035 10036 tree ret = NULL_TREE; 10037 if (!type_dependent_expression_p (arg) && !dependent_type_p (type)) 10038 ret = c_build_vec_convert (cp_expr_loc_or_loc (arg, input_location), 10039 decay_conversion (arg, complain), 10040 loc, type, (complain & tf_error) != 0); 10041 10042 if (!processing_template_decl) 10043 return ret; 10044 10045 return build_call_expr_internal_loc (loc, IFN_VEC_CONVERT, type, 1, arg); 10046 } 10047 10048 #include "gt-cp-semantics.h" 10049