From 79e7b1fe3290f351f178dafee4b3df4ece61ba9c Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 10 May 2018 19:40:28 +0200 Subject: 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 --- gcc/c/ChangeLog | 10 ++++++++++ gcc/c/c-fold.c | 2 +- gcc/c/c-typeck.c | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) (limited to 'gcc/c') 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 + + 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 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; } -- cgit v1.1