]> git.ipfire.org Git - thirdparty/gcc.git/commit
analyzer: warn on the use of floating-points operands in the size argument [PR106181]
authorTim Lange <mail@tim-lange.me>
Thu, 18 Aug 2022 09:36:08 +0000 (11:36 +0200)
committerTim Lange <mail@tim-lange.me>
Thu, 18 Aug 2022 14:41:56 +0000 (16:41 +0200)
commitc83e97317efb87fd5639a9ee9ec55aa1caa5423e
tree438c54d1f341f64f7397a25de6a919984f97df55
parent011d0a033ab370ea38b06b813ac62be8dde0801b
analyzer: warn on the use of floating-points operands in the size argument [PR106181]

This patch fixes the ICE reported in PR106181 and adds a new warning to
the analyzer complaining about the use of floating-point operands.

Regrtested on Linux x86_64.

2022-08-17  Tim Lange  <mail@tim-lange.me>

gcc/analyzer/ChangeLog:

PR analyzer/106181
* analyzer.opt: Add Wanalyzer-imprecise-floating-point-arithmetic.
* region-model.cc (is_any_cast_p): Formatting.
(region_model::check_region_size): Ensure precondition.
(class imprecise_floating_point_arithmetic): New abstract
diagnostic class for all floating-point related warnings.
(class float_as_size_arg): Concrete diagnostic class to complain
about floating-point operands inside the size argument.
(class contains_floating_point_visitor):
New visitor to find floating-point operands inside svalues.
(region_model::check_dynamic_size_for_floats): New function.
(region_model::set_dynamic_extents):
Call to check_dynamic_size_for_floats.
* region-model.h (class region_model):
Add region_model::check_dynamic_size_for_floats.

gcc/ChangeLog:

PR analyzer/106181
* doc/invoke.texi: Add Wanalyzer-imprecise-fp-arithmetic.

gcc/testsuite/ChangeLog:

PR analyzer/106181
* gcc.dg/analyzer/allocation-size-1.c: New test.
* gcc.dg/analyzer/imprecise-floating-point-1.c: New test.
* gcc.dg/analyzer/pr106181.c: New test.
gcc/analyzer/analyzer.opt
gcc/analyzer/region-model.cc
gcc/analyzer/region-model.h
gcc/doc/invoke.texi
gcc/testsuite/gcc.dg/analyzer/allocation-size-1.c
gcc/testsuite/gcc.dg/analyzer/imprecise-floating-point-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/analyzer/pr106181.c [new file with mode: 0644]