[cfe-dev] Adding more info to builtin source types.

Enea Zaffanella zaffanella at cs.unipr.it
Mon Jan 18 13:39:18 CST 2010


Douglas Gregor wrote:
> Hello Enea,

[...]

> Okay, great. I committed your patch here:
> 
>     http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20100118/026437.html 
> 
> 
> with a couple of tweaks:

[...]

> +  bool needsExtraLocalData() const {
> +    BuiltinType::Kind bk = getTypePtr()->getKind();
> +    return (bk >= BuiltinType::UShort && bk <= BuiltinType::UInt128)
> +      || (bk >= BuiltinType::Short && bk <= BuiltinType::LongDouble)
> +      || bk == BuiltinType::UChar
> +      || bk == BuiltinType::SChar;
> +  }
> 
> "float", "double", and "long double" don't need any extra data, since 
> we'll always have a location for the type specifier (float or double) 
> and the type is never implied by either a sign or a width.

Actually, the use of 'mode' attributes can change the width of floating 
point types, hence the need to store, even in this case, the written 
type specifier, the written width specifier and a Boolean flag for the 
presence of any 'mode' attribute.

As an example, 'float' is translated by 'XF' to 'long double':

$ cat a.c
float f __attribute__((mode(XF)));

$ clang -cc1 -ast-dump a.c
typedef __int128_t __int128_t;
typedef __uint128_t __uint128_t;
struct __va_list_tag {
     unsigned int gp_offset;
     unsigned int fp_offset;
     void *overflow_arg_area;
     void *reg_save_area;
};
typedef struct __va_list_tag __va_list_tag;
typedef __va_list_tag __builtin_va_list[1];
long double f;



You are right that, in this case, a sign specifier is not really needed 
... but this anyway incurs no additional space overhead.

All the other changes to my patch are plainly right.

Cheers,
Enea Zaffanella.



More information about the cfe-dev mailing list