public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r9-9389] openmp: Set cfun->calls_alloca when needed in OpenMP outlined regions [PR97294] Date: Tue, 20 Apr 2021 23:29:45 +0000 (GMT) [thread overview] Message-ID: <20210420232945.4900D3AA7C97@sourceware.org> (raw) https://gcc.gnu.org/g:2913a8f35b7100e8632d2c10dc4126a636cbc9d9 commit r9-9389-g2913a8f35b7100e8632d2c10dc4126a636cbc9d9 Author: Jakub Jelinek <jakub@redhat.com> Date: Thu Oct 8 11:10:34 2020 +0200 openmp: Set cfun->calls_alloca when needed in OpenMP outlined regions [PR97294] The following testcase FAILs, because we don't mark the child OpenMP function as cfun->calls_alloca when it does call alloca. When optimizing, during DCE we reset those flags and recompute them again, but with -O0 DCE is not performed. Fixed by calling notice_special_calls when moving insns to the child function. cfun->calls_alloca is normally set during gimplification and most of the alloca calls omp-low.c does go through the gimplifier, but one spot didn't and built the gcall directly, so that one needs to set calls_alloca too. 2020-10-08 Jakub Jelinek <jakub@redhat.com> PR sanitizer/97294 * tree-cfg.c (move_block_to_fn): Call notice_special_calls on call stmts being moved into dest_cfun. * omp-low.c (lower_rec_input_clauses): Set cfun->calls_alloca when adding __builtin_alloca_with_align call without gimplification. * gcc.dg/asan/pr97294.c: New test. (cherry picked from commit a30fcfb3b848e4b895cb47378b4a250184af3afe) Diff: --- gcc/omp-low.c | 1 + gcc/testsuite/gcc.dg/asan/pr97294.c | 41 +++++++++++++++++++++++++++++++++++++ gcc/tree-cfg.c | 2 ++ 3 files changed, 44 insertions(+) diff --git a/gcc/omp-low.c b/gcc/omp-low.c index 9708e2de7fb..d3cb3ba5333 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -4647,6 +4647,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, atmp = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN); stmt = gimple_build_call (atmp, 2, x, size_int (DECL_ALIGN (var))); + cfun->calls_alloca = 1; tmp = create_tmp_var_raw (ptr_type_node); gimple_add_tmp_var (tmp); gimple_call_set_lhs (stmt, tmp); diff --git a/gcc/testsuite/gcc.dg/asan/pr97294.c b/gcc/testsuite/gcc.dg/asan/pr97294.c new file mode 100644 index 00000000000..6de6c3e7637 --- /dev/null +++ b/gcc/testsuite/gcc.dg/asan/pr97294.c @@ -0,0 +1,41 @@ +/* PR sanitizer/97294 */ +/* { dg-do compile { target fopenmp } } */ +/* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */ +/* { dg-options "-O0 -fsanitize=address -fopenmp" } */ +/* { dg-final { scan-assembler "foo._omp_fn.\[0-9]\[1-9]*:.*call\[ \t]\*__*asan_allocas_unpoison.*\.size\[ \t]\*foo._omp_fn.\[0-9]\[1-9]*," { target x86_64-*-linux* i?86-*-linux* } } } */ + +__attribute__((noipa)) void +foo (int *p, int n) +{ + int i; + #pragma omp parallel for num_threads(2) reduction(+:p[:n]) + for (i = 0; i < 10; i++) + { + p[0]++; + p[n - 1] += 2; + } +} + +__attribute__((noipa)) void +bar (void) +{ + unsigned char buf[1024]; + int i; + asm volatile ("" : : "r" (&buf[0]) : "memory"); + for (i = 0; i < 1024; i++) + buf[i] = i; + asm volatile ("" : : "r" (&buf[0]) : "memory"); +} + +int +main () +{ + int p[50], i; + for (i = 0; i < 50; i++) + p[i] = 0; + foo (p, 50); + bar (); + if (p[0] != 10 || p[49] != 20) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index e5dfd17ded9..8eaf83bba2b 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -7165,6 +7165,8 @@ move_block_to_fn (struct function *dest_cfun, basic_block bb, free_stmt_operands (cfun, stmt); push_cfun (dest_cfun); update_stmt (stmt); + if (is_gimple_call (stmt)) + notice_special_calls (as_a <gcall *> (stmt)); pop_cfun (); }
reply other threads:[~2021-04-20 23:29 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210420232945.4900D3AA7C97@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).