[cfe-dev] Stmt.getEndLoc() vs semicolon

Alexander Lanin via cfe-dev cfe-dev at lists.llvm.org
Tue Feb 25 14:14:52 PST 2020


I’m having trouble with the locations returned by Stmt getEndLoc()/getSourceRange() and am wondering whether this is a bug/flaw:
the returned location sometimes includes and sometimes excludes the semicolon in the end.
This gets even more interesting when there are (multiple) comments before the semicolon, simply because the difference between the returned values gets even bigger.
Here is an example showing how DeclStmt includes the semicolon, while CallExpr and BinaryOperator exclude the semicolon http://ce.steveire.com/z/TW3IAG.

So Stmt behaves “completely differently” depending on it’s type, which is no way suggested by it’s interface.
Wouldn’t it be better for Stmt-Users if it would always be the same?
(Not sure whether it should always be included or excluded. It’s not even always a semicolon as in that 3rd foo() in the example)

Here is one of the effects of this complexity for users of Stmt as they struggle to find that semicolon:
https://bugs.llvm.org/show_bug.cgi?id=25970 / https://reviews.llvm.org/D16267
Of course it’s fixable there, but that would imply working around the issue in multiple places.

Alexander Lanin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200225/5551a1ae/attachment.html>

More information about the cfe-dev mailing list