From a9e4a1a56fb8e99594b65d6640432ba29c705f3e Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 27 Mar 2017 23:07:21 +0200 Subject: re PR target/80162 (ICE on invalid code (address of register variable)) PR middle-end/80162 c-family/ * c-common.c (c_common_mark_addressable_vec): Don't set TREE_ADDRESSABLE on DECL_HARD_REGISTER. c/ * c-tree.h (c_mark_addressable): Add array_ref_p argument. * c-typeck.c (c_mark_addressable): Likewise. Look through VIEW_CONVERT_EXPR unless array_ref_p and VCE is from VECTOR_TYPE to ARRAY_TYPE. (build_array_ref): Pass true as array_ref_p to c_mark_addressable. cp/ * cp-tree.h (cxx_mark_addressable): Add array_ref_p argument. * typeck.c (cxx_mark_addressable): Likewise. Look through VIEW_CONVERT_EXPR unless array_ref_p and VCE is from VECTOR_TYPE to ARRAY_TYPE. (cp_build_array_ref): Pass true as array_ref_p to cxx_mark_addressable. testsuite/ * c-c++-common/pr80162-1.c: New test. * c-c++-common/pr80162-2.c: New test. * c-c++-common/pr80162-3.c: New test. From-SVN: r246512 --- gcc/c/ChangeLog | 9 +++++++++ gcc/c/c-tree.h | 2 +- gcc/c/c-typeck.c | 16 +++++++++++++--- 3 files changed, 23 insertions(+), 4 deletions(-) (limited to 'gcc/c') diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index f4dbeeb..08a5b9a 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,12 @@ +2017-03-27 Jakub Jelinek + + PR middle-end/80162 + * c-tree.h (c_mark_addressable): Add array_ref_p argument. + * c-typeck.c (c_mark_addressable): Likewise. Look through + VIEW_CONVERT_EXPR unless array_ref_p and VCE is from VECTOR_TYPE + to ARRAY_TYPE. + (build_array_ref): Pass true as array_ref_p to c_mark_addressable. + 2017-03-23 Marek Polacek * c-tree.h: Remove a C_RID_YYCODE reference. diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index 9428d74..5fa32a4 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -615,7 +615,7 @@ extern int same_translation_unit_p (const_tree, const_tree); extern int comptypes (tree, tree); extern int comptypes_check_different_types (tree, tree, bool *); extern bool c_vla_type_p (const_tree); -extern bool c_mark_addressable (tree); +extern bool c_mark_addressable (tree, bool = false); extern void c_incomplete_type_error (location_t, const_tree, const_tree); extern tree c_type_promotes_to (tree); extern struct c_expr default_function_array_conversion (location_t, diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index b283a21..ff239e2 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -2654,7 +2654,7 @@ build_array_ref (location_t loc, tree array, tree index) || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array))) && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST)) { - if (!c_mark_addressable (array)) + if (!c_mark_addressable (array, true)) return error_mark_node; } /* An array that is indexed by a constant value which is not within @@ -4755,16 +4755,26 @@ lvalue_or_else (location_t loc, const_tree ref, enum lvalue_use use) /* Mark EXP saying that we need to be able to take the address of it; it should not be allocated in a register. - Returns true if successful. */ + Returns true if successful. ARRAY_REF_P is true if this + is for ARRAY_REF construction - in that case we don't want + to look through VIEW_CONVERT_EXPR from VECTOR_TYPE to ARRAY_TYPE, + it is fine to use ARRAY_REFs for vector subscripts on vector + register variables. */ bool -c_mark_addressable (tree exp) +c_mark_addressable (tree exp, bool array_ref_p) { tree x = exp; while (1) switch (TREE_CODE (x)) { + case VIEW_CONVERT_EXPR: + if (array_ref_p + && TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE + && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (x, 0)))) + return true; + /* FALLTHRU */ case COMPONENT_REF: case ADDR_EXPR: case ARRAY_REF: -- cgit v1.1