c char translated to i8 signext

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

c char translated to i8 signext

Ryan M. Lefever
I have a c function that takes a char as a parameter.  When it is
compiled to bytecode, it gets translated to i8 signext.  Why is signext
getting added to the type?  It doesn't get added if the parameter is an
int.  Is there a way to alter the parameter in the c code so that it
simply gets translated to an i8, or is there a way in LLVM to modify the
parameter's type?

By the way, I am using LLVM 2.1 in case this has been changed since then.

Regards,
Ryan
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: c char translated to i8 signext

Jonathan S. Shapiro-2
Ryan:

Not sure if this helps, but...

In the absence of an explicit signed/unsigned qualifier, the ANSI C
standard states that the signedness of char is implementation defined.

In the absence of a prototype, the compiler is obliged to pass that char
as a word, which (if char is signed) requires sign extend.

In the presence of a prototype, the sign extend is probably not strictly
required, but doing it regardless is a partial defense against certain
classes of common programming errors (not sure if this is what is going
on here).

So: if you don't have a prototype visible at the call site, add one and
see what happens.


shap


On Wed, 2008-04-30 at 12:55 -0500, Ryan M. Lefever wrote:

> I have a c function that takes a char as a parameter.  When it is
> compiled to bytecode, it gets translated to i8 signext.  Why is signext
> getting added to the type?  It doesn't get added if the parameter is an
> int.  Is there a way to alter the parameter in the c code so that it
> simply gets translated to an i8, or is there a way in LLVM to modify the
> parameter's type?
>
> By the way, I am using LLVM 2.1 in case this has been changed since then.
>
> Regards,
> Ryan
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: c char translated to i8 signext

Chris Lattner
In reply to this post by Ryan M. Lefever
On Wed, 30 Apr 2008, Ryan M. Lefever wrote:
> I have a c function that takes a char as a parameter.  When it is
> compiled to bytecode, it gets translated to i8 signext.  Why is signext
> getting added to the type?  It doesn't get added if the parameter is an
> int.  Is there a way to alter the parameter in the c code so that it
> simply gets translated to an i8, or is there a way in LLVM to modify the
> parameter's type?

This is an ABI requirement for your target.  You can remove it from the
llvm ir by removing the parameter attribute from the function and calls to
it.

-Chris

--
http://nondot.org/sabre/
http://llvm.org/
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: c char translated to i8 signext

Ryan M. Lefever
Thanks for your response.  When I attempt to get the parameter attribute
lists for the function and its call sites, the list is NULL.  Is there
someone else I should be looking to get the parameter attributes?

Chris Lattner wrote:

> On Wed, 30 Apr 2008, Ryan M. Lefever wrote:
>> I have a c function that takes a char as a parameter.  When it is
>> compiled to bytecode, it gets translated to i8 signext.  Why is signext
>> getting added to the type?  It doesn't get added if the parameter is an
>> int.  Is there a way to alter the parameter in the c code so that it
>> simply gets translated to an i8, or is there a way in LLVM to modify the
>> parameter's type?
>
> This is an ABI requirement for your target.  You can remove it from the
> llvm ir by removing the parameter attribute from the function and calls to
> it.
>
> -Chris
>
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: c char translated to i8 signext

Ryan M. Lefever
It appears that the only thing that has parameter attributes is the
function type.  However, you can't simply change a function's type
without reconstructing the whole function, can you?  Also, am I correct
that it would not be safe to remove the parameter attribute's from a
FunctionType?

Ryan M. Lefever wrote:

> Thanks for your response.  When I attempt to get the parameter attribute
> lists for the function and its call sites, the list is NULL.  Is there
> someone else I should be looking to get the parameter attributes?
>
> Chris Lattner wrote:
>> On Wed, 30 Apr 2008, Ryan M. Lefever wrote:
>>> I have a c function that takes a char as a parameter.  When it is
>>> compiled to bytecode, it gets translated to i8 signext.  Why is signext
>>> getting added to the type?  It doesn't get added if the parameter is an
>>> int.  Is there a way to alter the parameter in the c code so that it
>>> simply gets translated to an i8, or is there a way in LLVM to modify the
>>> parameter's type?
>> This is an ABI requirement for your target.  You can remove it from the
>> llvm ir by removing the parameter attribute from the function and calls to
>> it.
>>
>> -Chris
>>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: c char translated to i8 signext

Chris Lattner
On Wed, 30 Apr 2008, Ryan M. Lefever wrote:
> It appears that the only thing that has parameter attributes is the
> function type.  However, you can't simply change a function's type
> without reconstructing the whole function, can you?  Also, am I correct
> that it would not be safe to remove the parameter attribute's from a
> FunctionType?

Update to llvm 2.2 or mainline, there the attributes are on the function
and call for precisely that reason.

-Chris


> Ryan M. Lefever wrote:
>> Thanks for your response.  When I attempt to get the parameter attribute
>> lists for the function and its call sites, the list is NULL.  Is there
>> someone else I should be looking to get the parameter attributes?
>>
>> Chris Lattner wrote:
>>> On Wed, 30 Apr 2008, Ryan M. Lefever wrote:
>>>> I have a c function that takes a char as a parameter.  When it is
>>>> compiled to bytecode, it gets translated to i8 signext.  Why is signext
>>>> getting added to the type?  It doesn't get added if the parameter is an
>>>> int.  Is there a way to alter the parameter in the c code so that it
>>>> simply gets translated to an i8, or is there a way in LLVM to modify the
>>>> parameter's type?
>>> This is an ABI requirement for your target.  You can remove it from the
>>> llvm ir by removing the parameter attribute from the function and calls to
>>> it.
>>>
>>> -Chris
>>>
>> _______________________________________________
>> LLVM Developers mailing list
>> [hidden email]         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>

-Chris

--
http://nondot.org/sabre/
http://llvm.org/
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev