<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - clang_getInclusions is returning no includes after the preamble is compiled"
   href="https://llvm.org/bugs/show_bug.cgi?id=24748">24748</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang_getInclusions is returning no includes after the preamble is compiled
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>libclang
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>clang@bubke.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>klimek@google.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>