PR target/59685
[official-gcc.git] / gcc / cp / expr.c
bloba62e0f9b5df8f6d2fbebfe4ebb46e7e921b17d52
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 default:
78 /* There's nothing to do. */
79 break;
82 return cst;
85 /* Called whenever an expression is used
86 in a rvalue context. */
88 tree
89 mark_rvalue_use (tree expr)
91 mark_exp_read (expr);
92 return expr;
95 /* Called whenever an expression is used
96 in a lvalue context. */
98 tree
99 mark_lvalue_use (tree expr)
101 mark_exp_read (expr);
102 return expr;
105 /* Called whenever an expression is used in a type use context. */
107 tree
108 mark_type_use (tree expr)
110 mark_exp_read (expr);
111 return expr;
114 /* Mark EXP as read, not just set, for set but not used -Wunused
115 warning purposes. */
117 void
118 mark_exp_read (tree exp)
120 if (exp == NULL)
121 return;
123 switch (TREE_CODE (exp))
125 case VAR_DECL:
126 case PARM_DECL:
127 DECL_READ_P (exp) = 1;
128 break;
129 case ARRAY_REF:
130 case COMPONENT_REF:
131 case MODIFY_EXPR:
132 case REALPART_EXPR:
133 case IMAGPART_EXPR:
134 CASE_CONVERT:
135 case ADDR_EXPR:
136 case INDIRECT_REF:
137 case FLOAT_EXPR:
138 mark_exp_read (TREE_OPERAND (exp, 0));
139 break;
140 case COMPOUND_EXPR:
141 mark_exp_read (TREE_OPERAND (exp, 1));
142 break;
143 case COND_EXPR:
144 if (TREE_OPERAND (exp, 1))
145 mark_exp_read (TREE_OPERAND (exp, 1));
146 if (TREE_OPERAND (exp, 2))
147 mark_exp_read (TREE_OPERAND (exp, 2));
148 break;
149 default:
150 break;