]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/c-semantics.c
re PR target/37170 (gcc.dg/weak/weak-1.c)
[thirdparty/gcc.git] / gcc / c-semantics.c
1 /* This file contains the definitions and documentation for the common
2 tree codes used in the GNU C and C++ compilers (see c-common.def
3 for the standard codes).
4 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007
5 Free Software Foundation, Inc.
6 Written by Benjamin Chelf (chelf@codesourcery.com).
7
8 This file is part of GCC.
9
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
13 version.
14
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
23
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tm.h"
28 #include "tree.h"
29 #include "function.h"
30 #include "splay-tree.h"
31 #include "varray.h"
32 #include "c-common.h"
33 #include "except.h"
34 /* In order for the format checking to accept the C frontend
35 diagnostic framework extensions, you must define this token before
36 including toplev.h. */
37 #define GCC_DIAG_STYLE __gcc_cdiag__
38 #include "toplev.h"
39 #include "flags.h"
40 #include "ggc.h"
41 #include "rtl.h"
42 #include "output.h"
43 #include "timevar.h"
44 #include "predict.h"
45 #include "tree-inline.h"
46 #include "gimple.h"
47 #include "tree-iterator.h"
48 #include "langhooks.h"
49
50 /* Create an empty statement tree rooted at T. */
51
52 tree
53 push_stmt_list (void)
54 {
55 tree t;
56 t = alloc_stmt_list ();
57 TREE_CHAIN (t) = cur_stmt_list;
58 cur_stmt_list = t;
59 return t;
60 }
61
62 /* Finish the statement tree rooted at T. */
63
64 tree
65 pop_stmt_list (tree t)
66 {
67 tree u = cur_stmt_list, chain;
68
69 /* Pop statement lists until we reach the target level. The extra
70 nestings will be due to outstanding cleanups. */
71 while (1)
72 {
73 chain = TREE_CHAIN (u);
74 TREE_CHAIN (u) = NULL_TREE;
75 if (t == u)
76 break;
77 u = chain;
78 }
79 cur_stmt_list = chain;
80
81 /* If the statement list is completely empty, just return it. This is
82 just as good small as build_empty_stmt, with the advantage that
83 statement lists are merged when they appended to one another. So
84 using the STATEMENT_LIST avoids pathological buildup of EMPTY_STMT_P
85 statements. */
86 if (TREE_SIDE_EFFECTS (t))
87 {
88 tree_stmt_iterator i = tsi_start (t);
89
90 /* If the statement list contained exactly one statement, then
91 extract it immediately. */
92 if (tsi_one_before_end_p (i))
93 {
94 u = tsi_stmt (i);
95 tsi_delink (&i);
96 free_stmt_list (t);
97 t = u;
98 }
99 }
100
101 return t;
102 }
103
104 /* Build a generic statement based on the given type of node and
105 arguments. Similar to `build_nt', except that we set
106 EXPR_LOCATION to be the current source location. */
107 /* ??? This should be obsolete with the lineno_stmt productions
108 in the grammar. */
109
110 tree
111 build_stmt (enum tree_code code, ...)
112 {
113 tree ret;
114 int length, i;
115 va_list p;
116 bool side_effects;
117
118 /* This function cannot be used to construct variably-sized nodes. */
119 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
120
121 va_start (p, code);
122
123 ret = make_node (code);
124 TREE_TYPE (ret) = void_type_node;
125 length = TREE_CODE_LENGTH (code);
126 SET_EXPR_LOCATION (ret, input_location);
127
128 /* TREE_SIDE_EFFECTS will already be set for statements with
129 implicit side effects. Here we make sure it is set for other
130 expressions by checking whether the parameters have side
131 effects. */
132
133 side_effects = false;
134 for (i = 0; i < length; i++)
135 {
136 tree t = va_arg (p, tree);
137 if (t && !TYPE_P (t))
138 side_effects |= TREE_SIDE_EFFECTS (t);
139 TREE_OPERAND (ret, i) = t;
140 }
141
142 TREE_SIDE_EFFECTS (ret) |= side_effects;
143
144 va_end (p);
145 return ret;
146 }
147
148 /* Let the back-end know about DECL. */
149
150 void
151 emit_local_var (tree decl)
152 {
153 /* Create RTL for this variable. */
154 if (!DECL_RTL_SET_P (decl))
155 {
156 if (DECL_HARD_REGISTER (decl))
157 /* The user specified an assembler name for this variable.
158 Set that up now. */
159 rest_of_decl_compilation (decl, 0, 0);
160 else
161 expand_decl (decl);
162 }
163 }
164
165 /* Create a CASE_LABEL_EXPR tree node and return it. */
166
167 tree
168 build_case_label (tree low_value, tree high_value, tree label_decl)
169 {
170 return build_stmt (CASE_LABEL_EXPR, low_value, high_value, label_decl);
171 }