__typeof__ does not work as expected with XLC compiler on AIX 5.2

2016-10-28 Thread TestRealTime .
Hello,

I would like to report about two (probably, self-connected) bugs in the
__typeof__ C function.
These bugs are reproduced when I am trying to compile a simple code with
XLC compiler on AIX 5.2. Please, look at the code snippets below.

1. typeof_example_1.c
long Func(int x) { return x; }
int main()
{
int y, z = 1;
y = (__typeof__(Func(z)))0;
return 0;
}

cc_r typeof_example_1.c
"typeof_example_1.c", line 5.26: 1506-045 (S) Undeclared identifier z.

The 'z' variable is obviously defined, so "Undeclared identifier" message
is wrong.


2. typeof_example_2.c (fails on 64bit compilation only)
long Func(int x) { return x; }
int main()
{
int y, z = 1;
y = (__typeof__(Func((__typeof__(z))z)))0;
return 0;
}

cc_r -q64 typeof_example_2.c
"typeof_example_2.c", line 5.21: 1506-343 (S) Redeclaration of Func differs
from previous declaration on line 1 of "typeof_example_2.c".
"typeof_example_2.c", line 5.21: 1506-050 (I) Return type "int" in
redeclaration is not compatible with the previous return type "long".

Here the compiler erroneously considers the line as a function declaration,
but is is a call and not a declaration. This works although for 32bit
compilation.

Both code snippets work with GCC compiler in both 32-bit and 64bit modes.

What is interesting, we use cc_r, but not xlc binary in our build system
(it is probably due to historical reasons and persons who can answer me why
exactly cc_r have gone many years ago). But with xlc both code snippets
also fail, however with other error messages (no matter, 32 or 64bit).
xlc typeof_example_1.c
"typeof_example_1.c", line 5.30: 1506-275 (S) Unexpected text integer
constant encountered.
xlc typeof_example_2.c
"typeof_example_2.c", line 5.41: 1506-275 (S) Unexpected text z encountered.
"typeof_example_2.c", line 5.45: 1506-275 (S) Unexpected text integer
constant encountered.


Environment:
uname -a
AIX pavo 2 5 00C9E74E4C00
which cc_r
/usr/vac/bin/cc_r
which xlc
/usr/vac/bin/xlc
ls /usr/vac/bin/
CreateExportList  cc128 cc_r4 cleanpdf
xlc128xlc_r4
c89   cc128_r   cc_r7 resetpdf
xlc128_r  xlc_r7
cccc_r  cforaixhelp   xlc
xlc_r


Use case:
These issues were discovered at attempt to build FreeType 2.7.0 with XLC
compiler.
The link to the FreeType issue: http://savannah.nongnu.org/bugs/?49448.
I have contacted FreeType developers and got a feedback that TYPEOF
implementation is taken from gnulib's intprops.h, that is why my question
is addressed to gnu.org mail list.
I do understand that the OS AIX 5.2 is legacy and the best way is to
migrate to a newer one, but we cannot do it right now because customers
request builds for this OS.
I would be happy if you could give some clue why __typeof__ works
completely differently for XLC.

Thanks in advance!
--
Best Regards,
Alexander Samoilov,
Build & Integration Ingenieur,
Compart AG (Böblingen, Germany)


Re: __typeof__ does not work as expected with XLC compiler on AIX 5.2

2016-11-02 Thread TestRealTime .
Hello Paul,

I checked the values of macros you have asked:
__GNUC__, __SUNPRO_C, __STDC__, __xlC_ver__ are all undefined. The rest
ones are defined and the values are same for 32- and 64-bit compilation:

__IBM__TYPEOF__=1
__IBMC__=600
__xlC__=1536


Compiler version is much older than yours:
cc_r -qversion
C for AIX version 6.0.0.0
xlc -qversion
C for AIX version 6.0.0.0

So, __IBM__TYPEOF__ macro is defined and the resulting complex macro from
ftconfig.h is resolved to #define FT_TYPEOF( type )  (__typeof__ (type)),
but __typeof__ itself does not work as I wrote in the original message. I
suppose that if you use xlc 6.0.0.0 you should reproduce the problem as
well.

--
Best Regards,
Alexander.

2016-10-31 16:03 GMT+01:00 Paul Eggert :

> On 10/28/2016 08:13 AM, TestRealTime . wrote:
>
> long Func(int x) { return x; }
>> int main()
>> {
>> int y, z = 1;
>> y = (__typeof__(Func((__typeof__(z))z)))0;
>> return 0;
>> }
>>
>
> I don't observe any problem when compiling with this xlc:
>
> $ xlc -qversion
> IBM XL C/C++ for AIX, V12.1 (5765-J02, 5725-C72)
> Version: 12.01..
>
> gnulib/lib/intprops.h says __typeof__ should work with xlc if the
> __IBM__TYPEOF__ macro is defined. Is that macro defined for you? If not,
> then why is FT_TYPEOF misfiring for you? And if so, what are the values of
> the following macros? You can use the compiler's -E option to determine
> this.
>
> __IBMC__
>
> __xlC__
>
> __xlC_ver__
>
> Also, what does your compiler's manual (for your compiler's version) say
> about this?
>
>


Re: __typeof__ does not work as expected with XLC compiler on AIX 5.2

2016-11-02 Thread TestRealTime .
Hello Florian,

I tried to check your assumption. I prepared a small code snipper which is
compiled successfully. I think, it may be considered as some "evidence".

autobld@pavo:base> cat simple.c
int main()
{
int x = 3;
__typeof__(x) y = 4;
long z;
z = (__typeof__(z)) (x + y);

char * s, * p;
p = (__typeof__(s))malloc(10);
return 0;
}

autobld@pavo:base> cc_r -o simple.o -c simple.c; echo $?
0
autobld@pavo:base> cc_r -o simple.o -q64 -c simple.c; echo $?
0
autobld@pavo:base> cc_r -qversion
C for AIX version 6.0.0.0

So, it looks like compiler understands the usage of __typeof__ in two use
cases: a) as a type cast, b) as a type in the variable declaration.
So far I incline to think that it is a problem of compiler itself, what do
you think?

--
Best Regards,
Alexander.

2016-10-31 10:05 GMT+01:00 Florian Weimer :

> On 10/28/2016 05:13 PM, TestRealTime . wrote:
>
>> Hello,
>>
>> I would like to report about two (probably, self-connected) bugs in the
>> __typeof__ C function.
>> These bugs are reproduced when I am trying to compile a simple code with
>> XLC compiler on AIX 5.2. Please, look at the code snippets below.
>>
>> 1. typeof_example_1.c
>> long Func(int x) { return x; }
>> int main()
>> {
>> int y, z = 1;
>> y = (__typeof__(Func(z)))0;
>> return 0;
>> }
>>
>> cc_r typeof_example_1.c
>> "typeof_example_1.c", line 5.26: 1506-045 (S) Undeclared identifier z.
>>
>> The 'z' variable is obviously defined, so "Undeclared identifier" message
>> is wrong.
>>
>
> Do you have any evidence that the compiler supports __typeof__ at all?
> Maybe the compiler treats __typeof__ as an implicitly declared function.
>
> What is interesting, we use cc_r, but not xlc binary in our build system
>> (it is probably due to historical reasons and persons who can answer me
>> why
>> exactly cc_r have gone many years ago). But with xlc both code snippets
>> also fail, however with other error messages (no matter, 32 or 64bit).
>> xlc typeof_example_1.c
>> "typeof_example_1.c", line 5.30: 1506-275 (S) Unexpected text integer
>> constant encountered.
>> xlc typeof_example_2.c
>> "typeof_example_2.c", line 5.41: 1506-275 (S) Unexpected text z
>> encountered.
>> "typeof_example_2.c", line 5.45: 1506-275 (S) Unexpected text integer
>> constant encountered.
>>
>
> Those syntax errors are consistent with not supporting __typeof__ at all.
> The expression parts which contain __typeof__ are not recognized as types,
> and so the expression is not recognized as a cast.
>
> Florian
>