+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 ;;.
/* Except for variables which we can optimize to its initializer. */
if (VAR_P (expr) && !lval && (optimize || in_init))
{
- ret = decl_constant_value (expr);
+ 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
gimplifier. */
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);
/* 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
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
--- /dev/null
+/* 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;
+}