Re: How to determine if a struct is packed?

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

 



On Sat, Mar 03, 2018 at 02:27:27PM +0300, Dan Carpenter wrote:
> struct my_type {
>          uint64_t        base;
>          uint8_t         irq;
>          uint8_t         numldrv;
>          uint8_t         pcibus;
>          uint16_t        pcidev;
>          uint8_t         pcifun;
>          uint16_t        pciid;
>          uint16_t        pcivendor;
>          uint8_t         pcislot;
>          uint32_t        uid;
> } __attribute__ ((packed));
> 
> Say I have a pointer to a my_type struct.  When I run my code, I
> expected that the expr->ctype->ctype.alignment would be 1 but it's 8
> because the base struct member is 8 bytes.

Hi,

the method is/should be correct but currently sparse doesn't parse 
type attributes correctly. More exactly, they are dropped from the
type but attached to the declared variable if there is one in the
same declaration.

If you're interested, I've a fix for this in my dev tree:
  git://github.com/lucvoo/sparse-dev.git fix-ignored-type-attributes

This fix is not yet integrated in my main tree because:
1) it triggers a problem with the linearization of bitfields
   in a packed struct (warning 'access past of ...')
2) it needs to be done together with a feature request to
   better handle __bitwise and enums.

Regards,
-- Luc
--
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