Skip to content

Commit

Permalink
analyzer: fix uninit false +ves reading from DECL_HARD_REGISTER [PR10…
Browse files Browse the repository at this point in the history
…8968]

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 <[email protected]>
  • Loading branch information
davidmalcolm committed Mar 2, 2023
1 parent 4d82022 commit 20bd258
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion gcc/analyzer/region-model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
{
Expand Down
9 changes: 9 additions & 0 deletions gcc/testsuite/gcc.dg/analyzer/uninit-pr108968-register.c
Original file line number Diff line number Diff line change
@@ -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'" } */
}

0 comments on commit 20bd258

Please sign in to comment.