diff options
author | Jakub Jelinek <jakub@redhat.com> | 2018-06-22 23:23:03 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2018-06-22 23:23:03 +0200 |
commit | 3056ef4bff035f29d1cbdcb095287ceac06d92ad (patch) | |
tree | 0e8fbec3a7f991bab6a81da0ab9cd9d4b865f213 /gcc/c | |
parent | 7329a73260d52c7a350db95df51a0041bcd2a192 (diff) | |
download | gcc-3056ef4bff035f29d1cbdcb095287ceac06d92ad.zip gcc-3056ef4bff035f29d1cbdcb095287ceac06d92ad.tar.gz gcc-3056ef4bff035f29d1cbdcb095287ceac06d92ad.tar.bz2 |
backport: re PR c++/85662 ("error: non-constant condition for static assertion" from __builtin_offsetof in C++)
Backported from mainline
2018-06-22 Jakub Jelinek <jakub@redhat.com>
PR c++/85662
* g++.dg/ext/offsetof3.C: New test.
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.
* 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: r261962
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/c/c-fold.c | 2 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 2 |
3 files changed, 12 insertions, 2 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 96b9eff..9370bef 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,6 +1,16 @@ 2018-06-22 Jakub Jelinek <jakub@redhat.com> Backported from mainline + 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-03-21 Jakub Jelinek <jakub@redhat.com> PR c/84999 diff --git a/gcc/c/c-fold.c b/gcc/c/c-fold.c index b060d76d..96c041e 100644 --- a/gcc/c/c-fold.c +++ b/gcc/c/c-fold.c @@ -403,7 +403,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 363fa32..2c87ec9 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -4638,7 +4638,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; } |