Commit cc6534d4 by Jakub Jelinek Committed by Jakub Jelinek

re PR c/83222 (Inconsistent "initializer element is not constant" error)

	PR c/83222
	* c-tree.h (decl_constant_value_1): Declare.
	* c-typeck.c (decl_constant_value_1): New function.
	(decl_constant_value): Use it.
	* c-fold.c (c_fully_fold_internal): If in_init, use
	decl_constant_value_1 instead of decl_constant_value.

	* gcc.c-torture/compile/pr83222.c: New test.

From-SVN: r255285
parent 5de73c05
2017-12-01 Jakub Jelinek <jakub@redhat.com>
PR c/83222
* c-tree.h (decl_constant_value_1): Declare.
* c-typeck.c (decl_constant_value_1): New function.
(decl_constant_value): Use it.
* c-fold.c (c_fully_fold_internal): If in_init, use
decl_constant_value_1 instead of decl_constant_value.
2017-11-30 Jakub Jelinek <jakub@redhat.com>
* c-parser.c (c_parser_postfix_expression): Use ; instead of ;;.
......
......@@ -167,6 +167,9 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands,
/* Except for variables which we can optimize to its initializer. */
if (VAR_P (expr) && !lval && (optimize || in_init))
{
if (in_init)
ret = decl_constant_value_1 (expr);
else
ret = decl_constant_value (expr);
/* Avoid unwanted tree sharing between the initializer and current
function's body where the tree can be modified e.g. by the
......
......@@ -640,6 +640,7 @@ extern struct c_expr default_function_array_read_conversion (location_t,
struct c_expr);
extern struct c_expr convert_lvalue_to_rvalue (location_t, struct c_expr,
bool, bool);
extern tree decl_constant_value_1 (tree);
extern void mark_exp_read (tree);
extern tree composite_type (tree, tree);
extern tree build_component_ref (location_t, tree, tree, location_t);
......
......@@ -1832,13 +1832,10 @@ c_size_in_bytes (const_tree type)
/* Return either DECL or its known constant value (if it has one). */
tree
decl_constant_value (tree decl)
decl_constant_value_1 (tree decl)
{
if (/* Don't change a variable array bound or initial value to a constant
in a place where a variable is invalid. Note that DECL_INITIAL
isn't valid for a PARM_DECL. */
current_function_decl != NULL_TREE
&& TREE_CODE (decl) != PARM_DECL
if (/* Note that DECL_INITIAL isn't valid for a PARM_DECL. */
TREE_CODE (decl) != PARM_DECL
&& !TREE_THIS_VOLATILE (decl)
&& TREE_READONLY (decl)
&& DECL_INITIAL (decl) != NULL_TREE
......@@ -1853,6 +1850,17 @@ decl_constant_value (tree decl)
return decl;
}
/* Return either DECL or its known constant value (if it has one).
Like the above, but always return decl outside of functions. */
tree
decl_constant_value (tree decl)
{
/* Don't change a variable array bound or initial value to a constant
in a place where a variable is invalid. */
return current_function_decl ? decl_constant_value_1 (decl) : decl;
}
/* Convert the array expression EXP to a pointer. */
static tree
array_to_pointer_conversion (location_t loc, tree exp)
......
2017-12-01 Jakub Jelinek <jakub@redhat.com>
PR c/83222
* gcc.c-torture/compile/pr83222.c: New test.
2017-12-01 Maxim Ostapenko <m.ostapenko@samsung.com>
PR sanitizer/81697
......
/* PR c/83222 */
const char a = 0x42;
const double b = (double) a;
const double c = a;
double d = (double) a;
double e = a;
const double f = 1 + (double) a;
const double g = 1 + a;
double h = 1 + (double) a;
double i = 1 + a;
double j[] = { (double) a, a, 1 + (double) a, 1 + a };
void
foo (void)
{
static const double k = (double) a;
static const double l = a;
static const double m = 1 + (double) a;
static const double n = 1 + a;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment