On Wed, 22 Aug 2018, Bernd Edlinger wrote:

> On 08/21/18 10:59, Richard Biener wrote:
> > On Tue, 21 Aug 2018, Bernd Edlinger wrote:
> > 
> >> gcc -S -O2 -Wall -Wformat-overflow -ftrack-macro-expansion=0 -fshort-wchar 
> >> builtin-sprintf-warn-20.c
> >> builtin-sprintf-warn-20.c: In function 'test':
> >> builtin-sprintf-warn-20.c:19:39: warning: hex escape sequence out of range
> >> 19 |     ? (char*)L"\x4142\x4344" : (char*)L"\x41424344\x45464748";
> >>      |                                       ^~~~~~~~~~~~~~~~~~~~~~~
> >>
> >> Hmm, this test might create some noise on short-wchar targets.
> >>
> >> I would prefer a warning here, about the wrong type of the parameter.
> >> The buffer overflow is only a secondary thing.
> >>
> >> For constant objects like those, the GIMPLE type is still guaranteed to be 
> >> reliable,
> >> right?
> > 
> > TREE_TYPE of tcc_declaration and tcc_constant trees should more-or-less
> > (minus qualifications not affecting semantics) be those set by
> > frontends.
> > 
> 
> and in this case:
> 
> const union
> { struct {
>      wchar_t x[4];
>    };
>    struct {
>      char z[8];
>    };
> } u = {{L"123"}};
> 
> int test()
> {
>    return __builtin_strlen(u.z);
> }
> 
> 
> string_constant works out the initializer for u.x
> which has a different type than u.z

Yes.  That's because it uses ctor-for-folding and friends.  It's
a question of the desired semantics of string_constant whether
it should better return NULL_TREE in this case or whether the
caller has to deal with type mismatches.

Richard.

Reply via email to