Clang Static Analyzer: reporting a TypeLoc as error location?


I have some (AST-based) checkers that detect type bugs, i.e. cases where a specific type is incorrect. Unfortunately, I cannot find any way to make the Clang Static Analyzer accept a TypeLoc as the error location, since PathDiagnosticLocation only has overloads for Stmt and Decl. It also has one accepting a SourceLocation, but I want to highlight the entire range. So I’d need either an overload accepting a SourceRange, or two SourceLocations.

Currently I’m just displaying the variable/parameter definition as the error location, which is all right, I guess, but not ideal. Is there any way to achieve the above? The ability to report any SourceRange as error location would be very useful, I believe.



Hi, Gabor. The simplest thing to do here is to add ranges to the BugReport once it's been created. (See the addRange() method.) If you want to put the effort in, we'd probably take a refactoring of PathDiagnosticLocation to include TypeLocs as well.