[PATCH] D70494: [clangd] Fix diagnostic location for macro expansions
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 25 01:48:07 PST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe841029aef74: [clangd] Fix diagnostic location for macro expansions (authored by kadircet).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D70494/new/
https://reviews.llvm.org/D70494
Files:
clang-tools-extra/clangd/Diagnostics.cpp
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -941,7 +941,7 @@
WithNote(Diag(Header.range(), "error occurred here")))));
}
-TEST(IgnoreDiags, FromNonWrittenSources) {
+TEST(DiagsInHeaders, FromNonWrittenSources) {
Annotations Main(R"cpp(
#include [["a.h"]]
void foo() {})cpp");
@@ -951,11 +951,49 @@
TestTU TU = TestTU::withCode(Main.code());
TU.AdditionalFiles = {{"a.h", Header.code()}};
TU.ExtraArgs = {"-DFOO=NOOO"};
- EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre());
+ EXPECT_THAT(TU.build().getDiagnostics(),
+ UnorderedElementsAre(AllOf(
+ Diag(Main.range(),
+ "in included file: use of undeclared identifier 'NOOO'"),
+ WithNote(Diag(Header.range(), "error occurred here")))));
+}
+
+TEST(DiagsInHeaders, ErrorFromMacroExpansion) {
+ Annotations Main(R"cpp(
+ void bar() {
+ int fo;
+ #include [["a.h"]]
+ })cpp");
+ Annotations Header(R"cpp(
+ #define X foo
+ X;)cpp");
+ TestTU TU = TestTU::withCode(Main.code());
+ TU.AdditionalFiles = {{"a.h", Header.code()}};
+ EXPECT_THAT(TU.build().getDiagnostics(),
+ UnorderedElementsAre(
+ Diag(Main.range(), "in included file: use of undeclared "
+ "identifier 'foo'; did you mean 'fo'?")));
+}
+
+TEST(DiagsInHeaders, ErrorFromMacroArgument) {
+ Annotations Main(R"cpp(
+ void bar() {
+ int fo;
+ #include [["a.h"]]
+ })cpp");
+ Annotations Header(R"cpp(
+ #define X(arg) arg
+ X(foo);)cpp");
+ TestTU TU = TestTU::withCode(Main.code());
+ TU.AdditionalFiles = {{"a.h", Header.code()}};
+ EXPECT_THAT(TU.build().getDiagnostics(),
+ UnorderedElementsAre(
+ Diag(Main.range(), "in included file: use of undeclared "
+ "identifier 'foo'; did you mean 'fo'?")));
}
TEST(IgnoreDiags, FromNonWrittenInclude) {
- TestTU TU = TestTU::withCode("");
+ TestTU TU;
TU.ExtraArgs.push_back("--include=a.h");
TU.AdditionalFiles = {{"a.h", "void main();"}};
// The diagnostic "main must return int" is from the header, we don't attempt
@@ -964,6 +1002,5 @@
}
} // namespace
-
} // namespace clangd
} // namespace clang
Index: clang-tools-extra/clangd/Diagnostics.cpp
===================================================================
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -117,8 +117,8 @@
if (D.Severity < DiagnosticsEngine::Level::Error)
return false;
- const SourceLocation &DiagLoc = Info.getLocation();
const SourceManager &SM = Info.getSourceManager();
+ const SourceLocation &DiagLoc = SM.getExpansionLoc(Info.getLocation());
SourceLocation IncludeInMainFile;
auto GetIncludeLoc = [&SM](SourceLocation SLoc) {
return SM.getIncludeLoc(SM.getFileID(SLoc));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70494.230852.patch
Type: text/x-patch
Size: 3104 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191125/18ab3adb/attachment.bin>
More information about the cfe-commits
mailing list