aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Frontend/CommandLineSourceLoc.h8
-rw-r--r--lib/Frontend/CompilerInstance.cpp5
-rw-r--r--test/CodeCompletion/stdin.c7
3 files changed, 18 insertions, 2 deletions
diff --git a/include/clang/Frontend/CommandLineSourceLoc.h b/include/clang/Frontend/CommandLineSourceLoc.h
index bea468b017..8911cfadd5 100644
--- a/include/clang/Frontend/CommandLineSourceLoc.h
+++ b/include/clang/Frontend/CommandLineSourceLoc.h
@@ -37,9 +37,15 @@ public:
// If both tail splits were valid integers, return success.
if (!ColSplit.second.getAsInteger(10, PSL.Column) &&
- !LineSplit.second.getAsInteger(10, PSL.Line))
+ !LineSplit.second.getAsInteger(10, PSL.Line)) {
PSL.FileName = LineSplit.first;
+ // On the command-line, stdin may be specified via "-". Inside the
+ // compiler, stdin is called "<stdin>".
+ if (PSL.FileName == "-")
+ PSL.FileName = "<stdin>";
+ }
+
return PSL;
}
};
diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp
index a187140ca0..95d417f633 100644
--- a/lib/Frontend/CompilerInstance.cpp
+++ b/lib/Frontend/CompilerInstance.cpp
@@ -479,7 +479,10 @@ bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile,
Diags.Report(diag::err_fe_error_reading_stdin);
return false;
}
- SourceMgr.createMainFileIDForMemBuffer(SB);
+ const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
+ SB->getBufferSize(), 0);
+ SourceMgr.createMainFileID(File);
+ SourceMgr.overrideFileContents(File, SB);
}
assert(!SourceMgr.getMainFileID().isInvalid() &&
diff --git a/test/CodeCompletion/stdin.c b/test/CodeCompletion/stdin.c
new file mode 100644
index 0000000000..46495b2cd3
--- /dev/null
+++ b/test/CodeCompletion/stdin.c
@@ -0,0 +1,7 @@
+enum X { x };
+enum Y { y };
+
+enum
+ // RUN: %clang_cc1 -fsyntax-only -code-completion-at=-:4:6 < %s -o - | FileCheck -check-prefix=CC1 %s
+ // CHECK-CC1: X
+ // CHECK-CC1: Y