aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-01-11 22:11:14 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-01-11 22:11:14 +0000
commit814b51a3d572d4e4107e67d549c8a82484ce8160 (patch)
tree9c246bb85da06e14e8ddc7f3ab0d9c7b117d92ca /lib
parentf64c18ac9808c0e7baaf54f35803eaa6cd0e49bc (diff)
[libclang] In ASTUnit::getMainFileName() Invocation may be null because the ASTUnit
came from loading a PCH/module. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172259 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Frontend/ASTUnit.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp
index 242586a9be..35a9aa4ff0 100644
--- a/lib/Frontend/ASTUnit.cpp
+++ b/lib/Frontend/ASTUnit.cpp
@@ -1689,7 +1689,21 @@ void ASTUnit::transferASTDataFromCompilerInstance(CompilerInstance &CI) {
}
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,