Clang warning for invalid casting!

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Clang warning for invalid casting!

Sumner, Brian via cfe-dev
I am trying to compile a simple code (see below) with gcc and clang. the gcc generates a warning indicating an incomparable casting (great!). However, clang didn't generate any warnings! I have passed the same arguments for both:

cc -Wall -Wextra tmp3.c
gcc -Wall -Wextra tmp3.c


Should I expect clang to generate error or not? If yes, is there an additional option needs to be passed to clang compiler to generate a warning for something that is obviously wrong? 

Code:
int main(void)
{
   void *b = (void *)0x12345678;
   int   a = (int)(unsigned long)b;
   int   c = (int)b;
   return a + c;
}

Clang version 3.8



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clang warning for invalid casting!

Sumner, Brian via cfe-dev
Clang 3.8 gives an error as expected, so the problem is probably in
your setup. See https://godbolt.org/g/Uf6XyX

- Raphael

2017-07-27 4:05 GMT+02:00 David John via cfe-dev <[hidden email]>:

> I am trying to compile a simple code (see below) with gcc and clang. the gcc
> generates a warning indicating an incomparable casting (great!). However,
> clang didn't generate any warnings! I have passed the same arguments for
> both:
>
> cc -Wall -Wextra tmp3.c
> gcc -Wall -Wextra tmp3.c
>
> Should I expect clang to generate error or not? If yes, is there an
> additional option needs to be passed to clang compiler to generate a warning
> for something that is obviously wrong?
>
> Code:
>
> int main(void)
> {
>    void *b = (void *)0x12345678;
>    int   a = (int)(unsigned long)b;
>    int   c = (int)b;
>    return a + c;
> }
>
>
> Clang version 3.8
>
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clang warning for invalid casting!

Sumner, Brian via cfe-dev
On Thu, Jul 27, 2017 at 1:03 PM, Raphael Isemann via cfe-dev
<[hidden email]> wrote:
> Clang 3.8 gives an error as expected, so the problem is probably in
> your setup. See https://godbolt.org/g/Uf6XyX
To add to that, it only warns if -m64 is specified, and does not warn
if -m32 is specified. Similarly, here on 64-bit machine, it does not warn.

> - Raphael
Roman.

> 2017-07-27 4:05 GMT+02:00 David John via cfe-dev <[hidden email]>:
>> I am trying to compile a simple code (see below) with gcc and clang. the gcc
>> generates a warning indicating an incomparable casting (great!). However,
>> clang didn't generate any warnings! I have passed the same arguments for
>> both:
>>
>> cc -Wall -Wextra tmp3.c
>> gcc -Wall -Wextra tmp3.c
>>
>> Should I expect clang to generate error or not? If yes, is there an
>> additional option needs to be passed to clang compiler to generate a warning
>> for something that is obviously wrong?
>>
>> Code:
>>
>> int main(void)
>> {
>>    void *b = (void *)0x12345678;
>>    int   a = (int)(unsigned long)b;
>>    int   c = (int)b;
>>    return a + c;
>> }
>>
>>
>> Clang version 3.8
>>
>>
>>
>> _______________________________________________
>> cfe-dev mailing list
>> [hidden email]
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clang warning for invalid casting!

Sumner, Brian via cfe-dev
On Thu, Jul 27, 2017 at 1:42 PM, Roman Lebedev <[hidden email]> wrote:
> On Thu, Jul 27, 2017 at 1:03 PM, Raphael Isemann via cfe-dev
> <[hidden email]> wrote:
>> Clang 3.8 gives an error as expected, so the problem is probably in
>> your setup. See https://godbolt.org/g/Uf6XyX
> To add to that, it only warns if -m64 is specified, and does not warn
> if -m32 is specified. Similarly, here on 64-bit machine, it does not warn.
Edit: also, the original author asked about C, and not C++.
And if -x c is specified, there is no warning no matter the -m32/-m64

>> - Raphael
> Roman.

>> 2017-07-27 4:05 GMT+02:00 David John via cfe-dev <[hidden email]>:
>>> I am trying to compile a simple code (see below) with gcc and clang. the gcc
>>> generates a warning indicating an incomparable casting (great!). However,
>>> clang didn't generate any warnings! I have passed the same arguments for
>>> both:
>>>
>>> cc -Wall -Wextra tmp3.c
>>> gcc -Wall -Wextra tmp3.c
>>>
>>> Should I expect clang to generate error or not? If yes, is there an
>>> additional option needs to be passed to clang compiler to generate a warning
>>> for something that is obviously wrong?
>>>
>>> Code:
>>>
>>> int main(void)
>>> {
>>>    void *b = (void *)0x12345678;
>>>    int   a = (int)(unsigned long)b;
>>>    int   c = (int)b;
>>>    return a + c;
>>> }
>>>
>>>
>>> Clang version 3.8
>>>
>>>
>>>
>>> _______________________________________________
>>> cfe-dev mailing list
>>> [hidden email]
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>>
>> _______________________________________________
>> cfe-dev mailing list
>> [hidden email]
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clang warning for invalid casting!

Sumner, Brian via cfe-dev
Oh true, I stand corrected.

- Raphael

2017-07-27 12:44 GMT+02:00 Roman Lebedev <[hidden email]>:

> On Thu, Jul 27, 2017 at 1:42 PM, Roman Lebedev <[hidden email]> wrote:
>> On Thu, Jul 27, 2017 at 1:03 PM, Raphael Isemann via cfe-dev
>> <[hidden email]> wrote:
>>> Clang 3.8 gives an error as expected, so the problem is probably in
>>> your setup. See https://godbolt.org/g/Uf6XyX
>> To add to that, it only warns if -m64 is specified, and does not warn
>> if -m32 is specified. Similarly, here on 64-bit machine, it does not warn.
> Edit: also, the original author asked about C, and not C++.
> And if -x c is specified, there is no warning no matter the -m32/-m64
>
>>> - Raphael
>> Roman.
>
>>> 2017-07-27 4:05 GMT+02:00 David John via cfe-dev <[hidden email]>:
>>>> I am trying to compile a simple code (see below) with gcc and clang. the gcc
>>>> generates a warning indicating an incomparable casting (great!). However,
>>>> clang didn't generate any warnings! I have passed the same arguments for
>>>> both:
>>>>
>>>> cc -Wall -Wextra tmp3.c
>>>> gcc -Wall -Wextra tmp3.c
>>>>
>>>> Should I expect clang to generate error or not? If yes, is there an
>>>> additional option needs to be passed to clang compiler to generate a warning
>>>> for something that is obviously wrong?
>>>>
>>>> Code:
>>>>
>>>> int main(void)
>>>> {
>>>>    void *b = (void *)0x12345678;
>>>>    int   a = (int)(unsigned long)b;
>>>>    int   c = (int)b;
>>>>    return a + c;
>>>> }
>>>>
>>>>
>>>> Clang version 3.8
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> cfe-dev mailing list
>>>> [hidden email]
>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>>>
>>> _______________________________________________
>>> cfe-dev mailing list
>>> [hidden email]
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clang warning for invalid casting!

Sumner, Brian via cfe-dev
In reply to this post by Sumner, Brian via cfe-dev
So is there an answer for this inquiry or not?

Thank you!


On Wed, Jul 26, 2017 at 10:05 PM David John <[hidden email]> wrote:
I am trying to compile a simple code (see below) with gcc and clang. the gcc generates a warning indicating an incomparable casting (great!). However, clang didn't generate any warnings! I have passed the same arguments for both:

cc -Wall -Wextra tmp3.c
gcc -Wall -Wextra tmp3.c


Should I expect clang to generate error or not? If yes, is there an additional option needs to be passed to clang compiler to generate a warning for something that is obviously wrong? 

Code:
int main(void)
{
   void *b = (void *)0x12345678;
   int   a = (int)(unsigned long)b;
   int   c = (int)b;
   return a + c;
}

Clang version 3.8



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...