[cfe-dev] Weak function pointers (was "SymbolRef and SVal confusion")

Jordan Rose jordan_rose at apple.com
Mon Jan 28 18:30:18 PST 2013


On Jan 27, 2013, at 13:40 , Richard <tarka.t.otter at googlemail.com> wrote:

> 
> On 25 Jan 2013, at 18:51, Jordan Rose <jordan_rose at apple.com> wrote:
> 
>> I see what you mean about duplicated checks. Here's an idea: put all the checks in evalCastFromLoc under a special case for casting to bool. Then in evalBinOpLL:
>> 
>> if (rInt->isZeroConstant()) {
>>   if (op == BO_Sub)
>>     return evalCastFromLoc(lhs, resultTy);
>>   if (BinaryOperator::isComparisonOp(op))
>>     return evalBinOpNN(state, op,
>>                        evalCastFromLoc(lhs, getContext().BoolTy),
>>                        makeTruthVal(false, getContext().BoolTy));
>> }
>> 
>> That way you only have the ugly comparison once, and it's in SValBuilder rather than ConstraintManager.
> 
> This is a nice idea, but I don't think it will work. The problem is that evalCastFromLoc will then expect different return values for the same inputs depending on whether it is being called from evalBinOpLL or evalCast. I gave it a quick go, but it caused many tests to fail for varying reasons. 

I'm confused by this. When is a cast of a weak function pointer to bool going to be different from the symbolic value cast to bool? (Or the symbolic value itself, if you type it as 'bool' for now.) And a strong function pointer casted to bool should just be true, always.


> How about the attached diff instead? The function could be named more helpfully, but it does succeed at putting the ugly code in a single place, while changing the architecture as little as possible. 

One thing on the tests -- the analyzer treats (!foo) as (foo != 0), so that's not testing the same thing as (foo).

> 
> Thoughts?
> 
> <weak3.diff>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130128/f6746480/attachment.html>


More information about the cfe-dev mailing list