Suggest new opcode to help with initialization of aggregate types: Was: sparse-llvm initialization of local vars

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 26 March 2017 at 23:04, Dibyendu Majumdar <mobile@xxxxxxxxxxxxxxx> wrote:
> 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.
>

It may be better to have the linearizer output an explicit instruction
to zero out the aggregate type when an initializer is present. This
might help with the simplification phase as well - for example with
the issue I reported:

http://marc.info/?l=linux-sparse&m=149070715427276&w=2

Thanks and Regards
Dibyendu
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux