From 73f397d429016727961c2c4a9ff99cf2fc4ee7b3 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Tue, 5 Jul 2005 18:50:24 +0100 Subject: re PR c/22013 (ICE in gimple_add_tmp_var, at gimplify.c:535) PR c/22013 PR c/22098 * langhooks.h (struct lang_hooks): Add expr_to_decl. * langhooks.c (lhd_expr_to_decl): New. * langhooks-def.h (lhd_expr_to_decl, LANG_HOOKS_EXPR_TO_DECL): New. (LANG_HOOKS_INITIALIZER): Update. * tree.c (recompute_tree_invarant_for_addr_expr): Call expr_to_decl langhook. * c-tree.h (c_expr_to_decl): Declare. * c-typeck.c (c_expr_to_decl): New. (build_unary_op): Do not handle ADDR_EXPR of COMPOUND_LITERAL_EXPR specially. * c-objc-common.h (LANG_HOOKS_EXPR_TO_DECL): Define. testsuite: * gcc.c-torture/compile/pr22013-1.c, gcc.c-torture/execute/pr22098-1.c, gcc.c-torture/execute/pr22098-2.c, gcc.c-torture/execute/pr22098-3.c: New tests. From-SVN: r101630 --- gcc/ChangeLog | 17 +++++++++++++++++ gcc/c-objc-common.h | 2 ++ gcc/c-tree.h | 1 + gcc/c-typeck.c | 24 +++++++++++++++++++++--- gcc/langhooks-def.h | 3 +++ gcc/langhooks.c | 7 +++++++ gcc/langhooks.h | 6 ++++++ gcc/testsuite/ChangeLog | 9 +++++++++ gcc/testsuite/gcc.c-torture/compile/pr22013-1.c | 11 +++++++++++ gcc/testsuite/gcc.c-torture/execute/pr22098-1.c | 14 ++++++++++++++ gcc/testsuite/gcc.c-torture/execute/pr22098-2.c | 14 ++++++++++++++ gcc/testsuite/gcc.c-torture/execute/pr22098-3.c | 16 ++++++++++++++++ gcc/tree.c | 2 ++ 13 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr22013-1.c create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr22098-1.c create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr22098-2.c create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr22098-3.c (limited to 'gcc') diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2d38897..e03f97a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,22 @@ 2005-07-05 Joseph S. Myers + PR c/22013 + PR c/22098 + * langhooks.h (struct lang_hooks): Add expr_to_decl. + * langhooks.c (lhd_expr_to_decl): New. + * langhooks-def.h (lhd_expr_to_decl, LANG_HOOKS_EXPR_TO_DECL): + New. + (LANG_HOOKS_INITIALIZER): Update. + * tree.c (recompute_tree_invarant_for_addr_expr): Call + expr_to_decl langhook. + * c-tree.h (c_expr_to_decl): Declare. + * c-typeck.c (c_expr_to_decl): New. + (build_unary_op): Do not handle ADDR_EXPR of COMPOUND_LITERAL_EXPR + specially. + * c-objc-common.h (LANG_HOOKS_EXPR_TO_DECL): Define. + +2005-07-05 Joseph S. Myers + PR c/22308 * c-decl.c (finish_struct): Also copy C_TYPE_FIELDS_READONLY, C_TYPE_FIELDS_VOLATILE and C_TYPE_VARIABLE_SIZE to type variants. diff --git a/gcc/c-objc-common.h b/gcc/c-objc-common.h index d74273c..6921259 100644 --- a/gcc/c-objc-common.h +++ b/gcc/c-objc-common.h @@ -117,6 +117,8 @@ extern void c_initialize_diagnostics (diagnostic_context *); #define LANG_HOOKS_REGISTER_BUILTIN_TYPE c_register_builtin_type #undef LANG_HOOKS_TO_TARGET_CHARSET #define LANG_HOOKS_TO_TARGET_CHARSET c_common_to_target_charset +#undef LANG_HOOKS_EXPR_TO_DECL +#define LANG_HOOKS_EXPR_TO_DECL c_expr_to_decl /* The C front end's scoping structure is very different from that expected by the language-independent code; it is best diff --git a/gcc/c-tree.h b/gcc/c-tree.h index 4cf6fa7..3266cec 100644 --- a/gcc/c-tree.h +++ b/gcc/c-tree.h @@ -573,6 +573,7 @@ extern tree c_finish_goto_label (tree); extern tree c_finish_goto_ptr (tree); extern void c_begin_vm_scope (unsigned int); extern void c_end_vm_scope (unsigned int); +extern tree c_expr_to_decl (tree, bool *, bool *, bool *); /* Set to 0 at beginning of a function definition, set to 1 if a return statement that specifies a return value is seen. */ diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 64ec126..ab72cee 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -2790,9 +2790,6 @@ build_unary_op (enum tree_code code, tree xarg, int flag) val = build1 (ADDR_EXPR, argtype, arg); - if (TREE_CODE (arg) == COMPOUND_LITERAL_EXPR) - TREE_INVARIANT (val) = TREE_CONSTANT (val) = 1; - return val; default: @@ -8142,3 +8139,24 @@ c_objc_common_truthvalue_conversion (tree expr) leaving those to give errors later? */ return c_common_truthvalue_conversion (expr); } + + +/* Convert EXPR to a contained DECL, updating *TC, *TI and *SE as + required. */ + +tree +c_expr_to_decl (tree expr, bool *tc ATTRIBUTE_UNUSED, + bool *ti ATTRIBUTE_UNUSED, bool *se) +{ + if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR) + { + tree decl = COMPOUND_LITERAL_EXPR_DECL (expr); + /* Executing a compound literal inside a function reinitializes + it. */ + if (!TREE_STATIC (decl)) + *se = true; + return decl; + } + else + return expr; +} diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h index 2c8bb96..cd9a98e 100644 --- a/gcc/langhooks-def.h +++ b/gcc/langhooks-def.h @@ -69,6 +69,7 @@ extern const char *lhd_comdat_group (tree); extern tree lhd_expr_size (tree); extern size_t lhd_tree_size (enum tree_code); extern HOST_WIDE_INT lhd_to_target_charset (HOST_WIDE_INT); +extern tree lhd_expr_to_decl (tree, bool *, bool *, bool *); /* Declarations of default tree inlining hooks. */ extern tree lhd_tree_inlining_walk_subtrees (tree *, int *, walk_tree_fn, @@ -123,6 +124,7 @@ extern int lhd_gimplify_expr (tree *, tree *, tree *); #define LANG_HOOKS_TREE_SIZE lhd_tree_size #define LANG_HOOKS_TYPES_COMPATIBLE_P lhd_types_compatible_p #define LANG_HOOKS_BUILTIN_FUNCTION builtin_function +#define LANG_HOOKS_EXPR_TO_DECL lhd_expr_to_decl #define LANG_HOOKS_TO_TARGET_CHARSET lhd_to_target_charset #define LANG_HOOKS_FUNCTION_INIT lhd_do_nothing_f @@ -299,6 +301,7 @@ extern tree lhd_make_node (enum tree_code); LANG_HOOKS_GIMPLIFY_EXPR, \ LANG_HOOKS_FOLD_OBJ_TYPE_REF, \ LANG_HOOKS_BUILTIN_FUNCTION, \ + LANG_HOOKS_EXPR_TO_DECL, \ } #endif /* GCC_LANG_HOOKS_DEF_H */ diff --git a/gcc/langhooks.c b/gcc/langhooks.c index e2939f0..5f3fb4b 100644 --- a/gcc/langhooks.c +++ b/gcc/langhooks.c @@ -543,3 +543,10 @@ lhd_to_target_charset (HOST_WIDE_INT c) { return c; } + +tree +lhd_expr_to_decl (tree expr, bool *tc ATTRIBUTE_UNUSED, + bool *ti ATTRIBUTE_UNUSED, bool *se ATTRIBUTE_UNUSED) +{ + return expr; +} diff --git a/gcc/langhooks.h b/gcc/langhooks.h index a0c24fc..9ec07ad 100644 --- a/gcc/langhooks.h +++ b/gcc/langhooks.h @@ -412,6 +412,12 @@ struct lang_hooks enum built_in_class bt_class, const char *library_name, tree attrs); + /* Called by recompute_tree_invarant_for_addr_expr to go from EXPR + to a contained expression or DECL, possibly updating *TC, *TI or + *SE if in the process TREE_CONSTANT, TREE_INVARIANT or + TREE_SIDE_EFFECTS need updating. */ + tree (*expr_to_decl) (tree expr, bool *tc, bool *ti, bool *se); + /* Whenever you add entries here, make sure you adjust langhooks-def.h and langhooks.c accordingly. */ }; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7588b666..e598f6e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,14 @@ 2005-07-05 Joseph S. Myers + PR c/22013 + PR c/22098 + * gcc.c-torture/compile/pr22013-1.c, + gcc.c-torture/execute/pr22098-1.c, + gcc.c-torture/execute/pr22098-2.c, + gcc.c-torture/execute/pr22098-3.c: New tests. + +2005-07-05 Joseph S. Myers + PR c/22308 * gcc.dg/pr22308-1.c: New test. diff --git a/gcc/testsuite/gcc.c-torture/compile/pr22013-1.c b/gcc/testsuite/gcc.c-torture/compile/pr22013-1.c new file mode 100644 index 0000000..1dd0adc --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr22013-1.c @@ -0,0 +1,11 @@ +typedef unsigned short W; +typedef const W *P; + +extern void g(P); + +void +f () +{ + const P s = (const W []){ 'R' }; + g (s); +} diff --git a/gcc/testsuite/gcc.c-torture/execute/pr22098-1.c b/gcc/testsuite/gcc.c-torture/execute/pr22098-1.c new file mode 100644 index 0000000..142530f --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr22098-1.c @@ -0,0 +1,14 @@ +extern void abort (void); +extern void exit (int); +typedef __SIZE_TYPE__ size_t; +int +main (void) +{ + int a = 0; + int *p; + size_t b; + b = (size_t)(p = &(int []){0, 1, 2}[++a]); + if (a != 1 || *p != 1 || *(int *)b != 1) + abort (); + exit (0); +} diff --git a/gcc/testsuite/gcc.c-torture/execute/pr22098-2.c b/gcc/testsuite/gcc.c-torture/execute/pr22098-2.c new file mode 100644 index 0000000..249647d --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr22098-2.c @@ -0,0 +1,14 @@ +extern void abort (void); +extern void exit (int); +typedef __SIZE_TYPE__ size_t; +int +main (void) +{ + int a = 0; + int *p; + size_t b; + b = (size_t)(p = &(int []){0, 1, 2}[1]); + if (*p != 1 || *(int *)b != 1) + abort (); + exit (0); +} diff --git a/gcc/testsuite/gcc.c-torture/execute/pr22098-3.c b/gcc/testsuite/gcc.c-torture/execute/pr22098-3.c new file mode 100644 index 0000000..4c8a1c6 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr22098-3.c @@ -0,0 +1,16 @@ +extern void abort (void); +extern void exit (int); +typedef __SIZE_TYPE__ size_t; +int n = 0; +int f (void) { return ++n; } +int +main (void) +{ + int a = 0; + int *p; + size_t b; + b = (size_t)(p = &(int []){0, f(), 2}[1]); + if (*p != 1 || *(int *)b != 1 || n != 1) + abort (); + exit (0); +} diff --git a/gcc/tree.c b/gcc/tree.c index 76f52cd..6067881 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -2466,6 +2466,8 @@ do { tree _node = (NODE); \ UPDATE_TITCSE (TREE_OPERAND (node, 2)); } + node = lang_hooks.expr_to_decl (node, &tc, &ti, &se); + /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from the address, since &(*a)->b is a form of addition. If it's a decl, it's invariant and constant if the decl is static. It's also invariant if it's -- cgit v1.1