Hi. Starting from r11-165-geb72dc663e9070b2 we should not rewrite parameters that have DECL_NOT_GIMPLE_REG_P set to true.
Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin gcc/ChangeLog: 2020-05-11 Martin Liska <mli...@suse.cz> PR sanitizer/95033 * sanopt.c (sanitize_rewrite_addressable_params): Do not rewrite for DECL_NOT_GIMPLE_REG_P. gcc/testsuite/ChangeLog: 2020-05-11 Martin Liska <mli...@suse.cz> PR sanitizer/95033 * g++.dg/asan/function-argument-4.C: New test. * gcc.dg/asan/pr95033.c: New test. --- gcc/sanopt.c | 1 + .../g++.dg/asan/function-argument-4.C | 26 +++++++++++++++++++ gcc/testsuite/gcc.dg/asan/pr95033.c | 13 ++++++++++ 3 files changed, 40 insertions(+) create mode 100644 gcc/testsuite/g++.dg/asan/function-argument-4.C create mode 100644 gcc/testsuite/gcc.dg/asan/pr95033.c
diff --git a/gcc/sanopt.c b/gcc/sanopt.c index 86180e32c7e..28a63442f4d 100644 --- a/gcc/sanopt.c +++ b/gcc/sanopt.c @@ -1155,6 +1155,7 @@ sanitize_rewrite_addressable_params (function *fun) if (TREE_ADDRESSABLE (arg) && !TREE_ADDRESSABLE (type) && !TREE_THIS_VOLATILE (arg) + && !DECL_NOT_GIMPLE_REG_P (arg) && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST) { TREE_ADDRESSABLE (arg) = 0; diff --git a/gcc/testsuite/g++.dg/asan/function-argument-4.C b/gcc/testsuite/g++.dg/asan/function-argument-4.C new file mode 100644 index 00000000000..cec1f1d788f --- /dev/null +++ b/gcc/testsuite/g++.dg/asan/function-argument-4.C @@ -0,0 +1,26 @@ +// { dg-do run } +// { dg-shouldfail "asan" } + +#include <complex.h> + +static __attribute__ ((noinline)) long double +goo (long double _Complex *a) +{ + return crealf(*(volatile _Complex long double *)a); +} + +__attribute__ ((noinline)) float +foo (float _Complex arg) +{ + return goo ((long double _Complex *)&arg); +} + +int +main () +{ + return foo (3 + 2 * I); +} + +// { dg-output "ERROR: AddressSanitizer: stack-buffer-overflow on address.*(\n|\r\n|\r)" } +// { dg-output "READ of size \[0-9\]* at.*" } +// { dg-output ".*'arg' \\(line 13\\) <== Memory access at offset \[0-9\]* partially overflows this variable.*" } diff --git a/gcc/testsuite/gcc.dg/asan/pr95033.c b/gcc/testsuite/gcc.dg/asan/pr95033.c new file mode 100644 index 00000000000..1228b7edcdb --- /dev/null +++ b/gcc/testsuite/gcc.dg/asan/pr95033.c @@ -0,0 +1,13 @@ +/* PR sanitizer/95033 */ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=address" } */ + +struct a +{ + int b; +}; + +struct a c(_Complex d) +{ + return *(struct a *)&d; +}