[PATCH] D100501: [cland] Dont emit missing newline warnings when building preamble
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 23 00:02:15 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa46bbc14f004: [cland] Dont emit missing newline warnings when building preamble (authored by kadircet).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D100501/new/
https://reviews.llvm.org/D100501
Files:
clang-tools-extra/clangd/Preamble.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
@@ -1373,6 +1373,25 @@
EXPECT_THAT(*AST.getDiagnostics(),
testing::Contains(Diag(Code.range(), KDiagMsg.str())));
}
+
+TEST(Preamble, EndsOnNonEmptyLine) {
+ TestTU TU;
+ TU.ExtraArgs = {"-Wnewline-eof"};
+
+ {
+ TU.Code = "#define FOO\n void bar();\n";
+ auto AST = TU.build();
+ EXPECT_THAT(*AST.getDiagnostics(), IsEmpty());
+ }
+ {
+ Annotations Code("#define FOO[[]]");
+ TU.Code = Code.code().str();
+ auto AST = TU.build();
+ EXPECT_THAT(
+ *AST.getDiagnostics(),
+ testing::Contains(Diag(Code.range(), "no newline at end of file")));
+ }
+}
} // namespace
} // namespace clangd
} // namespace clang
Index: clang-tools-extra/clangd/Preamble.cpp
===================================================================
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -15,6 +15,7 @@
#include "support/Trace.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticLex.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
@@ -341,6 +342,20 @@
llvm::IntrusiveRefCntPtr<DiagnosticsEngine> PreambleDiagsEngine =
CompilerInstance::createDiagnostics(&CI.getDiagnosticOpts(),
&PreambleDiagnostics, false);
+ PreambleDiagnostics.setLevelAdjuster(
+ [&](DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &Info) {
+ switch (Info.getID()) {
+ case diag::warn_no_newline_eof:
+ case diag::warn_cxx98_compat_no_newline_eof:
+ case diag::ext_no_newline_eof:
+ // If the preamble doesn't span the whole file, drop the no newline at
+ // eof warnings.
+ return Bounds.Size != ContentsBuffer->getBufferSize()
+ ? DiagnosticsEngine::Level::Ignored
+ : DiagLevel;
+ }
+ return DiagLevel;
+ });
// Skip function bodies when building the preamble to speed up building
// the preamble and make it smaller.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100501.339903.patch
Type: text/x-patch
Size: 2352 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210423/215c0d29/attachment.bin>
More information about the cfe-commits
mailing list