aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-05-07 21:29:14 +0200
committerJakub Jelinek <jakub@redhat.com>2024-06-11 12:35:38 +0200
commit25bd98dfd99e92c57ff393d393f54d028d7f86f4 (patch)
tree70481714c9b06622a567af03652f2412f17c98a1
parentbf134407b494bf79f66fc5048ff0ca409275089c (diff)
downloadgcc-25bd98dfd99e92c57ff393d393f54d028d7f86f4.zip
gcc-25bd98dfd99e92c57ff393d393f54d028d7f86f4.tar.gz
gcc-25bd98dfd99e92c57ff393d393f54d028d7f86f4.tar.bz2
tree-inline: Remove .ASAN_MARK calls when inlining functions into no_sanitize callers [PR114956]
In r9-5742 we've started allowing to inline always_inline functions into functions which have disabled e.g. address sanitization even when the always_inline function is implicitly from command line options sanitized. This mostly works fine because most of the asan instrumentation is done only late after ipa, but as the following testcase the .ASAN_MARK ifn calls gimplifier adds can result in ICEs. Fixed by dropping those during inlining, similarly to how we drop .TSAN_FUNC_EXIT calls. 2024-05-07 Jakub Jelinek <jakub@redhat.com> PR sanitizer/114956 * tree-inline.cc: Include asan.h. (copy_bb): Remove also .ASAN_MARK calls if id->dst_fn has asan/hwasan sanitization disabled. * gcc.dg/asan/pr114956.c: New test. (cherry picked from commit d4e25cf4f7c1f51a8824cc62bbb85a81a41b829a)
-rw-r--r--gcc/testsuite/gcc.dg/asan/pr114956.c26
-rw-r--r--gcc/tree-inline.cc28
2 files changed, 47 insertions, 7 deletions
diff --git a/gcc/testsuite/gcc.dg/asan/pr114956.c b/gcc/testsuite/gcc.dg/asan/pr114956.c
new file mode 100644
index 0000000..fb87d51
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/asan/pr114956.c
@@ -0,0 +1,26 @@
+/* PR sanitizer/114956 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fsanitize=address,null" } */
+
+int **a;
+void qux (int *);
+
+__attribute__((always_inline)) static inline int *
+foo (void)
+{
+ int b[1];
+ qux (b);
+ return a[1];
+}
+
+__attribute__((no_sanitize_address)) void
+bar (void)
+{
+ *a = foo ();
+}
+
+void
+baz (void)
+{
+ bar ();
+}
diff --git a/gcc/tree-inline.cc b/gcc/tree-inline.cc
index 8f5a44e..a49724f 100644
--- a/gcc/tree-inline.cc
+++ b/gcc/tree-inline.cc
@@ -65,6 +65,7 @@ along with GCC; see the file COPYING3. If not see
#include "symbol-summary.h"
#include "symtab-thunks.h"
#include "symtab-clones.h"
+#include "asan.h"
/* I'm not real happy about this, but we need to handle gimple and
non-gimple trees. */
@@ -2210,13 +2211,26 @@ copy_bb (copy_body_data *id, basic_block bb,
}
else if (call_stmt
&& id->call_stmt
- && gimple_call_internal_p (stmt)
- && gimple_call_internal_fn (stmt) == IFN_TSAN_FUNC_EXIT)
- {
- /* Drop TSAN_FUNC_EXIT () internal calls during inlining. */
- gsi_remove (&copy_gsi, false);
- continue;
- }
+ && gimple_call_internal_p (stmt))
+ switch (gimple_call_internal_fn (stmt))
+ {
+ case IFN_TSAN_FUNC_EXIT:
+ /* Drop .TSAN_FUNC_EXIT () internal calls during inlining. */
+ gsi_remove (&copy_gsi, false);
+ continue;
+ case IFN_ASAN_MARK:
+ /* Drop .ASAN_MARK internal calls during inlining into
+ no_sanitize functions. */
+ if (!sanitize_flags_p (SANITIZE_ADDRESS, id->dst_fn)
+ && !sanitize_flags_p (SANITIZE_HWADDRESS, id->dst_fn))
+ {
+ gsi_remove (&copy_gsi, false);
+ continue;
+ }
+ break;
+ default:
+ break;
+ }
/* Statements produced by inlining can be unfolded, especially
when we constant propagated some operands. We can't fold