public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-6420] analyzer: fix uninit false +ves reading from DECL_HARD_REGISTER [PR108968] Date: Thu, 2 Mar 2023 19:02:30 +0000 (GMT) [thread overview] Message-ID: <20230302190230.1242F3858D33@sourceware.org> (raw) https://gcc.gnu.org/g:20bd258d0fa09837b3a93478ef92d8789cbcd442 commit r13-6420-g20bd258d0fa09837b3a93478ef92d8789cbcd442 Author: David Malcolm <dmalcolm@redhat.com> Date: Thu Mar 2 14:01:19 2023 -0500 analyzer: fix uninit false +ves reading from DECL_HARD_REGISTER [PR108968] gcc/analyzer/ChangeLog: PR analyzer/108968 * region-model.cc (region_model::get_rvalue_1): Handle VAR_DECLs with a DECL_HARD_REGISTER by returning UNKNOWN. gcc/testsuite/ChangeLog: PR analyzer/108968 * gcc.dg/analyzer/uninit-pr108968-register.c: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com> Diff: --- gcc/analyzer/region-model.cc | 9 ++++++++- gcc/testsuite/gcc.dg/analyzer/uninit-pr108968-register.c | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index 2187aecbe91..bf07cec2884 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -2203,9 +2203,16 @@ region_model::get_rvalue_1 (path_var pv, region_model_context *ctxt) const return get_rvalue_for_bits (TREE_TYPE (expr), reg, bits, ctxt); } - case SSA_NAME: case VAR_DECL: + if (DECL_HARD_REGISTER (pv.m_tree)) + { + /* If it has a hard register, it doesn't have a memory region + and can't be referred to as an lvalue. */ + return m_mgr->get_or_create_unknown_svalue (TREE_TYPE (pv.m_tree)); + } + /* Fall through. */ case PARM_DECL: + case SSA_NAME: case RESULT_DECL: case ARRAY_REF: { diff --git a/gcc/testsuite/gcc.dg/analyzer/uninit-pr108968-register.c b/gcc/testsuite/gcc.dg/analyzer/uninit-pr108968-register.c new file mode 100644 index 00000000000..a76c09e7b14 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/uninit-pr108968-register.c @@ -0,0 +1,9 @@ +/* { dg-do compile { target x86_64-*-* } } */ + +#define STACK_SIZE 4096 +struct cpu_info {}; +struct cpu_info *get_cpu_info(void) +{ + register unsigned long sp asm("rsp"); + return (struct cpu_info *)((sp | (STACK_SIZE - 1)) + 1) - 1; /* { dg-bogus "use of uninitialized value 'sp'" } */ +}
reply other threads:[~2023-03-02 19:02 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=20230302190230.1242F3858D33@sourceware.org \ --to=dmalcolm@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).