[backport gcc-4.8/trunk r192759 ] gcc/ 2012-10-24 Jakub Jelinek PR debug/54828 * gimple.h (is_gimple_sizepos): New inline function. * gimplify.c (gimplify_one_sizepos): Use it. Remove useless final assignment to expr variable. * tree.c (RETURN_TRUE_IF_VAR): Return true also if !TYPE_SIZES_GIMPLIFIED (type) and _t is going to be gimplified into a local temporary. gcc/testsuite/ 2012-10-24 Jakub Jelinek PR debug/54828 * g++.dg/debug/pr54828.C: New test. --- gcc-4.6.3/gcc/gimple.h.~1~ 2011-04-18 23:58:03.000000000 +0200 +++ gcc-4.6.3/gcc/gimple.h 2012-10-27 12:41:32.000000000 +0200 @@ -1031,6 +1031,24 @@ struct gimplify_ctx bool allow_rhs_cond_expr; }; +/* Return true if gimplify_one_sizepos doesn't need to gimplify + expr (when in TYPE_SIZE{,_UNIT} and similar type/decl size/bitsize + fields). */ +static inline bool +is_gimple_sizepos (tree expr) +{ + /* gimplify_one_sizepos doesn't need to do anything if the value isn't there, + is constant, or contains A PLACEHOLDER_EXPR. We also don't want to do + anything if it's already a VAR_DECL. If it's a VAR_DECL from another + function, the gimplifier will want to replace it with a new variable, + but that will cause problems if this type is from outside the function. + It's OK to have that here. */ + return (expr == NULL_TREE + || TREE_CONSTANT (expr) + || TREE_CODE (expr) == VAR_DECL + || CONTAINS_PLACEHOLDER_P (expr)); +} + extern enum gimplify_status gimplify_expr (tree *, gimple_seq *, gimple_seq *, bool (*) (tree), fallback_t); extern void gimplify_type_sizes (tree, gimple_seq *); --- gcc-4.6.3/gcc/gimplify.c.~1~ 2011-07-07 14:50:03.000000000 +0200 +++ gcc-4.6.3/gcc/gimplify.c 2012-10-27 12:41:32.000000000 +0200 @@ -7658,9 +7658,7 @@ gimplify_one_sizepos (tree *expr_p, gimp a VAR_DECL. If it's a VAR_DECL from another function, the gimplifier will want to replace it with a new variable, but that will cause problems if this type is from outside the function. It's OK to have that here. */ - if (expr == NULL_TREE || TREE_CONSTANT (expr) - || TREE_CODE (expr) == VAR_DECL - || CONTAINS_PLACEHOLDER_P (expr)) + if (is_gimple_sizepos (expr)) return; type = TREE_TYPE (expr); --- gcc-4.6.3/gcc/testsuite/g++.dg/debug/pr54828.C.~1~ 1970-01-01 01:00:00.000000000 +0100 +++ gcc-4.6.3/gcc/testsuite/g++.dg/debug/pr54828.C 2012-10-27 12:41:32.000000000 +0200 @@ -0,0 +1,14 @@ +// PR debug/54828 +// { dg-do compile } +// { dg-options "-g" } + +struct T { T (); virtual ~T (); }; +struct S : public virtual T { S (); virtual ~S (); }; +int v; +void foo (char *); + +S::S () +{ + char s[v]; + foo (s); +} --- gcc-4.6.3/gcc/tree.c.~1~ 2011-07-18 21:45:21.000000000 +0200 +++ gcc-4.6.3/gcc/tree.c 2012-10-27 12:42:19.000000000 +0200 @@ -8257,11 +8257,18 @@ variably_modified_type_p (tree type, tre tree t; /* Test if T is either variable (if FN is zero) or an expression containing - a variable in FN. */ + a variable in FN. If TYPE isn't gimplified, return true also if + gimplify_one_sizepos would gimplify the expression into a local + variable. */ #define RETURN_TRUE_IF_VAR(T) \ do { tree _t = (T); \ - if (_t && _t != error_mark_node && TREE_CODE (_t) != INTEGER_CST \ - && (!fn || walk_tree (&_t, find_var_from_fn, fn, NULL))) \ + if (_t != NULL_TREE \ + && _t != error_mark_node \ + && TREE_CODE (_t) != INTEGER_CST \ + && (!fn \ + || (!TYPE_SIZES_GIMPLIFIED (type) \ + && !is_gimple_sizepos (_t)) \ + || walk_tree (&_t, find_var_from_fn, fn, NULL))) \ return true; } while (0) if (type == error_mark_node)