]> gcc.gnu.org Git - gcc.git/commitdiff
asan: Fix up error recovery for too large frames [PR107317]
authorJakub Jelinek <jakub@redhat.com>
Thu, 24 Nov 2022 10:29:54 +0000 (11:29 +0100)
committerJakub Jelinek <jakub@redhat.com>
Thu, 24 Nov 2022 10:29:54 +0000 (11:29 +0100)
asan_emit_stack_protection and functions it calls have various asserts that
verify sanity of the stack protection instrumentation.  But, that
verification can easily fail if we've diagnosed a frame offset overflow.
asan_emit_stack_protection just emits some extra code in the prologue,
if we've reported errors, we aren't producing assembly, so it doesn't
really matter if we don't include the protection code, compilation
is going to fail anyway.

2022-11-24  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/107317
* asan.cc: Include diagnostic-core.h.
(asan_emit_stack_protection): Return NULL early if seen_error ().

* gcc.dg/asan/pr107317.c: New test.

gcc/asan.cc
gcc/testsuite/gcc.dg/asan/pr107317.c [new file with mode: 0644]

index 8276f12cc69438b99aa87cf318963397da344ec9..dc7b7f4bcf1803dd2ffbbaad782cf1b515d61ed8 100644 (file)
@@ -64,6 +64,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-inline.h"
 #include "tree-ssa.h"
 #include "tree-eh.h"
+#include "diagnostic-core.h"
 
 /* AddressSanitizer finds out-of-bounds and use-after-free bugs
    with <2x slowdown on average.
@@ -1818,6 +1819,11 @@ asan_emit_stack_protection (rtx base, rtx pbase, unsigned int alignb,
   tree str_cst, decl, id;
   int use_after_return_class = -1;
 
+  /* Don't emit anything when doing error recovery, the assertions
+     might fail e.g. if a function had a frame offset overflow.  */
+  if (seen_error ())
+    return NULL;
+
   if (shadow_ptr_types[0] == NULL_TREE)
     asan_init_shadow_ptr_types ();
 
diff --git a/gcc/testsuite/gcc.dg/asan/pr107317.c b/gcc/testsuite/gcc.dg/asan/pr107317.c
new file mode 100644 (file)
index 0000000..dd7ad7d
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR middle-end/107317 */
+/* { dg-do compile { target ilp32 } } */
+/* { dg-options "-fsanitize=address -ffat-lto-objects" } */
+
+void bar (float *, float *);
+
+void
+foo (void)             /* { dg-error "exceeds maximum" } */
+{
+  float a[400000000];
+  float b[200000000];
+  bar (a, b);
+}
This page took 0.072254 seconds and 5 git commands to generate.