linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] Fix crash in linearize_compound_statement()
@ 2008-04-07 20:45 Pavel Roskin
  2008-04-07 21:55 ` Christopher Li
  0 siblings, 1 reply; 4+ messages in thread
From: Pavel Roskin @ 2008-04-07 20:45 UTC (permalink / raw)
  To: linux-sparse

Hello!

The current sparse crashes on this program:


static int x;
static inline void foo(void)
{
    if (x)
	x = 1;
}
static void bar(void)
{
    foo();
}
static typeof(bar) quux;


The crash happens in linearize_compound_statement(), and I believe that
the reason is incorrect access to phi_node->phi_list without making sure
that phi_node->opcode is OP_PHI.  When processing the above program,
phi_node->phi_list can be OP_INLINED_CALL.

I understand very little in sparse code, and I have no idea what kind of
fallback is needed when phi_node->opcode is not OP_PHI.

But this patch fixes the crash:


diff --git a/linearize.c b/linearize.c
index 8a68f05..ff4f3b6 100644
--- a/linearize.c
+++ b/linearize.c
@@ -1633,7 +1633,7 @@ static pseudo_t linearize_compound_statement(struct entrypoint *ep, struct state
 		struct basic_block *bb = add_label(ep, ret);
 		struct instruction *phi_node = first_instruction(bb->insns);
 
-		if (!phi_node)
+		if (!phi_node || phi_node->opcode != OP_PHI)
 			return pseudo;
 
 		if (pseudo_list_size(phi_node->phi_list)==1) {


-- 
Regards,
Pavel Roskin

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-04-08  6:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-07 20:45 [RFC PATCH] Fix crash in linearize_compound_statement() Pavel Roskin
2008-04-07 21:55 ` Christopher Li
2008-04-08  5:14   ` Pavel Roskin
2008-04-08  6:05     ` Christopher Li

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 NNTP newsgroup(s).