All of lore.kernel.org
 help / color / mirror / Atom feed
* sparse-llvm initialization of local vars
@ 2017-03-26 22:04 Dibyendu Majumdar
  0 siblings, 0 replies; only message in thread
From: Dibyendu Majumdar @ 2017-03-26 22:04 UTC (permalink / raw)
  To: Linux-Sparse

Hi,

I noticed that when local variables are initialized, only explicit
initialization instructions are output. But I think C requires that
the whole object be zeroed out as well.

Example code:

extern int printf(const char *s, ...);

struct foo {
long long int i,j;
};

static void dosomething(struct foo *foo)
{
printf("foo->i = %lld, foo->j = %lld\n", foo->i, foo->j);
}

int main(void)
{
struct foo foo = { 1, 2 };
struct foo bar = { 99 };
dosomething(&foo);
dosomething(&bar);
return 0;
}

In this example, sparse-llvm outputs garbage value for bar->j whereas
it should be 0.

To fix this, before any instructions for initialization is run,
sparse-llvm should zero out the whole object using LLVM intrinsic such
as memset. This is implemented in my repository.

Regards
Dibyendu

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-03-26 22:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-26 22:04 sparse-llvm initialization of local vars Dibyendu Majumdar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.