[cfe-dev] Try-Throw-Catch handling in CFG

Jim Goodnow II Jim at TheGoodnows.net
Wed Nov 30 21:13:22 PST 2011


On 11/30/2011 5:24 PM, Ted Kremenek wrote:
> On Nov 30, 2011, at 2:52 PM, Jim Goodnow II wrote:
>
>> So, if I have a simple program like:
>>
>> void foo()
>> {
>>    try { throw( 5 ); }
>>    catch( int x ) {}
>>    catch( ... ) {}
>> }
>>
>> This generates a CFG that looks like: (Excuse the ASCII graphics .)
>>
>>        throw
>>             |
>>             v
>>            try
>>   |                    |
>>   v                    v
>> catch(int)     catch(...)
>>
>> where these are each blocks. How does the try block know the type of the
>> throw argument? Should that be stored in the state on exit from the
>> throw block or is there a better mechanism for passing that information?
> Hi Jim,
>
> I'm not certain I understand your question.  What are you trying to accomplish?  The CFG certainly doesn't retain any type information; that's up to the AST.  If you are talking about the static analyzer, it's up to the static analyzer's value flow analysis to track the thrown value, including its type, so that the path analysis matches with the right 'catch' block.
>
> Ted
>
Hi Ted,

Yes, that's exactly what I was asking about. So, the value and type of 
the thrown value has to be passed from the throw block to the try block 
which must in turn pass it to the appropriate catch handler block where 
it's value is bound to the argument of the catch. I guess the question 
here is how is the value 'thrown' designated in the state such that the 
'try' block is able to reference it? i.e., there is no declaration of 
the value that the try block can reference to look up the value, so how 
is it designated? Or, is there something I'm missing for tracking that 
value/type? I am assuming that I have to implement something, but wanted 
to check before I started.

  - jim




More information about the cfe-dev mailing list