aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-ssa-sprintf.c
AgeCommit message (Collapse)AuthorFilesLines
2017-11-02gimple-ssa-sprintf.c (sprintf_dom_walker): Remove virtual keyword on FINAL ↵Jeff Law1-1/+1
OVERRIDE members. * gimple-ssa-sprintf.c (sprintf_dom_walker): Remove virtual keyword on FINAL OVERRIDE members. * tree-ssa-propagate.h (ssa_propagation_engine): Group virtuals together. Add virtual destructor. (substitute_and_fold_engine): Similarly. From-SVN: r254345
2017-10-27gimple-ssa-sprintf.c: Include domwalk.h.Jeff Law1-30/+45
* gimple-ssa-sprintf.c: Include domwalk.h. (class sprintf_dom_walker): New class, derived from dom_walker. (sprintf_dom_walker::before_dom_children): New function. (struct call_info): Moved into sprintf_dom_walker class (compute_formath_length, handle_gimple_call): Likewise. (sprintf_length::execute): Call the dominator walker rather than walking the statements. From-SVN: r254156
2017-10-17Simplify format_warning_at_substring APIDavid Malcolm1-33/+27
The format_warning_at_substring API has a rather clunk way of indicating the location of the pertinent param (if any): a source_range * is passed in, which can be NULL. Doing so requires extracting a range from the location_t and passing around a pointer to it, or NULL, as needed. This patch simplifies things by eliminating the source_range * in favor of a location_t, with UNKNOWN_LOCATION used to signify that no param location is available. gcc/c-family/ChangeLog: * c-format.c (format_warning_at_char): Pass UNKNOWN_LOCATION rather than NULL to format_warning_va. (check_format_types): Likewise when calling format_type_warning. Remove code to extract source_ranges and source_range * in favor of just a location_t. (format_type_warning): Convert source_range * param to a location_t. gcc/ChangeLog: * gimple-ssa-sprintf.c (fmtwarn): Update for changed signature of format_warning_at_substring. (maybe_warn): Convert source_range * param to a location_t. Pass UNKNOWN_LOCATION rather than NULL to fmtwarn. (format_directive): Remove code to extract source_ranges and source_range * in favor of just a location_t. (parse_directive): Pass UNKNOWN_LOCATION rather than NULL to fmtwarn. * substring-locations.c (format_warning_va): Convert source_range * param to a location_t. (format_warning_at_substring): Likewise. * substring-locations.h (format_warning_va): Likewise. (format_warning_at_substring): Likewise. From-SVN: r253827
2017-08-30[20/77] Replace MODE_INT checks with is_int_modeRichard Sandiford1-2/+3
Replace checks of "GET_MODE_CLASS (...) == MODE_INT" with "is_int_mode (..., &var)", in cases where it becomes useful to refer to the mode as a scalar_int_mode. 2017-08-30 Richard Sandiford <richard.sandiford@linaro.org> Alan Hayward <alan.hayward@arm.com> David Sherwood <david.sherwood@arm.com> gcc/ * machmode.h (is_int_mode): New fuction. * combine.c (find_split_point): Use it. (combine_simplify_rtx): Likewise. (simplify_if_then_else): Likewise. (simplify_set): Likewise. (simplify_shift_const_1): Likewise. (simplify_comparison): Likewise. * config/aarch64/aarch64.c (aarch64_rtx_costs): Likewise. * cse.c (notreg_cost): Likewise. (cse_insn): Likewise. * cselib.c (cselib_lookup_1): Likewise. * dojump.c (do_jump_1): Likewise. (do_compare_rtx_and_jump): Likewise. * dse.c (get_call_args): Likewise. * dwarf2out.c (rtl_for_decl_init): Likewise. (native_encode_initializer): Likewise. * expmed.c (emit_store_flag_1): Likewise. (emit_store_flag): Likewise. * expr.c (convert_modes): Likewise. (store_field): Likewise. (expand_expr_real_1): Likewise. * fold-const.c (fold_read_from_constant_string): Likewise. * gimple-ssa-sprintf.c (get_format_string): Likewise. * optabs-libfuncs.c (gen_int_libfunc): Likewise. * optabs.c (expand_binop): Likewise. (expand_unop): Likewise. (expand_abs_nojump): Likewise. (expand_one_cmpl_abs_nojump): Likewise. * simplify-rtx.c (mode_signbit_p): Likewise. (val_signbit_p): Likewise. (val_signbit_known_set_p): Likewise. (val_signbit_known_clear_p): Likewise. (simplify_relational_operation_1): Likewise. * tree.c (vector_type_mode): Likewise. gcc/go/ * go-lang.c (go_langhook_type_for_mode): Use is_int_mode. Co-Authored-By: Alan Hayward <alan.hayward@arm.com> Co-Authored-By: David Sherwood <david.sherwood@arm.com> From-SVN: r251472
2017-08-14PR translation/79998 - typo in diagnostic "specified bound %wu"Martin Sebor1-1/+1
gcc/ChangeLog: * gimple-ssa-sprintf.c (pass_sprintf_length::handle_gimple_call): Remove a stray space. From-SVN: r251096
2017-07-10PR tree-optimization/80397 - missing -Wformat-overflow with arguments of ↵Martin Sebor1-3/+3
enum types gcc/ChangeLog: PR tree-optimization/80397 * gimple-ssa-sprintf.c (format_integer): Use INTEGRAL_TYPE_P() instead of testing for equality to INTEGER_TYPE. gcc/testsuite/ChangeLog: PR tree-optimization/80397 * gcc.dg/tree-ssa/builtin-sprintf-warn-17.c: New test. From-SVN: r250106
2017-05-14PR middle-end/77671 - missing -Wformat-overflow warning on sprintf overflow ↵Martin Sebor1-44/+115
with %s gcc/ChangeLog: PR middle-end/77671 * gimple-fold.c (gimple_fold_builtin_sprintf): Make extern. (gimple_fold_builtin_snprintf): Same. * gimple-fold.h (gimple_fold_builtin_sprintf): Declare. (gimple_fold_builtin_snprintf): Same. * gimple-ssa-sprintf.c (get_format_string): Correct the detection of character types. (is_call_safe): New function. (try_substitute_return_value): Call it. (try_simplify_call): New function. (pass_sprintf_length::handle_gimple_call): Call it. gcc/testsuite/ChangeLog: PR middle-end/77671 * gcc.dg/tree-ssa/builtin-sprintf-7.c: New test. * gcc.dg/tree-ssa/builtin-sprintf-8.c: New test. * gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Adjust. * gcc.dg/tree-ssa/builtin-sprintf-warn-2.c: Adjust. * gcc.dg/tree-ssa/builtin-sprintf-warn-3.c: Adjust. From-SVN: r248035
2017-05-01gimple-ssa-sprintf.c (format_integer): Set knownrange when it's known.Martin Sebor1-0/+1
gcc/ChangeLog: * gimple-ssa-sprintf.c (format_integer): Set knownrange when it's known. gcc/testsuite/ChangeLog: * tree-ssa/builtin-sprintf-warn-18.c: Adjust to avoid failures on ILP32 targets. From-SVN: r247444
2017-04-28PR tree-optimization/80523 - -Wformat-overflow doesn't consider -fexec-charsetMartin Sebor1-72/+286
gcc/ChangeLog: PR tree-optimization/80523 * gimple-ssa-sprintf.c (target_to_host_charmap): New global variable. (init_target_to_host_charmap, target_to_host, target_strtol10): New functions. (maybe_warn, format_directive, parse_directive): Use new functions. (pass_sprintf_length::execute): Call init_target_to_host_charmap. gcc/testsuite/ChangeLog: PR tree-optimization/80523 * gcc.dg/tree-ssa/builtin-sprintf-warn-18.c: New test. From-SVN: r247401
2017-04-25PR tree-optimization/80497 - ICE at -O1 and above on valid code on ↵Martin Sebor1-2/+5
x86_64-linux-gnu in tree_to_uhwi gcc/ChangeLog: PR tree-optimization/80497 * gimple-ssa-sprintf.c (get_int_range): Avoid assuming all integer constants are representable in HOST_WIDE_INT. (parse_directive): Ditto. gcc/testsuite/ChangeLog: PR tree-optimization/80497 * gcc.dg/tree-ssa/builtin-sprintf-warn-17.c: New test. From-SVN: r247262
2017-04-11PR middle-end/80364 - sanitizer detects signed integer overflow in ↵Martin Sebor1-27/+44
gimple-ssa-sprintf.c gcc/ChangeLog: PR middle-end/80364 * gimple-ssa-sprintf.c (get_int_range): Remove second argument and always use the int type. Use INTEGRAL_TYPE_P() rather than testing for INTEGER_TYPE. (directive::set_width, directive::set_precision, format_character): Adjust. (parse_directive): Use INTEGRAL_TYPE_P() rather than testing for INTEGER_TYPE. gcc/testsuite/ChangeLog: PR middle-end/80364 * gcc.dg/tree-ssa/builtin-sprintf-warn-16.c: New test. From-SVN: r246846
2017-03-14re PR tree-optimization/79800 (wrong snprintf result range with precision in ↵Martin Sebor1-28/+24
a narrow negative-positive range) PR tree-optimization/79800 * gimple-ssa-sprintf.c (format_floating: Add argument. Handle precision in negative-positive range. (format_floating): Call non-const overload with adjusted precision. PR tree-optimization/79800 * gcc.dg/tree-ssa/builtin-sprintf-warn-15.c: Add test cases. * gcc.dg/tree-ssa/pr79800.c: New test. From-SVN: r246151
2017-03-01PR middle-end/79692 - [7 Regression] -Wformat-overflow false positiveMartin Sebor1-32/+132
gcc/ChangeLog: PR middle-end/79692 * gimple-ssa-sprintf.c (directive::known_width_and_precision): New function. (format_integer): Use it. (get_mpfr_format_length): Consider the full range of precision when computing %g output with the # flag. Set the likely byte count to 3 rather than 1 when precision is indeterminate. (format_floating): Correct the lower bound of precision. gcc/testsuite/ChangeLog: PR middle-end/79692 * gcc.dg/tree-ssa/builtin-sprintf-2.c: Add test cases. * gcc.dg/tree-ssa/builtin-sprintf-warn-10.c: Correct %#g. * gcc.dg/tree-ssa/builtin-sprintf-warn-15.c: New test. * gcc.dg/tree-ssa/builtin-snprintf-3.c: Ditto. From-SVN: r245822
2017-02-17re PR tree-optimization/79327 (wrong code at -O2 and -fprintf-return-value)Jakub Jelinek1-20/+9
PR tree-optimization/79327 * gimple-ssa-sprintf.c (format_integer): Remove likely_adjust variable, its initialization and use. From-SVN: r245542
2017-02-14PR middle-end/79448 - unhelpful -Wformat-truncation=2 warningMartin Sebor1-3/+11
gcc/testsuite/ChangeLog: PR middle-end/79448 * gcc.dg/tree-ssa/builtin-snprintf-warn-3.c: New test. * gcc.dg/tree-ssa/pr79448-2.c: New test. * gcc.dg/tree-ssa/pr79448.c: New test. gcc/ChangeLog: PR middle-end/79448 * gimple-ssa-sprintf.c (format_directive): Avoid issuing INT_MAX warning for strings of unknown length. From-SVN: r245437
2017-02-13PR middle-end/79496 - call to snprintf with zero size eliminated with ↵Martin Sebor1-3/+12
-Wformat-truncation=2 gcc/ChangeLog: PR middle-end/79496 * gimple-ssa-sprintf.c (pass_sprintf_length::handle_gimple_call): Avoid clearing info.nowrite flag when snprintf size argument is a range. gcc/testsuite/ChangeLog: PR middle-end/79496 * gcc.dg/tree-ssa/builtin-snprintf-2.c: New test. From-SVN: r245415
2017-02-03PR tree-optimization/79327 - wrong code at -O2 and -fprintf-return-valueMartin Sebor1-2/+38
PR tree-optimization/79327 - wrong code at -O2 and -fprintf-return-value gcc/ChangeLog: * gimple-ssa-sprintf.c (tree_digits): Avoid adding the base prefix when precision has resulted in leading zeros. (format_integer): Adjust the likely counter to assume an unknown argument that may be zero is non-zero. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Adjust. * gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-13.c: New test. * gcc/testsuite/gcc.dg/tree-ssa/pr79327-2.c: Ditto. From-SVN: r245173
2017-02-03re PR tree-optimization/79327 (wrong code at -O2 and -fprintf-return-value)Jakub Jelinek1-76/+30
PR tree-optimization/79327 * gimple-ssa-sprintf.c (adjust_range_for_overflow): If returning true, always set *argmin and *argmax to TYPE_{MIN,MAX}_VALUE of dirtype. (format_integer): Use wide_int_to_tree instead of build_int_cst + to_?hwi. If argmin is NULL, just set argmin and argmax to TYPE_{MIN,MAX}_VALUE of argtype. Simplify and fix computation of shortest and longest sequence. * gcc.dg/tree-ssa/pr79327.c: New test. * gcc.dg/tree-ssa/builtin-sprintf-warn-1.c (test_sprintf_chk_hh_nonconst): Don't expect 2 bogus warnings. * gcc.dg/tree-ssa/builtin-sprintf-warn-3.c (test_sprintf_chk_range_schar): Adjust dg-message. * gcc.dg/tree-ssa/builtin-sprintf-warn-12.c: New test. * gcc.c-torture/execute/pr79327.c: New test. Co-Authored-By: Martin Sebor <msebor@redhat.com> From-SVN: r245166
2017-02-03PR tree-optimization/79352 - -fprintf-return-value doesn't handle ↵Martin Sebor1-2/+6
flexible-like array members properly gcc/ChangeLog: PR tree-optimization/79352 * gimple-fold.c (get_range_strlen): Add argument. (get_range_strlen): Change return type to bool. (get_maxval_strlen): Pass in a dummy argument. * gimple-fold.h (get_range_strlen): Change return type to bool. * gimple-ssa-sprintf.c (get_string_length): Set unlikely counter. * tree.h (array_at_struct_end_p): Add argument. * tree.c (array_at_struct_end_p): Handle it. gcc/testsuite/ChangeLog: PR tree-optimization/79352 * gcc.dg/tree-ssa/pr79352.c: New test. From-SVN: r245156
2017-02-03Fix memory leaks in gimple-ssa-sprintf.c (PR tree-optimization/79339).Martin Liska1-1/+5
2017-02-03 Martin Liska <mliska@suse.cz> PR tree-optimization/79339 * gimple-ssa-sprintf.c (format_floating_max): Call mpfr_clear. (format_floating): Likewise. From-SVN: r245146
2017-02-02PR middle-end/79275 - -Wformat-overflow false positive exceeding INT_MAX in ↵Martin Sebor1-22/+69
glibc sysdeps/posix/tempname.c gcc/testsuite/ChangeLog: PR middle-end/79275 * gcc.dg/tree-ssa/builtin-sprintf-warn-11.c: New test. * gcc.dg/tree-ssa/pr79275.c: New test. gcc/ChangeLog: PR middle-end/79275 * gimple-ssa-sprintf.c (get_string_length): Set lower bound to zero. (format_string): Tighten up the range of output for non-constant strings and correct the expected range for wide non-constant strings. From-SVN: r245142
2017-01-30gimple-ssa-sprintf.c (fmtresult::adjust_for_width_or_precision): Move ↵Martin Sebor1-14/+14
constant to the right of a relational operator. gcc/ChangeLog: * gimple-ssa-sprintf.c (fmtresult::adjust_for_width_or_precision): Move constant to the right of a relational operator. (get_mpfr_format_length, format_character, format_string): Ditto. (should_warn_p, maybe_warn): Same. From-SVN: r245040
2017-01-27realmpfr.h: Poison MPFR_RND{N,Z,U,D}.Jakub Jelinek1-1/+1
* realmpfr.h: Poison MPFR_RND{N,Z,U,D}. * gimple-ssa-sprintf.c (format_floating_max): Use GMP_RNDN instead of MPFR_RNDN. From-SVN: r244966
2017-01-26gimple-ssa-sprintf.c (format_floating): Simplify the computation of ↵Martin Sebor1-14/+4
precision to avoid preprocessor conditional. gcc/ChangeLog: * gimple-ssa-sprintf.c (format_floating): Simplify the computation of precision to avoid preprocessor conditional. From-SVN: r244961
2017-01-26gimple-ssa-sprintf.c (format_floating): Test HAVE_XFmode and HAVE_DFmode ↵Martin Sebor1-7/+16
before using XFmode or DFmode. gcc/ChangeLog: * gimple-ssa-sprintf.c (format_floating): Test HAVE_XFmode and HAVE_DFmode before using XFmode or DFmode. (parse_directive): Avoid using the z length modifier to avoid the ISO C++98 does not support the ‘z’ gnu_printf length modifier. From-SVN: r244957
2017-01-26PR middle-end/78703 - fprintf-return-value floating point handling incorrect ↵Martin Sebor1-195/+253
in locales with a mulltibyte decimal point gcc/ChangeLog: PR middle-end/78703 * gimple-ssa-sprintf.c (adjust_for_width_or_precision): Change to accept adjustment as an array. (get_int_range): New function. (struct directive): Make width and prec arrays. (directive::set_width, directive::set_precision): Call get_int_range. (format_integer, format_floating): Handle width and precision ranges. (format_string, parse_directive): Same. gcc/testsuite/ChangeLog: PR middle-end/78703 * gcc.dg/tree-ssa/builtin-snprintf-warn-1.c: Update * gcc.dg/tree-ssa/builtin-sprintf-warn-9.c: Rename... * gcc.dg/tree-ssa/builtin-sprintf-warn-10.c: ...to this. * gcc.dg/tree-ssa/builtin-sprintf-warn-9.c: New test. From-SVN: r244956
2017-01-26PR middle-end/78703 -fprintf-return-value floating point handling incorrect ↵Martin Sebor1-759/+945
in locales with a mulltibyte decimal point gcc/ChangeLog: PR middle-end/78703 * gimple-ssa-sprintf.c (struct result_range): Add likely and unlikely counters. (struct format_result): Replace number_chars, number_chars_min, and number_chars_max with a single member of struct result_range. Remove bounded. (format_result::operator+=): Adjust. (struct fmtresult): Remove bounded. Handle likely and unlikely counters. (fmtresult::adjust_for_width_or_precision): New function. (fmtresult:type_max_digits): New function. (bytes_remaining): Handle likely and unlikely counters. (min_bytes_remaining): Remove. (format_percent): Simplify. (format_integer, format_floating): Set likely and unlikely counters. (get_string_length, format_character, format_string): Same. (format_plain, should_warn_p): New function. (maybe_warn): Call should_warn_p. Update diagnostic messages and handle those for all directives, including plain strings. (format_directive): Handle likely and unlikely counters. Remove unnecessary quoting from diagnostics. Add an informational note. (add_bytes): Remove. (pass_sprintf_length::compute_format_length): Simplify. (try_substitute_return_value): Handle likely and unlikely counters. gcc/testsuite/ChangeLog: PR middle-end/78703 * gcc.dg/format/pr78569.c: Adjust. * gcc.dg/tree-ssa/builtin-snprintf-warn-2.c: Same. * gcc.dg/tree-ssa/builtin-sprintf-2.c: Same. * gcc.dg/tree-ssa/builtin-sprintf-5.c: Same. * gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Same. * gcc.dg/tree-ssa/builtin-sprintf-warn-2.c: Same. * gcc.dg/tree-ssa/builtin-sprintf-warn-3.c: Same. * gcc.dg/tree-ssa/builtin-sprintf-warn-4.c: Same. * gcc.dg/tree-ssa/builtin-sprintf-warn-6.c: Same. * gcc.dg/tree-ssa/builtin-sprintf-warn-7.c: Same. * gcc.dg/tree-ssa/builtin-sprintf-warn-9.c: Same. * gcc.dg/tree-ssa/builtin-sprintf.c: Same. From-SVN: r244953
2017-01-24Fix build failure with MPFR 2.4.xMarkus Trippelsdorf1-1/+1
* gimple-ssa-sprintf.c (format_floating): Change MPFR_RNDx to GMP_RNDx for compatiblity. From-SVN: r244858
2017-01-23PR middle-end/78703 - -fprintf-return-value floating point handling incorrect...Martin Sebor1-167/+234
PR middle-end/78703 - -fprintf-return-value floating point handling incorrect in locales with a mulltibyte decimal point * gimple-ssa-sprintf.c (warn_level): New global. (format_integer): Use it here and throughout the rest of the file. Use the same switch to compute sign as base. (maybe_warn): New function. (format_directive): Factor out warnings into maybe_warn. Add debugging output. Use warn_level. (add_bytes): Use warn_level. (pass_sprintf_length::compute_format_length): Add debugging output. (try_substitute_return_value): Same. (pass_sprintf_length::handle_gimple_call): Set and use warn_level. From-SVN: r244847
2017-01-23PR middle-end/78703 - -fprintf-return-value floating point handling incorrect...Martin Sebor1-110/+81
PR middle-end/78703 - -fprintf-return-value floating point handling incorrect in locales with a mulltibyte decimal point * gimple-ssa-sprintf.c (struct format_result): Remove constant member. (struct fmtresult, format_integer, format_floating): Adjust. (get_string_length, format_string,format_directive): Same. (pass_sprintf_length::compute_format_length): Same. (try_substitute_return_value): Simplify slightly. From-SVN: r244846
2017-01-23PR middle-end/78703 - -fprintf-return-value floating point handling incorrect...Martin Sebor1-660/+783
PR middle-end/78703 - -fprintf-return-value floating point handling incorrect in locales with a mulltibyte decimal point * gimple-ssa-sprintf.c (pass_sprintf_length::gate): Adjust formatting. (fmtresult::operator+=): Outlined. (struct fmtresult): Add ctors. (struct conversion_spec): Rename... (struct directive): ...to this. Add and remove data members. (directive::set_width, directive::set_precision): New functions. (format_percent): Use fmtresult ctor. (get_width_and_precision): Remove. (format_integer): Make naming changes. Avoid computing width and precision. (format_floating): Same. Adjust indentation. (format_character, format_none): New functions. (format_string): Moved character handling to format_character. (format_directive): Remove arguments, change return type. (parse_directive): New function. (pass_sprintf_length::compute_format_length): Move directive parsing to parse_directive. From-SVN: r244845
2017-01-16PR tree-optimization/78608 - gimple-ssa-sprintf.c:570:17: runtime error: ↵Martin Sebor1-10/+16
negation of -9223372036854775808 cannot be represented in type 'long int' gcc/ChangeLog: * gimple-ssa-sprintf.c (tree_digits): Avoid negating TYPE_MIN. From-SVN: r244511
2017-01-16gimple-ssa-sprintf.c (format_directive): Correct a typo in a warning message.Martin Sebor1-1/+2
gcc/ChangeLog: * gimple-ssa-sprintf.c (format_directive): Correct a typo in a warning message. From-SVN: r244500
2017-01-12(-Wformat-overflow): ...to this.Martin Sebor1-16/+16
gcc/c-family/ChangeLog: (-Wformat-overflow): ...to this. gcc/ChangeLog: to -Wformat-overflow. * gimple-ssa-sprintf.c (pass_sprintf_length::gate): Adjust. (min_bytes_remaining): Same. (get_string_length): Same. (format_string): Same. (format_directive): Same. (add_bytes): Same. (pass_sprintf_length::handle_gimple_call): Same. gcc/testsuite/ChangeLog: * gcc.dg/pr78138.c: Adjust. * gcc.dg/pr78768.c: Adjust. * gcc.dg/tree-ssa/builtin-sprintf-4.c: Adjust. * gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Adjust. * gcc.dg/tree-ssa/builtin-sprintf-warn-2.c: Adjust. * gcc.dg/tree-ssa/builtin-sprintf-warn-3.c: Adjust. * gcc.dg/tree-ssa/builtin-sprintf-warn-4.c: Adjust. * gcc.dg/tree-ssa/builtin-sprintf-warn-6.c: Adjust. * gcc.dg/tree-ssa/builtin-sprintf-warn-7.c: Adjust. * gcc.dg/tree-ssa/builtin-sprintf-warn-8.c: Adjust. * gcc.dg/tree-ssa/builtin-sprintf-warn-9.c: Adjust. * gcc.dg/tree-ssa/pr78605.c: Adjust. * gcc.dg/tree-ssa/pr78622.c: Adjust. From-SVN: r244385
2017-01-12gimple-ssa-sprintf.c (try_substitute_return_value): Remove info.nowrite ↵Jakub Jelinek1-20/+45
calls with no lhs that can't throw. * gimple-ssa-sprintf.c (try_substitute_return_value): Remove info.nowrite calls with no lhs that can't throw. Return bool whether gsi_remove has been called or not. (pass_sprintf_length::handle_gimple_call): Return bool whether try_substitute_return_value called gsi_remove. Formatting fix. (pass_sprintf_length::execute): Don't use gsi_remove if handle_gimple_call returned true. * gcc.dg/tree-ssa/builtin-snprintf-1.c: New test. From-SVN: r244384
2017-01-10PR middle-end/78245 - missing -Wformat-length on an overflow of a ↵Martin Sebor1-0/+5
dynamically allocated buffer gcc/testsuite/ChangeLog: PR middle-end/78245 * gcc.dg/tree-ssa/builtin-sprintf-warn-3.c: Add tests. gcc/ChangeLog: PR middle-end/78245 * gimple-ssa-sprintf.c (get_destination_size): Call {init,fini}object_sizes. * tree-object-size.c (addr_object_size): Adjust. (pass_through_call): Adjust. (pass_object_sizes::execute): Adjust. * tree-object-size.h (fini_object_sizes): Declare. From-SVN: r244293
2017-01-08PR tree-optimization/78913 - Probably misleading error reported by ↵Martin Sebor1-31/+50
-Wformat-length PR tree-optimization/78913 - Probably misleading error reported by -Wformat-length PR middle-end/77708 - -Wformat-length %s warns for snprintf gcc/ChangeLog: PR middle-end/77708 * doc/invoke.texi (Warning Options): Document -Wformat-truncation. * gimple-ssa-sprintf.c (call_info::reval_used, call_info::warnopt): New member functions. (format_directive): Used them. (add_bytes): Same. (pass_sprintf_length::handle_gimple_call): Same. * graphite-sese-to-poly.c (tree_int_to_gmp): Increase buffer size to avoid truncation for any argument. (extract_affine_mul): Same. * tree.c (get_file_function_name): Same. gcc/c-family/ChangeLog: PR middle-end/77708 * c.opt (-Wformat-truncation): New option. gcc/fortran/ChangeLog: PR tree-optimization/78913 PR middle-end/77708 * trans-common.c (build_equiv_decl): Increase buffer size to avoid truncation for any argument. * trans-types.c (gfc_build_logical_type): Same. gcc/testsuite/ChangeLog: PR middle-end/77708 * gcc.dg/tree-ssa/builtin-snprintf-warn-1.c: New test. * gcc.dg/tree-ssa/builtin-snprintf-warn-2.c: New test. * gcc.dg/tree-ssa/builtin-sprintf-warn-6.c: XFAIL test cases failing due to bug 78969. * gcc.dg/format/pr78569.c: Adjust. From-SVN: r244210
2017-01-05PR tree-optimization/78910 - Wrong print-return-value for a negative numberMartin Sebor1-13/+15
gcc/ChangeLog: PR tree-optimization/78910 * gimple-ssa-sprintf.c (tree_digits): Add an argument. (format_integer): Correct off-by-one error in the handling of precision with negative numbers in signed conversions.. gcc/testsuite/ChangeLog: PR tree-optimization/78910 * gcc.dg/tree-ssa/builtin-sprintf-warn-7.c: Adjust text of expected diagnostics. * gcc.dg/tree-ssa/builtin-sprintf.c: Add test cases. * gcc.dg/tree-ssa/pr78910.c: New test. From-SVN: r244116
2017-01-03PR tree-optimization/78696 - [7 Regression] -fprintf-return-value ↵Martin Sebor1-110/+138
misoptimizes %.Ng where N is greater than 10 gcc/ChangeLog: PR tree-optimization/78696 * gimple-ssa-sprintf.c (format_floating): Correct handling of precision. Use MPFR for %f for greater fidelity. Correct handling of %g. (pass_sprintf_length::compute_format_length): Set width and precision specified by asrerisk to void_node for vararg functions. (try_substitute_return_value): Adjust dump output. gcc/testsuite/ChangeLog: PR tree-optimization/78696 * gcc.dg/tree-ssa/builtin-sprintf-5.c: Remove incorrect test cases. * gcc.dg/tree-ssa/builtin-sprintf-warn-7.c: Correct off-by-1 errors. * gcc.dg/tree-ssa/builtin-sprintf-warn-9.c: New test. * gcc.dg/tree-ssa/builtin-sprintf.c: Add test cases. From-SVN: r244037
2017-01-03re PR tree-optimization/78965 (Invalid -fprintf-return-value optimization)Jakub Jelinek1-3/+7
PR tree-optimization/78965 * gimple-ssa-sprintf.c (pass_sprintf_length::compute_format_length): Change first argument from const call_info & to call_info &. For %n set info.nowrite to false. * gcc.dg/pr78965.c: New test. From-SVN: r244014
2017-01-03re PR middle-end/78901 (ICE: verify_gimple failed (error: statement marked ↵Jakub Jelinek1-2/+8
for throw in middle of block)) PR middle-end/78901 * gimple-ssa-sprintf.c (try_substitute_return_value): Don't change possibly throwing calls. * g++.dg/opt/pr78901.C: New test. From-SVN: r244013
2017-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r243994
2016-12-14PR middle-end/78519 - missing warning for sprintf %s with null pointerMartin Sebor1-5/+50
gcc/ChangeLog: PR middle-end/78519 * gimple-ssa-sprintf.c (format_string): Handle null pointers. (format_directive): Diagnose null pointer arguments. (pass_sprintf_length::handle_gimple_call): Diagnose null destination pointers. Correct location of null format string in diagnostics. gcc/testsuite/ChangeLog: PR middle-end/78519 * gcc.dg/tree-ssa/builtin-sprintf-warn-7.c: New test. From-SVN: r243684
2016-12-14PR middle-end/78786 - GCC hangs/out of memory calling sprintf with large ↵Martin Sebor1-48/+97
precision gcc/ChangeLog: PR middle-end/78786 * gimple-ssa-sprintf.c (target_dir_max): New macro. (get_mpfr_format_length): New function. (format_integer): Use HOST_WIDE_INT instead of int. (format_floating_max): Same. (format_floating): Call get_mpfr_format_length. (format_directive): Use target_dir_max. gcc/testsuite/ChangeLog: PR middle-end/78786 * gcc.dg/tree-ssa/builtin-sprintf-warn-7.c: New test. From-SVN: r243672
2016-12-12PR middle-end/78622 - -Wformat-length/-fprintf-return-value incorrect with ↵Martin Sebor1-95/+175
overflow/wrapping gcc/ChangeLog: PR middle-end/78622 PR middle-end78606 * gimple-ssa-sprintf.c (min_bytes_remaining): Use res.knownrange rather than res.bounded. (get_width_and_precision): Set precision to -1 when negative. (adjust_range_for_overflow): New function. (format_integer): Correct the handling of the space, plus, and pound flags, and the special case of zero precision. Always set res.bounded to true unless either precision or width is specified and unknown. Call adjust_range_for_overflow. Avoid use zero as the shortest value when precision is specified but unknown. (format_directive): Remove vestigial quoting. Always inform of argument value or range when it's available. (add_bytes): Correct the computation of boundrange used to decide whether a warning is of a "maybe" or "defnitely" kind. gcc/testsuite/ChangeLog: PR middle-end/78622 PR middle-end78606 * gcc.c-torture/execute/pr78622.c: New test. * gcc.dg/tree-ssa/builtin-sprintf-2.c: Remove "benign" undefined behavior inadvertently introduced in a previous commit. Tighten up final checking. * gcc.dg/tree-ssa/builtin-sprintf-5.c: Rename macros for clarity. Add test cases. * gcc.dg/tree-ssa/builtin-sprintf-6.c: Add test cases. * gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Same. * gcc.dg/tree-ssa/builtin-sprintf-warn-2.c: Same. * gcc.dg/tree-ssa/builtin-sprintf-warn-3.c: Same. * gcc.dg/tree-ssa/builtin-sprintf-warn-5.c: Same. * gcc.dg/tree-ssa/builtin-sprintf-warn-6.c: Remove xfails and add a final optimization check. * gcc.dg/tree-ssa/builtin-sprintf.c: Add test cases. * gcc.dg/tree-ssa/pr78622.c: New test. From-SVN: r243582
2016-12-07PR c/53562 - Add -Werror= support for -D_FORTIFY_SOURCE / __builtin___memcpy_chkMartin Sebor1-16/+45
PR c/53562 - Add -Werror= support for -D_FORTIFY_SOURCE / __builtin___memcpy_chk PR middle-end/77784 - duplicate warning for snprintf when n > object size PR middle-end/78149 - missing warning on strncpy buffer overflow due to an excessive bound PR middle-end/78138 - missing warnings on buffer overflow with non-constant source length gcc/c-family/ChangeLog: PR c/53562 PR middle-end/77784 PR middle-end/78149 PR middle-end/78138 * c.opt (-Wstringop-overflow): New option. gcc/ChangeLog: PR middle-end/77784 PR middle-end/78149 PR middle-end/78138 * builtins.c (expand_builtin_strcat, expand_builtin_strncat): New functions. (compute_dest_size, get_size_range, check_sizes, check_strncat_sizes) (check_memop_sizes): Same. (expand_builtin_memcpy): Call check memop_sizes. (expand_builtin_mempcpy): Same. (expand_builtin_memset): Same, (expand_builtin_bzero): Same. (expand_builtin_memory_chk): Call check_sizes. (expand_builtin_strcpy): Same. (expand_builtin_strncpy): Same. (maybe_emit_sprintf_chk_warning): Same. (expand_builtin): Handle strcat and strncat. (fini_object_sizes): Reset pointers. (compute_object_size): New function. * gimple-ssa-sprintf.c (pass_sprintf_length::handle_gimple_call): Avoid issuing warnings also issued during built-in expansion. * doc/invoke.texi (Warning Options): Document -Wstringop-overflow. gcc/testsuite/ChangeLog: PR middle-end/77784 PR middle-end/78149 PR middle-end/78138 * c-c++-common/Wsizeof-pointer-memaccess2.c: Adjust expected diagnostic. * g++.dg/ext/builtin-object-size3.C (bar): Same. * g++.dg/ext/strncpy-chk1.C: Same. * g++.dg/opt/memcpy1.C: Same. * g++.dg/torture/Wsizeof-pointer-memaccess1.C: Same. * gcc.c-torture/compile/pr55569.c: Disable -Wstringop-overflow. * gcc.dg/Wobjsize-1.c: Adjust expected diagnostic. * gcc.dg/attr-alloc_size.c: Same. * gcc.dg/builtin-stringop-chk-1.c: Adjust expected diagnostic. * gcc.dg/builtin-stringop-chk-2.c: Same. * gcc.dg/builtin-stringop-chk-4.c: New test. * gcc.dg/builtin-strncat-chk-1.c: Adjust expected diagnostic. * gcc.dg/memcpy-2.c: Same. * gcc.dg/pr40340-1.c: Same. * gcc.dg/pr40340-2.c (main): Same. * gcc.dg/pr40340-5.c (main): Same. * gcc.dg/torture/Wsizeof-pointer-memaccess1.c: Same. * gcc.dg/torture/pr71132.c: Disable -Wstringop-overflow. * gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Adjust text of expected warning. * gfortran.dg/char_length_3.f90: Prune expected warnings. * gfortran.dg/pr38868.f: Add expected warnings. From-SVN: r243419
2016-12-02re PR tree-optimization/78586 (Wrong code caused by printf-return-value)Jakub Jelinek1-18/+12
PR tree-optimization/78586 * gimple-ssa-sprintf.c (format_integer): Don't handle NOP_EXPR, CONVERT_EXPR or COMPONENT_REF here. Formatting fix. For SSA_NAME_DEF_STMT with NOP_EXPR only change argtype if the rhs1's type is INTEGER_TYPE or POINTER_TYPE. From-SVN: r243145
2016-11-30re PR tree-optimization/78586 (Wrong code caused by printf-return-value)Jakub Jelinek1-15/+16
PR tree-optimization/78586 * gimple-ssa-sprintf.c (format_integer): Use TYPE_MAX_VALUE or TYPE_MIN_VALUE or build_all_ones_cst instead of folding LSHIFT_EXPR. Don't build_int_cst min/max twice. Formatting fix. * gcc.c-torture/execute/pr78586.c: New test. From-SVN: r242998
2016-11-29PR tree-optimization/78512 - [7 Regression] r242674 miscompiles Linux kernelMartin Sebor1-90/+29
gcc/ChangeLog: PR tree-optimization/78512 * config/linux.h (TARGET_PRINTF_POINTER_FORMAT): Remove. * config/rs6000/linux.h: Same. * config/rs6000/linux64.h: Same. * config/sol2.h: Same. * config/sol2.c (solaris_printf_pointer_format): Remove. * doc/tm.texi.in (TARGET_PRINTF_POINTER_FORMAT): Remove. * doc/tm.texi: Regenerate. * gimple-ssa-sprintf.c (format_pointer): Rempove. (pass_sprintf_length::compute_format_length): Return bool. (pass_sprintf_length::handle_gimple_call): Adjust. * target.def (printf_pointer_format): Remove. * targhooks.c (default_printf_pointer_format): Remove. (linux_printf_pointer_format): Same. * targhooks.h (default_printf_pointer_format): Remove. (linux_printf_pointer_format, solaris_printf_pointer_format): Same. gcc/testsuite/ChangeLog: PR tree-optimization/78512 * gcc.dg/tree-ssa/builtin-sprintf-6.c: Add test cases. * gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Remove test cases. From-SVN: r242975
2016-11-28PR middle-end/78521 - [7 Regression] incorrect byte count in -Wformat-length...Martin Sebor1-124/+229
PR middle-end/78521 - [7 Regression] incorrect byte count in -Wformat-length warning with non-constant width or precision PR middle-end/78520 - missing warning for snprintf with size greater than INT_MAX gcc/ChangeLog: PR middle-end/78520 * gimple-ssa-sprintf.c (target_max_value): Remove. (target_int_max, target_size_max): Use TYPE_MAX_VALUE. (get_width_and_precision): New function. (format_integer, format_floating, get_string_length, format_string): Correct handling of width and precision with unknown value. (format_directive): Add warning. (pass_sprintf_length::compute_format_length): Allow for precision to consist of a sole period with no asterisk or digits after it. gcc/testsuite/ChangeLog: PR middle-end/78520 * gcc.dg/tree-ssa/builtin-sprintf-5.c: Add test cases. * gcc.dg/tree-ssa/builtin-sprintf-6.c: New test. * gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Add test cases. * gcc.dg/tree-ssa/builtin-sprintf-warn-3.c: Add test cases. From-SVN: r242935