[gcc-12,PR104308,analyzer] handle memmove like memcpy
Checks
Commit Message
Hello, David,
I'd written this patch for gcc-12, but you've worked too much on the
analyzer ;-) for it to apply in the trunk. I wonder if there's any use
you can make of it, or of the observations in it, or whether you'd
prefer me to try to port it.
I've regstrapped it on x86_64-linux-gnu, and also tested with crosses to
riscv64-elf and arm-eabi, but with gcc-12 only, so I'm hesitant to ask
whether it's ok to install. Trunk still fails to issue the warning for
memmove on riscv64-elf.
The testcase expects analyzer warnings for memmove just like for
memcpy. We get them when memmove is open-coded, but not when it
remains a call.
The analyzer has code to handle memcpy calls, whose logic can be
trivially reused for memmove, but we don't get the expected warnings
and notes for memmove on riscv64-*-elf. They wouldn't be issued for
memcpy either, if it wasn't open-coded.
I've managed to find out how to get the warning for the remaining-call
variants, but not to get the note issued for the point of creation of
the uninitialized buffer, so this patch also adds an xfail for the
note on riscv*-*-*.
for gcc/analyzer/ChangeLog
* region-model.cc (region_model::on_call_pre): Handle memmove
and memmove_chk like memcpy.
* region-model-impl-calls.cc (region_model::impl_call_memcpy):
Check for poison in the src region.
for gcc/testsuite/ChangeLog
* gcc.dg/analyzer/pr104308.c (test_memmove_within_uninit):
Expect creation point note to be missing on riscv*-*-*.
Change-Id: I66a856fa8e60f264a347dfd105e01c5a027d8f62
TN: VB12-006
---
gcc/analyzer/region-model-impl-calls.cc | 1 +
gcc/analyzer/region-model.cc | 4 ++++
gcc/testsuite/gcc.dg/analyzer/pr104308.c | 2 +-
3 files changed, 6 insertions(+), 1 deletion(-)
@@ -521,6 +521,7 @@ region_model::impl_call_memcpy (const call_details &cd)
= m_mgr->get_sized_region (dest_reg, NULL_TREE, num_bytes_sval);
const svalue *src_contents_sval
= get_store_value (sized_src_reg, cd.get_ctxt ());
+ check_for_poison (src_contents_sval, cd.get_arg_tree (1), cd.get_ctxt ());
set_value (sized_dest_reg, src_contents_sval, cd.get_ctxt ());
}
@@ -1421,6 +1421,10 @@ region_model::on_call_pre (const gcall *call, region_model_context *ctxt,
case BUILT_IN_MALLOC:
impl_call_malloc (cd);
return false;
+ case BUILT_IN_MEMMOVE:
+ case BUILT_IN_MEMMOVE_CHK:
+ /* We can use impl_call_memcpy until overlap checking is
+ added to it. */
case BUILT_IN_MEMCPY:
case BUILT_IN_MEMCPY_CHK:
impl_call_memcpy (cd);
@@ -6,7 +6,7 @@
int test_memmove_within_uninit (void)
{
- char s[5]; /* { dg-message "region created on stack here" } */
+ char s[5]; /* { dg-message "region created on stack here" "" { xfail riscv*-*-* } } */
memmove(s, s + 1, 2); /* { dg-warning "use of uninitialized value" } */
return 0;
}