This is an archive of the discontinued LLVM Phabricator instance.

compile commands header to source heuristic lower-cases filenames before inferring file types
ClosedPublic

Authored by ishaangandhi on Apr 22 2022, 7:36 AM.

Details

Summary

This leads to ".C" files being rewritten as ".c" files and being inferred to be "c" files as opposed to "c++" files.

See https://github.com/clangd/clangd/issues/1108 for the original bug report.

Diff Detail

Event Timeline

ishaangandhi created this revision.Apr 22 2022, 7:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2022, 7:36 AM
ishaangandhi requested review of this revision.Apr 22 2022, 7:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2022, 7:36 AM
ishaangandhi changed the visibility from "Public (No Login Required)" to "No One".Apr 22 2022, 7:37 AM
ishaangandhi changed the visibility from "No One" to "Public (No Login Required)".Apr 22 2022, 8:58 AM

Change looks good, thank you!

Can you add a test demonstrating it, and update the diff here?
Take a look at the InterpolateTest cases in clang/unittests/Tooling/CompilationDatabaseTest.cpp.

(If you can, please create diffs with context using -U99999 - this lets us see more context around the changed lines in phabricator)

clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
332

nit: StringRef() isn't needed here, conversion will happen implicitly.

(The one on 329 is needed because the overload set of StringSaver::save is ambiguous)

  • Added a test case
  • Removed redundant "StringRef" constructor
ishaangandhi marked an inline comment as done.Apr 25 2022, 7:45 AM

Test case added, re-diffed with -U9999, and removed redundant constructor. Thanks for the quick feedback, @sammccall!

(I didn't wait for the tests to run locally, I am hoping to use your CI systems to do that. It seems like a simple enough of a test that I hope I can get it right on the first try.)

Test case added, re-diffed with -U9999, and removed redundant constructor. Thanks for the quick feedback, @sammccall!

(I didn't wait for the tests to run locally, I am hoping to use your CI systems to do that. It seems like a simple enough of a test that I hope I can get it right on the first try.)

Unfortunately it looks like you've created a patch that phabricator can render, but the precommit CI can't apply (it's using git apply).
The usual way to upload is with arc, but the output of git diff -U9999 should also work.

clang/unittests/Tooling/CompilationDatabaseTest.cpp
843

Is this really what you intend to test?

I think our goal here is to treat .H and .C as C++ rather than C, not to link them together in some way. If the current file is foo.H, then foo.cpp and foo.C should be equally compelling candidates, but both beat foo.c.

ishaangandhi added inline comments.Apr 25 2022, 7:59 AM
clang/unittests/Tooling/CompilationDatabaseTest.cpp
843

Bleh brain fart. You're right. "exact.C" should win over "exact.c", not necessarily "exact.cpp".

Made test case reflect that proxies for ".H" files are ".C" files, and not ".c files".

ishaangandhi marked an inline comment as done and an inline comment as not done.Apr 25 2022, 8:03 AM
sammccall accepted this revision.Apr 25 2022, 9:04 AM

Thanks!
I can land this for you if you don't have commit access - can you provide the name/email to use for the commit?

This revision is now accepted and ready to land.Apr 25 2022, 9:04 AM

Thanks!
I can land this for you if you don't have commit access - can you provide the name/email to use for the commit?

Thank you!

Ishaan Gandhi
ishaangandhi@gmail.com