diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index f6b7f986a39..a559bc84eb0 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -1044,6 +1044,16 @@ region_model::on_stmt_pre (const gimple *stmt, } } +/* Ensure that all arguments at the call described by CD are checked + for poisoned values, by calling get_rvalue on each argument. */ + +void +region_model::check_call_args (const call_details &cd) const +{ + for (unsigned arg_idx = 0; arg_idx < cd.num_args (); arg_idx++) + cd.get_arg_svalue (arg_idx); +} + /* Update this model for the CALL stmt, using CTXT to report any diagnostics - the first half. @@ -1173,6 +1183,7 @@ region_model::on_call_pre (const gcall *call, region_model_context *ctxt, /* These stdio builtins have external effects that are out of scope for the analyzer: we only want to model the effects on the return value. */ + check_call_args (cd); break; } else if (is_named_call_p (callee_fndecl, "malloc", call, 1)) diff --git a/gcc/analyzer/region-model.h b/gcc/analyzer/region-model.h index c78efe8f215..40958842bce 100644 --- a/gcc/analyzer/region-model.h +++ b/gcc/analyzer/region-model.h @@ -832,6 +832,8 @@ class region_model void check_region_for_read (const region *src_reg, region_model_context *ctxt) const; + void check_call_args (const call_details &cd) const; + /* Storing this here to avoid passing it around everywhere. */ region_model_manager *const m_mgr; diff --git a/gcc/testsuite/gcc.dg/analyzer/pr104224.c b/gcc/testsuite/gcc.dg/analyzer/pr104224.c new file mode 100644 index 00000000000..8f69d72befa --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/pr104224.c @@ -0,0 +1,106 @@ +#include + +struct test { + int one; + int two; +}; + +void func2(const struct test *t) +{ + if (t->one == 0) + printf("init func2\n"); + + if (t->two == 0) /* { dg-warning "uninitialized" } */ + printf("uninit func2\n"); +} + +void func1(struct test *t) +{ + t->one = 1; + func2(t); +} + +int func3(int num) +{ + if (num) + return num; + else + return 0; +} + +void func4(int *a, int max) +{ + int i; + // skip the first + for (i=1; i