comparison gcc/gimplify.c @ 57:326d9e06c2e3

modify c-parser.c
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Mon, 15 Feb 2010 00:54:17 +0900
parents 9907f3135723 77e2b8dfacca
children 1b10fe6932e1
comparison
equal deleted inserted replaced
54:f62c169bbc24 57:326d9e06c2e3
54 #include "gimple.h" 54 #include "gimple.h"
55 #ifndef noCbC 55 #ifndef noCbC
56 #include "cbc-tree.h" 56 #include "cbc-tree.h"
57 #endif 57 #endif
58 58
59 59 #include "tree-pass.h"
60 60
61 enum gimplify_omp_var_data 61 enum gimplify_omp_var_data
62 { 62 {
63 GOVD_SEEN = 1, 63 GOVD_SEEN = 1,
64 GOVD_EXPLICIT = 2, 64 GOVD_EXPLICIT = 2,
69 GOVD_REDUCTION = 64, 69 GOVD_REDUCTION = 64,
70 GOVD_LOCAL = 128, 70 GOVD_LOCAL = 128,
71 GOVD_DEBUG_PRIVATE = 256, 71 GOVD_DEBUG_PRIVATE = 256,
72 GOVD_PRIVATE_OUTER_REF = 512, 72 GOVD_PRIVATE_OUTER_REF = 512,
73 GOVD_DATA_SHARE_CLASS = (GOVD_SHARED | GOVD_PRIVATE | GOVD_FIRSTPRIVATE 73 GOVD_DATA_SHARE_CLASS = (GOVD_SHARED | GOVD_PRIVATE | GOVD_FIRSTPRIVATE
74 | GOVD_LASTPRIVATE | GOVD_REDUCTION | GOVD_LOCAL) 74 | GOVD_LASTPRIVATE | GOVD_REDUCTION | GOVD_LOCAL)
75 }; 75 };
76 76
77 77
78 enum omp_region_type 78 enum omp_region_type
79 { 79 {
109 /* Forward declarations. */ 109 /* Forward declarations. */
110 static enum gimplify_status gimplify_compound_expr (tree *, gimple_seq *, bool); 110 static enum gimplify_status gimplify_compound_expr (tree *, gimple_seq *, bool);
111 111
112 /* Mark X addressable. Unlike the langhook we expect X to be in gimple 112 /* Mark X addressable. Unlike the langhook we expect X to be in gimple
113 form and we don't do any syntax checking. */ 113 form and we don't do any syntax checking. */
114 static void 114 void
115 mark_addressable (tree x) 115 mark_addressable (tree x)
116 { 116 {
117 while (handled_component_p (x)) 117 while (handled_component_p (x))
118 x = TREE_OPERAND (x, 0); 118 x = TREE_OPERAND (x, 0);
119 if (TREE_CODE (x) != VAR_DECL && TREE_CODE (x) != PARM_DECL) 119 if (TREE_CODE (x) != VAR_DECL
120 && TREE_CODE (x) != PARM_DECL
121 && TREE_CODE (x) != RESULT_DECL)
120 return ; 122 return ;
121 TREE_ADDRESSABLE (x) = 1; 123 TREE_ADDRESSABLE (x) = 1;
122 } 124 }
123 125
124 /* Return a hash value for a formal temporary table entry. */ 126 /* Return a hash value for a formal temporary table entry. */
214 216
215 void 217 void
216 pop_gimplify_context (gimple body) 218 pop_gimplify_context (gimple body)
217 { 219 {
218 struct gimplify_ctx *c = gimplify_ctxp; 220 struct gimplify_ctx *c = gimplify_ctxp;
219 tree t;
220 221
221 gcc_assert (c && (c->bind_expr_stack == NULL 222 gcc_assert (c && (c->bind_expr_stack == NULL
222 || VEC_empty (gimple, c->bind_expr_stack))); 223 || VEC_empty (gimple, c->bind_expr_stack)));
223 VEC_free (gimple, heap, c->bind_expr_stack); 224 VEC_free (gimple, heap, c->bind_expr_stack);
224 gimplify_ctxp = c->prev_context; 225 gimplify_ctxp = c->prev_context;
225
226 for (t = c->temps; t ; t = TREE_CHAIN (t))
227 DECL_GIMPLE_FORMAL_TEMP_P (t) = 0;
228 226
229 if (body) 227 if (body)
230 declare_vars (c->temps, body, false); 228 declare_vars (c->temps, body, false);
231 else 229 else
232 record_vars (c->temps); 230 record_vars (c->temps);
354 tree_stmt_iterator i; 352 tree_stmt_iterator i;
355 353
356 if (!list) 354 if (!list)
357 { 355 {
358 if (t && TREE_CODE (t) == STATEMENT_LIST) 356 if (t && TREE_CODE (t) == STATEMENT_LIST)
359 { 357 {
360 *list_p = t; 358 *list_p = t;
361 return; 359 return;
362 } 360 }
363 *list_p = list = alloc_stmt_list (); 361 *list_p = list = alloc_stmt_list ();
364 } 362 }
365 363
366 i = tsi_last (list); 364 i = tsi_last (list);
367 tsi_link_after (&i, t, TSI_CONTINUE_LINKING); 365 tsi_link_after (&i, t, TSI_CONTINUE_LINKING);
427 int i; 425 int i;
428 426
429 for (i = 2; i < 8 && len > i; i++) 427 for (i = 2; i < 8 && len > i; i++)
430 { 428 {
431 if (name[len - i] == '.') 429 if (name[len - i] == '.')
432 { 430 {
433 name[len - i] = '\0'; 431 name[len - i] = '\0';
434 break; 432 break;
435 } 433 }
436 } 434 }
437 }
438
439 /* Subroutine for find_single_pointer_decl. */
440
441 static tree
442 find_single_pointer_decl_1 (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
443 void *data)
444 {
445 tree *pdecl = (tree *) data;
446
447 /* We are only looking for pointers at the same level as the
448 original tree; we must not look through any indirections.
449 Returning anything other than NULL_TREE will cause the caller to
450 not find a base. */
451 if (REFERENCE_CLASS_P (*tp))
452 return *tp;
453
454 if (DECL_P (*tp) && POINTER_TYPE_P (TREE_TYPE (*tp)))
455 {
456 if (*pdecl)
457 {
458 /* We already found a pointer decl; return anything other
459 than NULL_TREE to unwind from walk_tree signalling that
460 we have a duplicate. */
461 return *tp;
462 }
463 *pdecl = *tp;
464 }
465
466 return NULL_TREE;
467 }
468
469 /* Find the single DECL of pointer type in the tree T, used directly
470 rather than via an indirection, and return it. If there are zero
471 or more than one such DECLs, return NULL. */
472
473 static tree
474 find_single_pointer_decl (tree t)
475 {
476 tree decl = NULL_TREE;
477
478 if (walk_tree (&t, find_single_pointer_decl_1, &decl, NULL))
479 {
480 /* find_single_pointer_decl_1 returns a nonzero value, causing
481 walk_tree to return a nonzero value, to indicate that it
482 found more than one pointer DECL or that it found an
483 indirection. */
484 return NULL_TREE;
485 }
486
487 return decl;
488 } 435 }
489 436
490 /* Create a new temporary name with PREFIX. Returns an identifier. */ 437 /* Create a new temporary name with PREFIX. Returns an identifier. */
491 438
492 static GTY(()) unsigned int tmp_var_id_num; 439 static GTY(()) unsigned int tmp_var_id_num;
520 467
521 /* Make the type of the variable writable. */ 468 /* Make the type of the variable writable. */
522 new_type = build_type_variant (type, 0, 0); 469 new_type = build_type_variant (type, 0, 0);
523 TYPE_ATTRIBUTES (new_type) = TYPE_ATTRIBUTES (type); 470 TYPE_ATTRIBUTES (new_type) = TYPE_ATTRIBUTES (type);
524 471
525 tmp_var = build_decl (VAR_DECL, prefix ? create_tmp_var_name (prefix) : NULL, 472 tmp_var = build_decl (input_location,
526 type); 473 VAR_DECL, prefix ? create_tmp_var_name (prefix) : NULL,
474 type);
527 475
528 /* The variable was declared by the compiler. */ 476 /* The variable was declared by the compiler. */
529 DECL_ARTIFICIAL (tmp_var) = 1; 477 DECL_ARTIFICIAL (tmp_var) = 1;
530 /* And we don't want debug info for it. */ 478 /* And we don't want debug info for it. */
531 DECL_IGNORED_P (tmp_var) = 1; 479 DECL_IGNORED_P (tmp_var) = 1;
593 void **slot; 541 void **slot;
594 542
595 elt.val = val; 543 elt.val = val;
596 if (gimplify_ctxp->temp_htab == NULL) 544 if (gimplify_ctxp->temp_htab == NULL)
597 gimplify_ctxp->temp_htab 545 gimplify_ctxp->temp_htab
598 = htab_create (1000, gimple_tree_hash, gimple_tree_eq, free); 546 = htab_create (1000, gimple_tree_hash, gimple_tree_eq, free);
599 slot = htab_find_slot (gimplify_ctxp->temp_htab, (void *)&elt, INSERT); 547 slot = htab_find_slot (gimplify_ctxp->temp_htab, (void *)&elt, INSERT);
600 if (*slot == NULL) 548 if (*slot == NULL)
601 { 549 {
602 elt_p = XNEW (elt_t); 550 elt_p = XNEW (elt_t);
603 elt_p->val = val; 551 elt_p->val = val;
604 elt_p->temp = ret = create_tmp_from_val (val); 552 elt_p->temp = ret = create_tmp_from_val (val);
605 *slot = (void *) elt_p; 553 *slot = (void *) elt_p;
606 } 554 }
607 else 555 else
608 { 556 {
609 elt_p = (elt_t *) *slot; 557 elt_p = (elt_t *) *slot;
610 ret = elt_p->temp; 558 ret = elt_p->temp;
611 } 559 }
612 } 560 }
613
614 if (is_formal)
615 DECL_GIMPLE_FORMAL_TEMP_P (ret) = 1;
616 561
617 return ret; 562 return ret;
618 } 563 }
619 564
620 565
622 assignmed to a temporary. Note that this predicate should only be 567 assignmed to a temporary. Note that this predicate should only be
623 used during gimplification. See the rationale for this in 568 used during gimplification. See the rationale for this in
624 gimplify_modify_expr. */ 569 gimplify_modify_expr. */
625 570
626 static bool 571 static bool
627 is_gimple_formal_tmp_or_call_rhs (tree t) 572 is_gimple_reg_rhs_or_call (tree t)
628 { 573 {
629 return TREE_CODE (t) == CALL_EXPR || is_gimple_formal_tmp_rhs (t); 574 return (get_gimple_rhs_class (TREE_CODE (t)) != GIMPLE_INVALID_RHS
630 } 575 || TREE_CODE (t) == CALL_EXPR);
631
632 /* Returns true iff T is a valid RHS for an assignment to a renamed
633 user -- or front-end generated artificial -- variable. */
634
635 static bool
636 is_gimple_reg_or_call_rhs (tree t)
637 {
638 /* If the RHS of the MODIFY_EXPR may throw or make a nonlocal goto
639 and the LHS is a user variable, then we need to introduce a formal
640 temporary. This way the optimizers can determine that the user
641 variable is only modified if evaluation of the RHS does not throw.
642
643 Don't force a temp of a non-renamable type; the copy could be
644 arbitrarily expensive. Instead we will generate a VDEF for
645 the assignment. */
646
647 if (is_gimple_reg_type (TREE_TYPE (t))
648 && ((TREE_CODE (t) == CALL_EXPR && TREE_SIDE_EFFECTS (t))
649 || tree_could_throw_p (t)))
650 return false;
651
652 return is_gimple_formal_tmp_or_call_rhs (t);
653 } 576 }
654 577
655 /* Return true if T is a valid memory RHS or a CALL_EXPR. Note that 578 /* Return true if T is a valid memory RHS or a CALL_EXPR. Note that
656 this predicate should only be used during gimplification. See the 579 this predicate should only be used during gimplification. See the
657 rationale for this in gimplify_modify_expr. */ 580 rationale for this in gimplify_modify_expr. */
658 581
659 static bool 582 static bool
660 is_gimple_mem_or_call_rhs (tree t) 583 is_gimple_mem_rhs_or_call (tree t)
661 { 584 {
662 /* If we're dealing with a renamable type, either source or dest must be 585 /* If we're dealing with a renamable type, either source or dest must be
663 a renamed variable. */ 586 a renamed variable. */
664 if (is_gimple_reg_type (TREE_TYPE (t))) 587 if (is_gimple_reg_type (TREE_TYPE (t)))
665 return is_gimple_val (t); 588 return is_gimple_val (t);
666 else 589 else
667 return is_gimple_formal_tmp_or_call_rhs (t); 590 return (is_gimple_val (t) || is_gimple_lvalue (t)
668 } 591 || TREE_CODE (t) == CALL_EXPR);
669 592 }
593
594 /* Helper for get_formal_tmp_var and get_initialized_tmp_var. */
595
596 static tree
597 internal_get_tmp_var (tree val, gimple_seq *pre_p, gimple_seq *post_p,
598 bool is_formal)
599 {
600 tree t, mod;
601
602 /* Notice that we explicitly allow VAL to be a CALL_EXPR so that we
603 can create an INIT_EXPR and convert it into a GIMPLE_CALL below. */
604 gimplify_expr (&val, pre_p, post_p, is_gimple_reg_rhs_or_call,
605 fb_rvalue);
606
607 t = lookup_tmp_var (val, is_formal);
608
609 if (is_formal
610 && (TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE
611 || TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE))
612 DECL_GIMPLE_REG_P (t) = 1;
613
614 mod = build2 (INIT_EXPR, TREE_TYPE (t), t, unshare_expr (val));
615
616 if (EXPR_HAS_LOCATION (val))
617 SET_EXPR_LOCATION (mod, EXPR_LOCATION (val));
618 else
619 SET_EXPR_LOCATION (mod, input_location);
620
621 /* gimplify_modify_expr might want to reduce this further. */
622 gimplify_and_add (mod, pre_p);
623 ggc_free (mod);
624
625 /* If we're gimplifying into ssa, gimplify_modify_expr will have
626 given our temporary an SSA name. Find and return it. */
627 if (gimplify_ctxp->into_ssa)
628 {
629 gimple last = gimple_seq_last_stmt (*pre_p);
630 t = gimple_get_lhs (last);
631 }
632
633 return t;
634 }
670 635
671 /* Returns a formal temporary variable initialized with VAL. PRE_P is as 636 /* Returns a formal temporary variable initialized with VAL. PRE_P is as
672 in gimplify_expr. Only use this function if: 637 in gimplify_expr. Only use this function if:
673 638
674 1) The value of the unfactored expression represented by VAL will not 639 1) The value of the unfactored expression represented by VAL will not
678 For instance, #1 means that this is inappropriate for SAVE_EXPR temps, 643 For instance, #1 means that this is inappropriate for SAVE_EXPR temps,
679 and #2 means it is inappropriate for && temps. 644 and #2 means it is inappropriate for && temps.
680 645
681 For other cases, use get_initialized_tmp_var instead. */ 646 For other cases, use get_initialized_tmp_var instead. */
682 647
683 static tree
684 internal_get_tmp_var (tree val, gimple_seq *pre_p, gimple_seq *post_p,
685 bool is_formal)
686 {
687 tree t, mod;
688
689 /* Notice that we explicitly allow VAL to be a CALL_EXPR so that we
690 can create an INIT_EXPR and convert it into a GIMPLE_CALL below. */
691 gimplify_expr (&val, pre_p, post_p, is_gimple_formal_tmp_or_call_rhs,
692 fb_rvalue);
693
694 t = lookup_tmp_var (val, is_formal);
695
696 if (is_formal)
697 {
698 tree u = find_single_pointer_decl (val);
699
700 if (u && TREE_CODE (u) == VAR_DECL && DECL_BASED_ON_RESTRICT_P (u))
701 u = DECL_GET_RESTRICT_BASE (u);
702 if (u && TYPE_RESTRICT (TREE_TYPE (u)))
703 {
704 if (DECL_BASED_ON_RESTRICT_P (t))
705 gcc_assert (u == DECL_GET_RESTRICT_BASE (t));
706 else
707 {
708 DECL_BASED_ON_RESTRICT_P (t) = 1;
709 SET_DECL_RESTRICT_BASE (t, u);
710 }
711 }
712 }
713
714 if (TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE
715 || TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE)
716 DECL_GIMPLE_REG_P (t) = 1;
717
718 mod = build2 (INIT_EXPR, TREE_TYPE (t), t, unshare_expr (val));
719
720 if (EXPR_HAS_LOCATION (val))
721 SET_EXPR_LOCUS (mod, EXPR_LOCUS (val));
722 else
723 SET_EXPR_LOCATION (mod, input_location);
724
725 /* gimplify_modify_expr might want to reduce this further. */
726 gimplify_and_add (mod, pre_p);
727 ggc_free (mod);
728
729 /* If we're gimplifying into ssa, gimplify_modify_expr will have
730 given our temporary an SSA name. Find and return it. */
731 if (gimplify_ctxp->into_ssa)
732 {
733 gimple last = gimple_seq_last_stmt (*pre_p);
734 t = gimple_get_lhs (last);
735 }
736
737 return t;
738 }
739
740 /* Returns a formal temporary variable initialized with VAL. PRE_P
741 points to a sequence where side-effects needed to compute VAL should be
742 stored. */
743
744 tree 648 tree
745 get_formal_tmp_var (tree val, gimple_seq *pre_p) 649 get_formal_tmp_var (tree val, gimple_seq *pre_p)
746 { 650 {
747 return internal_get_tmp_var (val, pre_p, NULL, true); 651 return internal_get_tmp_var (val, pre_p, NULL, true);
748 } 652 }
772 temps = nreverse (last); 676 temps = nreverse (last);
773 677
774 block = gimple_bind_block (scope); 678 block = gimple_bind_block (scope);
775 gcc_assert (!block || TREE_CODE (block) == BLOCK); 679 gcc_assert (!block || TREE_CODE (block) == BLOCK);
776 if (!block || !debug_info) 680 if (!block || !debug_info)
777 { 681 {
778 TREE_CHAIN (last) = gimple_bind_vars (scope); 682 TREE_CHAIN (last) = gimple_bind_vars (scope);
779 gimple_bind_set_vars (scope, temps); 683 gimple_bind_set_vars (scope, temps);
780 } 684 }
781 else 685 else
782 { 686 {
783 /* We need to attach the nodes both to the BIND_EXPR and to its 687 /* We need to attach the nodes both to the BIND_EXPR and to its
784 associated BLOCK for debugging purposes. The key point here 688 associated BLOCK for debugging purposes. The key point here
785 is that the BLOCK_VARS of the BIND_EXPR_BLOCK of a BIND_EXPR 689 is that the BLOCK_VARS of the BIND_EXPR_BLOCK of a BIND_EXPR
786 is a subchain of the BIND_EXPR_VARS of the BIND_EXPR. */ 690 is a subchain of the BIND_EXPR_VARS of the BIND_EXPR. */
787 if (BLOCK_VARS (block)) 691 if (BLOCK_VARS (block))
788 BLOCK_VARS (block) = chainon (BLOCK_VARS (block), temps); 692 BLOCK_VARS (block) = chainon (BLOCK_VARS (block), temps);
789 else 693 else
790 { 694 {
791 gimple_bind_set_vars (scope, 695 gimple_bind_set_vars (scope,
792 chainon (gimple_bind_vars (scope), temps)); 696 chainon (gimple_bind_vars (scope), temps));
793 BLOCK_VARS (block) = temps; 697 BLOCK_VARS (block) = temps;
794 } 698 }
795 } 699 }
796 } 700 }
797 } 701 }
798 702
799 /* For VAR a VAR_DECL of variable size, try to find a constant upper bound 703 /* For VAR a VAR_DECL of variable size, try to find a constant upper bound
800 for the size and adjust DECL_SIZE/DECL_SIZE_UNIT accordingly. Abort if 704 for the size and adjust DECL_SIZE/DECL_SIZE_UNIT accordingly. Abort if
839 TREE_CHAIN (tmp) = gimplify_ctxp->temps; 743 TREE_CHAIN (tmp) = gimplify_ctxp->temps;
840 gimplify_ctxp->temps = tmp; 744 gimplify_ctxp->temps = tmp;
841 745
842 /* Mark temporaries local within the nearest enclosing parallel. */ 746 /* Mark temporaries local within the nearest enclosing parallel. */
843 if (gimplify_omp_ctxp) 747 if (gimplify_omp_ctxp)
844 { 748 {
845 struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp; 749 struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
846 while (ctx && ctx->region_type == ORT_WORKSHARE) 750 while (ctx && ctx->region_type == ORT_WORKSHARE)
847 ctx = ctx->outer_context; 751 ctx = ctx->outer_context;
848 if (ctx) 752 if (ctx)
849 omp_add_variable (ctx, tmp, GOVD_LOCAL | GOVD_SEEN); 753 omp_add_variable (ctx, tmp, GOVD_LOCAL | GOVD_SEEN);
850 } 754 }
851 } 755 }
852 else if (cfun) 756 else if (cfun)
853 record_vars (tmp); 757 record_vars (tmp);
854 else 758 else
855 { 759 {
856 gimple_seq body_seq; 760 gimple_seq body_seq;
857 761
858 /* This case is for nested functions. We need to expose the locals 762 /* This case is for nested functions. We need to expose the locals
859 they create. */ 763 they create. */
860 body_seq = gimple_body (current_function_decl); 764 body_seq = gimple_body (current_function_decl);
861 declare_vars (tmp, gimple_seq_first_stmt (body_seq), false); 765 declare_vars (tmp, gimple_seq_first_stmt (body_seq), false);
862 } 766 }
863 } 767 }
864 768
874 return false; 778 return false;
875 779
876 return true; 780 return true;
877 } 781 }
878 782
879 /* Same, but for a tree. */
880
881 static bool
882 tree_should_carry_location_p (const_tree stmt)
883 {
884 /* Don't emit a line note for a label. We particularly don't want to
885 emit one for the break label, since it doesn't actually correspond
886 to the beginning of the loop/switch. */
887 if (TREE_CODE (stmt) == LABEL_EXPR)
888 return false;
889
890 /* Do not annotate empty statements, since it confuses gcov. */
891 if (!TREE_SIDE_EFFECTS (stmt))
892 return false;
893
894 return true;
895 }
896 783
897 /* Return true if a location should not be emitted for this statement 784 /* Return true if a location should not be emitted for this statement
898 by annotate_one_with_location. */ 785 by annotate_one_with_location. */
899 786
900 static inline bool 787 static inline bool
912 /* The PLF flags are initialized to 0 when a new tuple is created, 799 /* The PLF flags are initialized to 0 when a new tuple is created,
913 so no need to initialize it anywhere. */ 800 so no need to initialize it anywhere. */
914 gimple_set_plf (g, GF_PLF_1, true); 801 gimple_set_plf (g, GF_PLF_1, true);
915 } 802 }
916 803
917 /* Set the location for gimple statement GS to LOCUS. */ 804 /* Set the location for gimple statement GS to LOCATION. */
918 805
919 static void 806 static void
920 annotate_one_with_location (gimple gs, location_t location) 807 annotate_one_with_location (gimple gs, location_t location)
921 { 808 {
922 if (!gimple_has_location (gs) 809 if (!gimple_has_location (gs)
923 && !gimple_do_not_emit_location_p (gs) 810 && !gimple_do_not_emit_location_p (gs)
924 && should_carry_location_p (gs)) 811 && should_carry_location_p (gs))
925 gimple_set_location (gs, location); 812 gimple_set_location (gs, location);
926 } 813 }
927 814
928 /* Same, but for tree T. */
929
930 static void
931 tree_annotate_one_with_location (tree t, location_t location)
932 {
933 if (CAN_HAVE_LOCATION_P (t)
934 && ! EXPR_HAS_LOCATION (t) && tree_should_carry_location_p (t))
935 SET_EXPR_LOCATION (t, location);
936 }
937
938 815
939 /* Set LOCATION for all the statements after iterator GSI in sequence 816 /* Set LOCATION for all the statements after iterator GSI in sequence
940 SEQ. If GSI is pointing to the end of the sequence, start with the 817 SEQ. If GSI is pointing to the end of the sequence, start with the
941 first statement in SEQ. */ 818 first statement in SEQ. */
942 819
943 static void 820 static void
944 annotate_all_with_location_after (gimple_seq seq, gimple_stmt_iterator gsi, 821 annotate_all_with_location_after (gimple_seq seq, gimple_stmt_iterator gsi,
945 location_t location) 822 location_t location)
946 { 823 {
947 if (gsi_end_p (gsi)) 824 if (gsi_end_p (gsi))
948 gsi = gsi_start (seq); 825 gsi = gsi_start (seq);
949 else 826 else
950 gsi_next (&gsi); 827 gsi_next (&gsi);
952 for (; !gsi_end_p (gsi); gsi_next (&gsi)) 829 for (; !gsi_end_p (gsi); gsi_next (&gsi))
953 annotate_one_with_location (gsi_stmt (gsi), location); 830 annotate_one_with_location (gsi_stmt (gsi), location);
954 } 831 }
955 832
956 833
957 /* Set the location for all the statements in a sequence STMT_P to LOCUS. */ 834 /* Set the location for all the statements in a sequence STMT_P to LOCATION. */
958 835
959 void 836 void
960 annotate_all_with_location (gimple_seq stmt_p, location_t location) 837 annotate_all_with_location (gimple_seq stmt_p, location_t location)
961 { 838 {
962 gimple_stmt_iterator i; 839 gimple_stmt_iterator i;
966 843
967 for (i = gsi_start (stmt_p); !gsi_end_p (i); gsi_next (&i)) 844 for (i = gsi_start (stmt_p); !gsi_end_p (i); gsi_next (&i))
968 { 845 {
969 gimple gs = gsi_stmt (i); 846 gimple gs = gsi_stmt (i);
970 annotate_one_with_location (gs, location); 847 annotate_one_with_location (gs, location);
971 }
972 }
973
974 /* Same, but for statement or statement list in *STMT_P. */
975
976 void
977 tree_annotate_all_with_location (tree *stmt_p, location_t location)
978 {
979 tree_stmt_iterator i;
980
981 if (!*stmt_p)
982 return;
983
984 for (i = tsi_start (*stmt_p); !tsi_end_p (i); tsi_next (&i))
985 {
986 tree t = tsi_stmt (i);
987
988 /* Assuming we've already been gimplified, we shouldn't
989 see nested chaining constructs anymore. */
990 gcc_assert (TREE_CODE (t) != STATEMENT_LIST
991 && TREE_CODE (t) != COMPOUND_EXPR);
992
993 tree_annotate_one_with_location (t, location);
994 } 848 }
995 } 849 }
996 850
997 851
998 /* Similar to copy_tree_r() but do not copy SAVE_EXPR or TARGET_EXPR nodes. 852 /* Similar to copy_tree_r() but do not copy SAVE_EXPR or TARGET_EXPR nodes.
1008 if (TREE_CODE_CLASS (code) == tcc_type 862 if (TREE_CODE_CLASS (code) == tcc_type
1009 || TREE_CODE_CLASS (code) == tcc_declaration 863 || TREE_CODE_CLASS (code) == tcc_declaration
1010 || TREE_CODE_CLASS (code) == tcc_constant 864 || TREE_CODE_CLASS (code) == tcc_constant
1011 || code == SAVE_EXPR || code == TARGET_EXPR 865 || code == SAVE_EXPR || code == TARGET_EXPR
1012 /* We can't do anything sensible with a BLOCK used as an expression, 866 /* We can't do anything sensible with a BLOCK used as an expression,
1013 but we also can't just die when we see it because of non-expression 867 but we also can't just die when we see it because of non-expression
1014 uses. So just avert our eyes and cross our fingers. Silly Java. */ 868 uses. So just avert our eyes and cross our fingers. Silly Java. */
1015 || code == BLOCK) 869 || code == BLOCK)
1016 *walk_subtrees = 0; 870 *walk_subtrees = 0;
1017 else 871 else
1018 { 872 {
1019 gcc_assert (code != BIND_EXPR); 873 gcc_assert (code != BIND_EXPR);
1032 done once. If we were to unshare something like SAVE_EXPR(i++), the 886 done once. If we were to unshare something like SAVE_EXPR(i++), the
1033 gimplification process would create wrong code. */ 887 gimplification process would create wrong code. */
1034 888
1035 static tree 889 static tree
1036 copy_if_shared_r (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED, 890 copy_if_shared_r (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
1037 void *data ATTRIBUTE_UNUSED) 891 void *data ATTRIBUTE_UNUSED)
1038 { 892 {
1039 tree t = *tp; 893 tree t = *tp;
1040 enum tree_code code = TREE_CODE (t); 894 enum tree_code code = TREE_CODE (t);
1041 895
1042 /* Skip types, decls, and constants. But we do want to look at their 896 /* Skip types, decls, and constants. But we do want to look at their
1046 if (TREE_CODE_CLASS (code) == tcc_type 900 if (TREE_CODE_CLASS (code) == tcc_type
1047 || TREE_CODE_CLASS (code) == tcc_declaration 901 || TREE_CODE_CLASS (code) == tcc_declaration
1048 || TREE_CODE_CLASS (code) == tcc_constant) 902 || TREE_CODE_CLASS (code) == tcc_constant)
1049 { 903 {
1050 if (TREE_VISITED (t)) 904 if (TREE_VISITED (t))
1051 *walk_subtrees = 0; 905 *walk_subtrees = 0;
1052 else 906 else
1053 TREE_VISITED (t) = 1; 907 TREE_VISITED (t) = 1;
1054 } 908 }
1055 909
1056 /* If this node has been visited already, unshare it and don't look 910 /* If this node has been visited already, unshare it and don't look
1057 any deeper. */ 911 any deeper. */
1058 else if (TREE_VISITED (t)) 912 else if (TREE_VISITED (t))
1068 return NULL_TREE; 922 return NULL_TREE;
1069 } 923 }
1070 924
1071 static tree 925 static tree
1072 unmark_visited_r (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED, 926 unmark_visited_r (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
1073 void *data ATTRIBUTE_UNUSED) 927 void *data ATTRIBUTE_UNUSED)
1074 { 928 {
1075 if (TREE_VISITED (*tp)) 929 if (TREE_VISITED (*tp))
1076 TREE_VISITED (*tp) = 0; 930 TREE_VISITED (*tp) = 0;
1077 else 931 else
1078 *walk_subtrees = 0; 932 *walk_subtrees = 0;
1131 if (type && !VOID_TYPE_P (type)) 985 if (type && !VOID_TYPE_P (type))
1132 { 986 {
1133 tree *p; 987 tree *p;
1134 988
1135 /* Set p to point to the body of the wrapper. Loop until we find 989 /* Set p to point to the body of the wrapper. Loop until we find
1136 something that isn't a wrapper. */ 990 something that isn't a wrapper. */
1137 for (p = &wrapper; p && *p; ) 991 for (p = &wrapper; p && *p; )
1138 { 992 {
1139 switch (TREE_CODE (*p)) 993 switch (TREE_CODE (*p))
1140 { 994 {
1141 case BIND_EXPR: 995 case BIND_EXPR:
1142 TREE_SIDE_EFFECTS (*p) = 1; 996 TREE_SIDE_EFFECTS (*p) = 1;
1143 TREE_TYPE (*p) = void_type_node; 997 TREE_TYPE (*p) = void_type_node;
1144 /* For a BIND_EXPR, the body is operand 1. */ 998 /* For a BIND_EXPR, the body is operand 1. */
1145 p = &BIND_EXPR_BODY (*p); 999 p = &BIND_EXPR_BODY (*p);
1146 break; 1000 break;
1147 1001
1148 case CLEANUP_POINT_EXPR: 1002 case CLEANUP_POINT_EXPR:
1149 case TRY_FINALLY_EXPR: 1003 case TRY_FINALLY_EXPR:
1150 case TRY_CATCH_EXPR: 1004 case TRY_CATCH_EXPR:
1151 TREE_SIDE_EFFECTS (*p) = 1; 1005 TREE_SIDE_EFFECTS (*p) = 1;
1152 TREE_TYPE (*p) = void_type_node; 1006 TREE_TYPE (*p) = void_type_node;
1153 p = &TREE_OPERAND (*p, 0); 1007 p = &TREE_OPERAND (*p, 0);
1154 break; 1008 break;
1155 1009
1156 case STATEMENT_LIST: 1010 case STATEMENT_LIST:
1157 { 1011 {
1158 tree_stmt_iterator i = tsi_last (*p); 1012 tree_stmt_iterator i = tsi_last (*p);
1159 TREE_SIDE_EFFECTS (*p) = 1; 1013 TREE_SIDE_EFFECTS (*p) = 1;
1160 TREE_TYPE (*p) = void_type_node; 1014 TREE_TYPE (*p) = void_type_node;
1161 p = tsi_end_p (i) ? NULL : tsi_stmt_ptr (i); 1015 p = tsi_end_p (i) ? NULL : tsi_stmt_ptr (i);
1162 } 1016 }
1163 break; 1017 break;
1164 1018
1165 case COMPOUND_EXPR: 1019 case COMPOUND_EXPR:
1166 /* Advance to the last statement. Set all container types to void. */ 1020 /* Advance to the last statement. Set all container types to void. */
1167 for (; TREE_CODE (*p) == COMPOUND_EXPR; p = &TREE_OPERAND (*p, 1)) 1021 for (; TREE_CODE (*p) == COMPOUND_EXPR; p = &TREE_OPERAND (*p, 1))
1168 { 1022 {
1169 TREE_SIDE_EFFECTS (*p) = 1; 1023 TREE_SIDE_EFFECTS (*p) = 1;
1170 TREE_TYPE (*p) = void_type_node; 1024 TREE_TYPE (*p) = void_type_node;
1171 } 1025 }
1172 break; 1026 break;
1173 1027
1174 default: 1028 default:
1175 goto out; 1029 goto out;
1176 } 1030 }
1177 } 1031 }
1178 1032
1179 out: 1033 out:
1180 if (p == NULL || IS_EMPTY_STMT (*p)) 1034 if (p == NULL || IS_EMPTY_STMT (*p))
1181 temp = NULL_TREE; 1035 temp = NULL_TREE;
1182 else if (temp) 1036 else if (temp)
1183 { 1037 {
1184 /* The wrapper is on the RHS of an assignment that we're pushing 1038 /* The wrapper is on the RHS of an assignment that we're pushing
1185 down. */ 1039 down. */
1186 gcc_assert (TREE_CODE (temp) == INIT_EXPR 1040 gcc_assert (TREE_CODE (temp) == INIT_EXPR
1187 || TREE_CODE (temp) == MODIFY_EXPR); 1041 || TREE_CODE (temp) == MODIFY_EXPR);
1188 TREE_OPERAND (temp, 1) = *p; 1042 TREE_OPERAND (temp, 1) = *p;
1189 *p = temp; 1043 *p = temp;
1190 } 1044 }
1191 else 1045 else
1192 { 1046 {
1193 temp = create_tmp_var (type, "retval"); 1047 temp = create_tmp_var (type, "retval");
1194 *p = build2 (INIT_EXPR, type, temp, *p); 1048 *p = build2 (INIT_EXPR, type, temp, *p);
1195 } 1049 }
1196 1050
1197 return temp; 1051 return temp;
1198 } 1052 }
1199 1053
1200 return NULL_TREE; 1054 return NULL_TREE;
1211 *save = gimple_build_call (implicit_built_in_decls[BUILT_IN_STACK_SAVE], 0); 1065 *save = gimple_build_call (implicit_built_in_decls[BUILT_IN_STACK_SAVE], 0);
1212 tmp_var = create_tmp_var (ptr_type_node, "saved_stack"); 1066 tmp_var = create_tmp_var (ptr_type_node, "saved_stack");
1213 gimple_call_set_lhs (*save, tmp_var); 1067 gimple_call_set_lhs (*save, tmp_var);
1214 1068
1215 *restore = gimple_build_call (implicit_built_in_decls[BUILT_IN_STACK_RESTORE], 1069 *restore = gimple_build_call (implicit_built_in_decls[BUILT_IN_STACK_RESTORE],
1216 1, tmp_var); 1070 1, tmp_var);
1217 } 1071 }
1218 1072
1219 /* Gimplify a BIND_EXPR. Just voidify and recurse. */ 1073 /* Gimplify a BIND_EXPR. Just voidify and recurse. */
1220 1074
1221 static enum gimplify_status 1075 static enum gimplify_status
1231 1085
1232 /* Mark variables seen in this bind expr. */ 1086 /* Mark variables seen in this bind expr. */
1233 for (t = BIND_EXPR_VARS (bind_expr); t ; t = TREE_CHAIN (t)) 1087 for (t = BIND_EXPR_VARS (bind_expr); t ; t = TREE_CHAIN (t))
1234 { 1088 {
1235 if (TREE_CODE (t) == VAR_DECL) 1089 if (TREE_CODE (t) == VAR_DECL)
1236 { 1090 {
1237 struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp; 1091 struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
1238 1092
1239 /* Mark variable as local. */ 1093 /* Mark variable as local. */
1240 if (ctx && !is_global_var (t) 1094 if (ctx && !is_global_var (t)
1241 && (! DECL_SEEN_IN_BIND_EXPR_P (t) 1095 && (! DECL_SEEN_IN_BIND_EXPR_P (t)
1242 || splay_tree_lookup (ctx->variables, 1096 || splay_tree_lookup (ctx->variables,
1243 (splay_tree_key) t) == NULL)) 1097 (splay_tree_key) t) == NULL))
1244 omp_add_variable (gimplify_omp_ctxp, t, GOVD_LOCAL | GOVD_SEEN); 1098 omp_add_variable (gimplify_omp_ctxp, t, GOVD_LOCAL | GOVD_SEEN);
1245 1099
1246 DECL_SEEN_IN_BIND_EXPR_P (t) = 1; 1100 DECL_SEEN_IN_BIND_EXPR_P (t) = 1;
1247 1101
1248 if (DECL_HARD_REGISTER (t) && !is_global_var (t) && cfun) 1102 if (DECL_HARD_REGISTER (t) && !is_global_var (t) && cfun)
1249 cfun->has_local_explicit_reg_vars = true; 1103 cfun->has_local_explicit_reg_vars = true;
1250 } 1104 }
1251 1105
1252 /* Preliminarily mark non-addressed complex variables as eligible 1106 /* Preliminarily mark non-addressed complex variables as eligible
1253 for promotion to gimple registers. We'll transform their uses 1107 for promotion to gimple registers. We'll transform their uses
1254 as we find them. */ 1108 as we find them.
1255 if ((TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE 1109 We exclude complex types if not optimizing because they can be
1256 || TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE) 1110 subject to partial stores in GNU C by means of the __real__ and
1257 && !TREE_THIS_VOLATILE (t) 1111 __imag__ operators and we cannot promote them to total stores
1258 && (TREE_CODE (t) == VAR_DECL && !DECL_HARD_REGISTER (t)) 1112 (see gimplify_modify_expr_complex_part). */
1259 && !needs_to_live_in_memory (t)) 1113 if (optimize
1260 DECL_GIMPLE_REG_P (t) = 1; 1114 && (TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE
1115 || TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE)
1116 && !TREE_THIS_VOLATILE (t)
1117 && (TREE_CODE (t) == VAR_DECL && !DECL_HARD_REGISTER (t))
1118 && !needs_to_live_in_memory (t))
1119 DECL_GIMPLE_REG_P (t) = 1;
1261 } 1120 }
1262 1121
1263 gimple_bind = gimple_build_bind (BIND_EXPR_VARS (bind_expr), NULL, 1122 gimple_bind = gimple_build_bind (BIND_EXPR_VARS (bind_expr), NULL,
1264 BIND_EXPR_BLOCK (bind_expr)); 1123 BIND_EXPR_BLOCK (bind_expr));
1265 gimple_push_bind_expr (gimple_bind); 1124 gimple_push_bind_expr (gimple_bind);
1275 { 1134 {
1276 gimple stack_save, stack_restore, gs; 1135 gimple stack_save, stack_restore, gs;
1277 gimple_seq cleanup, new_body; 1136 gimple_seq cleanup, new_body;
1278 1137
1279 /* Save stack on entry and restore it on exit. Add a try_finally 1138 /* Save stack on entry and restore it on exit. Add a try_finally
1280 block to achieve this. Note that mudflap depends on the 1139 block to achieve this. Note that mudflap depends on the
1281 format of the emitted code: see mx_register_decls(). */ 1140 format of the emitted code: see mx_register_decls(). */
1282 build_stack_save_restore (&stack_save, &stack_restore); 1141 build_stack_save_restore (&stack_save, &stack_restore);
1283 1142
1284 cleanup = new_body = NULL; 1143 cleanup = new_body = NULL;
1285 gimplify_seq_add_stmt (&cleanup, stack_restore); 1144 gimplify_seq_add_stmt (&cleanup, stack_restore);
1286 gs = gimple_build_try (gimple_bind_body (gimple_bind), cleanup, 1145 gs = gimple_build_try (gimple_bind_body (gimple_bind), cleanup,
1287 GIMPLE_TRY_FINALLY); 1146 GIMPLE_TRY_FINALLY);
1288 1147
1289 gimplify_seq_add_stmt (&new_body, stack_save); 1148 gimplify_seq_add_stmt (&new_body, stack_save);
1290 gimplify_seq_add_stmt (&new_body, gs); 1149 gimplify_seq_add_stmt (&new_body, gs);
1291 gimple_bind_set_body (gimple_bind, new_body); 1150 gimple_bind_set_body (gimple_bind, new_body);
1292 } 1151 }
1331 gimple_set_no_warning (ret, TREE_NO_WARNING (stmt)); 1190 gimple_set_no_warning (ret, TREE_NO_WARNING (stmt));
1332 gimplify_seq_add_stmt (pre_p, ret); 1191 gimplify_seq_add_stmt (pre_p, ret);
1333 return GS_ALL_DONE; 1192 return GS_ALL_DONE;
1334 } 1193 }
1335 1194
1336 if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl))) 1195 if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl)))
1337 #ifndef noCbC 1196 #ifndef noCbC
1338 || ( ret_expr 1197 || ( ret_expr
1339 && TREE_CODE(ret_expr)==CALL_EXPR 1198 && TREE_CODE(ret_expr)==CALL_EXPR
1340 && CbC_IS_CbC_GOTO(ret_expr) 1199 && CbC_IS_CbC_GOTO(ret_expr)
1341 //&& !CbC_IS_CODE_SEGMENT(TREE_TYPE(current_function_decl))) 1200 //&& !CbC_IS_CODE_SEGMENT(TREE_TYPE(current_function_decl)))
1342 && !(current_function_decl&&CbC_IS_CODE_SEGMENT(TREE_TYPE(current_function_decl)))) 1201 && !(current_function_decl&&CbC_IS_CODE_SEGMENT(TREE_TYPE(current_function_decl))))
1343 //&& !(current_function_decl&&CbC_IS_CODE_SEGMENT(current_function_decl))) 1202 //&& !(current_function_decl&&CbC_IS_CODE_SEGMENT(current_function_decl)))
1344 #endif 1203 #endif
1345 ) 1204 )
1346 result_decl = NULL_TREE; 1205 result_decl = NULL_TREE;
1347 else 1206 else
1348 { 1207 {
1349 result_decl = TREE_OPERAND (ret_expr, 0); 1208 result_decl = TREE_OPERAND (ret_expr, 0);
1350 1209
1351 /* See through a return by reference. */ 1210 /* See through a return by reference. */
1352 if (TREE_CODE (result_decl) == INDIRECT_REF) 1211 if (TREE_CODE (result_decl) == INDIRECT_REF)
1353 result_decl = TREE_OPERAND (result_decl, 0); 1212 result_decl = TREE_OPERAND (result_decl, 0);
1354 1213
1355 gcc_assert ((TREE_CODE (ret_expr) == MODIFY_EXPR 1214 gcc_assert ((TREE_CODE (ret_expr) == MODIFY_EXPR
1356 || TREE_CODE (ret_expr) == INIT_EXPR) 1215 || TREE_CODE (ret_expr) == INIT_EXPR)
1357 && TREE_CODE (result_decl) == RESULT_DECL); 1216 && TREE_CODE (result_decl) == RESULT_DECL);
1358 } 1217 }
1359 1218
1360 /* If aggregate_value_p is true, then we can return the bare RESULT_DECL. 1219 /* If aggregate_value_p is true, then we can return the bare RESULT_DECL.
1361 Recall that aggregate_value_p is FALSE for any aggregate type that is 1220 Recall that aggregate_value_p is FALSE for any aggregate type that is
1362 returned in registers. If we're returning values in registers, then 1221 returned in registers. If we're returning values in registers, then
1376 if (TREE_CODE (TREE_TYPE (result)) == COMPLEX_TYPE 1235 if (TREE_CODE (TREE_TYPE (result)) == COMPLEX_TYPE
1377 || TREE_CODE (TREE_TYPE (result)) == VECTOR_TYPE) 1236 || TREE_CODE (TREE_TYPE (result)) == VECTOR_TYPE)
1378 DECL_GIMPLE_REG_P (result) = 1; 1237 DECL_GIMPLE_REG_P (result) = 1;
1379 1238
1380 /* ??? With complex control flow (usually involving abnormal edges), 1239 /* ??? With complex control flow (usually involving abnormal edges),
1381 we can wind up warning about an uninitialized value for this. Due 1240 we can wind up warning about an uninitialized value for this. Due
1382 to how this variable is constructed and initialized, this is never 1241 to how this variable is constructed and initialized, this is never
1383 true. Give up and never warn. */ 1242 true. Give up and never warn. */
1384 TREE_NO_WARNING (result) = 1; 1243 TREE_NO_WARNING (result) = 1;
1385 1244
1386 gimplify_ctxp->return_temp = result; 1245 gimplify_ctxp->return_temp = result;
1387 } 1246 }
1388 1247
1458 if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl)) 1317 if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl))
1459 { 1318 {
1460 tree init = DECL_INITIAL (decl); 1319 tree init = DECL_INITIAL (decl);
1461 1320
1462 if (TREE_CODE (DECL_SIZE_UNIT (decl)) != INTEGER_CST 1321 if (TREE_CODE (DECL_SIZE_UNIT (decl)) != INTEGER_CST
1463 || (!TREE_STATIC (decl) 1322 || (!TREE_STATIC (decl)
1464 && flag_stack_check == GENERIC_STACK_CHECK 1323 && flag_stack_check == GENERIC_STACK_CHECK
1465 && compare_tree_int (DECL_SIZE_UNIT (decl), 1324 && compare_tree_int (DECL_SIZE_UNIT (decl),
1466 STACK_CHECK_MAX_VAR_SIZE) > 0)) 1325 STACK_CHECK_MAX_VAR_SIZE) > 0))
1467 gimplify_vla_decl (decl, seq_p); 1326 gimplify_vla_decl (decl, seq_p);
1468 1327
1469 if (init && init != error_mark_node) 1328 if (init && init != error_mark_node)
1470 { 1329 {
1471 if (!TREE_STATIC (decl)) 1330 if (!TREE_STATIC (decl))
1472 { 1331 {
1473 DECL_INITIAL (decl) = NULL_TREE; 1332 DECL_INITIAL (decl) = NULL_TREE;
1474 init = build2 (INIT_EXPR, void_type_node, decl, init); 1333 init = build2 (INIT_EXPR, void_type_node, decl, init);
1475 gimplify_and_add (init, seq_p); 1334 gimplify_and_add (init, seq_p);
1476 ggc_free (init); 1335 ggc_free (init);
1477 } 1336 }
1478 else 1337 else
1479 /* We must still examine initializers for static variables 1338 /* We must still examine initializers for static variables
1480 as they may contain a label address. */ 1339 as they may contain a label address. */
1481 walk_tree (&init, force_labels_r, NULL, NULL); 1340 walk_tree (&init, force_labels_r, NULL, NULL);
1482 } 1341 }
1483 1342
1484 /* Some front ends do not explicitly declare all anonymous 1343 /* Some front ends do not explicitly declare all anonymous
1485 artificial variables. We compensate here by declaring the 1344 artificial variables. We compensate here by declaring the
1486 variables, though it would be better if the front ends would 1345 variables, though it would be better if the front ends would
1487 explicitly declare them. */ 1346 explicitly declare them. */
1488 if (!DECL_SEEN_IN_BIND_EXPR_P (decl) 1347 if (!DECL_SEEN_IN_BIND_EXPR_P (decl)
1489 && DECL_ARTIFICIAL (decl) && DECL_NAME (decl) == NULL_TREE) 1348 && DECL_ARTIFICIAL (decl) && DECL_NAME (decl) == NULL_TREE)
1490 gimple_add_tmp_var (decl); 1349 gimple_add_tmp_var (decl);
1491 } 1350 }
1492 1351
1493 return GS_ALL_DONE; 1352 return GS_ALL_DONE;
1494 } 1353 }
1495 1354
1499 1358
1500 static enum gimplify_status 1359 static enum gimplify_status
1501 gimplify_loop_expr (tree *expr_p, gimple_seq *pre_p) 1360 gimplify_loop_expr (tree *expr_p, gimple_seq *pre_p)
1502 { 1361 {
1503 tree saved_label = gimplify_ctxp->exit_label; 1362 tree saved_label = gimplify_ctxp->exit_label;
1504 tree start_label = create_artificial_label (); 1363 tree start_label = create_artificial_label (UNKNOWN_LOCATION);
1505 1364
1506 gimplify_seq_add_stmt (pre_p, gimple_build_label (start_label)); 1365 gimplify_seq_add_stmt (pre_p, gimple_build_label (start_label));
1507 1366
1508 gimplify_ctxp->exit_label = NULL_TREE; 1367 gimplify_ctxp->exit_label = NULL_TREE;
1509 1368
1596 VEC (tree,heap) *labels; 1455 VEC (tree,heap) *labels;
1597 VEC (tree,heap) *saved_labels; 1456 VEC (tree,heap) *saved_labels;
1598 tree default_case = NULL_TREE; 1457 tree default_case = NULL_TREE;
1599 size_t i, len; 1458 size_t i, len;
1600 gimple gimple_switch; 1459 gimple gimple_switch;
1601 1460
1602 /* If someone can be bothered to fill in the labels, they can 1461 /* If someone can be bothered to fill in the labels, they can
1603 be bothered to null out the body too. */ 1462 be bothered to null out the body too. */
1604 gcc_assert (!SWITCH_LABELS (switch_expr)); 1463 gcc_assert (!SWITCH_LABELS (switch_expr));
1605 1464
1606 /* save old labels, get new ones from body, then restore the old 1465 /* save old labels, get new ones from body, then restore the old
1607 labels. Save all the things from the switch body to append after. */ 1466 labels. Save all the things from the switch body to append after. */
1608 saved_labels = gimplify_ctxp->case_labels; 1467 saved_labels = gimplify_ctxp->case_labels;
1609 gimplify_ctxp->case_labels = VEC_alloc (tree, heap, 8); 1468 gimplify_ctxp->case_labels = VEC_alloc (tree, heap, 8);
1610 1469
1611 gimplify_stmt (&SWITCH_BODY (switch_expr), &switch_body_seq); 1470 gimplify_stmt (&SWITCH_BODY (switch_expr), &switch_body_seq);
1612 labels = gimplify_ctxp->case_labels; 1471 labels = gimplify_ctxp->case_labels;
1613 gimplify_ctxp->case_labels = saved_labels; 1472 gimplify_ctxp->case_labels = saved_labels;
1614 1473
1615 i = 0; 1474 i = 0;
1616 while (i < VEC_length (tree, labels)) 1475 while (i < VEC_length (tree, labels))
1617 { 1476 {
1618 tree elt = VEC_index (tree, labels, i); 1477 tree elt = VEC_index (tree, labels, i);
1619 tree low = CASE_LOW (elt); 1478 tree low = CASE_LOW (elt);
1620 bool remove_element = FALSE; 1479 bool remove_element = FALSE;
1621 1480
1622 if (low) 1481 if (low)
1623 { 1482 {
1624 /* Discard empty ranges. */ 1483 /* Discard empty ranges. */
1625 tree high = CASE_HIGH (elt); 1484 tree high = CASE_HIGH (elt);
1626 if (high && tree_int_cst_lt (high, low)) 1485 if (high && tree_int_cst_lt (high, low))
1627 remove_element = TRUE; 1486 remove_element = TRUE;
1628 } 1487 }
1629 else 1488 else
1630 { 1489 {
1631 /* The default case must be the last label in the list. */ 1490 /* The default case must be the last label in the list. */
1632 gcc_assert (!default_case); 1491 gcc_assert (!default_case);
1633 default_case = elt; 1492 default_case = elt;
1634 remove_element = TRUE; 1493 remove_element = TRUE;
1635 } 1494 }
1636 1495
1637 if (remove_element) 1496 if (remove_element)
1638 VEC_ordered_remove (tree, labels, i); 1497 VEC_ordered_remove (tree, labels, i);
1639 else 1498 else
1640 i++; 1499 i++;
1641 } 1500 }
1642 len = i; 1501 len = i;
1643 1502
1644 if (!VEC_empty (tree, labels)) 1503 if (!VEC_empty (tree, labels))
1645 sort_case_labels (labels); 1504 sort_case_labels (labels);
1646 1505
1647 if (!default_case) 1506 if (!default_case)
1648 { 1507 {
1649 tree type = TREE_TYPE (switch_expr); 1508 tree type = TREE_TYPE (switch_expr);
1650 1509
1651 /* If the switch has no default label, add one, so that we jump 1510 /* If the switch has no default label, add one, so that we jump
1652 around the switch body. If the labels already cover the whole 1511 around the switch body. If the labels already cover the whole
1653 range of type, add the default label pointing to one of the 1512 range of type, add the default label pointing to one of the
1654 existing labels. */ 1513 existing labels. */
1655 if (type == void_type_node) 1514 if (type == void_type_node)
1656 type = TREE_TYPE (SWITCH_COND (switch_expr)); 1515 type = TREE_TYPE (SWITCH_COND (switch_expr));
1657 if (len 1516 if (len
1658 && INTEGRAL_TYPE_P (type) 1517 && INTEGRAL_TYPE_P (type)
1659 && TYPE_MIN_VALUE (type) 1518 && TYPE_MIN_VALUE (type)
1660 && TYPE_MAX_VALUE (type) 1519 && TYPE_MAX_VALUE (type)
1661 && tree_int_cst_equal (CASE_LOW (VEC_index (tree, labels, 0)), 1520 && tree_int_cst_equal (CASE_LOW (VEC_index (tree, labels, 0)),
1662 TYPE_MIN_VALUE (type))) 1521 TYPE_MIN_VALUE (type)))
1663 { 1522 {
1664 tree low, high = CASE_HIGH (VEC_index (tree, labels, len - 1)); 1523 tree low, high = CASE_HIGH (VEC_index (tree, labels, len - 1));
1665 if (!high) 1524 if (!high)
1666 high = CASE_LOW (VEC_index (tree, labels, len - 1)); 1525 high = CASE_LOW (VEC_index (tree, labels, len - 1));
1667 if (tree_int_cst_equal (high, TYPE_MAX_VALUE (type))) 1526 if (tree_int_cst_equal (high, TYPE_MAX_VALUE (type)))
1668 { 1527 {
1669 for (i = 1; i < len; i++) 1528 for (i = 1; i < len; i++)
1670 { 1529 {
1671 high = CASE_LOW (VEC_index (tree, labels, i)); 1530 high = CASE_LOW (VEC_index (tree, labels, i));
1672 low = CASE_HIGH (VEC_index (tree, labels, i - 1)); 1531 low = CASE_HIGH (VEC_index (tree, labels, i - 1));
1673 if (!low) 1532 if (!low)
1674 low = CASE_LOW (VEC_index (tree, labels, i - 1)); 1533 low = CASE_LOW (VEC_index (tree, labels, i - 1));
1675 if ((TREE_INT_CST_LOW (low) + 1 1534 if ((TREE_INT_CST_LOW (low) + 1
1676 != TREE_INT_CST_LOW (high)) 1535 != TREE_INT_CST_LOW (high))
1677 || (TREE_INT_CST_HIGH (low) 1536 || (TREE_INT_CST_HIGH (low)
1678 + (TREE_INT_CST_LOW (high) == 0) 1537 + (TREE_INT_CST_LOW (high) == 0)
1679 != TREE_INT_CST_HIGH (high))) 1538 != TREE_INT_CST_HIGH (high)))
1680 break; 1539 break;
1681 } 1540 }
1682 if (i == len) 1541 if (i == len)
1683 default_case = build3 (CASE_LABEL_EXPR, void_type_node, 1542 default_case = build3 (CASE_LABEL_EXPR, void_type_node,
1684 NULL_TREE, NULL_TREE, 1543 NULL_TREE, NULL_TREE,
1685 CASE_LABEL (VEC_index (tree, 1544 CASE_LABEL (VEC_index (tree,
1686 labels, 0))); 1545 labels, 0)));
1687 } 1546 }
1688 } 1547 }
1689 1548
1690 if (!default_case) 1549 if (!default_case)
1691 { 1550 {
1692 gimple new_default; 1551 gimple new_default;
1693 1552
1694 default_case = build3 (CASE_LABEL_EXPR, void_type_node, 1553 default_case
1695 NULL_TREE, NULL_TREE, 1554 = build3 (CASE_LABEL_EXPR, void_type_node,
1696 create_artificial_label ()); 1555 NULL_TREE, NULL_TREE,
1697 new_default = gimple_build_label (CASE_LABEL (default_case)); 1556 create_artificial_label (UNKNOWN_LOCATION));
1698 gimplify_seq_add_stmt (&switch_body_seq, new_default); 1557 new_default = gimple_build_label (CASE_LABEL (default_case));
1699 } 1558 gimplify_seq_add_stmt (&switch_body_seq, new_default);
1700 } 1559 }
1701 1560 }
1702 gimple_switch = gimple_build_switch_vec (SWITCH_COND (switch_expr), 1561
1562 gimple_switch = gimple_build_switch_vec (SWITCH_COND (switch_expr),
1703 default_case, labels); 1563 default_case, labels);
1704 gimplify_seq_add_stmt (pre_p, gimple_switch); 1564 gimplify_seq_add_stmt (pre_p, gimple_switch);
1705 gimplify_seq_add_seq (pre_p, switch_body_seq); 1565 gimplify_seq_add_seq (pre_p, switch_body_seq);
1706 VEC_free(tree, heap, labels); 1566 VEC_free(tree, heap, labels);
1707 } 1567 }
1742 /* If there's nowhere to jump, just fall through. */ 1602 /* If there's nowhere to jump, just fall through. */
1743 return NULL_TREE; 1603 return NULL_TREE;
1744 1604
1745 if (*label_p == NULL_TREE) 1605 if (*label_p == NULL_TREE)
1746 { 1606 {
1747 tree label = create_artificial_label (); 1607 tree label = create_artificial_label (UNKNOWN_LOCATION);
1748 *label_p = label; 1608 *label_p = label;
1749 } 1609 }
1750 1610
1751 return build1 (GOTO_EXPR, void_type_node, *label_p); 1611 return build1 (GOTO_EXPR, void_type_node, *label_p);
1752 } 1612 }
1814 tree old_type = TREE_TYPE (expr); 1674 tree old_type = TREE_TYPE (expr);
1815 #endif 1675 #endif
1816 int type_quals; 1676 int type_quals;
1817 1677
1818 /* We need to preserve qualifiers and propagate them from 1678 /* We need to preserve qualifiers and propagate them from
1819 operand 0. */ 1679 operand 0. */
1820 type_quals = TYPE_QUALS (type) 1680 type_quals = TYPE_QUALS (type)
1821 | TYPE_QUALS (TREE_TYPE (TREE_OPERAND (expr, 0))); 1681 | TYPE_QUALS (TREE_TYPE (TREE_OPERAND (expr, 0)));
1822 if (TYPE_QUALS (type) != type_quals) 1682 if (TYPE_QUALS (type) != type_quals)
1823 type = build_qualified_type (TYPE_MAIN_VARIANT (type), type_quals); 1683 type = build_qualified_type (TYPE_MAIN_VARIANT (type), type_quals);
1824 1684
1825 /* Set the type of the COMPONENT_REF to the underlying type. */ 1685 /* Set the type of the COMPONENT_REF to the underlying type. */
1826 TREE_TYPE (expr) = type; 1686 TREE_TYPE (expr) = type;
1827 1687
1828 #ifdef ENABLE_TYPES_CHECKING 1688 #ifdef ENABLE_TYPES_CHECKING
1829 /* It is now a FE error, if the conversion from the canonical 1689 /* It is now a FE error, if the conversion from the canonical
1830 type to the original expression type is not useless. */ 1690 type to the original expression type is not useless. */
1831 gcc_assert (useless_type_conversion_p (old_type, type)); 1691 gcc_assert (useless_type_conversion_p (old_type, type));
1832 #endif 1692 #endif
1833 } 1693 }
1834 } 1694 }
1835 1695
1863 1723
1864 /* The pointer to element type shall be trivially convertible to 1724 /* The pointer to element type shall be trivially convertible to
1865 the expression pointer type. */ 1725 the expression pointer type. */
1866 ddatype = TREE_TYPE (datype); 1726 ddatype = TREE_TYPE (datype);
1867 pddatype = build_pointer_type (ddatype); 1727 pddatype = build_pointer_type (ddatype);
1868 if (!useless_type_conversion_p (pddatype, ddatype)) 1728 if (!useless_type_conversion_p (TYPE_MAIN_VARIANT (TREE_TYPE (expr)),
1729 pddatype))
1869 return; 1730 return;
1870 1731
1871 /* The lower bound and element sizes must be constant. */ 1732 /* The lower bound and element sizes must be constant. */
1872 if (!TYPE_SIZE_UNIT (ddatype) 1733 if (!TYPE_SIZE_UNIT (ddatype)
1873 || TREE_CODE (TYPE_SIZE_UNIT (ddatype)) != INTEGER_CST 1734 || TREE_CODE (TYPE_SIZE_UNIT (ddatype)) != INTEGER_CST
1875 || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (datype))) != INTEGER_CST) 1736 || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (datype))) != INTEGER_CST)
1876 return; 1737 return;
1877 1738
1878 /* All checks succeeded. Build a new node to merge the cast. */ 1739 /* All checks succeeded. Build a new node to merge the cast. */
1879 *expr_p = build4 (ARRAY_REF, ddatype, TREE_OPERAND (addr_expr, 0), 1740 *expr_p = build4 (ARRAY_REF, ddatype, TREE_OPERAND (addr_expr, 0),
1880 TYPE_MIN_VALUE (TYPE_DOMAIN (datype)), 1741 TYPE_MIN_VALUE (TYPE_DOMAIN (datype)),
1881 NULL_TREE, NULL_TREE); 1742 NULL_TREE, NULL_TREE);
1882 *expr_p = build1 (ADDR_EXPR, pddatype, *expr_p); 1743 *expr_p = build1 (ADDR_EXPR, pddatype, *expr_p);
1744
1745 /* We can have stripped a required restrict qualifier above. */
1746 if (!useless_type_conversion_p (TREE_TYPE (expr), TREE_TYPE (*expr_p)))
1747 *expr_p = fold_convert (TREE_TYPE (expr), *expr_p);
1883 } 1748 }
1884 1749
1885 /* *EXPR_P is a NOP_EXPR or CONVERT_EXPR. Remove it and/or other conversions 1750 /* *EXPR_P is a NOP_EXPR or CONVERT_EXPR. Remove it and/or other conversions
1886 underneath as appropriate. */ 1751 underneath as appropriate. */
1887 1752
1888 static enum gimplify_status 1753 static enum gimplify_status
1889 gimplify_conversion (tree *expr_p) 1754 gimplify_conversion (tree *expr_p)
1890 { 1755 {
1891 tree tem; 1756 tree tem;
1757 location_t loc = EXPR_LOCATION (*expr_p);
1892 gcc_assert (CONVERT_EXPR_P (*expr_p)); 1758 gcc_assert (CONVERT_EXPR_P (*expr_p));
1893 1759
1894 /* Then strip away all but the outermost conversion. */ 1760 /* Then strip away all but the outermost conversion. */
1895 STRIP_SIGN_NOPS (TREE_OPERAND (*expr_p, 0)); 1761 STRIP_SIGN_NOPS (TREE_OPERAND (*expr_p, 0));
1896 1762
1897 /* And remove the outermost conversion if it's useless. */ 1763 /* And remove the outermost conversion if it's useless. */
1898 if (tree_ssa_useless_type_conversion (*expr_p)) 1764 if (tree_ssa_useless_type_conversion (*expr_p))
1903 a need for statement. */ 1769 a need for statement. */
1904 if (CONVERT_EXPR_P (*expr_p) 1770 if (CONVERT_EXPR_P (*expr_p)
1905 && POINTER_TYPE_P (TREE_TYPE (*expr_p)) 1771 && POINTER_TYPE_P (TREE_TYPE (*expr_p))
1906 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (*expr_p, 0))) 1772 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (*expr_p, 0)))
1907 && (tem = maybe_fold_offset_to_address 1773 && (tem = maybe_fold_offset_to_address
1908 (TREE_OPERAND (*expr_p, 0), 1774 (EXPR_LOCATION (*expr_p), TREE_OPERAND (*expr_p, 0),
1909 integer_zero_node, TREE_TYPE (*expr_p))) != NULL_TREE) 1775 integer_zero_node, TREE_TYPE (*expr_p))) != NULL_TREE)
1910 *expr_p = tem; 1776 *expr_p = tem;
1911 1777
1912 /* If we still have a conversion at the toplevel, 1778 /* If we still have a conversion at the toplevel,
1913 then canonicalize some constructs. */ 1779 then canonicalize some constructs. */
1914 if (CONVERT_EXPR_P (*expr_p)) 1780 if (CONVERT_EXPR_P (*expr_p))
1915 { 1781 {
1916 tree sub = TREE_OPERAND (*expr_p, 0); 1782 tree sub = TREE_OPERAND (*expr_p, 0);
1917 1783
1918 /* If a NOP conversion is changing the type of a COMPONENT_REF 1784 /* If a NOP conversion is changing the type of a COMPONENT_REF
1919 expression, then canonicalize its type now in order to expose more 1785 expression, then canonicalize its type now in order to expose more
1920 redundant conversions. */ 1786 redundant conversions. */
1921 if (TREE_CODE (sub) == COMPONENT_REF) 1787 if (TREE_CODE (sub) == COMPONENT_REF)
1922 canonicalize_component_ref (&TREE_OPERAND (*expr_p, 0)); 1788 canonicalize_component_ref (&TREE_OPERAND (*expr_p, 0));
1923 1789
1924 /* If a NOP conversion is changing a pointer to array of foo 1790 /* If a NOP conversion is changing a pointer to array of foo
1925 to a pointer to foo, embed that change in the ADDR_EXPR. */ 1791 to a pointer to foo, embed that change in the ADDR_EXPR. */
1926 else if (TREE_CODE (sub) == ADDR_EXPR) 1792 else if (TREE_CODE (sub) == ADDR_EXPR)
1927 canonicalize_addr_expr (expr_p); 1793 canonicalize_addr_expr (expr_p);
1928 } 1794 }
1929 1795
1930 /* If we have a conversion to a non-register type force the 1796 /* If we have a conversion to a non-register type force the
1931 use of a VIEW_CONVERT_EXPR instead. */ 1797 use of a VIEW_CONVERT_EXPR instead. */
1932 if (CONVERT_EXPR_P (*expr_p) && !is_gimple_reg_type (TREE_TYPE (*expr_p))) 1798 if (CONVERT_EXPR_P (*expr_p) && !is_gimple_reg_type (TREE_TYPE (*expr_p)))
1933 *expr_p = fold_build1 (VIEW_CONVERT_EXPR, TREE_TYPE (*expr_p), 1799 *expr_p = fold_build1_loc (loc, VIEW_CONVERT_EXPR, TREE_TYPE (*expr_p),
1934 TREE_OPERAND (*expr_p, 0)); 1800 TREE_OPERAND (*expr_p, 0));
1935 1801
1936 return GS_OK; 1802 return GS_OK;
1937 } 1803 }
1938 1804
1939 /* Gimplify a VAR_DECL or PARM_DECL. Returns GS_OK if we expanded a 1805 /* Nonlocal VLAs seen in the current function. */
1806 static struct pointer_set_t *nonlocal_vlas;
1807
1808 /* Gimplify a VAR_DECL or PARM_DECL. Returns GS_OK if we expanded a
1940 DECL_VALUE_EXPR, and it's worth re-examining things. */ 1809 DECL_VALUE_EXPR, and it's worth re-examining things. */
1941 1810
1942 static enum gimplify_status 1811 static enum gimplify_status
1943 gimplify_var_or_parm_decl (tree *expr_p) 1812 gimplify_var_or_parm_decl (tree *expr_p)
1944 { 1813 {
1964 return GS_ALL_DONE; 1833 return GS_ALL_DONE;
1965 1834
1966 /* If the decl is an alias for another expression, substitute it now. */ 1835 /* If the decl is an alias for another expression, substitute it now. */
1967 if (DECL_HAS_VALUE_EXPR_P (decl)) 1836 if (DECL_HAS_VALUE_EXPR_P (decl))
1968 { 1837 {
1969 *expr_p = unshare_expr (DECL_VALUE_EXPR (decl)); 1838 tree value_expr = DECL_VALUE_EXPR (decl);
1839
1840 /* For referenced nonlocal VLAs add a decl for debugging purposes
1841 to the current function. */
1842 if (TREE_CODE (decl) == VAR_DECL
1843 && TREE_CODE (DECL_SIZE_UNIT (decl)) != INTEGER_CST
1844 && nonlocal_vlas != NULL
1845 && TREE_CODE (value_expr) == INDIRECT_REF
1846 && TREE_CODE (TREE_OPERAND (value_expr, 0)) == VAR_DECL
1847 && decl_function_context (decl) != current_function_decl)
1848 {
1849 struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
1850 while (ctx && ctx->region_type == ORT_WORKSHARE)
1851 ctx = ctx->outer_context;
1852 if (!ctx && !pointer_set_insert (nonlocal_vlas, decl))
1853 {
1854 tree copy = copy_node (decl), block;
1855
1856 lang_hooks.dup_lang_specific_decl (copy);
1857 SET_DECL_RTL (copy, NULL_RTX);
1858 TREE_USED (copy) = 1;
1859 block = DECL_INITIAL (current_function_decl);
1860 TREE_CHAIN (copy) = BLOCK_VARS (block);
1861 BLOCK_VARS (block) = copy;
1862 SET_DECL_VALUE_EXPR (copy, unshare_expr (value_expr));
1863 DECL_HAS_VALUE_EXPR_P (copy) = 1;
1864 }
1865 }
1866
1867 *expr_p = unshare_expr (value_expr);
1970 return GS_OK; 1868 return GS_OK;
1971 } 1869 }
1972 1870
1973 return GS_ALL_DONE; 1871 return GS_ALL_DONE;
1974 } 1872 }
1976 1874
1977 /* Gimplify the COMPONENT_REF, ARRAY_REF, REALPART_EXPR or IMAGPART_EXPR 1875 /* Gimplify the COMPONENT_REF, ARRAY_REF, REALPART_EXPR or IMAGPART_EXPR
1978 node *EXPR_P. 1876 node *EXPR_P.
1979 1877
1980 compound_lval 1878 compound_lval
1981 : min_lval '[' val ']' 1879 : min_lval '[' val ']'
1982 | min_lval '.' ID 1880 | min_lval '.' ID
1983 | compound_lval '[' val ']' 1881 | compound_lval '[' val ']'
1984 | compound_lval '.' ID 1882 | compound_lval '.' ID
1985 1883
1986 This is not part of the original SIMPLE definition, which separates 1884 This is not part of the original SIMPLE definition, which separates
1987 array and member references, but it seems reasonable to handle them 1885 array and member references, but it seems reasonable to handle them
1988 together. Also, this way we don't run into problems with union 1886 together. Also, this way we don't run into problems with union
1989 aliasing; gcc requires that for accesses through a union to alias, the 1887 aliasing; gcc requires that for accesses through a union to alias, the
1996 POST_P points to the sequence where side effects that must happen after 1894 POST_P points to the sequence where side effects that must happen after
1997 *EXPR_P should be stored. */ 1895 *EXPR_P should be stored. */
1998 1896
1999 static enum gimplify_status 1897 static enum gimplify_status
2000 gimplify_compound_lval (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, 1898 gimplify_compound_lval (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
2001 fallback_t fallback) 1899 fallback_t fallback)
2002 { 1900 {
2003 tree *p; 1901 tree *p;
2004 VEC(tree,heap) *stack; 1902 VEC(tree,heap) *stack;
2005 enum gimplify_status ret = GS_OK, tret; 1903 enum gimplify_status ret = GS_OK, tret;
2006 int i; 1904 int i;
1905 location_t loc = EXPR_LOCATION (*expr_p);
2007 1906
2008 /* Create a stack of the subexpressions so later we can walk them in 1907 /* Create a stack of the subexpressions so later we can walk them in
2009 order from inner to outer. */ 1908 order from inner to outer. */
2010 stack = VEC_alloc (tree, heap, 10); 1909 stack = VEC_alloc (tree, heap, 10);
2011 1910
2013 for (p = expr_p; ; p = &TREE_OPERAND (*p, 0)) 1912 for (p = expr_p; ; p = &TREE_OPERAND (*p, 0))
2014 { 1913 {
2015 restart: 1914 restart:
2016 /* Fold INDIRECT_REFs now to turn them into ARRAY_REFs. */ 1915 /* Fold INDIRECT_REFs now to turn them into ARRAY_REFs. */
2017 if (TREE_CODE (*p) == INDIRECT_REF) 1916 if (TREE_CODE (*p) == INDIRECT_REF)
2018 *p = fold_indirect_ref (*p); 1917 *p = fold_indirect_ref_loc (loc, *p);
2019 1918
2020 if (handled_component_p (*p)) 1919 if (handled_component_p (*p))
2021 ; 1920 ;
2022 /* Expand DECL_VALUE_EXPR now. In some cases that may expose 1921 /* Expand DECL_VALUE_EXPR now. In some cases that may expose
2023 additional COMPONENT_REFs. */ 1922 additional COMPONENT_REFs. */
2024 else if ((TREE_CODE (*p) == VAR_DECL || TREE_CODE (*p) == PARM_DECL) 1923 else if ((TREE_CODE (*p) == VAR_DECL || TREE_CODE (*p) == PARM_DECL)
2025 && gimplify_var_or_parm_decl (p) == GS_OK) 1924 && gimplify_var_or_parm_decl (p) == GS_OK)
2026 goto restart; 1925 goto restart;
2027 else 1926 else
2028 break; 1927 break;
2029 1928
2030 VEC_safe_push (tree, heap, stack, *p); 1929 VEC_safe_push (tree, heap, stack, *p);
2031 } 1930 }
2032 1931
2033 gcc_assert (VEC_length (tree, stack)); 1932 gcc_assert (VEC_length (tree, stack));
2034 1933
2047 for (i = VEC_length (tree, stack) - 1; i >= 0; i--) 1946 for (i = VEC_length (tree, stack) - 1; i >= 0; i--)
2048 { 1947 {
2049 tree t = VEC_index (tree, stack, i); 1948 tree t = VEC_index (tree, stack, i);
2050 1949
2051 if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF) 1950 if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
2052 { 1951 {
2053 /* Gimplify the low bound and element type size and put them into 1952 /* Gimplify the low bound and element type size and put them into
2054 the ARRAY_REF. If these values are set, they have already been 1953 the ARRAY_REF. If these values are set, they have already been
2055 gimplified. */ 1954 gimplified. */
2056 if (TREE_OPERAND (t, 2) == NULL_TREE) 1955 if (TREE_OPERAND (t, 2) == NULL_TREE)
2057 { 1956 {
2058 tree low = unshare_expr (array_ref_low_bound (t)); 1957 tree low = unshare_expr (array_ref_low_bound (t));
2059 if (!is_gimple_min_invariant (low)) 1958 if (!is_gimple_min_invariant (low))
2060 { 1959 {
2061 TREE_OPERAND (t, 2) = low; 1960 TREE_OPERAND (t, 2) = low;
2062 tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p, 1961 tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p,
2063 post_p, is_gimple_formal_tmp_reg, 1962 post_p, is_gimple_reg,
2064 fb_rvalue); 1963 fb_rvalue);
2065 ret = MIN (ret, tret); 1964 ret = MIN (ret, tret);
2066 } 1965 }
2067 } 1966 }
2068 1967
2069 if (!TREE_OPERAND (t, 3)) 1968 if (!TREE_OPERAND (t, 3))
2070 { 1969 {
2071 tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0))); 1970 tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0)));
2072 tree elmt_size = unshare_expr (array_ref_element_size (t)); 1971 tree elmt_size = unshare_expr (array_ref_element_size (t));
2073 tree factor = size_int (TYPE_ALIGN_UNIT (elmt_type)); 1972 tree factor = size_int (TYPE_ALIGN_UNIT (elmt_type));
2074 1973
2075 /* Divide the element size by the alignment of the element 1974 /* Divide the element size by the alignment of the element
2076 type (above). */ 1975 type (above). */
2077 elmt_size = size_binop (EXACT_DIV_EXPR, elmt_size, factor); 1976 elmt_size = size_binop_loc (loc, EXACT_DIV_EXPR, elmt_size, factor);
2078 1977
2079 if (!is_gimple_min_invariant (elmt_size)) 1978 if (!is_gimple_min_invariant (elmt_size))
2080 { 1979 {
2081 TREE_OPERAND (t, 3) = elmt_size; 1980 TREE_OPERAND (t, 3) = elmt_size;
2082 tret = gimplify_expr (&TREE_OPERAND (t, 3), pre_p, 1981 tret = gimplify_expr (&TREE_OPERAND (t, 3), pre_p,
2083 post_p, is_gimple_formal_tmp_reg, 1982 post_p, is_gimple_reg,
2084 fb_rvalue); 1983 fb_rvalue);
2085 ret = MIN (ret, tret); 1984 ret = MIN (ret, tret);
2086 } 1985 }
2087 } 1986 }
2088 } 1987 }
2089 else if (TREE_CODE (t) == COMPONENT_REF) 1988 else if (TREE_CODE (t) == COMPONENT_REF)
2090 { 1989 {
2091 /* Set the field offset into T and gimplify it. */ 1990 /* Set the field offset into T and gimplify it. */
2092 if (!TREE_OPERAND (t, 2)) 1991 if (!TREE_OPERAND (t, 2))
2093 { 1992 {
2094 tree offset = unshare_expr (component_ref_field_offset (t)); 1993 tree offset = unshare_expr (component_ref_field_offset (t));
2095 tree field = TREE_OPERAND (t, 1); 1994 tree field = TREE_OPERAND (t, 1);
2096 tree factor 1995 tree factor
2097 = size_int (DECL_OFFSET_ALIGN (field) / BITS_PER_UNIT); 1996 = size_int (DECL_OFFSET_ALIGN (field) / BITS_PER_UNIT);
2098 1997
2099 /* Divide the offset by its alignment. */ 1998 /* Divide the offset by its alignment. */
2100 offset = size_binop (EXACT_DIV_EXPR, offset, factor); 1999 offset = size_binop_loc (loc, EXACT_DIV_EXPR, offset, factor);
2101 2000
2102 if (!is_gimple_min_invariant (offset)) 2001 if (!is_gimple_min_invariant (offset))
2103 { 2002 {
2104 TREE_OPERAND (t, 2) = offset; 2003 TREE_OPERAND (t, 2) = offset;
2105 tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p, 2004 tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p,
2106 post_p, is_gimple_formal_tmp_reg, 2005 post_p, is_gimple_reg,
2107 fb_rvalue); 2006 fb_rvalue);
2108 ret = MIN (ret, tret); 2007 ret = MIN (ret, tret);
2109 } 2008 }
2110 } 2009 }
2111 } 2010 }
2112 } 2011 }
2113 2012
2114 /* Step 2 is to gimplify the base expression. Make sure lvalue is set 2013 /* Step 2 is to gimplify the base expression. Make sure lvalue is set
2115 so as to match the min_lval predicate. Failure to do so may result 2014 so as to match the min_lval predicate. Failure to do so may result
2116 in the creation of large aggregate temporaries. */ 2015 in the creation of large aggregate temporaries. */
2117 tret = gimplify_expr (p, pre_p, post_p, is_gimple_min_lval, 2016 tret = gimplify_expr (p, pre_p, post_p, is_gimple_min_lval,
2118 fallback | fb_lvalue); 2017 fallback | fb_lvalue);
2119 ret = MIN (ret, tret); 2018 ret = MIN (ret, tret);
2120 2019
2121 /* And finally, the indices and operands to BIT_FIELD_REF. During this 2020 /* And finally, the indices and operands to BIT_FIELD_REF. During this
2122 loop we also remove any useless conversions. */ 2021 loop we also remove any useless conversions. */
2123 for (; VEC_length (tree, stack) > 0; ) 2022 for (; VEC_length (tree, stack) > 0; )
2124 { 2023 {
2125 tree t = VEC_pop (tree, stack); 2024 tree t = VEC_pop (tree, stack);
2126 2025
2127 if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF) 2026 if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
2128 { 2027 {
2129 /* Gimplify the dimension. 2028 /* Gimplify the dimension. */
2130 Temporary fix for gcc.c-torture/execute/20040313-1.c. 2029 if (!is_gimple_min_invariant (TREE_OPERAND (t, 1)))
2131 Gimplify non-constant array indices into a temporary 2030 {
2132 variable. 2031 tret = gimplify_expr (&TREE_OPERAND (t, 1), pre_p, post_p,
2133 FIXME - The real fix is to gimplify post-modify 2032 is_gimple_val, fb_rvalue);
2134 expressions into a minimal gimple lvalue. However, that 2033 ret = MIN (ret, tret);
2135 exposes bugs in alias analysis. The alias analyzer does 2034 }
2136 not handle &PTR->FIELD very well. Will fix after the 2035 }
2137 branch is merged into mainline (dnovillo 2004-05-03). */
2138 if (!is_gimple_min_invariant (TREE_OPERAND (t, 1)))
2139 {
2140 tret = gimplify_expr (&TREE_OPERAND (t, 1), pre_p, post_p,
2141 is_gimple_formal_tmp_reg, fb_rvalue);
2142 ret = MIN (ret, tret);
2143 }
2144 }
2145 else if (TREE_CODE (t) == BIT_FIELD_REF) 2036 else if (TREE_CODE (t) == BIT_FIELD_REF)
2146 { 2037 {
2147 tret = gimplify_expr (&TREE_OPERAND (t, 1), pre_p, post_p, 2038 tret = gimplify_expr (&TREE_OPERAND (t, 1), pre_p, post_p,
2148 is_gimple_val, fb_rvalue); 2039 is_gimple_val, fb_rvalue);
2149 ret = MIN (ret, tret); 2040 ret = MIN (ret, tret);
2150 tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p, post_p, 2041 tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p, post_p,
2151 is_gimple_val, fb_rvalue); 2042 is_gimple_val, fb_rvalue);
2152 ret = MIN (ret, tret); 2043 ret = MIN (ret, tret);
2153 } 2044 }
2154 2045
2155 STRIP_USELESS_TYPE_CONVERSION (TREE_OPERAND (t, 0)); 2046 STRIP_USELESS_TYPE_CONVERSION (TREE_OPERAND (t, 0));
2156 2047
2157 /* The innermost expression P may have originally had 2048 /* The innermost expression P may have originally had
2158 TREE_SIDE_EFFECTS set which would have caused all the outer 2049 TREE_SIDE_EFFECTS set which would have caused all the outer
2159 expressions in *EXPR_P leading to P to also have had 2050 expressions in *EXPR_P leading to P to also have had
2160 TREE_SIDE_EFFECTS set. */ 2051 TREE_SIDE_EFFECTS set. */
2161 recalculate_side_effects (t); 2052 recalculate_side_effects (t);
2162 } 2053 }
2163 2054
2164 /* If the outermost expression is a COMPONENT_REF, canonicalize its type. */ 2055 /* If the outermost expression is a COMPONENT_REF, canonicalize its type. */
2165 if ((fallback & fb_rvalue) && TREE_CODE (*expr_p) == COMPONENT_REF) 2056 if ((fallback & fb_rvalue) && TREE_CODE (*expr_p) == COMPONENT_REF)
2175 2066
2176 /* Gimplify the self modifying expression pointed to by EXPR_P 2067 /* Gimplify the self modifying expression pointed to by EXPR_P
2177 (++, --, +=, -=). 2068 (++, --, +=, -=).
2178 2069
2179 PRE_P points to the list where side effects that must happen before 2070 PRE_P points to the list where side effects that must happen before
2180 *EXPR_P should be stored. 2071 *EXPR_P should be stored.
2181 2072
2182 POST_P points to the list where side effects that must happen after 2073 POST_P points to the list where side effects that must happen after
2183 *EXPR_P should be stored. 2074 *EXPR_P should be stored.
2184 2075
2185 WANT_VALUE is nonzero iff we want to use the value of this expression 2076 WANT_VALUE is nonzero iff we want to use the value of this expression
2186 in another expression. */ 2077 in another expression. */
2187 2078
2188 static enum gimplify_status 2079 static enum gimplify_status
2189 gimplify_self_mod_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, 2080 gimplify_self_mod_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
2190 bool want_value) 2081 bool want_value)
2191 { 2082 {
2192 enum tree_code code; 2083 enum tree_code code;
2193 tree lhs, lvalue, rhs, t1; 2084 tree lhs, lvalue, rhs, t1;
2194 gimple_seq post = NULL, *orig_post_p = post_p; 2085 gimple_seq post = NULL, *orig_post_p = post_p;
2195 bool postfix; 2086 bool postfix;
2196 enum tree_code arith_code; 2087 enum tree_code arith_code;
2197 enum gimplify_status ret; 2088 enum gimplify_status ret;
2089 location_t loc = EXPR_LOCATION (*expr_p);
2198 2090
2199 code = TREE_CODE (*expr_p); 2091 code = TREE_CODE (*expr_p);
2200 2092
2201 gcc_assert (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR 2093 gcc_assert (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR
2202 || code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR); 2094 || code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR);
2203 2095
2204 /* Prefix or postfix? */ 2096 /* Prefix or postfix? */
2205 if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR) 2097 if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
2206 /* Faster to treat as prefix if result is not used. */ 2098 /* Faster to treat as prefix if result is not used. */
2207 postfix = want_value; 2099 postfix = want_value;
2228 /* Extract the operands to the arithmetic operation. */ 2120 /* Extract the operands to the arithmetic operation. */
2229 lhs = lvalue; 2121 lhs = lvalue;
2230 rhs = TREE_OPERAND (*expr_p, 1); 2122 rhs = TREE_OPERAND (*expr_p, 1);
2231 2123
2232 /* For postfix operator, we evaluate the LHS to an rvalue and then use 2124 /* For postfix operator, we evaluate the LHS to an rvalue and then use
2233 that as the result value and in the postqueue operation. */ 2125 that as the result value and in the postqueue operation. We also
2126 make sure to make lvalue a minimal lval, see
2127 gcc.c-torture/execute/20040313-1.c for an example where this matters. */
2234 if (postfix) 2128 if (postfix)
2235 { 2129 {
2130 if (!is_gimple_min_lval (lvalue))
2131 {
2132 mark_addressable (lvalue);
2133 lvalue = build_fold_addr_expr_loc (input_location, lvalue);
2134 gimplify_expr (&lvalue, pre_p, post_p, is_gimple_val, fb_rvalue);
2135 lvalue = build_fold_indirect_ref_loc (input_location, lvalue);
2136 }
2236 ret = gimplify_expr (&lhs, pre_p, post_p, is_gimple_val, fb_rvalue); 2137 ret = gimplify_expr (&lhs, pre_p, post_p, is_gimple_val, fb_rvalue);
2237 if (ret == GS_ERROR) 2138 if (ret == GS_ERROR)
2238 return ret; 2139 return ret;
2239 } 2140 }
2240 2141
2241 /* For POINTERs increment, use POINTER_PLUS_EXPR. */ 2142 /* For POINTERs increment, use POINTER_PLUS_EXPR. */
2242 if (POINTER_TYPE_P (TREE_TYPE (lhs))) 2143 if (POINTER_TYPE_P (TREE_TYPE (lhs)))
2243 { 2144 {
2244 rhs = fold_convert (sizetype, rhs); 2145 rhs = fold_convert_loc (loc, sizetype, rhs);
2245 if (arith_code == MINUS_EXPR) 2146 if (arith_code == MINUS_EXPR)
2246 rhs = fold_build1 (NEGATE_EXPR, TREE_TYPE (rhs), rhs); 2147 rhs = fold_build1_loc (loc, NEGATE_EXPR, TREE_TYPE (rhs), rhs);
2247 arith_code = POINTER_PLUS_EXPR; 2148 arith_code = POINTER_PLUS_EXPR;
2248 } 2149 }
2249 2150
2250 t1 = build2 (arith_code, TREE_TYPE (*expr_p), lhs, rhs); 2151 t1 = build2 (arith_code, TREE_TYPE (*expr_p), lhs, rhs);
2251 2152
2312 test = is_gimple_lvalue, fb = fb_either; 2213 test = is_gimple_lvalue, fb = fb_either;
2313 2214
2314 /* If this is a variable sized type, we must remember the size. */ 2215 /* If this is a variable sized type, we must remember the size. */
2315 maybe_with_size_expr (arg_p); 2216 maybe_with_size_expr (arg_p);
2316 2217
2218 /* FIXME diagnostics: This will mess up gcc.dg/Warray-bounds.c. */
2317 /* Make sure arguments have the same location as the function call 2219 /* Make sure arguments have the same location as the function call
2318 itself. */ 2220 itself. */
2319 protected_set_expr_location (*arg_p, call_location); 2221 protected_set_expr_location (*arg_p, call_location);
2320 2222
2321 /* There is a sequence point before a function call. Side effects in 2223 /* There is a sequence point before a function call. Side effects in
2335 tree fndecl, parms, p; 2237 tree fndecl, parms, p;
2336 enum gimplify_status ret; 2238 enum gimplify_status ret;
2337 int i, nargs; 2239 int i, nargs;
2338 gimple call; 2240 gimple call;
2339 bool builtin_va_start_p = FALSE; 2241 bool builtin_va_start_p = FALSE;
2242 location_t loc = EXPR_LOCATION (*expr_p);
2340 2243
2341 gcc_assert (TREE_CODE (*expr_p) == CALL_EXPR); 2244 gcc_assert (TREE_CODE (*expr_p) == CALL_EXPR);
2342 2245
2343 /* For reliable diagnostics during inlining, it is necessary that 2246 /* For reliable diagnostics during inlining, it is necessary that
2344 every call_expr be annotated with file and line. */ 2247 every call_expr be annotated with file and line. */
2358 transform all calls in the same manner as the expanders do, but 2261 transform all calls in the same manner as the expanders do, but
2359 we do transform most of them. */ 2262 we do transform most of them. */
2360 fndecl = get_callee_fndecl (*expr_p); 2263 fndecl = get_callee_fndecl (*expr_p);
2361 if (fndecl && DECL_BUILT_IN (fndecl)) 2264 if (fndecl && DECL_BUILT_IN (fndecl))
2362 { 2265 {
2363 tree new_tree = fold_call_expr (*expr_p, !want_value); 2266 tree new_tree = fold_call_expr (input_location, *expr_p, !want_value);
2364 2267
2365 if (new_tree && new_tree != *expr_p) 2268 if (new_tree && new_tree != *expr_p)
2366 { 2269 {
2367 /* There was a transformation of this call which computes the 2270 /* There was a transformation of this call which computes the
2368 same value, but in a more efficient way. Return and try 2271 same value, but in a more efficient way. Return and try
2369 again. */ 2272 again. */
2370 *expr_p = new_tree; 2273 *expr_p = new_tree;
2371 return GS_OK; 2274 return GS_OK;
2372 } 2275 }
2373 2276
2374 if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL 2277 if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
2375 && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_VA_START) 2278 && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_VA_START)
2376 { 2279 {
2377 builtin_va_start_p = TRUE; 2280 builtin_va_start_p = TRUE;
2378 if (call_expr_nargs (*expr_p) < 2) 2281 if (call_expr_nargs (*expr_p) < 2)
2379 { 2282 {
2380 error ("too few arguments to function %<va_start%>"); 2283 error ("too few arguments to function %<va_start%>");
2381 *expr_p = build_empty_stmt (); 2284 *expr_p = build_empty_stmt (EXPR_LOCATION (*expr_p));
2382 return GS_OK; 2285 return GS_OK;
2383 } 2286 }
2384 2287
2385 if (fold_builtin_next_arg (*expr_p, true)) 2288 if (fold_builtin_next_arg (*expr_p, true))
2386 { 2289 {
2387 *expr_p = build_empty_stmt (); 2290 *expr_p = build_empty_stmt (EXPR_LOCATION (*expr_p));
2388 return GS_OK; 2291 return GS_OK;
2389 } 2292 }
2390 } 2293 }
2391 } 2294 }
2392 2295
2393 /* There is a sequence point before the call, so any side effects in 2296 /* There is a sequence point before the call, so any side effects in
2394 the calling expression must occur before the actual call. Force 2297 the calling expression must occur before the actual call. Force
2395 gimplify_expr to use an internal post queue. */ 2298 gimplify_expr to use an internal post queue. */
2396 ret = gimplify_expr (&CALL_EXPR_FN (*expr_p), pre_p, NULL, 2299 ret = gimplify_expr (&CALL_EXPR_FN (*expr_p), pre_p, NULL,
2397 is_gimple_call_addr, fb_rvalue); 2300 is_gimple_call_addr, fb_rvalue);
2398 2301
2399 nargs = call_expr_nargs (*expr_p); 2302 nargs = call_expr_nargs (*expr_p);
2400 2303
2401 /* Get argument types for verification. */ 2304 /* Get argument types for verification. */
2402 fndecl = get_callee_fndecl (*expr_p); 2305 fndecl = get_callee_fndecl (*expr_p);
2424 { 2327 {
2425 tree last_arg = CALL_EXPR_ARG (*expr_p, nargs - 1); 2328 tree last_arg = CALL_EXPR_ARG (*expr_p, nargs - 1);
2426 tree last_arg_fndecl = get_callee_fndecl (last_arg); 2329 tree last_arg_fndecl = get_callee_fndecl (last_arg);
2427 2330
2428 if (last_arg_fndecl 2331 if (last_arg_fndecl
2429 && TREE_CODE (last_arg_fndecl) == FUNCTION_DECL 2332 && TREE_CODE (last_arg_fndecl) == FUNCTION_DECL
2430 && DECL_BUILT_IN_CLASS (last_arg_fndecl) == BUILT_IN_NORMAL 2333 && DECL_BUILT_IN_CLASS (last_arg_fndecl) == BUILT_IN_NORMAL
2431 && DECL_FUNCTION_CODE (last_arg_fndecl) == BUILT_IN_VA_ARG_PACK) 2334 && DECL_FUNCTION_CODE (last_arg_fndecl) == BUILT_IN_VA_ARG_PACK)
2432 { 2335 {
2433 tree call = *expr_p; 2336 tree call = *expr_p;
2434 2337
2435 --nargs; 2338 --nargs;
2436 *expr_p = build_call_array (TREE_TYPE (call), CALL_EXPR_FN (call), 2339 *expr_p = build_call_array_loc (loc, TREE_TYPE (call),
2437 nargs, CALL_EXPR_ARGP (call)); 2340 CALL_EXPR_FN (call),
2438 2341 nargs, CALL_EXPR_ARGP (call));
2439 /* Copy all CALL_EXPR flags, location and block, except 2342
2440 CALL_EXPR_VA_ARG_PACK flag. */ 2343 /* Copy all CALL_EXPR flags, location and block, except
2441 CALL_EXPR_STATIC_CHAIN (*expr_p) = CALL_EXPR_STATIC_CHAIN (call); 2344 CALL_EXPR_VA_ARG_PACK flag. */
2442 CALL_EXPR_TAILCALL (*expr_p) = CALL_EXPR_TAILCALL (call); 2345 CALL_EXPR_STATIC_CHAIN (*expr_p) = CALL_EXPR_STATIC_CHAIN (call);
2443 CALL_EXPR_RETURN_SLOT_OPT (*expr_p) 2346 CALL_EXPR_TAILCALL (*expr_p) = CALL_EXPR_TAILCALL (call);
2444 = CALL_EXPR_RETURN_SLOT_OPT (call); 2347 CALL_EXPR_RETURN_SLOT_OPT (*expr_p)
2445 CALL_FROM_THUNK_P (*expr_p) = CALL_FROM_THUNK_P (call); 2348 = CALL_EXPR_RETURN_SLOT_OPT (call);
2446 CALL_CANNOT_INLINE_P (*expr_p) = CALL_CANNOT_INLINE_P (call); 2349 CALL_FROM_THUNK_P (*expr_p) = CALL_FROM_THUNK_P (call);
2447 SET_EXPR_LOCUS (*expr_p, EXPR_LOCUS (call)); 2350 CALL_CANNOT_INLINE_P (*expr_p) = CALL_CANNOT_INLINE_P (call);
2448 TREE_BLOCK (*expr_p) = TREE_BLOCK (call); 2351 SET_EXPR_LOCATION (*expr_p, EXPR_LOCATION (call));
2449 2352 TREE_BLOCK (*expr_p) = TREE_BLOCK (call);
2450 /* Set CALL_EXPR_VA_ARG_PACK. */ 2353
2451 CALL_EXPR_VA_ARG_PACK (*expr_p) = 1; 2354 /* Set CALL_EXPR_VA_ARG_PACK. */
2452 } 2355 CALL_EXPR_VA_ARG_PACK (*expr_p) = 1;
2356 }
2453 } 2357 }
2454 2358
2455 /* Finally, gimplify the function arguments. */ 2359 /* Finally, gimplify the function arguments. */
2456 if (nargs > 0) 2360 if (nargs > 0)
2457 { 2361 {
2464 /* Avoid gimplifying the second argument to va_start, which needs to 2368 /* Avoid gimplifying the second argument to va_start, which needs to
2465 be the plain PARM_DECL. */ 2369 be the plain PARM_DECL. */
2466 if ((i != 1) || !builtin_va_start_p) 2370 if ((i != 1) || !builtin_va_start_p)
2467 { 2371 {
2468 t = gimplify_arg (&CALL_EXPR_ARG (*expr_p, i), pre_p, 2372 t = gimplify_arg (&CALL_EXPR_ARG (*expr_p, i), pre_p,
2469 EXPR_LOCATION (*expr_p)); 2373 EXPR_LOCATION (*expr_p));
2470 2374
2471 if (t == GS_ERROR) 2375 if (t == GS_ERROR)
2472 ret = GS_ERROR; 2376 ret = GS_ERROR;
2473 } 2377 }
2474 } 2378 }
2475 } 2379 }
2476 2380
2381 /* Verify the function result. */
2382 if (want_value && fndecl
2383 && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (fndecl))))
2384 {
2385 error_at (loc, "using result of function returning %<void%>");
2386 ret = GS_ERROR;
2387 }
2388
2477 /* Try this again in case gimplification exposed something. */ 2389 /* Try this again in case gimplification exposed something. */
2478 if (ret != GS_ERROR) 2390 if (ret != GS_ERROR)
2479 { 2391 {
2480 tree new_tree = fold_call_expr (*expr_p, !want_value); 2392 tree new_tree = fold_call_expr (input_location, *expr_p, !want_value);
2481 2393
2482 if (new_tree && new_tree != *expr_p) 2394 if (new_tree && new_tree != *expr_p)
2483 { 2395 {
2484 /* There was a transformation of this call which computes the 2396 /* There was a transformation of this call which computes the
2485 same value, but in a more efficient way. Return and try 2397 same value, but in a more efficient way. Return and try
2486 again. */ 2398 again. */
2487 *expr_p = new_tree; 2399 *expr_p = new_tree;
2488 return GS_OK; 2400 return GS_OK;
2489 } 2401 }
2490 } 2402 }
2491 else 2403 else
2492 { 2404 {
2493 *expr_p = error_mark_node; 2405 *expr_p = error_mark_node;
2494 return GS_ERROR; 2406 return GS_ERROR;
2499 calls to "const" functions. */ 2411 calls to "const" functions. */
2500 if (TREE_CODE (*expr_p) == CALL_EXPR) 2412 if (TREE_CODE (*expr_p) == CALL_EXPR)
2501 { 2413 {
2502 int flags = call_expr_flags (*expr_p); 2414 int flags = call_expr_flags (*expr_p);
2503 if (flags & (ECF_CONST | ECF_PURE) 2415 if (flags & (ECF_CONST | ECF_PURE)
2504 /* An infinite loop is considered a side effect. */ 2416 /* An infinite loop is considered a side effect. */
2505 && !(flags & (ECF_LOOPING_CONST_OR_PURE))) 2417 && !(flags & (ECF_LOOPING_CONST_OR_PURE)))
2506 TREE_SIDE_EFFECTS (*expr_p) = 0; 2418 TREE_SIDE_EFFECTS (*expr_p) = 0;
2507 } 2419 }
2508 2420
2509 /* If the value is not needed by the caller, emit a new GIMPLE_CALL 2421 /* If the value is not needed by the caller, emit a new GIMPLE_CALL
2510 and clear *EXPR_P. Otherwise, leave *EXPR_P in its gimplified 2422 and clear *EXPR_P. Otherwise, leave *EXPR_P in its gimplified
2511 form and delegate the creation of a GIMPLE_CALL to 2423 form and delegate the creation of a GIMPLE_CALL to
2515 internal_get_tmp_var which will then be handled by 2427 internal_get_tmp_var which will then be handled by
2516 gimplify_modify_expr. */ 2428 gimplify_modify_expr. */
2517 if (!want_value) 2429 if (!want_value)
2518 { 2430 {
2519 /* The CALL_EXPR in *EXPR_P is already in GIMPLE form, so all we 2431 /* The CALL_EXPR in *EXPR_P is already in GIMPLE form, so all we
2520 have to do is replicate it as a GIMPLE_CALL tuple. */ 2432 have to do is replicate it as a GIMPLE_CALL tuple. */
2521 call = gimple_build_call_from_tree (*expr_p); 2433 call = gimple_build_call_from_tree (*expr_p);
2522 gimplify_seq_add_stmt (pre_p, call); 2434 gimplify_seq_add_stmt (pre_p, call);
2523 *expr_p = NULL_TREE; 2435 *expr_p = NULL_TREE;
2524 } 2436 }
2525 2437
2531 2443
2532 TRUE_LABEL_P and FALSE_LABEL_P point to the labels to jump to if the 2444 TRUE_LABEL_P and FALSE_LABEL_P point to the labels to jump to if the
2533 condition is true or false, respectively. If null, we should generate 2445 condition is true or false, respectively. If null, we should generate
2534 our own to skip over the evaluation of this specific expression. 2446 our own to skip over the evaluation of this specific expression.
2535 2447
2448 LOCUS is the source location of the COND_EXPR.
2449
2536 This function is the tree equivalent of do_jump. 2450 This function is the tree equivalent of do_jump.
2537 2451
2538 shortcut_cond_r should only be called by shortcut_cond_expr. */ 2452 shortcut_cond_r should only be called by shortcut_cond_expr. */
2539 2453
2540 static tree 2454 static tree
2541 shortcut_cond_r (tree pred, tree *true_label_p, tree *false_label_p) 2455 shortcut_cond_r (tree pred, tree *true_label_p, tree *false_label_p,
2456 location_t locus)
2542 { 2457 {
2543 tree local_label = NULL_TREE; 2458 tree local_label = NULL_TREE;
2544 tree t, expr = NULL; 2459 tree t, expr = NULL;
2545 2460
2546 /* OK, it's not a simple case; we need to pull apart the COND_EXPR to 2461 /* OK, it's not a simple case; we need to pull apart the COND_EXPR to
2547 retain the shortcut semantics. Just insert the gotos here; 2462 retain the shortcut semantics. Just insert the gotos here;
2548 shortcut_cond_expr will append the real blocks later. */ 2463 shortcut_cond_expr will append the real blocks later. */
2549 if (TREE_CODE (pred) == TRUTH_ANDIF_EXPR) 2464 if (TREE_CODE (pred) == TRUTH_ANDIF_EXPR)
2550 { 2465 {
2466 location_t new_locus;
2467
2551 /* Turn if (a && b) into 2468 /* Turn if (a && b) into
2552 2469
2553 if (a); else goto no; 2470 if (a); else goto no;
2554 if (b) goto yes; else goto no; 2471 if (b) goto yes; else goto no;
2555 (no:) */ 2472 (no:) */
2556 2473
2557 if (false_label_p == NULL) 2474 if (false_label_p == NULL)
2558 false_label_p = &local_label; 2475 false_label_p = &local_label;
2559 2476
2560 t = shortcut_cond_r (TREE_OPERAND (pred, 0), NULL, false_label_p); 2477 /* Keep the original source location on the first 'if'. */
2478 t = shortcut_cond_r (TREE_OPERAND (pred, 0), NULL, false_label_p, locus);
2561 append_to_statement_list (t, &expr); 2479 append_to_statement_list (t, &expr);
2562 2480
2563 t = shortcut_cond_r (TREE_OPERAND (pred, 1), true_label_p, 2481 /* Set the source location of the && on the second 'if'. */
2564 false_label_p); 2482 new_locus = EXPR_HAS_LOCATION (pred) ? EXPR_LOCATION (pred) : locus;
2483 t = shortcut_cond_r (TREE_OPERAND (pred, 1), true_label_p, false_label_p,
2484 new_locus);
2565 append_to_statement_list (t, &expr); 2485 append_to_statement_list (t, &expr);
2566 } 2486 }
2567 else if (TREE_CODE (pred) == TRUTH_ORIF_EXPR) 2487 else if (TREE_CODE (pred) == TRUTH_ORIF_EXPR)
2568 { 2488 {
2489 location_t new_locus;
2490
2569 /* Turn if (a || b) into 2491 /* Turn if (a || b) into
2570 2492
2571 if (a) goto yes; 2493 if (a) goto yes;
2572 if (b) goto yes; else goto no; 2494 if (b) goto yes; else goto no;
2573 (yes:) */ 2495 (yes:) */
2574 2496
2575 if (true_label_p == NULL) 2497 if (true_label_p == NULL)
2576 true_label_p = &local_label; 2498 true_label_p = &local_label;
2577 2499
2578 t = shortcut_cond_r (TREE_OPERAND (pred, 0), true_label_p, NULL); 2500 /* Keep the original source location on the first 'if'. */
2501 t = shortcut_cond_r (TREE_OPERAND (pred, 0), true_label_p, NULL, locus);
2579 append_to_statement_list (t, &expr); 2502 append_to_statement_list (t, &expr);
2580 2503
2581 t = shortcut_cond_r (TREE_OPERAND (pred, 1), true_label_p, 2504 /* Set the source location of the || on the second 'if'. */
2582 false_label_p); 2505 new_locus = EXPR_HAS_LOCATION (pred) ? EXPR_LOCATION (pred) : locus;
2506 t = shortcut_cond_r (TREE_OPERAND (pred, 1), true_label_p, false_label_p,
2507 new_locus);
2583 append_to_statement_list (t, &expr); 2508 append_to_statement_list (t, &expr);
2584 } 2509 }
2585 else if (TREE_CODE (pred) == COND_EXPR) 2510 else if (TREE_CODE (pred) == COND_EXPR)
2586 { 2511 {
2512 location_t new_locus;
2513
2587 /* As long as we're messing with gotos, turn if (a ? b : c) into 2514 /* As long as we're messing with gotos, turn if (a ? b : c) into
2588 if (a) 2515 if (a)
2589 if (b) goto yes; else goto no; 2516 if (b) goto yes; else goto no;
2590 else 2517 else
2591 if (c) goto yes; else goto no; */ 2518 if (c) goto yes; else goto no; */
2519
2520 /* Keep the original source location on the first 'if'. Set the source
2521 location of the ? on the second 'if'. */
2522 new_locus = EXPR_HAS_LOCATION (pred) ? EXPR_LOCATION (pred) : locus;
2592 expr = build3 (COND_EXPR, void_type_node, TREE_OPERAND (pred, 0), 2523 expr = build3 (COND_EXPR, void_type_node, TREE_OPERAND (pred, 0),
2593 shortcut_cond_r (TREE_OPERAND (pred, 1), true_label_p, 2524 shortcut_cond_r (TREE_OPERAND (pred, 1), true_label_p,
2594 false_label_p), 2525 false_label_p, locus),
2595 shortcut_cond_r (TREE_OPERAND (pred, 2), true_label_p, 2526 shortcut_cond_r (TREE_OPERAND (pred, 2), true_label_p,
2596 false_label_p)); 2527 false_label_p, new_locus));
2597 } 2528 }
2598 else 2529 else
2599 { 2530 {
2600 expr = build3 (COND_EXPR, void_type_node, pred, 2531 expr = build3 (COND_EXPR, void_type_node, pred,
2601 build_and_jump (true_label_p), 2532 build_and_jump (true_label_p),
2602 build_and_jump (false_label_p)); 2533 build_and_jump (false_label_p));
2534 SET_EXPR_LOCATION (expr, locus);
2603 } 2535 }
2604 2536
2605 if (local_label) 2537 if (local_label)
2606 { 2538 {
2607 t = build1 (LABEL_EXPR, void_type_node, local_label); 2539 t = build1 (LABEL_EXPR, void_type_node, local_label);
2629 bool else_se = else_ && TREE_SIDE_EFFECTS (else_); 2561 bool else_se = else_ && TREE_SIDE_EFFECTS (else_);
2630 2562
2631 /* First do simple transformations. */ 2563 /* First do simple transformations. */
2632 if (!else_se) 2564 if (!else_se)
2633 { 2565 {
2634 /* If there is no 'else', turn (a && b) into if (a) if (b). */ 2566 /* If there is no 'else', turn
2567 if (a && b) then c
2568 into
2569 if (a) if (b) then c. */
2635 while (TREE_CODE (pred) == TRUTH_ANDIF_EXPR) 2570 while (TREE_CODE (pred) == TRUTH_ANDIF_EXPR)
2636 { 2571 {
2637 TREE_OPERAND (expr, 0) = TREE_OPERAND (pred, 1); 2572 /* Keep the original source location on the first 'if'. */
2638 then_ = shortcut_cond_expr (expr); 2573 location_t locus = EXPR_HAS_LOCATION (expr)
2639 then_se = then_ && TREE_SIDE_EFFECTS (then_); 2574 ? EXPR_LOCATION (expr) : input_location;
2640 pred = TREE_OPERAND (pred, 0); 2575 TREE_OPERAND (expr, 0) = TREE_OPERAND (pred, 1);
2641 expr = build3 (COND_EXPR, void_type_node, pred, then_, NULL_TREE); 2576 /* Set the source location of the && on the second 'if'. */
2642 } 2577 if (EXPR_HAS_LOCATION (pred))
2578 SET_EXPR_LOCATION (expr, EXPR_LOCATION (pred));
2579 then_ = shortcut_cond_expr (expr);
2580 then_se = then_ && TREE_SIDE_EFFECTS (then_);
2581 pred = TREE_OPERAND (pred, 0);
2582 expr = build3 (COND_EXPR, void_type_node, pred, then_, NULL_TREE);
2583 SET_EXPR_LOCATION (expr, locus);
2584 }
2643 } 2585 }
2644 2586
2645 if (!then_se) 2587 if (!then_se)
2646 { 2588 {
2647 /* If there is no 'then', turn 2589 /* If there is no 'then', turn
2648 if (a || b); else d 2590 if (a || b); else d
2649 into 2591 into
2650 if (a); else if (b); else d. */ 2592 if (a); else if (b); else d. */
2651 while (TREE_CODE (pred) == TRUTH_ORIF_EXPR) 2593 while (TREE_CODE (pred) == TRUTH_ORIF_EXPR)
2652 { 2594 {
2653 TREE_OPERAND (expr, 0) = TREE_OPERAND (pred, 1); 2595 /* Keep the original source location on the first 'if'. */
2654 else_ = shortcut_cond_expr (expr); 2596 location_t locus = EXPR_HAS_LOCATION (expr)
2655 else_se = else_ && TREE_SIDE_EFFECTS (else_); 2597 ? EXPR_LOCATION (expr) : input_location;
2656 pred = TREE_OPERAND (pred, 0); 2598 TREE_OPERAND (expr, 0) = TREE_OPERAND (pred, 1);
2657 expr = build3 (COND_EXPR, void_type_node, pred, NULL_TREE, else_); 2599 /* Set the source location of the || on the second 'if'. */
2658 } 2600 if (EXPR_HAS_LOCATION (pred))
2601 SET_EXPR_LOCATION (expr, EXPR_LOCATION (pred));
2602 else_ = shortcut_cond_expr (expr);
2603 else_se = else_ && TREE_SIDE_EFFECTS (else_);
2604 pred = TREE_OPERAND (pred, 0);
2605 expr = build3 (COND_EXPR, void_type_node, pred, NULL_TREE, else_);
2606 SET_EXPR_LOCATION (expr, locus);
2607 }
2659 } 2608 }
2660 2609
2661 /* If we're done, great. */ 2610 /* If we're done, great. */
2662 if (TREE_CODE (pred) != TRUTH_ANDIF_EXPR 2611 if (TREE_CODE (pred) != TRUTH_ANDIF_EXPR
2663 && TREE_CODE (pred) != TRUTH_ORIF_EXPR) 2612 && TREE_CODE (pred) != TRUTH_ORIF_EXPR)
2706 else 2655 else
2707 false_label_p = NULL; 2656 false_label_p = NULL;
2708 2657
2709 /* If there was nothing else in our arms, just forward the label(s). */ 2658 /* If there was nothing else in our arms, just forward the label(s). */
2710 if (!then_se && !else_se) 2659 if (!then_se && !else_se)
2711 return shortcut_cond_r (pred, true_label_p, false_label_p); 2660 return shortcut_cond_r (pred, true_label_p, false_label_p,
2661 EXPR_HAS_LOCATION (expr)
2662 ? EXPR_LOCATION (expr) : input_location);
2712 2663
2713 /* If our last subexpression already has a terminal label, reuse it. */ 2664 /* If our last subexpression already has a terminal label, reuse it. */
2714 if (else_se) 2665 if (else_se)
2715 expr = expr_last (else_); 2666 t = expr_last (else_);
2716 else if (then_se) 2667 else if (then_se)
2717 expr = expr_last (then_); 2668 t = expr_last (then_);
2718 else 2669 else
2719 expr = NULL; 2670 t = NULL;
2720 if (expr && TREE_CODE (expr) == LABEL_EXPR) 2671 if (t && TREE_CODE (t) == LABEL_EXPR)
2721 end_label = LABEL_EXPR_LABEL (expr); 2672 end_label = LABEL_EXPR_LABEL (t);
2722 2673
2723 /* If we don't care about jumping to the 'else' branch, jump to the end 2674 /* If we don't care about jumping to the 'else' branch, jump to the end
2724 if the condition is false. */ 2675 if the condition is false. */
2725 if (!false_label_p) 2676 if (!false_label_p)
2726 false_label_p = &end_label; 2677 false_label_p = &end_label;
2737 which ends with such a condition, that can cause us to issue an 2688 which ends with such a condition, that can cause us to issue an
2738 inappropriate warning about control reaching the end of a 2689 inappropriate warning about control reaching the end of a
2739 non-void function. */ 2690 non-void function. */
2740 jump_over_else = block_may_fallthru (then_); 2691 jump_over_else = block_may_fallthru (then_);
2741 2692
2742 pred = shortcut_cond_r (pred, true_label_p, false_label_p); 2693 pred = shortcut_cond_r (pred, true_label_p, false_label_p,
2694 EXPR_HAS_LOCATION (expr)
2695 ? EXPR_LOCATION (expr) : input_location);
2743 2696
2744 expr = NULL; 2697 expr = NULL;
2745 append_to_statement_list (pred, &expr); 2698 append_to_statement_list (pred, &expr);
2746 2699
2747 append_to_statement_list (then_, &expr); 2700 append_to_statement_list (then_, &expr);
2748 if (else_se) 2701 if (else_se)
2749 { 2702 {
2750 if (jump_over_else) 2703 if (jump_over_else)
2751 { 2704 {
2752 t = build_and_jump (&end_label); 2705 tree last = expr_last (expr);
2753 append_to_statement_list (t, &expr); 2706 t = build_and_jump (&end_label);
2754 } 2707 if (EXPR_HAS_LOCATION (last))
2708 SET_EXPR_LOCATION (t, EXPR_LOCATION (last));
2709 append_to_statement_list (t, &expr);
2710 }
2755 if (emit_false) 2711 if (emit_false)
2756 { 2712 {
2757 t = build1 (LABEL_EXPR, void_type_node, false_label); 2713 t = build1 (LABEL_EXPR, void_type_node, false_label);
2758 append_to_statement_list (t, &expr); 2714 append_to_statement_list (t, &expr);
2759 } 2715 }
2760 append_to_statement_list (else_, &expr); 2716 append_to_statement_list (else_, &expr);
2761 } 2717 }
2762 if (emit_end && end_label) 2718 if (emit_end && end_label)
2763 { 2719 {
2764 t = build1 (LABEL_EXPR, void_type_node, end_label); 2720 t = build1 (LABEL_EXPR, void_type_node, end_label);
2772 2728
2773 tree 2729 tree
2774 gimple_boolify (tree expr) 2730 gimple_boolify (tree expr)
2775 { 2731 {
2776 tree type = TREE_TYPE (expr); 2732 tree type = TREE_TYPE (expr);
2733 location_t loc = EXPR_LOCATION (expr);
2777 2734
2778 if (TREE_CODE (type) == BOOLEAN_TYPE) 2735 if (TREE_CODE (type) == BOOLEAN_TYPE)
2779 return expr; 2736 return expr;
2780 2737
2781 switch (TREE_CODE (expr)) 2738 switch (TREE_CODE (expr))
2799 TREE_TYPE (expr) = boolean_type_node; 2756 TREE_TYPE (expr) = boolean_type_node;
2800 return expr; 2757 return expr;
2801 2758
2802 default: 2759 default:
2803 /* Other expressions that get here must have boolean values, but 2760 /* Other expressions that get here must have boolean values, but
2804 might need to be converted to the appropriate mode. */ 2761 might need to be converted to the appropriate mode. */
2805 return fold_convert (boolean_type_node, expr); 2762 return fold_convert_loc (loc, boolean_type_node, expr);
2806 } 2763 }
2807 } 2764 }
2808 2765
2809 /* Given a conditional expression *EXPR_P without side effects, gimplify 2766 /* Given a conditional expression *EXPR_P without side effects, gimplify
2810 its operands. New statements are inserted to PRE_P. */ 2767 its operands. New statements are inserted to PRE_P. */
2827 TREE_SET_CODE (cond, TRUTH_OR_EXPR); 2784 TREE_SET_CODE (cond, TRUTH_OR_EXPR);
2828 ret = gimplify_expr (&cond, pre_p, NULL, is_gimple_condexpr, fb_rvalue); 2785 ret = gimplify_expr (&cond, pre_p, NULL, is_gimple_condexpr, fb_rvalue);
2829 COND_EXPR_COND (*expr_p) = cond; 2786 COND_EXPR_COND (*expr_p) = cond;
2830 2787
2831 tret = gimplify_expr (&COND_EXPR_THEN (expr), pre_p, NULL, 2788 tret = gimplify_expr (&COND_EXPR_THEN (expr), pre_p, NULL,
2832 is_gimple_val, fb_rvalue); 2789 is_gimple_val, fb_rvalue);
2833 ret = MIN (ret, tret); 2790 ret = MIN (ret, tret);
2834 tret = gimplify_expr (&COND_EXPR_ELSE (expr), pre_p, NULL, 2791 tret = gimplify_expr (&COND_EXPR_ELSE (expr), pre_p, NULL,
2835 is_gimple_val, fb_rvalue); 2792 is_gimple_val, fb_rvalue);
2836 2793
2837 return MIN (ret, tret); 2794 return MIN (ret, tret);
2838 } 2795 }
2839 2796
2840 /* Returns true if evaluating EXPR could trap. 2797 /* Returns true if evaluating EXPR could trap.
2861 } 2818 }
2862 2819
2863 /* Convert the conditional expression pointed to by EXPR_P '(p) ? a : b;' 2820 /* Convert the conditional expression pointed to by EXPR_P '(p) ? a : b;'
2864 into 2821 into
2865 2822
2866 if (p) if (p) 2823 if (p) if (p)
2867 t1 = a; a; 2824 t1 = a; a;
2868 else or else 2825 else or else
2869 t1 = b; b; 2826 t1 = b; b;
2870 t1; 2827 t1;
2871 2828
2872 The second form is used when *EXPR_P is of type void. 2829 The second form is used when *EXPR_P is of type void.
2873 2830
2874 PRE_P points to the list where side effects that must happen before 2831 PRE_P points to the list where side effects that must happen before
2883 tree label_true, label_false, label_cont; 2840 tree label_true, label_false, label_cont;
2884 bool have_then_clause_p, have_else_clause_p; 2841 bool have_then_clause_p, have_else_clause_p;
2885 gimple gimple_cond; 2842 gimple gimple_cond;
2886 enum tree_code pred_code; 2843 enum tree_code pred_code;
2887 gimple_seq seq = NULL; 2844 gimple_seq seq = NULL;
2845 location_t loc = EXPR_LOCATION (*expr_p);
2888 2846
2889 type = TREE_TYPE (expr); 2847 type = TREE_TYPE (expr);
2890 2848
2891 /* If this COND_EXPR has a value, copy the values into a temporary within 2849 /* If this COND_EXPR has a value, copy the values into a temporary within
2892 the arms. */ 2850 the arms. */
2893 if (! VOID_TYPE_P (type)) 2851 if (! VOID_TYPE_P (type))
2894 { 2852 {
2895 tree result; 2853 tree result;
2896 2854
2897 /* If an rvalue is ok or we do not require an lvalue, avoid creating 2855 /* If an rvalue is ok or we do not require an lvalue, avoid creating
2898 an addressable temporary. */ 2856 an addressable temporary. */
2899 if (((fallback & fb_rvalue) 2857 if (((fallback & fb_rvalue)
2900 || !(fallback & fb_lvalue)) 2858 || !(fallback & fb_lvalue))
2901 && !TREE_ADDRESSABLE (type)) 2859 && !TREE_ADDRESSABLE (type))
2902 { 2860 {
2903 if (gimplify_ctxp->allow_rhs_cond_expr 2861 if (gimplify_ctxp->allow_rhs_cond_expr
2904 /* If either branch has side effects or could trap, it can't be 2862 /* If either branch has side effects or could trap, it can't be
2905 evaluated unconditionally. */ 2863 evaluated unconditionally. */
2906 && !TREE_SIDE_EFFECTS (TREE_OPERAND (*expr_p, 1)) 2864 && !TREE_SIDE_EFFECTS (TREE_OPERAND (*expr_p, 1))
2907 && !generic_expr_could_trap_p (TREE_OPERAND (*expr_p, 1)) 2865 && !generic_expr_could_trap_p (TREE_OPERAND (*expr_p, 1))
2908 && !TREE_SIDE_EFFECTS (TREE_OPERAND (*expr_p, 2)) 2866 && !TREE_SIDE_EFFECTS (TREE_OPERAND (*expr_p, 2))
2909 && !generic_expr_could_trap_p (TREE_OPERAND (*expr_p, 2))) 2867 && !generic_expr_could_trap_p (TREE_OPERAND (*expr_p, 2)))
2910 return gimplify_pure_cond_expr (expr_p, pre_p); 2868 return gimplify_pure_cond_expr (expr_p, pre_p);
2911 2869
2912 result = tmp = create_tmp_var (TREE_TYPE (expr), "iftmp"); 2870 result = tmp = create_tmp_var (TREE_TYPE (expr), "iftmp");
2913 ret = GS_ALL_DONE; 2871 ret = GS_ALL_DONE;
2914 } 2872 }
2915 else 2873 else
2916 { 2874 {
2917 tree type = build_pointer_type (TREE_TYPE (expr)); 2875 tree type = build_pointer_type (TREE_TYPE (expr));
2918 2876
2919 if (TREE_TYPE (TREE_OPERAND (expr, 1)) != void_type_node) 2877 if (TREE_TYPE (TREE_OPERAND (expr, 1)) != void_type_node)
2920 TREE_OPERAND (expr, 1) = 2878 TREE_OPERAND (expr, 1) =
2921 build_fold_addr_expr (TREE_OPERAND (expr, 1)); 2879 build_fold_addr_expr_loc (loc, TREE_OPERAND (expr, 1));
2922 2880
2923 if (TREE_TYPE (TREE_OPERAND (expr, 2)) != void_type_node) 2881 if (TREE_TYPE (TREE_OPERAND (expr, 2)) != void_type_node)
2924 TREE_OPERAND (expr, 2) = 2882 TREE_OPERAND (expr, 2) =
2925 build_fold_addr_expr (TREE_OPERAND (expr, 2)); 2883 build_fold_addr_expr_loc (loc, TREE_OPERAND (expr, 2));
2926 2884
2927 tmp = create_tmp_var (type, "iftmp"); 2885 tmp = create_tmp_var (type, "iftmp");
2928 2886
2929 expr = build3 (COND_EXPR, void_type_node, TREE_OPERAND (expr, 0), 2887 expr = build3 (COND_EXPR, void_type_node, TREE_OPERAND (expr, 0),
2930 TREE_OPERAND (expr, 1), TREE_OPERAND (expr, 2)); 2888 TREE_OPERAND (expr, 1), TREE_OPERAND (expr, 2));
2931 2889
2932 result = build_fold_indirect_ref (tmp); 2890 result = build_fold_indirect_ref_loc (loc, tmp);
2933 } 2891 }
2934 2892
2935 /* Build the then clause, 't1 = a;'. But don't build an assignment 2893 /* Build the then clause, 't1 = a;'. But don't build an assignment
2936 if this branch is void; in C++ it can be, if it's a throw. */ 2894 if this branch is void; in C++ it can be, if it's a throw. */
2937 if (TREE_TYPE (TREE_OPERAND (expr, 1)) != void_type_node) 2895 if (TREE_TYPE (TREE_OPERAND (expr, 1)) != void_type_node)
2938 TREE_OPERAND (expr, 1) 2896 TREE_OPERAND (expr, 1)
2939 = build2 (MODIFY_EXPR, TREE_TYPE (tmp), tmp, TREE_OPERAND (expr, 1)); 2897 = build2 (MODIFY_EXPR, TREE_TYPE (tmp), tmp, TREE_OPERAND (expr, 1));
2940 2898
2941 /* Build the else clause, 't1 = b;'. */ 2899 /* Build the else clause, 't1 = b;'. */
2942 if (TREE_TYPE (TREE_OPERAND (expr, 2)) != void_type_node) 2900 if (TREE_TYPE (TREE_OPERAND (expr, 2)) != void_type_node)
2943 TREE_OPERAND (expr, 2) 2901 TREE_OPERAND (expr, 2)
2944 = build2 (MODIFY_EXPR, TREE_TYPE (tmp), tmp, TREE_OPERAND (expr, 2)); 2902 = build2 (MODIFY_EXPR, TREE_TYPE (tmp), tmp, TREE_OPERAND (expr, 2));
2945 2903
2946 TREE_TYPE (expr) = void_type_node; 2904 TREE_TYPE (expr) = void_type_node;
2947 recalculate_side_effects (expr); 2905 recalculate_side_effects (expr);
2948 2906
2949 /* Move the COND_EXPR to the prequeue. */ 2907 /* Move the COND_EXPR to the prequeue. */
2961 || TREE_CODE (TREE_OPERAND (expr, 0)) == TRUTH_ORIF_EXPR) 2919 || TREE_CODE (TREE_OPERAND (expr, 0)) == TRUTH_ORIF_EXPR)
2962 { 2920 {
2963 expr = shortcut_cond_expr (expr); 2921 expr = shortcut_cond_expr (expr);
2964 2922
2965 if (expr != *expr_p) 2923 if (expr != *expr_p)
2966 { 2924 {
2967 *expr_p = expr; 2925 *expr_p = expr;
2968 2926
2969 /* We can't rely on gimplify_expr to re-gimplify the expanded 2927 /* We can't rely on gimplify_expr to re-gimplify the expanded
2970 form properly, as cleanups might cause the target labels to be 2928 form properly, as cleanups might cause the target labels to be
2971 wrapped in a TRY_FINALLY_EXPR. To prevent that, we need to 2929 wrapped in a TRY_FINALLY_EXPR. To prevent that, we need to
2972 set up a conditional context. */ 2930 set up a conditional context. */
2973 gimple_push_condition (); 2931 gimple_push_condition ();
2974 gimplify_stmt (expr_p, &seq); 2932 gimplify_stmt (expr_p, &seq);
2975 gimple_pop_condition (pre_p); 2933 gimple_pop_condition (pre_p);
2976 gimple_seq_add_seq (pre_p, seq); 2934 gimple_seq_add_seq (pre_p, seq);
2977 2935
2978 return GS_ALL_DONE; 2936 return GS_ALL_DONE;
2979 } 2937 }
2980 } 2938 }
2981 2939
2982 /* Now do the normal gimplification. */ 2940 /* Now do the normal gimplification. */
2983 2941
2984 /* Gimplify condition. */ 2942 /* Gimplify condition. */
2985 ret = gimplify_expr (&TREE_OPERAND (expr, 0), pre_p, NULL, is_gimple_condexpr, 2943 ret = gimplify_expr (&TREE_OPERAND (expr, 0), pre_p, NULL, is_gimple_condexpr,
2986 fb_rvalue); 2944 fb_rvalue);
2987 if (ret == GS_ERROR) 2945 if (ret == GS_ERROR)
2988 return GS_ERROR; 2946 return GS_ERROR;
2989 gcc_assert (TREE_OPERAND (expr, 0) != NULL_TREE); 2947 gcc_assert (TREE_OPERAND (expr, 0) != NULL_TREE);
2990 2948
2991 gimple_push_condition (); 2949 gimple_push_condition ();
2993 have_then_clause_p = have_else_clause_p = false; 2951 have_then_clause_p = have_else_clause_p = false;
2994 if (TREE_OPERAND (expr, 1) != NULL 2952 if (TREE_OPERAND (expr, 1) != NULL
2995 && TREE_CODE (TREE_OPERAND (expr, 1)) == GOTO_EXPR 2953 && TREE_CODE (TREE_OPERAND (expr, 1)) == GOTO_EXPR
2996 && TREE_CODE (GOTO_DESTINATION (TREE_OPERAND (expr, 1))) == LABEL_DECL 2954 && TREE_CODE (GOTO_DESTINATION (TREE_OPERAND (expr, 1))) == LABEL_DECL
2997 && (DECL_CONTEXT (GOTO_DESTINATION (TREE_OPERAND (expr, 1))) 2955 && (DECL_CONTEXT (GOTO_DESTINATION (TREE_OPERAND (expr, 1)))
2998 == current_function_decl) 2956 == current_function_decl)
2999 /* For -O0 avoid this optimization if the COND_EXPR and GOTO_EXPR 2957 /* For -O0 avoid this optimization if the COND_EXPR and GOTO_EXPR
3000 have different locations, otherwise we end up with incorrect 2958 have different locations, otherwise we end up with incorrect
3001 location information on the branches. */ 2959 location information on the branches. */
3002 && (optimize 2960 && (optimize
3003 || !EXPR_HAS_LOCATION (expr) 2961 || !EXPR_HAS_LOCATION (expr)
3004 || !EXPR_HAS_LOCATION (TREE_OPERAND (expr, 1)) 2962 || !EXPR_HAS_LOCATION (TREE_OPERAND (expr, 1))
3005 || EXPR_LOCATION (expr) == EXPR_LOCATION (TREE_OPERAND (expr, 1)))) 2963 || EXPR_LOCATION (expr) == EXPR_LOCATION (TREE_OPERAND (expr, 1))))
3006 { 2964 {
3007 label_true = GOTO_DESTINATION (TREE_OPERAND (expr, 1)); 2965 label_true = GOTO_DESTINATION (TREE_OPERAND (expr, 1));
3008 have_then_clause_p = true; 2966 have_then_clause_p = true;
3009 } 2967 }
3010 else 2968 else
3011 label_true = create_artificial_label (); 2969 label_true = create_artificial_label (UNKNOWN_LOCATION);
3012 if (TREE_OPERAND (expr, 2) != NULL 2970 if (TREE_OPERAND (expr, 2) != NULL
3013 && TREE_CODE (TREE_OPERAND (expr, 2)) == GOTO_EXPR 2971 && TREE_CODE (TREE_OPERAND (expr, 2)) == GOTO_EXPR
3014 && TREE_CODE (GOTO_DESTINATION (TREE_OPERAND (expr, 2))) == LABEL_DECL 2972 && TREE_CODE (GOTO_DESTINATION (TREE_OPERAND (expr, 2))) == LABEL_DECL
3015 && (DECL_CONTEXT (GOTO_DESTINATION (TREE_OPERAND (expr, 2))) 2973 && (DECL_CONTEXT (GOTO_DESTINATION (TREE_OPERAND (expr, 2)))
3016 == current_function_decl) 2974 == current_function_decl)
3017 /* For -O0 avoid this optimization if the COND_EXPR and GOTO_EXPR 2975 /* For -O0 avoid this optimization if the COND_EXPR and GOTO_EXPR
3018 have different locations, otherwise we end up with incorrect 2976 have different locations, otherwise we end up with incorrect
3019 location information on the branches. */ 2977 location information on the branches. */
3020 && (optimize 2978 && (optimize
3021 || !EXPR_HAS_LOCATION (expr) 2979 || !EXPR_HAS_LOCATION (expr)
3022 || !EXPR_HAS_LOCATION (TREE_OPERAND (expr, 2)) 2980 || !EXPR_HAS_LOCATION (TREE_OPERAND (expr, 2))
3023 || EXPR_LOCATION (expr) == EXPR_LOCATION (TREE_OPERAND (expr, 2)))) 2981 || EXPR_LOCATION (expr) == EXPR_LOCATION (TREE_OPERAND (expr, 2))))
3024 { 2982 {
3025 label_false = GOTO_DESTINATION (TREE_OPERAND (expr, 2)); 2983 label_false = GOTO_DESTINATION (TREE_OPERAND (expr, 2));
3026 have_else_clause_p = true; 2984 have_else_clause_p = true;
3027 } 2985 }
3028 else 2986 else
3029 label_false = create_artificial_label (); 2987 label_false = create_artificial_label (UNKNOWN_LOCATION);
3030 2988
3031 gimple_cond_get_ops_from_tree (COND_EXPR_COND (expr), &pred_code, &arm1, 2989 gimple_cond_get_ops_from_tree (COND_EXPR_COND (expr), &pred_code, &arm1,
3032 &arm2); 2990 &arm2);
3033 2991
3034 gimple_cond = gimple_build_cond (pred_code, arm1, arm2, label_true, 2992 gimple_cond = gimple_build_cond (pred_code, arm1, arm2, label_true,
3035 label_false); 2993 label_false);
3036 2994
3037 gimplify_seq_add_stmt (&seq, gimple_cond); 2995 gimplify_seq_add_stmt (&seq, gimple_cond);
3038 label_cont = NULL_TREE; 2996 label_cont = NULL_TREE;
3039 if (!have_then_clause_p) 2997 if (!have_then_clause_p)
3040 { 2998 {
3041 /* For if (...) {} else { code; } put label_true after 2999 /* For if (...) {} else { code; } put label_true after
3042 the else block. */ 3000 the else block. */
3043 if (TREE_OPERAND (expr, 1) == NULL_TREE 3001 if (TREE_OPERAND (expr, 1) == NULL_TREE
3044 && !have_else_clause_p 3002 && !have_else_clause_p
3045 && TREE_OPERAND (expr, 2) != NULL_TREE) 3003 && TREE_OPERAND (expr, 2) != NULL_TREE)
3046 label_cont = label_true; 3004 label_cont = label_true;
3047 else 3005 else
3048 { 3006 {
3049 gimplify_seq_add_stmt (&seq, gimple_build_label (label_true)); 3007 gimplify_seq_add_stmt (&seq, gimple_build_label (label_true));
3050 have_then_clause_p = gimplify_stmt (&TREE_OPERAND (expr, 1), &seq); 3008 have_then_clause_p = gimplify_stmt (&TREE_OPERAND (expr, 1), &seq);
3051 /* For if (...) { code; } else {} or 3009 /* For if (...) { code; } else {} or
3052 if (...) { code; } else goto label; or 3010 if (...) { code; } else goto label; or
3053 if (...) { code; return; } else { ... } 3011 if (...) { code; return; } else { ... }
3054 label_cont isn't needed. */ 3012 label_cont isn't needed. */
3055 if (!have_else_clause_p 3013 if (!have_else_clause_p
3056 && TREE_OPERAND (expr, 2) != NULL_TREE 3014 && TREE_OPERAND (expr, 2) != NULL_TREE
3057 && gimple_seq_may_fallthru (seq)) 3015 && gimple_seq_may_fallthru (seq))
3058 { 3016 {
3059 gimple g; 3017 gimple g;
3060 label_cont = create_artificial_label (); 3018 label_cont = create_artificial_label (UNKNOWN_LOCATION);
3061 3019
3062 g = gimple_build_goto (label_cont); 3020 g = gimple_build_goto (label_cont);
3063 3021
3064 /* GIMPLE_COND's are very low level; they have embedded 3022 /* GIMPLE_COND's are very low level; they have embedded
3065 gotos. This particular embedded goto should not be marked 3023 gotos. This particular embedded goto should not be marked
3066 with the location of the original COND_EXPR, as it would 3024 with the location of the original COND_EXPR, as it would
3067 correspond to the COND_EXPR's condition, not the ELSE or the 3025 correspond to the COND_EXPR's condition, not the ELSE or the
3068 THEN arms. To avoid marking it with the wrong location, flag 3026 THEN arms. To avoid marking it with the wrong location, flag
3069 it as "no location". */ 3027 it as "no location". */
3070 gimple_set_do_not_emit_location (g); 3028 gimple_set_do_not_emit_location (g);
3071 3029
3072 gimplify_seq_add_stmt (&seq, g); 3030 gimplify_seq_add_stmt (&seq, g);
3073 } 3031 }
3074 } 3032 }
3075 } 3033 }
3076 if (!have_else_clause_p) 3034 if (!have_else_clause_p)
3077 { 3035 {
3078 gimplify_seq_add_stmt (&seq, gimple_build_label (label_false)); 3036 gimplify_seq_add_stmt (&seq, gimple_build_label (label_false));
3079 have_else_clause_p = gimplify_stmt (&TREE_OPERAND (expr, 2), &seq); 3037 have_else_clause_p = gimplify_stmt (&TREE_OPERAND (expr, 2), &seq);
3097 3055
3098 *expr_p = NULL; 3056 *expr_p = NULL;
3099 return ret; 3057 return ret;
3100 } 3058 }
3101 3059
3060 /* Prepare the node pointed to by EXPR_P, an is_gimple_addressable expression,
3061 to be marked addressable.
3062
3063 We cannot rely on such an expression being directly markable if a temporary
3064 has been created by the gimplification. In this case, we create another
3065 temporary and initialize it with a copy, which will become a store after we
3066 mark it addressable. This can happen if the front-end passed us something
3067 that it could not mark addressable yet, like a Fortran pass-by-reference
3068 parameter (int) floatvar. */
3069
3070 static void
3071 prepare_gimple_addressable (tree *expr_p, gimple_seq *seq_p)
3072 {
3073 while (handled_component_p (*expr_p))
3074 expr_p = &TREE_OPERAND (*expr_p, 0);
3075 if (is_gimple_reg (*expr_p))
3076 *expr_p = get_initialized_tmp_var (*expr_p, seq_p, NULL);
3077 }
3078
3102 /* A subroutine of gimplify_modify_expr. Replace a MODIFY_EXPR with 3079 /* A subroutine of gimplify_modify_expr. Replace a MODIFY_EXPR with
3103 a call to __builtin_memcpy. */ 3080 a call to __builtin_memcpy. */
3104 3081
3105 static enum gimplify_status 3082 static enum gimplify_status
3106 gimplify_modify_expr_to_memcpy (tree *expr_p, tree size, bool want_value, 3083 gimplify_modify_expr_to_memcpy (tree *expr_p, tree size, bool want_value,
3107 gimple_seq *seq_p) 3084 gimple_seq *seq_p)
3108 { 3085 {
3109 tree t, to, to_ptr, from, from_ptr; 3086 tree t, to, to_ptr, from, from_ptr;
3110 gimple gs; 3087 gimple gs;
3088 location_t loc = EXPR_LOCATION (*expr_p);
3111 3089
3112 to = TREE_OPERAND (*expr_p, 0); 3090 to = TREE_OPERAND (*expr_p, 0);
3113 from = TREE_OPERAND (*expr_p, 1); 3091 from = TREE_OPERAND (*expr_p, 1);
3114 3092
3115 from_ptr = build_fold_addr_expr (from); 3093 /* Mark the RHS addressable. Beware that it may not be possible to do so
3116 gimplify_arg (&from_ptr, seq_p, EXPR_LOCATION (*expr_p)); 3094 directly if a temporary has been created by the gimplification. */
3117 3095 prepare_gimple_addressable (&from, seq_p);
3118 to_ptr = build_fold_addr_expr (to); 3096
3119 gimplify_arg (&to_ptr, seq_p, EXPR_LOCATION (*expr_p)); 3097 mark_addressable (from);
3098 from_ptr = build_fold_addr_expr_loc (loc, from);
3099 gimplify_arg (&from_ptr, seq_p, loc);
3100
3101 mark_addressable (to);
3102 to_ptr = build_fold_addr_expr_loc (loc, to);
3103 gimplify_arg (&to_ptr, seq_p, loc);
3120 3104
3121 t = implicit_built_in_decls[BUILT_IN_MEMCPY]; 3105 t = implicit_built_in_decls[BUILT_IN_MEMCPY];
3122 3106
3123 gs = gimple_build_call (t, 3, to_ptr, from_ptr, size); 3107 gs = gimple_build_call (t, 3, to_ptr, from_ptr, size);
3124 3108
3142 a call to __builtin_memset. In this case we know that the RHS is 3126 a call to __builtin_memset. In this case we know that the RHS is
3143 a CONSTRUCTOR with an empty element list. */ 3127 a CONSTRUCTOR with an empty element list. */
3144 3128
3145 static enum gimplify_status 3129 static enum gimplify_status
3146 gimplify_modify_expr_to_memset (tree *expr_p, tree size, bool want_value, 3130 gimplify_modify_expr_to_memset (tree *expr_p, tree size, bool want_value,
3147 gimple_seq *seq_p) 3131 gimple_seq *seq_p)
3148 { 3132 {
3149 tree t, from, to, to_ptr; 3133 tree t, from, to, to_ptr;
3150 gimple gs; 3134 gimple gs;
3135 location_t loc = EXPR_LOCATION (*expr_p);
3151 3136
3152 /* Assert our assumptions, to abort instead of producing wrong code 3137 /* Assert our assumptions, to abort instead of producing wrong code
3153 silently if they are not met. Beware that the RHS CONSTRUCTOR might 3138 silently if they are not met. Beware that the RHS CONSTRUCTOR might
3154 not be immediately exposed. */ 3139 not be immediately exposed. */
3155 from = TREE_OPERAND (*expr_p, 1); 3140 from = TREE_OPERAND (*expr_p, 1);
3156 if (TREE_CODE (from) == WITH_SIZE_EXPR) 3141 if (TREE_CODE (from) == WITH_SIZE_EXPR)
3157 from = TREE_OPERAND (from, 0); 3142 from = TREE_OPERAND (from, 0);
3158 3143
3159 gcc_assert (TREE_CODE (from) == CONSTRUCTOR 3144 gcc_assert (TREE_CODE (from) == CONSTRUCTOR
3160 && VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (from))); 3145 && VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (from)));
3161 3146
3162 /* Now proceed. */ 3147 /* Now proceed. */
3163 to = TREE_OPERAND (*expr_p, 0); 3148 to = TREE_OPERAND (*expr_p, 0);
3164 3149
3165 to_ptr = build_fold_addr_expr (to); 3150 to_ptr = build_fold_addr_expr_loc (loc, to);
3166 gimplify_arg (&to_ptr, seq_p, EXPR_LOCATION (*expr_p)); 3151 gimplify_arg (&to_ptr, seq_p, loc);
3167 t = implicit_built_in_decls[BUILT_IN_MEMSET]; 3152 t = implicit_built_in_decls[BUILT_IN_MEMSET];
3168 3153
3169 gs = gimple_build_call (t, 3, to_ptr, integer_zero_node, size); 3154 gs = gimple_build_call (t, 3, to_ptr, integer_zero_node, size);
3170 3155
3171 if (want_value) 3156 if (want_value)
3222 if (TREE_CODE (t) == CALL_EXPR) 3207 if (TREE_CODE (t) == CALL_EXPR)
3223 { 3208 {
3224 tree type, fntype = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (t))); 3209 tree type, fntype = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (t)));
3225 3210
3226 for (type = TYPE_ARG_TYPES (fntype); type; type = TREE_CHAIN (type)) 3211 for (type = TYPE_ARG_TYPES (fntype); type; type = TREE_CHAIN (type))
3227 if (POINTER_TYPE_P (TREE_VALUE (type)) 3212 if (POINTER_TYPE_P (TREE_VALUE (type))
3228 && (!data->lhs_base_decl || TREE_ADDRESSABLE (data->lhs_base_decl)) 3213 && (!data->lhs_base_decl || TREE_ADDRESSABLE (data->lhs_base_decl))
3229 && alias_sets_conflict_p (data->lhs_alias_set, 3214 && alias_sets_conflict_p (data->lhs_alias_set,
3230 get_alias_set 3215 get_alias_set
3231 (TREE_TYPE (TREE_VALUE (type))))) 3216 (TREE_TYPE (TREE_VALUE (type)))))
3232 return t; 3217 return t;
3233 } 3218 }
3234 3219
3235 if (IS_TYPE_OR_DECL_P (t)) 3220 if (IS_TYPE_OR_DECL_P (t))
3236 *walk_subtrees = 0; 3221 *walk_subtrees = 0;
3237 return NULL; 3222 return NULL;
3241 force values that overlap with the lhs (as described by *DATA) 3226 force values that overlap with the lhs (as described by *DATA)
3242 into temporaries. */ 3227 into temporaries. */
3243 3228
3244 static void 3229 static void
3245 gimplify_init_ctor_preeval (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, 3230 gimplify_init_ctor_preeval (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
3246 struct gimplify_init_ctor_preeval_data *data) 3231 struct gimplify_init_ctor_preeval_data *data)
3247 { 3232 {
3248 enum gimplify_status one; 3233 enum gimplify_status one;
3249 3234
3250 /* If the value is constant, then there's nothing to pre-evaluate. */ 3235 /* If the value is constant, then there's nothing to pre-evaluate. */
3251 if (TREE_CONSTANT (*expr_p)) 3236 if (TREE_CONSTANT (*expr_p))
3252 { 3237 {
3253 /* Ensure it does not have side effects, it might contain a reference to 3238 /* Ensure it does not have side effects, it might contain a reference to
3254 the object we're initializing. */ 3239 the object we're initializing. */
3255 gcc_assert (!TREE_SIDE_EFFECTS (*expr_p)); 3240 gcc_assert (!TREE_SIDE_EFFECTS (*expr_p));
3256 return; 3241 return;
3257 } 3242 }
3258 3243
3259 /* If the type has non-trivial constructors, we can't pre-evaluate. */ 3244 /* If the type has non-trivial constructors, we can't pre-evaluate. */
3266 unsigned HOST_WIDE_INT ix; 3251 unsigned HOST_WIDE_INT ix;
3267 constructor_elt *ce; 3252 constructor_elt *ce;
3268 VEC(constructor_elt,gc) *v = CONSTRUCTOR_ELTS (*expr_p); 3253 VEC(constructor_elt,gc) *v = CONSTRUCTOR_ELTS (*expr_p);
3269 3254
3270 for (ix = 0; VEC_iterate (constructor_elt, v, ix, ce); ix++) 3255 for (ix = 0; VEC_iterate (constructor_elt, v, ix, ce); ix++)
3271 gimplify_init_ctor_preeval (&ce->value, pre_p, post_p, data); 3256 gimplify_init_ctor_preeval (&ce->value, pre_p, post_p, data);
3272 3257
3273 return; 3258 return;
3274 } 3259 }
3275 3260
3276 /* If this is a variable sized type, we must remember the size. */ 3261 /* If this is a variable sized type, we must remember the size. */
3314 3299
3315 var = lower; 3300 var = lower;
3316 loop_entry: 3301 loop_entry:
3317 object[var] = value; 3302 object[var] = value;
3318 if (var == upper) 3303 if (var == upper)
3319 goto loop_exit; 3304 goto loop_exit;
3320 var = var + 1; 3305 var = var + 1;
3321 goto loop_entry; 3306 goto loop_entry;
3322 loop_exit: 3307 loop_exit:
3323 3308
3324 We increment var _after_ the loop exit check because we might otherwise 3309 We increment var _after_ the loop exit check because we might otherwise
3326 3311
3327 Note that we never have to deal with SAVE_EXPRs here, because this has 3312 Note that we never have to deal with SAVE_EXPRs here, because this has
3328 already been taken care of for us, in gimplify_init_ctor_preeval(). */ 3313 already been taken care of for us, in gimplify_init_ctor_preeval(). */
3329 3314
3330 static void gimplify_init_ctor_eval (tree, VEC(constructor_elt,gc) *, 3315 static void gimplify_init_ctor_eval (tree, VEC(constructor_elt,gc) *,
3331 gimple_seq *, bool); 3316 gimple_seq *, bool);
3332 3317
3333 static void 3318 static void
3334 gimplify_init_ctor_eval_range (tree object, tree lower, tree upper, 3319 gimplify_init_ctor_eval_range (tree object, tree lower, tree upper,
3335 tree value, tree array_elt_type, 3320 tree value, tree array_elt_type,
3336 gimple_seq *pre_p, bool cleared) 3321 gimple_seq *pre_p, bool cleared)
3337 { 3322 {
3338 tree loop_entry_label, loop_exit_label, fall_thru_label; 3323 tree loop_entry_label, loop_exit_label, fall_thru_label;
3339 tree var, var_type, cref, tmp; 3324 tree var, var_type, cref, tmp;
3340 3325
3341 loop_entry_label = create_artificial_label (); 3326 loop_entry_label = create_artificial_label (UNKNOWN_LOCATION);
3342 loop_exit_label = create_artificial_label (); 3327 loop_exit_label = create_artificial_label (UNKNOWN_LOCATION);
3343 fall_thru_label = create_artificial_label (); 3328 fall_thru_label = create_artificial_label (UNKNOWN_LOCATION);
3344 3329
3345 /* Create and initialize the index variable. */ 3330 /* Create and initialize the index variable. */
3346 var_type = TREE_TYPE (upper); 3331 var_type = TREE_TYPE (upper);
3347 var = create_tmp_var (var_type, NULL); 3332 var = create_tmp_var (var_type, NULL);
3348 gimplify_seq_add_stmt (pre_p, gimple_build_assign (var, lower)); 3333 gimplify_seq_add_stmt (pre_p, gimple_build_assign (var, lower));
3350 /* Add the loop entry label. */ 3335 /* Add the loop entry label. */
3351 gimplify_seq_add_stmt (pre_p, gimple_build_label (loop_entry_label)); 3336 gimplify_seq_add_stmt (pre_p, gimple_build_label (loop_entry_label));
3352 3337
3353 /* Build the reference. */ 3338 /* Build the reference. */
3354 cref = build4 (ARRAY_REF, array_elt_type, unshare_expr (object), 3339 cref = build4 (ARRAY_REF, array_elt_type, unshare_expr (object),
3355 var, NULL_TREE, NULL_TREE); 3340 var, NULL_TREE, NULL_TREE);
3356 3341
3357 /* If we are a constructor, just call gimplify_init_ctor_eval to do 3342 /* If we are a constructor, just call gimplify_init_ctor_eval to do
3358 the store. Otherwise just assign value to the reference. */ 3343 the store. Otherwise just assign value to the reference. */
3359 3344
3360 if (TREE_CODE (value) == CONSTRUCTOR) 3345 if (TREE_CODE (value) == CONSTRUCTOR)
3361 /* NB we might have to call ourself recursively through 3346 /* NB we might have to call ourself recursively through
3362 gimplify_init_ctor_eval if the value is a constructor. */ 3347 gimplify_init_ctor_eval if the value is a constructor. */
3363 gimplify_init_ctor_eval (cref, CONSTRUCTOR_ELTS (value), 3348 gimplify_init_ctor_eval (cref, CONSTRUCTOR_ELTS (value),
3364 pre_p, cleared); 3349 pre_p, cleared);
3365 else 3350 else
3366 gimplify_seq_add_stmt (pre_p, gimple_build_assign (cref, value)); 3351 gimplify_seq_add_stmt (pre_p, gimple_build_assign (cref, value));
3367 3352
3368 /* We exit the loop when the index var is equal to the upper bound. */ 3353 /* We exit the loop when the index var is equal to the upper bound. */
3369 gimplify_seq_add_stmt (pre_p, 3354 gimplify_seq_add_stmt (pre_p,
3370 gimple_build_cond (EQ_EXPR, var, upper, 3355 gimple_build_cond (EQ_EXPR, var, upper,
3371 loop_exit_label, fall_thru_label)); 3356 loop_exit_label, fall_thru_label));
3372 3357
3373 gimplify_seq_add_stmt (pre_p, gimple_build_label (fall_thru_label)); 3358 gimplify_seq_add_stmt (pre_p, gimple_build_label (fall_thru_label));
3374 3359
3375 /* Otherwise, increment the index var... */ 3360 /* Otherwise, increment the index var... */
3376 tmp = build2 (PLUS_EXPR, var_type, var, 3361 tmp = build2 (PLUS_EXPR, var_type, var,
3377 fold_convert (var_type, integer_one_node)); 3362 fold_convert (var_type, integer_one_node));
3378 gimplify_seq_add_stmt (pre_p, gimple_build_assign (var, tmp)); 3363 gimplify_seq_add_stmt (pre_p, gimple_build_assign (var, tmp));
3379 3364
3380 /* ...and jump back to the loop entry. */ 3365 /* ...and jump back to the loop entry. */
3381 gimplify_seq_add_stmt (pre_p, gimple_build_goto (loop_entry_label)); 3366 gimplify_seq_add_stmt (pre_p, gimple_build_goto (loop_entry_label));
3382 3367
3383 /* Add the loop exit label. */ 3368 /* Add the loop exit label. */
3384 gimplify_seq_add_stmt (pre_p, gimple_build_label (loop_exit_label)); 3369 gimplify_seq_add_stmt (pre_p, gimple_build_label (loop_exit_label));
3385 } 3370 }
3386 3371
3387 /* Return true if FDECL is accessing a field that is zero sized. */ 3372 /* Return true if FDECL is accessing a field that is zero sized. */
3388 3373
3389 static bool 3374 static bool
3390 zero_sized_field_decl (const_tree fdecl) 3375 zero_sized_field_decl (const_tree fdecl)
3391 { 3376 {
3392 if (TREE_CODE (fdecl) == FIELD_DECL && DECL_SIZE (fdecl) 3377 if (TREE_CODE (fdecl) == FIELD_DECL && DECL_SIZE (fdecl)
3393 && integer_zerop (DECL_SIZE (fdecl))) 3378 && integer_zerop (DECL_SIZE (fdecl)))
3394 return true; 3379 return true;
3395 return false; 3380 return false;
3396 } 3381 }
3397 3382
3398 /* Return true if TYPE is zero sized. */ 3383 /* Return true if TYPE is zero sized. */
3399 3384
3400 static bool 3385 static bool
3401 zero_sized_type (const_tree type) 3386 zero_sized_type (const_tree type)
3402 { 3387 {
3403 if (AGGREGATE_TYPE_P (type) && TYPE_SIZE (type) 3388 if (AGGREGATE_TYPE_P (type) && TYPE_SIZE (type)
3404 && integer_zerop (TYPE_SIZE (type))) 3389 && integer_zerop (TYPE_SIZE (type)))
3412 CONSTRUCTOR. CLEARED is true if the entire LHS object has been 3397 CONSTRUCTOR. CLEARED is true if the entire LHS object has been
3413 zeroed first. */ 3398 zeroed first. */
3414 3399
3415 static void 3400 static void
3416 gimplify_init_ctor_eval (tree object, VEC(constructor_elt,gc) *elts, 3401 gimplify_init_ctor_eval (tree object, VEC(constructor_elt,gc) *elts,
3417 gimple_seq *pre_p, bool cleared) 3402 gimple_seq *pre_p, bool cleared)
3418 { 3403 {
3419 tree array_elt_type = NULL; 3404 tree array_elt_type = NULL;
3420 unsigned HOST_WIDE_INT ix; 3405 unsigned HOST_WIDE_INT ix;
3421 tree purpose, value; 3406 tree purpose, value;
3422 3407
3427 { 3412 {
3428 tree cref; 3413 tree cref;
3429 3414
3430 /* NULL values are created above for gimplification errors. */ 3415 /* NULL values are created above for gimplification errors. */
3431 if (value == NULL) 3416 if (value == NULL)
3432 continue; 3417 continue;
3433 3418
3434 if (cleared && initializer_zerop (value)) 3419 if (cleared && initializer_zerop (value))
3435 continue; 3420 continue;
3436 3421
3437 /* ??? Here's to hoping the front end fills in all of the indices, 3422 /* ??? Here's to hoping the front end fills in all of the indices,
3438 so we don't have to figure out what's missing ourselves. */ 3423 so we don't have to figure out what's missing ourselves. */
3439 gcc_assert (purpose); 3424 gcc_assert (purpose);
3440 3425
3441 /* Skip zero-sized fields, unless value has side-effects. This can 3426 /* Skip zero-sized fields, unless value has side-effects. This can
3442 happen with calls to functions returning a zero-sized type, which 3427 happen with calls to functions returning a zero-sized type, which
3443 we shouldn't discard. As a number of downstream passes don't 3428 we shouldn't discard. As a number of downstream passes don't
3444 expect sets of zero-sized fields, we rely on the gimplification of 3429 expect sets of zero-sized fields, we rely on the gimplification of
3445 the MODIFY_EXPR we make below to drop the assignment statement. */ 3430 the MODIFY_EXPR we make below to drop the assignment statement. */
3446 if (! TREE_SIDE_EFFECTS (value) && zero_sized_field_decl (purpose)) 3431 if (! TREE_SIDE_EFFECTS (value) && zero_sized_field_decl (purpose))
3447 continue; 3432 continue;
3448 3433
3449 /* If we have a RANGE_EXPR, we have to build a loop to assign the 3434 /* If we have a RANGE_EXPR, we have to build a loop to assign the
3450 whole range. */ 3435 whole range. */
3451 if (TREE_CODE (purpose) == RANGE_EXPR) 3436 if (TREE_CODE (purpose) == RANGE_EXPR)
3452 { 3437 {
3453 tree lower = TREE_OPERAND (purpose, 0); 3438 tree lower = TREE_OPERAND (purpose, 0);
3454 tree upper = TREE_OPERAND (purpose, 1); 3439 tree upper = TREE_OPERAND (purpose, 1);
3455 3440
3456 /* If the lower bound is equal to upper, just treat it as if 3441 /* If the lower bound is equal to upper, just treat it as if
3457 upper was the index. */ 3442 upper was the index. */
3458 if (simple_cst_equal (lower, upper)) 3443 if (simple_cst_equal (lower, upper))
3459 purpose = upper; 3444 purpose = upper;
3460 else 3445 else
3461 { 3446 {
3462 gimplify_init_ctor_eval_range (object, lower, upper, value, 3447 gimplify_init_ctor_eval_range (object, lower, upper, value,
3463 array_elt_type, pre_p, cleared); 3448 array_elt_type, pre_p, cleared);
3464 continue; 3449 continue;
3465 } 3450 }
3466 } 3451 }
3467 3452
3468 if (array_elt_type) 3453 if (array_elt_type)
3469 { 3454 {
3470 /* Do not use bitsizetype for ARRAY_REF indices. */ 3455 /* Do not use bitsizetype for ARRAY_REF indices. */
3471 if (TYPE_DOMAIN (TREE_TYPE (object))) 3456 if (TYPE_DOMAIN (TREE_TYPE (object)))
3472 purpose = fold_convert (TREE_TYPE (TYPE_DOMAIN (TREE_TYPE (object))), 3457 purpose = fold_convert (TREE_TYPE (TYPE_DOMAIN (TREE_TYPE (object))),
3473 purpose); 3458 purpose);
3474 cref = build4 (ARRAY_REF, array_elt_type, unshare_expr (object), 3459 cref = build4 (ARRAY_REF, array_elt_type, unshare_expr (object),
3475 purpose, NULL_TREE, NULL_TREE); 3460 purpose, NULL_TREE, NULL_TREE);
3476 } 3461 }
3477 else 3462 else
3478 { 3463 {
3479 gcc_assert (TREE_CODE (purpose) == FIELD_DECL); 3464 gcc_assert (TREE_CODE (purpose) == FIELD_DECL);
3480 cref = build3 (COMPONENT_REF, TREE_TYPE (purpose), 3465 cref = build3 (COMPONENT_REF, TREE_TYPE (purpose),
3481 unshare_expr (object), purpose, NULL_TREE); 3466 unshare_expr (object), purpose, NULL_TREE);
3482 } 3467 }
3483 3468
3484 if (TREE_CODE (value) == CONSTRUCTOR 3469 if (TREE_CODE (value) == CONSTRUCTOR
3485 && TREE_CODE (TREE_TYPE (value)) != VECTOR_TYPE) 3470 && TREE_CODE (TREE_TYPE (value)) != VECTOR_TYPE)
3486 gimplify_init_ctor_eval (cref, CONSTRUCTOR_ELTS (value), 3471 gimplify_init_ctor_eval (cref, CONSTRUCTOR_ELTS (value),
3487 pre_p, cleared); 3472 pre_p, cleared);
3488 else 3473 else
3489 { 3474 {
3490 tree init = build2 (INIT_EXPR, TREE_TYPE (cref), cref, value); 3475 tree init = build2 (INIT_EXPR, TREE_TYPE (cref), cref, value);
3491 gimplify_and_add (init, pre_p); 3476 gimplify_and_add (init, pre_p);
3492 ggc_free (init); 3477 ggc_free (init);
3493 } 3478 }
3494 } 3479 }
3495 } 3480 }
3496 3481
3497 3482
3498 /* Returns the appropriate RHS predicate for this LHS. */ 3483 /* Returns the appropriate RHS predicate for this LHS. */
3499 3484
3500 gimple_predicate 3485 gimple_predicate
3501 rhs_predicate_for (tree lhs) 3486 rhs_predicate_for (tree lhs)
3502 { 3487 {
3503 if (is_gimple_formal_tmp_var (lhs)) 3488 if (is_gimple_reg (lhs))
3504 return is_gimple_formal_tmp_or_call_rhs; 3489 return is_gimple_reg_rhs_or_call;
3505 else if (is_gimple_reg (lhs))
3506 return is_gimple_reg_or_call_rhs;
3507 else 3490 else
3508 return is_gimple_mem_or_call_rhs; 3491 return is_gimple_mem_rhs_or_call;
3509 } 3492 }
3493
3494 /* Gimplify a C99 compound literal expression. This just means adding
3495 the DECL_EXPR before the current statement and using its anonymous
3496 decl instead. */
3497
3498 static enum gimplify_status
3499 gimplify_compound_literal_expr (tree *expr_p, gimple_seq *pre_p)
3500 {
3501 tree decl_s = COMPOUND_LITERAL_EXPR_DECL_EXPR (*expr_p);
3502 tree decl = DECL_EXPR_DECL (decl_s);
3503 /* Mark the decl as addressable if the compound literal
3504 expression is addressable now, otherwise it is marked too late
3505 after we gimplify the initialization expression. */
3506 if (TREE_ADDRESSABLE (*expr_p))
3507 TREE_ADDRESSABLE (decl) = 1;
3508
3509 /* Preliminarily mark non-addressed complex variables as eligible
3510 for promotion to gimple registers. We'll transform their uses
3511 as we find them. */
3512 if ((TREE_CODE (TREE_TYPE (decl)) == COMPLEX_TYPE
3513 || TREE_CODE (TREE_TYPE (decl)) == VECTOR_TYPE)
3514 && !TREE_THIS_VOLATILE (decl)
3515 && !needs_to_live_in_memory (decl))
3516 DECL_GIMPLE_REG_P (decl) = 1;
3517
3518 /* This decl isn't mentioned in the enclosing block, so add it to the
3519 list of temps. FIXME it seems a bit of a kludge to say that
3520 anonymous artificial vars aren't pushed, but everything else is. */
3521 if (DECL_NAME (decl) == NULL_TREE && !DECL_SEEN_IN_BIND_EXPR_P (decl))
3522 gimple_add_tmp_var (decl);
3523
3524 gimplify_and_add (decl_s, pre_p);
3525 *expr_p = decl;
3526 return GS_OK;
3527 }
3528
3529 /* Optimize embedded COMPOUND_LITERAL_EXPRs within a CONSTRUCTOR,
3530 return a new CONSTRUCTOR if something changed. */
3531
3532 static tree
3533 optimize_compound_literals_in_ctor (tree orig_ctor)
3534 {
3535 tree ctor = orig_ctor;
3536 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (ctor);
3537 unsigned int idx, num = VEC_length (constructor_elt, elts);
3538
3539 for (idx = 0; idx < num; idx++)
3540 {
3541 tree value = VEC_index (constructor_elt, elts, idx)->value;
3542 tree newval = value;
3543 if (TREE_CODE (value) == CONSTRUCTOR)
3544 newval = optimize_compound_literals_in_ctor (value);
3545 else if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR)
3546 {
3547 tree decl_s = COMPOUND_LITERAL_EXPR_DECL_EXPR (value);
3548 tree decl = DECL_EXPR_DECL (decl_s);
3549 tree init = DECL_INITIAL (decl);
3550
3551 if (!TREE_ADDRESSABLE (value)
3552 && !TREE_ADDRESSABLE (decl)
3553 && init)
3554 newval = optimize_compound_literals_in_ctor (init);
3555 }
3556 if (newval == value)
3557 continue;
3558
3559 if (ctor == orig_ctor)
3560 {
3561 ctor = copy_node (orig_ctor);
3562 CONSTRUCTOR_ELTS (ctor) = VEC_copy (constructor_elt, gc, elts);
3563 elts = CONSTRUCTOR_ELTS (ctor);
3564 }
3565 VEC_index (constructor_elt, elts, idx)->value = newval;
3566 }
3567 return ctor;
3568 }
3569
3510 3570
3511 3571
3512 /* A subroutine of gimplify_modify_expr. Break out elements of a 3572 /* A subroutine of gimplify_modify_expr. Break out elements of a
3513 CONSTRUCTOR used as an initializer into separate MODIFY_EXPRs. 3573 CONSTRUCTOR used as an initializer into separate MODIFY_EXPRs.
3514 3574
3522 3582
3523 If NOTIFY_TEMP_CREATION is false, just do the gimplification. */ 3583 If NOTIFY_TEMP_CREATION is false, just do the gimplification. */
3524 3584
3525 static enum gimplify_status 3585 static enum gimplify_status
3526 gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, 3586 gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
3527 bool want_value, bool notify_temp_creation) 3587 bool want_value, bool notify_temp_creation)
3528 { 3588 {
3529 tree object; 3589 tree object, ctor, type;
3530 tree ctor = TREE_OPERAND (*expr_p, 1);
3531 tree type = TREE_TYPE (ctor);
3532 enum gimplify_status ret; 3590 enum gimplify_status ret;
3533 VEC(constructor_elt,gc) *elts; 3591 VEC(constructor_elt,gc) *elts;
3534 3592
3535 if (TREE_CODE (ctor) != CONSTRUCTOR) 3593 gcc_assert (TREE_CODE (TREE_OPERAND (*expr_p, 1)) == CONSTRUCTOR);
3536 return GS_UNHANDLED;
3537 3594
3538 if (!notify_temp_creation) 3595 if (!notify_temp_creation)
3539 { 3596 {
3540 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p, 3597 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
3541 is_gimple_lvalue, fb_lvalue); 3598 is_gimple_lvalue, fb_lvalue);
3542 if (ret == GS_ERROR) 3599 if (ret == GS_ERROR)
3543 return ret; 3600 return ret;
3544 } 3601 }
3545 3602
3546 object = TREE_OPERAND (*expr_p, 0); 3603 object = TREE_OPERAND (*expr_p, 0);
3604 ctor = TREE_OPERAND (*expr_p, 1) =
3605 optimize_compound_literals_in_ctor (TREE_OPERAND (*expr_p, 1));
3606 type = TREE_TYPE (ctor);
3547 elts = CONSTRUCTOR_ELTS (ctor); 3607 elts = CONSTRUCTOR_ELTS (ctor);
3548 ret = GS_ALL_DONE; 3608 ret = GS_ALL_DONE;
3549 3609
3550 switch (TREE_CODE (type)) 3610 switch (TREE_CODE (type))
3551 { 3611 {
3552 case RECORD_TYPE: 3612 case RECORD_TYPE:
3553 case UNION_TYPE: 3613 case UNION_TYPE:
3554 case QUAL_UNION_TYPE: 3614 case QUAL_UNION_TYPE:
3555 case ARRAY_TYPE: 3615 case ARRAY_TYPE:
3556 { 3616 {
3557 struct gimplify_init_ctor_preeval_data preeval_data; 3617 struct gimplify_init_ctor_preeval_data preeval_data;
3558 HOST_WIDE_INT num_type_elements, num_ctor_elements; 3618 HOST_WIDE_INT num_type_elements, num_ctor_elements;
3559 HOST_WIDE_INT num_nonzero_elements; 3619 HOST_WIDE_INT num_nonzero_elements;
3560 bool cleared, valid_const_initializer; 3620 bool cleared, valid_const_initializer;
3561 3621
3562 /* Aggregate types must lower constructors to initialization of 3622 /* Aggregate types must lower constructors to initialization of
3563 individual elements. The exception is that a CONSTRUCTOR node 3623 individual elements. The exception is that a CONSTRUCTOR node
3564 with no elements indicates zero-initialization of the whole. */ 3624 with no elements indicates zero-initialization of the whole. */
3565 if (VEC_empty (constructor_elt, elts)) 3625 if (VEC_empty (constructor_elt, elts))
3566 { 3626 {
3567 if (notify_temp_creation) 3627 if (notify_temp_creation)
3568 return GS_OK; 3628 return GS_OK;
3569 break; 3629 break;
3570 } 3630 }
3571 3631
3572 /* Fetch information about the constructor to direct later processing. 3632 /* Fetch information about the constructor to direct later processing.
3573 We might want to make static versions of it in various cases, and 3633 We might want to make static versions of it in various cases, and
3574 can only do so if it known to be a valid constant initializer. */ 3634 can only do so if it known to be a valid constant initializer. */
3575 valid_const_initializer 3635 valid_const_initializer
3576 = categorize_ctor_elements (ctor, &num_nonzero_elements, 3636 = categorize_ctor_elements (ctor, &num_nonzero_elements,
3577 &num_ctor_elements, &cleared); 3637 &num_ctor_elements, &cleared);
3578 3638
3579 /* If a const aggregate variable is being initialized, then it 3639 /* If a const aggregate variable is being initialized, then it
3580 should never be a lose to promote the variable to be static. */ 3640 should never be a lose to promote the variable to be static. */
3581 if (valid_const_initializer 3641 if (valid_const_initializer
3582 && num_nonzero_elements > 1 3642 && num_nonzero_elements > 1
3583 && TREE_READONLY (object) 3643 && TREE_READONLY (object)
3584 && TREE_CODE (object) == VAR_DECL 3644 && TREE_CODE (object) == VAR_DECL
3585 && (flag_merge_constants >= 2 || !TREE_ADDRESSABLE (object))) 3645 && (flag_merge_constants >= 2 || !TREE_ADDRESSABLE (object)))
3586 { 3646 {
3587 if (notify_temp_creation) 3647 if (notify_temp_creation)
3588 return GS_ERROR; 3648 return GS_ERROR;
3589 DECL_INITIAL (object) = ctor; 3649 DECL_INITIAL (object) = ctor;
3590 TREE_STATIC (object) = 1; 3650 TREE_STATIC (object) = 1;
3591 if (!DECL_NAME (object)) 3651 if (!DECL_NAME (object))
3592 DECL_NAME (object) = create_tmp_var_name ("C"); 3652 DECL_NAME (object) = create_tmp_var_name ("C");
3593 walk_tree (&DECL_INITIAL (object), force_labels_r, NULL, NULL); 3653 walk_tree (&DECL_INITIAL (object), force_labels_r, NULL, NULL);
3594 3654
3595 /* ??? C++ doesn't automatically append a .<number> to the 3655 /* ??? C++ doesn't automatically append a .<number> to the
3596 assembler name, and even when it does, it looks a FE private 3656 assembler name, and even when it does, it looks a FE private
3597 data structures to figure out what that number should be, 3657 data structures to figure out what that number should be,
3598 which are not set for this variable. I suppose this is 3658 which are not set for this variable. I suppose this is
3599 important for local statics for inline functions, which aren't 3659 important for local statics for inline functions, which aren't
3600 "local" in the object file sense. So in order to get a unique 3660 "local" in the object file sense. So in order to get a unique
3601 TU-local symbol, we must invoke the lhd version now. */ 3661 TU-local symbol, we must invoke the lhd version now. */
3602 lhd_set_decl_assembler_name (object); 3662 lhd_set_decl_assembler_name (object);
3603 3663
3604 *expr_p = NULL_TREE; 3664 *expr_p = NULL_TREE;
3605 break; 3665 break;
3606 } 3666 }
3607 3667
3608 /* If there are "lots" of initialized elements, even discounting 3668 /* If there are "lots" of initialized elements, even discounting
3609 those that are not address constants (and thus *must* be 3669 those that are not address constants (and thus *must* be
3610 computed at runtime), then partition the constructor into 3670 computed at runtime), then partition the constructor into
3611 constant and non-constant parts. Block copy the constant 3671 constant and non-constant parts. Block copy the constant
3612 parts in, then generate code for the non-constant parts. */ 3672 parts in, then generate code for the non-constant parts. */
3613 /* TODO. There's code in cp/typeck.c to do this. */ 3673 /* TODO. There's code in cp/typeck.c to do this. */
3614 3674
3615 num_type_elements = count_type_elements (type, true); 3675 num_type_elements = count_type_elements (type, true);
3616 3676
3617 /* If count_type_elements could not determine number of type elements 3677 /* If count_type_elements could not determine number of type elements
3618 for a constant-sized object, assume clearing is needed. 3678 for a constant-sized object, assume clearing is needed.
3619 Don't do this for variable-sized objects, as store_constructor 3679 Don't do this for variable-sized objects, as store_constructor
3620 will ignore the clearing of variable-sized objects. */ 3680 will ignore the clearing of variable-sized objects. */
3621 if (num_type_elements < 0 && int_size_in_bytes (type) >= 0) 3681 if (num_type_elements < 0 && int_size_in_bytes (type) >= 0)
3622 cleared = true; 3682 cleared = true;
3623 /* If there are "lots" of zeros, then block clear the object first. */ 3683 /* If there are "lots" of zeros, then block clear the object first. */
3624 else if (num_type_elements - num_nonzero_elements 3684 else if (num_type_elements - num_nonzero_elements
3625 > CLEAR_RATIO (optimize_function_for_speed_p (cfun)) 3685 > CLEAR_RATIO (optimize_function_for_speed_p (cfun))
3626 && num_nonzero_elements < num_type_elements/4) 3686 && num_nonzero_elements < num_type_elements/4)
3627 cleared = true; 3687 cleared = true;
3628 /* ??? This bit ought not be needed. For any element not present 3688 /* ??? This bit ought not be needed. For any element not present
3629 in the initializer, we should simply set them to zero. Except 3689 in the initializer, we should simply set them to zero. Except
3630 we'd need to *find* the elements that are not present, and that 3690 we'd need to *find* the elements that are not present, and that
3631 requires trickery to avoid quadratic compile-time behavior in 3691 requires trickery to avoid quadratic compile-time behavior in
3632 large cases or excessive memory use in small cases. */ 3692 large cases or excessive memory use in small cases. */
3633 else if (num_ctor_elements < num_type_elements) 3693 else if (num_ctor_elements < num_type_elements)
3634 cleared = true; 3694 cleared = true;
3635 3695
3636 /* If there are "lots" of initialized elements, and all of them 3696 /* If there are "lots" of initialized elements, and all of them
3637 are valid address constants, then the entire initializer can 3697 are valid address constants, then the entire initializer can
3638 be dropped to memory, and then memcpy'd out. Don't do this 3698 be dropped to memory, and then memcpy'd out. Don't do this
3639 for sparse arrays, though, as it's more efficient to follow 3699 for sparse arrays, though, as it's more efficient to follow
3640 the standard CONSTRUCTOR behavior of memset followed by 3700 the standard CONSTRUCTOR behavior of memset followed by
3641 individual element initialization. Also don't do this for small 3701 individual element initialization. Also don't do this for small
3642 all-zero initializers (which aren't big enough to merit 3702 all-zero initializers (which aren't big enough to merit
3643 clearing), and don't try to make bitwise copies of 3703 clearing), and don't try to make bitwise copies of
3644 TREE_ADDRESSABLE types. */ 3704 TREE_ADDRESSABLE types. */
3645 if (valid_const_initializer 3705 if (valid_const_initializer
3646 && !(cleared || num_nonzero_elements == 0) 3706 && !(cleared || num_nonzero_elements == 0)
3647 && !TREE_ADDRESSABLE (type)) 3707 && !TREE_ADDRESSABLE (type))
3648 { 3708 {
3649 HOST_WIDE_INT size = int_size_in_bytes (type); 3709 HOST_WIDE_INT size = int_size_in_bytes (type);
3650 unsigned int align; 3710 unsigned int align;
3651 3711
3652 /* ??? We can still get unbounded array types, at least 3712 /* ??? We can still get unbounded array types, at least
3653 from the C++ front end. This seems wrong, but attempt 3713 from the C++ front end. This seems wrong, but attempt
3654 to work around it for now. */ 3714 to work around it for now. */
3655 if (size < 0) 3715 if (size < 0)
3656 { 3716 {
3657 size = int_size_in_bytes (TREE_TYPE (object)); 3717 size = int_size_in_bytes (TREE_TYPE (object));
3658 if (size >= 0) 3718 if (size >= 0)
3659 TREE_TYPE (ctor) = type = TREE_TYPE (object); 3719 TREE_TYPE (ctor) = type = TREE_TYPE (object);
3660 } 3720 }
3661 3721
3662 /* Find the maximum alignment we can assume for the object. */ 3722 /* Find the maximum alignment we can assume for the object. */
3663 /* ??? Make use of DECL_OFFSET_ALIGN. */ 3723 /* ??? Make use of DECL_OFFSET_ALIGN. */
3664 if (DECL_P (object)) 3724 if (DECL_P (object))
3665 align = DECL_ALIGN (object); 3725 align = DECL_ALIGN (object);
3666 else 3726 else
3667 align = TYPE_ALIGN (type); 3727 align = TYPE_ALIGN (type);
3668 3728
3669 if (size > 0 3729 if (size > 0
3670 && num_nonzero_elements > 1 3730 && num_nonzero_elements > 1
3671 && !can_move_by_pieces (size, align)) 3731 && !can_move_by_pieces (size, align))
3672 { 3732 {
3673 tree new_tree; 3733 tree new_tree;
3674 3734
3675 if (notify_temp_creation) 3735 if (notify_temp_creation)
3676 return GS_ERROR; 3736 return GS_ERROR;
3677 3737
3678 new_tree = create_tmp_var_raw (type, "C"); 3738 new_tree = create_tmp_var_raw (type, "C");
3679 3739
3680 gimple_add_tmp_var (new_tree); 3740 gimple_add_tmp_var (new_tree);
3681 TREE_STATIC (new_tree) = 1; 3741 TREE_STATIC (new_tree) = 1;
3682 TREE_READONLY (new_tree) = 1; 3742 TREE_READONLY (new_tree) = 1;
3683 DECL_INITIAL (new_tree) = ctor; 3743 DECL_INITIAL (new_tree) = ctor;
3684 if (align > DECL_ALIGN (new_tree)) 3744 if (align > DECL_ALIGN (new_tree))
3685 { 3745 {
3686 DECL_ALIGN (new_tree) = align; 3746 DECL_ALIGN (new_tree) = align;
3687 DECL_USER_ALIGN (new_tree) = 1; 3747 DECL_USER_ALIGN (new_tree) = 1;
3688 } 3748 }
3689 walk_tree (&DECL_INITIAL (new_tree), force_labels_r, NULL, NULL); 3749 walk_tree (&DECL_INITIAL (new_tree), force_labels_r, NULL, NULL);
3690 3750
3691 TREE_OPERAND (*expr_p, 1) = new_tree; 3751 TREE_OPERAND (*expr_p, 1) = new_tree;
3692 3752
3693 /* This is no longer an assignment of a CONSTRUCTOR, but 3753 /* This is no longer an assignment of a CONSTRUCTOR, but
3694 we still may have processing to do on the LHS. So 3754 we still may have processing to do on the LHS. So
3695 pretend we didn't do anything here to let that happen. */ 3755 pretend we didn't do anything here to let that happen. */
3696 return GS_UNHANDLED; 3756 return GS_UNHANDLED;
3697 } 3757 }
3698 } 3758 }
3699 3759
3700 if (notify_temp_creation) 3760 if (notify_temp_creation)
3701 return GS_OK; 3761 return GS_OK;
3702 3762
3703 /* If there are nonzero elements, pre-evaluate to capture elements 3763 /* If there are nonzero elements, pre-evaluate to capture elements
3704 overlapping with the lhs into temporaries. We must do this before 3764 overlapping with the lhs into temporaries. We must do this before
3705 clearing to fetch the values before they are zeroed-out. */ 3765 clearing to fetch the values before they are zeroed-out. */
3706 if (num_nonzero_elements > 0) 3766 if (num_nonzero_elements > 0)
3707 { 3767 {
3708 preeval_data.lhs_base_decl = get_base_address (object); 3768 preeval_data.lhs_base_decl = get_base_address (object);
3709 if (!DECL_P (preeval_data.lhs_base_decl)) 3769 if (!DECL_P (preeval_data.lhs_base_decl))
3710 preeval_data.lhs_base_decl = NULL; 3770 preeval_data.lhs_base_decl = NULL;
3711 preeval_data.lhs_alias_set = get_alias_set (object); 3771 preeval_data.lhs_alias_set = get_alias_set (object);
3712 3772
3713 gimplify_init_ctor_preeval (&TREE_OPERAND (*expr_p, 1), 3773 gimplify_init_ctor_preeval (&TREE_OPERAND (*expr_p, 1),
3714 pre_p, post_p, &preeval_data); 3774 pre_p, post_p, &preeval_data);
3715 } 3775 }
3716 3776
3717 if (cleared) 3777 if (cleared)
3718 { 3778 {
3719 /* Zap the CONSTRUCTOR element list, which simplifies this case. 3779 /* Zap the CONSTRUCTOR element list, which simplifies this case.
3720 Note that we still have to gimplify, in order to handle the 3780 Note that we still have to gimplify, in order to handle the
3721 case of variable sized types. Avoid shared tree structures. */ 3781 case of variable sized types. Avoid shared tree structures. */
3722 CONSTRUCTOR_ELTS (ctor) = NULL; 3782 CONSTRUCTOR_ELTS (ctor) = NULL;
3723 TREE_SIDE_EFFECTS (ctor) = 0; 3783 TREE_SIDE_EFFECTS (ctor) = 0;
3724 object = unshare_expr (object); 3784 object = unshare_expr (object);
3725 gimplify_stmt (expr_p, pre_p); 3785 gimplify_stmt (expr_p, pre_p);
3726 } 3786 }
3727 3787
3728 /* If we have not block cleared the object, or if there are nonzero 3788 /* If we have not block cleared the object, or if there are nonzero
3729 elements in the constructor, add assignments to the individual 3789 elements in the constructor, add assignments to the individual
3730 scalar fields of the object. */ 3790 scalar fields of the object. */
3731 if (!cleared || num_nonzero_elements > 0) 3791 if (!cleared || num_nonzero_elements > 0)
3732 gimplify_init_ctor_eval (object, elts, pre_p, cleared); 3792 gimplify_init_ctor_eval (object, elts, pre_p, cleared);
3733 3793
3734 *expr_p = NULL_TREE; 3794 *expr_p = NULL_TREE;
3735 } 3795 }
3736 break; 3796 break;
3737 3797
3738 case COMPLEX_TYPE: 3798 case COMPLEX_TYPE:
3739 { 3799 {
3740 tree r, i; 3800 tree r, i;
3741 3801
3742 if (notify_temp_creation) 3802 if (notify_temp_creation)
3743 return GS_OK; 3803 return GS_OK;
3744 3804
3745 /* Extract the real and imaginary parts out of the ctor. */ 3805 /* Extract the real and imaginary parts out of the ctor. */
3746 gcc_assert (VEC_length (constructor_elt, elts) == 2); 3806 gcc_assert (VEC_length (constructor_elt, elts) == 2);
3747 r = VEC_index (constructor_elt, elts, 0)->value; 3807 r = VEC_index (constructor_elt, elts, 0)->value;
3748 i = VEC_index (constructor_elt, elts, 1)->value; 3808 i = VEC_index (constructor_elt, elts, 1)->value;
3749 if (r == NULL || i == NULL) 3809 if (r == NULL || i == NULL)
3750 { 3810 {
3751 tree zero = fold_convert (TREE_TYPE (type), integer_zero_node); 3811 tree zero = fold_convert (TREE_TYPE (type), integer_zero_node);
3752 if (r == NULL) 3812 if (r == NULL)
3753 r = zero; 3813 r = zero;
3754 if (i == NULL) 3814 if (i == NULL)
3755 i = zero; 3815 i = zero;
3756 } 3816 }
3757 3817
3758 /* Complex types have either COMPLEX_CST or COMPLEX_EXPR to 3818 /* Complex types have either COMPLEX_CST or COMPLEX_EXPR to
3759 represent creation of a complex value. */ 3819 represent creation of a complex value. */
3760 if (TREE_CONSTANT (r) && TREE_CONSTANT (i)) 3820 if (TREE_CONSTANT (r) && TREE_CONSTANT (i))
3761 { 3821 {
3762 ctor = build_complex (type, r, i); 3822 ctor = build_complex (type, r, i);
3763 TREE_OPERAND (*expr_p, 1) = ctor; 3823 TREE_OPERAND (*expr_p, 1) = ctor;
3764 } 3824 }
3765 else 3825 else
3766 { 3826 {
3767 ctor = build2 (COMPLEX_EXPR, type, r, i); 3827 ctor = build2 (COMPLEX_EXPR, type, r, i);
3768 TREE_OPERAND (*expr_p, 1) = ctor; 3828 TREE_OPERAND (*expr_p, 1) = ctor;
3769 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 1), 3829 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 1),
3770 pre_p, 3830 pre_p,
3771 post_p, 3831 post_p,
3772 rhs_predicate_for (TREE_OPERAND (*expr_p, 0)), 3832 rhs_predicate_for (TREE_OPERAND (*expr_p, 0)),
3773 fb_rvalue); 3833 fb_rvalue);
3774 } 3834 }
3775 } 3835 }
3776 break; 3836 break;
3777 3837
3778 case VECTOR_TYPE: 3838 case VECTOR_TYPE:
3779 { 3839 {
3780 unsigned HOST_WIDE_INT ix; 3840 unsigned HOST_WIDE_INT ix;
3781 constructor_elt *ce; 3841 constructor_elt *ce;
3782 3842
3783 if (notify_temp_creation) 3843 if (notify_temp_creation)
3784 return GS_OK; 3844 return GS_OK;
3785 3845
3786 /* Go ahead and simplify constant constructors to VECTOR_CST. */ 3846 /* Go ahead and simplify constant constructors to VECTOR_CST. */
3787 if (TREE_CONSTANT (ctor)) 3847 if (TREE_CONSTANT (ctor))
3788 { 3848 {
3789 bool constant_p = true; 3849 bool constant_p = true;
3790 tree value; 3850 tree value;
3791 3851
3792 /* Even when ctor is constant, it might contain non-*_CST 3852 /* Even when ctor is constant, it might contain non-*_CST
3793 elements, such as addresses or trapping values like 3853 elements, such as addresses or trapping values like
3794 1.0/0.0 - 1.0/0.0. Such expressions don't belong 3854 1.0/0.0 - 1.0/0.0. Such expressions don't belong
3795 in VECTOR_CST nodes. */ 3855 in VECTOR_CST nodes. */
3796 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value) 3856 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
3797 if (!CONSTANT_CLASS_P (value)) 3857 if (!CONSTANT_CLASS_P (value))
3798 { 3858 {
3799 constant_p = false; 3859 constant_p = false;
3800 break; 3860 break;
3801 } 3861 }
3802 3862
3803 if (constant_p) 3863 if (constant_p)
3804 { 3864 {
3805 TREE_OPERAND (*expr_p, 1) = build_vector_from_ctor (type, elts); 3865 TREE_OPERAND (*expr_p, 1) = build_vector_from_ctor (type, elts);
3806 break; 3866 break;
3807 } 3867 }
3808 3868
3809 /* Don't reduce an initializer constant even if we can't 3869 /* Don't reduce an initializer constant even if we can't
3810 make a VECTOR_CST. It won't do anything for us, and it'll 3870 make a VECTOR_CST. It won't do anything for us, and it'll
3811 prevent us from representing it as a single constant. */ 3871 prevent us from representing it as a single constant. */
3812 if (initializer_constant_valid_p (ctor, type)) 3872 if (initializer_constant_valid_p (ctor, type))
3813 break; 3873 break;
3814 3874
3815 TREE_CONSTANT (ctor) = 0; 3875 TREE_CONSTANT (ctor) = 0;
3816 } 3876 }
3817 3877
3818 /* Vector types use CONSTRUCTOR all the way through gimple 3878 /* Vector types use CONSTRUCTOR all the way through gimple
3819 compilation as a general initializer. */ 3879 compilation as a general initializer. */
3820 for (ix = 0; VEC_iterate (constructor_elt, elts, ix, ce); ix++) 3880 for (ix = 0; VEC_iterate (constructor_elt, elts, ix, ce); ix++)
3821 { 3881 {
3822 enum gimplify_status tret; 3882 enum gimplify_status tret;
3823 tret = gimplify_expr (&ce->value, pre_p, post_p, is_gimple_val, 3883 tret = gimplify_expr (&ce->value, pre_p, post_p, is_gimple_val,
3824 fb_rvalue); 3884 fb_rvalue);
3825 if (tret == GS_ERROR) 3885 if (tret == GS_ERROR)
3826 ret = GS_ERROR; 3886 ret = GS_ERROR;
3827 } 3887 }
3828 if (!is_gimple_reg (TREE_OPERAND (*expr_p, 0))) 3888 if (!is_gimple_reg (TREE_OPERAND (*expr_p, 0)))
3829 TREE_OPERAND (*expr_p, 1) = get_formal_tmp_var (ctor, pre_p); 3889 TREE_OPERAND (*expr_p, 1) = get_formal_tmp_var (ctor, pre_p);
3830 } 3890 }
3831 break; 3891 break;
3832 3892
3833 default: 3893 default:
3834 /* So how did we get a CONSTRUCTOR for a scalar type? */ 3894 /* So how did we get a CONSTRUCTOR for a scalar type? */
3843 return GS_OK; 3903 return GS_OK;
3844 } 3904 }
3845 else 3905 else
3846 { 3906 {
3847 /* If we have gimplified both sides of the initializer but have 3907 /* If we have gimplified both sides of the initializer but have
3848 not emitted an assignment, do so now. */ 3908 not emitted an assignment, do so now. */
3849 if (*expr_p) 3909 if (*expr_p)
3850 { 3910 {
3851 tree lhs = TREE_OPERAND (*expr_p, 0); 3911 tree lhs = TREE_OPERAND (*expr_p, 0);
3852 tree rhs = TREE_OPERAND (*expr_p, 1); 3912 tree rhs = TREE_OPERAND (*expr_p, 1);
3853 gimple init = gimple_build_assign (lhs, rhs); 3913 gimple init = gimple_build_assign (lhs, rhs);
3854 gimplify_seq_add_stmt (pre_p, init); 3914 gimplify_seq_add_stmt (pre_p, init);
3855 *expr_p = NULL; 3915 *expr_p = NULL;
3856 } 3916 }
3857 3917
3858 return GS_ALL_DONE; 3918 return GS_ALL_DONE;
3859 } 3919 }
3860 } 3920 }
3861 3921
3885 if (useless_type_conversion_p (type, optype)) 3945 if (useless_type_conversion_p (type, optype))
3886 return op; 3946 return op;
3887 3947
3888 /* *(foo *)&fooarray => fooarray[0] */ 3948 /* *(foo *)&fooarray => fooarray[0] */
3889 if (TREE_CODE (optype) == ARRAY_TYPE 3949 if (TREE_CODE (optype) == ARRAY_TYPE
3890 && useless_type_conversion_p (type, TREE_TYPE (optype))) 3950 && useless_type_conversion_p (type, TREE_TYPE (optype)))
3891 { 3951 {
3892 tree type_domain = TYPE_DOMAIN (optype); 3952 tree type_domain = TYPE_DOMAIN (optype);
3893 tree min_val = size_zero_node; 3953 tree min_val = size_zero_node;
3894 if (type_domain && TYPE_MIN_VALUE (type_domain)) 3954 if (type_domain && TYPE_MIN_VALUE (type_domain))
3895 min_val = TYPE_MIN_VALUE (type_domain); 3955 min_val = TYPE_MIN_VALUE (type_domain);
3904 tree type_domain; 3964 tree type_domain;
3905 tree min_val = size_zero_node; 3965 tree min_val = size_zero_node;
3906 tree osub = sub; 3966 tree osub = sub;
3907 sub = gimple_fold_indirect_ref (sub); 3967 sub = gimple_fold_indirect_ref (sub);
3908 if (! sub) 3968 if (! sub)
3909 sub = build1 (INDIRECT_REF, TREE_TYPE (subtype), osub); 3969 sub = build1 (INDIRECT_REF, TREE_TYPE (subtype), osub);
3910 type_domain = TYPE_DOMAIN (TREE_TYPE (sub)); 3970 type_domain = TYPE_DOMAIN (TREE_TYPE (sub));
3911 if (type_domain && TYPE_MIN_VALUE (type_domain)) 3971 if (type_domain && TYPE_MIN_VALUE (type_domain))
3912 min_val = TYPE_MIN_VALUE (type_domain); 3972 min_val = TYPE_MIN_VALUE (type_domain);
3913 return build4 (ARRAY_REF, type, sub, min_val, NULL_TREE, NULL_TREE); 3973 return build4 (ARRAY_REF, type, sub, min_val, NULL_TREE, NULL_TREE);
3914 } 3974 }
3933 MODIFY_EXPRs based on the code of the RHS. We loop for as long as 3993 MODIFY_EXPRs based on the code of the RHS. We loop for as long as
3934 something changes. */ 3994 something changes. */
3935 3995
3936 static enum gimplify_status 3996 static enum gimplify_status
3937 gimplify_modify_expr_rhs (tree *expr_p, tree *from_p, tree *to_p, 3997 gimplify_modify_expr_rhs (tree *expr_p, tree *from_p, tree *to_p,
3938 gimple_seq *pre_p, gimple_seq *post_p, 3998 gimple_seq *pre_p, gimple_seq *post_p,
3939 bool want_value) 3999 bool want_value)
3940 { 4000 {
3941 enum gimplify_status ret = GS_OK; 4001 enum gimplify_status ret = GS_OK;
3942 4002
3943 while (ret != GS_UNHANDLED) 4003 while (ret != GS_UNHANDLED)
3944 switch (TREE_CODE (*from_p)) 4004 switch (TREE_CODE (*from_p))
3945 { 4005 {
3946 case VAR_DECL: 4006 case VAR_DECL:
3947 /* If we're assigning from a constant constructor, move the 4007 /* If we're assigning from a read-only variable initialized with
3948 constructor expression to the RHS of the MODIFY_EXPR. */ 4008 a constructor, do the direct assignment from the constructor,
3949 if (DECL_INITIAL (*from_p) 4009 but only if neither source nor target are volatile since this
3950 && TREE_READONLY (*from_p) 4010 latter assignment might end up being done on a per-field basis. */
3951 && !TREE_THIS_VOLATILE (*from_p) 4011 if (DECL_INITIAL (*from_p)
3952 && TREE_CODE (DECL_INITIAL (*from_p)) == CONSTRUCTOR) 4012 && TREE_READONLY (*from_p)
3953 { 4013 && !TREE_THIS_VOLATILE (*from_p)
3954 tree old_from = *from_p; 4014 && !TREE_THIS_VOLATILE (*to_p)
3955 4015 && TREE_CODE (DECL_INITIAL (*from_p)) == CONSTRUCTOR)
3956 /* Move the constructor into the RHS. */ 4016 {
3957 *from_p = unshare_expr (DECL_INITIAL (*from_p)); 4017 tree old_from = *from_p;
3958 4018
3959 /* Let's see if gimplify_init_constructor will need to put 4019 /* Move the constructor into the RHS. */
3960 it in memory. If so, revert the change. */ 4020 *from_p = unshare_expr (DECL_INITIAL (*from_p));
3961 ret = gimplify_init_constructor (expr_p, NULL, NULL, false, true); 4021
3962 if (ret == GS_ERROR) 4022 /* Let's see if gimplify_init_constructor will need to put
3963 { 4023 it in memory. If so, revert the change. */
3964 *from_p = old_from; 4024 ret = gimplify_init_constructor (expr_p, NULL, NULL, false, true);
3965 /* Fall through. */ 4025 if (ret == GS_ERROR)
3966 } 4026 {
3967 else 4027 *from_p = old_from;
3968 { 4028 /* Fall through. */
3969 ret = GS_OK; 4029 }
3970 break; 4030 else
3971 } 4031 {
3972 } 4032 ret = GS_OK;
3973 ret = GS_UNHANDLED; 4033 break;
3974 break; 4034 }
4035 }
4036 ret = GS_UNHANDLED;
4037 break;
3975 case INDIRECT_REF: 4038 case INDIRECT_REF:
3976 { 4039 {
3977 /* If we have code like 4040 /* If we have code like
3978 4041
3979 *(const A*)(A*)&x 4042 *(const A*)(A*)&x
3980 4043
3981 where the type of "x" is a (possibly cv-qualified variant 4044 where the type of "x" is a (possibly cv-qualified variant
3982 of "A"), treat the entire expression as identical to "x". 4045 of "A"), treat the entire expression as identical to "x".
3983 This kind of code arises in C++ when an object is bound 4046 This kind of code arises in C++ when an object is bound
3984 to a const reference, and if "x" is a TARGET_EXPR we want 4047 to a const reference, and if "x" is a TARGET_EXPR we want
3985 to take advantage of the optimization below. */ 4048 to take advantage of the optimization below. */
3986 tree t = gimple_fold_indirect_ref_rhs (TREE_OPERAND (*from_p, 0)); 4049 tree t = gimple_fold_indirect_ref_rhs (TREE_OPERAND (*from_p, 0));
3987 if (t) 4050 if (t)
3988 { 4051 {
3989 *from_p = t; 4052 *from_p = t;
3990 ret = GS_OK; 4053 ret = GS_OK;
3991 } 4054 }
3992 else 4055 else
3993 ret = GS_UNHANDLED; 4056 ret = GS_UNHANDLED;
3994 break; 4057 break;
3995 } 4058 }
3996 4059
3997 case TARGET_EXPR: 4060 case TARGET_EXPR:
3998 { 4061 {
3999 /* If we are initializing something from a TARGET_EXPR, strip the 4062 /* If we are initializing something from a TARGET_EXPR, strip the
4000 TARGET_EXPR and initialize it directly, if possible. This can't 4063 TARGET_EXPR and initialize it directly, if possible. This can't
4001 be done if the initializer is void, since that implies that the 4064 be done if the initializer is void, since that implies that the
4002 temporary is set in some non-trivial way. 4065 temporary is set in some non-trivial way.
4003 4066
4004 ??? What about code that pulls out the temp and uses it 4067 ??? What about code that pulls out the temp and uses it
4005 elsewhere? I think that such code never uses the TARGET_EXPR as 4068 elsewhere? I think that such code never uses the TARGET_EXPR as
4006 an initializer. If I'm wrong, we'll die because the temp won't 4069 an initializer. If I'm wrong, we'll die because the temp won't
4007 have any RTL. In that case, I guess we'll need to replace 4070 have any RTL. In that case, I guess we'll need to replace
4008 references somehow. */ 4071 references somehow. */
4009 tree init = TARGET_EXPR_INITIAL (*from_p); 4072 tree init = TARGET_EXPR_INITIAL (*from_p);
4010 4073
4011 if (init 4074 if (init
4012 && !VOID_TYPE_P (TREE_TYPE (init))) 4075 && !VOID_TYPE_P (TREE_TYPE (init)))
4013 { 4076 {
4014 *from_p = init; 4077 *from_p = init;
4015 ret = GS_OK; 4078 ret = GS_OK;
4016 } 4079 }
4017 else 4080 else
4018 ret = GS_UNHANDLED; 4081 ret = GS_UNHANDLED;
4019 } 4082 }
4020 break; 4083 break;
4021 4084
4022 case COMPOUND_EXPR: 4085 case COMPOUND_EXPR:
4023 /* Remove any COMPOUND_EXPR in the RHS so the following cases will be 4086 /* Remove any COMPOUND_EXPR in the RHS so the following cases will be
4024 caught. */ 4087 caught. */
4025 gimplify_compound_expr (from_p, pre_p, true); 4088 gimplify_compound_expr (from_p, pre_p, true);
4026 ret = GS_OK; 4089 ret = GS_OK;
4027 break; 4090 break;
4028 4091
4029 case CONSTRUCTOR: 4092 case CONSTRUCTOR:
4030 /* If we're initializing from a CONSTRUCTOR, break this into 4093 /* If we're initializing from a CONSTRUCTOR, break this into
4031 individual MODIFY_EXPRs. */ 4094 individual MODIFY_EXPRs. */
4032 return gimplify_init_constructor (expr_p, pre_p, post_p, want_value, 4095 return gimplify_init_constructor (expr_p, pre_p, post_p, want_value,
4033 false); 4096 false);
4034 4097
4035 case COND_EXPR: 4098 case COND_EXPR:
4036 /* If we're assigning to a non-register type, push the assignment 4099 /* If we're assigning to a non-register type, push the assignment
4037 down into the branches. This is mandatory for ADDRESSABLE types, 4100 down into the branches. This is mandatory for ADDRESSABLE types,
4038 since we cannot generate temporaries for such, but it saves a 4101 since we cannot generate temporaries for such, but it saves a
4039 copy in other cases as well. */ 4102 copy in other cases as well. */
4040 if (!is_gimple_reg_type (TREE_TYPE (*from_p))) 4103 if (!is_gimple_reg_type (TREE_TYPE (*from_p)))
4041 { 4104 {
4042 /* This code should mirror the code in gimplify_cond_expr. */ 4105 /* This code should mirror the code in gimplify_cond_expr. */
4043 enum tree_code code = TREE_CODE (*expr_p); 4106 enum tree_code code = TREE_CODE (*expr_p);
4044 tree cond = *from_p; 4107 tree cond = *from_p;
4045 tree result = *to_p; 4108 tree result = *to_p;
4046 4109
4047 ret = gimplify_expr (&result, pre_p, post_p, 4110 ret = gimplify_expr (&result, pre_p, post_p,
4048 is_gimple_lvalue, fb_lvalue); 4111 is_gimple_lvalue, fb_lvalue);
4049 if (ret != GS_ERROR) 4112 if (ret != GS_ERROR)
4050 ret = GS_OK; 4113 ret = GS_OK;
4051 4114
4052 if (TREE_TYPE (TREE_OPERAND (cond, 1)) != void_type_node) 4115 if (TREE_TYPE (TREE_OPERAND (cond, 1)) != void_type_node)
4053 TREE_OPERAND (cond, 1) 4116 TREE_OPERAND (cond, 1)
4054 = build2 (code, void_type_node, result, 4117 = build2 (code, void_type_node, result,
4055 TREE_OPERAND (cond, 1)); 4118 TREE_OPERAND (cond, 1));
4056 if (TREE_TYPE (TREE_OPERAND (cond, 2)) != void_type_node) 4119 if (TREE_TYPE (TREE_OPERAND (cond, 2)) != void_type_node)
4057 TREE_OPERAND (cond, 2) 4120 TREE_OPERAND (cond, 2)
4058 = build2 (code, void_type_node, unshare_expr (result), 4121 = build2 (code, void_type_node, unshare_expr (result),
4059 TREE_OPERAND (cond, 2)); 4122 TREE_OPERAND (cond, 2));
4060 4123
4061 TREE_TYPE (cond) = void_type_node; 4124 TREE_TYPE (cond) = void_type_node;
4062 recalculate_side_effects (cond); 4125 recalculate_side_effects (cond);
4063 4126
4064 if (want_value) 4127 if (want_value)
4065 { 4128 {
4066 gimplify_and_add (cond, pre_p); 4129 gimplify_and_add (cond, pre_p);
4067 *expr_p = unshare_expr (result); 4130 *expr_p = unshare_expr (result);
4068 } 4131 }
4069 else 4132 else
4070 *expr_p = cond; 4133 *expr_p = cond;
4071 return ret; 4134 return ret;
4072 } 4135 }
4073 else 4136 else
4074 ret = GS_UNHANDLED; 4137 ret = GS_UNHANDLED;
4075 break; 4138 break;
4076 4139
4077 case CALL_EXPR: 4140 case CALL_EXPR:
4078 /* For calls that return in memory, give *to_p as the CALL_EXPR's 4141 /* For calls that return in memory, give *to_p as the CALL_EXPR's
4079 return slot so that we don't generate a temporary. */ 4142 return slot so that we don't generate a temporary. */
4080 if (!CALL_EXPR_RETURN_SLOT_OPT (*from_p) 4143 if (!CALL_EXPR_RETURN_SLOT_OPT (*from_p)
4081 && aggregate_value_p (*from_p, *from_p)) 4144 && aggregate_value_p (*from_p, *from_p))
4082 { 4145 {
4083 bool use_target; 4146 bool use_target;
4084 4147
4085 if (!(rhs_predicate_for (*to_p))(*from_p)) 4148 if (!(rhs_predicate_for (*to_p))(*from_p))
4086 /* If we need a temporary, *to_p isn't accurate. */ 4149 /* If we need a temporary, *to_p isn't accurate. */
4087 use_target = false; 4150 use_target = false;
4088 else if (TREE_CODE (*to_p) == RESULT_DECL 4151 else if (TREE_CODE (*to_p) == RESULT_DECL
4089 && DECL_NAME (*to_p) == NULL_TREE 4152 && DECL_NAME (*to_p) == NULL_TREE
4090 && needs_to_live_in_memory (*to_p)) 4153 && needs_to_live_in_memory (*to_p))
4091 /* It's OK to use the return slot directly unless it's an NRV. */ 4154 /* It's OK to use the return slot directly unless it's an NRV. */
4092 use_target = true; 4155 use_target = true;
4093 else if (is_gimple_reg_type (TREE_TYPE (*to_p)) 4156 else if (is_gimple_reg_type (TREE_TYPE (*to_p))
4094 || (DECL_P (*to_p) && DECL_REGISTER (*to_p))) 4157 || (DECL_P (*to_p) && DECL_REGISTER (*to_p)))
4095 /* Don't force regs into memory. */ 4158 /* Don't force regs into memory. */
4096 use_target = false; 4159 use_target = false;
4097 else if (TREE_CODE (*to_p) == VAR_DECL 4160 else if (TREE_CODE (*expr_p) == INIT_EXPR)
4098 && DECL_GIMPLE_FORMAL_TEMP_P (*to_p)) 4161 /* It's OK to use the target directly if it's being
4099 /* Don't use the original target if it's a formal temp; we 4162 initialized. */
4100 don't want to take their addresses. */ 4163 use_target = true;
4101 use_target = false; 4164 else if (!is_gimple_non_addressable (*to_p))
4102 else if (TREE_CODE (*expr_p) == INIT_EXPR) 4165 /* Don't use the original target if it's already addressable;
4103 /* It's OK to use the target directly if it's being 4166 if its address escapes, and the called function uses the
4104 initialized. */ 4167 NRV optimization, a conforming program could see *to_p
4105 use_target = true; 4168 change before the called function returns; see c++/19317.
4106 else if (!is_gimple_non_addressable (*to_p)) 4169 When optimizing, the return_slot pass marks more functions
4107 /* Don't use the original target if it's already addressable; 4170 as safe after we have escape info. */
4108 if its address escapes, and the called function uses the 4171 use_target = false;
4109 NRV optimization, a conforming program could see *to_p 4172 else
4110 change before the called function returns; see c++/19317. 4173 use_target = true;
4111 When optimizing, the return_slot pass marks more functions 4174
4112 as safe after we have escape info. */ 4175 if (use_target)
4113 use_target = false; 4176 {
4114 else 4177 CALL_EXPR_RETURN_SLOT_OPT (*from_p) = 1;
4115 use_target = true; 4178 mark_addressable (*to_p);
4116 4179 }
4117 if (use_target) 4180 }
4118 { 4181
4119 CALL_EXPR_RETURN_SLOT_OPT (*from_p) = 1; 4182 ret = GS_UNHANDLED;
4120 mark_addressable (*to_p); 4183 break;
4121 } 4184
4122 } 4185 /* If we're initializing from a container, push the initialization
4123 4186 inside it. */
4124 ret = GS_UNHANDLED;
4125 break;
4126
4127 /* If we're initializing from a container, push the initialization
4128 inside it. */
4129 case CLEANUP_POINT_EXPR: 4187 case CLEANUP_POINT_EXPR:
4130 case BIND_EXPR: 4188 case BIND_EXPR:
4131 case STATEMENT_LIST: 4189 case STATEMENT_LIST:
4132 { 4190 {
4133 tree wrap = *from_p; 4191 tree wrap = *from_p;
4134 tree t; 4192 tree t;
4135 4193
4136 ret = gimplify_expr (to_p, pre_p, post_p, is_gimple_min_lval, 4194 ret = gimplify_expr (to_p, pre_p, post_p, is_gimple_min_lval,
4137 fb_lvalue); 4195 fb_lvalue);
4138 if (ret != GS_ERROR) 4196 if (ret != GS_ERROR)
4139 ret = GS_OK; 4197 ret = GS_OK;
4140 4198
4141 t = voidify_wrapper_expr (wrap, *expr_p); 4199 t = voidify_wrapper_expr (wrap, *expr_p);
4142 gcc_assert (t == *expr_p); 4200 gcc_assert (t == *expr_p);
4143 4201
4144 if (want_value) 4202 if (want_value)
4145 { 4203 {
4146 gimplify_and_add (wrap, pre_p); 4204 gimplify_and_add (wrap, pre_p);
4147 *expr_p = unshare_expr (*to_p); 4205 *expr_p = unshare_expr (*to_p);
4148 } 4206 }
4149 else 4207 else
4150 *expr_p = wrap; 4208 *expr_p = wrap;
4151 return GS_OK; 4209 return GS_OK;
4152 } 4210 }
4153 4211
4212 case COMPOUND_LITERAL_EXPR:
4213 {
4214 tree complit = TREE_OPERAND (*expr_p, 1);
4215 tree decl_s = COMPOUND_LITERAL_EXPR_DECL_EXPR (complit);
4216 tree decl = DECL_EXPR_DECL (decl_s);
4217 tree init = DECL_INITIAL (decl);
4218
4219 /* struct T x = (struct T) { 0, 1, 2 } can be optimized
4220 into struct T x = { 0, 1, 2 } if the address of the
4221 compound literal has never been taken. */
4222 if (!TREE_ADDRESSABLE (complit)
4223 && !TREE_ADDRESSABLE (decl)
4224 && init)
4225 {
4226 *expr_p = copy_node (*expr_p);
4227 TREE_OPERAND (*expr_p, 1) = init;
4228 return GS_OK;
4229 }
4230 }
4231
4154 default: 4232 default:
4155 ret = GS_UNHANDLED; 4233 ret = GS_UNHANDLED;
4156 break; 4234 break;
4157 } 4235 }
4158 4236
4159 return ret; 4237 return ret;
4160 } 4238 }
4161 4239
4204 4282
4205 4283
4206 /* Gimplify the MODIFY_EXPR node pointed to by EXPR_P. 4284 /* Gimplify the MODIFY_EXPR node pointed to by EXPR_P.
4207 4285
4208 modify_expr 4286 modify_expr
4209 : varname '=' rhs 4287 : varname '=' rhs
4210 | '*' ID '=' rhs 4288 | '*' ID '=' rhs
4211 4289
4212 PRE_P points to the list where side effects that must happen before 4290 PRE_P points to the list where side effects that must happen before
4213 *EXPR_P should be stored. 4291 *EXPR_P should be stored.
4214 4292
4215 POST_P points to the list where side effects that must happen after 4293 POST_P points to the list where side effects that must happen after
4216 *EXPR_P should be stored. 4294 *EXPR_P should be stored.
4217 4295
4218 WANT_VALUE is nonzero iff we want to use the value of this expression 4296 WANT_VALUE is nonzero iff we want to use the value of this expression
4219 in another expression. */ 4297 in another expression. */
4220 4298
4221 static enum gimplify_status 4299 static enum gimplify_status
4222 gimplify_modify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, 4300 gimplify_modify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
4223 bool want_value) 4301 bool want_value)
4224 { 4302 {
4225 tree *from_p = &TREE_OPERAND (*expr_p, 1); 4303 tree *from_p = &TREE_OPERAND (*expr_p, 1);
4226 tree *to_p = &TREE_OPERAND (*expr_p, 0); 4304 tree *to_p = &TREE_OPERAND (*expr_p, 0);
4227 enum gimplify_status ret = GS_UNHANDLED; 4305 enum gimplify_status ret = GS_UNHANDLED;
4228 gimple assign; 4306 gimple assign;
4307 location_t loc = EXPR_LOCATION (*expr_p);
4229 4308
4230 gcc_assert (TREE_CODE (*expr_p) == MODIFY_EXPR 4309 gcc_assert (TREE_CODE (*expr_p) == MODIFY_EXPR
4231 || TREE_CODE (*expr_p) == INIT_EXPR); 4310 || TREE_CODE (*expr_p) == INIT_EXPR);
4232 4311
4233 /* Insert pointer conversions required by the middle-end that are not 4312 /* Insert pointer conversions required by the middle-end that are not
4234 required by the frontend. This fixes middle-end type checking for 4313 required by the frontend. This fixes middle-end type checking for
4235 for example gcc.dg/redecl-6.c. */ 4314 for example gcc.dg/redecl-6.c. */
4236 if (POINTER_TYPE_P (TREE_TYPE (*to_p)) 4315 if (POINTER_TYPE_P (TREE_TYPE (*to_p)))
4237 && lang_hooks.types_compatible_p (TREE_TYPE (*to_p), TREE_TYPE (*from_p)))
4238 { 4316 {
4239 STRIP_USELESS_TYPE_CONVERSION (*from_p); 4317 STRIP_USELESS_TYPE_CONVERSION (*from_p);
4240 if (!useless_type_conversion_p (TREE_TYPE (*to_p), TREE_TYPE (*from_p))) 4318 if (!useless_type_conversion_p (TREE_TYPE (*to_p), TREE_TYPE (*from_p)))
4241 *from_p = fold_convert (TREE_TYPE (*to_p), *from_p); 4319 *from_p = fold_convert_loc (loc, TREE_TYPE (*to_p), *from_p);
4242 } 4320 }
4243 4321
4244 /* See if any simplifications can be done based on what the RHS is. */ 4322 /* See if any simplifications can be done based on what the RHS is. */
4245 ret = gimplify_modify_expr_rhs (expr_p, from_p, to_p, pre_p, post_p, 4323 ret = gimplify_modify_expr_rhs (expr_p, from_p, to_p, pre_p, post_p,
4246 want_value); 4324 want_value);
4247 if (ret != GS_UNHANDLED) 4325 if (ret != GS_UNHANDLED)
4248 return ret; 4326 return ret;
4249 4327
4250 /* For zero sized types only gimplify the left hand side and right hand 4328 /* For zero sized types only gimplify the left hand side and right hand
4251 side as statements and throw away the assignment. Do this after 4329 side as statements and throw away the assignment. Do this after
4282 foo's LHS, we tell it that it should only gimplify until it 4360 foo's LHS, we tell it that it should only gimplify until it
4283 reaches the CALL_EXPR. On return from gimplify_expr, the newly 4361 reaches the CALL_EXPR. On return from gimplify_expr, the newly
4284 created GIMPLE_CALL <foo> will be the last statement in *PRE_P 4362 created GIMPLE_CALL <foo> will be the last statement in *PRE_P
4285 and all we need to do here is set 'a' to be its LHS. */ 4363 and all we need to do here is set 'a' to be its LHS. */
4286 ret = gimplify_expr (from_p, pre_p, post_p, rhs_predicate_for (*to_p), 4364 ret = gimplify_expr (from_p, pre_p, post_p, rhs_predicate_for (*to_p),
4287 fb_rvalue); 4365 fb_rvalue);
4288 if (ret == GS_ERROR) 4366 if (ret == GS_ERROR)
4289 return ret; 4367 return ret;
4290 4368
4291 /* Now see if the above changed *from_p to something we handle specially. */ 4369 /* Now see if the above changed *from_p to something we handle specially. */
4292 ret = gimplify_modify_expr_rhs (expr_p, from_p, to_p, pre_p, post_p, 4370 ret = gimplify_modify_expr_rhs (expr_p, from_p, to_p, pre_p, post_p,
4293 want_value); 4371 want_value);
4294 if (ret != GS_UNHANDLED) 4372 if (ret != GS_UNHANDLED)
4295 return ret; 4373 return ret;
4296 4374
4297 /* If we've got a variable sized assignment between two lvalues (i.e. does 4375 /* If we've got a variable sized assignment between two lvalues (i.e. does
4298 not involve a call), then we can make things a bit more straightforward 4376 not involve a call), then we can make things a bit more straightforward
4301 { 4379 {
4302 tree from = TREE_OPERAND (*from_p, 0); 4380 tree from = TREE_OPERAND (*from_p, 0);
4303 tree size = TREE_OPERAND (*from_p, 1); 4381 tree size = TREE_OPERAND (*from_p, 1);
4304 4382
4305 if (TREE_CODE (from) == CONSTRUCTOR) 4383 if (TREE_CODE (from) == CONSTRUCTOR)
4306 return gimplify_modify_expr_to_memset (expr_p, size, want_value, pre_p); 4384 return gimplify_modify_expr_to_memset (expr_p, size, want_value, pre_p);
4307 4385
4308 if (is_gimple_addressable (from)) 4386 if (is_gimple_addressable (from))
4309 { 4387 {
4310 *from_p = from; 4388 *from_p = from;
4311 return gimplify_modify_expr_to_memcpy (expr_p, size, want_value, 4389 return gimplify_modify_expr_to_memcpy (expr_p, size, want_value,
4312 pre_p); 4390 pre_p);
4313 } 4391 }
4314 } 4392 }
4315 4393
4316 /* Transform partial stores to non-addressable complex variables into 4394 /* Transform partial stores to non-addressable complex variables into
4317 total stores. This allows us to use real instead of virtual operands 4395 total stores. This allows us to use real instead of virtual operands
4318 for these variables, which improves optimization. */ 4396 for these variables, which improves optimization. */
4328 && DECL_IGNORED_P (*from_p) 4406 && DECL_IGNORED_P (*from_p)
4329 && DECL_P (*to_p) 4407 && DECL_P (*to_p)
4330 && !DECL_IGNORED_P (*to_p)) 4408 && !DECL_IGNORED_P (*to_p))
4331 { 4409 {
4332 if (!DECL_NAME (*from_p) && DECL_NAME (*to_p)) 4410 if (!DECL_NAME (*from_p) && DECL_NAME (*to_p))
4333 DECL_NAME (*from_p) 4411 DECL_NAME (*from_p)
4334 = create_tmp_var_name (IDENTIFIER_POINTER (DECL_NAME (*to_p))); 4412 = create_tmp_var_name (IDENTIFIER_POINTER (DECL_NAME (*to_p)));
4335 DECL_DEBUG_EXPR_IS_FROM (*from_p) = 1; 4413 DECL_DEBUG_EXPR_IS_FROM (*from_p) = 1;
4336 SET_DECL_DEBUG_EXPR (*from_p, *to_p); 4414 SET_DECL_DEBUG_EXPR (*from_p, *to_p);
4337 } 4415 }
4338 4416
4339 if (TREE_CODE (*from_p) == CALL_EXPR) 4417 if (TREE_CODE (*from_p) == CALL_EXPR)
4340 { 4418 {
4341 /* Since the RHS is a CALL_EXPR, we need to create a GIMPLE_CALL 4419 /* Since the RHS is a CALL_EXPR, we need to create a GIMPLE_CALL
4342 instead of a GIMPLE_ASSIGN. */ 4420 instead of a GIMPLE_ASSIGN. */
4343 assign = gimple_build_call_from_tree (*from_p); 4421 assign = gimple_build_call_from_tree (*from_p);
4344 gimple_call_set_lhs (assign, *to_p); 4422 gimple_call_set_lhs (assign, *to_p);
4345 } 4423 }
4346 else 4424 else
4347 assign = gimple_build_assign (*to_p, *from_p); 4425 {
4426 assign = gimple_build_assign (*to_p, *from_p);
4427 gimple_set_location (assign, EXPR_LOCATION (*expr_p));
4428 }
4348 4429
4349 gimplify_seq_add_stmt (pre_p, assign); 4430 gimplify_seq_add_stmt (pre_p, assign);
4350 4431
4351 if (gimplify_ctxp->into_ssa && is_gimple_reg (*to_p)) 4432 if (gimplify_ctxp->into_ssa && is_gimple_reg (*to_p))
4352 { 4433 {
4353 /* If we've somehow already got an SSA_NAME on the LHS, then 4434 /* If we've somehow already got an SSA_NAME on the LHS, then
4354 we've probably modified it twice. Not good. */ 4435 we've probably modified it twice. Not good. */
4355 gcc_assert (TREE_CODE (*to_p) != SSA_NAME); 4436 gcc_assert (TREE_CODE (*to_p) != SSA_NAME);
4356 *to_p = make_ssa_name (*to_p, assign); 4437 *to_p = make_ssa_name (*to_p, assign);
4357 gimple_set_lhs (assign, *to_p); 4438 gimple_set_lhs (assign, *to_p);
4358 } 4439 }
4359 4440
4375 gimplify_variable_sized_compare (tree *expr_p) 4456 gimplify_variable_sized_compare (tree *expr_p)
4376 { 4457 {
4377 tree op0 = TREE_OPERAND (*expr_p, 0); 4458 tree op0 = TREE_OPERAND (*expr_p, 0);
4378 tree op1 = TREE_OPERAND (*expr_p, 1); 4459 tree op1 = TREE_OPERAND (*expr_p, 1);
4379 tree t, arg, dest, src; 4460 tree t, arg, dest, src;
4461 location_t loc = EXPR_LOCATION (*expr_p);
4380 4462
4381 arg = TYPE_SIZE_UNIT (TREE_TYPE (op0)); 4463 arg = TYPE_SIZE_UNIT (TREE_TYPE (op0));
4382 arg = unshare_expr (arg); 4464 arg = unshare_expr (arg);
4383 arg = SUBSTITUTE_PLACEHOLDER_IN_EXPR (arg, op0); 4465 arg = SUBSTITUTE_PLACEHOLDER_IN_EXPR (arg, op0);
4384 src = build_fold_addr_expr (op1); 4466 src = build_fold_addr_expr_loc (loc, op1);
4385 dest = build_fold_addr_expr (op0); 4467 dest = build_fold_addr_expr_loc (loc, op0);
4386 t = implicit_built_in_decls[BUILT_IN_MEMCMP]; 4468 t = implicit_built_in_decls[BUILT_IN_MEMCMP];
4387 t = build_call_expr (t, 3, dest, src, arg); 4469 t = build_call_expr_loc (loc, t, 3, dest, src, arg);
4388 *expr_p 4470 *expr_p
4389 = build2 (TREE_CODE (*expr_p), TREE_TYPE (*expr_p), t, integer_zero_node); 4471 = build2 (TREE_CODE (*expr_p), TREE_TYPE (*expr_p), t, integer_zero_node);
4390 4472
4391 return GS_OK; 4473 return GS_OK;
4392 } 4474 }
4395 mode as a comparison between the bitwise equivalent scalar values. */ 4477 mode as a comparison between the bitwise equivalent scalar values. */
4396 4478
4397 static enum gimplify_status 4479 static enum gimplify_status
4398 gimplify_scalar_mode_aggregate_compare (tree *expr_p) 4480 gimplify_scalar_mode_aggregate_compare (tree *expr_p)
4399 { 4481 {
4482 location_t loc = EXPR_LOCATION (*expr_p);
4400 tree op0 = TREE_OPERAND (*expr_p, 0); 4483 tree op0 = TREE_OPERAND (*expr_p, 0);
4401 tree op1 = TREE_OPERAND (*expr_p, 1); 4484 tree op1 = TREE_OPERAND (*expr_p, 1);
4402 4485
4403 tree type = TREE_TYPE (op0); 4486 tree type = TREE_TYPE (op0);
4404 tree scalar_type = lang_hooks.types.type_for_mode (TYPE_MODE (type), 1); 4487 tree scalar_type = lang_hooks.types.type_for_mode (TYPE_MODE (type), 1);
4405 4488
4406 op0 = fold_build1 (VIEW_CONVERT_EXPR, scalar_type, op0); 4489 op0 = fold_build1_loc (loc, VIEW_CONVERT_EXPR, scalar_type, op0);
4407 op1 = fold_build1 (VIEW_CONVERT_EXPR, scalar_type, op1); 4490 op1 = fold_build1_loc (loc, VIEW_CONVERT_EXPR, scalar_type, op1);
4408 4491
4409 *expr_p 4492 *expr_p
4410 = fold_build2 (TREE_CODE (*expr_p), TREE_TYPE (*expr_p), op0, op1); 4493 = fold_build2_loc (loc, TREE_CODE (*expr_p), TREE_TYPE (*expr_p), op0, op1);
4411 4494
4412 return GS_OK; 4495 return GS_OK;
4413 } 4496 }
4414 4497
4415 /* Gimplify TRUTH_ANDIF_EXPR and TRUTH_ORIF_EXPR expressions. EXPR_P 4498 /* Gimplify TRUTH_ANDIF_EXPR and TRUTH_ORIF_EXPR expressions. EXPR_P
4416 points to the expression to gimplify. 4499 points to the expression to gimplify.
4417 4500
4418 Expressions of the form 'a && b' are gimplified to: 4501 Expressions of the form 'a && b' are gimplified to:
4419 4502
4420 a && b ? true : false 4503 a && b ? true : false
4421 4504
4422 gimplify_cond_expr will do the rest. 4505 LOCUS is the source location to be put on the generated COND_EXPR.
4423 4506 gimplify_cond_expr will do the rest. */
4424 PRE_P points to the list where side effects that must happen before
4425 *EXPR_P should be stored. */
4426 4507
4427 static enum gimplify_status 4508 static enum gimplify_status
4428 gimplify_boolean_expr (tree *expr_p) 4509 gimplify_boolean_expr (tree *expr_p, location_t locus)
4429 { 4510 {
4430 /* Preserve the original type of the expression. */ 4511 /* Preserve the original type of the expression. */
4431 tree type = TREE_TYPE (*expr_p); 4512 tree type = TREE_TYPE (*expr_p);
4432 4513
4433 *expr_p = build3 (COND_EXPR, type, *expr_p, 4514 *expr_p = build3 (COND_EXPR, type, *expr_p,
4434 fold_convert (type, boolean_true_node), 4515 fold_convert_loc (locus, type, boolean_true_node),
4435 fold_convert (type, boolean_false_node)); 4516 fold_convert_loc (locus, type, boolean_false_node));
4517
4518 SET_EXPR_LOCATION (*expr_p, locus);
4436 4519
4437 return GS_OK; 4520 return GS_OK;
4438 } 4521 }
4439 4522
4440 /* Gimplifies an expression sequence. This function gimplifies each 4523 /* Gimplifies an expression sequence. This function gimplifies each
4454 do 4537 do
4455 { 4538 {
4456 tree *sub_p = &TREE_OPERAND (t, 0); 4539 tree *sub_p = &TREE_OPERAND (t, 0);
4457 4540
4458 if (TREE_CODE (*sub_p) == COMPOUND_EXPR) 4541 if (TREE_CODE (*sub_p) == COMPOUND_EXPR)
4459 gimplify_compound_expr (sub_p, pre_p, false); 4542 gimplify_compound_expr (sub_p, pre_p, false);
4460 else 4543 else
4461 gimplify_stmt (sub_p, pre_p); 4544 gimplify_stmt (sub_p, pre_p);
4462 4545
4463 t = TREE_OPERAND (t, 1); 4546 t = TREE_OPERAND (t, 1);
4464 } 4547 }
4465 while (TREE_CODE (t) == COMPOUND_EXPR); 4548 while (TREE_CODE (t) == COMPOUND_EXPR);
4466 4549
4493 4576
4494 /* If the SAVE_EXPR has not been resolved, then evaluate it once. */ 4577 /* If the SAVE_EXPR has not been resolved, then evaluate it once. */
4495 if (!SAVE_EXPR_RESOLVED_P (*expr_p)) 4578 if (!SAVE_EXPR_RESOLVED_P (*expr_p))
4496 { 4579 {
4497 /* The operand may be a void-valued expression such as SAVE_EXPRs 4580 /* The operand may be a void-valued expression such as SAVE_EXPRs
4498 generated by the Java frontend for class initialization. It is 4581 generated by the Java frontend for class initialization. It is
4499 being executed only for its side-effects. */ 4582 being executed only for its side-effects. */
4500 if (TREE_TYPE (val) == void_type_node) 4583 if (TREE_TYPE (val) == void_type_node)
4501 { 4584 {
4502 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p, 4585 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
4503 is_gimple_stmt, fb_none); 4586 is_gimple_stmt, fb_none);
4504 val = NULL; 4587 val = NULL;
4505 } 4588 }
4506 else 4589 else
4507 val = get_initialized_tmp_var (val, pre_p, post_p); 4590 val = get_initialized_tmp_var (val, pre_p, post_p);
4508 4591
4509 TREE_OPERAND (*expr_p, 0) = val; 4592 TREE_OPERAND (*expr_p, 0) = val;
4510 SAVE_EXPR_RESOLVED_P (*expr_p) = 1; 4593 SAVE_EXPR_RESOLVED_P (*expr_p) = 1;
4511 } 4594 }
4512 4595
4516 } 4599 }
4517 4600
4518 /* Re-write the ADDR_EXPR node pointed to by EXPR_P 4601 /* Re-write the ADDR_EXPR node pointed to by EXPR_P
4519 4602
4520 unary_expr 4603 unary_expr
4521 : ... 4604 : ...
4522 | '&' varname 4605 | '&' varname
4523 ... 4606 ...
4524 4607
4525 PRE_P points to the list where side effects that must happen before 4608 PRE_P points to the list where side effects that must happen before
4526 *EXPR_P should be stored. 4609 *EXPR_P should be stored.
4527 4610
4528 POST_P points to the list where side effects that must happen after 4611 POST_P points to the list where side effects that must happen after
4529 *EXPR_P should be stored. */ 4612 *EXPR_P should be stored. */
4530 4613
4531 static enum gimplify_status 4614 static enum gimplify_status
4532 gimplify_addr_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p) 4615 gimplify_addr_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
4533 { 4616 {
4534 tree expr = *expr_p; 4617 tree expr = *expr_p;
4535 tree op0 = TREE_OPERAND (expr, 0); 4618 tree op0 = TREE_OPERAND (expr, 0);
4536 enum gimplify_status ret; 4619 enum gimplify_status ret;
4620 location_t loc = EXPR_LOCATION (*expr_p);
4537 4621
4538 switch (TREE_CODE (op0)) 4622 switch (TREE_CODE (op0))
4539 { 4623 {
4540 case INDIRECT_REF: 4624 case INDIRECT_REF:
4541 case MISALIGNED_INDIRECT_REF: 4625 case MISALIGNED_INDIRECT_REF:
4542 do_indirect_ref: 4626 do_indirect_ref:
4543 /* Check if we are dealing with an expression of the form '&*ptr'. 4627 /* Check if we are dealing with an expression of the form '&*ptr'.
4544 While the front end folds away '&*ptr' into 'ptr', these 4628 While the front end folds away '&*ptr' into 'ptr', these
4545 expressions may be generated internally by the compiler (e.g., 4629 expressions may be generated internally by the compiler (e.g.,
4546 builtins like __builtin_va_end). */ 4630 builtins like __builtin_va_end). */
4547 /* Caution: the silent array decomposition semantics we allow for 4631 /* Caution: the silent array decomposition semantics we allow for
4548 ADDR_EXPR means we can't always discard the pair. */ 4632 ADDR_EXPR means we can't always discard the pair. */
4549 /* Gimplification of the ADDR_EXPR operand may drop 4633 /* Gimplification of the ADDR_EXPR operand may drop
4550 cv-qualification conversions, so make sure we add them if 4634 cv-qualification conversions, so make sure we add them if
4551 needed. */ 4635 needed. */
4552 { 4636 {
4553 tree op00 = TREE_OPERAND (op0, 0); 4637 tree op00 = TREE_OPERAND (op0, 0);
4554 tree t_expr = TREE_TYPE (expr); 4638 tree t_expr = TREE_TYPE (expr);
4555 tree t_op00 = TREE_TYPE (op00); 4639 tree t_op00 = TREE_TYPE (op00);
4556 4640
4557 if (!useless_type_conversion_p (t_expr, t_op00)) 4641 if (!useless_type_conversion_p (t_expr, t_op00))
4558 op00 = fold_convert (TREE_TYPE (expr), op00); 4642 op00 = fold_convert_loc (loc, TREE_TYPE (expr), op00);
4559 *expr_p = op00; 4643 *expr_p = op00;
4560 ret = GS_OK; 4644 ret = GS_OK;
4561 } 4645 }
4562 break; 4646 break;
4563 4647
4564 case VIEW_CONVERT_EXPR: 4648 case VIEW_CONVERT_EXPR:
4565 /* Take the address of our operand and then convert it to the type of 4649 /* Take the address of our operand and then convert it to the type of
4566 this ADDR_EXPR. 4650 this ADDR_EXPR.
4567 4651
4568 ??? The interactions of VIEW_CONVERT_EXPR and aliasing is not at 4652 ??? The interactions of VIEW_CONVERT_EXPR and aliasing is not at
4569 all clear. The impact of this transformation is even less clear. */ 4653 all clear. The impact of this transformation is even less clear. */
4570 4654
4571 /* If the operand is a useless conversion, look through it. Doing so 4655 /* If the operand is a useless conversion, look through it. Doing so
4572 guarantees that the ADDR_EXPR and its operand will remain of the 4656 guarantees that the ADDR_EXPR and its operand will remain of the
4573 same type. */ 4657 same type. */
4574 if (tree_ssa_useless_type_conversion (TREE_OPERAND (op0, 0))) 4658 if (tree_ssa_useless_type_conversion (TREE_OPERAND (op0, 0)))
4575 op0 = TREE_OPERAND (op0, 0); 4659 op0 = TREE_OPERAND (op0, 0);
4576 4660
4577 *expr_p = fold_convert (TREE_TYPE (expr), 4661 *expr_p = fold_convert_loc (loc, TREE_TYPE (expr),
4578 build_fold_addr_expr (TREE_OPERAND (op0, 0))); 4662 build_fold_addr_expr_loc (loc,
4663 TREE_OPERAND (op0, 0)));
4579 ret = GS_OK; 4664 ret = GS_OK;
4580 break; 4665 break;
4581 4666
4582 default: 4667 default:
4583 /* We use fb_either here because the C frontend sometimes takes 4668 /* We use fb_either here because the C frontend sometimes takes
4584 the address of a call that returns a struct; see 4669 the address of a call that returns a struct; see
4585 gcc.dg/c99-array-lval-1.c. The gimplifier will correctly make 4670 gcc.dg/c99-array-lval-1.c. The gimplifier will correctly make
4586 the implied temporary explicit. */ 4671 the implied temporary explicit. */
4587 4672
4588 /* Mark the RHS addressable. */ 4673 /* Make the operand addressable. */
4589 ret = gimplify_expr (&TREE_OPERAND (expr, 0), pre_p, post_p, 4674 ret = gimplify_expr (&TREE_OPERAND (expr, 0), pre_p, post_p,
4590 is_gimple_addressable, fb_either); 4675 is_gimple_addressable, fb_either);
4591 if (ret == GS_ERROR) 4676 if (ret == GS_ERROR)
4592 break; 4677 break;
4593 4678
4594 /* We cannot rely on making the RHS addressable if it is 4679 /* Then mark it. Beware that it may not be possible to do so directly
4595 a temporary created by gimplification. In this case create a 4680 if a temporary has been created by the gimplification. */
4596 new temporary that is initialized by a copy (which will 4681 prepare_gimple_addressable (&TREE_OPERAND (expr, 0), pre_p);
4597 become a store after we mark it addressable).
4598 This mostly happens if the frontend passed us something that
4599 it could not mark addressable yet, like a fortran
4600 pass-by-reference parameter (int) floatvar. */
4601 if (is_gimple_formal_tmp_var (TREE_OPERAND (expr, 0)))
4602 TREE_OPERAND (expr, 0)
4603 = get_initialized_tmp_var (TREE_OPERAND (expr, 0), pre_p, post_p);
4604 4682
4605 op0 = TREE_OPERAND (expr, 0); 4683 op0 = TREE_OPERAND (expr, 0);
4606 4684
4607 /* For various reasons, the gimplification of the expression 4685 /* For various reasons, the gimplification of the expression
4608 may have made a new INDIRECT_REF. */ 4686 may have made a new INDIRECT_REF. */
4609 if (TREE_CODE (op0) == INDIRECT_REF) 4687 if (TREE_CODE (op0) == INDIRECT_REF)
4610 goto do_indirect_ref; 4688 goto do_indirect_ref;
4689
4690 mark_addressable (TREE_OPERAND (expr, 0));
4691
4692 /* The FEs may end up building ADDR_EXPRs early on a decl with
4693 an incomplete type. Re-build ADDR_EXPRs in canonical form
4694 here. */
4695 if (!types_compatible_p (TREE_TYPE (op0), TREE_TYPE (TREE_TYPE (expr))))
4696 *expr_p = build_fold_addr_expr (op0);
4611 4697
4612 /* Make sure TREE_CONSTANT and TREE_SIDE_EFFECTS are set properly. */ 4698 /* Make sure TREE_CONSTANT and TREE_SIDE_EFFECTS are set properly. */
4613 recompute_tree_invariant_for_addr_expr (expr); 4699 recompute_tree_invariant_for_addr_expr (*expr_p);
4614 4700
4615 mark_addressable (TREE_OPERAND (expr, 0)); 4701 /* If we re-built the ADDR_EXPR add a conversion to the original type
4702 if required. */
4703 if (!useless_type_conversion_p (TREE_TYPE (expr), TREE_TYPE (*expr_p)))
4704 *expr_p = fold_convert (TREE_TYPE (expr), *expr_p);
4705
4616 break; 4706 break;
4617 } 4707 }
4618 4708
4619 return ret; 4709 return ret;
4620 } 4710 }
4635 enum gimplify_status ret, tret; 4725 enum gimplify_status ret, tret;
4636 gimple stmt; 4726 gimple stmt;
4637 VEC(tree, gc) *inputs; 4727 VEC(tree, gc) *inputs;
4638 VEC(tree, gc) *outputs; 4728 VEC(tree, gc) *outputs;
4639 VEC(tree, gc) *clobbers; 4729 VEC(tree, gc) *clobbers;
4730 VEC(tree, gc) *labels;
4640 tree link_next; 4731 tree link_next;
4641 4732
4642 expr = *expr_p; 4733 expr = *expr_p;
4643 noutputs = list_length (ASM_OUTPUTS (expr)); 4734 noutputs = list_length (ASM_OUTPUTS (expr));
4644 oconstraints = (const char **) alloca ((noutputs) * sizeof (const char *)); 4735 oconstraints = (const char **) alloca ((noutputs) * sizeof (const char *));
4645 4736
4646 inputs = outputs = clobbers = NULL; 4737 inputs = outputs = clobbers = labels = NULL;
4647 4738
4648 ret = GS_ALL_DONE; 4739 ret = GS_ALL_DONE;
4649 link_next = NULL_TREE; 4740 link_next = NULL_TREE;
4650 for (i = 0, link = ASM_OUTPUTS (expr); link; ++i, link = link_next) 4741 for (i = 0, link = ASM_OUTPUTS (expr); link; ++i, link = link_next)
4651 { 4742 {
4653 size_t constraint_len; 4744 size_t constraint_len;
4654 4745
4655 link_next = TREE_CHAIN (link); 4746 link_next = TREE_CHAIN (link);
4656 4747
4657 oconstraints[i] 4748 oconstraints[i]
4658 = constraint 4749 = constraint
4659 = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link))); 4750 = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
4660 constraint_len = strlen (constraint); 4751 constraint_len = strlen (constraint);
4661 if (constraint_len == 0) 4752 if (constraint_len == 0)
4662 continue; 4753 continue;
4663 4754
4664 ok = parse_output_constraint (&constraint, i, 0, 0, 4755 ok = parse_output_constraint (&constraint, i, 0, 0,
4665 &allows_mem, &allows_reg, &is_inout); 4756 &allows_mem, &allows_reg, &is_inout);
4666 if (!ok) 4757 if (!ok)
4667 { 4758 {
4668 ret = GS_ERROR; 4759 ret = GS_ERROR;
4669 is_inout = false; 4760 is_inout = false;
4670 } 4761 }
4671 4762
4672 if (!allows_reg && allows_mem) 4763 if (!allows_reg && allows_mem)
4673 mark_addressable (TREE_VALUE (link)); 4764 mark_addressable (TREE_VALUE (link));
4674 4765
4675 tret = gimplify_expr (&TREE_VALUE (link), pre_p, post_p, 4766 tret = gimplify_expr (&TREE_VALUE (link), pre_p, post_p,
4676 is_inout ? is_gimple_min_lval : is_gimple_lvalue, 4767 is_inout ? is_gimple_min_lval : is_gimple_lvalue,
4677 fb_lvalue | fb_mayfail); 4768 fb_lvalue | fb_mayfail);
4678 if (tret == GS_ERROR) 4769 if (tret == GS_ERROR)
4679 { 4770 {
4680 error ("invalid lvalue in asm output %d", i); 4771 error ("invalid lvalue in asm output %d", i);
4681 ret = tret; 4772 ret = tret;
4682 } 4773 }
4683 4774
4684 VEC_safe_push (tree, gc, outputs, link); 4775 VEC_safe_push (tree, gc, outputs, link);
4685 TREE_CHAIN (link) = NULL_TREE; 4776 TREE_CHAIN (link) = NULL_TREE;
4686 4777
4687 if (is_inout) 4778 if (is_inout)
4688 { 4779 {
4689 /* An input/output operand. To give the optimizers more 4780 /* An input/output operand. To give the optimizers more
4690 flexibility, split it into separate input and output 4781 flexibility, split it into separate input and output
4691 operands. */ 4782 operands. */
4692 tree input; 4783 tree input;
4693 char buf[10]; 4784 char buf[10];
4694 4785
4695 /* Turn the in/out constraint into an output constraint. */ 4786 /* Turn the in/out constraint into an output constraint. */
4696 char *p = xstrdup (constraint); 4787 char *p = xstrdup (constraint);
4697 p[0] = '='; 4788 p[0] = '=';
4698 TREE_VALUE (TREE_PURPOSE (link)) = build_string (constraint_len, p); 4789 TREE_VALUE (TREE_PURPOSE (link)) = build_string (constraint_len, p);
4699 4790
4700 /* And add a matching input constraint. */ 4791 /* And add a matching input constraint. */
4701 if (allows_reg) 4792 if (allows_reg)
4702 { 4793 {
4703 sprintf (buf, "%d", i); 4794 sprintf (buf, "%d", i);
4704 4795
4705 /* If there are multiple alternatives in the constraint, 4796 /* If there are multiple alternatives in the constraint,
4706 handle each of them individually. Those that allow register 4797 handle each of them individually. Those that allow register
4707 will be replaced with operand number, the others will stay 4798 will be replaced with operand number, the others will stay
4708 unchanged. */ 4799 unchanged. */
4709 if (strchr (p, ',') != NULL) 4800 if (strchr (p, ',') != NULL)
4710 { 4801 {
4711 size_t len = 0, buflen = strlen (buf); 4802 size_t len = 0, buflen = strlen (buf);
4712 char *beg, *end, *str, *dst; 4803 char *beg, *end, *str, *dst;
4713 4804
4714 for (beg = p + 1;;) 4805 for (beg = p + 1;;)
4715 { 4806 {
4716 end = strchr (beg, ','); 4807 end = strchr (beg, ',');
4717 if (end == NULL) 4808 if (end == NULL)
4718 end = strchr (beg, '\0'); 4809 end = strchr (beg, '\0');
4719 if ((size_t) (end - beg) < buflen) 4810 if ((size_t) (end - beg) < buflen)
4720 len += buflen + 1; 4811 len += buflen + 1;
4721 else 4812 else
4722 len += end - beg + 1; 4813 len += end - beg + 1;
4723 if (*end) 4814 if (*end)
4724 beg = end + 1; 4815 beg = end + 1;
4725 else 4816 else
4726 break; 4817 break;
4727 } 4818 }
4728 4819
4729 str = (char *) alloca (len); 4820 str = (char *) alloca (len);
4730 for (beg = p + 1, dst = str;;) 4821 for (beg = p + 1, dst = str;;)
4731 { 4822 {
4732 const char *tem; 4823 const char *tem;
4733 bool mem_p, reg_p, inout_p; 4824 bool mem_p, reg_p, inout_p;
4734 4825
4735 end = strchr (beg, ','); 4826 end = strchr (beg, ',');
4736 if (end) 4827 if (end)
4737 *end = '\0'; 4828 *end = '\0';
4738 beg[-1] = '='; 4829 beg[-1] = '=';
4739 tem = beg - 1; 4830 tem = beg - 1;
4740 parse_output_constraint (&tem, i, 0, 0, 4831 parse_output_constraint (&tem, i, 0, 0,
4741 &mem_p, &reg_p, &inout_p); 4832 &mem_p, &reg_p, &inout_p);
4742 if (dst != str) 4833 if (dst != str)
4743 *dst++ = ','; 4834 *dst++ = ',';
4744 if (reg_p) 4835 if (reg_p)
4745 { 4836 {
4746 memcpy (dst, buf, buflen); 4837 memcpy (dst, buf, buflen);
4747 dst += buflen; 4838 dst += buflen;
4748 } 4839 }
4749 else 4840 else
4750 { 4841 {
4751 if (end) 4842 if (end)
4752 len = end - beg; 4843 len = end - beg;
4753 else 4844 else
4754 len = strlen (beg); 4845 len = strlen (beg);
4755 memcpy (dst, beg, len); 4846 memcpy (dst, beg, len);
4756 dst += len; 4847 dst += len;
4757 } 4848 }
4758 if (end) 4849 if (end)
4759 beg = end + 1; 4850 beg = end + 1;
4760 else 4851 else
4761 break; 4852 break;
4762 } 4853 }
4763 *dst = '\0'; 4854 *dst = '\0';
4764 input = build_string (dst - str, str); 4855 input = build_string (dst - str, str);
4765 } 4856 }
4766 else 4857 else
4767 input = build_string (strlen (buf), buf); 4858 input = build_string (strlen (buf), buf);
4768 } 4859 }
4769 else 4860 else
4770 input = build_string (constraint_len - 1, constraint + 1); 4861 input = build_string (constraint_len - 1, constraint + 1);
4771 4862
4772 free (p); 4863 free (p);
4773 4864
4774 input = build_tree_list (build_tree_list (NULL_TREE, input), 4865 input = build_tree_list (build_tree_list (NULL_TREE, input),
4775 unshare_expr (TREE_VALUE (link))); 4866 unshare_expr (TREE_VALUE (link)));
4776 ASM_INPUTS (expr) = chainon (ASM_INPUTS (expr), input); 4867 ASM_INPUTS (expr) = chainon (ASM_INPUTS (expr), input);
4777 } 4868 }
4778 } 4869 }
4779 4870
4780 link_next = NULL_TREE; 4871 link_next = NULL_TREE;
4781 for (link = ASM_INPUTS (expr); link; ++i, link = link_next) 4872 for (link = ASM_INPUTS (expr); link; ++i, link = link_next)
4782 { 4873 {
4783 link_next = TREE_CHAIN (link); 4874 link_next = TREE_CHAIN (link);
4784 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link))); 4875 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
4785 parse_input_constraint (&constraint, 0, 0, noutputs, 0, 4876 parse_input_constraint (&constraint, 0, 0, noutputs, 0,
4786 oconstraints, &allows_mem, &allows_reg); 4877 oconstraints, &allows_mem, &allows_reg);
4787 4878
4788 /* If we can't make copies, we can only accept memory. */ 4879 /* If we can't make copies, we can only accept memory. */
4789 if (TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (link)))) 4880 if (TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (link))))
4790 { 4881 {
4791 if (allows_mem) 4882 if (allows_mem)
4792 allows_reg = 0; 4883 allows_reg = 0;
4793 else 4884 else
4794 { 4885 {
4795 error ("impossible constraint in %<asm%>"); 4886 error ("impossible constraint in %<asm%>");
4796 error ("non-memory input %d must stay in memory", i); 4887 error ("non-memory input %d must stay in memory", i);
4797 return GS_ERROR; 4888 return GS_ERROR;
4798 } 4889 }
4799 } 4890 }
4800 4891
4801 /* If the operand is a memory input, it should be an lvalue. */ 4892 /* If the operand is a memory input, it should be an lvalue. */
4802 if (!allows_reg && allows_mem) 4893 if (!allows_reg && allows_mem)
4803 { 4894 {
4804 tret = gimplify_expr (&TREE_VALUE (link), pre_p, post_p, 4895 tret = gimplify_expr (&TREE_VALUE (link), pre_p, post_p,
4805 is_gimple_lvalue, fb_lvalue | fb_mayfail); 4896 is_gimple_lvalue, fb_lvalue | fb_mayfail);
4806 mark_addressable (TREE_VALUE (link)); 4897 mark_addressable (TREE_VALUE (link));
4807 if (tret == GS_ERROR) 4898 if (tret == GS_ERROR)
4808 { 4899 {
4809 if (EXPR_HAS_LOCATION (TREE_VALUE (link))) 4900 if (EXPR_HAS_LOCATION (TREE_VALUE (link)))
4810 input_location = EXPR_LOCATION (TREE_VALUE (link)); 4901 input_location = EXPR_LOCATION (TREE_VALUE (link));
4811 error ("memory input %d is not directly addressable", i); 4902 error ("memory input %d is not directly addressable", i);
4812 ret = tret; 4903 ret = tret;
4813 } 4904 }
4814 } 4905 }
4815 else 4906 else
4816 { 4907 {
4817 tret = gimplify_expr (&TREE_VALUE (link), pre_p, post_p, 4908 tret = gimplify_expr (&TREE_VALUE (link), pre_p, post_p,
4818 is_gimple_asm_val, fb_rvalue); 4909 is_gimple_asm_val, fb_rvalue);
4819 if (tret == GS_ERROR) 4910 if (tret == GS_ERROR)
4820 ret = tret; 4911 ret = tret;
4821 } 4912 }
4822 4913
4823 TREE_CHAIN (link) = NULL_TREE; 4914 TREE_CHAIN (link) = NULL_TREE;
4824 VEC_safe_push (tree, gc, inputs, link); 4915 VEC_safe_push (tree, gc, inputs, link);
4825 } 4916 }
4826 4917
4827 for (link = ASM_CLOBBERS (expr); link; ++i, link = TREE_CHAIN (link)) 4918 for (link = ASM_CLOBBERS (expr); link; ++i, link = TREE_CHAIN (link))
4828 VEC_safe_push (tree, gc, clobbers, link); 4919 VEC_safe_push (tree, gc, clobbers, link);
4829 4920
4830 stmt = gimple_build_asm_vec (TREE_STRING_POINTER (ASM_STRING (expr)), 4921 for (link = ASM_LABELS (expr); link; ++i, link = TREE_CHAIN (link))
4831 inputs, outputs, clobbers); 4922 VEC_safe_push (tree, gc, labels, link);
4832 4923
4833 gimple_asm_set_volatile (stmt, ASM_VOLATILE_P (expr)); 4924 /* Do not add ASMs with errors to the gimple IL stream. */
4834 gimple_asm_set_input (stmt, ASM_INPUT_P (expr)); 4925 if (ret != GS_ERROR)
4835 4926 {
4836 gimplify_seq_add_stmt (pre_p, stmt); 4927 stmt = gimple_build_asm_vec (TREE_STRING_POINTER (ASM_STRING (expr)),
4928 inputs, outputs, clobbers, labels);
4929
4930 gimple_asm_set_volatile (stmt, ASM_VOLATILE_P (expr));
4931 gimple_asm_set_input (stmt, ASM_INPUT_P (expr));
4932
4933 gimplify_seq_add_stmt (pre_p, stmt);
4934 }
4837 4935
4838 return ret; 4936 return ret;
4839 } 4937 }
4840 4938
4841 /* Gimplify a CLEANUP_POINT_EXPR. Currently this works by adding 4939 /* Gimplify a CLEANUP_POINT_EXPR. Currently this works by adding
4876 for (iter = gsi_start (body_sequence); !gsi_end_p (iter); ) 4974 for (iter = gsi_start (body_sequence); !gsi_end_p (iter); )
4877 { 4975 {
4878 gimple wce = gsi_stmt (iter); 4976 gimple wce = gsi_stmt (iter);
4879 4977
4880 if (gimple_code (wce) == GIMPLE_WITH_CLEANUP_EXPR) 4978 if (gimple_code (wce) == GIMPLE_WITH_CLEANUP_EXPR)
4881 { 4979 {
4882 if (gsi_one_before_end_p (iter)) 4980 if (gsi_one_before_end_p (iter))
4883 { 4981 {
4884 /* Note that gsi_insert_seq_before and gsi_remove do not 4982 /* Note that gsi_insert_seq_before and gsi_remove do not
4885 scan operands, unlike some other sequence mutators. */ 4983 scan operands, unlike some other sequence mutators. */
4886 gsi_insert_seq_before_without_update (&iter, 4984 gsi_insert_seq_before_without_update (&iter,
4887 gimple_wce_cleanup (wce), 4985 gimple_wce_cleanup (wce),
4888 GSI_SAME_STMT); 4986 GSI_SAME_STMT);
4889 gsi_remove (&iter, true); 4987 gsi_remove (&iter, true);
4890 break; 4988 break;
4891 } 4989 }
4892 else 4990 else
4893 { 4991 {
4894 gimple gtry; 4992 gimple gtry;
4895 gimple_seq seq; 4993 gimple_seq seq;
4896 enum gimple_try_flags kind; 4994 enum gimple_try_flags kind;
4897 4995
4898 if (gimple_wce_cleanup_eh_only (wce)) 4996 if (gimple_wce_cleanup_eh_only (wce))
4899 kind = GIMPLE_TRY_CATCH; 4997 kind = GIMPLE_TRY_CATCH;
4900 else 4998 else
4901 kind = GIMPLE_TRY_FINALLY; 4999 kind = GIMPLE_TRY_FINALLY;
4902 seq = gsi_split_seq_after (iter); 5000 seq = gsi_split_seq_after (iter);
4903 5001
4904 gtry = gimple_build_try (seq, gimple_wce_cleanup (wce), kind); 5002 gtry = gimple_build_try (seq, gimple_wce_cleanup (wce), kind);
4905 /* Do not use gsi_replace here, as it may scan operands. 5003 /* Do not use gsi_replace here, as it may scan operands.
4906 We want to do a simple structural modification only. */ 5004 We want to do a simple structural modification only. */
4907 *gsi_stmt_ptr (&iter) = gtry; 5005 *gsi_stmt_ptr (&iter) = gtry;
4908 iter = gsi_start (seq); 5006 iter = gsi_start (seq);
4909 } 5007 }
4910 } 5008 }
4911 else 5009 else
4912 gsi_next (&iter); 5010 gsi_next (&iter);
4913 } 5011 }
4914 5012
4915 gimplify_seq_add_seq (pre_p, body_sequence); 5013 gimplify_seq_add_seq (pre_p, body_sequence);
4916 if (temp) 5014 if (temp)
4917 { 5015 {
4941 return; 5039 return;
4942 5040
4943 if (gimple_conditional_context ()) 5041 if (gimple_conditional_context ())
4944 { 5042 {
4945 /* If we're in a conditional context, this is more complex. We only 5043 /* If we're in a conditional context, this is more complex. We only
4946 want to run the cleanup if we actually ran the initialization that 5044 want to run the cleanup if we actually ran the initialization that
4947 necessitates it, but we want to run it after the end of the 5045 necessitates it, but we want to run it after the end of the
4948 conditional context. So we wrap the try/finally around the 5046 conditional context. So we wrap the try/finally around the
4949 condition and use a flag to determine whether or not to actually 5047 condition and use a flag to determine whether or not to actually
4950 run the destructor. Thus 5048 run the destructor. Thus
4951 5049
4952 test ? f(A()) : 0 5050 test ? f(A()) : 0
4953 5051
4954 becomes (approximately) 5052 becomes (approximately)
4955 5053
4956 flag = 0; 5054 flag = 0;
4957 try { 5055 try {
4958 if (test) { A::A(temp); flag = 1; val = f(temp); } 5056 if (test) { A::A(temp); flag = 1; val = f(temp); }
4959 else { val = 0; } 5057 else { val = 0; }
4960 } finally { 5058 } finally {
4961 if (flag) A::~A(temp); 5059 if (flag) A::~A(temp);
4962 } 5060 }
4963 val 5061 val
4964 */ 5062 */
4965 tree flag = create_tmp_var (boolean_type_node, "cleanup"); 5063 tree flag = create_tmp_var (boolean_type_node, "cleanup");
4966 gimple ffalse = gimple_build_assign (flag, boolean_false_node); 5064 gimple ffalse = gimple_build_assign (flag, boolean_false_node);
4967 gimple ftrue = gimple_build_assign (flag, boolean_true_node); 5065 gimple ftrue = gimple_build_assign (flag, boolean_true_node);
4968 5066
4973 gimplify_seq_add_stmt (&gimplify_ctxp->conditional_cleanups, ffalse); 5071 gimplify_seq_add_stmt (&gimplify_ctxp->conditional_cleanups, ffalse);
4974 gimplify_seq_add_stmt (&gimplify_ctxp->conditional_cleanups, wce); 5072 gimplify_seq_add_stmt (&gimplify_ctxp->conditional_cleanups, wce);
4975 gimplify_seq_add_stmt (pre_p, ftrue); 5073 gimplify_seq_add_stmt (pre_p, ftrue);
4976 5074
4977 /* Because of this manipulation, and the EH edges that jump 5075 /* Because of this manipulation, and the EH edges that jump
4978 threading cannot redirect, the temporary (VAR) will appear 5076 threading cannot redirect, the temporary (VAR) will appear
4979 to be used uninitialized. Don't warn. */ 5077 to be used uninitialized. Don't warn. */
4980 TREE_NO_WARNING (var) = 1; 5078 TREE_NO_WARNING (var) = 1;
4981 } 5079 }
4982 else 5080 else
4983 { 5081 {
4984 gimplify_stmt (&cleanup, &cleanup_stmts); 5082 gimplify_stmt (&cleanup, &cleanup_stmts);
4999 enum gimplify_status ret; 5097 enum gimplify_status ret;
5000 5098
5001 if (init) 5099 if (init)
5002 { 5100 {
5003 /* TARGET_EXPR temps aren't part of the enclosing block, so add it 5101 /* TARGET_EXPR temps aren't part of the enclosing block, so add it
5004 to the temps list. Handle also variable length TARGET_EXPRs. */ 5102 to the temps list. Handle also variable length TARGET_EXPRs. */
5005 if (TREE_CODE (DECL_SIZE (temp)) != INTEGER_CST) 5103 if (TREE_CODE (DECL_SIZE (temp)) != INTEGER_CST)
5006 { 5104 {
5007 if (!TYPE_SIZES_GIMPLIFIED (TREE_TYPE (temp))) 5105 if (!TYPE_SIZES_GIMPLIFIED (TREE_TYPE (temp)))
5008 gimplify_type_sizes (TREE_TYPE (temp), pre_p); 5106 gimplify_type_sizes (TREE_TYPE (temp), pre_p);
5009 gimplify_vla_decl (temp, pre_p); 5107 gimplify_vla_decl (temp, pre_p);
5010 } 5108 }
5011 else 5109 else
5012 gimple_add_tmp_var (temp); 5110 gimple_add_tmp_var (temp);
5013 5111
5014 /* If TARGET_EXPR_INITIAL is void, then the mere evaluation of the 5112 /* If TARGET_EXPR_INITIAL is void, then the mere evaluation of the
5015 expression is supposed to initialize the slot. */ 5113 expression is supposed to initialize the slot. */
5016 if (VOID_TYPE_P (TREE_TYPE (init))) 5114 if (VOID_TYPE_P (TREE_TYPE (init)))
5017 ret = gimplify_expr (&init, pre_p, post_p, is_gimple_stmt, fb_none); 5115 ret = gimplify_expr (&init, pre_p, post_p, is_gimple_stmt, fb_none);
5018 else 5116 else
5019 { 5117 {
5020 tree init_expr = build2 (INIT_EXPR, void_type_node, temp, init); 5118 tree init_expr = build2 (INIT_EXPR, void_type_node, temp, init);
5021 init = init_expr; 5119 init = init_expr;
5022 ret = gimplify_expr (&init, pre_p, post_p, is_gimple_stmt, fb_none); 5120 ret = gimplify_expr (&init, pre_p, post_p, is_gimple_stmt, fb_none);
5023 init = NULL; 5121 init = NULL;
5024 ggc_free (init_expr); 5122 ggc_free (init_expr);
5025 } 5123 }
5026 if (ret == GS_ERROR) 5124 if (ret == GS_ERROR)
5027 { 5125 {
5028 /* PR c++/28266 Make sure this is expanded only once. */ 5126 /* PR c++/28266 Make sure this is expanded only once. */
5029 TARGET_EXPR_INITIAL (targ) = NULL_TREE; 5127 TARGET_EXPR_INITIAL (targ) = NULL_TREE;
5030 return GS_ERROR; 5128 return GS_ERROR;
5031 } 5129 }
5032 if (init) 5130 if (init)
5033 gimplify_and_add (init, pre_p); 5131 gimplify_and_add (init, pre_p);
5034 5132
5035 /* If needed, push the cleanup for the temp. */ 5133 /* If needed, push the cleanup for the temp. */
5036 if (TARGET_EXPR_CLEANUP (targ)) 5134 if (TARGET_EXPR_CLEANUP (targ))
5037 gimple_push_cleanup (temp, TARGET_EXPR_CLEANUP (targ), 5135 gimple_push_cleanup (temp, TARGET_EXPR_CLEANUP (targ),
5038 CLEANUP_EH_ONLY (targ), pre_p); 5136 CLEANUP_EH_ONLY (targ), pre_p);
5039 5137
5040 /* Only expand this once. */ 5138 /* Only expand this once. */
5041 TREE_OPERAND (targ, 3) = init; 5139 TREE_OPERAND (targ, 3) = init;
5042 TARGET_EXPR_INITIAL (targ) = NULL_TREE; 5140 TARGET_EXPR_INITIAL (targ) = NULL_TREE;
5043 } 5141 }
5085 5183
5086 do 5184 do
5087 { 5185 {
5088 n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl); 5186 n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl);
5089 if (n != NULL) 5187 if (n != NULL)
5090 { 5188 {
5091 if (n->value & GOVD_SHARED) 5189 if (n->value & GOVD_SHARED)
5092 n->value = GOVD_FIRSTPRIVATE | (n->value & GOVD_SEEN); 5190 n->value = GOVD_FIRSTPRIVATE | (n->value & GOVD_SEEN);
5093 else 5191 else
5094 return; 5192 return;
5095 } 5193 }
5096 else if (ctx->region_type != ORT_WORKSHARE) 5194 else if (ctx->region_type != ORT_WORKSHARE)
5097 omp_add_variable (ctx, decl, GOVD_FIRSTPRIVATE); 5195 omp_add_variable (ctx, decl, GOVD_FIRSTPRIVATE);
5098 5196
5099 ctx = ctx->outer_context; 5197 ctx = ctx->outer_context;
5100 } 5198 }
5101 while (ctx); 5199 while (ctx);
5102 } 5200 }
5131 5229
5132 case RECORD_TYPE: 5230 case RECORD_TYPE:
5133 case UNION_TYPE: 5231 case UNION_TYPE:
5134 case QUAL_UNION_TYPE: 5232 case QUAL_UNION_TYPE:
5135 { 5233 {
5136 tree field; 5234 tree field;
5137 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) 5235 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
5138 if (TREE_CODE (field) == FIELD_DECL) 5236 if (TREE_CODE (field) == FIELD_DECL)
5139 { 5237 {
5140 omp_firstprivatize_variable (ctx, DECL_FIELD_OFFSET (field)); 5238 omp_firstprivatize_variable (ctx, DECL_FIELD_OFFSET (field));
5141 omp_firstprivatize_type_sizes (ctx, TREE_TYPE (field)); 5239 omp_firstprivatize_type_sizes (ctx, TREE_TYPE (field));
5142 } 5240 }
5143 } 5241 }
5144 break; 5242 break;
5145 5243
5146 case POINTER_TYPE: 5244 case POINTER_TYPE:
5147 case REFERENCE_TYPE: 5245 case REFERENCE_TYPE:
5177 5275
5178 n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl); 5276 n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl);
5179 if (n != NULL) 5277 if (n != NULL)
5180 { 5278 {
5181 /* We shouldn't be re-adding the decl with the same data 5279 /* We shouldn't be re-adding the decl with the same data
5182 sharing class. */ 5280 sharing class. */
5183 gcc_assert ((n->value & GOVD_DATA_SHARE_CLASS & flags) == 0); 5281 gcc_assert ((n->value & GOVD_DATA_SHARE_CLASS & flags) == 0);
5184 /* The only combination of data sharing classes we should see is 5282 /* The only combination of data sharing classes we should see is
5185 FIRSTPRIVATE and LASTPRIVATE. */ 5283 FIRSTPRIVATE and LASTPRIVATE. */
5186 nflags = n->value | flags; 5284 nflags = n->value | flags;
5187 gcc_assert ((nflags & GOVD_DATA_SHARE_CLASS) 5285 gcc_assert ((nflags & GOVD_DATA_SHARE_CLASS)
5188 == (GOVD_FIRSTPRIVATE | GOVD_LASTPRIVATE)); 5286 == (GOVD_FIRSTPRIVATE | GOVD_LASTPRIVATE));
5189 n->value = nflags; 5287 n->value = nflags;
5190 return; 5288 return;
5191 } 5289 }
5192 5290
5193 /* When adding a variable-sized variable, we have to handle all sorts 5291 /* When adding a variable-sized variable, we have to handle all sorts
5194 of additional bits of data: the pointer replacement variable, and 5292 of additional bits of data: the pointer replacement variable, and
5195 the parameters of the type. */ 5293 the parameters of the type. */
5196 if (DECL_SIZE (decl) && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST) 5294 if (DECL_SIZE (decl) && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
5197 { 5295 {
5198 /* Add the pointer replacement variable as PRIVATE if the variable 5296 /* Add the pointer replacement variable as PRIVATE if the variable
5199 replacement is private, else FIRSTPRIVATE since we'll need the 5297 replacement is private, else FIRSTPRIVATE since we'll need the
5200 address of the original variable either for SHARED, or for the 5298 address of the original variable either for SHARED, or for the
5201 copy into or out of the context. */ 5299 copy into or out of the context. */
5202 if (!(flags & GOVD_LOCAL)) 5300 if (!(flags & GOVD_LOCAL))
5203 { 5301 {
5204 nflags = flags & GOVD_PRIVATE ? GOVD_PRIVATE : GOVD_FIRSTPRIVATE; 5302 nflags = flags & GOVD_PRIVATE ? GOVD_PRIVATE : GOVD_FIRSTPRIVATE;
5205 nflags |= flags & GOVD_SEEN; 5303 nflags |= flags & GOVD_SEEN;
5206 t = DECL_VALUE_EXPR (decl); 5304 t = DECL_VALUE_EXPR (decl);
5207 gcc_assert (TREE_CODE (t) == INDIRECT_REF); 5305 gcc_assert (TREE_CODE (t) == INDIRECT_REF);
5208 t = TREE_OPERAND (t, 0); 5306 t = TREE_OPERAND (t, 0);
5209 gcc_assert (DECL_P (t)); 5307 gcc_assert (DECL_P (t));
5210 omp_add_variable (ctx, t, nflags); 5308 omp_add_variable (ctx, t, nflags);
5211 } 5309 }
5212 5310
5213 /* Add all of the variable and type parameters (which should have 5311 /* Add all of the variable and type parameters (which should have
5214 been gimplified to a formal temporary) as FIRSTPRIVATE. */ 5312 been gimplified to a formal temporary) as FIRSTPRIVATE. */
5215 omp_firstprivatize_variable (ctx, DECL_SIZE_UNIT (decl)); 5313 omp_firstprivatize_variable (ctx, DECL_SIZE_UNIT (decl));
5216 omp_firstprivatize_variable (ctx, DECL_SIZE (decl)); 5314 omp_firstprivatize_variable (ctx, DECL_SIZE (decl));
5217 omp_firstprivatize_type_sizes (ctx, TREE_TYPE (decl)); 5315 omp_firstprivatize_type_sizes (ctx, TREE_TYPE (decl));
5218 5316
5219 /* The variable-sized variable itself is never SHARED, only some form 5317 /* The variable-sized variable itself is never SHARED, only some form
5220 of PRIVATE. The sharing would take place via the pointer variable 5318 of PRIVATE. The sharing would take place via the pointer variable
5221 which we remapped above. */ 5319 which we remapped above. */
5222 if (flags & GOVD_SHARED) 5320 if (flags & GOVD_SHARED)
5223 flags = GOVD_PRIVATE | GOVD_DEBUG_PRIVATE 5321 flags = GOVD_PRIVATE | GOVD_DEBUG_PRIVATE
5224 | (flags & (GOVD_SEEN | GOVD_EXPLICIT)); 5322 | (flags & (GOVD_SEEN | GOVD_EXPLICIT));
5225 5323
5226 /* We're going to make use of the TYPE_SIZE_UNIT at least in the 5324 /* We're going to make use of the TYPE_SIZE_UNIT at least in the
5227 alloca statement we generate for the variable, so make sure it 5325 alloca statement we generate for the variable, so make sure it
5228 is available. This isn't automatically needed for the SHARED 5326 is available. This isn't automatically needed for the SHARED
5229 case, since we won't be allocating local storage then. 5327 case, since we won't be allocating local storage then.
5230 For local variables TYPE_SIZE_UNIT might not be gimplified yet, 5328 For local variables TYPE_SIZE_UNIT might not be gimplified yet,
5231 in this case omp_notice_variable will be called later 5329 in this case omp_notice_variable will be called later
5232 on when it is gimplified. */ 5330 on when it is gimplified. */
5233 else if (! (flags & GOVD_LOCAL)) 5331 else if (! (flags & GOVD_LOCAL))
5234 omp_notice_variable (ctx, TYPE_SIZE_UNIT (TREE_TYPE (decl)), true); 5332 omp_notice_variable (ctx, TYPE_SIZE_UNIT (TREE_TYPE (decl)), true);
5235 } 5333 }
5236 else if (lang_hooks.decls.omp_privatize_by_reference (decl)) 5334 else if (lang_hooks.decls.omp_privatize_by_reference (decl))
5237 { 5335 {
5238 gcc_assert ((flags & GOVD_LOCAL) == 0); 5336 gcc_assert ((flags & GOVD_LOCAL) == 0);
5239 omp_firstprivatize_type_sizes (ctx, TREE_TYPE (decl)); 5337 omp_firstprivatize_type_sizes (ctx, TREE_TYPE (decl));
5240 5338
5241 /* Similar to the direct variable sized case above, we'll need the 5339 /* Similar to the direct variable sized case above, we'll need the
5242 size of references being privatized. */ 5340 size of references being privatized. */
5243 if ((flags & GOVD_SHARED) == 0) 5341 if ((flags & GOVD_SHARED) == 0)
5244 { 5342 {
5245 t = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl))); 5343 t = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl)));
5246 if (TREE_CODE (t) != INTEGER_CST) 5344 if (TREE_CODE (t) != INTEGER_CST)
5247 omp_notice_variable (ctx, t, true); 5345 omp_notice_variable (ctx, t, true);
5248 } 5346 }
5249 } 5347 }
5250 5348
5251 splay_tree_insert (ctx->variables, (splay_tree_key)decl, flags); 5349 splay_tree_insert (ctx->variables, (splay_tree_key)decl, flags);
5252 } 5350 }
5253 5351
5269 5367
5270 /* Threadprivate variables are predetermined. */ 5368 /* Threadprivate variables are predetermined. */
5271 if (is_global_var (decl)) 5369 if (is_global_var (decl))
5272 { 5370 {
5273 if (DECL_THREAD_LOCAL_P (decl)) 5371 if (DECL_THREAD_LOCAL_P (decl))
5274 return false; 5372 return false;
5275 5373
5276 if (DECL_HAS_VALUE_EXPR_P (decl)) 5374 if (DECL_HAS_VALUE_EXPR_P (decl))
5277 { 5375 {
5278 tree value = get_base_address (DECL_VALUE_EXPR (decl)); 5376 tree value = get_base_address (DECL_VALUE_EXPR (decl));
5279 5377
5280 if (value && DECL_P (value) && DECL_THREAD_LOCAL_P (value)) 5378 if (value && DECL_P (value) && DECL_THREAD_LOCAL_P (value))
5281 return false; 5379 return false;
5282 } 5380 }
5283 } 5381 }
5284 5382
5285 n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl); 5383 n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl);
5286 if (n == NULL) 5384 if (n == NULL)
5287 { 5385 {
5288 enum omp_clause_default_kind default_kind, kind; 5386 enum omp_clause_default_kind default_kind, kind;
5289 struct gimplify_omp_ctx *octx; 5387 struct gimplify_omp_ctx *octx;
5290 5388
5291 if (ctx->region_type == ORT_WORKSHARE) 5389 if (ctx->region_type == ORT_WORKSHARE)
5292 goto do_outer; 5390 goto do_outer;
5293 5391
5294 /* ??? Some compiler-generated variables (like SAVE_EXPRs) could be 5392 /* ??? Some compiler-generated variables (like SAVE_EXPRs) could be
5295 remapped firstprivate instead of shared. To some extent this is 5393 remapped firstprivate instead of shared. To some extent this is
5296 addressed in omp_firstprivatize_type_sizes, but not effectively. */ 5394 addressed in omp_firstprivatize_type_sizes, but not effectively. */
5297 default_kind = ctx->default_kind; 5395 default_kind = ctx->default_kind;
5298 kind = lang_hooks.decls.omp_predetermined_sharing (decl); 5396 kind = lang_hooks.decls.omp_predetermined_sharing (decl);
5299 if (kind != OMP_CLAUSE_DEFAULT_UNSPECIFIED) 5397 if (kind != OMP_CLAUSE_DEFAULT_UNSPECIFIED)
5300 default_kind = kind; 5398 default_kind = kind;
5301 5399
5302 switch (default_kind) 5400 switch (default_kind)
5303 { 5401 {
5304 case OMP_CLAUSE_DEFAULT_NONE: 5402 case OMP_CLAUSE_DEFAULT_NONE:
5305 error ("%qs not specified in enclosing parallel", 5403 error ("%qE not specified in enclosing parallel",
5306 IDENTIFIER_POINTER (DECL_NAME (decl))); 5404 DECL_NAME (decl));
5307 error ("%Henclosing parallel", &ctx->location); 5405 error_at (ctx->location, "enclosing parallel");
5308 /* FALLTHRU */ 5406 /* FALLTHRU */
5309 case OMP_CLAUSE_DEFAULT_SHARED: 5407 case OMP_CLAUSE_DEFAULT_SHARED:
5310 flags |= GOVD_SHARED; 5408 flags |= GOVD_SHARED;
5311 break; 5409 break;
5312 case OMP_CLAUSE_DEFAULT_PRIVATE: 5410 case OMP_CLAUSE_DEFAULT_PRIVATE:
5313 flags |= GOVD_PRIVATE; 5411 flags |= GOVD_PRIVATE;
5314 break; 5412 break;
5315 case OMP_CLAUSE_DEFAULT_FIRSTPRIVATE: 5413 case OMP_CLAUSE_DEFAULT_FIRSTPRIVATE:
5316 flags |= GOVD_FIRSTPRIVATE; 5414 flags |= GOVD_FIRSTPRIVATE;
5317 break; 5415 break;
5318 case OMP_CLAUSE_DEFAULT_UNSPECIFIED: 5416 case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
5319 /* decl will be either GOVD_FIRSTPRIVATE or GOVD_SHARED. */ 5417 /* decl will be either GOVD_FIRSTPRIVATE or GOVD_SHARED. */
5320 gcc_assert (ctx->region_type == ORT_TASK); 5418 gcc_assert (ctx->region_type == ORT_TASK);
5321 if (ctx->outer_context) 5419 if (ctx->outer_context)
5322 omp_notice_variable (ctx->outer_context, decl, in_code); 5420 omp_notice_variable (ctx->outer_context, decl, in_code);
5323 for (octx = ctx->outer_context; octx; octx = octx->outer_context) 5421 for (octx = ctx->outer_context; octx; octx = octx->outer_context)
5324 { 5422 {
5325 splay_tree_node n2; 5423 splay_tree_node n2;
5326 5424
5327 n2 = splay_tree_lookup (octx->variables, (splay_tree_key) decl); 5425 n2 = splay_tree_lookup (octx->variables, (splay_tree_key) decl);
5328 if (n2 && (n2->value & GOVD_DATA_SHARE_CLASS) != GOVD_SHARED) 5426 if (n2 && (n2->value & GOVD_DATA_SHARE_CLASS) != GOVD_SHARED)
5329 { 5427 {
5330 flags |= GOVD_FIRSTPRIVATE; 5428 flags |= GOVD_FIRSTPRIVATE;
5331 break; 5429 break;
5332 } 5430 }
5333 if ((octx->region_type & ORT_PARALLEL) != 0) 5431 if ((octx->region_type & ORT_PARALLEL) != 0)
5334 break; 5432 break;
5335 } 5433 }
5336 if (flags & GOVD_FIRSTPRIVATE) 5434 if (flags & GOVD_FIRSTPRIVATE)
5337 break; 5435 break;
5338 if (octx == NULL 5436 if (octx == NULL
5339 && (TREE_CODE (decl) == PARM_DECL 5437 && (TREE_CODE (decl) == PARM_DECL
5340 || (!is_global_var (decl) 5438 || (!is_global_var (decl)
5341 && DECL_CONTEXT (decl) == current_function_decl))) 5439 && DECL_CONTEXT (decl) == current_function_decl)))
5342 { 5440 {
5343 flags |= GOVD_FIRSTPRIVATE; 5441 flags |= GOVD_FIRSTPRIVATE;
5344 break; 5442 break;
5345 } 5443 }
5346 flags |= GOVD_SHARED; 5444 flags |= GOVD_SHARED;
5347 break; 5445 break;
5348 default: 5446 default:
5349 gcc_unreachable (); 5447 gcc_unreachable ();
5350 } 5448 }
5351 5449
5352 if ((flags & GOVD_PRIVATE) 5450 if ((flags & GOVD_PRIVATE)
5353 && lang_hooks.decls.omp_private_outer_ref (decl)) 5451 && lang_hooks.decls.omp_private_outer_ref (decl))
5354 flags |= GOVD_PRIVATE_OUTER_REF; 5452 flags |= GOVD_PRIVATE_OUTER_REF;
5355 5453
5356 omp_add_variable (ctx, decl, flags); 5454 omp_add_variable (ctx, decl, flags);
5357 5455
5358 shared = (flags & GOVD_SHARED) != 0; 5456 shared = (flags & GOVD_SHARED) != 0;
5359 ret = lang_hooks.decls.omp_disregard_value_expr (decl, shared); 5457 ret = lang_hooks.decls.omp_disregard_value_expr (decl, shared);
5404 5502
5405 n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl); 5503 n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl);
5406 if (n != NULL) 5504 if (n != NULL)
5407 { 5505 {
5408 if (n->value & GOVD_SHARED) 5506 if (n->value & GOVD_SHARED)
5409 { 5507 {
5410 if (ctx == gimplify_omp_ctxp) 5508 if (ctx == gimplify_omp_ctxp)
5411 { 5509 {
5412 error ("iteration variable %qs should be private", 5510 error ("iteration variable %qE should be private",
5413 IDENTIFIER_POINTER (DECL_NAME (decl))); 5511 DECL_NAME (decl));
5414 n->value = GOVD_PRIVATE; 5512 n->value = GOVD_PRIVATE;
5415 return true; 5513 return true;
5416 } 5514 }
5417 else 5515 else
5418 return false; 5516 return false;
5419 } 5517 }
5420 else if ((n->value & GOVD_EXPLICIT) != 0 5518 else if ((n->value & GOVD_EXPLICIT) != 0
5421 && (ctx == gimplify_omp_ctxp 5519 && (ctx == gimplify_omp_ctxp
5422 || (ctx->region_type == ORT_COMBINED_PARALLEL 5520 || (ctx->region_type == ORT_COMBINED_PARALLEL
5423 && gimplify_omp_ctxp->outer_context == ctx))) 5521 && gimplify_omp_ctxp->outer_context == ctx)))
5424 { 5522 {
5425 if ((n->value & GOVD_FIRSTPRIVATE) != 0) 5523 if ((n->value & GOVD_FIRSTPRIVATE) != 0)
5426 error ("iteration variable %qs should not be firstprivate", 5524 error ("iteration variable %qE should not be firstprivate",
5427 IDENTIFIER_POINTER (DECL_NAME (decl))); 5525 DECL_NAME (decl));
5428 else if ((n->value & GOVD_REDUCTION) != 0) 5526 else if ((n->value & GOVD_REDUCTION) != 0)
5429 error ("iteration variable %qs should not be reduction", 5527 error ("iteration variable %qE should not be reduction",
5430 IDENTIFIER_POINTER (DECL_NAME (decl))); 5528 DECL_NAME (decl));
5431 } 5529 }
5432 return (ctx == gimplify_omp_ctxp 5530 return (ctx == gimplify_omp_ctxp
5433 || (ctx->region_type == ORT_COMBINED_PARALLEL 5531 || (ctx->region_type == ORT_COMBINED_PARALLEL
5434 && gimplify_omp_ctxp->outer_context == ctx)); 5532 && gimplify_omp_ctxp->outer_context == ctx));
5435 } 5533 }
5436 5534
5437 if (ctx->region_type != ORT_WORKSHARE) 5535 if (ctx->region_type != ORT_WORKSHARE)
5438 return false; 5536 return false;
5439 else if (ctx->outer_context) 5537 else if (ctx->outer_context)
5452 5550
5453 do 5551 do
5454 { 5552 {
5455 ctx = ctx->outer_context; 5553 ctx = ctx->outer_context;
5456 if (ctx == NULL) 5554 if (ctx == NULL)
5457 return !(is_global_var (decl) 5555 return !(is_global_var (decl)
5458 /* References might be private, but might be shared too. */ 5556 /* References might be private, but might be shared too. */
5459 || lang_hooks.decls.omp_privatize_by_reference (decl)); 5557 || lang_hooks.decls.omp_privatize_by_reference (decl));
5460 5558
5461 n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl); 5559 n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
5462 if (n != NULL) 5560 if (n != NULL)
5463 return (n->value & GOVD_SHARED) == 0; 5561 return (n->value & GOVD_SHARED) == 0;
5464 } 5562 }
5465 while (ctx->region_type == ORT_WORKSHARE); 5563 while (ctx->region_type == ORT_WORKSHARE);
5466 return false; 5564 return false;
5467 } 5565 }
5468 5566
5469 /* Scan the OpenMP clauses in *LIST_P, installing mappings into a new 5567 /* Scan the OpenMP clauses in *LIST_P, installing mappings into a new
5470 and previous omp contexts. */ 5568 and previous omp contexts. */
5471 5569
5472 static void 5570 static void
5473 gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, 5571 gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
5474 enum omp_region_type region_type) 5572 enum omp_region_type region_type)
5475 { 5573 {
5476 struct gimplify_omp_ctx *ctx, *outer_ctx; 5574 struct gimplify_omp_ctx *ctx, *outer_ctx;
5477 struct gimplify_ctx gctx; 5575 struct gimplify_ctx gctx;
5478 tree c; 5576 tree c;
5479 5577
5487 const char *check_non_private = NULL; 5585 const char *check_non_private = NULL;
5488 unsigned int flags; 5586 unsigned int flags;
5489 tree decl; 5587 tree decl;
5490 5588
5491 switch (OMP_CLAUSE_CODE (c)) 5589 switch (OMP_CLAUSE_CODE (c))
5492 { 5590 {
5493 case OMP_CLAUSE_PRIVATE: 5591 case OMP_CLAUSE_PRIVATE:
5494 flags = GOVD_PRIVATE | GOVD_EXPLICIT; 5592 flags = GOVD_PRIVATE | GOVD_EXPLICIT;
5495 if (lang_hooks.decls.omp_private_outer_ref (OMP_CLAUSE_DECL (c))) 5593 if (lang_hooks.decls.omp_private_outer_ref (OMP_CLAUSE_DECL (c)))
5496 { 5594 {
5497 flags |= GOVD_PRIVATE_OUTER_REF; 5595 flags |= GOVD_PRIVATE_OUTER_REF;
5498 OMP_CLAUSE_PRIVATE_OUTER_REF (c) = 1; 5596 OMP_CLAUSE_PRIVATE_OUTER_REF (c) = 1;
5499 } 5597 }
5500 else 5598 else
5501 notice_outer = false; 5599 notice_outer = false;
5502 goto do_add; 5600 goto do_add;
5503 case OMP_CLAUSE_SHARED: 5601 case OMP_CLAUSE_SHARED:
5504 flags = GOVD_SHARED | GOVD_EXPLICIT; 5602 flags = GOVD_SHARED | GOVD_EXPLICIT;
5505 goto do_add; 5603 goto do_add;
5506 case OMP_CLAUSE_FIRSTPRIVATE: 5604 case OMP_CLAUSE_FIRSTPRIVATE:
5507 flags = GOVD_FIRSTPRIVATE | GOVD_EXPLICIT; 5605 flags = GOVD_FIRSTPRIVATE | GOVD_EXPLICIT;
5508 check_non_private = "firstprivate"; 5606 check_non_private = "firstprivate";
5509 goto do_add; 5607 goto do_add;
5510 case OMP_CLAUSE_LASTPRIVATE: 5608 case OMP_CLAUSE_LASTPRIVATE:
5511 flags = GOVD_LASTPRIVATE | GOVD_SEEN | GOVD_EXPLICIT; 5609 flags = GOVD_LASTPRIVATE | GOVD_SEEN | GOVD_EXPLICIT;
5512 check_non_private = "lastprivate"; 5610 check_non_private = "lastprivate";
5513 goto do_add; 5611 goto do_add;
5514 case OMP_CLAUSE_REDUCTION: 5612 case OMP_CLAUSE_REDUCTION:
5515 flags = GOVD_REDUCTION | GOVD_SEEN | GOVD_EXPLICIT; 5613 flags = GOVD_REDUCTION | GOVD_SEEN | GOVD_EXPLICIT;
5516 check_non_private = "reduction"; 5614 check_non_private = "reduction";
5517 goto do_add; 5615 goto do_add;
5518 5616
5519 do_add: 5617 do_add:
5520 decl = OMP_CLAUSE_DECL (c); 5618 decl = OMP_CLAUSE_DECL (c);
5521 if (decl == error_mark_node || TREE_TYPE (decl) == error_mark_node) 5619 if (decl == error_mark_node || TREE_TYPE (decl) == error_mark_node)
5522 { 5620 {
5523 remove = true; 5621 remove = true;
5524 break; 5622 break;
5525 } 5623 }
5526 omp_add_variable (ctx, decl, flags); 5624 omp_add_variable (ctx, decl, flags);
5527 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION 5625 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
5528 && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)) 5626 && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
5529 { 5627 {
5530 omp_add_variable (ctx, OMP_CLAUSE_REDUCTION_PLACEHOLDER (c), 5628 omp_add_variable (ctx, OMP_CLAUSE_REDUCTION_PLACEHOLDER (c),
5531 GOVD_LOCAL | GOVD_SEEN); 5629 GOVD_LOCAL | GOVD_SEEN);
5532 gimplify_omp_ctxp = ctx; 5630 gimplify_omp_ctxp = ctx;
5533 push_gimplify_context (&gctx); 5631 push_gimplify_context (&gctx);
5534 5632
5535 OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c) = gimple_seq_alloc (); 5633 OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c) = gimple_seq_alloc ();
5536 OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c) = gimple_seq_alloc (); 5634 OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c) = gimple_seq_alloc ();
5537 5635
5538 gimplify_and_add (OMP_CLAUSE_REDUCTION_INIT (c), 5636 gimplify_and_add (OMP_CLAUSE_REDUCTION_INIT (c),
5539 &OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c)); 5637 &OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c));
5540 pop_gimplify_context 5638 pop_gimplify_context
5541 (gimple_seq_first_stmt (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c))); 5639 (gimple_seq_first_stmt (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c)));
5542 push_gimplify_context (&gctx); 5640 push_gimplify_context (&gctx);
5543 gimplify_and_add (OMP_CLAUSE_REDUCTION_MERGE (c), 5641 gimplify_and_add (OMP_CLAUSE_REDUCTION_MERGE (c),
5544 &OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c)); 5642 &OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c));
5545 pop_gimplify_context 5643 pop_gimplify_context
5546 (gimple_seq_first_stmt (OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c))); 5644 (gimple_seq_first_stmt (OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c)));
5547 OMP_CLAUSE_REDUCTION_INIT (c) = NULL_TREE; 5645 OMP_CLAUSE_REDUCTION_INIT (c) = NULL_TREE;
5548 OMP_CLAUSE_REDUCTION_MERGE (c) = NULL_TREE; 5646 OMP_CLAUSE_REDUCTION_MERGE (c) = NULL_TREE;
5549 5647
5550 gimplify_omp_ctxp = outer_ctx; 5648 gimplify_omp_ctxp = outer_ctx;
5551 } 5649 }
5552 else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE 5650 else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
5553 && OMP_CLAUSE_LASTPRIVATE_STMT (c)) 5651 && OMP_CLAUSE_LASTPRIVATE_STMT (c))
5554 { 5652 {
5555 gimplify_omp_ctxp = ctx; 5653 gimplify_omp_ctxp = ctx;
5556 push_gimplify_context (&gctx); 5654 push_gimplify_context (&gctx);
5557 if (TREE_CODE (OMP_CLAUSE_LASTPRIVATE_STMT (c)) != BIND_EXPR) 5655 if (TREE_CODE (OMP_CLAUSE_LASTPRIVATE_STMT (c)) != BIND_EXPR)
5558 { 5656 {
5559 tree bind = build3 (BIND_EXPR, void_type_node, NULL, 5657 tree bind = build3 (BIND_EXPR, void_type_node, NULL,
5560 NULL, NULL); 5658 NULL, NULL);
5561 TREE_SIDE_EFFECTS (bind) = 1; 5659 TREE_SIDE_EFFECTS (bind) = 1;
5562 BIND_EXPR_BODY (bind) = OMP_CLAUSE_LASTPRIVATE_STMT (c); 5660 BIND_EXPR_BODY (bind) = OMP_CLAUSE_LASTPRIVATE_STMT (c);
5563 OMP_CLAUSE_LASTPRIVATE_STMT (c) = bind; 5661 OMP_CLAUSE_LASTPRIVATE_STMT (c) = bind;
5564 } 5662 }
5565 gimplify_and_add (OMP_CLAUSE_LASTPRIVATE_STMT (c), 5663 gimplify_and_add (OMP_CLAUSE_LASTPRIVATE_STMT (c),
5566 &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c)); 5664 &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c));
5567 pop_gimplify_context 5665 pop_gimplify_context
5568 (gimple_seq_first_stmt (OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c))); 5666 (gimple_seq_first_stmt (OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c)));
5569 OMP_CLAUSE_LASTPRIVATE_STMT (c) = NULL_TREE; 5667 OMP_CLAUSE_LASTPRIVATE_STMT (c) = NULL_TREE;
5570 5668
5571 gimplify_omp_ctxp = outer_ctx; 5669 gimplify_omp_ctxp = outer_ctx;
5572 } 5670 }
5573 if (notice_outer) 5671 if (notice_outer)
5574 goto do_notice; 5672 goto do_notice;
5575 break; 5673 break;
5576 5674
5577 case OMP_CLAUSE_COPYIN: 5675 case OMP_CLAUSE_COPYIN:
5578 case OMP_CLAUSE_COPYPRIVATE: 5676 case OMP_CLAUSE_COPYPRIVATE:
5579 decl = OMP_CLAUSE_DECL (c); 5677 decl = OMP_CLAUSE_DECL (c);
5580 if (decl == error_mark_node || TREE_TYPE (decl) == error_mark_node) 5678 if (decl == error_mark_node || TREE_TYPE (decl) == error_mark_node)
5581 { 5679 {
5582 remove = true; 5680 remove = true;
5583 break; 5681 break;
5584 } 5682 }
5585 do_notice: 5683 do_notice:
5586 if (outer_ctx) 5684 if (outer_ctx)
5587 omp_notice_variable (outer_ctx, decl, true); 5685 omp_notice_variable (outer_ctx, decl, true);
5588 if (check_non_private 5686 if (check_non_private
5589 && region_type == ORT_WORKSHARE 5687 && region_type == ORT_WORKSHARE
5590 && omp_check_private (ctx, decl)) 5688 && omp_check_private (ctx, decl))
5591 { 5689 {
5592 error ("%s variable %qs is private in outer context", 5690 error ("%s variable %qE is private in outer context",
5593 check_non_private, IDENTIFIER_POINTER (DECL_NAME (decl))); 5691 check_non_private, DECL_NAME (decl));
5594 remove = true; 5692 remove = true;
5595 } 5693 }
5596 break; 5694 break;
5597 5695
5598 case OMP_CLAUSE_IF: 5696 case OMP_CLAUSE_IF:
5599 OMP_CLAUSE_OPERAND (c, 0) 5697 OMP_CLAUSE_OPERAND (c, 0)
5600 = gimple_boolify (OMP_CLAUSE_OPERAND (c, 0)); 5698 = gimple_boolify (OMP_CLAUSE_OPERAND (c, 0));
5601 /* Fall through. */ 5699 /* Fall through. */
5602 5700
5603 case OMP_CLAUSE_SCHEDULE: 5701 case OMP_CLAUSE_SCHEDULE:
5604 case OMP_CLAUSE_NUM_THREADS: 5702 case OMP_CLAUSE_NUM_THREADS:
5605 if (gimplify_expr (&OMP_CLAUSE_OPERAND (c, 0), pre_p, NULL, 5703 if (gimplify_expr (&OMP_CLAUSE_OPERAND (c, 0), pre_p, NULL,
5606 is_gimple_val, fb_rvalue) == GS_ERROR) 5704 is_gimple_val, fb_rvalue) == GS_ERROR)
5607 remove = true; 5705 remove = true;
5608 break; 5706 break;
5609 5707
5610 case OMP_CLAUSE_NOWAIT: 5708 case OMP_CLAUSE_NOWAIT:
5611 case OMP_CLAUSE_ORDERED: 5709 case OMP_CLAUSE_ORDERED:
5612 case OMP_CLAUSE_UNTIED: 5710 case OMP_CLAUSE_UNTIED:
5613 case OMP_CLAUSE_COLLAPSE: 5711 case OMP_CLAUSE_COLLAPSE:
5614 break; 5712 break;
5615 5713
5616 case OMP_CLAUSE_DEFAULT: 5714 case OMP_CLAUSE_DEFAULT:
5617 ctx->default_kind = OMP_CLAUSE_DEFAULT_KIND (c); 5715 ctx->default_kind = OMP_CLAUSE_DEFAULT_KIND (c);
5618 break; 5716 break;
5619 5717
5620 default: 5718 default:
5621 gcc_unreachable (); 5719 gcc_unreachable ();
5622 } 5720 }
5623 5721
5624 if (remove) 5722 if (remove)
5625 *list_p = OMP_CLAUSE_CHAIN (c); 5723 *list_p = OMP_CLAUSE_CHAIN (c);
5626 else 5724 else
5627 list_p = &OMP_CLAUSE_CHAIN (c); 5725 list_p = &OMP_CLAUSE_CHAIN (c);
5628 } 5726 }
5629 5727
5630 gimplify_omp_ctxp = ctx; 5728 gimplify_omp_ctxp = ctx;
5631 } 5729 }
5632 5730
5653 private_debug = true; 5751 private_debug = true;
5654 } 5752 }
5655 else 5753 else
5656 private_debug 5754 private_debug
5657 = lang_hooks.decls.omp_private_debug_clause (decl, 5755 = lang_hooks.decls.omp_private_debug_clause (decl,
5658 !!(flags & GOVD_SHARED)); 5756 !!(flags & GOVD_SHARED));
5659 if (private_debug) 5757 if (private_debug)
5660 code = OMP_CLAUSE_PRIVATE; 5758 code = OMP_CLAUSE_PRIVATE;
5661 else if (flags & GOVD_SHARED) 5759 else if (flags & GOVD_SHARED)
5662 { 5760 {
5663 if (is_global_var (decl)) 5761 if (is_global_var (decl))
5664 { 5762 {
5665 struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp->outer_context; 5763 struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp->outer_context;
5666 while (ctx != NULL) 5764 while (ctx != NULL)
5667 { 5765 {
5668 splay_tree_node on 5766 splay_tree_node on
5669 = splay_tree_lookup (ctx->variables, (splay_tree_key) decl); 5767 = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
5670 if (on && (on->value & (GOVD_FIRSTPRIVATE | GOVD_LASTPRIVATE 5768 if (on && (on->value & (GOVD_FIRSTPRIVATE | GOVD_LASTPRIVATE
5671 | GOVD_PRIVATE | GOVD_REDUCTION)) != 0) 5769 | GOVD_PRIVATE | GOVD_REDUCTION)) != 0)
5672 break; 5770 break;
5673 ctx = ctx->outer_context; 5771 ctx = ctx->outer_context;
5674 } 5772 }
5675 if (ctx == NULL) 5773 if (ctx == NULL)
5676 return 0; 5774 return 0;
5677 } 5775 }
5678 code = OMP_CLAUSE_SHARED; 5776 code = OMP_CLAUSE_SHARED;
5679 } 5777 }
5680 else if (flags & GOVD_PRIVATE) 5778 else if (flags & GOVD_PRIVATE)
5681 code = OMP_CLAUSE_PRIVATE; 5779 code = OMP_CLAUSE_PRIVATE;
5682 else if (flags & GOVD_FIRSTPRIVATE) 5780 else if (flags & GOVD_FIRSTPRIVATE)
5683 code = OMP_CLAUSE_FIRSTPRIVATE; 5781 code = OMP_CLAUSE_FIRSTPRIVATE;
5684 else 5782 else
5685 gcc_unreachable (); 5783 gcc_unreachable ();
5686 5784
5687 clause = build_omp_clause (code); 5785 clause = build_omp_clause (input_location, code);
5688 OMP_CLAUSE_DECL (clause) = decl; 5786 OMP_CLAUSE_DECL (clause) = decl;
5689 OMP_CLAUSE_CHAIN (clause) = *list_p; 5787 OMP_CLAUSE_CHAIN (clause) = *list_p;
5690 if (private_debug) 5788 if (private_debug)
5691 OMP_CLAUSE_PRIVATE_DEBUG (clause) = 1; 5789 OMP_CLAUSE_PRIVATE_DEBUG (clause) = 1;
5692 else if (code == OMP_CLAUSE_PRIVATE && (flags & GOVD_PRIVATE_OUTER_REF)) 5790 else if (code == OMP_CLAUSE_PRIVATE && (flags & GOVD_PRIVATE_OUTER_REF))
5707 { 5805 {
5708 splay_tree_node n; 5806 splay_tree_node n;
5709 bool remove = false; 5807 bool remove = false;
5710 5808
5711 switch (OMP_CLAUSE_CODE (c)) 5809 switch (OMP_CLAUSE_CODE (c))
5712 { 5810 {
5713 case OMP_CLAUSE_PRIVATE: 5811 case OMP_CLAUSE_PRIVATE:
5714 case OMP_CLAUSE_SHARED: 5812 case OMP_CLAUSE_SHARED:
5715 case OMP_CLAUSE_FIRSTPRIVATE: 5813 case OMP_CLAUSE_FIRSTPRIVATE:
5716 decl = OMP_CLAUSE_DECL (c); 5814 decl = OMP_CLAUSE_DECL (c);
5717 n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl); 5815 n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
5718 remove = !(n->value & GOVD_SEEN); 5816 remove = !(n->value & GOVD_SEEN);
5719 if (! remove) 5817 if (! remove)
5720 { 5818 {
5721 bool shared = OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED; 5819 bool shared = OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED;
5722 if ((n->value & GOVD_DEBUG_PRIVATE) 5820 if ((n->value & GOVD_DEBUG_PRIVATE)
5723 || lang_hooks.decls.omp_private_debug_clause (decl, shared)) 5821 || lang_hooks.decls.omp_private_debug_clause (decl, shared))
5724 { 5822 {
5725 gcc_assert ((n->value & GOVD_DEBUG_PRIVATE) == 0 5823 gcc_assert ((n->value & GOVD_DEBUG_PRIVATE) == 0
5726 || ((n->value & GOVD_DATA_SHARE_CLASS) 5824 || ((n->value & GOVD_DATA_SHARE_CLASS)
5727 == GOVD_PRIVATE)); 5825 == GOVD_PRIVATE));
5728 OMP_CLAUSE_SET_CODE (c, OMP_CLAUSE_PRIVATE); 5826 OMP_CLAUSE_SET_CODE (c, OMP_CLAUSE_PRIVATE);
5729 OMP_CLAUSE_PRIVATE_DEBUG (c) = 1; 5827 OMP_CLAUSE_PRIVATE_DEBUG (c) = 1;
5730 } 5828 }
5731 } 5829 }
5732 break; 5830 break;
5733 5831
5734 case OMP_CLAUSE_LASTPRIVATE: 5832 case OMP_CLAUSE_LASTPRIVATE:
5735 /* Make sure OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE is set to 5833 /* Make sure OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE is set to
5736 accurately reflect the presence of a FIRSTPRIVATE clause. */ 5834 accurately reflect the presence of a FIRSTPRIVATE clause. */
5737 decl = OMP_CLAUSE_DECL (c); 5835 decl = OMP_CLAUSE_DECL (c);
5738 n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl); 5836 n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
5739 OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c) 5837 OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c)
5740 = (n->value & GOVD_FIRSTPRIVATE) != 0; 5838 = (n->value & GOVD_FIRSTPRIVATE) != 0;
5741 break; 5839 break;
5742 5840
5743 case OMP_CLAUSE_REDUCTION: 5841 case OMP_CLAUSE_REDUCTION:
5744 case OMP_CLAUSE_COPYIN: 5842 case OMP_CLAUSE_COPYIN:
5745 case OMP_CLAUSE_COPYPRIVATE: 5843 case OMP_CLAUSE_COPYPRIVATE:
5746 case OMP_CLAUSE_IF: 5844 case OMP_CLAUSE_IF:
5747 case OMP_CLAUSE_NUM_THREADS: 5845 case OMP_CLAUSE_NUM_THREADS:
5748 case OMP_CLAUSE_SCHEDULE: 5846 case OMP_CLAUSE_SCHEDULE:
5749 case OMP_CLAUSE_NOWAIT: 5847 case OMP_CLAUSE_NOWAIT:
5750 case OMP_CLAUSE_ORDERED: 5848 case OMP_CLAUSE_ORDERED:
5751 case OMP_CLAUSE_DEFAULT: 5849 case OMP_CLAUSE_DEFAULT:
5752 case OMP_CLAUSE_UNTIED: 5850 case OMP_CLAUSE_UNTIED:
5753 case OMP_CLAUSE_COLLAPSE: 5851 case OMP_CLAUSE_COLLAPSE:
5754 break; 5852 break;
5755 5853
5756 default: 5854 default:
5757 gcc_unreachable (); 5855 gcc_unreachable ();
5758 } 5856 }
5759 5857
5760 if (remove) 5858 if (remove)
5761 *list_p = OMP_CLAUSE_CHAIN (c); 5859 *list_p = OMP_CLAUSE_CHAIN (c);
5762 else 5860 else
5763 list_p = &OMP_CLAUSE_CHAIN (c); 5861 list_p = &OMP_CLAUSE_CHAIN (c);
5764 } 5862 }
5765 5863
5766 /* Add in any implicit data sharing. */ 5864 /* Add in any implicit data sharing. */
5767 splay_tree_foreach (ctx->variables, gimplify_adjust_omp_clauses_1, list_p); 5865 splay_tree_foreach (ctx->variables, gimplify_adjust_omp_clauses_1, list_p);
5768 5866
5769 gimplify_omp_ctxp = ctx->outer_context; 5867 gimplify_omp_ctxp = ctx->outer_context;
5770 delete_omp_context (ctx); 5868 delete_omp_context (ctx);
5771 } 5869 }
5772 5870
5773 /* Gimplify the contents of an OMP_PARALLEL statement. This involves 5871 /* Gimplify the contents of an OMP_PARALLEL statement. This involves
5782 gimple g; 5880 gimple g;
5783 gimple_seq body = NULL; 5881 gimple_seq body = NULL;
5784 struct gimplify_ctx gctx; 5882 struct gimplify_ctx gctx;
5785 5883
5786 gimplify_scan_omp_clauses (&OMP_PARALLEL_CLAUSES (expr), pre_p, 5884 gimplify_scan_omp_clauses (&OMP_PARALLEL_CLAUSES (expr), pre_p,
5787 OMP_PARALLEL_COMBINED (expr) 5885 OMP_PARALLEL_COMBINED (expr)
5788 ? ORT_COMBINED_PARALLEL 5886 ? ORT_COMBINED_PARALLEL
5789 : ORT_PARALLEL); 5887 : ORT_PARALLEL);
5790 5888
5791 push_gimplify_context (&gctx); 5889 push_gimplify_context (&gctx);
5792 5890
5793 g = gimplify_and_return_first (OMP_PARALLEL_BODY (expr), &body); 5891 g = gimplify_and_return_first (OMP_PARALLEL_BODY (expr), &body);
5794 if (gimple_code (g) == GIMPLE_BIND) 5892 if (gimple_code (g) == GIMPLE_BIND)
5797 pop_gimplify_context (NULL); 5895 pop_gimplify_context (NULL);
5798 5896
5799 gimplify_adjust_omp_clauses (&OMP_PARALLEL_CLAUSES (expr)); 5897 gimplify_adjust_omp_clauses (&OMP_PARALLEL_CLAUSES (expr));
5800 5898
5801 g = gimple_build_omp_parallel (body, 5899 g = gimple_build_omp_parallel (body,
5802 OMP_PARALLEL_CLAUSES (expr), 5900 OMP_PARALLEL_CLAUSES (expr),
5803 NULL_TREE, NULL_TREE); 5901 NULL_TREE, NULL_TREE);
5804 if (OMP_PARALLEL_COMBINED (expr)) 5902 if (OMP_PARALLEL_COMBINED (expr))
5805 gimple_omp_set_subcode (g, GF_OMP_PARALLEL_COMBINED); 5903 gimple_omp_set_subcode (g, GF_OMP_PARALLEL_COMBINED);
5806 gimplify_seq_add_stmt (pre_p, g); 5904 gimplify_seq_add_stmt (pre_p, g);
5807 *expr_p = NULL_TREE; 5905 *expr_p = NULL_TREE;
5808 } 5906 }
5831 pop_gimplify_context (NULL); 5929 pop_gimplify_context (NULL);
5832 5930
5833 gimplify_adjust_omp_clauses (&OMP_TASK_CLAUSES (expr)); 5931 gimplify_adjust_omp_clauses (&OMP_TASK_CLAUSES (expr));
5834 5932
5835 g = gimple_build_omp_task (body, 5933 g = gimple_build_omp_task (body,
5836 OMP_TASK_CLAUSES (expr), 5934 OMP_TASK_CLAUSES (expr),
5837 NULL_TREE, NULL_TREE, 5935 NULL_TREE, NULL_TREE,
5838 NULL_TREE, NULL_TREE, NULL_TREE); 5936 NULL_TREE, NULL_TREE, NULL_TREE);
5839 gimplify_seq_add_stmt (pre_p, g); 5937 gimplify_seq_add_stmt (pre_p, g);
5840 *expr_p = NULL_TREE; 5938 *expr_p = NULL_TREE;
5841 } 5939 }
5842 5940
5843 /* Gimplify the gross structure of an OMP_FOR statement. */ 5941 /* Gimplify the gross structure of an OMP_FOR statement. */
5844 5942
5845 static enum gimplify_status 5943 static enum gimplify_status
5846 gimplify_omp_for (tree *expr_p, gimple_seq *pre_p) 5944 gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
5847 { 5945 {
5848 tree for_stmt, decl, var, t; 5946 tree for_stmt, decl, var, t;
5849 enum gimplify_status ret = GS_OK; 5947 enum gimplify_status ret = GS_ALL_DONE;
5948 enum gimplify_status tret;
5850 gimple gfor; 5949 gimple gfor;
5851 gimple_seq for_body, for_pre_body; 5950 gimple_seq for_body, for_pre_body;
5852 int i; 5951 int i;
5853 5952
5854 for_stmt = *expr_p; 5953 for_stmt = *expr_p;
5855 5954
5856 gimplify_scan_omp_clauses (&OMP_FOR_CLAUSES (for_stmt), pre_p, 5955 gimplify_scan_omp_clauses (&OMP_FOR_CLAUSES (for_stmt), pre_p,
5857 ORT_WORKSHARE); 5956 ORT_WORKSHARE);
5858 5957
5859 /* Handle OMP_FOR_INIT. */ 5958 /* Handle OMP_FOR_INIT. */
5860 for_pre_body = NULL; 5959 for_pre_body = NULL;
5861 gimplify_and_add (OMP_FOR_PRE_BODY (for_stmt), &for_pre_body); 5960 gimplify_and_add (OMP_FOR_PRE_BODY (for_stmt), &for_pre_body);
5862 OMP_FOR_PRE_BODY (for_stmt) = NULL_TREE; 5961 OMP_FOR_PRE_BODY (for_stmt) = NULL_TREE;
5863 5962
5864 for_body = gimple_seq_alloc (); 5963 for_body = gimple_seq_alloc ();
5865 gcc_assert (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)) 5964 gcc_assert (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt))
5866 == TREE_VEC_LENGTH (OMP_FOR_COND (for_stmt))); 5965 == TREE_VEC_LENGTH (OMP_FOR_COND (for_stmt)));
5867 gcc_assert (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)) 5966 gcc_assert (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt))
5868 == TREE_VEC_LENGTH (OMP_FOR_INCR (for_stmt))); 5967 == TREE_VEC_LENGTH (OMP_FOR_INCR (for_stmt)));
5869 for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); i++) 5968 for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); i++)
5870 { 5969 {
5871 t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i); 5970 t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i);
5872 gcc_assert (TREE_CODE (t) == MODIFY_EXPR); 5971 gcc_assert (TREE_CODE (t) == MODIFY_EXPR);
5873 decl = TREE_OPERAND (t, 0); 5972 decl = TREE_OPERAND (t, 0);
5874 gcc_assert (DECL_P (decl)); 5973 gcc_assert (DECL_P (decl));
5875 gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (decl)) 5974 gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (decl))
5876 || POINTER_TYPE_P (TREE_TYPE (decl))); 5975 || POINTER_TYPE_P (TREE_TYPE (decl)));
5877 5976
5878 /* Make sure the iteration variable is private. */ 5977 /* Make sure the iteration variable is private. */
5879 if (omp_is_private (gimplify_omp_ctxp, decl)) 5978 if (omp_is_private (gimplify_omp_ctxp, decl))
5880 omp_notice_variable (gimplify_omp_ctxp, decl, true); 5979 omp_notice_variable (gimplify_omp_ctxp, decl, true);
5881 else 5980 else
5882 omp_add_variable (gimplify_omp_ctxp, decl, GOVD_PRIVATE | GOVD_SEEN); 5981 omp_add_variable (gimplify_omp_ctxp, decl, GOVD_PRIVATE | GOVD_SEEN);
5883 5982
5884 /* If DECL is not a gimple register, create a temporary variable to act 5983 /* If DECL is not a gimple register, create a temporary variable to act
5885 as an iteration counter. This is valid, since DECL cannot be 5984 as an iteration counter. This is valid, since DECL cannot be
5886 modified in the body of the loop. */ 5985 modified in the body of the loop. */
5887 if (!is_gimple_reg (decl)) 5986 if (!is_gimple_reg (decl))
5888 { 5987 {
5889 var = create_tmp_var (TREE_TYPE (decl), get_name (decl)); 5988 var = create_tmp_var (TREE_TYPE (decl), get_name (decl));
5890 TREE_OPERAND (t, 0) = var; 5989 TREE_OPERAND (t, 0) = var;
5891 5990
5892 gimplify_seq_add_stmt (&for_body, gimple_build_assign (decl, var)); 5991 gimplify_seq_add_stmt (&for_body, gimple_build_assign (decl, var));
5893 5992
5894 omp_add_variable (gimplify_omp_ctxp, var, GOVD_PRIVATE | GOVD_SEEN); 5993 omp_add_variable (gimplify_omp_ctxp, var, GOVD_PRIVATE | GOVD_SEEN);
5895 } 5994 }
5896 else 5995 else
5897 var = decl; 5996 var = decl;
5898 5997
5899 ret |= gimplify_expr (&TREE_OPERAND (t, 1), &for_pre_body, NULL, 5998 tret = gimplify_expr (&TREE_OPERAND (t, 1), &for_pre_body, NULL,
5900 is_gimple_val, fb_rvalue); 5999 is_gimple_val, fb_rvalue);
6000 ret = MIN (ret, tret);
5901 if (ret == GS_ERROR) 6001 if (ret == GS_ERROR)
5902 return ret; 6002 return ret;
5903 6003
5904 /* Handle OMP_FOR_COND. */ 6004 /* Handle OMP_FOR_COND. */
5905 t = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), i); 6005 t = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), i);
5906 gcc_assert (COMPARISON_CLASS_P (t)); 6006 gcc_assert (COMPARISON_CLASS_P (t));
5907 gcc_assert (TREE_OPERAND (t, 0) == decl); 6007 gcc_assert (TREE_OPERAND (t, 0) == decl);
5908 6008
5909 ret |= gimplify_expr (&TREE_OPERAND (t, 1), &for_pre_body, NULL, 6009 tret = gimplify_expr (&TREE_OPERAND (t, 1), &for_pre_body, NULL,
5910 is_gimple_val, fb_rvalue); 6010 is_gimple_val, fb_rvalue);
6011 ret = MIN (ret, tret);
5911 6012
5912 /* Handle OMP_FOR_INCR. */ 6013 /* Handle OMP_FOR_INCR. */
5913 t = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i); 6014 t = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i);
5914 switch (TREE_CODE (t)) 6015 switch (TREE_CODE (t))
5915 { 6016 {
5916 case PREINCREMENT_EXPR: 6017 case PREINCREMENT_EXPR:
5917 case POSTINCREMENT_EXPR: 6018 case POSTINCREMENT_EXPR:
5918 t = build_int_cst (TREE_TYPE (decl), 1); 6019 t = build_int_cst (TREE_TYPE (decl), 1);
5919 t = build2 (PLUS_EXPR, TREE_TYPE (decl), var, t); 6020 t = build2 (PLUS_EXPR, TREE_TYPE (decl), var, t);
5920 t = build2 (MODIFY_EXPR, TREE_TYPE (var), var, t); 6021 t = build2 (MODIFY_EXPR, TREE_TYPE (var), var, t);
5921 TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i) = t; 6022 TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i) = t;
5922 break; 6023 break;
5923 6024
5924 case PREDECREMENT_EXPR: 6025 case PREDECREMENT_EXPR:
5925 case POSTDECREMENT_EXPR: 6026 case POSTDECREMENT_EXPR:
5926 t = build_int_cst (TREE_TYPE (decl), -1); 6027 t = build_int_cst (TREE_TYPE (decl), -1);
5927 t = build2 (PLUS_EXPR, TREE_TYPE (decl), var, t); 6028 t = build2 (PLUS_EXPR, TREE_TYPE (decl), var, t);
5928 t = build2 (MODIFY_EXPR, TREE_TYPE (var), var, t); 6029 t = build2 (MODIFY_EXPR, TREE_TYPE (var), var, t);
5929 TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i) = t; 6030 TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i) = t;
5930 break; 6031 break;
5931 6032
5932 case MODIFY_EXPR: 6033 case MODIFY_EXPR:
5933 gcc_assert (TREE_OPERAND (t, 0) == decl); 6034 gcc_assert (TREE_OPERAND (t, 0) == decl);
5934 TREE_OPERAND (t, 0) = var; 6035 TREE_OPERAND (t, 0) = var;
5935 6036
5936 t = TREE_OPERAND (t, 1); 6037 t = TREE_OPERAND (t, 1);
5937 switch (TREE_CODE (t)) 6038 switch (TREE_CODE (t))
5938 { 6039 {
5939 case PLUS_EXPR: 6040 case PLUS_EXPR:
5940 if (TREE_OPERAND (t, 1) == decl) 6041 if (TREE_OPERAND (t, 1) == decl)
5941 { 6042 {
5942 TREE_OPERAND (t, 1) = TREE_OPERAND (t, 0); 6043 TREE_OPERAND (t, 1) = TREE_OPERAND (t, 0);
5943 TREE_OPERAND (t, 0) = var; 6044 TREE_OPERAND (t, 0) = var;
5944 break; 6045 break;
5945 } 6046 }
5946 6047
5947 /* Fallthru. */ 6048 /* Fallthru. */
5948 case MINUS_EXPR: 6049 case MINUS_EXPR:
5949 case POINTER_PLUS_EXPR: 6050 case POINTER_PLUS_EXPR:
5950 gcc_assert (TREE_OPERAND (t, 0) == decl); 6051 gcc_assert (TREE_OPERAND (t, 0) == decl);
5951 TREE_OPERAND (t, 0) = var; 6052 TREE_OPERAND (t, 0) = var;
5952 break; 6053 break;
5953 default: 6054 default:
5954 gcc_unreachable (); 6055 gcc_unreachable ();
5955 } 6056 }
5956 6057
5957 ret |= gimplify_expr (&TREE_OPERAND (t, 1), &for_pre_body, NULL, 6058 tret = gimplify_expr (&TREE_OPERAND (t, 1), &for_pre_body, NULL,
5958 is_gimple_val, fb_rvalue); 6059 is_gimple_val, fb_rvalue);
5959 break; 6060 ret = MIN (ret, tret);
5960 6061 break;
5961 default: 6062
5962 gcc_unreachable (); 6063 default:
5963 } 6064 gcc_unreachable ();
6065 }
5964 6066
5965 if (var != decl || TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)) > 1) 6067 if (var != decl || TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)) > 1)
5966 { 6068 {
5967 tree c; 6069 tree c;
5968 for (c = OMP_FOR_CLAUSES (for_stmt); c ; c = OMP_CLAUSE_CHAIN (c)) 6070 for (c = OMP_FOR_CLAUSES (for_stmt); c ; c = OMP_CLAUSE_CHAIN (c))
5969 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE 6071 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
5970 && OMP_CLAUSE_DECL (c) == decl 6072 && OMP_CLAUSE_DECL (c) == decl
5971 && OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c) == NULL) 6073 && OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c) == NULL)
5972 { 6074 {
5973 t = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i); 6075 t = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i);
5974 gcc_assert (TREE_CODE (t) == MODIFY_EXPR); 6076 gcc_assert (TREE_CODE (t) == MODIFY_EXPR);
5975 gcc_assert (TREE_OPERAND (t, 0) == var); 6077 gcc_assert (TREE_OPERAND (t, 0) == var);
5976 t = TREE_OPERAND (t, 1); 6078 t = TREE_OPERAND (t, 1);
5977 gcc_assert (TREE_CODE (t) == PLUS_EXPR 6079 gcc_assert (TREE_CODE (t) == PLUS_EXPR
5978 || TREE_CODE (t) == MINUS_EXPR 6080 || TREE_CODE (t) == MINUS_EXPR
5979 || TREE_CODE (t) == POINTER_PLUS_EXPR); 6081 || TREE_CODE (t) == POINTER_PLUS_EXPR);
5980 gcc_assert (TREE_OPERAND (t, 0) == var); 6082 gcc_assert (TREE_OPERAND (t, 0) == var);
5981 t = build2 (TREE_CODE (t), TREE_TYPE (decl), decl, 6083 t = build2 (TREE_CODE (t), TREE_TYPE (decl), decl,
5982 TREE_OPERAND (t, 1)); 6084 TREE_OPERAND (t, 1));
5983 gimplify_assign (decl, t, 6085 gimplify_assign (decl, t,
5984 &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c)); 6086 &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c));
5985 } 6087 }
5986 } 6088 }
5987 } 6089 }
5988 6090
5989 gimplify_and_add (OMP_FOR_BODY (for_stmt), &for_body); 6091 gimplify_and_add (OMP_FOR_BODY (for_stmt), &for_body);
5990 6092
5991 gimplify_adjust_omp_clauses (&OMP_FOR_CLAUSES (for_stmt)); 6093 gimplify_adjust_omp_clauses (&OMP_FOR_CLAUSES (for_stmt));
5992 6094
5993 gfor = gimple_build_omp_for (for_body, OMP_FOR_CLAUSES (for_stmt), 6095 gfor = gimple_build_omp_for (for_body, OMP_FOR_CLAUSES (for_stmt),
5994 TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)), 6096 TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)),
5995 for_pre_body); 6097 for_pre_body);
5996 6098
5997 for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); i++) 6099 for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); i++)
5998 { 6100 {
5999 t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i); 6101 t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i);
6000 gimple_omp_for_set_index (gfor, i, TREE_OPERAND (t, 0)); 6102 gimple_omp_for_set_index (gfor, i, TREE_OPERAND (t, 0));
6033 6135
6034 gimplify_seq_add_stmt (pre_p, stmt); 6136 gimplify_seq_add_stmt (pre_p, stmt);
6035 } 6137 }
6036 6138
6037 /* A subroutine of gimplify_omp_atomic. The front end is supposed to have 6139 /* A subroutine of gimplify_omp_atomic. The front end is supposed to have
6038 stabilized the lhs of the atomic operation as *ADDR. Return true if 6140 stabilized the lhs of the atomic operation as *ADDR. Return true if
6039 EXPR is this stabilized form. */ 6141 EXPR is this stabilized form. */
6040 6142
6041 static bool 6143 static bool
6042 goa_lhs_expr_p (tree expr, tree addr) 6144 goa_lhs_expr_p (tree expr, tree addr)
6043 { 6145 {
6044 /* Also include casts to other type variants. The C front end is fond 6146 /* Also include casts to other type variants. The C front end is fond
6045 of adding these for e.g. volatile variables. This is like 6147 of adding these for e.g. volatile variables. This is like
6046 STRIP_TYPE_NOPS but includes the main variant lookup. */ 6148 STRIP_TYPE_NOPS but includes the main variant lookup. */
6047 while ((CONVERT_EXPR_P (expr) 6149 STRIP_USELESS_TYPE_CONVERSION (expr);
6048 || TREE_CODE (expr) == NON_LVALUE_EXPR)
6049 && TREE_OPERAND (expr, 0) != error_mark_node
6050 && (TYPE_MAIN_VARIANT (TREE_TYPE (expr))
6051 == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (expr, 0)))))
6052 expr = TREE_OPERAND (expr, 0);
6053 6150
6054 if (TREE_CODE (expr) == INDIRECT_REF) 6151 if (TREE_CODE (expr) == INDIRECT_REF)
6055 { 6152 {
6056 expr = TREE_OPERAND (expr, 0); 6153 expr = TREE_OPERAND (expr, 0);
6057 while (expr != addr 6154 while (expr != addr
6058 && (CONVERT_EXPR_P (expr) 6155 && (CONVERT_EXPR_P (expr)
6059 || TREE_CODE (expr) == NON_LVALUE_EXPR) 6156 || TREE_CODE (expr) == NON_LVALUE_EXPR)
6060 && TREE_CODE (expr) == TREE_CODE (addr) 6157 && TREE_CODE (expr) == TREE_CODE (addr)
6061 && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) 6158 && types_compatible_p (TREE_TYPE (expr), TREE_TYPE (addr)))
6062 == TYPE_MAIN_VARIANT (TREE_TYPE (addr))) 6159 {
6063 { 6160 expr = TREE_OPERAND (expr, 0);
6064 expr = TREE_OPERAND (expr, 0); 6161 addr = TREE_OPERAND (addr, 0);
6065 addr = TREE_OPERAND (addr, 0); 6162 }
6066 }
6067 if (expr == addr) 6163 if (expr == addr)
6068 return true; 6164 return true;
6069 return (TREE_CODE (addr) == ADDR_EXPR 6165 return (TREE_CODE (addr) == ADDR_EXPR
6070 && TREE_CODE (expr) == ADDR_EXPR 6166 && TREE_CODE (expr) == ADDR_EXPR
6071 && TREE_OPERAND (addr, 0) == TREE_OPERAND (expr, 0)); 6167 && TREE_OPERAND (addr, 0) == TREE_OPERAND (expr, 0));
6072 } 6168 }
6073 if (TREE_CODE (addr) == ADDR_EXPR && expr == TREE_OPERAND (addr, 0)) 6169 if (TREE_CODE (addr) == ADDR_EXPR && expr == TREE_OPERAND (addr, 0))
6074 return true; 6170 return true;
6075 return false; 6171 return false;
6076 } 6172 }
6080 the lhs, evaluate it into a temporary. Return 1 if the lhs appeared as 6176 the lhs, evaluate it into a temporary. Return 1 if the lhs appeared as
6081 a subexpression, 0 if it did not, or -1 if an error was encountered. */ 6177 a subexpression, 0 if it did not, or -1 if an error was encountered. */
6082 6178
6083 static int 6179 static int
6084 goa_stabilize_expr (tree *expr_p, gimple_seq *pre_p, tree lhs_addr, 6180 goa_stabilize_expr (tree *expr_p, gimple_seq *pre_p, tree lhs_addr,
6085 tree lhs_var) 6181 tree lhs_var)
6086 { 6182 {
6087 tree expr = *expr_p; 6183 tree expr = *expr_p;
6088 int saw_lhs; 6184 int saw_lhs;
6089 6185
6090 if (goa_lhs_expr_p (expr, lhs_addr)) 6186 if (goa_lhs_expr_p (expr, lhs_addr))
6092 *expr_p = lhs_var; 6188 *expr_p = lhs_var;
6093 return 1; 6189 return 1;
6094 } 6190 }
6095 if (is_gimple_val (expr)) 6191 if (is_gimple_val (expr))
6096 return 0; 6192 return 0;
6097 6193
6098 saw_lhs = 0; 6194 saw_lhs = 0;
6099 switch (TREE_CODE_CLASS (TREE_CODE (expr))) 6195 switch (TREE_CODE_CLASS (TREE_CODE (expr)))
6100 { 6196 {
6101 case tcc_binary: 6197 case tcc_binary:
6102 case tcc_comparison: 6198 case tcc_comparison:
6103 saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 1), pre_p, lhs_addr, 6199 saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 1), pre_p, lhs_addr,
6104 lhs_var); 6200 lhs_var);
6105 case tcc_unary: 6201 case tcc_unary:
6106 saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 0), pre_p, lhs_addr, 6202 saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 0), pre_p, lhs_addr,
6107 lhs_var); 6203 lhs_var);
6108 break; 6204 break;
6109 case tcc_expression: 6205 case tcc_expression:
6110 switch (TREE_CODE (expr)) 6206 switch (TREE_CODE (expr))
6111 { 6207 {
6112 case TRUTH_ANDIF_EXPR: 6208 case TRUTH_ANDIF_EXPR:
6113 case TRUTH_ORIF_EXPR: 6209 case TRUTH_ORIF_EXPR:
6114 saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 1), pre_p, 6210 saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 1), pre_p,
6115 lhs_addr, lhs_var); 6211 lhs_addr, lhs_var);
6116 saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 0), pre_p, 6212 saw_lhs |= goa_stabilize_expr (&TREE_OPERAND (expr, 0), pre_p,
6117 lhs_addr, lhs_var); 6213 lhs_addr, lhs_var);
6118 break; 6214 break;
6119 default: 6215 default:
6120 break; 6216 break;
6121 } 6217 }
6122 break; 6218 break;
6123 default: 6219 default:
6124 break; 6220 break;
6125 } 6221 }
6126 6222
6127 if (saw_lhs == 0) 6223 if (saw_lhs == 0)
6128 { 6224 {
6129 enum gimplify_status gs; 6225 enum gimplify_status gs;
6130 gs = gimplify_expr (expr_p, pre_p, NULL, is_gimple_val, fb_rvalue); 6226 gs = gimplify_expr (expr_p, pre_p, NULL, is_gimple_val, fb_rvalue);
6131 if (gs != GS_ALL_DONE) 6227 if (gs != GS_ALL_DONE)
6132 saw_lhs = -1; 6228 saw_lhs = -1;
6133 } 6229 }
6134 6230
6135 return saw_lhs; 6231 return saw_lhs;
6136 } 6232 }
6137 6233
6205 side-effects of '--' must actually occur *after* the post 6301 side-effects of '--' must actually occur *after* the post
6206 side-effects of '++'. However, gimplification will first visit 6302 side-effects of '++'. However, gimplification will first visit
6207 the inner expression, so if a separate POST sequence was not 6303 the inner expression, so if a separate POST sequence was not
6208 used, the resulting sequence would be: 6304 used, the resulting sequence would be:
6209 6305
6210 1 t.1 = *p 6306 1 t.1 = *p
6211 2 p = p - 1 6307 2 p = p - 1
6212 3 t.2 = t.1 + 1 6308 3 t.2 = t.1 + 1
6213 4 *p = t.2 6309 4 *p = t.2
6214 6310
6215 However, the post-decrement operation in line #2 must not be 6311 However, the post-decrement operation in line #2 must not be
6216 evaluated until after the store to *p at line #4, so the 6312 evaluated until after the store to *p at line #4, so the
6217 correct sequence should be: 6313 correct sequence should be:
6218 6314
6219 1 t.1 = *p 6315 1 t.1 = *p
6220 2 t.2 = t.1 + 1 6316 2 t.2 = t.1 + 1
6221 3 *p = t.2 6317 3 *p = t.2
6222 4 p = p - 1 6318 4 p = p - 1
6223 6319
6224 So, by specifying a separate post queue, it is possible 6320 So, by specifying a separate post queue, it is possible
6225 to emit the post side-effects in the correct order. 6321 to emit the post side-effects in the correct order.
6226 If POST_P is NULL, an internal queue will be used. Before 6322 If POST_P is NULL, an internal queue will be used. Before
6227 returning to the caller, the sequence POST_P is appended to 6323 returning to the caller, the sequence POST_P is appended to
6246 function iterates until EXPR is completely gimplified or an error 6342 function iterates until EXPR is completely gimplified or an error
6247 occurs. */ 6343 occurs. */
6248 6344
6249 enum gimplify_status 6345 enum gimplify_status
6250 gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, 6346 gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
6251 bool (*gimple_test_f) (tree), fallback_t fallback) 6347 bool (*gimple_test_f) (tree), fallback_t fallback)
6252 { 6348 {
6253 tree tmp; 6349 tree tmp;
6254 gimple_seq internal_pre = NULL; 6350 gimple_seq internal_pre = NULL;
6255 gimple_seq internal_post = NULL; 6351 gimple_seq internal_post = NULL;
6256 tree save_expr; 6352 tree save_expr;
6270 6366
6271 /* Consistency checks. */ 6367 /* Consistency checks. */
6272 if (gimple_test_f == is_gimple_reg) 6368 if (gimple_test_f == is_gimple_reg)
6273 gcc_assert (fallback & (fb_rvalue | fb_lvalue)); 6369 gcc_assert (fallback & (fb_rvalue | fb_lvalue));
6274 else if (gimple_test_f == is_gimple_val 6370 else if (gimple_test_f == is_gimple_val
6275 || gimple_test_f == is_gimple_formal_tmp_rhs
6276 || gimple_test_f == is_gimple_formal_tmp_or_call_rhs
6277 || gimple_test_f == is_gimple_formal_tmp_reg
6278 || gimple_test_f == is_gimple_formal_tmp_var
6279 || gimple_test_f == is_gimple_call_addr 6371 || gimple_test_f == is_gimple_call_addr
6280 || gimple_test_f == is_gimple_condexpr 6372 || gimple_test_f == is_gimple_condexpr
6281 || gimple_test_f == is_gimple_mem_rhs 6373 || gimple_test_f == is_gimple_mem_rhs
6282 || gimple_test_f == is_gimple_mem_or_call_rhs 6374 || gimple_test_f == is_gimple_mem_rhs_or_call
6283 || gimple_test_f == is_gimple_reg_rhs 6375 || gimple_test_f == is_gimple_reg_rhs
6284 || gimple_test_f == is_gimple_reg_or_call_rhs 6376 || gimple_test_f == is_gimple_reg_rhs_or_call
6285 || gimple_test_f == is_gimple_asm_val) 6377 || gimple_test_f == is_gimple_asm_val)
6286 gcc_assert (fallback & fb_rvalue); 6378 gcc_assert (fallback & fb_rvalue);
6287 else if (gimple_test_f == is_gimple_min_lval 6379 else if (gimple_test_f == is_gimple_min_lval
6288 || gimple_test_f == is_gimple_lvalue) 6380 || gimple_test_f == is_gimple_lvalue)
6289 gcc_assert (fallback & fb_lvalue); 6381 gcc_assert (fallback & fb_lvalue);
6290 else if (gimple_test_f == is_gimple_addressable) 6382 else if (gimple_test_f == is_gimple_addressable)
6291 gcc_assert (fallback & fb_either); 6383 gcc_assert (fallback & fb_either);
6292 else if (gimple_test_f == is_gimple_stmt) 6384 else if (gimple_test_f == is_gimple_stmt)
6293 gcc_assert (fallback == fb_none); 6385 gcc_assert (fallback == fb_none);
6294 else 6386 else
6295 { 6387 {
6296 /* We should have recognized the GIMPLE_TEST_F predicate to 6388 /* We should have recognized the GIMPLE_TEST_F predicate to
6297 know what kind of fallback to use in case a temporary is 6389 know what kind of fallback to use in case a temporary is
6298 needed to hold the value or address of *EXPR_P. */ 6390 needed to hold the value or address of *EXPR_P. */
6299 gcc_unreachable (); 6391 gcc_unreachable ();
6300 } 6392 }
6301 6393
6302 /* We used to check the predicate here and return immediately if it 6394 /* We used to check the predicate here and return immediately if it
6303 succeeds. This is wrong; the design is for gimplification to be 6395 succeeds. This is wrong; the design is for gimplification to be
6328 /* Loop over the specific gimplifiers until the toplevel node 6420 /* Loop over the specific gimplifiers until the toplevel node
6329 remains the same. */ 6421 remains the same. */
6330 do 6422 do
6331 { 6423 {
6332 /* Strip away as many useless type conversions as possible 6424 /* Strip away as many useless type conversions as possible
6333 at the toplevel. */ 6425 at the toplevel. */
6334 STRIP_USELESS_TYPE_CONVERSION (*expr_p); 6426 STRIP_USELESS_TYPE_CONVERSION (*expr_p);
6335 6427
6336 /* Remember the expr. */ 6428 /* Remember the expr. */
6337 save_expr = *expr_p; 6429 save_expr = *expr_p;
6338 6430
6339 /* Die, die, die, my darling. */ 6431 /* Die, die, die, my darling. */
6340 if (save_expr == error_mark_node 6432 if (save_expr == error_mark_node
6341 || (TREE_TYPE (save_expr) 6433 || (TREE_TYPE (save_expr)
6342 && TREE_TYPE (save_expr) == error_mark_node)) 6434 && TREE_TYPE (save_expr) == error_mark_node))
6343 { 6435 {
6344 ret = GS_ERROR; 6436 ret = GS_ERROR;
6345 break; 6437 break;
6346 } 6438 }
6347 6439
6348 /* Do any language-specific gimplification. */ 6440 /* Do any language-specific gimplification. */
6349 ret = lang_hooks.gimplify_expr (expr_p, pre_p, post_p); 6441 ret = ((enum gimplify_status)
6442 lang_hooks.gimplify_expr (expr_p, pre_p, post_p));
6350 if (ret == GS_OK) 6443 if (ret == GS_OK)
6351 { 6444 {
6352 if (*expr_p == NULL_TREE) 6445 if (*expr_p == NULL_TREE)
6353 break; 6446 break;
6354 if (*expr_p != save_expr) 6447 if (*expr_p != save_expr)
6355 continue; 6448 continue;
6356 } 6449 }
6357 else if (ret != GS_UNHANDLED) 6450 else if (ret != GS_UNHANDLED)
6358 break; 6451 break;
6359 6452
6360 ret = GS_OK; 6453 ret = GS_OK;
6361 switch (TREE_CODE (*expr_p)) 6454 switch (TREE_CODE (*expr_p))
6362 { 6455 {
6363 /* First deal with the special cases. */ 6456 /* First deal with the special cases. */
6364 6457
6365 case POSTINCREMENT_EXPR: 6458 case POSTINCREMENT_EXPR:
6366 case POSTDECREMENT_EXPR: 6459 case POSTDECREMENT_EXPR:
6367 case PREINCREMENT_EXPR: 6460 case PREINCREMENT_EXPR:
6368 case PREDECREMENT_EXPR: 6461 case PREDECREMENT_EXPR:
6369 ret = gimplify_self_mod_expr (expr_p, pre_p, post_p, 6462 ret = gimplify_self_mod_expr (expr_p, pre_p, post_p,
6370 fallback != fb_none); 6463 fallback != fb_none);
6371 break; 6464 break;
6372 6465
6373 case ARRAY_REF: 6466 case ARRAY_REF:
6374 case ARRAY_RANGE_REF: 6467 case ARRAY_RANGE_REF:
6375 case REALPART_EXPR: 6468 case REALPART_EXPR:
6376 case IMAGPART_EXPR: 6469 case IMAGPART_EXPR:
6377 case COMPONENT_REF: 6470 case COMPONENT_REF:
6378 case VIEW_CONVERT_EXPR: 6471 case VIEW_CONVERT_EXPR:
6379 ret = gimplify_compound_lval (expr_p, pre_p, post_p, 6472 ret = gimplify_compound_lval (expr_p, pre_p, post_p,
6380 fallback ? fallback : fb_rvalue); 6473 fallback ? fallback : fb_rvalue);
6381 break; 6474 break;
6382 6475
6383 case COND_EXPR: 6476 case COND_EXPR:
6384 ret = gimplify_cond_expr (expr_p, pre_p, fallback); 6477 ret = gimplify_cond_expr (expr_p, pre_p, fallback);
6385 6478
6386 /* C99 code may assign to an array in a structure value of a 6479 /* C99 code may assign to an array in a structure value of a
6387 conditional expression, and this has undefined behavior 6480 conditional expression, and this has undefined behavior
6388 only on execution, so create a temporary if an lvalue is 6481 only on execution, so create a temporary if an lvalue is
6389 required. */ 6482 required. */
6390 if (fallback == fb_lvalue) 6483 if (fallback == fb_lvalue)
6391 { 6484 {
6392 *expr_p = get_initialized_tmp_var (*expr_p, pre_p, post_p); 6485 *expr_p = get_initialized_tmp_var (*expr_p, pre_p, post_p);
6393 mark_addressable (*expr_p); 6486 mark_addressable (*expr_p);
6394 } 6487 }
6395 break; 6488 break;
6396 6489
6397 case CALL_EXPR: 6490 case CALL_EXPR:
6398 ret = gimplify_call_expr (expr_p, pre_p, fallback != fb_none); 6491 ret = gimplify_call_expr (expr_p, pre_p, fallback != fb_none);
6399 6492
6400 /* C99 code may assign to an array in a structure returned 6493 /* C99 code may assign to an array in a structure returned
6401 from a function, and this has undefined behavior only on 6494 from a function, and this has undefined behavior only on
6402 execution, so create a temporary if an lvalue is 6495 execution, so create a temporary if an lvalue is
6403 required. */ 6496 required. */
6404 if (fallback == fb_lvalue) 6497 if (fallback == fb_lvalue)
6405 { 6498 {
6406 *expr_p = get_initialized_tmp_var (*expr_p, pre_p, post_p); 6499 *expr_p = get_initialized_tmp_var (*expr_p, pre_p, post_p);
6407 mark_addressable (*expr_p); 6500 mark_addressable (*expr_p);
6408 } 6501 }
6409 break; 6502 break;
6410 6503
6411 case TREE_LIST: 6504 case TREE_LIST:
6412 gcc_unreachable (); 6505 gcc_unreachable ();
6413 6506
6414 case COMPOUND_EXPR: 6507 case COMPOUND_EXPR:
6415 ret = gimplify_compound_expr (expr_p, pre_p, fallback != fb_none); 6508 ret = gimplify_compound_expr (expr_p, pre_p, fallback != fb_none);
6416 break; 6509 break;
6417 6510
6418 case MODIFY_EXPR: 6511 case COMPOUND_LITERAL_EXPR:
6419 case INIT_EXPR: 6512 ret = gimplify_compound_literal_expr (expr_p, pre_p);
6420 ret = gimplify_modify_expr (expr_p, pre_p, post_p, 6513 break;
6421 fallback != fb_none); 6514
6422 break; 6515 case MODIFY_EXPR:
6423 6516 case INIT_EXPR:
6424 case TRUTH_ANDIF_EXPR: 6517 ret = gimplify_modify_expr (expr_p, pre_p, post_p,
6425 case TRUTH_ORIF_EXPR: 6518 fallback != fb_none);
6426 ret = gimplify_boolean_expr (expr_p); 6519 break;
6427 break; 6520
6428 6521 case TRUTH_ANDIF_EXPR:
6429 case TRUTH_NOT_EXPR: 6522 case TRUTH_ORIF_EXPR:
6430 if (TREE_CODE (TREE_TYPE (*expr_p)) != BOOLEAN_TYPE) 6523 /* Pass the source location of the outer expression. */
6431 { 6524 ret = gimplify_boolean_expr (expr_p, saved_location);
6432 tree type = TREE_TYPE (*expr_p); 6525 break;
6433 *expr_p = fold_convert (type, gimple_boolify (*expr_p)); 6526
6434 ret = GS_OK; 6527 case TRUTH_NOT_EXPR:
6435 break; 6528 if (TREE_CODE (TREE_TYPE (*expr_p)) != BOOLEAN_TYPE)
6436 } 6529 {
6437 6530 tree type = TREE_TYPE (*expr_p);
6438 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p, 6531 *expr_p = fold_convert (type, gimple_boolify (*expr_p));
6439 is_gimple_val, fb_rvalue); 6532 ret = GS_OK;
6440 recalculate_side_effects (*expr_p); 6533 break;
6441 break; 6534 }
6442 6535
6443 case ADDR_EXPR: 6536 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
6444 ret = gimplify_addr_expr (expr_p, pre_p, post_p); 6537 is_gimple_val, fb_rvalue);
6445 break; 6538 recalculate_side_effects (*expr_p);
6446 6539 break;
6447 case VA_ARG_EXPR: 6540
6448 ret = gimplify_va_arg_expr (expr_p, pre_p, post_p); 6541 case ADDR_EXPR:
6449 break; 6542 ret = gimplify_addr_expr (expr_p, pre_p, post_p);
6450 6543 break;
6451 CASE_CONVERT: 6544
6452 if (IS_EMPTY_STMT (*expr_p)) 6545 case VA_ARG_EXPR:
6453 { 6546 ret = gimplify_va_arg_expr (expr_p, pre_p, post_p);
6454 ret = GS_ALL_DONE; 6547 break;
6455 break; 6548
6456 } 6549 CASE_CONVERT:
6457 6550 if (IS_EMPTY_STMT (*expr_p))
6458 if (VOID_TYPE_P (TREE_TYPE (*expr_p)) 6551 {
6459 || fallback == fb_none) 6552 ret = GS_ALL_DONE;
6460 { 6553 break;
6461 /* Just strip a conversion to void (or in void context) and 6554 }
6462 try again. */ 6555
6463 *expr_p = TREE_OPERAND (*expr_p, 0); 6556 if (VOID_TYPE_P (TREE_TYPE (*expr_p))
6464 break; 6557 || fallback == fb_none)
6465 } 6558 {
6466 6559 /* Just strip a conversion to void (or in void context) and
6467 ret = gimplify_conversion (expr_p); 6560 try again. */
6468 if (ret == GS_ERROR) 6561 *expr_p = TREE_OPERAND (*expr_p, 0);
6469 break; 6562 break;
6470 if (*expr_p != save_expr) 6563 }
6471 break; 6564
6472 /* FALLTHRU */ 6565 ret = gimplify_conversion (expr_p);
6473 6566 if (ret == GS_ERROR)
6474 case FIX_TRUNC_EXPR: 6567 break;
6475 /* unary_expr: ... | '(' cast ')' val | ... */ 6568 if (*expr_p != save_expr)
6476 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p, 6569 break;
6477 is_gimple_val, fb_rvalue); 6570 /* FALLTHRU */
6478 recalculate_side_effects (*expr_p); 6571
6479 break; 6572 case FIX_TRUNC_EXPR:
6480 6573 /* unary_expr: ... | '(' cast ')' val | ... */
6481 case INDIRECT_REF: 6574 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
6482 *expr_p = fold_indirect_ref (*expr_p); 6575 is_gimple_val, fb_rvalue);
6483 if (*expr_p != save_expr) 6576 recalculate_side_effects (*expr_p);
6484 break; 6577 break;
6485 /* else fall through. */ 6578
6486 case ALIGN_INDIRECT_REF: 6579 case INDIRECT_REF:
6487 case MISALIGNED_INDIRECT_REF: 6580 *expr_p = fold_indirect_ref_loc (input_location, *expr_p);
6488 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p, 6581 if (*expr_p != save_expr)
6489 is_gimple_reg, fb_rvalue); 6582 break;
6490 recalculate_side_effects (*expr_p); 6583 /* else fall through. */
6491 break; 6584 case ALIGN_INDIRECT_REF:
6492 6585 case MISALIGNED_INDIRECT_REF:
6493 /* Constants need not be gimplified. */ 6586 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
6494 case INTEGER_CST: 6587 is_gimple_reg, fb_rvalue);
6495 case REAL_CST: 6588 recalculate_side_effects (*expr_p);
6496 case FIXED_CST: 6589 break;
6497 case STRING_CST: 6590
6498 case COMPLEX_CST: 6591 /* Constants need not be gimplified. */
6499 case VECTOR_CST: 6592 case INTEGER_CST:
6500 ret = GS_ALL_DONE; 6593 case REAL_CST:
6501 break; 6594 case FIXED_CST:
6502 6595 case STRING_CST:
6503 case CONST_DECL: 6596 case COMPLEX_CST:
6504 /* If we require an lvalue, such as for ADDR_EXPR, retain the 6597 case VECTOR_CST:
6505 CONST_DECL node. Otherwise the decl is replaceable by its 6598 ret = GS_ALL_DONE;
6506 value. */ 6599 break;
6507 /* ??? Should be == fb_lvalue, but ADDR_EXPR passes fb_either. */ 6600
6508 if (fallback & fb_lvalue) 6601 case CONST_DECL:
6509 ret = GS_ALL_DONE; 6602 /* If we require an lvalue, such as for ADDR_EXPR, retain the
6510 else 6603 CONST_DECL node. Otherwise the decl is replaceable by its
6511 *expr_p = DECL_INITIAL (*expr_p); 6604 value. */
6512 break; 6605 /* ??? Should be == fb_lvalue, but ADDR_EXPR passes fb_either. */
6513 6606 if (fallback & fb_lvalue)
6514 case DECL_EXPR: 6607 ret = GS_ALL_DONE;
6515 ret = gimplify_decl_expr (expr_p, pre_p); 6608 else
6516 break; 6609 *expr_p = DECL_INITIAL (*expr_p);
6517 6610 break;
6518 case EXC_PTR_EXPR: 6611
6519 /* FIXME make this a decl. */ 6612 case DECL_EXPR:
6520 ret = GS_ALL_DONE; 6613 ret = gimplify_decl_expr (expr_p, pre_p);
6521 break; 6614 break;
6522 6615
6523 case BIND_EXPR: 6616 case BIND_EXPR:
6524 ret = gimplify_bind_expr (expr_p, pre_p); 6617 ret = gimplify_bind_expr (expr_p, pre_p);
6525 break; 6618 break;
6526 6619
6527 case LOOP_EXPR: 6620 case LOOP_EXPR:
6528 ret = gimplify_loop_expr (expr_p, pre_p); 6621 ret = gimplify_loop_expr (expr_p, pre_p);
6529 break; 6622 break;
6530 6623
6531 case SWITCH_EXPR: 6624 case SWITCH_EXPR:
6532 ret = gimplify_switch_expr (expr_p, pre_p); 6625 ret = gimplify_switch_expr (expr_p, pre_p);
6533 break; 6626 break;
6534 6627
6535 case EXIT_EXPR: 6628 case EXIT_EXPR:
6536 ret = gimplify_exit_expr (expr_p); 6629 ret = gimplify_exit_expr (expr_p);
6537 break; 6630 break;
6538 6631
6539 case GOTO_EXPR: 6632 case GOTO_EXPR:
6540 /* If the target is not LABEL, then it is a computed jump 6633 /* If the target is not LABEL, then it is a computed jump
6541 and the target needs to be gimplified. */ 6634 and the target needs to be gimplified. */
6542 if (TREE_CODE (GOTO_DESTINATION (*expr_p)) != LABEL_DECL) 6635 if (TREE_CODE (GOTO_DESTINATION (*expr_p)) != LABEL_DECL)
6543 { 6636 {
6544 ret = gimplify_expr (&GOTO_DESTINATION (*expr_p), pre_p, 6637 ret = gimplify_expr (&GOTO_DESTINATION (*expr_p), pre_p,
6545 NULL, is_gimple_val, fb_rvalue); 6638 NULL, is_gimple_val, fb_rvalue);
6546 if (ret == GS_ERROR) 6639 if (ret == GS_ERROR)
6547 break; 6640 break;
6548 } 6641 }
6549 gimplify_seq_add_stmt (pre_p, 6642 gimplify_seq_add_stmt (pre_p,
6550 gimple_build_goto (GOTO_DESTINATION (*expr_p))); 6643 gimple_build_goto (GOTO_DESTINATION (*expr_p)));
6551 break; 6644 break;
6552 6645
6553 case PREDICT_EXPR: 6646 case PREDICT_EXPR:
6554 gimplify_seq_add_stmt (pre_p, 6647 gimplify_seq_add_stmt (pre_p,
6555 gimple_build_predict (PREDICT_EXPR_PREDICTOR (*expr_p), 6648 gimple_build_predict (PREDICT_EXPR_PREDICTOR (*expr_p),
6556 PREDICT_EXPR_OUTCOME (*expr_p))); 6649 PREDICT_EXPR_OUTCOME (*expr_p)));
6557 ret = GS_ALL_DONE; 6650 ret = GS_ALL_DONE;
6558 break; 6651 break;
6559 6652
6560 case LABEL_EXPR: 6653 case LABEL_EXPR:
6561 ret = GS_ALL_DONE; 6654 ret = GS_ALL_DONE;
6562 gcc_assert (decl_function_context (LABEL_EXPR_LABEL (*expr_p)) 6655 gcc_assert (decl_function_context (LABEL_EXPR_LABEL (*expr_p))
6563 == current_function_decl); 6656 == current_function_decl);
6564 gimplify_seq_add_stmt (pre_p, 6657 gimplify_seq_add_stmt (pre_p,
6565 gimple_build_label (LABEL_EXPR_LABEL (*expr_p))); 6658 gimple_build_label (LABEL_EXPR_LABEL (*expr_p)));
6566 break; 6659 break;
6567 6660
6568 case CASE_LABEL_EXPR: 6661 case CASE_LABEL_EXPR:
6569 ret = gimplify_case_label_expr (expr_p, pre_p); 6662 ret = gimplify_case_label_expr (expr_p, pre_p);
6570 break; 6663 break;
6571 6664
6572 case RETURN_EXPR: 6665 case RETURN_EXPR:
6573 ret = gimplify_return_expr (*expr_p, pre_p); 6666 ret = gimplify_return_expr (*expr_p, pre_p);
6574 break; 6667 break;
6575 6668
6576 case CONSTRUCTOR: 6669 case CONSTRUCTOR:
6577 /* Don't reduce this in place; let gimplify_init_constructor work its 6670 /* Don't reduce this in place; let gimplify_init_constructor work its
6578 magic. Buf if we're just elaborating this for side effects, just 6671 magic. Buf if we're just elaborating this for side effects, just
6579 gimplify any element that has side-effects. */ 6672 gimplify any element that has side-effects. */
6580 if (fallback == fb_none) 6673 if (fallback == fb_none)
6581 { 6674 {
6582 unsigned HOST_WIDE_INT ix; 6675 unsigned HOST_WIDE_INT ix;
6583 constructor_elt *ce; 6676 constructor_elt *ce;
6584 tree temp = NULL_TREE; 6677 tree temp = NULL_TREE;
6585 for (ix = 0; 6678 for (ix = 0;
6586 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (*expr_p), 6679 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (*expr_p),
6587 ix, ce); 6680 ix, ce);
6588 ix++) 6681 ix++)
6589 if (TREE_SIDE_EFFECTS (ce->value)) 6682 if (TREE_SIDE_EFFECTS (ce->value))
6590 append_to_statement_list (ce->value, &temp); 6683 append_to_statement_list (ce->value, &temp);
6591 6684
6592 *expr_p = temp; 6685 *expr_p = temp;
6593 ret = GS_OK; 6686 ret = GS_OK;
6594 } 6687 }
6595 /* C99 code may assign to an array in a constructed 6688 /* C99 code may assign to an array in a constructed
6596 structure or union, and this has undefined behavior only 6689 structure or union, and this has undefined behavior only
6597 on execution, so create a temporary if an lvalue is 6690 on execution, so create a temporary if an lvalue is
6598 required. */ 6691 required. */
6599 else if (fallback == fb_lvalue) 6692 else if (fallback == fb_lvalue)
6600 { 6693 {
6601 *expr_p = get_initialized_tmp_var (*expr_p, pre_p, post_p); 6694 *expr_p = get_initialized_tmp_var (*expr_p, pre_p, post_p);
6602 mark_addressable (*expr_p); 6695 mark_addressable (*expr_p);
6603 } 6696 }
6604 else 6697 else
6605 ret = GS_ALL_DONE; 6698 ret = GS_ALL_DONE;
6606 break; 6699 break;
6607 6700
6608 /* The following are special cases that are not handled by the 6701 /* The following are special cases that are not handled by the
6609 original GIMPLE grammar. */ 6702 original GIMPLE grammar. */
6610 6703
6611 /* SAVE_EXPR nodes are converted into a GIMPLE identifier and 6704 /* SAVE_EXPR nodes are converted into a GIMPLE identifier and
6612 eliminated. */ 6705 eliminated. */
6613 case SAVE_EXPR: 6706 case SAVE_EXPR:
6614 ret = gimplify_save_expr (expr_p, pre_p, post_p); 6707 ret = gimplify_save_expr (expr_p, pre_p, post_p);
6615 break; 6708 break;
6616 6709
6617 case BIT_FIELD_REF: 6710 case BIT_FIELD_REF:
6618 { 6711 {
6619 enum gimplify_status r0, r1, r2; 6712 enum gimplify_status r0, r1, r2;
6620 6713
6621 r0 = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, 6714 r0 = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p,
6622 post_p, is_gimple_lvalue, fb_either); 6715 post_p, is_gimple_lvalue, fb_either);
6623 r1 = gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p, 6716 r1 = gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p,
6624 post_p, is_gimple_val, fb_rvalue); 6717 post_p, is_gimple_val, fb_rvalue);
6625 r2 = gimplify_expr (&TREE_OPERAND (*expr_p, 2), pre_p, 6718 r2 = gimplify_expr (&TREE_OPERAND (*expr_p, 2), pre_p,
6626 post_p, is_gimple_val, fb_rvalue); 6719 post_p, is_gimple_val, fb_rvalue);
6627 recalculate_side_effects (*expr_p); 6720 recalculate_side_effects (*expr_p);
6628 6721
6629 ret = MIN (r0, MIN (r1, r2)); 6722 ret = MIN (r0, MIN (r1, r2));
6630 } 6723 }
6631 break; 6724 break;
6632 6725
6633 case NON_LVALUE_EXPR: 6726 case TARGET_MEM_REF:
6634 /* This should have been stripped above. */ 6727 {
6635 gcc_unreachable (); 6728 enum gimplify_status r0 = GS_ALL_DONE, r1 = GS_ALL_DONE;
6636 6729
6637 case ASM_EXPR: 6730 if (TMR_SYMBOL (*expr_p))
6638 ret = gimplify_asm_expr (expr_p, pre_p, post_p); 6731 r0 = gimplify_expr (&TMR_SYMBOL (*expr_p), pre_p,
6639 break; 6732 post_p, is_gimple_lvalue, fb_either);
6640 6733 else if (TMR_BASE (*expr_p))
6641 case TRY_FINALLY_EXPR: 6734 r0 = gimplify_expr (&TMR_BASE (*expr_p), pre_p,
6642 case TRY_CATCH_EXPR: 6735 post_p, is_gimple_val, fb_either);
6643 { 6736 if (TMR_INDEX (*expr_p))
6644 gimple_seq eval, cleanup; 6737 r1 = gimplify_expr (&TMR_INDEX (*expr_p), pre_p,
6645 gimple try_; 6738 post_p, is_gimple_val, fb_rvalue);
6646 6739 /* TMR_STEP and TMR_OFFSET are always integer constants. */
6647 eval = cleanup = NULL; 6740 ret = MIN (r0, r1);
6648 gimplify_and_add (TREE_OPERAND (*expr_p, 0), &eval); 6741 }
6649 gimplify_and_add (TREE_OPERAND (*expr_p, 1), &cleanup); 6742 break;
6650 /* Don't create bogus GIMPLE_TRY with empty cleanup. */ 6743
6651 if (gimple_seq_empty_p (cleanup)) 6744 case NON_LVALUE_EXPR:
6652 { 6745 /* This should have been stripped above. */
6653 gimple_seq_add_seq (pre_p, eval); 6746 gcc_unreachable ();
6654 ret = GS_ALL_DONE; 6747
6655 break; 6748 case ASM_EXPR:
6656 } 6749 ret = gimplify_asm_expr (expr_p, pre_p, post_p);
6657 try_ = gimple_build_try (eval, cleanup, 6750 break;
6658 TREE_CODE (*expr_p) == TRY_FINALLY_EXPR 6751
6659 ? GIMPLE_TRY_FINALLY 6752 case TRY_FINALLY_EXPR:
6660 : GIMPLE_TRY_CATCH); 6753 case TRY_CATCH_EXPR:
6661 if (TREE_CODE (*expr_p) == TRY_CATCH_EXPR) 6754 {
6662 gimple_try_set_catch_is_cleanup (try_, 6755 gimple_seq eval, cleanup;
6663 TRY_CATCH_IS_CLEANUP (*expr_p)); 6756 gimple try_;
6664 gimplify_seq_add_stmt (pre_p, try_); 6757
6665 ret = GS_ALL_DONE; 6758 eval = cleanup = NULL;
6666 break; 6759 gimplify_and_add (TREE_OPERAND (*expr_p, 0), &eval);
6667 } 6760 gimplify_and_add (TREE_OPERAND (*expr_p, 1), &cleanup);
6668 6761 /* Don't create bogus GIMPLE_TRY with empty cleanup. */
6669 case CLEANUP_POINT_EXPR: 6762 if (gimple_seq_empty_p (cleanup))
6670 ret = gimplify_cleanup_point_expr (expr_p, pre_p); 6763 {
6671 break; 6764 gimple_seq_add_seq (pre_p, eval);
6672 6765 ret = GS_ALL_DONE;
6673 case TARGET_EXPR: 6766 break;
6674 ret = gimplify_target_expr (expr_p, pre_p, post_p); 6767 }
6675 break; 6768 try_ = gimple_build_try (eval, cleanup,
6676 6769 TREE_CODE (*expr_p) == TRY_FINALLY_EXPR
6677 case CATCH_EXPR: 6770 ? GIMPLE_TRY_FINALLY
6678 { 6771 : GIMPLE_TRY_CATCH);
6679 gimple c; 6772 if (TREE_CODE (*expr_p) == TRY_CATCH_EXPR)
6680 gimple_seq handler = NULL; 6773 gimple_try_set_catch_is_cleanup (try_,
6681 gimplify_and_add (CATCH_BODY (*expr_p), &handler); 6774 TRY_CATCH_IS_CLEANUP (*expr_p));
6682 c = gimple_build_catch (CATCH_TYPES (*expr_p), handler); 6775 gimplify_seq_add_stmt (pre_p, try_);
6683 gimplify_seq_add_stmt (pre_p, c); 6776 ret = GS_ALL_DONE;
6684 ret = GS_ALL_DONE; 6777 break;
6685 break; 6778 }
6686 } 6779
6687 6780 case CLEANUP_POINT_EXPR:
6688 case EH_FILTER_EXPR: 6781 ret = gimplify_cleanup_point_expr (expr_p, pre_p);
6689 { 6782 break;
6690 gimple ehf; 6783
6691 gimple_seq failure = NULL; 6784 case TARGET_EXPR:
6692 6785 ret = gimplify_target_expr (expr_p, pre_p, post_p);
6693 gimplify_and_add (EH_FILTER_FAILURE (*expr_p), &failure); 6786 break;
6694 ehf = gimple_build_eh_filter (EH_FILTER_TYPES (*expr_p), failure); 6787
6695 gimple_eh_filter_set_must_not_throw 6788 case CATCH_EXPR:
6696 (ehf, EH_FILTER_MUST_NOT_THROW (*expr_p)); 6789 {
6697 gimplify_seq_add_stmt (pre_p, ehf); 6790 gimple c;
6698 ret = GS_ALL_DONE; 6791 gimple_seq handler = NULL;
6699 break; 6792 gimplify_and_add (CATCH_BODY (*expr_p), &handler);
6700 } 6793 c = gimple_build_catch (CATCH_TYPES (*expr_p), handler);
6701 6794 gimplify_seq_add_stmt (pre_p, c);
6702 case CHANGE_DYNAMIC_TYPE_EXPR: 6795 ret = GS_ALL_DONE;
6703 { 6796 break;
6704 gimple cdt; 6797 }
6705 6798
6706 ret = gimplify_expr (&CHANGE_DYNAMIC_TYPE_LOCATION (*expr_p), 6799 case EH_FILTER_EXPR:
6707 pre_p, post_p, is_gimple_reg, fb_lvalue); 6800 {
6708 cdt = gimple_build_cdt (CHANGE_DYNAMIC_TYPE_NEW_TYPE (*expr_p), 6801 gimple ehf;
6709 CHANGE_DYNAMIC_TYPE_LOCATION (*expr_p)); 6802 gimple_seq failure = NULL;
6710 gimplify_seq_add_stmt (pre_p, cdt); 6803
6711 ret = GS_ALL_DONE; 6804 gimplify_and_add (EH_FILTER_FAILURE (*expr_p), &failure);
6712 } 6805 ehf = gimple_build_eh_filter (EH_FILTER_TYPES (*expr_p), failure);
6713 break; 6806 gimple_set_no_warning (ehf, TREE_NO_WARNING (*expr_p));
6714 6807 gimplify_seq_add_stmt (pre_p, ehf);
6715 case OBJ_TYPE_REF: 6808 ret = GS_ALL_DONE;
6716 { 6809 break;
6717 enum gimplify_status r0, r1; 6810 }
6718 r0 = gimplify_expr (&OBJ_TYPE_REF_OBJECT (*expr_p), pre_p, 6811
6719 post_p, is_gimple_val, fb_rvalue); 6812 case OBJ_TYPE_REF:
6720 r1 = gimplify_expr (&OBJ_TYPE_REF_EXPR (*expr_p), pre_p, 6813 {
6721 post_p, is_gimple_val, fb_rvalue); 6814 enum gimplify_status r0, r1;
6722 TREE_SIDE_EFFECTS (*expr_p) = 0; 6815 r0 = gimplify_expr (&OBJ_TYPE_REF_OBJECT (*expr_p), pre_p,
6723 ret = MIN (r0, r1); 6816 post_p, is_gimple_val, fb_rvalue);
6724 } 6817 r1 = gimplify_expr (&OBJ_TYPE_REF_EXPR (*expr_p), pre_p,
6725 break; 6818 post_p, is_gimple_val, fb_rvalue);
6726 6819 TREE_SIDE_EFFECTS (*expr_p) = 0;
6727 case LABEL_DECL: 6820 ret = MIN (r0, r1);
6728 /* We get here when taking the address of a label. We mark 6821 }
6729 the label as "forced"; meaning it can never be removed and 6822 break;
6730 it is a potential target for any computed goto. */ 6823
6731 FORCED_LABEL (*expr_p) = 1; 6824 case LABEL_DECL:
6732 ret = GS_ALL_DONE; 6825 /* We get here when taking the address of a label. We mark
6733 break; 6826 the label as "forced"; meaning it can never be removed and
6734 6827 it is a potential target for any computed goto. */
6735 case STATEMENT_LIST: 6828 FORCED_LABEL (*expr_p) = 1;
6736 ret = gimplify_statement_list (expr_p, pre_p); 6829 ret = GS_ALL_DONE;
6737 break; 6830 break;
6738 6831
6739 case WITH_SIZE_EXPR: 6832 case STATEMENT_LIST:
6740 { 6833 ret = gimplify_statement_list (expr_p, pre_p);
6741 gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, 6834 break;
6742 post_p == &internal_post ? NULL : post_p, 6835
6743 gimple_test_f, fallback); 6836 case WITH_SIZE_EXPR:
6744 gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p, post_p, 6837 {
6745 is_gimple_val, fb_rvalue); 6838 gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p,
6746 } 6839 post_p == &internal_post ? NULL : post_p,
6747 break; 6840 gimple_test_f, fallback);
6748 6841 gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p, post_p,
6749 case VAR_DECL: 6842 is_gimple_val, fb_rvalue);
6750 case PARM_DECL: 6843 }
6751 ret = gimplify_var_or_parm_decl (expr_p); 6844 break;
6752 break; 6845
6753 6846 case VAR_DECL:
6754 case RESULT_DECL: 6847 case PARM_DECL:
6755 /* When within an OpenMP context, notice uses of variables. */ 6848 ret = gimplify_var_or_parm_decl (expr_p);
6756 if (gimplify_omp_ctxp) 6849 break;
6757 omp_notice_variable (gimplify_omp_ctxp, *expr_p, true); 6850
6758 ret = GS_ALL_DONE; 6851 case RESULT_DECL:
6759 break; 6852 /* When within an OpenMP context, notice uses of variables. */
6760 6853 if (gimplify_omp_ctxp)
6761 case SSA_NAME: 6854 omp_notice_variable (gimplify_omp_ctxp, *expr_p, true);
6762 /* Allow callbacks into the gimplifier during optimization. */ 6855 ret = GS_ALL_DONE;
6763 ret = GS_ALL_DONE; 6856 break;
6764 break; 6857
6765 6858 case SSA_NAME:
6766 case OMP_PARALLEL: 6859 /* Allow callbacks into the gimplifier during optimization. */
6767 gimplify_omp_parallel (expr_p, pre_p); 6860 ret = GS_ALL_DONE;
6768 ret = GS_ALL_DONE; 6861 break;
6769 break; 6862
6770 6863 case OMP_PARALLEL:
6771 case OMP_TASK: 6864 gimplify_omp_parallel (expr_p, pre_p);
6772 gimplify_omp_task (expr_p, pre_p); 6865 ret = GS_ALL_DONE;
6773 ret = GS_ALL_DONE; 6866 break;
6774 break; 6867
6775 6868 case OMP_TASK:
6776 case OMP_FOR: 6869 gimplify_omp_task (expr_p, pre_p);
6777 ret = gimplify_omp_for (expr_p, pre_p); 6870 ret = GS_ALL_DONE;
6778 break; 6871 break;
6779 6872
6780 case OMP_SECTIONS: 6873 case OMP_FOR:
6781 case OMP_SINGLE: 6874 ret = gimplify_omp_for (expr_p, pre_p);
6782 gimplify_omp_workshare (expr_p, pre_p); 6875 break;
6783 ret = GS_ALL_DONE; 6876
6784 break; 6877 case OMP_SECTIONS:
6785 6878 case OMP_SINGLE:
6786 case OMP_SECTION: 6879 gimplify_omp_workshare (expr_p, pre_p);
6787 case OMP_MASTER: 6880 ret = GS_ALL_DONE;
6788 case OMP_ORDERED: 6881 break;
6789 case OMP_CRITICAL: 6882
6790 { 6883 case OMP_SECTION:
6791 gimple_seq body = NULL; 6884 case OMP_MASTER:
6792 gimple g; 6885 case OMP_ORDERED:
6793 6886 case OMP_CRITICAL:
6794 gimplify_and_add (OMP_BODY (*expr_p), &body); 6887 {
6795 switch (TREE_CODE (*expr_p)) 6888 gimple_seq body = NULL;
6796 { 6889 gimple g;
6797 case OMP_SECTION: 6890
6798 g = gimple_build_omp_section (body); 6891 gimplify_and_add (OMP_BODY (*expr_p), &body);
6799 break; 6892 switch (TREE_CODE (*expr_p))
6800 case OMP_MASTER: 6893 {
6801 g = gimple_build_omp_master (body); 6894 case OMP_SECTION:
6802 break; 6895 g = gimple_build_omp_section (body);
6803 case OMP_ORDERED: 6896 break;
6804 g = gimple_build_omp_ordered (body); 6897 case OMP_MASTER:
6805 break; 6898 g = gimple_build_omp_master (body);
6806 case OMP_CRITICAL: 6899 break;
6807 g = gimple_build_omp_critical (body, 6900 case OMP_ORDERED:
6808 OMP_CRITICAL_NAME (*expr_p)); 6901 g = gimple_build_omp_ordered (body);
6809 break; 6902 break;
6810 default: 6903 case OMP_CRITICAL:
6811 gcc_unreachable (); 6904 g = gimple_build_omp_critical (body,
6812 } 6905 OMP_CRITICAL_NAME (*expr_p));
6813 gimplify_seq_add_stmt (pre_p, g); 6906 break;
6814 ret = GS_ALL_DONE; 6907 default:
6815 break; 6908 gcc_unreachable ();
6816 } 6909 }
6817 6910 gimplify_seq_add_stmt (pre_p, g);
6818 case OMP_ATOMIC: 6911 ret = GS_ALL_DONE;
6819 ret = gimplify_omp_atomic (expr_p, pre_p); 6912 break;
6820 break; 6913 }
6821 6914
6822 case POINTER_PLUS_EXPR: 6915 case OMP_ATOMIC:
6916 ret = gimplify_omp_atomic (expr_p, pre_p);
6917 break;
6918
6919 case POINTER_PLUS_EXPR:
6823 /* Convert ((type *)A)+offset into &A->field_of_type_and_offset. 6920 /* Convert ((type *)A)+offset into &A->field_of_type_and_offset.
6824 The second is gimple immediate saving a need for extra statement. 6921 The second is gimple immediate saving a need for extra statement.
6825 */ 6922 */
6826 if (TREE_CODE (TREE_OPERAND (*expr_p, 1)) == INTEGER_CST 6923 if (TREE_CODE (TREE_OPERAND (*expr_p, 1)) == INTEGER_CST
6827 && (tmp = maybe_fold_offset_to_address 6924 && (tmp = maybe_fold_offset_to_address
6828 (TREE_OPERAND (*expr_p, 0), TREE_OPERAND (*expr_p, 1), 6925 (EXPR_LOCATION (*expr_p),
6829 TREE_TYPE (*expr_p)))) 6926 TREE_OPERAND (*expr_p, 0), TREE_OPERAND (*expr_p, 1),
6830 { 6927 TREE_TYPE (*expr_p))))
6831 *expr_p = tmp; 6928 {
6832 break; 6929 *expr_p = tmp;
6833 } 6930 break;
6834 /* Convert (void *)&a + 4 into (void *)&a[1]. */ 6931 }
6835 if (TREE_CODE (TREE_OPERAND (*expr_p, 0)) == NOP_EXPR 6932 /* Convert (void *)&a + 4 into (void *)&a[1]. */
6836 && TREE_CODE (TREE_OPERAND (*expr_p, 1)) == INTEGER_CST 6933 if (TREE_CODE (TREE_OPERAND (*expr_p, 0)) == NOP_EXPR
6837 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (*expr_p, 6934 && TREE_CODE (TREE_OPERAND (*expr_p, 1)) == INTEGER_CST
6838 0),0))) 6935 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (*expr_p,
6839 && (tmp = maybe_fold_offset_to_address 6936 0),0)))
6840 (TREE_OPERAND (TREE_OPERAND (*expr_p, 0), 0), 6937 && (tmp = maybe_fold_offset_to_address
6841 TREE_OPERAND (*expr_p, 1), 6938 (EXPR_LOCATION (*expr_p),
6842 TREE_TYPE (TREE_OPERAND (TREE_OPERAND (*expr_p, 0), 6939 TREE_OPERAND (TREE_OPERAND (*expr_p, 0), 0),
6843 0))))) 6940 TREE_OPERAND (*expr_p, 1),
6844 { 6941 TREE_TYPE (TREE_OPERAND (TREE_OPERAND (*expr_p, 0),
6942 0)))))
6943 {
6845 *expr_p = fold_convert (TREE_TYPE (*expr_p), tmp); 6944 *expr_p = fold_convert (TREE_TYPE (*expr_p), tmp);
6846 break; 6945 break;
6847 } 6946 }
6848 /* FALLTHRU */ 6947 /* FALLTHRU */
6849 6948
6850 default: 6949 default:
6851 switch (TREE_CODE_CLASS (TREE_CODE (*expr_p))) 6950 switch (TREE_CODE_CLASS (TREE_CODE (*expr_p)))
6852 { 6951 {
6853 case tcc_comparison: 6952 case tcc_comparison:
6854 /* Handle comparison of objects of non scalar mode aggregates 6953 /* Handle comparison of objects of non scalar mode aggregates
6855 with a call to memcmp. It would be nice to only have to do 6954 with a call to memcmp. It would be nice to only have to do
6856 this for variable-sized objects, but then we'd have to allow 6955 this for variable-sized objects, but then we'd have to allow
6857 the same nest of reference nodes we allow for MODIFY_EXPR and 6956 the same nest of reference nodes we allow for MODIFY_EXPR and
6858 that's too complex. 6957 that's too complex.
6859 6958
6860 Compare scalar mode aggregates as scalar mode values. Using 6959 Compare scalar mode aggregates as scalar mode values. Using
6861 memcmp for them would be very inefficient at best, and is 6960 memcmp for them would be very inefficient at best, and is
6862 plain wrong if bitfields are involved. */ 6961 plain wrong if bitfields are involved. */
6863 { 6962 {
6864 tree type = TREE_TYPE (TREE_OPERAND (*expr_p, 1)); 6963 tree type = TREE_TYPE (TREE_OPERAND (*expr_p, 1));
6865 6964
6866 if (!AGGREGATE_TYPE_P (type)) 6965 if (!AGGREGATE_TYPE_P (type))
6867 goto expr_2; 6966 goto expr_2;
6868 else if (TYPE_MODE (type) != BLKmode) 6967 else if (TYPE_MODE (type) != BLKmode)
6869 ret = gimplify_scalar_mode_aggregate_compare (expr_p); 6968 ret = gimplify_scalar_mode_aggregate_compare (expr_p);
6870 else 6969 else
6871 ret = gimplify_variable_sized_compare (expr_p); 6970 ret = gimplify_variable_sized_compare (expr_p);
6872 6971
6873 break; 6972 break;
6874 } 6973 }
6875 6974
6876 /* If *EXPR_P does not need to be special-cased, handle it 6975 /* If *EXPR_P does not need to be special-cased, handle it
6877 according to its class. */ 6976 according to its class. */
6878 case tcc_unary: 6977 case tcc_unary:
6879 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, 6978 ret = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p,
6880 post_p, is_gimple_val, fb_rvalue); 6979 post_p, is_gimple_val, fb_rvalue);
6881 break; 6980 break;
6882 6981
6883 case tcc_binary: 6982 case tcc_binary:
6884 expr_2: 6983 expr_2:
6885 { 6984 {
6886 enum gimplify_status r0, r1; 6985 enum gimplify_status r0, r1;
6887 6986
6888 r0 = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, 6987 r0 = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p,
6889 post_p, is_gimple_val, fb_rvalue); 6988 post_p, is_gimple_val, fb_rvalue);
6890 r1 = gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p, 6989 r1 = gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p,
6891 post_p, is_gimple_val, fb_rvalue); 6990 post_p, is_gimple_val, fb_rvalue);
6892 6991
6893 ret = MIN (r0, r1); 6992 ret = MIN (r0, r1);
6894 break; 6993 break;
6895 } 6994 }
6896 6995
6897 case tcc_declaration: 6996 case tcc_declaration:
6898 case tcc_constant: 6997 case tcc_constant:
6899 ret = GS_ALL_DONE; 6998 ret = GS_ALL_DONE;
6900 goto dont_recalculate; 6999 goto dont_recalculate;
6901 7000
6902 default: 7001 default:
6903 gcc_assert (TREE_CODE (*expr_p) == TRUTH_AND_EXPR 7002 gcc_assert (TREE_CODE (*expr_p) == TRUTH_AND_EXPR
6904 || TREE_CODE (*expr_p) == TRUTH_OR_EXPR 7003 || TREE_CODE (*expr_p) == TRUTH_OR_EXPR
6905 || TREE_CODE (*expr_p) == TRUTH_XOR_EXPR); 7004 || TREE_CODE (*expr_p) == TRUTH_XOR_EXPR);
6906 goto expr_2; 7005 goto expr_2;
6907 } 7006 }
6908 7007
6909 recalculate_side_effects (*expr_p); 7008 recalculate_side_effects (*expr_p);
6910 7009
6911 dont_recalculate: 7010 dont_recalculate:
6912 break; 7011 break;
6913 } 7012 }
6914 7013
6915 /* If we replaced *expr_p, gimplify again. */ 7014 /* If we replaced *expr_p, gimplify again. */
6916 if (ret == GS_OK && (*expr_p == NULL || *expr_p == save_expr)) 7015 if (ret == GS_OK && (*expr_p == NULL || *expr_p == save_expr))
6917 ret = GS_ALL_DONE; 7016 ret = GS_ALL_DONE;
6918 } 7017 }
6919 while (ret == GS_OK); 7018 while (ret == GS_OK);
6920 7019
6921 /* If we encountered an error_mark somewhere nested inside, either 7020 /* If we encountered an error_mark somewhere nested inside, either
6922 stub out the statement or propagate the error back out. */ 7021 stub out the statement or propagate the error back out. */
6923 if (ret == GS_ERROR) 7022 if (ret == GS_ERROR)
6924 { 7023 {
6925 if (is_statement) 7024 if (is_statement)
6926 *expr_p = NULL; 7025 *expr_p = NULL;
6927 goto out; 7026 goto out;
6928 } 7027 }
6929 7028
6930 /* This was only valid as a return value from the langhook, which 7029 /* This was only valid as a return value from the langhook, which
6931 we handled. Make sure it doesn't escape from any other context. */ 7030 we handled. Make sure it doesn't escape from any other context. */
6932 gcc_assert (ret != GS_UNHANDLED); 7031 gcc_assert (ret != GS_UNHANDLED);
6933 7032
6934 if (fallback == fb_none && *expr_p && !is_gimple_stmt (*expr_p)) 7033 if (fallback == fb_none && *expr_p && !is_gimple_stmt (*expr_p))
6935 { 7034 {
6936 /* We aren't looking for a value, and we don't have a valid 7035 /* We aren't looking for a value, and we don't have a valid
6937 statement. If it doesn't have side-effects, throw it away. */ 7036 statement. If it doesn't have side-effects, throw it away. */
6938 if (!TREE_SIDE_EFFECTS (*expr_p)) 7037 if (!TREE_SIDE_EFFECTS (*expr_p))
6939 *expr_p = NULL; 7038 *expr_p = NULL;
6940 else if (!TREE_THIS_VOLATILE (*expr_p)) 7039 else if (!TREE_THIS_VOLATILE (*expr_p))
6941 { 7040 {
6942 /* This is probably a _REF that contains something nested that 7041 /* This is probably a _REF that contains something nested that
6943 has side effects. Recurse through the operands to find it. */ 7042 has side effects. Recurse through the operands to find it. */
6944 enum tree_code code = TREE_CODE (*expr_p); 7043 enum tree_code code = TREE_CODE (*expr_p);
6945 7044
6946 switch (code) 7045 switch (code)
6947 { 7046 {
6948 case COMPONENT_REF: 7047 case COMPONENT_REF:
6949 case REALPART_EXPR: 7048 case REALPART_EXPR:
6950 case IMAGPART_EXPR: 7049 case IMAGPART_EXPR:
6951 case VIEW_CONVERT_EXPR: 7050 case VIEW_CONVERT_EXPR:
6952 gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p, 7051 gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
6953 gimple_test_f, fallback); 7052 gimple_test_f, fallback);
6954 break; 7053 break;
6955 7054
6956 case ARRAY_REF: 7055 case ARRAY_REF:
6957 case ARRAY_RANGE_REF: 7056 case ARRAY_RANGE_REF:
6958 gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p, 7057 gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
6959 gimple_test_f, fallback); 7058 gimple_test_f, fallback);
6960 gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p, post_p, 7059 gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p, post_p,
6961 gimple_test_f, fallback); 7060 gimple_test_f, fallback);
6962 break; 7061 break;
6963 7062
6964 default: 7063 default:
6965 /* Anything else with side-effects must be converted to 7064 /* Anything else with side-effects must be converted to
6966 a valid statement before we get here. */ 7065 a valid statement before we get here. */
6967 gcc_unreachable (); 7066 gcc_unreachable ();
6968 } 7067 }
6969 7068
6970 *expr_p = NULL; 7069 *expr_p = NULL;
6971 } 7070 }
6972 else if (COMPLETE_TYPE_P (TREE_TYPE (*expr_p)) 7071 else if (COMPLETE_TYPE_P (TREE_TYPE (*expr_p))
6973 && TYPE_MODE (TREE_TYPE (*expr_p)) != BLKmode) 7072 && TYPE_MODE (TREE_TYPE (*expr_p)) != BLKmode)
6974 { 7073 {
6975 /* Historically, the compiler has treated a bare reference 7074 /* Historically, the compiler has treated a bare reference
6976 to a non-BLKmode volatile lvalue as forcing a load. */ 7075 to a non-BLKmode volatile lvalue as forcing a load. */
6977 tree type = TYPE_MAIN_VARIANT (TREE_TYPE (*expr_p)); 7076 tree type = TYPE_MAIN_VARIANT (TREE_TYPE (*expr_p));
6978 7077
6979 /* Normally, we do not want to create a temporary for a 7078 /* Normally, we do not want to create a temporary for a
6980 TREE_ADDRESSABLE type because such a type should not be 7079 TREE_ADDRESSABLE type because such a type should not be
6981 copied by bitwise-assignment. However, we make an 7080 copied by bitwise-assignment. However, we make an
6982 exception here, as all we are doing here is ensuring that 7081 exception here, as all we are doing here is ensuring that
6983 we read the bytes that make up the type. We use 7082 we read the bytes that make up the type. We use
6984 create_tmp_var_raw because create_tmp_var will abort when 7083 create_tmp_var_raw because create_tmp_var will abort when
6985 given a TREE_ADDRESSABLE type. */ 7084 given a TREE_ADDRESSABLE type. */
6986 tree tmp = create_tmp_var_raw (type, "vol"); 7085 tree tmp = create_tmp_var_raw (type, "vol");
6987 gimple_add_tmp_var (tmp); 7086 gimple_add_tmp_var (tmp);
6988 gimplify_assign (tmp, *expr_p, pre_p); 7087 gimplify_assign (tmp, *expr_p, pre_p);
6989 *expr_p = NULL; 7088 *expr_p = NULL;
6990 } 7089 }
6991 else 7090 else
6992 /* We can't do anything useful with a volatile reference to 7091 /* We can't do anything useful with a volatile reference to
6993 an incomplete type, so just throw it away. Likewise for 7092 an incomplete type, so just throw it away. Likewise for
6994 a BLKmode type, since any implicit inner load should 7093 a BLKmode type, since any implicit inner load should
6995 already have been turned into an explicit one by the 7094 already have been turned into an explicit one by the
6996 gimplification process. */ 7095 gimplification process. */
6997 *expr_p = NULL; 7096 *expr_p = NULL;
6998 } 7097 }
6999 7098
7000 /* If we are gimplifying at the statement level, we're done. Tack 7099 /* If we are gimplifying at the statement level, we're done. Tack
7001 everything together and return. */ 7100 everything together and return. */
7002 if (fallback == fb_none || is_statement) 7101 if (fallback == fb_none || is_statement)
7004 /* Since *EXPR_P has been converted into a GIMPLE tuple, clear 7103 /* Since *EXPR_P has been converted into a GIMPLE tuple, clear
7005 it out for GC to reclaim it. */ 7104 it out for GC to reclaim it. */
7006 *expr_p = NULL_TREE; 7105 *expr_p = NULL_TREE;
7007 7106
7008 if (!gimple_seq_empty_p (internal_pre) 7107 if (!gimple_seq_empty_p (internal_pre)
7009 || !gimple_seq_empty_p (internal_post)) 7108 || !gimple_seq_empty_p (internal_post))
7010 { 7109 {
7011 gimplify_seq_add_seq (&internal_pre, internal_post); 7110 gimplify_seq_add_seq (&internal_pre, internal_post);
7012 gimplify_seq_add_seq (pre_p, internal_pre); 7111 gimplify_seq_add_seq (pre_p, internal_pre);
7013 } 7112 }
7014 7113
7015 /* The result of gimplifying *EXPR_P is going to be the last few 7114 /* The result of gimplifying *EXPR_P is going to be the last few
7016 statements in *PRE_P and *POST_P. Add location information 7115 statements in *PRE_P and *POST_P. Add location information
7017 to all the statements that were added by the gimplification 7116 to all the statements that were added by the gimplification
7018 helpers. */ 7117 helpers. */
7019 if (!gimple_seq_empty_p (*pre_p)) 7118 if (!gimple_seq_empty_p (*pre_p))
7020 annotate_all_with_location_after (*pre_p, pre_last_gsi, input_location); 7119 annotate_all_with_location_after (*pre_p, pre_last_gsi, input_location);
7021 7120
7022 if (!gimple_seq_empty_p (*post_p)) 7121 if (!gimple_seq_empty_p (*post_p))
7023 annotate_all_with_location_after (*post_p, post_last_gsi, 7122 annotate_all_with_location_after (*post_p, post_last_gsi,
7024 input_location); 7123 input_location);
7025 7124
7026 goto out; 7125 goto out;
7027 } 7126 }
7028 7127
7029 #ifdef ENABLE_GIMPLE_CHECKING 7128 #ifdef ENABLE_GIMPLE_CHECKING
7030 if (*expr_p) 7129 if (*expr_p)
7031 { 7130 {
7032 enum tree_code code = TREE_CODE (*expr_p); 7131 enum tree_code code = TREE_CODE (*expr_p);
7033 /* These expressions should already be in gimple IR form. */ 7132 /* These expressions should already be in gimple IR form. */
7034 gcc_assert (code != MODIFY_EXPR 7133 gcc_assert (code != MODIFY_EXPR
7035 && code != ASM_EXPR 7134 && code != ASM_EXPR
7036 && code != BIND_EXPR 7135 && code != BIND_EXPR
7037 && code != CATCH_EXPR 7136 && code != CATCH_EXPR
7038 && (code != COND_EXPR || gimplify_ctxp->allow_rhs_cond_expr) 7137 && (code != COND_EXPR || gimplify_ctxp->allow_rhs_cond_expr)
7039 && code != EH_FILTER_EXPR 7138 && code != EH_FILTER_EXPR
7040 && code != GOTO_EXPR 7139 && code != GOTO_EXPR
7041 && code != LABEL_EXPR 7140 && code != LABEL_EXPR
7042 && code != LOOP_EXPR 7141 && code != LOOP_EXPR
7043 && code != RESX_EXPR 7142 && code != SWITCH_EXPR
7044 && code != SWITCH_EXPR 7143 && code != TRY_FINALLY_EXPR
7045 && code != TRY_FINALLY_EXPR 7144 && code != OMP_CRITICAL
7046 && code != OMP_CRITICAL 7145 && code != OMP_FOR
7047 && code != OMP_FOR 7146 && code != OMP_MASTER
7048 && code != OMP_MASTER 7147 && code != OMP_ORDERED
7049 && code != OMP_ORDERED 7148 && code != OMP_PARALLEL
7050 && code != OMP_PARALLEL 7149 && code != OMP_SECTIONS
7051 && code != OMP_SECTIONS 7150 && code != OMP_SECTION
7052 && code != OMP_SECTION 7151 && code != OMP_SINGLE);
7053 && code != OMP_SINGLE);
7054 } 7152 }
7055 #endif 7153 #endif
7056 7154
7057 /* Otherwise we're gimplifying a subexpression, so the resulting 7155 /* Otherwise we're gimplifying a subexpression, so the resulting
7058 value is interesting. If it's a valid operand that matches 7156 value is interesting. If it's a valid operand that matches
7072 if ((fallback & fb_lvalue) 7170 if ((fallback & fb_lvalue)
7073 && gimple_seq_empty_p (internal_post) 7171 && gimple_seq_empty_p (internal_post)
7074 && is_gimple_addressable (*expr_p)) 7172 && is_gimple_addressable (*expr_p))
7075 { 7173 {
7076 /* An lvalue will do. Take the address of the expression, store it 7174 /* An lvalue will do. Take the address of the expression, store it
7077 in a temporary, and replace the expression with an INDIRECT_REF of 7175 in a temporary, and replace the expression with an INDIRECT_REF of
7078 that temporary. */ 7176 that temporary. */
7079 tmp = build_fold_addr_expr (*expr_p); 7177 tmp = build_fold_addr_expr_loc (input_location, *expr_p);
7080 gimplify_expr (&tmp, pre_p, post_p, is_gimple_reg, fb_rvalue); 7178 gimplify_expr (&tmp, pre_p, post_p, is_gimple_reg, fb_rvalue);
7081 *expr_p = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (tmp)), tmp); 7179 *expr_p = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (tmp)), tmp);
7082 } 7180 }
7083 else if ((fallback & fb_rvalue) && is_gimple_formal_tmp_or_call_rhs (*expr_p)) 7181 else if ((fallback & fb_rvalue) && is_gimple_reg_rhs_or_call (*expr_p))
7084 { 7182 {
7085 /* An rvalue will do. Assign the gimplified expression into a 7183 /* An rvalue will do. Assign the gimplified expression into a
7086 new temporary TMP and replace the original expression with 7184 new temporary TMP and replace the original expression with
7087 TMP. First, make sure that the expression has a type so that 7185 TMP. First, make sure that the expression has a type so that
7088 it can be assigned into a temporary. */ 7186 it can be assigned into a temporary. */
7089 gcc_assert (!VOID_TYPE_P (TREE_TYPE (*expr_p))); 7187 gcc_assert (!VOID_TYPE_P (TREE_TYPE (*expr_p)));
7090 7188
7091 if (!gimple_seq_empty_p (internal_post) || (fallback & fb_lvalue)) 7189 if (!gimple_seq_empty_p (internal_post) || (fallback & fb_lvalue))
7092 /* The postqueue might change the value of the expression between 7190 /* The postqueue might change the value of the expression between
7093 the initialization and use of the temporary, so we can't use a 7191 the initialization and use of the temporary, so we can't use a
7094 formal temp. FIXME do we care? */ 7192 formal temp. FIXME do we care? */
7095 *expr_p = get_initialized_tmp_var (*expr_p, pre_p, post_p); 7193 {
7194 *expr_p = get_initialized_tmp_var (*expr_p, pre_p, post_p);
7195 if (TREE_CODE (TREE_TYPE (*expr_p)) == COMPLEX_TYPE
7196 || TREE_CODE (TREE_TYPE (*expr_p)) == VECTOR_TYPE)
7197 DECL_GIMPLE_REG_P (*expr_p) = 1;
7198 }
7096 else 7199 else
7097 *expr_p = get_formal_tmp_var (*expr_p, pre_p); 7200 *expr_p = get_formal_tmp_var (*expr_p, pre_p);
7098
7099 if (TREE_CODE (*expr_p) != SSA_NAME)
7100 DECL_GIMPLE_FORMAL_TEMP_P (*expr_p) = 1;
7101 } 7201 }
7102 else 7202 else
7103 { 7203 {
7104 #ifdef ENABLE_GIMPLE_CHECKING 7204 #ifdef ENABLE_GIMPLE_CHECKING
7105 if (!(fallback & fb_mayfail)) 7205 if (!(fallback & fb_mayfail))
7106 { 7206 {
7107 fprintf (stderr, "gimplification failed:\n"); 7207 fprintf (stderr, "gimplification failed:\n");
7108 print_generic_expr (stderr, *expr_p, 0); 7208 print_generic_expr (stderr, *expr_p, 0);
7109 debug_tree (*expr_p); 7209 debug_tree (*expr_p);
7110 internal_error ("gimplification failed"); 7210 internal_error ("gimplification failed");
7111 } 7211 }
7112 #endif 7212 #endif
7113 gcc_assert (fallback & fb_mayfail); 7213 gcc_assert (fallback & fb_mayfail);
7114 7214
7115 /* If this is an asm statement, and the user asked for the 7215 /* If this is an asm statement, and the user asked for the
7116 impossible, don't die. Fail and let gimplify_asm_expr 7216 impossible, don't die. Fail and let gimplify_asm_expr
7117 issue an error. */ 7217 issue an error. */
7118 ret = GS_ERROR; 7218 ret = GS_ERROR;
7119 goto out; 7219 goto out;
7120 } 7220 }
7121 7221
7122 /* Make sure the temporary matches our predicate. */ 7222 /* Make sure the temporary matches our predicate. */
7162 case FIXED_POINT_TYPE: 7262 case FIXED_POINT_TYPE:
7163 gimplify_one_sizepos (&TYPE_MIN_VALUE (type), list_p); 7263 gimplify_one_sizepos (&TYPE_MIN_VALUE (type), list_p);
7164 gimplify_one_sizepos (&TYPE_MAX_VALUE (type), list_p); 7264 gimplify_one_sizepos (&TYPE_MAX_VALUE (type), list_p);
7165 7265
7166 for (t = TYPE_NEXT_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t)) 7266 for (t = TYPE_NEXT_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
7167 { 7267 {
7168 TYPE_MIN_VALUE (t) = TYPE_MIN_VALUE (type); 7268 TYPE_MIN_VALUE (t) = TYPE_MIN_VALUE (type);
7169 TYPE_MAX_VALUE (t) = TYPE_MAX_VALUE (type); 7269 TYPE_MAX_VALUE (t) = TYPE_MAX_VALUE (type);
7170 } 7270 }
7171 break; 7271 break;
7172 7272
7173 case ARRAY_TYPE: 7273 case ARRAY_TYPE:
7174 /* These types may not have declarations, so handle them here. */ 7274 /* These types may not have declarations, so handle them here. */
7175 gimplify_type_sizes (TREE_TYPE (type), list_p); 7275 gimplify_type_sizes (TREE_TYPE (type), list_p);
7176 gimplify_type_sizes (TYPE_DOMAIN (type), list_p); 7276 gimplify_type_sizes (TYPE_DOMAIN (type), list_p);
7177 /* When not optimizing, ensure VLA bounds aren't removed. */ 7277 /* When not optimizing, ensure VLA bounds aren't removed. */
7178 if (!optimize 7278 if (!optimize
7179 && TYPE_DOMAIN (type) 7279 && TYPE_DOMAIN (type)
7180 && INTEGRAL_TYPE_P (TYPE_DOMAIN (type))) 7280 && INTEGRAL_TYPE_P (TYPE_DOMAIN (type)))
7181 { 7281 {
7182 t = TYPE_MIN_VALUE (TYPE_DOMAIN (type)); 7282 t = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
7183 if (t && TREE_CODE (t) == VAR_DECL && DECL_ARTIFICIAL (t)) 7283 if (t && TREE_CODE (t) == VAR_DECL && DECL_ARTIFICIAL (t))
7184 DECL_IGNORED_P (t) = 0; 7284 DECL_IGNORED_P (t) = 0;
7185 t = TYPE_MAX_VALUE (TYPE_DOMAIN (type)); 7285 t = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
7186 if (t && TREE_CODE (t) == VAR_DECL && DECL_ARTIFICIAL (t)) 7286 if (t && TREE_CODE (t) == VAR_DECL && DECL_ARTIFICIAL (t))
7187 DECL_IGNORED_P (t) = 0; 7287 DECL_IGNORED_P (t) = 0;
7188 } 7288 }
7189 break; 7289 break;
7190 7290
7191 case RECORD_TYPE: 7291 case RECORD_TYPE:
7192 case UNION_TYPE: 7292 case UNION_TYPE:
7193 case QUAL_UNION_TYPE: 7293 case QUAL_UNION_TYPE:
7194 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) 7294 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
7195 if (TREE_CODE (field) == FIELD_DECL) 7295 if (TREE_CODE (field) == FIELD_DECL)
7196 { 7296 {
7197 gimplify_one_sizepos (&DECL_FIELD_OFFSET (field), list_p); 7297 gimplify_one_sizepos (&DECL_FIELD_OFFSET (field), list_p);
7198 gimplify_one_sizepos (&DECL_SIZE (field), list_p); 7298 gimplify_one_sizepos (&DECL_SIZE (field), list_p);
7199 gimplify_one_sizepos (&DECL_SIZE_UNIT (field), list_p); 7299 gimplify_one_sizepos (&DECL_SIZE_UNIT (field), list_p);
7200 gimplify_type_sizes (TREE_TYPE (field), list_p); 7300 gimplify_type_sizes (TREE_TYPE (field), list_p);
7201 } 7301 }
7202 break; 7302 break;
7203 7303
7204 case POINTER_TYPE: 7304 case POINTER_TYPE:
7205 case REFERENCE_TYPE: 7305 case REFERENCE_TYPE:
7206 /* We used to recurse on the pointed-to type here, which turned out to 7306 /* We used to recurse on the pointed-to type here, which turned out to
7207 be incorrect because its definition might refer to variables not 7307 be incorrect because its definition might refer to variables not
7208 yet initialized at this point if a forward declaration is involved. 7308 yet initialized at this point if a forward declaration is involved.
7209 7309
7210 It was actually useful for anonymous pointed-to types to ensure 7310 It was actually useful for anonymous pointed-to types to ensure
7211 that the sizes evaluation dominates every possible later use of the 7311 that the sizes evaluation dominates every possible later use of the
7212 values. Restricting to such types here would be safe since there 7312 values. Restricting to such types here would be safe since there
7213 is no possible forward declaration around, but would introduce an 7313 is no possible forward declaration around, but would introduce an
7214 undesirable middle-end semantic to anonymity. We then defer to 7314 undesirable middle-end semantic to anonymity. We then defer to
7215 front-ends the responsibility of ensuring that the sizes are 7315 front-ends the responsibility of ensuring that the sizes are
7216 evaluated both early and late enough, e.g. by attaching artificial 7316 evaluated both early and late enough, e.g. by attaching artificial
7217 type declarations to the tree. */ 7317 type declarations to the tree. */
7218 break; 7318 break;
7219 7319
7220 default: 7320 default:
7221 break; 7321 break;
7222 } 7322 }
7272 7372
7273 *expr_p = create_tmp_var (type, NULL); 7373 *expr_p = create_tmp_var (type, NULL);
7274 tmp = build1 (NOP_EXPR, type, expr); 7374 tmp = build1 (NOP_EXPR, type, expr);
7275 stmt = gimplify_assign (*expr_p, tmp, stmt_p); 7375 stmt = gimplify_assign (*expr_p, tmp, stmt_p);
7276 if (EXPR_HAS_LOCATION (expr)) 7376 if (EXPR_HAS_LOCATION (expr))
7277 gimple_set_location (stmt, *EXPR_LOCUS (expr)); 7377 gimple_set_location (stmt, EXPR_LOCATION (expr));
7278 else 7378 else
7279 gimple_set_location (stmt, input_location); 7379 gimple_set_location (stmt, input_location);
7280 } 7380 }
7281 } 7381 }
7282 7382
7283 7383
7284 /* Gimplify the body of statements pointed to by BODY_P and return a 7384 /* Gimplify the body of statements pointed to by BODY_P and return a
7307 It would seem we don't have to do this for nested functions because 7407 It would seem we don't have to do this for nested functions because
7308 they are supposed to be output and then the outer function gimplified 7408 they are supposed to be output and then the outer function gimplified
7309 first, but the g++ front end doesn't always do it that way. */ 7409 first, but the g++ front end doesn't always do it that way. */
7310 unshare_body (body_p, fndecl); 7410 unshare_body (body_p, fndecl);
7311 unvisit_body (body_p, fndecl); 7411 unvisit_body (body_p, fndecl);
7412
7413 if (cgraph_node (fndecl)->origin)
7414 nonlocal_vlas = pointer_set_create ();
7312 7415
7313 /* Make sure input_location isn't set to something weird. */ 7416 /* Make sure input_location isn't set to something weird. */
7314 input_location = DECL_SOURCE_LOCATION (fndecl); 7417 input_location = DECL_SOURCE_LOCATION (fndecl);
7315 7418
7316 /* Resolve callee-copies. This has to be done before processing 7419 /* Resolve callee-copies. This has to be done before processing
7343 { 7446 {
7344 gimplify_seq_add_seq (&parm_stmts, gimple_bind_body (outer_bind)); 7447 gimplify_seq_add_seq (&parm_stmts, gimple_bind_body (outer_bind));
7345 gimple_bind_set_body (outer_bind, parm_stmts); 7448 gimple_bind_set_body (outer_bind, parm_stmts);
7346 } 7449 }
7347 7450
7451 if (nonlocal_vlas)
7452 {
7453 pointer_set_destroy (nonlocal_vlas);
7454 nonlocal_vlas = NULL;
7455 }
7456
7348 pop_gimplify_context (outer_bind); 7457 pop_gimplify_context (outer_bind);
7349 gcc_assert (gimplify_ctxp == NULL); 7458 gcc_assert (gimplify_ctxp == NULL);
7350 7459
7351 #ifdef ENABLE_TYPES_CHECKING 7460 #ifdef ENABLE_TYPES_CHECKING
7352 if (!errorcount && !sorrycount) 7461 if (!errorcount && !sorrycount)
7359 return outer_bind; 7468 return outer_bind;
7360 } 7469 }
7361 7470
7362 /* Entry point to the gimplification pass. FNDECL is the FUNCTION_DECL 7471 /* Entry point to the gimplification pass. FNDECL is the FUNCTION_DECL
7363 node for the function we want to gimplify. 7472 node for the function we want to gimplify.
7364 7473
7365 Returns the sequence of GIMPLE statements corresponding to the body 7474 Returns the sequence of GIMPLE statements corresponding to the body
7366 of FNDECL. */ 7475 of FNDECL. */
7367 7476
7368 void 7477 void
7369 gimplify_function_tree (tree fndecl) 7478 gimplify_function_tree (tree fndecl)
7370 { 7479 {
7371 tree oldfn, parm, ret; 7480 tree oldfn, parm, ret;
7372 gimple_seq seq; 7481 gimple_seq seq;
7373 gimple bind; 7482 gimple bind;
7483
7484 gcc_assert (!gimple_body (fndecl));
7374 7485
7375 oldfn = current_function_decl; 7486 oldfn = current_function_decl;
7376 current_function_decl = fndecl; 7487 current_function_decl = fndecl;
7377 if (DECL_STRUCT_FUNCTION (fndecl)) 7488 if (DECL_STRUCT_FUNCTION (fndecl))
7378 push_cfun (DECL_STRUCT_FUNCTION (fndecl)); 7489 push_cfun (DECL_STRUCT_FUNCTION (fndecl));
7383 { 7494 {
7384 /* Preliminarily mark non-addressed complex variables as eligible 7495 /* Preliminarily mark non-addressed complex variables as eligible
7385 for promotion to gimple registers. We'll transform their uses 7496 for promotion to gimple registers. We'll transform their uses
7386 as we find them. */ 7497 as we find them. */
7387 if ((TREE_CODE (TREE_TYPE (parm)) == COMPLEX_TYPE 7498 if ((TREE_CODE (TREE_TYPE (parm)) == COMPLEX_TYPE
7388 || TREE_CODE (TREE_TYPE (parm)) == VECTOR_TYPE) 7499 || TREE_CODE (TREE_TYPE (parm)) == VECTOR_TYPE)
7389 && !TREE_THIS_VOLATILE (parm) 7500 && !TREE_THIS_VOLATILE (parm)
7390 && !needs_to_live_in_memory (parm)) 7501 && !needs_to_live_in_memory (parm))
7391 DECL_GIMPLE_REG_P (parm) = 1; 7502 DECL_GIMPLE_REG_P (parm) = 1;
7392 } 7503 }
7393 7504
7436 gimple_seq_add_stmt (&seq, new_bind); 7547 gimple_seq_add_stmt (&seq, new_bind);
7437 gimple_set_body (fndecl, seq); 7548 gimple_set_body (fndecl, seq);
7438 } 7549 }
7439 7550
7440 DECL_SAVED_TREE (fndecl) = NULL_TREE; 7551 DECL_SAVED_TREE (fndecl) = NULL_TREE;
7552 cfun->curr_properties = PROP_gimple_any;
7441 7553
7442 current_function_decl = oldfn; 7554 current_function_decl = oldfn;
7443 pop_cfun (); 7555 pop_cfun ();
7444 } 7556 }
7445 7557
7463 7575
7464 switch (gimple_code (stmt)) 7576 switch (gimple_code (stmt))
7465 { 7577 {
7466 case GIMPLE_COND: 7578 case GIMPLE_COND:
7467 gimplify_expr (gimple_cond_lhs_ptr (stmt), &pre, NULL, 7579 gimplify_expr (gimple_cond_lhs_ptr (stmt), &pre, NULL,
7468 is_gimple_val, fb_rvalue); 7580 is_gimple_val, fb_rvalue);
7469 gimplify_expr (gimple_cond_rhs_ptr (stmt), &pre, NULL, 7581 gimplify_expr (gimple_cond_rhs_ptr (stmt), &pre, NULL,
7470 is_gimple_val, fb_rvalue); 7582 is_gimple_val, fb_rvalue);
7471 break; 7583 break;
7472 case GIMPLE_SWITCH: 7584 case GIMPLE_SWITCH:
7473 gimplify_expr (gimple_switch_index_ptr (stmt), &pre, NULL, 7585 gimplify_expr (gimple_switch_index_ptr (stmt), &pre, NULL,
7474 is_gimple_val, fb_rvalue); 7586 is_gimple_val, fb_rvalue);
7475 break; 7587 break;
7476 case GIMPLE_OMP_ATOMIC_LOAD: 7588 case GIMPLE_OMP_ATOMIC_LOAD:
7477 gimplify_expr (gimple_omp_atomic_load_rhs_ptr (stmt), &pre, NULL, 7589 gimplify_expr (gimple_omp_atomic_load_rhs_ptr (stmt), &pre, NULL,
7478 is_gimple_val, fb_rvalue); 7590 is_gimple_val, fb_rvalue);
7479 break; 7591 break;
7480 case GIMPLE_ASM: 7592 case GIMPLE_ASM:
7481 { 7593 {
7482 size_t i, noutputs = gimple_asm_noutputs (stmt); 7594 size_t i, noutputs = gimple_asm_noutputs (stmt);
7483 const char *constraint, **oconstraints; 7595 const char *constraint, **oconstraints;
7484 bool allows_mem, allows_reg, is_inout; 7596 bool allows_mem, allows_reg, is_inout;
7485 7597
7486 oconstraints 7598 oconstraints
7487 = (const char **) alloca ((noutputs) * sizeof (const char *)); 7599 = (const char **) alloca ((noutputs) * sizeof (const char *));
7488 for (i = 0; i < noutputs; i++) 7600 for (i = 0; i < noutputs; i++)
7489 { 7601 {
7490 tree op = gimple_asm_output_op (stmt, i); 7602 tree op = gimple_asm_output_op (stmt, i);
7491 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op))); 7603 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
7492 oconstraints[i] = constraint; 7604 oconstraints[i] = constraint;
7493 parse_output_constraint (&constraint, i, 0, 0, &allows_mem, 7605 parse_output_constraint (&constraint, i, 0, 0, &allows_mem,
7494 &allows_reg, &is_inout); 7606 &allows_reg, &is_inout);
7495 gimplify_expr (&TREE_VALUE (op), &pre, NULL, 7607 gimplify_expr (&TREE_VALUE (op), &pre, NULL,
7496 is_inout ? is_gimple_min_lval : is_gimple_lvalue, 7608 is_inout ? is_gimple_min_lval : is_gimple_lvalue,
7497 fb_lvalue | fb_mayfail); 7609 fb_lvalue | fb_mayfail);
7498 } 7610 }
7499 for (i = 0; i < gimple_asm_ninputs (stmt); i++) 7611 for (i = 0; i < gimple_asm_ninputs (stmt); i++)
7500 { 7612 {
7501 tree op = gimple_asm_input_op (stmt, i); 7613 tree op = gimple_asm_input_op (stmt, i);
7502 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op))); 7614 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
7503 parse_input_constraint (&constraint, 0, 0, noutputs, 0, 7615 parse_input_constraint (&constraint, 0, 0, noutputs, 0,
7504 oconstraints, &allows_mem, &allows_reg); 7616 oconstraints, &allows_mem, &allows_reg);
7505 if (TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (op))) && allows_mem) 7617 if (TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (op))) && allows_mem)
7506 allows_reg = 0; 7618 allows_reg = 0;
7507 if (!allows_reg && allows_mem) 7619 if (!allows_reg && allows_mem)
7508 gimplify_expr (&TREE_VALUE (op), &pre, NULL, 7620 gimplify_expr (&TREE_VALUE (op), &pre, NULL,
7509 is_gimple_lvalue, fb_lvalue | fb_mayfail); 7621 is_gimple_lvalue, fb_lvalue | fb_mayfail);
7510 else 7622 else
7511 gimplify_expr (&TREE_VALUE (op), &pre, NULL, 7623 gimplify_expr (&TREE_VALUE (op), &pre, NULL,
7512 is_gimple_asm_val, fb_rvalue); 7624 is_gimple_asm_val, fb_rvalue);
7513 } 7625 }
7514 } 7626 }
7515 break; 7627 break;
7516 default: 7628 default:
7517 /* NOTE: We start gimplifying operands from last to first to 7629 /* NOTE: We start gimplifying operands from last to first to
7518 make sure that side-effects on the RHS of calls, assignments 7630 make sure that side-effects on the RHS of calls, assignments
7519 and ASMs are executed before the LHS. The ordering is not 7631 and ASMs are executed before the LHS. The ordering is not
7520 important for other statements. */ 7632 important for other statements. */
7521 num_ops = gimple_num_ops (stmt); 7633 num_ops = gimple_num_ops (stmt);
7522 orig_lhs = gimple_get_lhs (stmt); 7634 orig_lhs = gimple_get_lhs (stmt);
7523 for (i = num_ops; i > 0; i--) 7635 for (i = num_ops; i > 0; i--)
7524 { 7636 {
7525 tree op = gimple_op (stmt, i - 1); 7637 tree op = gimple_op (stmt, i - 1);
7526 if (op == NULL_TREE) 7638 if (op == NULL_TREE)
7527 continue; 7639 continue;
7528 if (i == 1 && (is_gimple_call (stmt) || is_gimple_assign (stmt))) 7640 if (i == 1 && (is_gimple_call (stmt) || is_gimple_assign (stmt)))
7529 gimplify_expr (&op, &pre, NULL, is_gimple_lvalue, fb_lvalue); 7641 gimplify_expr (&op, &pre, NULL, is_gimple_lvalue, fb_lvalue);
7530 else if (i == 2 7642 else if (i == 2
7531 && is_gimple_assign (stmt) 7643 && is_gimple_assign (stmt)
7532 && num_ops == 2 7644 && num_ops == 2
7533 && get_gimple_rhs_class (gimple_expr_code (stmt)) 7645 && get_gimple_rhs_class (gimple_expr_code (stmt))
7534 == GIMPLE_SINGLE_RHS) 7646 == GIMPLE_SINGLE_RHS)
7535 gimplify_expr (&op, &pre, NULL, 7647 gimplify_expr (&op, &pre, NULL,
7536 rhs_predicate_for (gimple_assign_lhs (stmt)), 7648 rhs_predicate_for (gimple_assign_lhs (stmt)),
7537 fb_rvalue); 7649 fb_rvalue);
7538 else if (i == 2 && is_gimple_call (stmt)) 7650 else if (i == 2 && is_gimple_call (stmt))
7539 { 7651 {
7540 if (TREE_CODE (op) == FUNCTION_DECL) 7652 if (TREE_CODE (op) == FUNCTION_DECL)
7541 continue; 7653 continue;
7542 gimplify_expr (&op, &pre, NULL, is_gimple_call_addr, fb_rvalue); 7654 gimplify_expr (&op, &pre, NULL, is_gimple_call_addr, fb_rvalue);
7543 } 7655 }
7544 else 7656 else
7545 gimplify_expr (&op, &pre, NULL, is_gimple_val, fb_rvalue); 7657 gimplify_expr (&op, &pre, NULL, is_gimple_val, fb_rvalue);
7546 gimple_set_op (stmt, i - 1, op); 7658 gimple_set_op (stmt, i - 1, op);
7547 } 7659 }
7548 7660
7549 lhs = gimple_get_lhs (stmt); 7661 lhs = gimple_get_lhs (stmt);
7550 /* If the LHS changed it in a way that requires a simple RHS, 7662 /* If the LHS changed it in a way that requires a simple RHS,
7551 create temporary. */ 7663 create temporary. */
7552 if (lhs && !is_gimple_formal_tmp_var (lhs)) 7664 if (lhs && !is_gimple_reg (lhs))
7553 { 7665 {
7554 bool need_temp = false; 7666 bool need_temp = false;
7555 7667
7556 if (is_gimple_assign (stmt) 7668 if (is_gimple_assign (stmt)
7557 && num_ops == 2 7669 && num_ops == 2
7558 && get_gimple_rhs_class (gimple_expr_code (stmt)) 7670 && get_gimple_rhs_class (gimple_expr_code (stmt))
7559 == GIMPLE_SINGLE_RHS) 7671 == GIMPLE_SINGLE_RHS)
7560 gimplify_expr (gimple_assign_rhs1_ptr (stmt), &pre, NULL, 7672 gimplify_expr (gimple_assign_rhs1_ptr (stmt), &pre, NULL,
7561 rhs_predicate_for (gimple_assign_lhs (stmt)), 7673 rhs_predicate_for (gimple_assign_lhs (stmt)),
7562 fb_rvalue); 7674 fb_rvalue);
7563 else if (is_gimple_reg (lhs)) 7675 else if (is_gimple_reg (lhs))
7564 { 7676 {
7565 if (is_gimple_reg_type (TREE_TYPE (lhs))) 7677 if (is_gimple_reg_type (TREE_TYPE (lhs)))
7566 { 7678 {
7567 if (is_gimple_call (stmt)) 7679 if (is_gimple_call (stmt))
7568 { 7680 {
7569 i = gimple_call_flags (stmt); 7681 i = gimple_call_flags (stmt);
7570 if ((i & ECF_LOOPING_CONST_OR_PURE) 7682 if ((i & ECF_LOOPING_CONST_OR_PURE)
7571 || !(i & (ECF_CONST | ECF_PURE))) 7683 || !(i & (ECF_CONST | ECF_PURE)))
7572 need_temp = true; 7684 need_temp = true;
7573 } 7685 }
7574 if (stmt_can_throw_internal (stmt)) 7686 if (stmt_can_throw_internal (stmt))
7575 need_temp = true; 7687 need_temp = true;
7576 } 7688 }
7577 } 7689 }
7578 else 7690 else
7579 { 7691 {
7580 if (is_gimple_reg_type (TREE_TYPE (lhs))) 7692 if (is_gimple_reg_type (TREE_TYPE (lhs)))
7581 need_temp = true; 7693 need_temp = true;
7582 else if (TYPE_MODE (TREE_TYPE (lhs)) != BLKmode) 7694 else if (TYPE_MODE (TREE_TYPE (lhs)) != BLKmode)
7583 { 7695 {
7584 if (is_gimple_call (stmt)) 7696 if (is_gimple_call (stmt))
7585 { 7697 {
7586 tree fndecl = gimple_call_fndecl (stmt); 7698 tree fndecl = gimple_call_fndecl (stmt);
7587 7699
7588 if (!aggregate_value_p (TREE_TYPE (lhs), fndecl) 7700 if (!aggregate_value_p (TREE_TYPE (lhs), fndecl)
7589 && !(fndecl && DECL_RESULT (fndecl) 7701 && !(fndecl && DECL_RESULT (fndecl)
7590 && DECL_BY_REFERENCE (DECL_RESULT (fndecl)))) 7702 && DECL_BY_REFERENCE (DECL_RESULT (fndecl))))
7591 need_temp = true; 7703 need_temp = true;
7592 } 7704 }
7593 else 7705 else
7594 need_temp = true; 7706 need_temp = true;
7595 } 7707 }
7596 } 7708 }
7597 if (need_temp) 7709 if (need_temp)
7598 { 7710 {
7599 tree temp = create_tmp_var (TREE_TYPE (lhs), NULL); 7711 tree temp = create_tmp_var (TREE_TYPE (lhs), NULL);
7600 7712
7601 DECL_GIMPLE_FORMAL_TEMP_P (temp) = 1; 7713 if (TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE
7602 if (TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE 7714 || TREE_CODE (TREE_TYPE (lhs)) == VECTOR_TYPE)
7603 || TREE_CODE (TREE_TYPE (lhs)) == VECTOR_TYPE) 7715 DECL_GIMPLE_REG_P (temp) = 1;
7604 DECL_GIMPLE_REG_P (temp) = 1; 7716 if (TREE_CODE (orig_lhs) == SSA_NAME)
7605 if (TREE_CODE (orig_lhs) == SSA_NAME) 7717 orig_lhs = SSA_NAME_VAR (orig_lhs);
7606 orig_lhs = SSA_NAME_VAR (orig_lhs); 7718
7607 if (TREE_CODE (orig_lhs) == VAR_DECL 7719 if (gimple_in_ssa_p (cfun))
7608 && DECL_BASED_ON_RESTRICT_P (orig_lhs)) 7720 temp = make_ssa_name (temp, NULL);
7609 { 7721 gimple_set_lhs (stmt, temp);
7610 DECL_BASED_ON_RESTRICT_P (temp) = 1; 7722 post_stmt = gimple_build_assign (lhs, temp);
7611 SET_DECL_RESTRICT_BASE (temp, 7723 if (TREE_CODE (lhs) == SSA_NAME)
7612 DECL_GET_RESTRICT_BASE (orig_lhs)); 7724 SSA_NAME_DEF_STMT (lhs) = post_stmt;
7613 } 7725 }
7614 7726 }
7615 if (gimple_in_ssa_p (cfun))
7616 temp = make_ssa_name (temp, NULL);
7617 gimple_set_lhs (stmt, temp);
7618 post_stmt = gimple_build_assign (lhs, temp);
7619 if (TREE_CODE (lhs) == SSA_NAME)
7620 SSA_NAME_DEF_STMT (lhs) = post_stmt;
7621 }
7622 }
7623 break; 7727 break;
7624 } 7728 }
7625 7729
7626 if (gimple_referenced_vars (cfun)) 7730 if (gimple_referenced_vars (cfun))
7627 for (t = gimplify_ctxp->temps; t ; t = TREE_CHAIN (t)) 7731 for (t = gimplify_ctxp->temps; t ; t = TREE_CHAIN (t))
7628 add_referenced_var (t); 7732 add_referenced_var (t);
7629 7733
7630 if (!gimple_seq_empty_p (pre)) 7734 if (!gimple_seq_empty_p (pre))
7631 { 7735 {
7632 if (gimple_in_ssa_p (cfun)) 7736 if (gimple_in_ssa_p (cfun))
7633 { 7737 {
7634 gimple_stmt_iterator i; 7738 gimple_stmt_iterator i;
7635 7739
7636 for (i = gsi_start (pre); !gsi_end_p (i); gsi_next (&i)) 7740 for (i = gsi_start (pre); !gsi_end_p (i); gsi_next (&i))
7637 mark_symbols_for_renaming (gsi_stmt (i)); 7741 mark_symbols_for_renaming (gsi_stmt (i));
7638 } 7742 }
7639 gsi_insert_seq_before (gsi_p, pre, GSI_SAME_STMT); 7743 gsi_insert_seq_before (gsi_p, pre, GSI_SAME_STMT);
7640 } 7744 }
7641 if (post_stmt) 7745 if (post_stmt)
7642 gsi_insert_after (gsi_p, post_stmt, GSI_NEW_STMT); 7746 gsi_insert_after (gsi_p, post_stmt, GSI_NEW_STMT);
7643 7747
7699 it. M specifies the way GSI moves after insertion (GSI_SAME_STMT or 7803 it. M specifies the way GSI moves after insertion (GSI_SAME_STMT or
7700 GSI_CONTINUE_LINKING are the usual values). */ 7804 GSI_CONTINUE_LINKING are the usual values). */
7701 7805
7702 tree 7806 tree
7703 force_gimple_operand_gsi (gimple_stmt_iterator *gsi, tree expr, 7807 force_gimple_operand_gsi (gimple_stmt_iterator *gsi, tree expr,
7704 bool simple_p, tree var, bool before, 7808 bool simple_p, tree var, bool before,
7705 enum gsi_iterator_update m) 7809 enum gsi_iterator_update m)
7706 { 7810 {
7707 gimple_seq stmts; 7811 gimple_seq stmts;
7708 7812
7709 expr = force_gimple_operand (expr, &stmts, simple_p, var); 7813 expr = force_gimple_operand (expr, &stmts, simple_p, var);
7710 7814
7711 if (!gimple_seq_empty_p (stmts)) 7815 if (!gimple_seq_empty_p (stmts))
7712 { 7816 {
7713 if (gimple_in_ssa_p (cfun)) 7817 if (gimple_in_ssa_p (cfun))
7714 { 7818 {
7715 gimple_stmt_iterator i; 7819 gimple_stmt_iterator i;
7716 7820
7717 for (i = gsi_start (stmts); !gsi_end_p (i); gsi_next (&i)) 7821 for (i = gsi_start (stmts); !gsi_end_p (i); gsi_next (&i))
7718 mark_symbols_for_renaming (gsi_stmt (i)); 7822 mark_symbols_for_renaming (gsi_stmt (i));
7719 } 7823 }
7720 7824
7721 if (before) 7825 if (before)
7722 gsi_insert_seq_before (gsi, stmts, m); 7826 gsi_insert_seq_before (gsi, stmts, m);
7723 else 7827 else
7724 gsi_insert_seq_after (gsi, stmts, m); 7828 gsi_insert_seq_after (gsi, stmts, m);
7725 } 7829 }
7726 7830
7727 return expr; 7831 return expr;
7728 } 7832 }
7729 7833