re PR c++/63757 (nullptr conversion sequence fails to compile)
[official-gcc.git] / gcc / cp / expr.c
blob99f8006fbd80f4f4ca6eb8d8915dbc9085ce78f4
1 /* Convert language-specific tree expression to rtl instructions,
2 for GNU compiler.
3 Copyright (C) 1988-2014 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "flags.h"
28 #include "cp-tree.h"
29 #include "tm_p.h"
31 /* Expand C++-specific constants. Currently, this means PTRMEM_CST. */
33 tree
34 cplus_expand_constant (tree cst)
36 switch (TREE_CODE (cst))
38 case PTRMEM_CST:
40 tree type = TREE_TYPE (cst);
41 tree member;
43 /* Find the member. */
44 member = PTRMEM_CST_MEMBER (cst);
46 /* We can't lower this until the class is complete. */
47 if (!COMPLETE_TYPE_P (DECL_CONTEXT (member)))
48 return cst;
50 if (TREE_CODE (member) == FIELD_DECL)
52 /* Find the offset for the field. */
53 cst = byte_position (member);
54 while (!same_type_p (DECL_CONTEXT (member),
55 TYPE_PTRMEM_CLASS_TYPE (type)))
57 /* The MEMBER must have been nestled within an
58 anonymous aggregate contained in TYPE. Find the
59 anonymous aggregate. */
60 member = lookup_anon_field (TYPE_PTRMEM_CLASS_TYPE (type),
61 DECL_CONTEXT (member));
62 cst = size_binop (PLUS_EXPR, cst, byte_position (member));
64 cst = fold (build_nop (type, cst));
66 else
68 tree delta;
69 tree pfn;
71 expand_ptrmemfunc_cst (cst, &delta, &pfn);
72 cst = build_ptrmemfunc1 (type, delta, pfn);
75 break;
77 case CONSTRUCTOR:
79 constructor_elt *elt;
80 unsigned HOST_WIDE_INT idx;
81 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (cst), idx, elt)
82 elt->value = cplus_expand_constant (elt->value);
85 default:
86 /* There's nothing to do. */
87 break;
90 return cst;
93 /* Called whenever an expression is used
94 in a rvalue context. */
96 tree
97 mark_rvalue_use (tree expr)
99 mark_exp_read (expr);
100 return expr;
103 /* Called whenever an expression is used
104 in a lvalue context. */
106 tree
107 mark_lvalue_use (tree expr)
109 mark_exp_read (expr);
110 return expr;
113 /* Called whenever an expression is used in a type use context. */
115 tree
116 mark_type_use (tree expr)
118 mark_exp_read (expr);
119 return expr;
122 /* Mark EXP as read, not just set, for set but not used -Wunused
123 warning purposes. */
125 void
126 mark_exp_read (tree exp)
128 if (exp == NULL)
129 return;
131 switch (TREE_CODE (exp))
133 case VAR_DECL:
134 case PARM_DECL:
135 DECL_READ_P (exp) = 1;
136 break;
137 case ARRAY_REF:
138 case COMPONENT_REF:
139 case MODIFY_EXPR:
140 case REALPART_EXPR:
141 case IMAGPART_EXPR:
142 CASE_CONVERT:
143 case ADDR_EXPR:
144 case INDIRECT_REF:
145 case FLOAT_EXPR:
146 mark_exp_read (TREE_OPERAND (exp, 0));
147 break;
148 case COMPOUND_EXPR:
149 mark_exp_read (TREE_OPERAND (exp, 1));
150 break;
151 case COND_EXPR:
152 if (TREE_OPERAND (exp, 1))
153 mark_exp_read (TREE_OPERAND (exp, 1));
154 if (TREE_OPERAND (exp, 2))
155 mark_exp_read (TREE_OPERAND (exp, 2));
156 break;
157 default:
158 break;