[llvm-bugs] [Bug 24748] New: clang_getInclusions is returning no includes after the preamble is compiled

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Sep 8 06:39:39 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=24748

            Bug ID: 24748
           Summary: clang_getInclusions is returning no includes after the
                    preamble is compiled
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: libclang
          Assignee: unassignedclangbugs at nondot.org
          Reporter: clang at bubke.de
                CC: klimek at google.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

1. clang_parseTranslationUnit2 (CXTranslationUnit_CacheCompletionResults
         | CXTranslationUnit_PrecompiledPreamble
         | CXTranslationUnit_IncludeBriefCommentsInCodeCompletion)
2. clang_getInclusions -> get expected include list
3. clang_reparseTranslationUnit
4. clang_getInclusions -> get no includes anymore

After playing around in the clang source the following patch is fixing it. It
looks like there are more than the expected one entry but all except one are
invalid.

Index: tools/libclang/CIndexInclusionStack.cpp
===================================================================
--- tools/libclang/CIndexInclusionStack.cpp    (revision 246452)
+++ tools/libclang/CIndexInclusionStack.cpp    (working copy)
@@ -35,12 +35,28 @@

   SmallVector<CXSourceLocation, 10> InclusionStack;
   unsigned n =  SM.local_sloc_entry_size();
+  unsigned n2 = 0;

+  const SrcMgr::SLocEntry &(SourceManager::*Getter)(unsigned, bool*) const;
+  Getter = &SourceManager::getLocalSLocEntry;
+
+  for (unsigned i = 0 ; i < n ; ++i) {
+    bool Invalid = false;
+    const SrcMgr::SLocEntry &SL = (SM.*Getter)(i, &Invalid);
+
+    if (!SL.isFile() || Invalid)
+      continue;
+
+    const SrcMgr::FileInfo &FI = SL.getFile();
+    if (!FI.getContentCache()->OrigEntry)
+      continue;
+
+    ++n2;
+    }
   // In the case where all the SLocEntries are in an external source, traverse
   // those SLocEntries as well.  This is the case where we are looking
   // at the inclusion stack of an AST/PCH file.
-  const SrcMgr::SLocEntry &(SourceManager::*Getter)(unsigned, bool*) const;
-  if (n == 1) {
+  if (n2 == 1) {
     Getter = &SourceManager::getLoadedSLocEntry;
     n = SM.loaded_sloc_entry_size();
   } else

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150908/13cde632/attachment.html>


More information about the llvm-bugs mailing list