[PATCH] D90192: WIP: Speculative fix for ASTImporter crash with SLocEntry changes

Duncan P. N. Exon Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 26 14:20:21 PDT 2020


dexonsmith created this revision.
dexonsmith added a reviewer: teemperor.
Herald added subscribers: ributzka, martong.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
dexonsmith requested review of this revision.

This is a speculative fix for the ASTImporter crash in https://reviews.llvm.org/D89749; I will clean this up and commit if it's the right direction.


https://reviews.llvm.org/D90192

Files:
  clang/lib/AST/ASTImporter.cpp


Index: clang/lib/AST/ASTImporter.cpp
===================================================================
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -8634,7 +8634,7 @@
   // Map the FromID to the "to" source manager.
   FileID ToID;
   if (FromSLoc.isExpansion()) {
-    const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
+    SrcMgr::ExpansionInfo FromEx = FromSLoc.getExpansion();
     ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
     if (!ToSpLoc)
       return ToSpLoc.takeError();
@@ -8654,11 +8654,12 @@
     }
     ToID = ToSM.getFileID(MLoc);
   } else {
-    const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
+    SrcMgr::FileInfo FromFI = FromSLoc.getFile();
+    const SrcMgr::ContentCache *Cache = &FromFI.getContentCache();
 
     if (!IsBuiltin && !Cache->BufferOverridden) {
       // Include location of this file.
-      ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
+      ExpectedSLoc ToIncludeLoc = Import(FromFI.getIncludeLoc());
       if (!ToIncludeLoc)
         return ToIncludeLoc.takeError();
 
@@ -8683,7 +8684,7 @@
         // the memory buffer below.
         if (Entry)
           ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
-                                   FromSLoc.getFile().getFileCharacteristic());
+                                   FromFI.getFileCharacteristic());
       }
     }
 
@@ -8698,8 +8699,8 @@
       std::unique_ptr<llvm::MemoryBuffer> ToBuf =
           llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
                                                FromBuf->getBufferIdentifier());
-      ToID = ToSM.createFileID(std::move(ToBuf),
-                               FromSLoc.getFile().getFileCharacteristic());
+      ToID =
+          ToSM.createFileID(std::move(ToBuf), FromFI.getFileCharacteristic());
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90192.300788.patch
Type: text/x-patch
Size: 1896 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201026/349d20a9/attachment.bin>


More information about the cfe-commits mailing list