[PATCH] D48726: Attempt to write a test to reproduce #37963

Simon Marchi via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 28 08:29:06 PDT 2018


simark created this revision.
Herald added subscribers: cfe-commits, jkorous, ioeric, ilya-biryukov.

This is not intended to be merged, it is my attempt at reproducing this:

https://bugs.llvm.org/show_bug.cgi?id=37963

using a unit test.  However, I can't manage to get the faulty result
like this.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48726

Files:
  unittests/clangd/XRefsTests.cpp


Index: unittests/clangd/XRefsTests.cpp
===================================================================
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -335,6 +335,72 @@
                                                SourceAnnotations.range()}));
 }
 
+TEST(GoToDefinition, TestSimon) {
+  Annotations FirstHSrc(R"cpp(
+static inline void
+bob()
+{
+}
+)cpp");
+  Annotations FirstCppSrc(R"cpp(
+#include "first.h"
+
+void bar();
+
+void foo()
+{
+  b^ob();
+}
+
+int main()
+{
+  bar();
+  foo();
+}
+)cpp");
+
+  StringRef CompileCommandsJson = R"json(
+[
+    {
+        "arguments": ["c++", "-c", "-g3", "-O0", "-o", "second.o", "../src/second.cpp"],
+        "directory": "/home/emaisin/src/ls-interact/cpp-test/build",
+        "file": "../src/second.cpp"
+    },
+    {
+        "arguments": ["c++", "-c", "-g3", "-O0", "-o", "first.o", "../src/first.cpp"],
+        "directory": "/home/emaisin/src/ls-interact/cpp-test/build",
+        "file": "../src/first.cpp"
+    }
+]
+
+)json";
+
+  MockFSProvider FS;
+
+  FS.Files["/home/emaisin/src/ls-interact/cpp-test/src/first.h"] = FirstHSrc.code();
+  FS.Files["/home/emaisin/src/ls-interact/cpp-test/src/first.cpp"] = FirstCppSrc.code();
+  FS.Files["/home/emaisin/src/ls-interact/cpp-test/build/compile_commands.json"] = CompileCommandsJson;
+
+  DirectoryBasedGlobalCompilationDatabase CDB (Path("/home/emaisin/src/ls-interact/cpp-test/build"));
+  IgnoreDiagnostics DiagConsumer;
+  ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest());
+
+  runAddDocument(Server, "/home/emaisin/src/ls-interact/cpp-test/src/first.cpp", FirstCppSrc.code());
+
+  llvm::Expected<std::vector<Location>> Locations = runFindDefinitions(Server, "/home/emaisin/src/ls-interact/cpp-test/src/first.cpp", FirstCppSrc.point());
+
+  EXPECT_TRUE(bool(Locations)) << "findDefinitions returned an error";
+
+  fprintf(stderr, "\n\n");
+
+  for (const Location &L : *Locations) {
+    fprintf(stderr, "%s %d:%d to %d:%d", L.uri.file().data(),
+        L.range.start.line , L.range.start.character, L.range.end.line, L.range.end.character);
+  }
+
+  fprintf(stderr, "\n\n");
+}
+
 TEST(Hover, All) {
   struct OneTest {
     StringRef Input;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48726.153331.patch
Type: text/x-patch
Size: 2221 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180628/9c89ebd2/attachment.bin>


More information about the cfe-commits mailing list