aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2018-05-10 19:40:28 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2018-05-10 19:40:28 +0200
commit79e7b1fe3290f351f178dafee4b3df4ece61ba9c (patch)
treed48f413c93e9cc59329413239736490ef5c5f916 /gcc/c
parentc7b7749d9f2c68ca4f9cda52b21ef690aef009bd (diff)
downloadgcc-79e7b1fe3290f351f178dafee4b3df4ece61ba9c.zip
gcc-79e7b1fe3290f351f178dafee4b3df4ece61ba9c.tar.gz
gcc-79e7b1fe3290f351f178dafee4b3df4ece61ba9c.tar.bz2
re PR c++/85662 ("error: non-constant condition for static assertion" from __builtin_offsetof in C++)
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. * c-fold.c (c_fully_fold_internal): Use fold_offsetof rather than fold_offsetof_1, pass TREE_TYPE (expr) as TYPE to it and drop the fold_convert_loc. * c-typeck.c (build_unary_op): Use fold_offsetof rather than fold_offsetof_1, pass argtype as TYPE to it and drop the fold_convert_loc. * cp-gimplify.c (cp_fold): Use fold_offsetof rather than fold_offsetof_1, pass TREE_TYPE (x) as TYPE to it and drop the fold_convert. * g++.dg/ext/offsetof2.C: New test. From-SVN: r260119
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog10
-rw-r--r--gcc/c/c-fold.c2
-rw-r--r--gcc/c/c-typeck.c2
3 files changed, 12 insertions, 2 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index d88d70d..a8e2128 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,13 @@
+2018-05-10 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/85662
+ * c-fold.c (c_fully_fold_internal): Use fold_offsetof rather than
+ fold_offsetof_1, pass TREE_TYPE (expr) as TYPE to it and drop the
+ fold_convert_loc.
+ * c-typeck.c (build_unary_op): Use fold_offsetof rather than
+ fold_offsetof_1, pass argtype as TYPE to it and drop the
+ fold_convert_loc.
+
2018-05-02 David Pagan <dave.pagan@oracle.com>
PR c/30552
diff --git a/gcc/c/c-fold.c b/gcc/c/c-fold.c
index 480e34c..d276e63 100644
--- a/gcc/c/c-fold.c
+++ b/gcc/c/c-fold.c
@@ -473,7 +473,7 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands,
&& (op1 = get_base_address (op0)) != NULL_TREE
&& INDIRECT_REF_P (op1)
&& TREE_CONSTANT (TREE_OPERAND (op1, 0)))
- ret = fold_convert_loc (loc, TREE_TYPE (expr), fold_offsetof_1 (op0));
+ ret = fold_offsetof (op0, TREE_TYPE (expr));
else if (op0 != orig_op0 || in_init)
ret = in_init
? fold_build1_initializer_loc (loc, code, TREE_TYPE (expr), op0)
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 5b3ea28..45a4529 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -4676,7 +4676,7 @@ build_unary_op (location_t location, enum tree_code code, tree xarg,
if (val && INDIRECT_REF_P (val)
&& TREE_CONSTANT (TREE_OPERAND (val, 0)))
{
- ret = fold_convert_loc (location, argtype, fold_offsetof_1 (arg));
+ ret = fold_offsetof (arg, argtype);
goto return_build_unary_op;
}