aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/c-family')
-rw-r--r--gcc/c-family/ChangeLog41
-rw-r--r--gcc/c-family/c-common.c30
-rw-r--r--gcc/c-family/c-common.h4
-rw-r--r--gcc/c-family/c-gimplify.c4
-rw-r--r--gcc/c-family/c-omp.c8
5 files changed, 65 insertions, 22 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 7a83a0a9062..a3e153a13db 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,44 @@
+2018-06-22 Jakub Jelinek <jakub@redhat.com>
+
+ Backported from mainline
+ 2018-06-20 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/86210
+ * c-common.c (check_nonnull_arg): Use fold_for_warn. Adjust obsolete
+ comment.
+
+ 2018-05-11 Jakub Jelinek <jakub@redhat.com>
+
+ PR c/85696
+ * c-omp.c (c_omp_predetermined_sharing): Return
+ OMP_CLAUSE_DEFAULT_SHARED for artificial vars with integral type.
+
+ 2018-05-10 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/85662
+ * c-common.h (fold_offsetof_1): Removed.
+ (fold_offsetof): Add TYPE argument defaulted to size_type_node and
+ CTX argument defaulted to ERROR_MARK.
+ * c-common.c (fold_offsetof_1): Renamed to ...
+ (fold_offsetof): ... this. Remove wrapper function. Add TYPE
+ argument, convert the pointer constant to TYPE and use size_binop
+ with PLUS_EXPR instead of fold_build_pointer_plus if type is not
+ a pointer type. Adjust recursive calls.
+
+2018-04-26 Richard Biener <rguenther@suse.de>
+
+ Backport from mainline
+ 2018-03-16 Richard Biener <rguenther@suse.de>
+
+ PR c/84873
+ * c-gimplify.c (c_gimplify_expr): Revert previous change. Instead
+ unshare the possibly folded expression.
+
+ 2018-03-15 Richard Biener <rguenther@suse.de>
+
+ PR c/84873
+ * c-gimplify.c (c_gimplify_expr): Do not fold expressions.
+
2018-03-03 Jakub Jelinek <jakub@redhat.com>
Backported from mainline
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index e272488b39b..45be4bd1cbe 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -5434,10 +5434,8 @@ check_nonnull_arg (void *ctx, tree param, unsigned HOST_WIDE_INT param_num)
if (TREE_CODE (TREE_TYPE (param)) != POINTER_TYPE)
return;
- /* When not optimizing diagnose the simple cases of null arguments.
- When optimization is enabled defer the checking until expansion
- when more cases can be detected. */
- if (integer_zerop (param))
+ /* Diagnose the simple cases of null arguments. */
+ if (integer_zerop (fold_for_warn (param)))
{
warning_at (pctx->loc, OPT_Wnonnull, "null argument where non-null "
"required (argument %lu)", (unsigned long) param_num);
@@ -6253,10 +6251,11 @@ c_common_to_target_charset (HOST_WIDE_INT c)
/* Fold an offsetof-like expression. EXPR is a nested sequence of component
references with an INDIRECT_REF of a constant at the bottom; much like the
- traditional rendering of offsetof as a macro. Return the folded result. */
+ traditional rendering of offsetof as a macro. TYPE is the desired type of
+ the whole expression. Return the folded result. */
tree
-fold_offsetof_1 (tree expr, enum tree_code ctx)
+fold_offsetof (tree expr, tree type, enum tree_code ctx)
{
tree base, off, t;
tree_code code = TREE_CODE (expr);
@@ -6281,10 +6280,10 @@ fold_offsetof_1 (tree expr, enum tree_code ctx)
error ("cannot apply %<offsetof%> to a non constant address");
return error_mark_node;
}
- return TREE_OPERAND (expr, 0);
+ return convert (type, TREE_OPERAND (expr, 0));
case COMPONENT_REF:
- base = fold_offsetof_1 (TREE_OPERAND (expr, 0), code);
+ base = fold_offsetof (TREE_OPERAND (expr, 0), type, code);
if (base == error_mark_node)
return base;
@@ -6301,7 +6300,7 @@ fold_offsetof_1 (tree expr, enum tree_code ctx)
break;
case ARRAY_REF:
- base = fold_offsetof_1 (TREE_OPERAND (expr, 0), code);
+ base = fold_offsetof (TREE_OPERAND (expr, 0), type, code);
if (base == error_mark_node)
return base;
@@ -6358,23 +6357,16 @@ fold_offsetof_1 (tree expr, enum tree_code ctx)
/* Handle static members of volatile structs. */
t = TREE_OPERAND (expr, 1);
gcc_assert (VAR_P (t));
- return fold_offsetof_1 (t);
+ return fold_offsetof (t, type);
default:
gcc_unreachable ();
}
+ if (!POINTER_TYPE_P (type))
+ return size_binop (PLUS_EXPR, base, convert (type, off));
return fold_build_pointer_plus (base, off);
}
-
-/* Likewise, but convert it to the return type of offsetof. */
-
-tree
-fold_offsetof (tree expr)
-{
- return convert (size_type_node, fold_offsetof_1 (expr));
-}
-
/* *PTYPE is an incomplete array. Complete it with a domain based on
INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index b9333420434..0cff4414294 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -1053,8 +1053,8 @@ extern bool c_dump_tree (void *, tree);
extern void verify_sequence_points (tree);
-extern tree fold_offsetof_1 (tree, tree_code ctx = ERROR_MARK);
-extern tree fold_offsetof (tree);
+extern tree fold_offsetof (tree, tree = size_type_node,
+ tree_code ctx = ERROR_MARK);
extern int complete_array_type (tree *, tree, bool);
diff --git a/gcc/c-family/c-gimplify.c b/gcc/c-family/c-gimplify.c
index 57edb41af0f..deecb1a3e4a 100644
--- a/gcc/c-family/c-gimplify.c
+++ b/gcc/c-family/c-gimplify.c
@@ -244,7 +244,9 @@ c_gimplify_expr (tree *expr_p, gimple_seq *pre_p ATTRIBUTE_UNUSED,
unsigned_type_node)
&& !types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (*op1_p)),
integer_type_node))
- *op1_p = convert (unsigned_type_node, *op1_p);
+ /* Make sure to unshare the result, tree sharing is invalid
+ during gimplification. */
+ *op1_p = unshare_expr (convert (unsigned_type_node, *op1_p));
break;
}
diff --git a/gcc/c-family/c-omp.c b/gcc/c-family/c-omp.c
index 977cb0ea153..eee718ddce1 100644
--- a/gcc/c-family/c-omp.c
+++ b/gcc/c-family/c-omp.c
@@ -1540,5 +1540,13 @@ c_omp_predetermined_sharing (tree decl)
if (TREE_READONLY (decl))
return OMP_CLAUSE_DEFAULT_SHARED;
+ /* Predetermine artificial variables holding integral values, those
+ are usually result of gimplify_one_sizepos or SAVE_EXPR
+ gimplification. */
+ if (VAR_P (decl)
+ && DECL_ARTIFICIAL (decl)
+ && INTEGRAL_TYPE_P (TREE_TYPE (decl)))
+ return OMP_CLAUSE_DEFAULT_SHARED;
+
return OMP_CLAUSE_DEFAULT_UNSPECIFIED;
}