public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH RFA] asan: poisoning promoted statics [PR113531]
@ 2024-01-31  3:37 Jason Merrill
  2024-01-31  8:51 ` Richard Biener
  0 siblings, 1 reply; 8+ messages in thread
From: Jason Merrill @ 2024-01-31  3:37 UTC (permalink / raw)
  To: gcc-patches

Tested x86_64-pc-linux-gnu, OK for trunk?

-- 8< --

Since my r14-1500-g4d935f52b0d5c0 we promote an initializer_list backing
array to static storage where appropriate, but this happens after we decided
to add it to asan_poisoned_variables.  As a result we add unpoison/poison
for it to the gimple.  But then sanopt removes the unpoison.  So the second
time we call the function and want to load from the array asan still
considers it poisoned.

A simple fix seems to be to not expand unpoison/poison for such a variable,
since by that time we know it's static.

	PR c++/113531

gcc/ChangeLog:

	* asan.cc (asan_expand_mark_ifn): Check TREE_STATIC.

gcc/testsuite/ChangeLog:

	* g++.dg/asan/initlist1.C: New test.
---
 gcc/asan.cc                           |  8 ++++++++
 gcc/testsuite/g++.dg/asan/initlist1.C | 20 ++++++++++++++++++++
 2 files changed, 28 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/asan/initlist1.C

diff --git a/gcc/asan.cc b/gcc/asan.cc
index 0fd7dd1f3ed..efecac2ea2b 100644
--- a/gcc/asan.cc
+++ b/gcc/asan.cc
@@ -3762,6 +3762,14 @@ asan_expand_mark_ifn (gimple_stmt_iterator *iter)
 
   gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
 
+  if (TREE_STATIC (decl))
+    {
+      /* Don't poison a variable with static storage; it might have gotten
+	 marked before gimplify_init_constructor promoted it to static.  */
+      gsi_remove (iter, true);
+      return false;
+    }
+
   if (hwasan_sanitize_p ())
     {
       gcc_assert (param_hwasan_instrument_stack);
diff --git a/gcc/testsuite/g++.dg/asan/initlist1.C b/gcc/testsuite/g++.dg/asan/initlist1.C
new file mode 100644
index 00000000000..6cd5b7d3aba
--- /dev/null
+++ b/gcc/testsuite/g++.dg/asan/initlist1.C
@@ -0,0 +1,20 @@
+// PR c++/113531
+// { dg-do run { target c++11 } }
+// { dg-additional-options "-fsanitize=address" }
+
+#include <initializer_list>
+
+void f(int) { }
+
+void g()
+{
+  for (auto i : { 1, 2, 3 })
+    f (i);
+  f(42);
+}
+
+int main()
+{
+  g();
+  g();
+}

base-commit: 209fc1e5f6c67e55e579b69f617b0b678b1bfdf0
-- 
2.39.3


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

end of thread, other threads:[~2024-01-31 17:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-31  3:37 [PATCH RFA] asan: poisoning promoted statics [PR113531] Jason Merrill
2024-01-31  8:51 ` Richard Biener
2024-01-31  9:07   ` Jakub Jelinek
2024-01-31 11:18     ` [PATCH] gimple-fold: Remove .ASAN_MARK calls on TREE_STATIC variables [PR113531] Jakub Jelinek
2024-01-31 12:04       ` Richard Biener
2024-01-31 15:20         ` [PATCH] gimple-low: " Jakub Jelinek
2024-01-31 17:57           ` Richard Biener
2024-01-31 13:45   ` [PATCH RFA] asan: poisoning promoted statics [PR113531] Jason Merrill

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