[cfe-dev] GotoStmt::getSourceRange, bug?
Steve Naroff
snaroff at apple.com
Thu Sep 6 09:58:16 PDT 2007
On Sep 6, 2007, at 9:42 AM, Ted Kremenek wrote:
> The question is that do we have enough extent information recorded in
> GotoStmt to accurately recreate the full source range for a goto
> statement?
Not currently. It looks like we need to add a "LabelLoc" to the AST
(this is already passed into the actions, so it's trivial to do).
Make sense?
Thanks for finding this,
snaroff
> I think there is a bug in the current implementation of getSourceRange
> for GotoStmt:
>
>
> class GotoStmt : public Stmt {
> LabelStmt *Label;
> SourceLocation GotoLoc;
> public:
> ...
> virtual SourceRange getSourceRange() const {
> return SourceRange(GotoLoc, Label->getLocEnd());
> }
> ...
> };
>
>
> I believe that getting the end SourceLocation using Label->getLocEnd()
> is incorrect. While the target LabelStmt is referenced by GotoStmt,
> it isn't a substatement in the tree. Consider the following snippet
> of code:
>
> l1: goto l1;
>
> Here, the GotoStmt is a substatement of the LabelStmt for "l1". The
> implementation of getSourceRange() in LabelStmt is as follows (notice
> the call to SubStmt->getLocEnd):
>
>
> class LabelStmt : public Stmt {
> IdentifierInfo *Label;
> Stmt *SubStmt;
> SourceLocation IdentLoc;
> public:
> ...
> virtual SourceRange getSourceRange() const {
> return SourceRange(IdentLoc, SubStmt->getLocEnd());
> }
> ....
> };
>
>
> There is an unbounded recursion here. While LabelStmt is correctly
> calling getLocEnd for its substatement, GotoStmt is incorrectly
> calling getLocEnd for the target LabelStmt.
>
> The question is that do we have enough extent information recorded in
> GotoStmt to accurately recreate the full source range for a goto
> statement?
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list