[cfe-dev] Diagnostic source location accuracy with and without remarks enabled

Adam Nemet via cfe-dev cfe-dev at lists.llvm.org
Fri Aug 16 21:56:14 PDT 2019



> On Aug 16, 2019, at 8:17 PM, Paul Kirth <paulkirth at google.com> wrote:
> 
> I'm trying to get some insight into why source locations in a warning resolve differently when remarks are enabled in a cc1 invocation. 
> 
> In a diagnostic handler I have two diagnostics being emitted(one warning and one remark), but the accuracy of the source location changes dramatically if I request remarks to be emitted through '-R<remark>'. Note that I don't mean the specific remark I'm emitting, I mean *any* remark.
> 
> More concretely, when I enable the warning and request no remarks, I get a source location that is the beginning of the function. However, if I enable any remarks(such as for the inliner pass), the source location becomes fully accurate for the warning(i.e. pointing to a branch location in the function body).

Requesting remarks implies -gline-tables-only.

Adam

> 
> The invocations only differ in a small way:
> 
> clang -cc1 source.ll -Wmisexpect <... rest of invocation>
> 
> vs.
> 
> clang -cc1 source.ll -Wmisexpect -R<anything> <... rest of invocation> 
> 
> I ran into this when working on some tests in https://reviews.llvm.org/D66324 <https://reviews.llvm.org/D66324>, and I'm having trouble understanding why this is happening. The same source location is passed to both diagnostics. This behavior also doesn't seem to appear if I don't use cc1 directly, but I would still like to understand this behavior.
> 
> Can someone explain why enabling remarks here has an effect on the accuracy of the source locations? Do they cause a delay in the source location resolution, or is there an important piece of infrastructure that the remarks framework enables that I've missed?
> 
> For reference my backend diagnostic handler looks something like the following snippet where the source location is passed to both the warning and remark:
> 
> ```
> void BackendConsumer::MisExpectDiagHandler(
>     const llvm::DiagnosticInfoMisExpect &D) {
>   StringRef Filename;
>   unsigned Line, Column;
>   bool BadDebugInfo = false;
>   FullSourceLoc Loc =
>       getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
> 
>   Diags.Report(Loc, diag::warn_misexpect) << D.getMsg().str();
>   Diags.Report(Loc, diag::remark_misexpect) << D.getMsg().str();
>  
>   // ...
> }
> ```
> 
> 
> -- 
> Paul Kirth

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


More information about the cfe-dev mailing list