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-10107] openmp: For default(none) ignore variables created by ubsan_create_data [PR64888] Date: Wed, 11 May 2022 06:22:57 +0000 (GMT) [thread overview] Message-ID: <20220511062257.AC96238515F7@sourceware.org> (raw) https://gcc.gnu.org/g:a76e866211798da138c51abea390bcd605b6da02 commit r9-10107-ga76e866211798da138c51abea390bcd605b6da02 Author: Jakub Jelinek <jakub@redhat.com> Date: Thu Oct 21 10:27:44 2021 +0200 openmp: For default(none) ignore variables created by ubsan_create_data [PR64888] We weren't ignoring the ubsan variables created by c-ubsan.c before gimplification (others are added later). One way to fix this would be to introduce further UBSAN_ internal functions and lower it later (sanopt pass) like other ifns, this patch instead recognizes those magic vars by name/name of type and DECL_ARTIFICIAL and TYPE_ARTIFICIAL. 2021-10-21 Jakub Jelinek <jakub@redhat.com> PR middle-end/64888 gcc/c-family/ * c-omp.c (c_omp_predefined_variable): Return true also for ubsan_create_data created artificial variables. gcc/testsuite/ * c-c++-common/ubsan/pr64888.c: New test. (cherry picked from commit 40dd9d839e52f679d8eabc1c5ca0ca17a5ccfd14) Diff: --- gcc/c-family/c-omp.c | 43 +++++++++++++++++++++++++----- gcc/testsuite/c-c++-common/ubsan/pr64888.c | 27 +++++++++++++++++++ 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/gcc/c-family/c-omp.c b/gcc/c-family/c-omp.c index ebe0b4e8155..d2db5b4b20d 100644 --- a/gcc/c-family/c-omp.c +++ b/gcc/c-family/c-omp.c @@ -2032,13 +2032,44 @@ c_omp_predefined_variable (tree decl) { if (VAR_P (decl) && DECL_ARTIFICIAL (decl) - && TREE_READONLY (decl) && TREE_STATIC (decl) - && DECL_NAME (decl) - && (DECL_NAME (decl) == ridpointers[RID_C99_FUNCTION_NAME] - || DECL_NAME (decl) == ridpointers[RID_FUNCTION_NAME] - || DECL_NAME (decl) == ridpointers[RID_PRETTY_FUNCTION_NAME])) - return true; + && DECL_NAME (decl)) + { + if (TREE_READONLY (decl) + && (DECL_NAME (decl) == ridpointers[RID_C99_FUNCTION_NAME] + || DECL_NAME (decl) == ridpointers[RID_FUNCTION_NAME] + || DECL_NAME (decl) == ridpointers[RID_PRETTY_FUNCTION_NAME])) + return true; + /* For UBSan handle the same also ubsan_create_data created + variables. There is no magic flag for those, but user variables + shouldn't be DECL_ARTIFICIAL or have TYPE_ARTIFICIAL type with + such names. */ + if ((flag_sanitize & (SANITIZE_UNDEFINED + | SANITIZE_UNDEFINED_NONDEFAULT)) != 0 + && DECL_IGNORED_P (decl) + && !TREE_READONLY (decl) + && TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE + && TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE + && TYPE_ARTIFICIAL (TREE_TYPE (decl)) + && TYPE_NAME (TREE_TYPE (decl)) + && TREE_CODE (TYPE_NAME (TREE_TYPE (decl))) == TYPE_DECL + && DECL_NAME (TYPE_NAME (TREE_TYPE (decl))) + && (TREE_CODE (DECL_NAME (TYPE_NAME (TREE_TYPE (decl)))) + == IDENTIFIER_NODE)) + { + tree id1 = DECL_NAME (decl); + tree id2 = DECL_NAME (TYPE_NAME (TREE_TYPE (decl))); + if (IDENTIFIER_LENGTH (id1) >= sizeof ("ubsan_data") - 1 + && IDENTIFIER_LENGTH (id2) >= sizeof ("__ubsan__data") + && !memcmp (IDENTIFIER_POINTER (id2), "__ubsan_", + sizeof ("__ubsan_") - 1) + && !memcmp (IDENTIFIER_POINTER (id2) + IDENTIFIER_LENGTH (id2) + - sizeof ("_data") + 1, "_data", + sizeof ("_data") - 1) + && strstr (IDENTIFIER_POINTER (id1), "ubsan_data")) + return true; + } + } return false; } diff --git a/gcc/testsuite/c-c++-common/ubsan/pr64888.c b/gcc/testsuite/c-c++-common/ubsan/pr64888.c new file mode 100644 index 00000000000..6319c2feced --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/pr64888.c @@ -0,0 +1,27 @@ +/* PR middle-end/64888 */ +/* { dg-do compile { target fopenmp } } */ +/* { dg-options "-fopenmp -fsanitize=undefined" } */ + +int a, b; + +void +foo () +{ + int c; +#pragma omp parallel default (none) shared (a, b) private (c) + { + c = a / b; /* { dg-bogus "not specified in enclosing" } */ + (void) c; + } +#pragma omp task default (none) shared (a, b) private (c) + { + c = a << b; /* { dg-bogus "not specified in enclosing" } */ + (void) c; + } +#pragma omp teams default (none) shared (a, b) + { + int d[a]; /* { dg-bogus "not specified in enclosing" } */ + d[0] = 0; + (void) d[0]; + } +}
reply other threads:[~2022-05-11 6:22 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=20220511062257.AC96238515F7@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).