public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH gcc-12] [PR104308] [analyzer] handle memmove like memcpy
@ 2022-12-02  9:45 Alexandre Oliva
  2022-12-02 19:11 ` [PATCH trunk] " David Malcolm
  0 siblings, 1 reply; 4+ messages in thread
From: Alexandre Oliva @ 2022-12-02  9:45 UTC (permalink / raw)
  To: David Malcolm; +Cc: gcc-patches

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(-)

diff --git a/gcc/analyzer/region-model-impl-calls.cc b/gcc/analyzer/region-model-impl-calls.cc
index 621e7002ffb38..21b10e4b477db 100644
--- a/gcc/analyzer/region-model-impl-calls.cc
+++ b/gcc/analyzer/region-model-impl-calls.cc
@@ -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 ());
 }
 
diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc
index 23837a173460e..e0e95ae514576 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -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);
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr104308.c b/gcc/testsuite/gcc.dg/analyzer/pr104308.c
index a3a0cbb731776..e6a2c8821bf54 100644
--- a/gcc/testsuite/gcc.dg/analyzer/pr104308.c
+++ b/gcc/testsuite/gcc.dg/analyzer/pr104308.c
@@ -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;
 }

-- 
Alexandre Oliva, happy hacker                https://FSFLA.org/blogs/lxo/
   Free Software Activist                       GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about <https://stallmansupport.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-12-09  2:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-02  9:45 [PATCH gcc-12] [PR104308] [analyzer] handle memmove like memcpy Alexandre Oliva
2022-12-02 19:11 ` [PATCH trunk] " David Malcolm
2022-12-08 10:36   ` Alexandre Oliva
2022-12-09  2:28     ` [committed] analyzer: " David Malcolm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).