[cfe-commits] r172259 - /cfe/trunk/lib/Frontend/ASTUnit.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Fri Jan 11 14:11:14 PST 2013
Author: akirtzidis
Date: Fri Jan 11 16:11:14 2013
New Revision: 172259
URL: http://llvm.org/viewvc/llvm-project?rev=172259&view=rev
Log:
[libclang] In ASTUnit::getMainFileName() Invocation may be null because the ASTUnit
came from loading a PCH/module.
Modified:
cfe/trunk/lib/Frontend/ASTUnit.cpp
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=172259&r1=172258&r2=172259&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Fri Jan 11 16:11:14 2013
@@ -1689,7 +1689,21 @@
}
StringRef ASTUnit::getMainFileName() const {
- return Invocation->getFrontendOpts().Inputs[0].getFile();
+ if (Invocation && !Invocation->getFrontendOpts().Inputs.empty()) {
+ const FrontendInputFile &Input = Invocation->getFrontendOpts().Inputs[0];
+ if (Input.isFile())
+ return Input.getFile();
+ else
+ return Input.getBuffer()->getBufferIdentifier();
+ }
+
+ if (SourceMgr) {
+ if (const FileEntry *
+ FE = SourceMgr->getFileEntryForID(SourceMgr->getMainFileID()))
+ return FE->getName();
+ }
+
+ return StringRef();
}
ASTUnit *ASTUnit::create(CompilerInvocation *CI,
More information about the cfe-commits
mailing list