mirrored from git://gcc.gnu.org/git/gcc.git
/
tree.cc
6397 lines (5476 loc) · 178 KB
/
tree.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Language-dependent node constructors for parse phase of GNU compiler.
Copyright (C) 1987-2024 Free Software Foundation, Inc.
Hacked by Michael Tiemann (tiemann@cygnus.com)
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tree.h"
#include "cp-tree.h"
#include "gimple-expr.h"
#include "cgraph.h"
#include "stor-layout.h"
#include "print-tree.h"
#include "tree-iterator.h"
#include "tree-inline.h"
#include "debug.h"
#include "convert.h"
#include "gimplify.h"
#include "stringpool.h"
#include "attribs.h"
#include "flags.h"
#include "selftest.h"
static tree bot_manip (tree *, int *, void *);
static tree bot_replace (tree *, int *, void *);
static hashval_t list_hash_pieces (tree, tree, tree);
static tree build_target_expr (tree, tree, tsubst_flags_t);
static tree count_trees_r (tree *, int *, void *);
static tree verify_stmt_tree_r (tree *, int *, void *);
static tree handle_init_priority_attribute (tree *, tree, tree, int, bool *);
static tree handle_abi_tag_attribute (tree *, tree, tree, int, bool *);
static tree handle_contract_attribute (tree *, tree, tree, int, bool *);
static tree handle_no_dangling_attribute (tree *, tree, tree, int, bool *);
/* If REF is an lvalue, returns the kind of lvalue that REF is.
Otherwise, returns clk_none. */
cp_lvalue_kind
lvalue_kind (const_tree ref)
{
cp_lvalue_kind op1_lvalue_kind = clk_none;
cp_lvalue_kind op2_lvalue_kind = clk_none;
/* Expressions of reference type are sometimes wrapped in
INDIRECT_REFs. INDIRECT_REFs are just internal compiler
representation, not part of the language, so we have to look
through them. */
if (REFERENCE_REF_P (ref))
return lvalue_kind (TREE_OPERAND (ref, 0));
if (TREE_TYPE (ref)
&& TYPE_REF_P (TREE_TYPE (ref)))
{
/* unnamed rvalue references are rvalues */
if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref))
&& TREE_CODE (ref) != PARM_DECL
&& !VAR_P (ref)
&& TREE_CODE (ref) != COMPONENT_REF
/* Functions are always lvalues. */
&& TREE_CODE (TREE_TYPE (TREE_TYPE (ref))) != FUNCTION_TYPE)
{
op1_lvalue_kind = clk_rvalueref;
if (implicit_rvalue_p (ref))
op1_lvalue_kind |= clk_implicit_rval;
return op1_lvalue_kind;
}
/* lvalue references and named rvalue references are lvalues. */
return clk_ordinary;
}
if (ref == current_class_ptr)
return clk_none;
/* Expressions with cv void type are prvalues. */
if (TREE_TYPE (ref) && VOID_TYPE_P (TREE_TYPE (ref)))
return clk_none;
switch (TREE_CODE (ref))
{
case SAVE_EXPR:
return clk_none;
/* preincrements and predecrements are valid lvals, provided
what they refer to are valid lvals. */
case PREINCREMENT_EXPR:
case PREDECREMENT_EXPR:
case TRY_CATCH_EXPR:
case REALPART_EXPR:
case IMAGPART_EXPR:
case VIEW_CONVERT_EXPR:
op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
/* As for ARRAY_REF and COMPONENT_REF, these codes turn a class prvalue
into an xvalue: we need to materialize the temporary before we mess
with it. Except VIEW_CONVERT_EXPR that doesn't actually change the
type, as in location wrapper and REF_PARENTHESIZED_P. */
if (op1_lvalue_kind == clk_class
&& !(TREE_CODE (ref) == VIEW_CONVERT_EXPR
&& (same_type_ignoring_top_level_qualifiers_p
(TREE_TYPE (ref), TREE_TYPE (TREE_OPERAND (ref, 0))))))
return clk_rvalueref;
return op1_lvalue_kind;
case ARRAY_REF:
{
tree op1 = TREE_OPERAND (ref, 0);
if (TREE_CODE (TREE_TYPE (op1)) == ARRAY_TYPE)
{
op1_lvalue_kind = lvalue_kind (op1);
if (op1_lvalue_kind == clk_class)
/* in the case of an array operand, the result is an lvalue if
that operand is an lvalue and an xvalue otherwise */
op1_lvalue_kind = clk_rvalueref;
return op1_lvalue_kind;
}
else
return clk_ordinary;
}
case MEMBER_REF:
case DOTSTAR_EXPR:
if (TREE_CODE (ref) == MEMBER_REF)
op1_lvalue_kind = clk_ordinary;
else
op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
if (TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (ref, 1))))
op1_lvalue_kind = clk_none;
else if (op1_lvalue_kind == clk_class)
/* The result of a .* expression whose second operand is a pointer to a
data member is an lvalue if the first operand is an lvalue and an
xvalue otherwise. */
op1_lvalue_kind = clk_rvalueref;
return op1_lvalue_kind;
case COMPONENT_REF:
if (BASELINK_P (TREE_OPERAND (ref, 1)))
{
tree fn = BASELINK_FUNCTIONS (TREE_OPERAND (ref, 1));
/* For static member function recurse on the BASELINK, we can get
here e.g. from reference_binding. If BASELINK_FUNCTIONS is
OVERLOAD, the overload is resolved first if possible through
resolve_address_of_overloaded_function. */
if (TREE_CODE (fn) == FUNCTION_DECL && DECL_STATIC_FUNCTION_P (fn))
return lvalue_kind (TREE_OPERAND (ref, 1));
}
op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
if (op1_lvalue_kind == clk_class)
/* If E1 is an lvalue, then E1.E2 is an lvalue;
otherwise E1.E2 is an xvalue. */
op1_lvalue_kind = clk_rvalueref;
/* Look at the member designator. */
if (!op1_lvalue_kind)
;
else if (is_overloaded_fn (TREE_OPERAND (ref, 1)))
/* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
situations. If we're seeing a COMPONENT_REF, it's a non-static
member, so it isn't an lvalue. */
op1_lvalue_kind = clk_none;
else if (TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL)
/* This can be IDENTIFIER_NODE in a template. */;
else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1)))
{
/* Clear the ordinary bit. If this object was a class
rvalue we want to preserve that information. */
op1_lvalue_kind &= ~clk_ordinary;
/* The lvalue is for a bitfield. */
op1_lvalue_kind |= clk_bitfield;
}
else if (DECL_PACKED (TREE_OPERAND (ref, 1)))
op1_lvalue_kind |= clk_packed;
return op1_lvalue_kind;
case STRING_CST:
case COMPOUND_LITERAL_EXPR:
return clk_ordinary;
case CONST_DECL:
/* CONST_DECL without TREE_STATIC are enumeration values and
thus not lvalues. With TREE_STATIC they are used by ObjC++
in objc_build_string_object and need to be considered as
lvalues. */
if (! TREE_STATIC (ref))
return clk_none;
/* FALLTHRU */
case VAR_DECL:
if (VAR_P (ref) && DECL_HAS_VALUE_EXPR_P (ref))
return lvalue_kind (DECL_VALUE_EXPR (CONST_CAST_TREE (ref)));
if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
&& DECL_LANG_SPECIFIC (ref)
&& DECL_IN_AGGR_P (ref))
return clk_none;
/* FALLTHRU */
case INDIRECT_REF:
case ARROW_EXPR:
case PARM_DECL:
case RESULT_DECL:
case PLACEHOLDER_EXPR:
return clk_ordinary;
/* A scope ref in a template, left as SCOPE_REF to support later
access checking. */
case SCOPE_REF:
gcc_assert (!type_dependent_expression_p (CONST_CAST_TREE (ref)));
{
tree op = TREE_OPERAND (ref, 1);
if (TREE_CODE (op) == FIELD_DECL)
return (DECL_C_BIT_FIELD (op) ? clk_bitfield : clk_ordinary);
else
return lvalue_kind (op);
}
case MAX_EXPR:
case MIN_EXPR:
/* Disallow <? and >? as lvalues if either argument side-effects. */
if (TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 0))
|| TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 1)))
return clk_none;
op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
op2_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 1));
break;
case COND_EXPR:
if (processing_template_decl)
{
/* Within templates, a REFERENCE_TYPE will indicate whether
the COND_EXPR result is an ordinary lvalue or rvalueref.
Since REFERENCE_TYPEs are handled above, if we reach this
point, we know we got a plain rvalue. Unless we have a
type-dependent expr, that is, but we shouldn't be testing
lvalueness if we can't even tell the types yet! */
gcc_assert (!type_dependent_expression_p (CONST_CAST_TREE (ref)));
goto default_;
}
{
tree op1 = TREE_OPERAND (ref, 1);
if (!op1) op1 = TREE_OPERAND (ref, 0);
tree op2 = TREE_OPERAND (ref, 2);
op1_lvalue_kind = lvalue_kind (op1);
op2_lvalue_kind = lvalue_kind (op2);
if (!op1_lvalue_kind != !op2_lvalue_kind)
{
/* The second or the third operand (but not both) is a
throw-expression; the result is of the type
and value category of the other. */
if (op1_lvalue_kind && TREE_CODE (op2) == THROW_EXPR)
op2_lvalue_kind = op1_lvalue_kind;
else if (op2_lvalue_kind && TREE_CODE (op1) == THROW_EXPR)
op1_lvalue_kind = op2_lvalue_kind;
}
}
break;
case MODOP_EXPR:
/* We expect to see unlowered MODOP_EXPRs only during
template processing. */
gcc_assert (processing_template_decl);
return clk_ordinary;
case MODIFY_EXPR:
case TYPEID_EXPR:
return clk_ordinary;
case COMPOUND_EXPR:
return lvalue_kind (TREE_OPERAND (ref, 1));
case TARGET_EXPR:
return clk_class;
case VA_ARG_EXPR:
return (CLASS_TYPE_P (TREE_TYPE (ref)) ? clk_class : clk_none);
case CALL_EXPR:
/* We can see calls outside of TARGET_EXPR in templates. */
if (CLASS_TYPE_P (TREE_TYPE (ref)))
return clk_class;
return clk_none;
case FUNCTION_DECL:
/* All functions (except non-static-member functions) are
lvalues. */
return (DECL_IOBJ_MEMBER_FUNCTION_P (ref)
? clk_none : clk_ordinary);
case BASELINK:
/* We now represent a reference to a single static member function
with a BASELINK. */
/* This CONST_CAST is okay because BASELINK_FUNCTIONS returns
its argument unmodified and we assign it to a const_tree. */
return lvalue_kind (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref)));
case PAREN_EXPR:
return lvalue_kind (TREE_OPERAND (ref, 0));
case TEMPLATE_PARM_INDEX:
if (CLASS_TYPE_P (TREE_TYPE (ref)))
/* A template parameter object is an lvalue. */
return clk_ordinary;
return clk_none;
default:
default_:
if (!TREE_TYPE (ref))
return clk_none;
if (CLASS_TYPE_P (TREE_TYPE (ref))
|| TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE)
return clk_class;
return clk_none;
}
/* If one operand is not an lvalue at all, then this expression is
not an lvalue. */
if (!op1_lvalue_kind || !op2_lvalue_kind)
return clk_none;
/* Otherwise, it's an lvalue, and it has all the odd properties
contributed by either operand. */
op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
/* It's not an ordinary lvalue if it involves any other kind. */
if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
op1_lvalue_kind &= ~clk_ordinary;
/* It can't be both a pseudo-lvalue and a non-addressable lvalue.
A COND_EXPR of those should be wrapped in a TARGET_EXPR. */
if ((op1_lvalue_kind & (clk_rvalueref|clk_class))
&& (op1_lvalue_kind & (clk_bitfield|clk_packed)))
op1_lvalue_kind = clk_none;
return op1_lvalue_kind;
}
/* Returns the kind of lvalue that REF is, in the sense of [basic.lval]. */
cp_lvalue_kind
real_lvalue_p (const_tree ref)
{
cp_lvalue_kind kind = lvalue_kind (ref);
if (kind & (clk_rvalueref|clk_class))
return clk_none;
else
return kind;
}
/* c-common wants us to return bool. */
bool
lvalue_p (const_tree t)
{
return real_lvalue_p (t);
}
/* This differs from lvalue_p in that xvalues are included. */
bool
glvalue_p (const_tree ref)
{
cp_lvalue_kind kind = lvalue_kind (ref);
if (kind & clk_class)
return false;
else
return (kind != clk_none);
}
/* This differs from glvalue_p in that class prvalues are included. */
bool
obvalue_p (const_tree ref)
{
return (lvalue_kind (ref) != clk_none);
}
/* Returns true if REF is an xvalue (the result of dereferencing an rvalue
reference), false otherwise. */
bool
xvalue_p (const_tree ref)
{
return (lvalue_kind (ref) & clk_rvalueref);
}
/* True if REF is a bit-field. */
bool
bitfield_p (const_tree ref)
{
return (lvalue_kind (ref) & clk_bitfield);
}
/* C++-specific version of stabilize_reference. */
tree
cp_stabilize_reference (tree ref)
{
if (processing_template_decl)
/* As in cp_save_expr. */
return ref;
STRIP_ANY_LOCATION_WRAPPER (ref);
switch (TREE_CODE (ref))
{
/* We need to treat specially anything stabilize_reference doesn't
handle specifically. */
case VAR_DECL:
case PARM_DECL:
case RESULT_DECL:
CASE_CONVERT:
case FLOAT_EXPR:
case FIX_TRUNC_EXPR:
case INDIRECT_REF:
case COMPONENT_REF:
case BIT_FIELD_REF:
case ARRAY_REF:
case ARRAY_RANGE_REF:
case ERROR_MARK:
break;
default:
cp_lvalue_kind kind = lvalue_kind (ref);
if ((kind & ~clk_class) != clk_none)
{
tree type = unlowered_expr_type (ref);
bool rval = !!(kind & clk_rvalueref);
type = cp_build_reference_type (type, rval);
/* This inhibits warnings in, eg, cxx_mark_addressable
(c++/60955). */
warning_sentinel s (extra_warnings);
ref = build_static_cast (input_location, type, ref,
tf_error);
}
}
return stabilize_reference (ref);
}
/* Test whether DECL is a builtin that may appear in a
constant-expression. */
bool
builtin_valid_in_constant_expr_p (const_tree decl)
{
STRIP_ANY_LOCATION_WRAPPER (decl);
if (TREE_CODE (decl) != FUNCTION_DECL)
/* Not a function. */
return false;
if (DECL_BUILT_IN_CLASS (decl) != BUILT_IN_NORMAL)
{
if (fndecl_built_in_p (decl, BUILT_IN_FRONTEND))
switch (DECL_FE_FUNCTION_CODE (decl))
{
case CP_BUILT_IN_IS_CONSTANT_EVALUATED:
case CP_BUILT_IN_SOURCE_LOCATION:
case CP_BUILT_IN_IS_CORRESPONDING_MEMBER:
case CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS:
return true;
default:
break;
}
/* Not a built-in. */
return false;
}
switch (DECL_FUNCTION_CODE (decl))
{
/* These always have constant results like the corresponding
macros/symbol. */
case BUILT_IN_FILE:
case BUILT_IN_FUNCTION:
case BUILT_IN_LINE:
/* The following built-ins are valid in constant expressions
when their arguments are. */
case BUILT_IN_ADD_OVERFLOW_P:
case BUILT_IN_SUB_OVERFLOW_P:
case BUILT_IN_MUL_OVERFLOW_P:
/* These have constant results even if their operands are
non-constant. */
case BUILT_IN_CONSTANT_P:
case BUILT_IN_ATOMIC_ALWAYS_LOCK_FREE:
return true;
default:
return false;
}
}
/* Build a TARGET_EXPR, initializing the DECL with the VALUE. */
static tree
build_target_expr (tree decl, tree value, tsubst_flags_t complain)
{
tree t;
tree type = TREE_TYPE (decl);
value = mark_rvalue_use (value);
gcc_checking_assert (VOID_TYPE_P (TREE_TYPE (value))
|| TREE_TYPE (decl) == TREE_TYPE (value)
/* On ARM ctors return 'this'. */
|| (TYPE_PTR_P (TREE_TYPE (value))
&& TREE_CODE (value) == CALL_EXPR)
|| useless_type_conversion_p (TREE_TYPE (decl),
TREE_TYPE (value)));
/* Set TREE_READONLY for optimization, such as gimplify_init_constructor
moving a constant aggregate into .rodata. */
if (CP_TYPE_CONST_NON_VOLATILE_P (type)
&& !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
&& !VOID_TYPE_P (TREE_TYPE (value))
&& !TYPE_HAS_MUTABLE_P (type)
&& reduced_constant_expression_p (value))
TREE_READONLY (decl) = true;
if (complain & tf_no_cleanup)
/* The caller is building a new-expr and does not need a cleanup. */
t = NULL_TREE;
else
{
t = cxx_maybe_build_cleanup (decl, complain);
if (t == error_mark_node)
return error_mark_node;
}
set_target_expr_eliding (value);
t = build4 (TARGET_EXPR, type, decl, value, t, NULL_TREE);
if (location_t eloc = cp_expr_location (value))
SET_EXPR_LOCATION (t, eloc);
/* We always set TREE_SIDE_EFFECTS so that expand_expr does not
ignore the TARGET_EXPR. If there really turn out to be no
side-effects, then the optimizer should be able to get rid of
whatever code is generated anyhow. */
TREE_SIDE_EFFECTS (t) = 1;
return t;
}
/* Return an undeclared local temporary of type TYPE for use in building a
TARGET_EXPR. */
tree
build_local_temp (tree type)
{
tree slot = build_decl (input_location,
VAR_DECL, NULL_TREE, type);
DECL_ARTIFICIAL (slot) = 1;
DECL_IGNORED_P (slot) = 1;
DECL_CONTEXT (slot) = current_function_decl;
layout_decl (slot, 0);
return slot;
}
/* Return whether DECL is such a local temporary (or one from
create_tmp_var_raw). */
bool
is_local_temp (tree decl)
{
return (VAR_P (decl) && DECL_ARTIFICIAL (decl)
&& !TREE_STATIC (decl));
}
/* Set various status flags when building an AGGR_INIT_EXPR object T. */
static void
process_aggr_init_operands (tree t)
{
bool side_effects;
side_effects = TREE_SIDE_EFFECTS (t);
if (!side_effects)
{
int i, n;
n = TREE_OPERAND_LENGTH (t);
for (i = 1; i < n; i++)
{
tree op = TREE_OPERAND (t, i);
if (op && TREE_SIDE_EFFECTS (op))
{
side_effects = 1;
break;
}
}
}
TREE_SIDE_EFFECTS (t) = side_effects;
}
/* Build an AGGR_INIT_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE,
FN, and SLOT. NARGS is the number of call arguments which are specified
as a tree array ARGS. */
static tree
build_aggr_init_array (tree return_type, tree fn, tree slot, int nargs,
tree *args)
{
tree t;
int i;
t = build_vl_exp (AGGR_INIT_EXPR, nargs + 3);
TREE_TYPE (t) = return_type;
AGGR_INIT_EXPR_FN (t) = fn;
AGGR_INIT_EXPR_SLOT (t) = slot;
for (i = 0; i < nargs; i++)
AGGR_INIT_EXPR_ARG (t, i) = args[i];
process_aggr_init_operands (t);
return t;
}
/* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
target. TYPE is the type to be initialized.
Build an AGGR_INIT_EXPR to represent the initialization. This function
differs from build_cplus_new in that an AGGR_INIT_EXPR can only be used
to initialize another object, whereas a TARGET_EXPR can either
initialize another object or create its own temporary object, and as a
result building up a TARGET_EXPR requires that the type's destructor be
callable. */
tree
build_aggr_init_expr (tree type, tree init)
{
tree fn;
tree slot;
tree rval;
int is_ctor;
gcc_assert (!VOID_TYPE_P (type));
/* Don't build AGGR_INIT_EXPR in a template. */
if (processing_template_decl)
return init;
fn = cp_get_callee (init);
if (fn == NULL_TREE)
return convert (type, init);
is_ctor = (TREE_CODE (fn) == ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
&& DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0)));
/* We split the CALL_EXPR into its function and its arguments here.
Then, in expand_expr, we put them back together. The reason for
this is that this expression might be a default argument
expression. In that case, we need a new temporary every time the
expression is used. That's what break_out_target_exprs does; it
replaces every AGGR_INIT_EXPR with a copy that uses a fresh
temporary slot. Then, expand_expr builds up a call-expression
using the new slot. */
/* If we don't need to use a constructor to create an object of this
type, don't mess with AGGR_INIT_EXPR. */
if (is_ctor || TREE_ADDRESSABLE (type))
{
slot = build_local_temp (type);
if (TREE_CODE (init) == CALL_EXPR)
{
rval = build_aggr_init_array (void_type_node, fn, slot,
call_expr_nargs (init),
CALL_EXPR_ARGP (init));
AGGR_INIT_FROM_THUNK_P (rval)
= CALL_FROM_THUNK_P (init);
}
else
{
rval = build_aggr_init_array (void_type_node, fn, slot,
aggr_init_expr_nargs (init),
AGGR_INIT_EXPR_ARGP (init));
AGGR_INIT_FROM_THUNK_P (rval)
= AGGR_INIT_FROM_THUNK_P (init);
}
TREE_SIDE_EFFECTS (rval) = 1;
AGGR_INIT_VIA_CTOR_P (rval) = is_ctor;
TREE_NOTHROW (rval) = TREE_NOTHROW (init);
CALL_EXPR_OPERATOR_SYNTAX (rval) = CALL_EXPR_OPERATOR_SYNTAX (init);
CALL_EXPR_ORDERED_ARGS (rval) = CALL_EXPR_ORDERED_ARGS (init);
CALL_EXPR_REVERSE_ARGS (rval) = CALL_EXPR_REVERSE_ARGS (init);
SET_EXPR_LOCATION (rval, EXPR_LOCATION (init));
}
else
rval = init;
return rval;
}
/* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
target. TYPE is the type that this initialization should appear to
have.
Build an encapsulation of the initialization to perform
and return it so that it can be processed by language-independent
and language-specific expression expanders. */
tree
build_cplus_new (tree type, tree init, tsubst_flags_t complain)
{
/* This function should cope with what build_special_member_call
can produce. When performing parenthesized aggregate initialization,
it can produce a { }. */
if (BRACE_ENCLOSED_INITIALIZER_P (init))
{
gcc_assert (cxx_dialect >= cxx20);
return finish_compound_literal (type, init, complain);
}
tree rval = build_aggr_init_expr (type, init);
tree slot;
if (init == error_mark_node)
return error_mark_node;
if (!complete_type_or_maybe_complain (type, init, complain))
return error_mark_node;
/* Make sure that we're not trying to create an instance of an
abstract class. */
if (abstract_virtuals_error (NULL_TREE, type, complain))
return error_mark_node;
if (TREE_CODE (rval) == AGGR_INIT_EXPR)
slot = AGGR_INIT_EXPR_SLOT (rval);
else if (TREE_CODE (rval) == CALL_EXPR
|| TREE_CODE (rval) == CONSTRUCTOR)
slot = build_local_temp (type);
else
return rval;
rval = build_target_expr (slot, rval, complain);
if (rval != error_mark_node)
TARGET_EXPR_IMPLICIT_P (rval) = 1;
return rval;
}
/* Subroutine of build_vec_init_expr: Build up a single element
intialization as a proxy for the full array initialization to get things
marked as used and any appropriate diagnostics.
This used to be necessary because we were deferring building the actual
constructor calls until gimplification time; now we only do it to set
VEC_INIT_EXPR_IS_CONSTEXPR.
We assume that init is either NULL_TREE, {}, void_type_node (indicating
value-initialization), or another array to copy. */
static tree
build_vec_init_elt (tree type, tree init, tsubst_flags_t complain)
{
tree inner_type = strip_array_types (type);
if (integer_zerop (array_type_nelts_total (type))
|| !CLASS_TYPE_P (inner_type))
/* No interesting initialization to do. */
return integer_zero_node;
if (init && BRACE_ENCLOSED_INITIALIZER_P (init))
{
/* Even if init has initializers for some array elements,
we're interested in the {}-init of trailing elements. */
if (CP_AGGREGATE_TYPE_P (inner_type))
{
tree empty = build_constructor (init_list_type_node, nullptr);
return digest_init (inner_type, empty, complain);
}
else
/* It's equivalent to value-init. */
init = void_type_node;
}
if (init == void_type_node)
return build_value_init (inner_type, complain);
releasing_vec argvec;
if (init && !BRACE_ENCLOSED_INITIALIZER_P (init))
{
tree init_type = strip_array_types (TREE_TYPE (init));
tree dummy = build_dummy_object (init_type);
if (!lvalue_p (init))
dummy = move (dummy);
argvec->quick_push (dummy);
}
init = build_special_member_call (NULL_TREE, complete_ctor_identifier,
&argvec, inner_type, LOOKUP_NORMAL,
complain);
/* For a trivial constructor, build_over_call creates a TARGET_EXPR. But
we don't want one here because we aren't creating a temporary. */
if (TREE_CODE (init) == TARGET_EXPR)
init = TARGET_EXPR_INITIAL (init);
return init;
}
/* Return a TARGET_EXPR which expresses the initialization of an array to
be named later, either default-initialization or copy-initialization
from another array of the same type. */
tree
build_vec_init_expr (tree type, tree init, tsubst_flags_t complain)
{
if (tree vi = get_vec_init_expr (init))
return vi;
tree elt_init;
if (init && TREE_CODE (init) == CONSTRUCTOR
&& !BRACE_ENCLOSED_INITIALIZER_P (init))
/* We built any needed constructor calls in digest_init. */
elt_init = init;
else
elt_init = build_vec_init_elt (type, init, complain);
bool value_init = false;
if (init == void_type_node)
{
value_init = true;
init = NULL_TREE;
}
tree slot = build_local_temp (type);
init = build2 (VEC_INIT_EXPR, type, slot, init);
TREE_SIDE_EFFECTS (init) = true;
SET_EXPR_LOCATION (init, input_location);
if (cxx_dialect >= cxx11)
{
bool cx = potential_constant_expression (elt_init);
if (BRACE_ENCLOSED_INITIALIZER_P (init))
cx &= potential_constant_expression (init);
VEC_INIT_EXPR_IS_CONSTEXPR (init) = cx;
}
VEC_INIT_EXPR_VALUE_INIT (init) = value_init;
return init;
}
/* Call build_vec_init to expand VEC_INIT into TARGET (for which NULL_TREE
means VEC_INIT_EXPR_SLOT). */
tree
expand_vec_init_expr (tree target, tree vec_init, tsubst_flags_t complain,
vec<tree,va_gc> **flags)
{
iloc_sentinel ils = EXPR_LOCATION (vec_init);
if (!target)
target = VEC_INIT_EXPR_SLOT (vec_init);
tree init = VEC_INIT_EXPR_INIT (vec_init);
int from_array = (init && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE);
return build_vec_init (target, NULL_TREE, init,
VEC_INIT_EXPR_VALUE_INIT (vec_init),
from_array, complain, flags);
}
/* Give a helpful diagnostic for a non-constexpr VEC_INIT_EXPR in a context
that requires a constant expression. */
void
diagnose_non_constexpr_vec_init (tree expr)
{
tree type = TREE_TYPE (VEC_INIT_EXPR_SLOT (expr));
tree init, elt_init;
if (VEC_INIT_EXPR_VALUE_INIT (expr))
init = void_type_node;
else
init = VEC_INIT_EXPR_INIT (expr);
elt_init = build_vec_init_elt (type, init, tf_warning_or_error);
require_potential_constant_expression (elt_init);
}
tree
build_array_copy (tree init)
{
return get_target_expr (build_vec_init_expr
(TREE_TYPE (init), init, tf_warning_or_error));
}
/* Build a TARGET_EXPR using INIT to initialize a new temporary of the
indicated TYPE. */
tree
build_target_expr_with_type (tree init, tree type, tsubst_flags_t complain)
{
gcc_assert (!VOID_TYPE_P (type));
gcc_assert (!VOID_TYPE_P (TREE_TYPE (init)));
if (TREE_CODE (init) == TARGET_EXPR
|| init == error_mark_node)
return init;
else if (CLASS_TYPE_P (type) && type_has_nontrivial_copy_init (type)
&& TREE_CODE (init) != COND_EXPR
&& TREE_CODE (init) != CONSTRUCTOR
&& TREE_CODE (init) != VA_ARG_EXPR
&& TREE_CODE (init) != CALL_EXPR)
/* We need to build up a copy constructor call. COND_EXPR is a special
case because we already have copies on the arms and we don't want
another one here. A CONSTRUCTOR is aggregate initialization, which
is handled separately. A VA_ARG_EXPR is magic creation of an
aggregate; there's no additional work to be done. A CALL_EXPR
already creates a prvalue. */
return force_rvalue (init, complain);
return force_target_expr (type, init, complain);
}
/* Like the above function, but without the checking. This function should
only be used by code which is deliberately trying to subvert the type
system, such as call_builtin_trap. Or build_over_call, to avoid
infinite recursion. */
tree
force_target_expr (tree type, tree init, tsubst_flags_t complain)
{
tree slot;
gcc_assert (!VOID_TYPE_P (type));
slot = build_local_temp (type);
return build_target_expr (slot, init, complain);
}
/* Like build_target_expr_with_type, but use the type of INIT. */
tree
get_target_expr (tree init, tsubst_flags_t complain /* = tf_warning_or_error */)
{
if (TREE_CODE (init) == AGGR_INIT_EXPR)
return build_target_expr (AGGR_INIT_EXPR_SLOT (init), init, complain);
else if (TREE_CODE (init) == VEC_INIT_EXPR)
return build_target_expr (VEC_INIT_EXPR_SLOT (init), init, complain);
else
{
init = convert_bitfield_to_declared_type (init);
return build_target_expr_with_type (init, TREE_TYPE (init), complain);
}
}
/* If EXPR is a bitfield reference, convert it to the declared type of
the bitfield, and return the resulting expression. Otherwise,
return EXPR itself. */
tree
convert_bitfield_to_declared_type (tree expr)
{
tree bitfield_type;
bitfield_type = is_bitfield_expr_with_lowered_type (expr);
if (bitfield_type)
expr = convert_to_integer_nofold (TYPE_MAIN_VARIANT (bitfield_type),
expr);
return expr;
}
/* EXPR is being used in an rvalue context. Return a version of EXPR
that is marked as an rvalue. */
tree
rvalue (tree expr)
{
tree type;
if (error_operand_p (expr))
return expr;
expr = mark_rvalue_use (expr);
/* [expr.type]: "If a prvalue initially has the type "cv T", where T is a
cv-unqualified non-class, non-array type, the type of the expression is
adjusted to T prior to any further analysis. */
type = TREE_TYPE (expr);
if (!CLASS_TYPE_P (type) && TREE_CODE (type) != ARRAY_TYPE
&& cv_qualified_p (type))
type = cv_unqualified (type);
/* We need to do this for rvalue refs as well to get the right answer
from decltype; see c++/36628. */
if (!processing_template_decl && glvalue_p (expr))
{
/* But don't use this function for class lvalues; use move (to treat an
lvalue as an xvalue) or force_rvalue (to make a prvalue copy). */
gcc_checking_assert (!CLASS_TYPE_P (type));
expr = build1 (NON_LVALUE_EXPR, type, expr);
}
else if (type != TREE_TYPE (expr))
expr = build_nop (type, expr);