[cfe-commits] r165592 - in /cfe/trunk: include/clang/Frontend/ASTUnit.h include/clang/Serialization/ASTReader.h lib/Frontend/ASTUnit.cpp lib/Serialization/ASTReader.cpp tools/libclang/Indexing.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue Oct 9 19:12:47 PDT 2012


Author: akirtzidis
Date: Tue Oct  9 21:12:47 2012
New Revision: 165592

URL: http://llvm.org/viewvc/llvm-project?rev=165592&view=rev
Log:
When indexing a module file, for the ppIncludedFile callback give
an invalid location if the location points to the synthetic buffer
for the module input.

Modified:
    cfe/trunk/include/clang/Frontend/ASTUnit.h
    cfe/trunk/include/clang/Serialization/ASTReader.h
    cfe/trunk/lib/Frontend/ASTUnit.cpp
    cfe/trunk/lib/Serialization/ASTReader.cpp
    cfe/trunk/tools/libclang/Indexing.cpp

Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=165592&r1=165591&r2=165592&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Tue Oct  9 21:12:47 2012
@@ -626,6 +626,10 @@
   /// \brief Get the PCH file if one was included.
   const FileEntry *getPCHFile();
 
+  /// \brief Returns true if the ASTUnit was constructed from a serialized
+  /// module file.
+  bool isModuleFile();
+
   llvm::MemoryBuffer *getBufferForFile(StringRef Filename,
                                        std::string *ErrorStr = 0);
 

Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=165592&r1=165591&r2=165592&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Tue Oct  9 21:12:47 2012
@@ -105,14 +105,16 @@
   /// \brief Receives the language options.
   ///
   /// \returns true to indicate the options are invalid or false otherwise.
-  virtual bool ReadLanguageOptions(const LangOptions &LangOpts) {
+  virtual bool ReadLanguageOptions(const serialization::ModuleFile &M,
+                                   const LangOptions &LangOpts) {
     return false;
   }
 
   /// \brief Receives the target triple.
   ///
   /// \returns true to indicate the target triple is invalid or false otherwise.
-  virtual bool ReadTargetTriple(StringRef Triple) {
+  virtual bool ReadTargetTriple(const serialization::ModuleFile &M,
+                                StringRef Triple) {
     return false;
   }
 
@@ -138,7 +140,8 @@
   virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID) {}
 
   /// \brief Receives __COUNTER__ value.
-  virtual void ReadCounter(unsigned Value) {}
+  virtual void ReadCounter(const serialization::ModuleFile &M,
+                           unsigned Value) {}
 };
 
 /// \brief ASTReaderListener implementation to validate the information of
@@ -153,14 +156,16 @@
   PCHValidator(Preprocessor &PP, ASTReader &Reader)
     : PP(PP), Reader(Reader), NumHeaderInfos(0) {}
 
-  virtual bool ReadLanguageOptions(const LangOptions &LangOpts);
-  virtual bool ReadTargetTriple(StringRef Triple);
+  virtual bool ReadLanguageOptions(const serialization::ModuleFile &M,
+                                   const LangOptions &LangOpts);
+  virtual bool ReadTargetTriple(const serialization::ModuleFile &M,
+                                StringRef Triple);
   virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
                                     StringRef OriginalFileName,
                                     std::string &SuggestedPredefines,
                                     FileManager &FileMgr);
   virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID);
-  virtual void ReadCounter(unsigned Value);
+  virtual void ReadCounter(const serialization::ModuleFile &M, unsigned Value);
 
 private:
   void Error(const char *Msg);
@@ -834,7 +839,7 @@
   llvm::BitstreamCursor &SLocCursorForID(int ID);
   SourceLocation getImportLocation(ModuleFile *F);
   ASTReadResult ReadSubmoduleBlock(ModuleFile &F);
-  bool ParseLanguageOptions(const RecordData &Record);
+  bool ParseLanguageOptions(const ModuleFile &M, const RecordData &Record);
   
   struct RecordLocation {
     RecordLocation(ModuleFile *M, uint64_t O)

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=165592&r1=165591&r2=165592&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Tue Oct  9 21:12:47 2012
@@ -512,8 +512,9 @@
       Predefines(Predefines), Counter(Counter), NumHeaderInfos(0),
       InitializedLanguage(false) {}
 
-  virtual bool ReadLanguageOptions(const LangOptions &LangOpts) {
-    if (InitializedLanguage)
+  virtual bool ReadLanguageOptions(const serialization::ModuleFile &M,
+                                   const LangOptions &LangOpts) {
+    if (InitializedLanguage || M.Kind != serialization::MK_MainFile)
       return false;
     
     LangOpt = LangOpts;
@@ -530,9 +531,10 @@
     return false;
   }
 
-  virtual bool ReadTargetTriple(StringRef Triple) {
+  virtual bool ReadTargetTriple(const serialization::ModuleFile &M,
+                                StringRef Triple) {
     // If we've already initialized the target, don't do it again.
-    if (Target)
+    if (Target || M.Kind != serialization::MK_MainFile)
       return false;
     
     // FIXME: This is broken, we should store the TargetOptions in the AST file.
@@ -563,7 +565,7 @@
     HSI.setHeaderFileInfoForUID(HFI, NumHeaderInfos++);
   }
 
-  virtual void ReadCounter(unsigned Value) {
+  virtual void ReadCounter(const serialization::ModuleFile &M, unsigned Value) {
     Counter = Value;
   }
 
@@ -2852,6 +2854,10 @@
   return 0;
 }
 
+bool ASTUnit::isModuleFile() {
+  return isMainFileAST() && !ASTFileLangOpts.CurrentModule.empty();
+}
+
 void ASTUnit::PreambleData::countLines() const {
   NumLines = 0;
   if (empty())

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=165592&r1=165591&r2=165592&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Oct  9 21:12:47 2012
@@ -63,7 +63,8 @@
 ASTReaderListener::~ASTReaderListener() {}
 
 bool
-PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) {
+PCHValidator::ReadLanguageOptions(const ModuleFile &M,
+                                  const LangOptions &LangOpts) {
   const LangOptions &PPLangOpts = PP.getLangOpts();
   
 #define LANGOPT(Name, Bits, Default, Description)         \
@@ -100,7 +101,7 @@
   return false;
 }
 
-bool PCHValidator::ReadTargetTriple(StringRef Triple) {
+bool PCHValidator::ReadTargetTriple(const ModuleFile &M, StringRef Triple) {
   if (Triple == PP.getTargetInfo().getTriple().str())
     return false;
 
@@ -408,7 +409,7 @@
   ++NumHeaderInfos;
 }
 
-void PCHValidator::ReadCounter(unsigned Value) {
+void PCHValidator::ReadCounter(const ModuleFile &M, unsigned Value) {
   PP.setCounterValue(Value);
 }
 
@@ -1828,7 +1829,7 @@
       RelocatablePCH = Record[4];
       if (Listener) {
         std::string TargetTriple(BlobStart, BlobLen);
-        if (Listener->ReadTargetTriple(TargetTriple))
+        if (Listener->ReadTargetTriple(F, TargetTriple))
           return IgnorePCH;
       }
       break;
@@ -1938,7 +1939,7 @@
     }
 
     case LANGUAGE_OPTIONS:
-      if (ParseLanguageOptions(Record) && !DisableValidation)
+      if (ParseLanguageOptions(F, Record) && !DisableValidation)
         return IgnorePCH;
       break;
 
@@ -2083,7 +2084,7 @@
 
     case PP_COUNTER_VALUE:
       if (!Record.empty() && Listener)
-        Listener->ReadCounter(Record[0]);
+        Listener->ReadCounter(F, Record[0]);
       break;
       
     case FILE_SORTED_DECLS:
@@ -3430,7 +3431,8 @@
 /// them to the AST listener if one is set.
 ///
 /// \returns true if the listener deems the file unacceptable, false otherwise.
-bool ASTReader::ParseLanguageOptions(const RecordData &Record) {
+bool ASTReader::ParseLanguageOptions(const ModuleFile &M,
+                                     const RecordData &Record) {
   if (Listener) {
     LangOptions LangOpts;
     unsigned Idx = 0;
@@ -3447,7 +3449,7 @@
     unsigned Length = Record[Idx++];
     LangOpts.CurrentModule.assign(Record.begin() + Idx, 
                                   Record.begin() + Idx + Length);
-    return Listener->ReadLanguageOptions(LangOpts);
+    return Listener->ReadLanguageOptions(M, LangOpts);
   }
 
   return false;

Modified: cfe/trunk/tools/libclang/Indexing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/Indexing.cpp?rev=165592&r1=165591&r2=165592&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/Indexing.cpp (original)
+++ cfe/trunk/tools/libclang/Indexing.cpp Tue Oct  9 21:12:47 2012
@@ -450,14 +450,21 @@
   PreprocessingRecord::iterator I, E;
   llvm::tie(I, E) = Unit.getLocalPreprocessingEntities();
 
+  bool isModuleFile = Unit.isModuleFile();
   for (; I != E; ++I) {
     PreprocessedEntity *PPE = *I;
 
     if (InclusionDirective *ID = dyn_cast<InclusionDirective>(PPE)) {
-      if (!ID->importedModule())
-        IdxCtx.ppIncludedFile(ID->getSourceRange().getBegin(),ID->getFileName(),
+      if (!ID->importedModule()) {
+        SourceLocation Loc = ID->getSourceRange().getBegin();
+        // Modules have synthetic main files as input, give an invalid location
+        // if the location points to such a file.
+        if (isModuleFile && Unit.isInMainFileID(Loc))
+          Loc = SourceLocation();
+        IdxCtx.ppIncludedFile(Loc, ID->getFileName(),
                      ID->getFile(), ID->getKind() == InclusionDirective::Import,
                      !ID->wasInQuotes());
+      }
     }
   }
 }





More information about the cfe-commits mailing list