aboutsummaryrefslogtreecommitdiff
path: root/gcc/c/c-fold.c
AgeCommit message (Collapse)AuthorFilesLines
2020-05-20c/95141 - fix bogus integer overflow warningRichard Biener1-0/+1
This fixes an integer overflow warning that ultimatively happens because of TREE_OVERFLOW propagating through transforms and the existing guard against this, 375 if (TREE_OVERFLOW_P (ret) 376 && !TREE_OVERFLOW_P (op0) 377 && !TREE_OVERFLOW_P (op1)) 378 overflow_warning (EXPR_LOC_OR_LOC (expr, input_location, being insufficient. Rather than trying to use sth like walk_tree to exhaustively walk operands (with the possibility of introducing quadraticness when folding larger expressions recursively) the following amends the above with an ad-hoc test for a binary op0 with a possibly constant op1. 2020-05-30 Richard Biener <rguenther@suse.de> PR c/95141 gcc/c * c-fold.c (c_fully_fold_internal): Enhance guard on overflow_warning. gcc/testsuite * gcc.dg/pr95141.c: New testcase.
2020-03-16c: Handle MEM_REF in c_fully_fold* [PR94179]Jakub Jelinek1-0/+9
The recent match.pd changes can generate a MEM_REF which can be seen by the C FE folding routines. Unlike the C++ FE, they weren't expected in the C FE yet. MEM_REF should be handled like INDIRECT_REF, except that it has two operands rather than just one and that we should preserve the type of the second operand. Given that it already has to be an INTEGER_CST with pointer type, I think we are fine, the recursive call should return the INTEGER_CST unmodified and STRIP_TYPE_NOPS will not strip anything. 2020-03-16 Jakub Jelinek <jakub@redhat.com> PR c/94179 * c-fold.c (c_fully_fold_internal): Handle MEM_REF. * gcc.c-torture/compile/pr94179.c: New test.
2020-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r279813
2019-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r267494
2018-05-10re PR c++/85662 ("error: non-constant condition for static assertion" from ↵Jakub Jelinek1-1/+1
__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
2018-01-17C++: Fix crash in warn_for_memset within templates (PR c++/83814)David Malcolm1-0/+10
gcc/c-family/ChangeLog: PR c++/83814 * c-common.c (fold_for_warn): Move to c/c-fold.c and cp/expr.c. gcc/c/ChangeLog: PR c++/83814 * c-fold.c (fold_for_warn): Move from c-common.c, reducing to just the C part. gcc/cp/ChangeLog: PR c++/83814 * expr.c (fold_for_warn): Move from c-common.c, reducing to just the C++ part. If processing a template, call fold_non_dependent_expr rather than fully folding. gcc/testsuite/ChangeLog: PR c++/83814 PR c++/83902 * g++.dg/wrappers/pr83814.C: New test case. * g++.dg/wrappers/pr83902.C: New test case. From-SVN: r256804
2018-01-13re PR c/83801 ([avr] String constant in __flash not put into .progmem)Jakub Jelinek1-2/+10
PR c/83801 * c-tree.h (decl_constant_value_1): Add a bool argument. * c-typeck.c (decl_constant_value_1): Add IN_INIT argument, allow returning a CONSTRUCTOR if it is true. Use error_operand_p. (decl_constant_value): Adjust caller. * c-fold.c (c_fully_fold_internal): If in_init, pass true to decl_constant_value_1 as IN_INIT. Otherwise, punt if decl_constant_value returns initializer that has BLKmode or array type. (c_fully_fold_internal) <case COMPONENT_REF>: Fold if !lval. * gcc.dg/pr83801.c: New test. From-SVN: r256608
2018-01-03Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r256169
2017-12-14re PR middle-end/83415 (ICE during gimplification of assignment to read-only ↵Richard Biener1-1/+1
vector) 2017-12-14 Richard Biener <rguenther@suse.de> PR c/83415 c/ * c-fold.c (c_fully_fold_internal): Treat VIEW_CONVERT_EXPR like REALPART_EXPR for the behavior of whether its operand is an lvalue. * gcc.dg/pr83415.c: New testcase. From-SVN: r255629
2017-12-01re PR c/83222 (Inconsistent "initializer element is not constant" error)Jakub Jelinek1-1/+4
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. * gcc.c-torture/compile/pr83222.c: New test. From-SVN: r255285
2017-11-21New POINTER_DIFF_EXPRMarc Glisse1-0/+1
2017-11-21 Marc Glisse <marc.glisse@inria.fr> gcc/c/ * c-fold.c (c_fully_fold_internal): Handle POINTER_DIFF_EXPR. * c-typeck.c (pointer_diff): Use POINTER_DIFF_EXPR. gcc/c-family/ * c-pretty-print.c (pp_c_additive_expression, c_pretty_printer::expression): Handle POINTER_DIFF_EXPR. gcc/cp/ * constexpr.c (cxx_eval_constant_expression, potential_constant_expression_1): Handle POINTER_DIFF_EXPR. * cp-gimplify.c (cp_fold): Likewise. * error.c (dump_expr): Likewise. * typeck.c (pointer_diff): Use POINTER_DIFF_EXPR. gcc/ * doc/generic.texi: Document POINTER_DIFF_EXPR, update POINTER_PLUS_EXPR. * cfgexpand.c (expand_debug_expr): Handle POINTER_DIFF_EXPR. * expr.c (expand_expr_real_2): Likewise. * fold-const.c (const_binop, fold_addr_of_array_ref_difference, fold_binary_loc): Likewise. * match.pd (X-X, P+(Q-P), &D-P, (P+N)-P, P-(P+N), (P+M)-(P+N), P-Q==0, -(A-B), X-Z<Y-Z, (X-Z)-(Y-Z), Z-X<Z-Y, (Z-X)-(Z-Y), (A-B)+(C-A)): New transformations for POINTER_DIFF_EXPR, based on MINUS_EXPR transformations. * optabs-tree.c (optab_for_tree_code): Handle POINTER_DIFF_EXPR. * tree-cfg.c (verify_expr, verify_gimple_assign_binary): Likewise. * tree-inline.c (estimate_operator_cost): Likewise. * tree-pretty-print.c (dump_generic_node, op_code_prio, op_symbol_code): Likewise. * tree-vect-stmts.c (vectorizable_operation): Likewise. * vr-values.c (extract_range_from_binary_expr): Likewise. * varasm.c (initializer_constant_valid_p_1): Likewise. * tree.def: New tree code POINTER_DIFF_EXPR. From-SVN: r255021
2017-11-19re PR c/66618 (Failure to diagnose non-constant initializer for static ↵Jakub Jelinek1-65/+100
object with -O1) PR c/66618 PR c/69960 c-family/ * c-common.h (c_fully_fold): Add LVAL argument defaulted to false. c/ * c-parser.c (c_parser_omp_atomic): Pass true as LVAL to c_fully_fold where needed. * c-typeck.c (build_unary_op, build_modify_expr, build_asm_expr, handle_omp_array_sections): Likewise. (digest_init): Don't call decl_constant_value_for_optimization. * c-tree.h (decl_constant_value_for_optimization): Removed. * c-fold.c (c_fold_array_ref): New function. (c_fully_fold_internal): Add LVAL argument, propagate it through recursive calls. For VAR_P call decl_constant_value and unshare if not LVAL and either optimizing or IN_INIT. Remove decl_constant_value_for_optimization calls. If IN_INIT and not LVAL, fold ARRAY_REF with STRING_CST and INTEGER_CST operands. (c_fully_fold): Add LVAL argument, pass it through to c_fully_fold_internal. (decl_constant_value_for_optimization): Removed. cp/ * cp-gimplify.c (c_fully_fold): Add LVAL argument, call cp_fold_maybe_rvalue instead of cp_fold_rvalue and pass it !LVAL. testsuite/ * gcc.dg/pr69960.c: New test. * gcc.dg/pr66618.c: New test. * gcc.dg/pr66618-2.c: New test. From-SVN: r254930
2017-05-24PR c/80731 - poor -Woverflow warningsMartin Sebor1-2/+2
gcc/c-family/ChangeLog: PR c/80731 * c-common.h (unsafe_conversion_p): Add a function argument. * c-common.c (unsafe_conversion_p): Same. Add type names and values to diagnostics. (scalar_to_vector): Adjust. * c-warn.c (constant_expression_error): Add a function argument. Add type names and values to diagnostics. (conversion_warning): Add a function argument. Add type names and values to diagnostics. (warnings_for_convert_and_check): Same. gcc/c/ChangeLog: PR c/80731 * c-fold.c (c_fully_fold_internal): Adjust. * c-typeck.c (parser_build_unary_op): Adjust. gcc/cp/ChangeLog: PR c/80731 * call.c (fully_fold_internal): Adjust. gcc/testsuite/ChangeLog: PR c/80731 * c-c++-common/Wfloat-conversion.c: Adjust. * c-c++-common/dfp/convert-int-saturate.c: Same. * c-c++-common/pr68657-1.c: Same. * g++.dg/ext/utf-cvt.C: Same. * g++.dg/ext/utf16-4.C: Same. * g++.dg/warn/Wconversion-real-integer-3.C: Same. * g++.dg/warn/Wconversion-real-integer2.C: Same. * g++.dg/warn/Wconversion3.C: Same. * g++.dg/warn/Wconversion4.C: Same. * g++.dg/warn/Wsign-conversion.C: Same. * g++.dg/warn/overflow-warn-1.C: Same. * g++.dg/warn/overflow-warn-3.C: Same. * g++.dg/warn/overflow-warn-4.C: Same. * g++.dg/warn/pr35635.C: Same. * g++.old-deja/g++.mike/enum1.C: Same. * gcc.dg/Wconversion-3.c: Same. * gcc.dg/Wconversion-5.c: Same. * gcc.dg/Wconversion-complex-c99.c: Same. * gcc.dg/Wconversion-complex-gnu.c: Same. * gcc.dg/Wconversion-integer.c: Same. * gcc.dg/Wsign-conversion.c: Same. * gcc.dg/bitfld-2.c: Same. * gcc.dg/c90-const-expr-11.c: Same. * gcc.dg/c90-const-expr-7.c: Same. * gcc.dg/c99-const-expr-7.c: Same. * gcc.dg/overflow-warn-1.c: Same. * gcc.dg/overflow-warn-2.c: Same. * gcc.dg/overflow-warn-3.c: Same. * gcc.dg/overflow-warn-4.c: Same. * gcc.dg/overflow-warn-5.c: Same. * gcc.dg/overflow-warn-8.c: Same. * gcc.dg/overflow-warn-9.c: New test. * gcc.dg/pr35635.c: Adjust. * gcc.dg/pr59940.c: Same. * gcc.dg/pr59963-2.c: Same. * gcc.dg/pr60114.c: Same. * gcc.dg/switch-warn-2.c: Same. * gcc.dg/utf-cvt.c: Same. * gcc.dg/utf16-4.c: Same. From-SVN: r248431
2017-05-22c-fold.c (c_fully_fold_internal): Save the c_fully_fold_internal result for ↵Jakub Jelinek1-10/+6
SAVE_EXPR operand and set... * c-fold.c (c_fully_fold_internal): Save the c_fully_fold_internal result for SAVE_EXPR operand and set SAVE_EXPR_FOLDED_P even if it returned invariant. Call tree_invariant_p unconditionally afterwards to decide whether to return expr or op0. From-SVN: r248347
2017-05-17Bye bye, c_save_expr.Marek Polacek1-5/+23
From-SVN: r248139
2017-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r243994
2016-08-01extend shift count warnings to vector typesJan Beulich1-5/+13
gcc/c/ 2016-08-01 Jan Beulich <jbeulich@suse.com> * c-fold.c (c_fully_fold_internal): Also emit shift count warnings for vector types. * c-typeck.c (build_binary_op): Likewise. gcc/testsuite/ 2016-08-01 Jan Beulich <jbeulich@suse.com> * gcc.dg/vshift-6.c, gcc.dg/vshift-7.c: New. From-SVN: r238936
2016-04-04re PR middle-end/70307 (ICE: in gimplify_expr, at gimplify.c:10915 on valid ↵Marek Polacek1-0/+20
code) PR c/70307 * c-fold.c (c_fully_fold_internal): Handle VEC_COND_EXPR. * gcc.dg/torture/pr70307.c: New test. From-SVN: r234706
2016-01-04Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r232055
2015-12-02Define c_fully_fold separately for C and C++.Jason Merrill1-0/+589
gcc/c-family/ * c-common.c (c_disable_warnings, c_enable_warnings, c_fully_fold) (c_fully_fold_internal, decl_constant_value_for_optimization): Move to c/c-fold.c. * c-common.h: Don't declare decl_constant_value_for_optimization. gcc/c/ * c-fold.c (c_disable_warnings, c_enable_warnings, c_fully_fold) (c_fully_fold_internal, decl_constant_value_for_optimization): Move from c-common.c. * c-tree.h: Declare decl_constant_value_for_optimization. * Make-lang.in (C_AND_OBJC_OBJS): Add c-fold.o. gcc/cp/ * cp-gimplify.c (c_fully_fold): Define. From-SVN: r231196