[LLVMdev] finding implicit casts
sabre at nondot.org
Wed Apr 26 01:13:24 CDT 2006
On Tue, 25 Apr 2006, John Trimble wrote:
> Err.. Your right. What about just finding casts in general.
Two separate issues: cast instructions and cast constant expressions.
You can find cast instructions by looping through all the instructions,
and using "isa<CastInst>(I)". To find cast constant expressions, you'd
use basically what you describe below: loop through globals and
instructions, checking the operands to see if they are constant expression
> On 4/25/06, Chris Lattner <sabre at nondot.org> wrote:
>> On Tue, 25 Apr 2006, John Trimble wrote:
>>> I'm trying to find all the implicit casts in a program compiled with
>> I'm not sure exactly what you're trying to do here. In particular,
>> llvm-gcc will turn any casts that are implicit in the C code into explicit
>> casts in the LLVM... which means that there is no good way to tell the
>> difference between an implicit or explicit cast.
>>> What I've been doing is for each function taking all the
>>> instruction and going through each of their operands (and the opreands
>>> their operands etc...) and checking to see if any are an instance of
>>> UnaryConstantExpr. When I encounter such an instance, I determine
>>> the type of that value and its 0th operand differ, if they do its an
>>> implicit cast. I do basically the same procedure for the the global
>>> variables. Is this the best approach to take or is there a better way of
>>> going about this?
>> I'm not sure I follow here. It sounds like you are detecting things like:
>> short A = ...
>> int B = ...
>> int C = (int)A + B;
>> However, there isn't a way to tell if the "(int)" was implicit or
>>> I've asked at least a few questions on this mailing-list and you haveall
>>> been VERY helpful. Thank you all so much.
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> John Trimble
> Research Assistant
> University of Arizona
More information about the LLVMdev