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:
- 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).
- 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.
It doesn't show up well in the diff, but there's a call to HandleComment() 13 lines further up that this refers to.