Re: [DRAFT] add support for GCC's __auto_type

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

 



On Wed, Dec 04, 2019 at 05:28:04PM +0000, Ramsay Jones wrote:
> On 04/12/2019 03:06, Luc Van Oostenryck wrote:
> > +/*
> > + * check-name: autotype-ko
> > + * check-command: sparse -Wno-decl $file
> > + * checz-known-to-fail
> 
> s/checz-/check-/

Hehe, that was my extra-lazy way of temporarily disabling
the tag by changing a single character ...
 
> > +
> > +extern char ch;
> > +extern const int ci;
> > +
> > +__auto_type i = 0;		is_type(i, int);
> > +__auto_type m = 1UL;		is_type(m, unsigned long);
> > +__auto_type p = &i;		is_type(p, int *);
> > +__auto_type f = 0.0;		is_type(f, double);
> > +__auto_type s = (struct s){0};	is_type(s, struct s);
> > +__auto_type c = ch;		is_type(c, char);
> > +__auto_type ct = ci;		is_type(ct, int);
> 
> Hmm, this loses the 'const', ...
> 
> > +__auto_type pci = &ci;		is_type(pci, const int *);
> 
> ... but this doesn't?
> 
> Unfortunately, the gcc documentation that I have doesn't give a
> sufficiently detailed specification for me to tell if this is
> expected.

Yes, there is definitively a problem here.
In fact, I think it does the right thing because:
	extern const int ci;
	
	static void foo(void)
	{
		__auto_type ct = ci;
		ct++;
	}

rightfully complains we're trying to modify a const variable.
OTOH, the sparse-specifc type compare in the assert seems to ignore
the qualifiers at the first level. I suppose it's purposely so but ...

Another problem, maybe more important, is that the lines:
	__auto_type c = ch;
	__auto_type ct = ci;

at top-level are invalid because ch & ci are not constant
values/expressions and no warnings are issued.
It's orthogonal to __auto_type but quite annoying.

Thanks for noticing all this!
-- Luc



[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