1

I have a utility that uses Clang's LibTooling framework to parse the AST and perform static code analysis. I am using LLVM and Clang v10.0.

Recently I observed that the utility never finishes parsing the AST of a particular file. On debugging, I observed that the SourceManager.cpp calls an abort due to failed assertion. The exact place is here:

FileID SourceManager::createFileID(const ContentCache *File,
                                   SourceLocation IncludePos,
                                   SrcMgr::CharacteristicKind FileCharacter,
                                   int LoadedID, unsigned LoadedOffset) {
...
...
assert(NextLocalOffset + FileSize + 1 > NextLocalOffset &&
         NextLocalOffset + FileSize + 1 <= CurrentLoadedOffset &&
         "Ran out of source locations!");
...
...
...
}

The values of the variables when the assertion fails are: NextLocalOffset=2147335549, FileSize=303516, CurrentLoadedOffset=2147483648 and (NextLocalOffset + FileSize)=2147639065.

The source file is automatically generated and is around 28,268,746 bytes (~27MB) and contains several include directives (~7000) for memory mapping different code blocks.

Is there a limit to the source files size Clang can process?

asumang
  • 673
  • 1
  • 6
  • 11
  • 1
    Found a bug report which exactly matches my observation: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=220233 – asumang Jun 06 '20 at 11:18
  • I have the same problem. Unfortubately I cannot submit bug report because my code base is a company property which is strictly closed source. @asumang could you please submit bug report to llvm community? https://llvm.org/docs/HowToSubmitABug.html – fskoras Jul 23 '20 at 09:53
  • @fskoras: I have the same issue. I tried to reproduce the behavior using a sample source file so that I can share it. However the big file works fine! The issue seem to occur only when I supply a Compilation Database JSON to the Clang libtooling framework that includes my big file. So to reproduce the issue, I would need to share my entire project "as is" which is difficult. I thought Clang experts could easily look at the assertion and explain what causes it. Clearly it is neither the file size nor the include directives. – asumang Aug 03 '20 at 08:25

0 Answers0