r273976 - Avoid accessing an invalid PresumedLoc.

Jordan Rose via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 27 18:02:31 PDT 2016

Author: jrose
Date: Mon Jun 27 20:02:31 2016
New Revision: 273976

URL: http://llvm.org/viewvc/llvm-project?rev=273976&view=rev
Avoid accessing an invalid PresumedLoc.

DiagnosticNoteRenderer asserts trying to emit its "while building
module Foo imported from bar.h:5" note when the presumed location
of the import is invalid. This assertion was added in r267914,
where most uses of 'getFilename' were updated to test 'isValid'
instead. This one must have been missed.

I can't come up with a test because this location is always valid
in C-based code, but external clients that manually import modules
(*cough*Swift*cough*) sometimes provide invalid SourceLocations.




Modified: cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp?rev=273976&r1=273975&r2=273976&view=diff
--- cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp (original)
+++ cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp Mon Jun 27 20:02:31 2016
@@ -618,7 +618,7 @@ DiagnosticNoteRenderer::emitBuildingModu
   // Generate a note indicating the include location.
   SmallString<200> MessageStorage;
   llvm::raw_svector_ostream Message(MessageStorage);
-  if (PLoc.getFilename())
+  if (PLoc.isValid())
     Message << "while building module '" << ModuleName << "' imported from "
             << PLoc.getFilename() << ':' << PLoc.getLine() << ":";

More information about the cfe-commits mailing list