diff options
author | Tim Lange <mail@tim-lange.me> | 2022-08-18 11:36:08 +0200 |
---|---|---|
committer | Tim Lange <mail@tim-lange.me> | 2022-08-18 16:41:56 +0200 |
commit | c83e97317efb87fd5639a9ee9ec55aa1caa5423e (patch) | |
tree | 438c54d1f341f64f7397a25de6a919984f97df55 /gcc/testsuite/gcc.dg/analyzer/pr106181.c | |
parent | 011d0a033ab370ea38b06b813ac62be8dde0801b (diff) | |
download | gcc-c83e97317efb87fd5639a9ee9ec55aa1caa5423e.zip gcc-c83e97317efb87fd5639a9ee9ec55aa1caa5423e.tar.gz gcc-c83e97317efb87fd5639a9ee9ec55aa1caa5423e.tar.bz2 |
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.
Diffstat (limited to 'gcc/testsuite/gcc.dg/analyzer/pr106181.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/analyzer/pr106181.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr106181.c b/gcc/testsuite/gcc.dg/analyzer/pr106181.c new file mode 100644 index 0000000..6a78b78 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/pr106181.c @@ -0,0 +1,11 @@ +#include <stdint.h> + +void * +foo (int x) +{ + return __builtin_calloc (x * 1.1, 1); /* { dg-line calloc } */ + + /* { dg-warning "use of floating-point arithmetic here might yield unexpected results" "warning" { target *-*-* } calloc } */ + /* { dg-message "operand '\(\\d|e|f|\\.|\\+|\)+' is of type 'double'" "note" { target *-*-* } calloc } */ + /* { dg-message "only use operands of an integer type inside the size argument" "note" { target *-*-* } calloc } */ +} |