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