[PATCH] D60418: inline asm: Don't copy llvm::MemoryBuffers when showing diagnostics

Nico Weber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 8 12:10:12 PDT 2019


thakis created this revision.
thakis added reviewers: rnk, rsmith.

This fixes one TODO and one FIXME in ConvertBackendLocation() about not copying llvm::MemoryBuffers when converting from from llvm::SMDiagnostics to clang::Diagnostics.

The basic idea is to use `SourceManager::createFileID(clang::SourceManager::Unowned, …` to hand the llvm::SMDiagnostic's llvm::MemoryBuffer buffer directly to clang.

This has the implication that the SourceManager now has a reference to a MemoryBuffer that's only alive while LLVM's asm pass runs; in particular the buffer is gone by the time TextDiagnosticBuffer computes the expected line number for the diagnostics it records in -verify mode. To fix this, make TextDiagnosticBuffer do this conversion eagerly when the diagnostic is recorded. This in turn has two implications:

1. It matches how clang emits diagnostics in normal operation, which is a good thing. This e.g. identified a problem where clang's normal diagnostic emission code path works fine but the -verify code path is broken (PR41431).

2. Since HandleComment() for end-of-line comments in preprocessor directives is called _before_ the directive is completely processed, comments at the end of `#line` directives don't see the effect of the `#line` directive yet. Just update tests affected by this by moving the comments down a line and using the `@-1` syntax to refer to the previous line. (This is less weird than it appears at first: `@+1` lines for `#line` directives already don't work which is confusing some people – PR16952. But as you can see, only very few tests use this.) (See the `XXX` comment in the patch for details; I'll remove that comment before landing this.)

This is blocked on fixing PR41431.


https://reviews.llvm.org/D60418

Files:
  clang/include/clang/Frontend/TextDiagnosticBuffer.h
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/Frontend/TextDiagnosticBuffer.cpp
  clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
  clang/lib/Lex/Lexer.cpp
  clang/test/Lexer/gnu-flags.c
  clang/test/Modules/explicit-build-missing-files.cpp
  clang/test/Preprocessor/line-directive.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60418.194187.patch
Type: text/x-patch
Size: 11876 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190408/3a66da6c/attachment-0001.bin>


More information about the cfe-commits mailing list