This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: nano printf + powerpc gcc


Hi,

I looked a bit further into this and I can't reproduce this behavior for
the i386 backend. So I had a look through GCC's parser implementation
for _Generic and it seems GCC evaluates the expressions in each matching
case, that is to say it will also parse the default case. In arm, the
type of va_list is a struct, since it is invalid to cast structs to
pointers, the c-parser will error out when it parses this cast in the
default case. For an i386 gcc, and I'm guessing your case is the same,
the type of va_list can be cast to a pointer type, so it parses it
without errors.

I don't know if parsing the expression of default if another case has
matched is intended behavior. I will investigate this further and if I
can convince myself this is wrong behavior I'll chase it with upstream gcc.

On the other hand, I believe we can leave out the cast here, since the
prototype for the function taking this as a parameter should be
explicitly trying to cast it if that gets picked anyway no?

I tried it with a pet example and it compiles if I leave out the cast
for the 'default' case on all three implementations of va_ptr.


Cheers,
Andre

On 23/01/18 14:04, Andre Vieira (lists) wrote:
> Hi Alexander,
> 
> This patch is causing our arm-none-eabi-gcc newlib-nano builds to fail.
> 
> It seems the _Generic isn't picking up the right type when ap is of type
> va_list. We get the following error:
> newlib/libc/stdio/nano-vfscanf.c:430:2: error: cannot convert to a
> pointer type
> ret = _scanf_chars (rptr, &scan_data, fp, va_ptr(ap));
> ^~~
> newlib/libc/stdio/nano-vfscanf.c:432:2: error: cannot convert to a
> pointer type
> ret = _scanf_i (rptr, &scan_data, fp, va_ptr(ap));
> ^~~
> newlib/libc/stdio/nano-vfscanf.c:435:2: error: cannot convert to a
> pointer type
> ret = _scanf_float (rptr, &scan_data, fp, va_ptr(ap));
> 
> 
> A reduced test-case, see:
> 
> #include <stdio.h>
> extern void bar(va_list *ap);
> void foo(va_list ap) {
>     bar(_Generic(&(ap), va_list *: &(ap), default: (va_list *)(ap)));
> }
> 
> Note that va_list for our toolchain is defined as gcc's __builtin_va_list.
> 
> I have tried your other definitions of va_ptr too and none of them seem
> to work. How do you suggest we proceed?
> 
> Cheers,
> Andre
> 
> 
> 
> On 08/01/18 10:07, Corinna Vinschen wrote:
>> On Dec 25 16:39, Alexander Fedotov wrote:
>>> Hi
>>>
>>> I'm experienced a strange printf() for float variables behaviour with
>>> Nano version while regular is fine. It just prins out a garbage (even
>>> with enabled -u _printf_float). After some digging I've managed to
>>> track down issue until this line:
>>>
>>> n = _printf_float (data, &prt_data, fp, pfunc, &ap);
>>>
>>>
>>> Moreover there are number of warnings also in build log:
>>>
>>> src_newlib/newlib/libc/stdio/nano-vfprintf.c -o lib_a-nano-svfprintf.o
>>> ../../../../../../src_newlib/newlib/libc/stdio/nano-vfprintf.c: In
>>> function '_svfprintf_r':
>>> ../../../../../../src_newlib/newlib/libc/stdio/nano-vfprintf.c:645:55:
>>> warning: passing argument 5 of '_printf_float' from incompatible
>>> pointer type
>>>         n = _printf_float (data, &prt_data, fp, pfunc, &ap);
>>>                                                                        ^
>>> In file included from
>>> ../../../../../../src_newlib/newlib/libc/stdio/nano-vfprintf.c:169:0:
>>> ../../../../../../src_newlib/newlib/libc/stdio/nano-vfprintf_local.h:228:1:
>>> note: expected 'struct __va_list_tag (*)[1]' but argument is of type
>>> 'struct __va_list_tag **'
>>>  _printf_float (struct _reent *data,
>>>  ^
>>> ../../../../../../src_newlib/newlib/libc/stdio/nano-vfprintf.c:650:45:
>>> warning: passing argument 5 of '_printf_i' from incompatible pointer
>>> type
>>>   n = _printf_i (data, &prt_data, fp, pfunc, &ap);
>>>                                                             ^
>>> In file included from
>>> ../../../../../../src_newlib/newlib/libc/stdio/nano-vfprintf.c:169:0:
>>> ../../../../../../src_newlib/newlib/libc/stdio/nano-vfprintf_local.h:221:1:
>>> note: expected 'struct __va_list_tag (*)[1]' but argument is of type
>>> 'struct __va_list_tag **'
>>>  _printf_i (struct _reent *data, struct _prt_data_t *pdata, FILE *fp,
>>>
>>>
>>> It looks like nano written without taking in mind such targets. Here I
>>> found workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14557
>>> that's working.
>>>
>>> I'm attaching a patch.
>>>
>>> Alex
>>
>> Pushed.
>>
>>
>> Thanks,
>> Corinna
>>
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]