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());
     }
   }
 


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());
     }
   }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to