[clang-tools-extra] [clangd] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114661)
https://github.com/chomosuke updated https://github.com/llvm/llvm-project/pull/114661 >From f52c645a8b0a3664c2520e70b46e248c984037ae Mon Sep 17 00:00:00 2001 From: chomosuke Date: Sat, 2 Nov 2024 09:18:38 + Subject: [PATCH] Add quick fix to automatically adds NOLINTNEXTLINE comment above clang-tidy warnings --- clang-tools-extra/clangd/CMakeLists.txt | 1 + clang-tools-extra/clangd/ClangdServer.cpp | 3 +- clang-tools-extra/clangd/Diagnostics.cpp | 23 +++- clang-tools-extra/clangd/Diagnostics.h| 12 +- clang-tools-extra/clangd/NoLintFixes.cpp | 99 +++ clang-tools-extra/clangd/NoLintFixes.h| 36 ++ clang-tools-extra/clangd/ParsedAST.cpp| 19 ++- .../fixits-codeaction-documentchanges.test| 47 .../clangd/test/fixits-codeaction.test| 41 +++ .../test/fixits-command-documentchanges.test | 62 ++ .../clangd/test/fixits-command.test | 50 .../clangd/unittests/ClangdLSPServerTests.cpp | 18 ++- .../clangd/unittests/DiagnosticsTests.cpp | 113 -- 13 files changed, 492 insertions(+), 32 deletions(-) create mode 100644 clang-tools-extra/clangd/NoLintFixes.cpp create mode 100644 clang-tools-extra/clangd/NoLintFixes.h diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt index d797ddce8c44d1..2a6433a5c3effd 100644 --- a/clang-tools-extra/clangd/CMakeLists.txt +++ b/clang-tools-extra/clangd/CMakeLists.txt @@ -98,6 +98,7 @@ add_clang_library(clangDaemon STATIC InlayHints.cpp JSONTransport.cpp ModulesBuilder.cpp + NoLintFixes.cpp PathMapping.cpp Protocol.cpp Quality.cpp diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 9b38be04e7ddd7..7f73b61b12c63f 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -15,6 +15,7 @@ #include "Format.h" #include "HeaderSourceSwitch.h" #include "InlayHints.h" +#include "NoLintFixes.h" #include "ParsedAST.h" #include "Preamble.h" #include "Protocol.h" @@ -661,7 +662,7 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) { bool IsClangTidyRename = Diag->Source == Diag::ClangTidy && Diag->Name == "readability-identifier-naming" && !Fix.Edits.empty(); - if (IsClangTidyRename && Diag->InsideMainFile) { + if (IsClangTidyRename && !isNoLintFixes(Fix) && Diag->InsideMainFile) { ClangdServer::CodeActionResult::Rename R; R.NewName = Fix.Edits.front().newText; R.FixMessage = Fix.Message; diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index a59d1e7ac84096..6948e12995bed1 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -9,6 +9,7 @@ #include "Diagnostics.h" #include "../clang-tidy/ClangTidyDiagnosticConsumer.h" #include "Compiler.h" +#include "NoLintFixes.h" #include "Protocol.h" #include "SourceCode.h" #include "support/Logger.h" @@ -311,8 +312,18 @@ std::string mainMessage(const Diag &D, const ClangdDiagnosticOptions &Opts) { std::string Result; llvm::raw_string_ostream OS(Result); OS << D.Message; - if (Opts.DisplayFixesCount && !D.Fixes.empty()) -OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)"; + + // NOLINT fixes are somewhat not real fixes and to say "(fix available)" when + // the fixes is just to suppress could be misleading. + int RealFixCount = D.Fixes.size(); + for (auto const &Fix : D.Fixes) { +if (isNoLintFixes(Fix)) { + RealFixCount--; +} + } + + if (Opts.DisplayFixesCount && RealFixCount > 0) +OS << " (" << (RealFixCount > 1 ? "fixes" : "fix") << " available)"; // If notes aren't emitted as structured info, add them to the message. if (!Opts.EmitRelatedLocations) for (auto &Note : D.Notes) { @@ -822,8 +833,8 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, LastDiagOriginallyError = OriginallyError; if (!Info.getFixItHints().empty()) AddFix(true /* try to invent a message instead of repeating the diag */); -if (Fixer) { - auto ExtraFixes = Fixer(LastDiag->Severity, Info); +if (MainFixer) { + auto ExtraFixes = MainFixer(*LastDiag, Info); LastDiag->Fixes.insert(LastDiag->Fixes.end(), ExtraFixes.begin(), ExtraFixes.end()); } @@ -841,8 +852,8 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, return; // Give include-fixer a chance to replace a note with a fix. -if (Fixer) { - auto ReplacementFixes = Fixer(LastDiag->Severity, Info); +if (NoteFixer) { + auto ReplacementFixes = NoteFixer(*LastDiag, Info); if (!ReplacementFixes.empty()) { assert(Info.getNumFixItHints() == 0 && "Include-fixer replaced a note with clang fix
[clang] [LoongArch][Clang] Make the parameter and return value of {x,}vmsknz.b builtins `signed char` vector (PR #114511)
SixWeining wrote: > > Is it the time to remove the FIXME in those tests? > > There are several random inconsistencies and I separated the fixes into > multiple PRs as suggested by Xuerui. The FIXME is removed in #114513. Oh, I missed those PRs. https://github.com/llvm/llvm-project/pull/114511 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114660)
https://github.com/chomosuke updated https://github.com/llvm/llvm-project/pull/114660 >From a8caf223a55b16fc4e0aaa483c4af62306137179 Mon Sep 17 00:00:00 2001 From: chomosuke Date: Sat, 2 Nov 2024 09:18:38 + Subject: [PATCH] Add quick fix to automatically adds NOLINTNEXTLINE comment above clang-tidy warnings --- clang-tools-extra/clangd/CMakeLists.txt | 1 + clang-tools-extra/clangd/ClangdServer.cpp | 7 +- clang-tools-extra/clangd/Diagnostics.cpp | 26 ++-- clang-tools-extra/clangd/Diagnostics.h| 12 +- clang-tools-extra/clangd/NoLintFixes.cpp | 99 +++ clang-tools-extra/clangd/NoLintFixes.h| 36 ++ clang-tools-extra/clangd/ParsedAST.cpp| 20 ++- .../fixits-codeaction-documentchanges.test| 47 +++ .../clangd/test/fixits-codeaction.test| 41 ++ .../test/fixits-command-documentchanges.test | 62 ++ .../clangd/test/fixits-command.test | 50 .../clangd/unittests/ClangdLSPServerTests.cpp | 16 ++- .../clangd/unittests/DiagnosticsTests.cpp | 117 +++--- 13 files changed, 497 insertions(+), 37 deletions(-) create mode 100644 clang-tools-extra/clangd/NoLintFixes.cpp create mode 100644 clang-tools-extra/clangd/NoLintFixes.h diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt index d797ddce8c44d1..2a6433a5c3effd 100644 --- a/clang-tools-extra/clangd/CMakeLists.txt +++ b/clang-tools-extra/clangd/CMakeLists.txt @@ -98,6 +98,7 @@ add_clang_library(clangDaemon STATIC InlayHints.cpp JSONTransport.cpp ModulesBuilder.cpp + NoLintFixes.cpp PathMapping.cpp Protocol.cpp Quality.cpp diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 9b38be04e7ddd7..925a015ae341bc 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -15,6 +15,7 @@ #include "Format.h" #include "HeaderSourceSwitch.h" #include "InlayHints.h" +#include "NoLintFixes.h" #include "ParsedAST.h" #include "Preamble.h" #include "Protocol.h" @@ -62,8 +63,8 @@ namespace clangd { namespace { // Tracks number of times a tweak has been offered. -static constexpr trace::Metric TweakAvailable( -"tweak_available", trace::Metric::Counter, "tweak_id"); +static constexpr trace::Metric +TweakAvailable("tweak_available", trace::Metric::Counter, "tweak_id"); // Update the FileIndex with new ASTs and plumb the diagnostics responses. struct UpdateIndexCallbacks : public ParsingCallbacks { @@ -661,7 +662,7 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) { bool IsClangTidyRename = Diag->Source == Diag::ClangTidy && Diag->Name == "readability-identifier-naming" && !Fix.Edits.empty(); - if (IsClangTidyRename && Diag->InsideMainFile) { + if (IsClangTidyRename && !isNoLintFixes(Fix) && Diag->InsideMainFile) { ClangdServer::CodeActionResult::Rename R; R.NewName = Fix.Edits.front().newText; R.FixMessage = Fix.Message; diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index a59d1e7ac84096..e42da2a9135e9b 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -9,6 +9,7 @@ #include "Diagnostics.h" #include "../clang-tidy/ClangTidyDiagnosticConsumer.h" #include "Compiler.h" +#include "NoLintFixes.h" #include "Protocol.h" #include "SourceCode.h" #include "support/Logger.h" @@ -311,8 +312,18 @@ std::string mainMessage(const Diag &D, const ClangdDiagnosticOptions &Opts) { std::string Result; llvm::raw_string_ostream OS(Result); OS << D.Message; - if (Opts.DisplayFixesCount && !D.Fixes.empty()) -OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)"; + + // NOLINT fixes are somewhat not real fixes and to say "(fix available)" when + // the fixes is just to suppress could be misleading. + int RealFixCount = D.Fixes.size(); + for (auto const &Fix : D.Fixes) { +if (isNoLintFixes(Fix)) { + RealFixCount--; +} + } + + if (Opts.DisplayFixesCount && RealFixCount > 0) +OS << " (" << (RealFixCount > 1 ? "fixes" : "fix") << " available)"; // If notes aren't emitted as structured info, add them to the message. if (!Opts.EmitRelatedLocations) for (auto &Note : D.Notes) { @@ -795,8 +806,7 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, } if (Message.empty()) // either !SyntheticMessage, or we failed to make one. Info.FormatDiagnostic(Message); -LastDiag->Fixes.push_back( -Fix{std::string(Message), std::move(Edits), {}}); +LastDiag->Fixes.push_back(Fix{std::string(Message), std::move(Edits), {}}); return true; }; @@ -822,8 +832,8 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, LastDiagOriginallyError = OriginallyError; if (!Info.g
[clang-tools-extra] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114660)
https://github.com/chomosuke updated https://github.com/llvm/llvm-project/pull/114660 >From 4c506db1c879a648ba3f0dc3851c47f597f9ad96 Mon Sep 17 00:00:00 2001 From: chomosuke Date: Sat, 2 Nov 2024 09:18:38 + Subject: [PATCH] Add quick fix to automatically adds NOLINTNEXTLINE comment above clang-tidy warnings --- clang-tools-extra/clangd/CMakeLists.txt | 1 + clang-tools-extra/clangd/ClangdServer.cpp | 3 +- clang-tools-extra/clangd/Diagnostics.cpp | 23 +++- clang-tools-extra/clangd/Diagnostics.h| 12 +- clang-tools-extra/clangd/NoLintFixes.cpp | 99 +++ clang-tools-extra/clangd/NoLintFixes.h| 36 ++ clang-tools-extra/clangd/ParsedAST.cpp| 20 +++- .../fixits-codeaction-documentchanges.test| 47 .../clangd/test/fixits-codeaction.test| 41 +++ .../test/fixits-command-documentchanges.test | 62 ++ .../clangd/test/fixits-command.test | 50 .../clangd/unittests/ClangdLSPServerTests.cpp | 16 ++- .../clangd/unittests/DiagnosticsTests.cpp | 113 -- 13 files changed, 492 insertions(+), 31 deletions(-) create mode 100644 clang-tools-extra/clangd/NoLintFixes.cpp create mode 100644 clang-tools-extra/clangd/NoLintFixes.h diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt index d797ddce8c44d1..2a6433a5c3effd 100644 --- a/clang-tools-extra/clangd/CMakeLists.txt +++ b/clang-tools-extra/clangd/CMakeLists.txt @@ -98,6 +98,7 @@ add_clang_library(clangDaemon STATIC InlayHints.cpp JSONTransport.cpp ModulesBuilder.cpp + NoLintFixes.cpp PathMapping.cpp Protocol.cpp Quality.cpp diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 9b38be04e7ddd7..7f73b61b12c63f 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -15,6 +15,7 @@ #include "Format.h" #include "HeaderSourceSwitch.h" #include "InlayHints.h" +#include "NoLintFixes.h" #include "ParsedAST.h" #include "Preamble.h" #include "Protocol.h" @@ -661,7 +662,7 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) { bool IsClangTidyRename = Diag->Source == Diag::ClangTidy && Diag->Name == "readability-identifier-naming" && !Fix.Edits.empty(); - if (IsClangTidyRename && Diag->InsideMainFile) { + if (IsClangTidyRename && !isNoLintFixes(Fix) && Diag->InsideMainFile) { ClangdServer::CodeActionResult::Rename R; R.NewName = Fix.Edits.front().newText; R.FixMessage = Fix.Message; diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index a59d1e7ac84096..6948e12995bed1 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -9,6 +9,7 @@ #include "Diagnostics.h" #include "../clang-tidy/ClangTidyDiagnosticConsumer.h" #include "Compiler.h" +#include "NoLintFixes.h" #include "Protocol.h" #include "SourceCode.h" #include "support/Logger.h" @@ -311,8 +312,18 @@ std::string mainMessage(const Diag &D, const ClangdDiagnosticOptions &Opts) { std::string Result; llvm::raw_string_ostream OS(Result); OS << D.Message; - if (Opts.DisplayFixesCount && !D.Fixes.empty()) -OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)"; + + // NOLINT fixes are somewhat not real fixes and to say "(fix available)" when + // the fixes is just to suppress could be misleading. + int RealFixCount = D.Fixes.size(); + for (auto const &Fix : D.Fixes) { +if (isNoLintFixes(Fix)) { + RealFixCount--; +} + } + + if (Opts.DisplayFixesCount && RealFixCount > 0) +OS << " (" << (RealFixCount > 1 ? "fixes" : "fix") << " available)"; // If notes aren't emitted as structured info, add them to the message. if (!Opts.EmitRelatedLocations) for (auto &Note : D.Notes) { @@ -822,8 +833,8 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, LastDiagOriginallyError = OriginallyError; if (!Info.getFixItHints().empty()) AddFix(true /* try to invent a message instead of repeating the diag */); -if (Fixer) { - auto ExtraFixes = Fixer(LastDiag->Severity, Info); +if (MainFixer) { + auto ExtraFixes = MainFixer(*LastDiag, Info); LastDiag->Fixes.insert(LastDiag->Fixes.end(), ExtraFixes.begin(), ExtraFixes.end()); } @@ -841,8 +852,8 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, return; // Give include-fixer a chance to replace a note with a fix. -if (Fixer) { - auto ReplacementFixes = Fixer(LastDiag->Severity, Info); +if (NoteFixer) { + auto ReplacementFixes = NoteFixer(*LastDiag, Info); if (!ReplacementFixes.empty()) { assert(Info.getNumFixItHints() == 0 && "Include-fixer replaced a note with clang fi
[clang-tools-extra] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114660)
https://github.com/chomosuke updated https://github.com/llvm/llvm-project/pull/114660 >From f52c645a8b0a3664c2520e70b46e248c984037ae Mon Sep 17 00:00:00 2001 From: chomosuke Date: Sat, 2 Nov 2024 09:18:38 + Subject: [PATCH] Add quick fix to automatically adds NOLINTNEXTLINE comment above clang-tidy warnings --- clang-tools-extra/clangd/CMakeLists.txt | 1 + clang-tools-extra/clangd/ClangdServer.cpp | 3 +- clang-tools-extra/clangd/Diagnostics.cpp | 23 +++- clang-tools-extra/clangd/Diagnostics.h| 12 +- clang-tools-extra/clangd/NoLintFixes.cpp | 99 +++ clang-tools-extra/clangd/NoLintFixes.h| 36 ++ clang-tools-extra/clangd/ParsedAST.cpp| 19 ++- .../fixits-codeaction-documentchanges.test| 47 .../clangd/test/fixits-codeaction.test| 41 +++ .../test/fixits-command-documentchanges.test | 62 ++ .../clangd/test/fixits-command.test | 50 .../clangd/unittests/ClangdLSPServerTests.cpp | 18 ++- .../clangd/unittests/DiagnosticsTests.cpp | 113 -- 13 files changed, 492 insertions(+), 32 deletions(-) create mode 100644 clang-tools-extra/clangd/NoLintFixes.cpp create mode 100644 clang-tools-extra/clangd/NoLintFixes.h diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt index d797ddce8c44d1..2a6433a5c3effd 100644 --- a/clang-tools-extra/clangd/CMakeLists.txt +++ b/clang-tools-extra/clangd/CMakeLists.txt @@ -98,6 +98,7 @@ add_clang_library(clangDaemon STATIC InlayHints.cpp JSONTransport.cpp ModulesBuilder.cpp + NoLintFixes.cpp PathMapping.cpp Protocol.cpp Quality.cpp diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 9b38be04e7ddd7..7f73b61b12c63f 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -15,6 +15,7 @@ #include "Format.h" #include "HeaderSourceSwitch.h" #include "InlayHints.h" +#include "NoLintFixes.h" #include "ParsedAST.h" #include "Preamble.h" #include "Protocol.h" @@ -661,7 +662,7 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) { bool IsClangTidyRename = Diag->Source == Diag::ClangTidy && Diag->Name == "readability-identifier-naming" && !Fix.Edits.empty(); - if (IsClangTidyRename && Diag->InsideMainFile) { + if (IsClangTidyRename && !isNoLintFixes(Fix) && Diag->InsideMainFile) { ClangdServer::CodeActionResult::Rename R; R.NewName = Fix.Edits.front().newText; R.FixMessage = Fix.Message; diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index a59d1e7ac84096..6948e12995bed1 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -9,6 +9,7 @@ #include "Diagnostics.h" #include "../clang-tidy/ClangTidyDiagnosticConsumer.h" #include "Compiler.h" +#include "NoLintFixes.h" #include "Protocol.h" #include "SourceCode.h" #include "support/Logger.h" @@ -311,8 +312,18 @@ std::string mainMessage(const Diag &D, const ClangdDiagnosticOptions &Opts) { std::string Result; llvm::raw_string_ostream OS(Result); OS << D.Message; - if (Opts.DisplayFixesCount && !D.Fixes.empty()) -OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)"; + + // NOLINT fixes are somewhat not real fixes and to say "(fix available)" when + // the fixes is just to suppress could be misleading. + int RealFixCount = D.Fixes.size(); + for (auto const &Fix : D.Fixes) { +if (isNoLintFixes(Fix)) { + RealFixCount--; +} + } + + if (Opts.DisplayFixesCount && RealFixCount > 0) +OS << " (" << (RealFixCount > 1 ? "fixes" : "fix") << " available)"; // If notes aren't emitted as structured info, add them to the message. if (!Opts.EmitRelatedLocations) for (auto &Note : D.Notes) { @@ -822,8 +833,8 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, LastDiagOriginallyError = OriginallyError; if (!Info.getFixItHints().empty()) AddFix(true /* try to invent a message instead of repeating the diag */); -if (Fixer) { - auto ExtraFixes = Fixer(LastDiag->Severity, Info); +if (MainFixer) { + auto ExtraFixes = MainFixer(*LastDiag, Info); LastDiag->Fixes.insert(LastDiag->Fixes.end(), ExtraFixes.begin(), ExtraFixes.end()); } @@ -841,8 +852,8 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, return; // Give include-fixer a chance to replace a note with a fix. -if (Fixer) { - auto ReplacementFixes = Fixer(LastDiag->Severity, Info); +if (NoteFixer) { + auto ReplacementFixes = NoteFixer(*LastDiag, Info); if (!ReplacementFixes.empty()) { assert(Info.getNumFixItHints() == 0 && "Include-fixer replaced a note with clang fix
[clang-tools-extra] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114660)
https://github.com/chomosuke created https://github.com/llvm/llvm-project/pull/114660 For some other lsp / linters. They will offer a "Ignore this error for this line" code actions for warnings. I find that convenient as I don't have to type the comment myself and copy the name of the diagnostics. This is the first time I work on such a large code base so any feedback and guidance are greatly appreciated. >From 1902b40e074d3ea461d9088a7d37a47b0e12d41e Mon Sep 17 00:00:00 2001 From: chomosuke Date: Sat, 2 Nov 2024 09:18:38 + Subject: [PATCH] Add quick fix to automatically adds NOLINTNEXTLINE comment above clang-tidy warnings --- clang-tools-extra/clangd/CMakeLists.txt | 1 + clang-tools-extra/clangd/ClangdServer.cpp | 7 +- clang-tools-extra/clangd/Diagnostics.cpp | 26 ++-- clang-tools-extra/clangd/Diagnostics.h| 12 +- clang-tools-extra/clangd/NoLintFixes.cpp | 99 +++ clang-tools-extra/clangd/NoLintFixes.h| 36 ++ clang-tools-extra/clangd/ParsedAST.cpp| 20 ++- .../fixits-codeaction-documentchanges.test| 47 +++ .../clangd/test/fixits-codeaction.test| 41 ++ .../test/fixits-command-documentchanges.test | 62 + .../clangd/test/fixits-command.test | 50 .../clangd/unittests/ClangdLSPServerTests.cpp | 16 ++- .../clangd/unittests/DiagnosticsTests.cpp | 120 +++--- 13 files changed, 500 insertions(+), 37 deletions(-) create mode 100644 clang-tools-extra/clangd/NoLintFixes.cpp create mode 100644 clang-tools-extra/clangd/NoLintFixes.h diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt index d797ddce8c44d1..2a6433a5c3effd 100644 --- a/clang-tools-extra/clangd/CMakeLists.txt +++ b/clang-tools-extra/clangd/CMakeLists.txt @@ -98,6 +98,7 @@ add_clang_library(clangDaemon STATIC InlayHints.cpp JSONTransport.cpp ModulesBuilder.cpp + NoLintFixes.cpp PathMapping.cpp Protocol.cpp Quality.cpp diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 9b38be04e7ddd7..925a015ae341bc 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -15,6 +15,7 @@ #include "Format.h" #include "HeaderSourceSwitch.h" #include "InlayHints.h" +#include "NoLintFixes.h" #include "ParsedAST.h" #include "Preamble.h" #include "Protocol.h" @@ -62,8 +63,8 @@ namespace clangd { namespace { // Tracks number of times a tweak has been offered. -static constexpr trace::Metric TweakAvailable( -"tweak_available", trace::Metric::Counter, "tweak_id"); +static constexpr trace::Metric +TweakAvailable("tweak_available", trace::Metric::Counter, "tweak_id"); // Update the FileIndex with new ASTs and plumb the diagnostics responses. struct UpdateIndexCallbacks : public ParsingCallbacks { @@ -661,7 +662,7 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) { bool IsClangTidyRename = Diag->Source == Diag::ClangTidy && Diag->Name == "readability-identifier-naming" && !Fix.Edits.empty(); - if (IsClangTidyRename && Diag->InsideMainFile) { + if (IsClangTidyRename && !isNoLintFixes(Fix) && Diag->InsideMainFile) { ClangdServer::CodeActionResult::Rename R; R.NewName = Fix.Edits.front().newText; R.FixMessage = Fix.Message; diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index a59d1e7ac84096..e42da2a9135e9b 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -9,6 +9,7 @@ #include "Diagnostics.h" #include "../clang-tidy/ClangTidyDiagnosticConsumer.h" #include "Compiler.h" +#include "NoLintFixes.h" #include "Protocol.h" #include "SourceCode.h" #include "support/Logger.h" @@ -311,8 +312,18 @@ std::string mainMessage(const Diag &D, const ClangdDiagnosticOptions &Opts) { std::string Result; llvm::raw_string_ostream OS(Result); OS << D.Message; - if (Opts.DisplayFixesCount && !D.Fixes.empty()) -OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)"; + + // NOLINT fixes are somewhat not real fixes and to say "(fix available)" when + // the fixes is just to suppress could be misleading. + int RealFixCount = D.Fixes.size(); + for (auto const &Fix : D.Fixes) { +if (isNoLintFixes(Fix)) { + RealFixCount--; +} + } + + if (Opts.DisplayFixesCount && RealFixCount > 0) +OS << " (" << (RealFixCount > 1 ? "fixes" : "fix") << " available)"; // If notes aren't emitted as structured info, add them to the message. if (!Opts.EmitRelatedLocations) for (auto &Note : D.Notes) { @@ -795,8 +806,7 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, } if (Message.empty()) // either !SyntheticMessage, or we failed to make one. Info.FormatDiagnostic(Message); -LastDiag->Fixes.push_
[clang-tools-extra] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114660)
https://github.com/chomosuke updated https://github.com/llvm/llvm-project/pull/114660 >From 3cc27f1a8880e2c31ce19d86e3bb74ce0b82fbec Mon Sep 17 00:00:00 2001 From: chomosuke Date: Sat, 2 Nov 2024 09:18:38 + Subject: [PATCH] Add quick fix to automatically adds NOLINTNEXTLINE comment above clang-tidy warnings --- clang-tools-extra/clangd/CMakeLists.txt | 1 + clang-tools-extra/clangd/ClangdServer.cpp | 7 +- clang-tools-extra/clangd/Diagnostics.cpp | 26 ++-- clang-tools-extra/clangd/Diagnostics.h| 12 +- clang-tools-extra/clangd/NoLintFixes.cpp | 99 +++ clang-tools-extra/clangd/NoLintFixes.h| 36 ++ clang-tools-extra/clangd/ParsedAST.cpp| 20 ++- .../fixits-codeaction-documentchanges.test| 47 +++ .../clangd/test/fixits-codeaction.test| 41 ++ .../test/fixits-command-documentchanges.test | 62 ++ .../clangd/test/fixits-command.test | 50 .../clangd/unittests/ClangdLSPServerTests.cpp | 16 ++- .../clangd/unittests/DiagnosticsTests.cpp | 117 +++--- 13 files changed, 497 insertions(+), 37 deletions(-) create mode 100644 clang-tools-extra/clangd/NoLintFixes.cpp create mode 100644 clang-tools-extra/clangd/NoLintFixes.h diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt index d797ddce8c44d1..2a6433a5c3effd 100644 --- a/clang-tools-extra/clangd/CMakeLists.txt +++ b/clang-tools-extra/clangd/CMakeLists.txt @@ -98,6 +98,7 @@ add_clang_library(clangDaemon STATIC InlayHints.cpp JSONTransport.cpp ModulesBuilder.cpp + NoLintFixes.cpp PathMapping.cpp Protocol.cpp Quality.cpp diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 9b38be04e7ddd7..925a015ae341bc 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -15,6 +15,7 @@ #include "Format.h" #include "HeaderSourceSwitch.h" #include "InlayHints.h" +#include "NoLintFixes.h" #include "ParsedAST.h" #include "Preamble.h" #include "Protocol.h" @@ -62,8 +63,8 @@ namespace clangd { namespace { // Tracks number of times a tweak has been offered. -static constexpr trace::Metric TweakAvailable( -"tweak_available", trace::Metric::Counter, "tweak_id"); +static constexpr trace::Metric +TweakAvailable("tweak_available", trace::Metric::Counter, "tweak_id"); // Update the FileIndex with new ASTs and plumb the diagnostics responses. struct UpdateIndexCallbacks : public ParsingCallbacks { @@ -661,7 +662,7 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) { bool IsClangTidyRename = Diag->Source == Diag::ClangTidy && Diag->Name == "readability-identifier-naming" && !Fix.Edits.empty(); - if (IsClangTidyRename && Diag->InsideMainFile) { + if (IsClangTidyRename && !isNoLintFixes(Fix) && Diag->InsideMainFile) { ClangdServer::CodeActionResult::Rename R; R.NewName = Fix.Edits.front().newText; R.FixMessage = Fix.Message; diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index a59d1e7ac84096..e42da2a9135e9b 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -9,6 +9,7 @@ #include "Diagnostics.h" #include "../clang-tidy/ClangTidyDiagnosticConsumer.h" #include "Compiler.h" +#include "NoLintFixes.h" #include "Protocol.h" #include "SourceCode.h" #include "support/Logger.h" @@ -311,8 +312,18 @@ std::string mainMessage(const Diag &D, const ClangdDiagnosticOptions &Opts) { std::string Result; llvm::raw_string_ostream OS(Result); OS << D.Message; - if (Opts.DisplayFixesCount && !D.Fixes.empty()) -OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)"; + + // NOLINT fixes are somewhat not real fixes and to say "(fix available)" when + // the fixes is just to suppress could be misleading. + int RealFixCount = D.Fixes.size(); + for (auto const &Fix : D.Fixes) { +if (isNoLintFixes(Fix)) { + RealFixCount--; +} + } + + if (Opts.DisplayFixesCount && RealFixCount > 0) +OS << " (" << (RealFixCount > 1 ? "fixes" : "fix") << " available)"; // If notes aren't emitted as structured info, add them to the message. if (!Opts.EmitRelatedLocations) for (auto &Note : D.Notes) { @@ -795,8 +806,7 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, } if (Message.empty()) // either !SyntheticMessage, or we failed to make one. Info.FormatDiagnostic(Message); -LastDiag->Fixes.push_back( -Fix{std::string(Message), std::move(Edits), {}}); +LastDiag->Fixes.push_back(Fix{std::string(Message), std::move(Edits), {}}); return true; }; @@ -822,8 +832,8 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, LastDiagOriginallyError = OriginallyError; if (!Info.g
[clang-tools-extra] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114660)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: Richard Li (chomosuke) Changes For some other lsp / linters. They will offer a "Ignore this error for this line" code actions for warnings. I find that convenient as I don't have to type the comment myself and copy the name of the diagnostics. This is the first time I work on such a large code base so any feedback and guidance are greatly appreciated. --- Patch is 32.58 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/114660.diff 13 Files Affected: - (modified) clang-tools-extra/clangd/CMakeLists.txt (+1) - (modified) clang-tools-extra/clangd/ClangdServer.cpp (+4-3) - (modified) clang-tools-extra/clangd/Diagnostics.cpp (+18-8) - (modified) clang-tools-extra/clangd/Diagnostics.h (+8-4) - (added) clang-tools-extra/clangd/NoLintFixes.cpp (+99) - (added) clang-tools-extra/clangd/NoLintFixes.h (+36) - (modified) clang-tools-extra/clangd/ParsedAST.cpp (+16-4) - (modified) clang-tools-extra/clangd/test/fixits-codeaction-documentchanges.test (+47) - (modified) clang-tools-extra/clangd/test/fixits-codeaction.test (+41) - (modified) clang-tools-extra/clangd/test/fixits-command-documentchanges.test (+62) - (modified) clang-tools-extra/clangd/test/fixits-command.test (+50) - (modified) clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp (+13-3) - (modified) clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp (+102-15) ``diff diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt index d797ddce8c44d1..2a6433a5c3effd 100644 --- a/clang-tools-extra/clangd/CMakeLists.txt +++ b/clang-tools-extra/clangd/CMakeLists.txt @@ -98,6 +98,7 @@ add_clang_library(clangDaemon STATIC InlayHints.cpp JSONTransport.cpp ModulesBuilder.cpp + NoLintFixes.cpp PathMapping.cpp Protocol.cpp Quality.cpp diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 9b38be04e7ddd7..925a015ae341bc 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -15,6 +15,7 @@ #include "Format.h" #include "HeaderSourceSwitch.h" #include "InlayHints.h" +#include "NoLintFixes.h" #include "ParsedAST.h" #include "Preamble.h" #include "Protocol.h" @@ -62,8 +63,8 @@ namespace clangd { namespace { // Tracks number of times a tweak has been offered. -static constexpr trace::Metric TweakAvailable( -"tweak_available", trace::Metric::Counter, "tweak_id"); +static constexpr trace::Metric +TweakAvailable("tweak_available", trace::Metric::Counter, "tweak_id"); // Update the FileIndex with new ASTs and plumb the diagnostics responses. struct UpdateIndexCallbacks : public ParsingCallbacks { @@ -661,7 +662,7 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) { bool IsClangTidyRename = Diag->Source == Diag::ClangTidy && Diag->Name == "readability-identifier-naming" && !Fix.Edits.empty(); - if (IsClangTidyRename && Diag->InsideMainFile) { + if (IsClangTidyRename && !isNoLintFixes(Fix) && Diag->InsideMainFile) { ClangdServer::CodeActionResult::Rename R; R.NewName = Fix.Edits.front().newText; R.FixMessage = Fix.Message; diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index a59d1e7ac84096..e42da2a9135e9b 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -9,6 +9,7 @@ #include "Diagnostics.h" #include "../clang-tidy/ClangTidyDiagnosticConsumer.h" #include "Compiler.h" +#include "NoLintFixes.h" #include "Protocol.h" #include "SourceCode.h" #include "support/Logger.h" @@ -311,8 +312,18 @@ std::string mainMessage(const Diag &D, const ClangdDiagnosticOptions &Opts) { std::string Result; llvm::raw_string_ostream OS(Result); OS << D.Message; - if (Opts.DisplayFixesCount && !D.Fixes.empty()) -OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)"; + + // NOLINT fixes are somewhat not real fixes and to say "(fix available)" when + // the fixes is just to suppress could be misleading. + int RealFixCount = D.Fixes.size(); + for (auto const &Fix : D.Fixes) { +if (isNoLintFixes(Fix)) { + RealFixCount--; +} + } + + if (Opts.DisplayFixesCount && RealFixCount > 0) +OS << " (" << (RealFixCount > 1 ? "fixes" : "fix") << " available)"; // If notes aren't emitted as structured info, add them to the message. if (!Opts.EmitRelatedLocations) for (auto &Note : D.Notes) { @@ -795,8 +806,7 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, } if (Message.empty()) // either !SyntheticMessage, or we failed to make one. Info.FormatDiagnostic(Message); -LastDiag->Fixes.push_back( -Fix{std::string(Message), std::move(Edits), {}}); +LastDiag->Fixes.push_back(Fix{std::string(Mess
[clang-tools-extra] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114660)
llvmbot wrote: @llvm/pr-subscribers-clangd Author: Richard Li (chomosuke) Changes For some other lsp / linters. They will offer a "Ignore this error for this line" code actions for warnings. I find that convenient as I don't have to type the comment myself and copy the name of the diagnostics. This is the first time I work on such a large code base so any feedback and guidance are greatly appreciated. --- Patch is 32.58 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/114660.diff 13 Files Affected: - (modified) clang-tools-extra/clangd/CMakeLists.txt (+1) - (modified) clang-tools-extra/clangd/ClangdServer.cpp (+4-3) - (modified) clang-tools-extra/clangd/Diagnostics.cpp (+18-8) - (modified) clang-tools-extra/clangd/Diagnostics.h (+8-4) - (added) clang-tools-extra/clangd/NoLintFixes.cpp (+99) - (added) clang-tools-extra/clangd/NoLintFixes.h (+36) - (modified) clang-tools-extra/clangd/ParsedAST.cpp (+16-4) - (modified) clang-tools-extra/clangd/test/fixits-codeaction-documentchanges.test (+47) - (modified) clang-tools-extra/clangd/test/fixits-codeaction.test (+41) - (modified) clang-tools-extra/clangd/test/fixits-command-documentchanges.test (+62) - (modified) clang-tools-extra/clangd/test/fixits-command.test (+50) - (modified) clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp (+13-3) - (modified) clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp (+102-15) ``diff diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt index d797ddce8c44d1..2a6433a5c3effd 100644 --- a/clang-tools-extra/clangd/CMakeLists.txt +++ b/clang-tools-extra/clangd/CMakeLists.txt @@ -98,6 +98,7 @@ add_clang_library(clangDaemon STATIC InlayHints.cpp JSONTransport.cpp ModulesBuilder.cpp + NoLintFixes.cpp PathMapping.cpp Protocol.cpp Quality.cpp diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 9b38be04e7ddd7..925a015ae341bc 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -15,6 +15,7 @@ #include "Format.h" #include "HeaderSourceSwitch.h" #include "InlayHints.h" +#include "NoLintFixes.h" #include "ParsedAST.h" #include "Preamble.h" #include "Protocol.h" @@ -62,8 +63,8 @@ namespace clangd { namespace { // Tracks number of times a tweak has been offered. -static constexpr trace::Metric TweakAvailable( -"tweak_available", trace::Metric::Counter, "tweak_id"); +static constexpr trace::Metric +TweakAvailable("tweak_available", trace::Metric::Counter, "tweak_id"); // Update the FileIndex with new ASTs and plumb the diagnostics responses. struct UpdateIndexCallbacks : public ParsingCallbacks { @@ -661,7 +662,7 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) { bool IsClangTidyRename = Diag->Source == Diag::ClangTidy && Diag->Name == "readability-identifier-naming" && !Fix.Edits.empty(); - if (IsClangTidyRename && Diag->InsideMainFile) { + if (IsClangTidyRename && !isNoLintFixes(Fix) && Diag->InsideMainFile) { ClangdServer::CodeActionResult::Rename R; R.NewName = Fix.Edits.front().newText; R.FixMessage = Fix.Message; diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index a59d1e7ac84096..e42da2a9135e9b 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -9,6 +9,7 @@ #include "Diagnostics.h" #include "../clang-tidy/ClangTidyDiagnosticConsumer.h" #include "Compiler.h" +#include "NoLintFixes.h" #include "Protocol.h" #include "SourceCode.h" #include "support/Logger.h" @@ -311,8 +312,18 @@ std::string mainMessage(const Diag &D, const ClangdDiagnosticOptions &Opts) { std::string Result; llvm::raw_string_ostream OS(Result); OS << D.Message; - if (Opts.DisplayFixesCount && !D.Fixes.empty()) -OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)"; + + // NOLINT fixes are somewhat not real fixes and to say "(fix available)" when + // the fixes is just to suppress could be misleading. + int RealFixCount = D.Fixes.size(); + for (auto const &Fix : D.Fixes) { +if (isNoLintFixes(Fix)) { + RealFixCount--; +} + } + + if (Opts.DisplayFixesCount && RealFixCount > 0) +OS << " (" << (RealFixCount > 1 ? "fixes" : "fix") << " available)"; // If notes aren't emitted as structured info, add them to the message. if (!Opts.EmitRelatedLocations) for (auto &Note : D.Notes) { @@ -795,8 +806,7 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, } if (Message.empty()) // either !SyntheticMessage, or we failed to make one. Info.FormatDiagnostic(Message); -LastDiag->Fixes.push_back( -Fix{std::string(Message), std::move(Edits), {}}); +LastDiag->Fixes.push_back(Fix{std::string(Message), std::
[clang-tools-extra] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114660)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/114660 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114660)
https://github.com/chomosuke updated https://github.com/llvm/llvm-project/pull/114660 >From 3cc27f1a8880e2c31ce19d86e3bb74ce0b82fbec Mon Sep 17 00:00:00 2001 From: chomosuke Date: Sat, 2 Nov 2024 09:18:38 + Subject: [PATCH] Add quick fix to automatically adds NOLINTNEXTLINE comment above clang-tidy warnings --- clang-tools-extra/clangd/CMakeLists.txt | 1 + clang-tools-extra/clangd/ClangdServer.cpp | 7 +- clang-tools-extra/clangd/Diagnostics.cpp | 26 ++-- clang-tools-extra/clangd/Diagnostics.h| 12 +- clang-tools-extra/clangd/NoLintFixes.cpp | 99 +++ clang-tools-extra/clangd/NoLintFixes.h| 36 ++ clang-tools-extra/clangd/ParsedAST.cpp| 20 ++- .../fixits-codeaction-documentchanges.test| 47 +++ .../clangd/test/fixits-codeaction.test| 41 ++ .../test/fixits-command-documentchanges.test | 62 ++ .../clangd/test/fixits-command.test | 50 .../clangd/unittests/ClangdLSPServerTests.cpp | 16 ++- .../clangd/unittests/DiagnosticsTests.cpp | 117 +++--- 13 files changed, 497 insertions(+), 37 deletions(-) create mode 100644 clang-tools-extra/clangd/NoLintFixes.cpp create mode 100644 clang-tools-extra/clangd/NoLintFixes.h diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt index d797ddce8c44d1..2a6433a5c3effd 100644 --- a/clang-tools-extra/clangd/CMakeLists.txt +++ b/clang-tools-extra/clangd/CMakeLists.txt @@ -98,6 +98,7 @@ add_clang_library(clangDaemon STATIC InlayHints.cpp JSONTransport.cpp ModulesBuilder.cpp + NoLintFixes.cpp PathMapping.cpp Protocol.cpp Quality.cpp diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 9b38be04e7ddd7..925a015ae341bc 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -15,6 +15,7 @@ #include "Format.h" #include "HeaderSourceSwitch.h" #include "InlayHints.h" +#include "NoLintFixes.h" #include "ParsedAST.h" #include "Preamble.h" #include "Protocol.h" @@ -62,8 +63,8 @@ namespace clangd { namespace { // Tracks number of times a tweak has been offered. -static constexpr trace::Metric TweakAvailable( -"tweak_available", trace::Metric::Counter, "tweak_id"); +static constexpr trace::Metric +TweakAvailable("tweak_available", trace::Metric::Counter, "tweak_id"); // Update the FileIndex with new ASTs and plumb the diagnostics responses. struct UpdateIndexCallbacks : public ParsingCallbacks { @@ -661,7 +662,7 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) { bool IsClangTidyRename = Diag->Source == Diag::ClangTidy && Diag->Name == "readability-identifier-naming" && !Fix.Edits.empty(); - if (IsClangTidyRename && Diag->InsideMainFile) { + if (IsClangTidyRename && !isNoLintFixes(Fix) && Diag->InsideMainFile) { ClangdServer::CodeActionResult::Rename R; R.NewName = Fix.Edits.front().newText; R.FixMessage = Fix.Message; diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index a59d1e7ac84096..e42da2a9135e9b 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -9,6 +9,7 @@ #include "Diagnostics.h" #include "../clang-tidy/ClangTidyDiagnosticConsumer.h" #include "Compiler.h" +#include "NoLintFixes.h" #include "Protocol.h" #include "SourceCode.h" #include "support/Logger.h" @@ -311,8 +312,18 @@ std::string mainMessage(const Diag &D, const ClangdDiagnosticOptions &Opts) { std::string Result; llvm::raw_string_ostream OS(Result); OS << D.Message; - if (Opts.DisplayFixesCount && !D.Fixes.empty()) -OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)"; + + // NOLINT fixes are somewhat not real fixes and to say "(fix available)" when + // the fixes is just to suppress could be misleading. + int RealFixCount = D.Fixes.size(); + for (auto const &Fix : D.Fixes) { +if (isNoLintFixes(Fix)) { + RealFixCount--; +} + } + + if (Opts.DisplayFixesCount && RealFixCount > 0) +OS << " (" << (RealFixCount > 1 ? "fixes" : "fix") << " available)"; // If notes aren't emitted as structured info, add them to the message. if (!Opts.EmitRelatedLocations) for (auto &Note : D.Notes) { @@ -795,8 +806,7 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, } if (Message.empty()) // either !SyntheticMessage, or we failed to make one. Info.FormatDiagnostic(Message); -LastDiag->Fixes.push_back( -Fix{std::string(Message), std::move(Edits), {}}); +LastDiag->Fixes.push_back(Fix{std::string(Message), std::move(Edits), {}}); return true; }; @@ -822,8 +832,8 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, LastDiagOriginallyError = OriginallyError; if (!Info.g
[clang-tools-extra] [clangd] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114660)
https://github.com/chomosuke edited https://github.com/llvm/llvm-project/pull/114660 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114660)
https://github.com/chomosuke closed https://github.com/llvm/llvm-project/pull/114660 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114661)
https://github.com/chomosuke created https://github.com/llvm/llvm-project/pull/114661 For some other lsp / linters. They will offer a "Ignore this error for this line" code actions for warnings. I find that convenient as I don't have to type the comment myself and copy the name of the diagnostics. This PR implements this for clangd. For all diagnostics from clang-tidy, this PR adds an extra quick fix to insert a // NOLINTNEXTLINE(diag-name) to suppress the diagnostics. This is the first time I work on such a large code base so any feedback and guidance are greatly appreciated. >From f52c645a8b0a3664c2520e70b46e248c984037ae Mon Sep 17 00:00:00 2001 From: chomosuke Date: Sat, 2 Nov 2024 09:18:38 + Subject: [PATCH] Add quick fix to automatically adds NOLINTNEXTLINE comment above clang-tidy warnings --- clang-tools-extra/clangd/CMakeLists.txt | 1 + clang-tools-extra/clangd/ClangdServer.cpp | 3 +- clang-tools-extra/clangd/Diagnostics.cpp | 23 +++- clang-tools-extra/clangd/Diagnostics.h| 12 +- clang-tools-extra/clangd/NoLintFixes.cpp | 99 +++ clang-tools-extra/clangd/NoLintFixes.h| 36 ++ clang-tools-extra/clangd/ParsedAST.cpp| 19 ++- .../fixits-codeaction-documentchanges.test| 47 .../clangd/test/fixits-codeaction.test| 41 +++ .../test/fixits-command-documentchanges.test | 62 ++ .../clangd/test/fixits-command.test | 50 .../clangd/unittests/ClangdLSPServerTests.cpp | 18 ++- .../clangd/unittests/DiagnosticsTests.cpp | 113 -- 13 files changed, 492 insertions(+), 32 deletions(-) create mode 100644 clang-tools-extra/clangd/NoLintFixes.cpp create mode 100644 clang-tools-extra/clangd/NoLintFixes.h diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt index d797ddce8c44d1..2a6433a5c3effd 100644 --- a/clang-tools-extra/clangd/CMakeLists.txt +++ b/clang-tools-extra/clangd/CMakeLists.txt @@ -98,6 +98,7 @@ add_clang_library(clangDaemon STATIC InlayHints.cpp JSONTransport.cpp ModulesBuilder.cpp + NoLintFixes.cpp PathMapping.cpp Protocol.cpp Quality.cpp diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 9b38be04e7ddd7..7f73b61b12c63f 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -15,6 +15,7 @@ #include "Format.h" #include "HeaderSourceSwitch.h" #include "InlayHints.h" +#include "NoLintFixes.h" #include "ParsedAST.h" #include "Preamble.h" #include "Protocol.h" @@ -661,7 +662,7 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) { bool IsClangTidyRename = Diag->Source == Diag::ClangTidy && Diag->Name == "readability-identifier-naming" && !Fix.Edits.empty(); - if (IsClangTidyRename && Diag->InsideMainFile) { + if (IsClangTidyRename && !isNoLintFixes(Fix) && Diag->InsideMainFile) { ClangdServer::CodeActionResult::Rename R; R.NewName = Fix.Edits.front().newText; R.FixMessage = Fix.Message; diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index a59d1e7ac84096..6948e12995bed1 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -9,6 +9,7 @@ #include "Diagnostics.h" #include "../clang-tidy/ClangTidyDiagnosticConsumer.h" #include "Compiler.h" +#include "NoLintFixes.h" #include "Protocol.h" #include "SourceCode.h" #include "support/Logger.h" @@ -311,8 +312,18 @@ std::string mainMessage(const Diag &D, const ClangdDiagnosticOptions &Opts) { std::string Result; llvm::raw_string_ostream OS(Result); OS << D.Message; - if (Opts.DisplayFixesCount && !D.Fixes.empty()) -OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)"; + + // NOLINT fixes are somewhat not real fixes and to say "(fix available)" when + // the fixes is just to suppress could be misleading. + int RealFixCount = D.Fixes.size(); + for (auto const &Fix : D.Fixes) { +if (isNoLintFixes(Fix)) { + RealFixCount--; +} + } + + if (Opts.DisplayFixesCount && RealFixCount > 0) +OS << " (" << (RealFixCount > 1 ? "fixes" : "fix") << " available)"; // If notes aren't emitted as structured info, add them to the message. if (!Opts.EmitRelatedLocations) for (auto &Note : D.Notes) { @@ -822,8 +833,8 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, LastDiagOriginallyError = OriginallyError; if (!Info.getFixItHints().empty()) AddFix(true /* try to invent a message instead of repeating the diag */); -if (Fixer) { - auto ExtraFixes = Fixer(LastDiag->Severity, Info); +if (MainFixer) { + auto ExtraFixes = MainFixer(*LastDiag, Info); LastDiag->Fixes.insert(LastDiag->Fixes.end(), ExtraFixes.begin(), ExtraF
[clang-tools-extra] [clangd] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114661)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/114661 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114661)
https://github.com/chomosuke updated https://github.com/llvm/llvm-project/pull/114661 >From 7b70b905e5a9942f592316b407135975977c93cb Mon Sep 17 00:00:00 2001 From: chomosuke Date: Fri, 16 Aug 2024 13:31:21 + Subject: [PATCH 01/19] Fixing one error --- clang-tools-extra/clangd/ClangdServer.cpp | 23 ++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 9b38be04e7ddd7..e08ce12223f6b0 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -44,6 +44,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" +#include "llvm/Support/Format.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include @@ -672,6 +673,21 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) { return std::nullopt; } +// Add NOLINT insert as code actions +std::optional tryAddClangTidySuppression(const Diag *Diag) { + if (Diag->Source == Diag::ClangTidy) { +Fix F; +F.Message = llvm::formatv("ignore [{0}] for this line", Diag->Name); +TextEdit &E = F.Edits.emplace_back(); +E.newText = llvm::formatv("// NOLINTNEXTLINE({0})\n", Diag->Name); +Position InsertPos = Diag->Range.start; +InsertPos.character = 0; +E.range = {InsertPos, InsertPos}; +return F; + } + return std::nullopt; +} + } // namespace void ClangdServer::codeAction(const CodeActionInputs &Params, @@ -701,7 +717,7 @@ void ClangdServer::codeAction(const CodeActionInputs &Params, return nullptr; }; for (const auto &DiagRef : Params.Diagnostics) { -if (const auto *Diag = FindMatchedDiag(DiagRef)) +if (const auto *Diag = FindMatchedDiag(DiagRef)) { for (const auto &Fix : Diag->Fixes) { if (auto Rename = tryConvertToRename(Diag, Fix)) { Result.Renames.emplace_back(std::move(*Rename)); @@ -709,6 +725,11 @@ void ClangdServer::codeAction(const CodeActionInputs &Params, Result.QuickFixes.push_back({DiagRef, Fix}); } } + + if (auto Fix = tryAddClangTidySuppression(Diag)) { +Result.QuickFixes.push_back({DiagRef, std::move(*Fix)}); + } +} } } >From d5deb1d93e994f44d6b4d932e261a3bd9a42dcc8 Mon Sep 17 00:00:00 2001 From: chomosuke Date: Sun, 18 Aug 2024 17:15:21 + Subject: [PATCH 02/19] Revert "Fixing one error" This reverts commit 17989044ad480628a2f7814674dbe7cd985abd17. --- clang-tools-extra/clangd/ClangdServer.cpp | 23 +-- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index e08ce12223f6b0..9b38be04e7ddd7 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -44,7 +44,6 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" -#include "llvm/Support/Format.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include @@ -673,21 +672,6 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) { return std::nullopt; } -// Add NOLINT insert as code actions -std::optional tryAddClangTidySuppression(const Diag *Diag) { - if (Diag->Source == Diag::ClangTidy) { -Fix F; -F.Message = llvm::formatv("ignore [{0}] for this line", Diag->Name); -TextEdit &E = F.Edits.emplace_back(); -E.newText = llvm::formatv("// NOLINTNEXTLINE({0})\n", Diag->Name); -Position InsertPos = Diag->Range.start; -InsertPos.character = 0; -E.range = {InsertPos, InsertPos}; -return F; - } - return std::nullopt; -} - } // namespace void ClangdServer::codeAction(const CodeActionInputs &Params, @@ -717,7 +701,7 @@ void ClangdServer::codeAction(const CodeActionInputs &Params, return nullptr; }; for (const auto &DiagRef : Params.Diagnostics) { -if (const auto *Diag = FindMatchedDiag(DiagRef)) { +if (const auto *Diag = FindMatchedDiag(DiagRef)) for (const auto &Fix : Diag->Fixes) { if (auto Rename = tryConvertToRename(Diag, Fix)) { Result.Renames.emplace_back(std::move(*Rename)); @@ -725,11 +709,6 @@ void ClangdServer::codeAction(const CodeActionInputs &Params, Result.QuickFixes.push_back({DiagRef, Fix}); } } - - if (auto Fix = tryAddClangTidySuppression(Diag)) { -Result.QuickFixes.push_back({DiagRef, std::move(*Fix)}); - } -} } } >From 355a32406ae0ce93aed941c4865b040009289c82 Mon Sep 17 00:00:00 2001 From: chomosuke Date: Mon, 19 Aug 2024 15:17:05 + Subject: [PATCH 03/19] inserted NOLINT with indent Retrieved CurLine and PrevLine --- clang-tools-extra/clangd/Diagnostics.cpp | 4 +- clang-tools-extra/cl
[clang-tools-extra] [clangd] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114660)
https://github.com/chomosuke edited https://github.com/llvm/llvm-project/pull/114660 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 67c8b0e - [clang][NFC] Remove an unnecessary variable in CheckExprLifetime.cpp
Author: Haojian Wu Date: 2024-11-02T12:00:18+01:00 New Revision: 67c8b0efbe5c783f39556be2ee841441b50600b5 URL: https://github.com/llvm/llvm-project/commit/67c8b0efbe5c783f39556be2ee841441b50600b5 DIFF: https://github.com/llvm/llvm-project/commit/67c8b0efbe5c783f39556be2ee841441b50600b5.diff LOG: [clang][NFC] Remove an unnecessary variable in CheckExprLifetime.cpp Added: Modified: clang/lib/Sema/CheckExprLifetime.cpp Removed: diff --git a/clang/lib/Sema/CheckExprLifetime.cpp b/clang/lib/Sema/CheckExprLifetime.cpp index 7f9b484ef6c05d..3baa8cb3394092 100644 --- a/clang/lib/Sema/CheckExprLifetime.cpp +++ b/clang/lib/Sema/CheckExprLifetime.cpp @@ -1132,7 +1132,6 @@ static void checkExprLifetimeImpl(Sema &SemaRef, auto *MTE = dyn_cast(L); bool IsGslPtrValueFromGslTempOwner = false; -bool IsLocalGslOwner = false; if (pathOnlyHandlesGslPointer(Path)) { if (isa(L)) { // We do not want to follow the references when returning a pointer @@ -1140,8 +1139,8 @@ static void checkExprLifetimeImpl(Sema &SemaRef, // int &p = *localUniquePtr; // someContainer.add(std::move(localUniquePtr)); // return p; -IsLocalGslOwner = isRecordWithAttr(L->getType()); -if (pathContainsInit(Path) || !IsLocalGslOwner) +if (pathContainsInit(Path) || +!isRecordWithAttr(L->getType())) return false; } else { IsGslPtrValueFromGslTempOwner = ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Extend bugprone-use-after-move check to handle std::optional::reset() and std::any::reset() (PR #114255)
@@ -279,7 +281,7 @@ void UseAfterMoveFinder::getDeclRefs( if (DeclRef && BlockMap->blockContainingStmt(DeclRef) == Block) { // Ignore uses of a standard smart pointer that don't dereference the // pointer. - if (Operator || !isStandardSmartPointer(DeclRef->getDecl())) { + if (Operator || !isStandardResettableOwner(DeclRef->getDecl())) { 5chmidti wrote: > `std::optional::has_value` seems OK (it's no different than `operator==(const > std::unique_ptr &, std::nullptr_t)`, both of which are OK as they don't > actually access the moved-from value)+ [...] I'm kind of torn here. I'd much rather prioritize C++17 over C++23, since I expect `reset` to be used much more, but the monadic operators might eventually become commonplace too. Actually, it is for `optional` and `any` (though `any` is left in a fully unspecified state, unlike `optional`). It's not just the monadic operators, but e.g., `has_value` together with `value` (etc.): https://godbolt.org/z/hc4MEPWj8 ```c++ #include #include #include void sink(std::optional> b) { if (b.has_value()) { std::cout << "moved to: " << b.value().front() << '\n' << std::flush; } } int main() { auto a = std::optional>{{42}}; sink(std::move(a)); if (a.has_value()) { // moved-from optional `a` still returns true here // accessing moved from contained object std::cout << "moved from: " << a.value().front() << '\n' << std::flush; } } ``` Both post-move accesses would not be considered as accessing the contained value due to the focus on the dereferencing operators of smart pointers. > But then again, it seems(?) the fact that we don't warn on `operator==` is > just an accident caused by it being a non-member, not intentional? All operations except `operator*`, `operator->` or `operator[]` are completely fine from what I can tell. The ptr of smart pointers is set to `nullptr`, which allows for things like `operator==` or `operator bool` to be valid uses, because unlike `optional` they don't return `true` when the internal object has been moved from/is a `nullptr` (`weak_ptr` is different, but has similar semantics to the other smart pointers). > I guess, in theory, what we need to do here is to distinguish the different > methods [...] > Barring that, a blanket rule should either allow ~all members, or prohibit > ~all members. For `optional` and `any` I'd say we swap the logic around and only allow `reset`, `emplace` and assignments (already exists) as resetting the state, and warn on anything else, while the smart_ptr case only disallows the operators it does right now. > but I don't really have the bandwidth to try to figure out how to implement > that... I would've said that this PR should be blocked until the above is handled correctly, but actually, the PR as is, is removing some false-positives by considering the calls to `reset` as resetting the state. So there are no real negatives attached to this PR, that weren't there before, it's only improving the state. The changes outlined above make some negatives positives, which could be done in a follow-up (+issue in case you do not end up implementing it) (in one go would be nicer, of course). https://github.com/llvm/llvm-project/pull/114255 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] fix crash in altera-id-dependent-backward-branch (PR #113833)
https://github.com/5chmidti closed https://github.com/llvm/llvm-project/pull/113833 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] 0edaba1 - [clang-tidy] fix crash in altera-id-dependent-backward-branch (#113833)
Author: Julian Schmidt Date: 2024-11-02T12:08:35+01:00 New Revision: 0edaba1b29f8eee011e5fdf387d6c786ec6cb52f URL: https://github.com/llvm/llvm-project/commit/0edaba1b29f8eee011e5fdf387d6c786ec6cb52f DIFF: https://github.com/llvm/llvm-project/commit/0edaba1b29f8eee011e5fdf387d6c786ec6cb52f.diff LOG: [clang-tidy] fix crash in altera-id-dependent-backward-branch (#113833) Add some checks for `nullptr` and change some `dyn_cast` to `dyn_cast_if_present` to avoid crashes. Fixes #55408 Added: Modified: clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp Removed: diff --git a/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp b/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp index 09f7d8c5c2f952..94db0a793cf53d 100644 --- a/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp +++ b/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp @@ -78,16 +78,22 @@ void IdDependentBackwardBranchCheck::registerMatchers(MatchFinder *Finder) { IdDependentBackwardBranchCheck::IdDependencyRecord * IdDependentBackwardBranchCheck::hasIdDepVar(const Expr *Expression) { + if (!Expression) +return nullptr; + if (const auto *Declaration = dyn_cast(Expression)) { // It is a DeclRefExpr, so check if it's an ID-dependent variable. -const auto *CheckVariable = dyn_cast(Declaration->getDecl()); +const auto *CheckVariable = +dyn_cast_if_present(Declaration->getDecl()); +if (!CheckVariable) + return nullptr; auto FoundVariable = IdDepVarsMap.find(CheckVariable); if (FoundVariable == IdDepVarsMap.end()) return nullptr; return &(FoundVariable->second); } for (const auto *Child : Expression->children()) -if (const auto *ChildExpression = dyn_cast(Child)) +if (const auto *ChildExpression = dyn_cast_if_present(Child)) if (IdDependencyRecord *Result = hasIdDepVar(ChildExpression)) return Result; return nullptr; @@ -95,16 +101,21 @@ IdDependentBackwardBranchCheck::hasIdDepVar(const Expr *Expression) { IdDependentBackwardBranchCheck::IdDependencyRecord * IdDependentBackwardBranchCheck::hasIdDepField(const Expr *Expression) { + if (!Expression) +return nullptr; + if (const auto *MemberExpression = dyn_cast(Expression)) { const auto *CheckField = -dyn_cast(MemberExpression->getMemberDecl()); +dyn_cast_if_present(MemberExpression->getMemberDecl()); +if (!CheckField) + return nullptr; auto FoundField = IdDepFieldsMap.find(CheckField); if (FoundField == IdDepFieldsMap.end()) return nullptr; return &(FoundField->second); } for (const auto *Child : Expression->children()) -if (const auto *ChildExpression = dyn_cast(Child)) +if (const auto *ChildExpression = dyn_cast_if_present(Child)) if (IdDependencyRecord *Result = hasIdDepField(ChildExpression)) return Result; return nullptr; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 2c71e1fcb747bc..51ba157ab05deb 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -147,6 +147,10 @@ New check aliases Changes in existing checks ^^ +- Improved :doc:`altera-id-dependent-backward-branch + ` check by fixing + crashes from invalid code. + - Improved :doc:`bugprone-casting-through-void ` check to suggest replacing the offending code with ``reinterpret_cast``, to more clearly express intent. diff --git a/clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp b/clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp index c0a75fae98d757..6137e6f929dc08 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy %s altera-id-dependent-backward-branch %t -- -header-filter=.* "--" -cl-std=CL1.2 -c +// RUN: %check_clang_tidy %s altera-id-dependent-backward-branch %t -- -header-filter=.* "--" -cl-std=CLC++1.0 -c void error() { // Conditional Expressions @@ -80,3 +80,9 @@ void success() { } } } + +template +void gh55408(char const input[], int pos) { + while (((input[pos] != STOP) && ...)); +} + ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 2804762 - [clang][NFC] Use const reference for IndirectLocalPath if possible.
Author: Haojian Wu Date: 2024-11-02T12:09:52+01:00 New Revision: 2804762e2643c793d12eeabf422b81f4de80ceea URL: https://github.com/llvm/llvm-project/commit/2804762e2643c793d12eeabf422b81f4de80ceea DIFF: https://github.com/llvm/llvm-project/commit/2804762e2643c793d12eeabf422b81f4de80ceea.diff LOG: [clang][NFC] Use const reference for IndirectLocalPath if possible. Added: Modified: clang/lib/Sema/CheckExprLifetime.cpp Removed: diff --git a/clang/lib/Sema/CheckExprLifetime.cpp b/clang/lib/Sema/CheckExprLifetime.cpp index 3baa8cb3394092..a1a402b4a2b530 100644 --- a/clang/lib/Sema/CheckExprLifetime.cpp +++ b/clang/lib/Sema/CheckExprLifetime.cpp @@ -226,14 +226,14 @@ using LocalVisitor = llvm::function_ref; } // namespace -static bool isVarOnPath(IndirectLocalPath &Path, VarDecl *VD) { +static bool isVarOnPath(const IndirectLocalPath &Path, VarDecl *VD) { for (auto E : Path) if (E.Kind == IndirectLocalPathEntry::VarInit && E.D == VD) return true; return false; } -static bool pathContainsInit(IndirectLocalPath &Path) { +static bool pathContainsInit(const IndirectLocalPath &Path) { return llvm::any_of(Path, [=](IndirectLocalPathEntry E) { return E.Kind == IndirectLocalPathEntry::DefaultInit || E.Kind == IndirectLocalPathEntry::VarInit; @@ -1076,7 +1076,7 @@ static SourceRange nextPathEntryRange(const IndirectLocalPath &Path, unsigned I, return E->getSourceRange(); } -static bool pathOnlyHandlesGslPointer(IndirectLocalPath &Path) { +static bool pathOnlyHandlesGslPointer(const IndirectLocalPath &Path) { for (const auto &It : llvm::reverse(Path)) { switch (It.Kind) { case IndirectLocalPathEntry::VarInit: @@ -1124,7 +1124,7 @@ static void checkExprLifetimeImpl(Sema &SemaRef, // FIXME: consider moving the TemporaryVisitor and visitLocalsRetained* // functions to a dedicated class. - auto TemporaryVisitor = [&](IndirectLocalPath &Path, Local L, + auto TemporaryVisitor = [&](const IndirectLocalPath &Path, Local L, ReferenceKind RK) -> bool { SourceRange DiagRange = nextPathEntryRange(Path, 0, L); SourceLocation DiagLoc = DiagRange.getBegin(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LoongArch][Clang] Make the parameter and return value of {x,}vmsknz.b builtins `signed char` vector (PR #114511)
https://github.com/SixWeining commented: Is it the time to remove the FIXME in those tests? https://github.com/llvm/llvm-project/pull/114511 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LoongArch][Clang] Make the parameters and return value of {x,}vshuf.b builtins `signed char` vectors (PR #114512)
https://github.com/xry111 updated https://github.com/llvm/llvm-project/pull/114512 >From ef96a6e483030e649d69ffa778c0b0f229bbb739 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Fri, 1 Nov 2024 00:13:29 +0800 Subject: [PATCH 1/2] [LoongArch][Clang] Make the parameter and return value of {x,}vmsknz.b builtins `signed char` vector These builtins operate on int8 vectors, not int16 vectors. So the old definition does not make any sense. --- clang/include/clang/Basic/BuiltinsLoongArchLASX.def | 2 +- clang/include/clang/Basic/BuiltinsLoongArchLSX.def | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def index 0d7c2df5c5c503..477f704860873c 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def @@ -357,7 +357,7 @@ TARGET_BUILTIN(__builtin_lasx_xvmskltz_w, "V8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvmskltz_d, "V4LLiV4LLi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvmskgez_b, "V32ScV32Sc", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvmsknz_b, "V16sV16s", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvmsknz_b, "V32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvldi, "V4LLiIi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvrepli_b, "V32ScIi", "nc", "lasx") diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLSX.def b/clang/include/clang/Basic/BuiltinsLoongArchLSX.def index 25a178e1ca98ab..e847985f390367 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLSX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLSX.def @@ -341,7 +341,7 @@ TARGET_BUILTIN(__builtin_lsx_vmskltz_w, "V4iV4i", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vmskltz_d, "V2LLiV2LLi", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vmskgez_b, "V16ScV16Sc", "nc", "lsx") -TARGET_BUILTIN(__builtin_lsx_vmsknz_b, "V8sV8s", "nc", "lsx") +TARGET_BUILTIN(__builtin_lsx_vmsknz_b, "V16ScV16Sc", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vldi, "V2LLiIi", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vrepli_b, "V16ScIi", "nc", "lsx") >From 349b79172a1ede63a25173366c1607b001bf1511 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Fri, 1 Nov 2024 00:17:44 +0800 Subject: [PATCH 2/2] [LoongArch][Clang] Make the parameters and return value of {x,}vshuf.b builtins `signed char` vectors The lsxintrin.h and and lasxintrin.h headers uses `signed char` vectors instead of `unsigned char` vectors. GCC also uses `signed char` for them, so align their definition with the headers and GCC. --- clang/include/clang/Basic/BuiltinsLoongArchLASX.def | 2 +- clang/include/clang/Basic/BuiltinsLoongArchLSX.def | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def index 477f704860873c..e6c41dd0974948 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def @@ -935,7 +935,7 @@ TARGET_BUILTIN(__builtin_lasx_xvilvh_h, "V16sV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvilvh_w, "V8iV8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvilvh_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvshuf_b, "V32UcV32UcV32UcV32Uc", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvshuf_b, "V32ScV32ScV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvshuf_h, "V16sV16sV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvshuf_w, "V8iV8iV8iV8i", "nc", "lasx") diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLSX.def b/clang/include/clang/Basic/BuiltinsLoongArchLSX.def index e847985f390367..ded6519f3ef16c 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLSX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLSX.def @@ -910,7 +910,7 @@ TARGET_BUILTIN(__builtin_lsx_vilvh_h, "V8sV8sV8s", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vilvh_w, "V4iV4iV4i", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vilvh_d, "V2LLiV2LLiV2LLi", "nc", "lsx") -TARGET_BUILTIN(__builtin_lsx_vshuf_b, "V16UcV16UcV16UcV16Uc", "nc", "lsx") +TARGET_BUILTIN(__builtin_lsx_vshuf_b, "V16ScV16ScV16ScV16Sc", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vshuf_h, "V8sV8sV8sV8s", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vshuf_w, "V4iV4iV4iV4i", "nc", "lsx") ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Extend bugprone-use-after-move check to handle std::optional::reset() and std::any::reset() (PR #114255)
@@ -279,7 +281,7 @@ void UseAfterMoveFinder::getDeclRefs( if (DeclRef && BlockMap->blockContainingStmt(DeclRef) == Block) { // Ignore uses of a standard smart pointer that don't dereference the // pointer. - if (Operator || !isStandardSmartPointer(DeclRef->getDecl())) { + if (Operator || !isStandardResettableOwner(DeclRef->getDecl())) { higher-performance wrote: Oh wow, nice catch... the C++23 members definitely weren't on my mind; this seems kind of ugly. `std::optional::has_value` seems OK (it's no different than `operator==(std::unique_ptr, std::nullptr_t)`, both of which are OK as they don't actually access the moved-from value), but the monadic operations definitely can be problematic... But then again, it seems(?) the fact that we don't warn on `operator==` is just an accident caused it being a non-member, not intentional? I guess, in theory, what we need to do here is to distinguish the different methods, but I don't really have the bandwidth to try to figure out how to implement that... Barring that, a blanket rule should either allow ~all members, or prohibit ~all members. I'm kind of torn here. I'd much rather prioritize C++17 over C++23, since I expect `reset` to be used much more, but the monadic operators might eventually become commonplace too. Ideas? https://github.com/llvm/llvm-project/pull/114255 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 92daad2 - [LoongArch][Clang] Make the parameter and return value of {x,}vmsknz.b builtins `signed char` vector (#114511)
Author: Xi Ruoyao Date: 2024-11-02T16:19:28+08:00 New Revision: 92daad2eac587cb0592de019cd5f6cbb7c42bb78 URL: https://github.com/llvm/llvm-project/commit/92daad2eac587cb0592de019cd5f6cbb7c42bb78 DIFF: https://github.com/llvm/llvm-project/commit/92daad2eac587cb0592de019cd5f6cbb7c42bb78.diff LOG: [LoongArch][Clang] Make the parameter and return value of {x,}vmsknz.b builtins `signed char` vector (#114511) These builtins operate on int8 vectors, not int16 vectors. So the old definition does not make any sense. Depends on #114510. Part of #110834 fix. Added: Modified: clang/include/clang/Basic/BuiltinsLoongArchLASX.def clang/include/clang/Basic/BuiltinsLoongArchLSX.def Removed: diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def index 0d7c2df5c5c503..477f704860873c 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def @@ -357,7 +357,7 @@ TARGET_BUILTIN(__builtin_lasx_xvmskltz_w, "V8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvmskltz_d, "V4LLiV4LLi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvmskgez_b, "V32ScV32Sc", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvmsknz_b, "V16sV16s", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvmsknz_b, "V32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvldi, "V4LLiIi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvrepli_b, "V32ScIi", "nc", "lasx") diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLSX.def b/clang/include/clang/Basic/BuiltinsLoongArchLSX.def index 25a178e1ca98ab..e847985f390367 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLSX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLSX.def @@ -341,7 +341,7 @@ TARGET_BUILTIN(__builtin_lsx_vmskltz_w, "V4iV4i", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vmskltz_d, "V2LLiV2LLi", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vmskgez_b, "V16ScV16Sc", "nc", "lsx") -TARGET_BUILTIN(__builtin_lsx_vmsknz_b, "V8sV8s", "nc", "lsx") +TARGET_BUILTIN(__builtin_lsx_vmsknz_b, "V16ScV16Sc", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vldi, "V2LLiIi", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vrepli_b, "V16ScIi", "nc", "lsx") ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Nolint fix (PR #114663)
https://github.com/chomosuke created https://github.com/llvm/llvm-project/pull/114663 None >From 7b70b905e5a9942f592316b407135975977c93cb Mon Sep 17 00:00:00 2001 From: chomosuke Date: Fri, 16 Aug 2024 13:31:21 + Subject: [PATCH 01/19] Fixing one error --- clang-tools-extra/clangd/ClangdServer.cpp | 23 ++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 9b38be04e7ddd7..e08ce12223f6b0 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -44,6 +44,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" +#include "llvm/Support/Format.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include @@ -672,6 +673,21 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) { return std::nullopt; } +// Add NOLINT insert as code actions +std::optional tryAddClangTidySuppression(const Diag *Diag) { + if (Diag->Source == Diag::ClangTidy) { +Fix F; +F.Message = llvm::formatv("ignore [{0}] for this line", Diag->Name); +TextEdit &E = F.Edits.emplace_back(); +E.newText = llvm::formatv("// NOLINTNEXTLINE({0})\n", Diag->Name); +Position InsertPos = Diag->Range.start; +InsertPos.character = 0; +E.range = {InsertPos, InsertPos}; +return F; + } + return std::nullopt; +} + } // namespace void ClangdServer::codeAction(const CodeActionInputs &Params, @@ -701,7 +717,7 @@ void ClangdServer::codeAction(const CodeActionInputs &Params, return nullptr; }; for (const auto &DiagRef : Params.Diagnostics) { -if (const auto *Diag = FindMatchedDiag(DiagRef)) +if (const auto *Diag = FindMatchedDiag(DiagRef)) { for (const auto &Fix : Diag->Fixes) { if (auto Rename = tryConvertToRename(Diag, Fix)) { Result.Renames.emplace_back(std::move(*Rename)); @@ -709,6 +725,11 @@ void ClangdServer::codeAction(const CodeActionInputs &Params, Result.QuickFixes.push_back({DiagRef, Fix}); } } + + if (auto Fix = tryAddClangTidySuppression(Diag)) { +Result.QuickFixes.push_back({DiagRef, std::move(*Fix)}); + } +} } } >From d5deb1d93e994f44d6b4d932e261a3bd9a42dcc8 Mon Sep 17 00:00:00 2001 From: chomosuke Date: Sun, 18 Aug 2024 17:15:21 + Subject: [PATCH 02/19] Revert "Fixing one error" This reverts commit 17989044ad480628a2f7814674dbe7cd985abd17. --- clang-tools-extra/clangd/ClangdServer.cpp | 23 +-- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index e08ce12223f6b0..9b38be04e7ddd7 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -44,7 +44,6 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" -#include "llvm/Support/Format.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include @@ -673,21 +672,6 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) { return std::nullopt; } -// Add NOLINT insert as code actions -std::optional tryAddClangTidySuppression(const Diag *Diag) { - if (Diag->Source == Diag::ClangTidy) { -Fix F; -F.Message = llvm::formatv("ignore [{0}] for this line", Diag->Name); -TextEdit &E = F.Edits.emplace_back(); -E.newText = llvm::formatv("// NOLINTNEXTLINE({0})\n", Diag->Name); -Position InsertPos = Diag->Range.start; -InsertPos.character = 0; -E.range = {InsertPos, InsertPos}; -return F; - } - return std::nullopt; -} - } // namespace void ClangdServer::codeAction(const CodeActionInputs &Params, @@ -717,7 +701,7 @@ void ClangdServer::codeAction(const CodeActionInputs &Params, return nullptr; }; for (const auto &DiagRef : Params.Diagnostics) { -if (const auto *Diag = FindMatchedDiag(DiagRef)) { +if (const auto *Diag = FindMatchedDiag(DiagRef)) for (const auto &Fix : Diag->Fixes) { if (auto Rename = tryConvertToRename(Diag, Fix)) { Result.Renames.emplace_back(std::move(*Rename)); @@ -725,11 +709,6 @@ void ClangdServer::codeAction(const CodeActionInputs &Params, Result.QuickFixes.push_back({DiagRef, Fix}); } } - - if (auto Fix = tryAddClangTidySuppression(Diag)) { -Result.QuickFixes.push_back({DiagRef, std::move(*Fix)}); - } -} } } >From 355a32406ae0ce93aed941c4865b040009289c82 Mon Sep 17 00:00:00 2001 From: chomosuke Date: Mon, 19 Aug 2024 15:17:05 + Subject: [PATCH 03/19] inserted NOLINT with indent Retrieved CurLine and PrevLine --- clang-tools-extra/clangd/Diagnostics.cpp | 4 +- clang-tools-ex
[clang-tools-extra] Nolint fix (PR #114663)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/114663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't re-annotate CaseLabelColon as ConditionalExpr (PR #114639)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/114639 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Nolint fix (PR #114663)
https://github.com/chomosuke edited https://github.com/llvm/llvm-project/pull/114663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [Modules] Support Reusable Modules Builder (PR #106683)
https://github.com/kadircet requested changes to this pull request. thanks I think this LG in terms of module-builder interfaces, but I think we can make some more changes to implementation to ensure it's easier to maintain going forward. speaking of maintenance, @HighCommander4 is definitely doing more of that than me recently. so i'd like to make sure he's also ok with this new complexity. i also would like to highlight @ChuanqiXu9 is definitely a responsible member of community, hence i believe he'll also be around if we have bug reports about this bits. https://github.com/llvm/llvm-project/pull/106683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [Modules] Support Reusable Modules Builder (PR #106683)
@@ -316,36 +287,169 @@ llvm::Error buildModuleFile(llvm::StringRef ModuleName, if (Clang->getDiagnostics().hasErrorOccurred()) return llvm::createStringError("Compilation failed"); - BuiltModuleFiles.addModuleFile(ModuleName, Inputs.CompileCommand.Output); - return llvm::Error::success(); + return ModuleFile{ModuleName, Inputs.CompileCommand.Output}; +} + +bool ReusablePrerequisiteModules::canReuse( +const CompilerInvocation &CI, +llvm::IntrusiveRefCntPtr VFS) const { + if (RequiredModules.empty()) +return true; + + SmallVector BMIPaths; + for (auto &MF : RequiredModules) +BMIPaths.push_back(MF->ModuleFilePath); + return IsModuleFilesUpToDate(BMIPaths, *this, VFS); } } // namespace +class ModulesBuilder::ModuleFileCache { +public: + ModuleFileCache(const GlobalCompilationDatabase &CDB) : CDB(CDB) {} + + llvm::Error + getOrBuildModuleFile(StringRef ModuleName, const ThreadsafeFS &TFS, + ProjectModules &MDB, + ReusablePrerequisiteModules &RequiredModules); + const GlobalCompilationDatabase &getCDB() const { return CDB; } + +private: + std::shared_ptr + getValidModuleFile(StringRef ModuleName, ProjectModules &MDB, + const ThreadsafeFS &TFS, + PrerequisiteModules &BuiltModuleFiles); + + /// This should only be called by getValidModuleFile. This is unlocked version + /// of getValidModuleFile. The function is extracted to avoid dead locks when + /// recursing. + std::shared_ptr + isValidModuleFileUnlocked(StringRef ModuleName, ProjectModules &MDB, +const ThreadsafeFS &TFS, +PrerequisiteModules &BuiltModuleFiles); + + const GlobalCompilationDatabase &CDB; + + llvm::StringMap> ModuleFiles; + // Mutex to guard accesses to ModuleFiles. + std::mutex ModuleFilesMutex; +}; + +std::shared_ptr +ModulesBuilder::ModuleFileCache::isValidModuleFileUnlocked( +StringRef ModuleName, ProjectModules &MDB, const ThreadsafeFS &TFS, +PrerequisiteModules &BuiltModuleFiles) { + auto Iter = ModuleFiles.find(ModuleName); + if (Iter != ModuleFiles.end()) { +if (!IsModuleFileUpToDate(Iter->second->ModuleFilePath, BuiltModuleFiles, + TFS.view(std::nullopt))) { + log("Found not-up-date module file {0} for module {1} in cache", + Iter->second->ModuleFilePath, ModuleName); + ModuleFiles.erase(Iter); + return nullptr; +} + +if (llvm::any_of( +MDB.getRequiredModules(MDB.getSourceForModuleName(ModuleName)), +[&MDB, &TFS, &BuiltModuleFiles, this](auto &&RequiredModuleName) { + return !isValidModuleFileUnlocked(RequiredModuleName, MDB, TFS, +BuiltModuleFiles); +})) { + ModuleFiles.erase(Iter); + return nullptr; +} + +return Iter->second; + } + + log("Don't find {0} in cache", ModuleName); + + return nullptr; +} + +std::shared_ptr ModulesBuilder::ModuleFileCache::getValidModuleFile( +StringRef ModuleName, ProjectModules &MDB, const ThreadsafeFS &TFS, +PrerequisiteModules &BuiltModuleFiles) { + std::lock_guard _(ModuleFilesMutex); + + return isValidModuleFileUnlocked(ModuleName, MDB, TFS, BuiltModuleFiles); +} + +llvm::Error ModulesBuilder::ModuleFileCache::getOrBuildModuleFile( kadircet wrote: similar to comment in `buildModuleFile`, can we turn this into just `getModuleFile`, which returns the latest cached module-file and make it callers responsibility to deal with freshness of the data. I don't think making this class concerned about both cache management and building/verifying module-files is necessary (and goes against separation of concerns). https://github.com/llvm/llvm-project/pull/106683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [Modules] Support Reusable Modules Builder (PR #106683)
https://github.com/kadircet edited https://github.com/llvm/llvm-project/pull/106683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [Modules] Support Reusable Modules Builder (PR #106683)
@@ -316,36 +287,169 @@ llvm::Error buildModuleFile(llvm::StringRef ModuleName, if (Clang->getDiagnostics().hasErrorOccurred()) return llvm::createStringError("Compilation failed"); - BuiltModuleFiles.addModuleFile(ModuleName, Inputs.CompileCommand.Output); - return llvm::Error::success(); + return ModuleFile{ModuleName, Inputs.CompileCommand.Output}; +} + +bool ReusablePrerequisiteModules::canReuse( +const CompilerInvocation &CI, +llvm::IntrusiveRefCntPtr VFS) const { + if (RequiredModules.empty()) +return true; + + SmallVector BMIPaths; + for (auto &MF : RequiredModules) +BMIPaths.push_back(MF->ModuleFilePath); + return IsModuleFilesUpToDate(BMIPaths, *this, VFS); } } // namespace +class ModulesBuilder::ModuleFileCache { +public: + ModuleFileCache(const GlobalCompilationDatabase &CDB) : CDB(CDB) {} + + llvm::Error + getOrBuildModuleFile(StringRef ModuleName, const ThreadsafeFS &TFS, + ProjectModules &MDB, + ReusablePrerequisiteModules &RequiredModules); + const GlobalCompilationDatabase &getCDB() const { return CDB; } + +private: + std::shared_ptr + getValidModuleFile(StringRef ModuleName, ProjectModules &MDB, + const ThreadsafeFS &TFS, + PrerequisiteModules &BuiltModuleFiles); + + /// This should only be called by getValidModuleFile. This is unlocked version + /// of getValidModuleFile. The function is extracted to avoid dead locks when + /// recursing. + std::shared_ptr + isValidModuleFileUnlocked(StringRef ModuleName, ProjectModules &MDB, +const ThreadsafeFS &TFS, +PrerequisiteModules &BuiltModuleFiles); + + const GlobalCompilationDatabase &CDB; + + llvm::StringMap> ModuleFiles; + // Mutex to guard accesses to ModuleFiles. + std::mutex ModuleFilesMutex; +}; + +std::shared_ptr +ModulesBuilder::ModuleFileCache::isValidModuleFileUnlocked( kadircet wrote: doing all of this work while holding a lock makes me nervous. what about: - first perform the traversal to find all the relevant module names, without holding any locks - then acquire the lock, check if all module names exist in the cache and also copy the modulefiles and release the lock - now we can check if all the modulefiles are up-to-date and return accordingly. https://github.com/llvm/llvm-project/pull/106683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [Modules] Support Reusable Modules Builder (PR #106683)
@@ -316,36 +287,169 @@ llvm::Error buildModuleFile(llvm::StringRef ModuleName, if (Clang->getDiagnostics().hasErrorOccurred()) return llvm::createStringError("Compilation failed"); - BuiltModuleFiles.addModuleFile(ModuleName, Inputs.CompileCommand.Output); - return llvm::Error::success(); + return ModuleFile{ModuleName, Inputs.CompileCommand.Output}; +} + +bool ReusablePrerequisiteModules::canReuse( +const CompilerInvocation &CI, +llvm::IntrusiveRefCntPtr VFS) const { + if (RequiredModules.empty()) +return true; + + SmallVector BMIPaths; + for (auto &MF : RequiredModules) +BMIPaths.push_back(MF->ModuleFilePath); + return IsModuleFilesUpToDate(BMIPaths, *this, VFS); } } // namespace +class ModulesBuilder::ModuleFileCache { +public: + ModuleFileCache(const GlobalCompilationDatabase &CDB) : CDB(CDB) {} + + llvm::Error + getOrBuildModuleFile(StringRef ModuleName, const ThreadsafeFS &TFS, + ProjectModules &MDB, + ReusablePrerequisiteModules &RequiredModules); + const GlobalCompilationDatabase &getCDB() const { return CDB; } + +private: + std::shared_ptr + getValidModuleFile(StringRef ModuleName, ProjectModules &MDB, + const ThreadsafeFS &TFS, + PrerequisiteModules &BuiltModuleFiles); + + /// This should only be called by getValidModuleFile. This is unlocked version + /// of getValidModuleFile. The function is extracted to avoid dead locks when + /// recursing. + std::shared_ptr + isValidModuleFileUnlocked(StringRef ModuleName, ProjectModules &MDB, +const ThreadsafeFS &TFS, +PrerequisiteModules &BuiltModuleFiles); + + const GlobalCompilationDatabase &CDB; + + llvm::StringMap> ModuleFiles; kadircet wrote: can we keep a std::weak_ptr here instead? That way we can ensure that a module-file is kept alive iff there's a prerequisitemodules referencing it. we're still left with this map growing unboundedly, but map entries are cheap, just a pointer and a modulename. that can also be addressed by triggering a cleanup when we destroy a prerequisitemodules. https://github.com/llvm/llvm-project/pull/106683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [Modules] Support Reusable Modules Builder (PR #106683)
@@ -482,6 +482,42 @@ void func() { EXPECT_EQ(Result.signatures[0].parameters[0].labelString, "int a"); } +TEST_F(PrerequisiteModulesTests, ReusablePrerequisiteModulesTest) { kadircet wrote: can you also add some tests demonstrating behavior in presence of stale cache entries? https://github.com/llvm/llvm-project/pull/106683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [Modules] Support Reusable Modules Builder (PR #106683)
@@ -228,54 +223,30 @@ class StandalonePrerequisiteModules : public PrerequisiteModules { return BuiltModuleNames.contains(ModuleName); } - void addModuleFile(llvm::StringRef ModuleName, - llvm::StringRef ModuleFilePath) { -RequiredModules.emplace_back(ModuleName, ModuleFilePath); -BuiltModuleNames.insert(ModuleName); + void addModuleFile(std::shared_ptr BMI) { +BuiltModuleNames.insert(BMI->ModuleName); +RequiredModules.emplace_back(std::move(BMI)); } private: - llvm::SmallVector RequiredModules; + mutable llvm::SmallVector, 8> RequiredModules; kadircet wrote: why do we need to make this mutable? also let's store a `std::shared_ptr` instead (and update rest of the places to make sure a module file is never mutated after construction) https://github.com/llvm/llvm-project/pull/106683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix a typo in clangs README (PR #114410)
PhilippRados wrote: @jroelofs can you merge this? https://github.com/llvm/llvm-project/pull/114410 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [Modules] Support Reusable Modules Builder (PR #106683)
@@ -228,54 +223,30 @@ class StandalonePrerequisiteModules : public PrerequisiteModules { return BuiltModuleNames.contains(ModuleName); } - void addModuleFile(llvm::StringRef ModuleName, - llvm::StringRef ModuleFilePath) { -RequiredModules.emplace_back(ModuleName, ModuleFilePath); -BuiltModuleNames.insert(ModuleName); + void addModuleFile(std::shared_ptr BMI) { +BuiltModuleNames.insert(BMI->ModuleName); +RequiredModules.emplace_back(std::move(BMI)); } private: - llvm::SmallVector RequiredModules; + mutable llvm::SmallVector, 8> RequiredModules; // A helper class to speedup the query if a module is built. llvm::StringSet<> BuiltModuleNames; }; -// Build a module file for module with `ModuleName`. The information of built -// module file are stored in \param BuiltModuleFiles. -llvm::Error buildModuleFile(llvm::StringRef ModuleName, -const GlobalCompilationDatabase &CDB, -const ThreadsafeFS &TFS, ProjectModules &MDB, -PathRef ModuleFilesPrefix, -StandalonePrerequisiteModules &BuiltModuleFiles) { - if (BuiltModuleFiles.isModuleUnitBuilt(ModuleName)) -return llvm::Error::success(); - - PathRef ModuleUnitFileName = MDB.getSourceForModuleName(ModuleName); - // It is possible that we're meeting third party modules (modules whose - // source are not in the project. e.g, the std module may be a third-party - // module for most projects) or something wrong with the implementation of - // ProjectModules. - // FIXME: How should we treat third party modules here? If we want to ignore - // third party modules, we should return true instead of false here. - // Currently we simply bail out. - if (ModuleUnitFileName.empty()) -return llvm::createStringError("Failed to get the primary source"); - +/// Build a module file for module with `ModuleName`. The information of built +/// module file are stored in \param BuiltModuleFiles. +llvm::Expected +buildModuleFile(llvm::StringRef ModuleName, PathRef ModuleUnitFileName, +const GlobalCompilationDatabase &CDB, const ThreadsafeFS &TFS, +PathRef ModuleFilesPrefix, +const ReusablePrerequisiteModules &BuiltModuleFiles) { // Try cheap operation earlier to boil-out cheaply if there are problems. auto Cmd = CDB.getCompileCommand(ModuleUnitFileName); if (!Cmd) return llvm::createStringError( llvm::formatv("No compile command for {0}", ModuleUnitFileName)); - for (auto &RequiredModuleName : MDB.getRequiredModules(ModuleUnitFileName)) { kadircet wrote: i am a little worried about this change. previously we were making sure all the dependent modules were built within this free function. now we're relying on the caller ensuring that, without any checks. can we keep this behavior, but pass in the module-cache as a parameter and skip building if module-file is available in the cache? later on caller can update the cache using the information in `BuiltModuleFiles`. https://github.com/llvm/llvm-project/pull/106683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix a typo in clangs README (PR #114410)
github-actions[bot] wrote: @PhilippRados Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail [here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr). If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of [LLVM development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy). You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! https://github.com/llvm/llvm-project/pull/114410 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] ad0a1b9 - [clang] Fix a typo in clangs README (#114410)
Author: Philipp Rados Date: 2024-11-02T08:19:28-07:00 New Revision: ad0a1b90adccd3a9b8fdfbe5923a6ebe9ca2e1a3 URL: https://github.com/llvm/llvm-project/commit/ad0a1b90adccd3a9b8fdfbe5923a6ebe9ca2e1a3 DIFF: https://github.com/llvm/llvm-project/commit/ad0a1b90adccd3a9b8fdfbe5923a6ebe9ca2e1a3.diff LOG: [clang] Fix a typo in clangs README (#114410) changed "disucss" to "discuss" Added: Modified: clang/README.md Removed: diff --git a/clang/README.md b/clang/README.md index b98182d8a3f684..a5e2c9f12e6ac5 100644 --- a/clang/README.md +++ b/clang/README.md @@ -16,7 +16,7 @@ If you're interested in more (including how to build Clang) it is best to read t * Information on the LLVM project:http://llvm.org/ -* If you have questions or comments about Clang, a great place to disucss them is on the Clang forums: +* If you have questions or comments about Clang, a great place to discuss them is on the Clang forums: [Clang Frontend - LLVM Discussion Forums](https://discourse.llvm.org/c/clang/) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix a typo in clangs README (PR #114410)
https://github.com/jroelofs closed https://github.com/llvm/llvm-project/pull/114410 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] SemaFunctionEffects: When verifying a function, ignore any trailing 'requires' clause. (PR #114266)
https://github.com/cjappl commented: for whatever it's worth - LGTM. Leaving to more experienced heads in this area to actually approve. Good sleuthing! https://github.com/llvm/llvm-project/pull/114266 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][TableGen] Add explicit symbol visibility macros to code generated (PR #109362)
vgvassilev wrote: @fsfod, can you rebase? https://github.com/llvm/llvm-project/pull/109362 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] New option `CompilationArgsToRemoveRegex` to remove arguments from the command line (PR #111453)
@@ -106,6 +106,9 @@ Improvements to clang-tidy - Improved :program:`run-clang-tidy.py` script. Fixed minor shutdown noise happening on certain platforms when interrupting the script. +- Improved :program:`clang-tidy` by adding the option `CompilationArgsToRemoveRegex` felix642 wrote: @EugeneZelenko, I might be wrong, but since the option is only mentioned in index.rst, I don't think I can use :option: in the Release notes. https://github.com/llvm/llvm-project/pull/111453 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] New option `CompilationArgsToRemoveRegex` to remove arguments from the command line (PR #111453)
https://github.com/felix642 updated https://github.com/llvm/llvm-project/pull/111453 From 5cdc27e543b0f4dea3dd3848d974a27614aea713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?= Date: Mon, 7 Oct 2024 19:22:44 -0400 Subject: [PATCH 1/2] [clang-tidy] New option to remove arguments from the command line When using clang-tidy from a compilation database, some options might not be recognized by clang if the compilation database was generated for another compiler. This forces the user to add conditional code in their CMakeLists.txt to remove those arguments when using clang-tidy. A new option was added to the .clang-tidy config to remove those unknown flags without the need to generate a second compilation_commands.json Fixes #108455 --- clang-tools-extra/clang-tidy/ClangTidy.cpp| 24 +++ .../clang-tidy/ClangTidyOptions.cpp | 5 .../clang-tidy/ClangTidyOptions.h | 4 clang-tools-extra/docs/ReleaseNotes.rst | 3 +++ clang-tools-extra/docs/clang-tidy/index.rst | 3 +++ .../compilation-args-to-ignore.cpp| 9 +++ 6 files changed, 48 insertions(+) create mode 100644 clang-tools-extra/test/clang-tidy/infrastructure/compilation-args-to-ignore.cpp diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp index 62f9d19b2a362f..4bd921b819260e 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp @@ -552,6 +552,30 @@ runClangTidy(clang::tidy::ClangTidyContext &Context, return AdjustedArgs; }; + // Remove unwanted arguments passed to the compiler + ArgumentsAdjuster CompilationArgsToIgnore = + [&Context](const CommandLineArguments &Args, StringRef Filename) { +ClangTidyOptions Opts = Context.getOptionsForFile(Filename); +CommandLineArguments AdjustedArgs = Args; + +if (Opts.CompilationArgsToRemoveRegex) { + for (StringRef ArgToIgnore : *Opts.CompilationArgsToRemoveRegex) { +llvm::Regex ArgToIgnoreRegex(ArgToIgnore); +AdjustedArgs.erase( +std::remove_if(AdjustedArgs.begin(), AdjustedArgs.end(), + [&](llvm::StringRef Arg) { + return Arg.starts_with("-") && +Arg != "-fsyntax-only" && +ArgToIgnoreRegex.match(Arg); + }), +AdjustedArgs.end()); + } +} + +return AdjustedArgs; + }; + + Tool.appendArgumentsAdjuster(CompilationArgsToIgnore); Tool.appendArgumentsAdjuster(PerFileExtraArgumentsInserter); Tool.appendArgumentsAdjuster(getStripPluginsAdjuster()); Context.setEnableProfiling(EnableCheckProfile); diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp index 445c7f85c900c6..32112db07b09d2 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp @@ -174,6 +174,8 @@ template <> struct MappingTraits { Options.ExcludeHeaderFilterRegex); IO.mapOptional("FormatStyle", Options.FormatStyle); IO.mapOptional("User", Options.User); +IO.mapOptional("CompilationArgsToRemoveRegex", + Options.CompilationArgsToRemoveRegex); IO.mapOptional("CheckOptions", Options.CheckOptions); IO.mapOptional("ExtraArgs", Options.ExtraArgs); IO.mapOptional("ExtraArgsBefore", Options.ExtraArgsBefore); @@ -198,6 +200,7 @@ ClangTidyOptions ClangTidyOptions::getDefaults() { Options.SystemHeaders = false; Options.FormatStyle = "none"; Options.User = std::nullopt; + Options.CompilationArgsToRemoveRegex = std::nullopt; for (const ClangTidyModuleRegistry::entry &Module : ClangTidyModuleRegistry::entries()) Options.mergeWith(Module.instantiate()->getModuleOptions(), 0); @@ -238,6 +241,8 @@ ClangTidyOptions &ClangTidyOptions::mergeWith(const ClangTidyOptions &Other, overrideValue(SystemHeaders, Other.SystemHeaders); overrideValue(FormatStyle, Other.FormatStyle); overrideValue(User, Other.User); + overrideValue(CompilationArgsToRemoveRegex, +Other.CompilationArgsToRemoveRegex); overrideValue(UseColor, Other.UseColor); mergeVectors(ExtraArgs, Other.ExtraArgs); mergeVectors(ExtraArgsBefore, Other.ExtraArgsBefore); diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.h b/clang-tools-extra/clang-tidy/ClangTidyOptions.h index 85d5a02ebbc1bc..0ccdde1ff3fc31 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyOptions.h +++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.h @@ -110,6 +110,10 @@ struct ClangTidyOptions { /// comments in the relevant check. std::optional User; + /// \brief Remove command line arguments sent to the compiler matching this + /// regex. + std::optional> Com
[clang] [clang] SemaFunctionEffects: When verifying a function, ignore any trailing 'requires' clause. (PR #114266)
https://github.com/cjappl edited https://github.com/llvm/llvm-project/pull/114266 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] SemaFunctionEffects: When verifying a function, ignore any trailing 'requires' clause. (PR #114266)
@@ -1259,6 +1263,12 @@ class Analyzer { return true; } +bool TraverseStmt(Stmt *Statement) { + if (Statement != TrailingRequiresClause) cjappl wrote: Could consider leaving a comment here saying why you skip trailing requires clauses (some truncated version of the description/findings of this PR) https://github.com/llvm/llvm-project/pull/114266 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][TableGen] Add explicit symbol visibility macros to code generated (PR #109362)
vgvassilev wrote: @AaronBallman, ping. https://github.com/llvm/llvm-project/pull/109362 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Nolint fix (PR #114663)
https://github.com/chomosuke updated https://github.com/llvm/llvm-project/pull/114663 >From 7b70b905e5a9942f592316b407135975977c93cb Mon Sep 17 00:00:00 2001 From: chomosuke Date: Fri, 16 Aug 2024 13:31:21 + Subject: [PATCH 01/20] Fixing one error --- clang-tools-extra/clangd/ClangdServer.cpp | 23 ++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 9b38be04e7ddd7..e08ce12223f6b0 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -44,6 +44,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" +#include "llvm/Support/Format.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include @@ -672,6 +673,21 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) { return std::nullopt; } +// Add NOLINT insert as code actions +std::optional tryAddClangTidySuppression(const Diag *Diag) { + if (Diag->Source == Diag::ClangTidy) { +Fix F; +F.Message = llvm::formatv("ignore [{0}] for this line", Diag->Name); +TextEdit &E = F.Edits.emplace_back(); +E.newText = llvm::formatv("// NOLINTNEXTLINE({0})\n", Diag->Name); +Position InsertPos = Diag->Range.start; +InsertPos.character = 0; +E.range = {InsertPos, InsertPos}; +return F; + } + return std::nullopt; +} + } // namespace void ClangdServer::codeAction(const CodeActionInputs &Params, @@ -701,7 +717,7 @@ void ClangdServer::codeAction(const CodeActionInputs &Params, return nullptr; }; for (const auto &DiagRef : Params.Diagnostics) { -if (const auto *Diag = FindMatchedDiag(DiagRef)) +if (const auto *Diag = FindMatchedDiag(DiagRef)) { for (const auto &Fix : Diag->Fixes) { if (auto Rename = tryConvertToRename(Diag, Fix)) { Result.Renames.emplace_back(std::move(*Rename)); @@ -709,6 +725,11 @@ void ClangdServer::codeAction(const CodeActionInputs &Params, Result.QuickFixes.push_back({DiagRef, Fix}); } } + + if (auto Fix = tryAddClangTidySuppression(Diag)) { +Result.QuickFixes.push_back({DiagRef, std::move(*Fix)}); + } +} } } >From d5deb1d93e994f44d6b4d932e261a3bd9a42dcc8 Mon Sep 17 00:00:00 2001 From: chomosuke Date: Sun, 18 Aug 2024 17:15:21 + Subject: [PATCH 02/20] Revert "Fixing one error" This reverts commit 17989044ad480628a2f7814674dbe7cd985abd17. --- clang-tools-extra/clangd/ClangdServer.cpp | 23 +-- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index e08ce12223f6b0..9b38be04e7ddd7 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -44,7 +44,6 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" -#include "llvm/Support/Format.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include @@ -673,21 +672,6 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) { return std::nullopt; } -// Add NOLINT insert as code actions -std::optional tryAddClangTidySuppression(const Diag *Diag) { - if (Diag->Source == Diag::ClangTidy) { -Fix F; -F.Message = llvm::formatv("ignore [{0}] for this line", Diag->Name); -TextEdit &E = F.Edits.emplace_back(); -E.newText = llvm::formatv("// NOLINTNEXTLINE({0})\n", Diag->Name); -Position InsertPos = Diag->Range.start; -InsertPos.character = 0; -E.range = {InsertPos, InsertPos}; -return F; - } - return std::nullopt; -} - } // namespace void ClangdServer::codeAction(const CodeActionInputs &Params, @@ -717,7 +701,7 @@ void ClangdServer::codeAction(const CodeActionInputs &Params, return nullptr; }; for (const auto &DiagRef : Params.Diagnostics) { -if (const auto *Diag = FindMatchedDiag(DiagRef)) { +if (const auto *Diag = FindMatchedDiag(DiagRef)) for (const auto &Fix : Diag->Fixes) { if (auto Rename = tryConvertToRename(Diag, Fix)) { Result.Renames.emplace_back(std::move(*Rename)); @@ -725,11 +709,6 @@ void ClangdServer::codeAction(const CodeActionInputs &Params, Result.QuickFixes.push_back({DiagRef, Fix}); } } - - if (auto Fix = tryAddClangTidySuppression(Diag)) { -Result.QuickFixes.push_back({DiagRef, std::move(*Fix)}); - } -} } } >From 355a32406ae0ce93aed941c4865b040009289c82 Mon Sep 17 00:00:00 2001 From: chomosuke Date: Mon, 19 Aug 2024 15:17:05 + Subject: [PATCH 03/20] inserted NOLINT with indent Retrieved CurLine and PrevLine --- clang-tools-extra/clangd/Diagnostics.cpp | 4 +- clang-tools-extra/cl
[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)
https://github.com/ccotter updated https://github.com/llvm/llvm-project/pull/114244 >From fd914cc82688b122654d2d7ada72007541b197c0 Mon Sep 17 00:00:00 2001 From: Chris Cotter Date: Wed, 30 Oct 2024 10:54:49 -0400 Subject: [PATCH 1/5] Add bugprone-sprintf-overlap --- .../bugprone/BugproneTidyModule.cpp | 3 + .../clang-tidy/bugprone/CMakeLists.txt| 1 + .../bugprone/UndefinedSprintfOverlapCheck.cpp | 93 +++ .../bugprone/UndefinedSprintfOverlapCheck.h | 36 +++ clang-tools-extra/docs/ReleaseNotes.rst | 6 ++ .../bugprone/undefined-sprintf-overlap.rst| 23 + .../docs/clang-tidy/checks/list.rst | 3 +- .../bugprone/undefined-sprintf-overlap.cpp| 59 8 files changed, 223 insertions(+), 1 deletion(-) create mode 100644 clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp create mode 100644 clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.h create mode 100644 clang-tools-extra/docs/clang-tidy/checks/bugprone/undefined-sprintf-overlap.rst create mode 100644 clang-tools-extra/test/clang-tidy/checkers/bugprone/undefined-sprintf-overlap.cpp diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp index 33ac65e715ce81..ac3a08c80d7ae6 100644 --- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp @@ -86,6 +86,7 @@ #include "TooSmallLoopVariableCheck.h" #include "UncheckedOptionalAccessCheck.h" #include "UndefinedMemoryManipulationCheck.h" +#include "UndefinedSprintfOverlapCheck.h" #include "UndelegatedConstructorCheck.h" #include "UnhandledExceptionAtNewCheck.h" #include "UnhandledSelfAssignmentCheck.h" @@ -248,6 +249,8 @@ class BugproneModule : public ClangTidyModule { "bugprone-unchecked-optional-access"); CheckFactories.registerCheck( "bugprone-undefined-memory-manipulation"); +CheckFactories.registerCheck( +"bugprone-undefined-sprintf-overlap"); CheckFactories.registerCheck( "bugprone-undelegated-constructor"); CheckFactories.registerCheck( diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt index b0a2318acc0597..2403ed665fd5c7 100644 --- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt @@ -81,6 +81,7 @@ add_clang_library(clangTidyBugproneModule STATIC TooSmallLoopVariableCheck.cpp UncheckedOptionalAccessCheck.cpp UndefinedMemoryManipulationCheck.cpp + UndefinedSprintfOverlapCheck.cpp UndelegatedConstructorCheck.cpp UnhandledExceptionAtNewCheck.cpp UnhandledSelfAssignmentCheck.cpp diff --git a/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp new file mode 100644 index 00..301b6bce0dbbad --- /dev/null +++ b/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp @@ -0,0 +1,93 @@ +//===--- UndefinedSprintfOverlapCheck.cpp - clang-tidy ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "UndefinedSprintfOverlapCheck.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Lex/Lexer.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::bugprone { + +AST_MATCHER_P(CallExpr, hasAnyOtherArgument, + ast_matchers::internal::Matcher, InnerMatcher) { + for (const auto *Arg : llvm::drop_begin(Node.arguments())) { +ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder); +if (InnerMatcher.matches(*Arg, Finder, &Result)) { + *Builder = std::move(Result); + return true; +} + } + return false; +} + +AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) { + return Builder->removeBindings( + [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) { +const auto &BN = Nodes.getNode(ID); +if (const auto *Lit = BN.get()) { + return Lit->getValue() != Node.getValue(); +} +return true; + }); +} + +UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck( +StringRef Name, ClangTidyContext *Context) +: ClangTidyCheck(Name, Context), + SprintfRegex(Options.get("SprintfFunction", "(::std)?::(sn?printf)")) {} + +void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) { + auto FirstArg = declRefExpr(to(varDecl().bind("firstArg"))); + auto OtherRefToArg = declRefExpr(to(varDecl(equalsBoundNode("firstArg" + .bind("overlappingArg"); + Finder->addM
[clang] [clang][NFC] Spell out DynTypedNode instead of auto (PR #114427)
ccotter wrote: While working on #114244, I noticed the use of `auto` in `memberHasSameNameAsBoundNode`. The only other place I could find using `auto` with `Nodes.getNode` was in the second file I changed. https://github.com/llvm/llvm-project/pull/114427 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Nolint fix (PR #114663)
https://github.com/chomosuke closed https://github.com/llvm/llvm-project/pull/114663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114661)
https://github.com/chomosuke updated https://github.com/llvm/llvm-project/pull/114661 >From 97a830bdf1b3eb1eb352561ef38f95e8baa4e0b9 Mon Sep 17 00:00:00 2001 From: chomosuke Date: Sat, 2 Nov 2024 09:18:38 + Subject: [PATCH] Add quick fix to automatically adds NOLINTNEXTLINE comment above clang-tidy warnings --- clang-tools-extra/clangd/CMakeLists.txt | 1 + clang-tools-extra/clangd/ClangdServer.cpp | 3 +- clang-tools-extra/clangd/Diagnostics.cpp | 23 +++- clang-tools-extra/clangd/Diagnostics.h| 12 +- clang-tools-extra/clangd/NoLintFixes.cpp | 99 +++ clang-tools-extra/clangd/NoLintFixes.h| 36 ++ clang-tools-extra/clangd/ParsedAST.cpp| 19 ++- .../fixits-codeaction-documentchanges.test| 47 .../clangd/test/fixits-codeaction.test| 82 + .../test/fixits-command-documentchanges.test | 62 ++ .../clangd/test/fixits-command.test | 100 .../clangd/unittests/ClangdLSPServerTests.cpp | 18 ++- .../clangd/unittests/DiagnosticsTests.cpp | 113 -- 13 files changed, 583 insertions(+), 32 deletions(-) create mode 100644 clang-tools-extra/clangd/NoLintFixes.cpp create mode 100644 clang-tools-extra/clangd/NoLintFixes.h diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt index d797ddce8c44d1..2a6433a5c3effd 100644 --- a/clang-tools-extra/clangd/CMakeLists.txt +++ b/clang-tools-extra/clangd/CMakeLists.txt @@ -98,6 +98,7 @@ add_clang_library(clangDaemon STATIC InlayHints.cpp JSONTransport.cpp ModulesBuilder.cpp + NoLintFixes.cpp PathMapping.cpp Protocol.cpp Quality.cpp diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 9b38be04e7ddd7..7f73b61b12c63f 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -15,6 +15,7 @@ #include "Format.h" #include "HeaderSourceSwitch.h" #include "InlayHints.h" +#include "NoLintFixes.h" #include "ParsedAST.h" #include "Preamble.h" #include "Protocol.h" @@ -661,7 +662,7 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) { bool IsClangTidyRename = Diag->Source == Diag::ClangTidy && Diag->Name == "readability-identifier-naming" && !Fix.Edits.empty(); - if (IsClangTidyRename && Diag->InsideMainFile) { + if (IsClangTidyRename && !isNoLintFixes(Fix) && Diag->InsideMainFile) { ClangdServer::CodeActionResult::Rename R; R.NewName = Fix.Edits.front().newText; R.FixMessage = Fix.Message; diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index a59d1e7ac84096..6948e12995bed1 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -9,6 +9,7 @@ #include "Diagnostics.h" #include "../clang-tidy/ClangTidyDiagnosticConsumer.h" #include "Compiler.h" +#include "NoLintFixes.h" #include "Protocol.h" #include "SourceCode.h" #include "support/Logger.h" @@ -311,8 +312,18 @@ std::string mainMessage(const Diag &D, const ClangdDiagnosticOptions &Opts) { std::string Result; llvm::raw_string_ostream OS(Result); OS << D.Message; - if (Opts.DisplayFixesCount && !D.Fixes.empty()) -OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)"; + + // NOLINT fixes are somewhat not real fixes and to say "(fix available)" when + // the fixes is just to suppress could be misleading. + int RealFixCount = D.Fixes.size(); + for (auto const &Fix : D.Fixes) { +if (isNoLintFixes(Fix)) { + RealFixCount--; +} + } + + if (Opts.DisplayFixesCount && RealFixCount > 0) +OS << " (" << (RealFixCount > 1 ? "fixes" : "fix") << " available)"; // If notes aren't emitted as structured info, add them to the message. if (!Opts.EmitRelatedLocations) for (auto &Note : D.Notes) { @@ -822,8 +833,8 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, LastDiagOriginallyError = OriginallyError; if (!Info.getFixItHints().empty()) AddFix(true /* try to invent a message instead of repeating the diag */); -if (Fixer) { - auto ExtraFixes = Fixer(LastDiag->Severity, Info); +if (MainFixer) { + auto ExtraFixes = MainFixer(*LastDiag, Info); LastDiag->Fixes.insert(LastDiag->Fixes.end(), ExtraFixes.begin(), ExtraFixes.end()); } @@ -841,8 +852,8 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, return; // Give include-fixer a chance to replace a note with a fix. -if (Fixer) { - auto ReplacementFixes = Fixer(LastDiag->Severity, Info); +if (NoteFixer) { + auto ReplacementFixes = NoteFixer(*LastDiag, Info); if (!ReplacementFixes.empty()) { assert(Info.getNumFixItHints() == 0 && "Include-fixer replaced a note
[clang] [LoongArch][Clang] Make the parameter and return value of {x,}vmsknz.b builtins `signed char` vector (PR #114511)
xry111 wrote: > Is it the time to remove the FIXME in those tests? There are several random inconsistencies and I separated the fixes into multiple PRs as suggested by Xuerui. The FIXME is removed in #114513. https://github.com/llvm/llvm-project/pull/114511 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Extend bugprone-use-after-move check to handle std::optional::reset() and std::any::reset() (PR #114255)
https://github.com/higher-performance edited https://github.com/llvm/llvm-project/pull/114255 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix a typo in clangs README (PR #114410)
jroelofs wrote: sure! https://github.com/llvm/llvm-project/pull/114410 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix a typo in clangs README (PR #114410)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `llvm-clang-x86_64-darwin` running on `doug-worker-3` while building `clang` at step 6 "test-build-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/23/builds/4425 Here is the relevant piece of the build log for the reference ``` Step 6 (test-build-unified-tree-check-all) failure: test (failure) TEST 'lit :: shtest-external-shell-kill.py' FAILED Exit Code: 1 Command Output (stdout): -- # RUN: at line 23 env -u FILECHECK_OPTS "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/bin/python3.9" /Users/buildbot/buildbot-root/x86_64-darwin/llvm-project/llvm/utils/lit/lit.py -j1 --order=lexical -a Inputs/shtest-external-shell-kill | grep -v 'bash.exe: warning: could not find /tmp, please create!' | FileCheck /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/utils/lit/tests/shtest-external-shell-kill.py # executed command: env -u FILECHECK_OPTS /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/bin/python3.9 /Users/buildbot/buildbot-root/x86_64-darwin/llvm-project/llvm/utils/lit/lit.py -j1 --order=lexical -a Inputs/shtest-external-shell-kill # note: command had no output on stdout or stderr # error: command failed with exit status: 1 # executed command: grep -v 'bash.exe: warning: could not find /tmp, please create!' # executed command: FileCheck /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/utils/lit/tests/shtest-external-shell-kill.py # .---command stderr # | /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/utils/lit/tests/shtest-external-shell-kill.py:29:15: error: CHECK-NEXT: is not on the line after the previous match # | # CHECK-NEXT: end # | ^ # | :22:22: note: 'next' match was here # | RUN: at line 5: echo end # | ^ # | :8:6: note: previous match ended here # | start # | ^ # | :9:1: note: non-matching line after previous match is here # | # | ^ # | # | Input file: # | Check file: /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/utils/lit/tests/shtest-external-shell-kill.py # | # | -dump-input=help explains the following input dump. # | # | Input was: # | << # | . # | . # | . # | 17: RUN: at line 3: sleep 2 # | 18: + sleep 2 # | 19: + sleep 300 # | 20: RUN: at line 4: kill $PID # | 21: + kill 69629 # | 22: RUN: at line 5: echo end # | next:29 !~~ error: match on wrong line # | 23: /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/utils/lit/tests/Inputs/shtest-external-shell-kill/Output/test.txt.script: line 5: echo: write error: Interrupted system call # | 24: /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/utils/lit/tests/Inputs/shtest-external-shell-kill/Output/test.txt.script: line 6: 69629 Terminated: 15 sleep 300 # | 25: # | 26: -- # | 27: # | . # | . ... ``` https://github.com/llvm/llvm-project/pull/114410 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114661)
https://github.com/chomosuke updated https://github.com/llvm/llvm-project/pull/114661 >From 581004de1006ce232ad5dbbed9f8af8eb2f312ae Mon Sep 17 00:00:00 2001 From: chomosuke Date: Sat, 2 Nov 2024 09:18:38 + Subject: [PATCH] Add quick fix to automatically adds NOLINTNEXTLINE comment above clang-tidy warnings --- clang-tools-extra/clangd/CMakeLists.txt | 1 + clang-tools-extra/clangd/ClangdServer.cpp | 3 +- clang-tools-extra/clangd/Diagnostics.cpp | 23 +++- clang-tools-extra/clangd/Diagnostics.h| 12 +- clang-tools-extra/clangd/NoLintFixes.cpp | 99 +++ clang-tools-extra/clangd/NoLintFixes.h| 36 ++ clang-tools-extra/clangd/ParsedAST.cpp| 19 ++- .../fixits-codeaction-documentchanges.test| 47 .../clangd/test/fixits-codeaction.test| 82 + .../test/fixits-command-documentchanges.test | 62 ++ .../clangd/test/fixits-command.test | 100 .../clangd/unittests/ClangdLSPServerTests.cpp | 18 ++- .../clangd/unittests/DiagnosticsTests.cpp | 113 -- 13 files changed, 583 insertions(+), 32 deletions(-) create mode 100644 clang-tools-extra/clangd/NoLintFixes.cpp create mode 100644 clang-tools-extra/clangd/NoLintFixes.h diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt index d797ddce8c44d1..2a6433a5c3effd 100644 --- a/clang-tools-extra/clangd/CMakeLists.txt +++ b/clang-tools-extra/clangd/CMakeLists.txt @@ -98,6 +98,7 @@ add_clang_library(clangDaemon STATIC InlayHints.cpp JSONTransport.cpp ModulesBuilder.cpp + NoLintFixes.cpp PathMapping.cpp Protocol.cpp Quality.cpp diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 9b38be04e7ddd7..7f73b61b12c63f 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -15,6 +15,7 @@ #include "Format.h" #include "HeaderSourceSwitch.h" #include "InlayHints.h" +#include "NoLintFixes.h" #include "ParsedAST.h" #include "Preamble.h" #include "Protocol.h" @@ -661,7 +662,7 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) { bool IsClangTidyRename = Diag->Source == Diag::ClangTidy && Diag->Name == "readability-identifier-naming" && !Fix.Edits.empty(); - if (IsClangTidyRename && Diag->InsideMainFile) { + if (IsClangTidyRename && !isNoLintFixes(Fix) && Diag->InsideMainFile) { ClangdServer::CodeActionResult::Rename R; R.NewName = Fix.Edits.front().newText; R.FixMessage = Fix.Message; diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index a59d1e7ac84096..6948e12995bed1 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -9,6 +9,7 @@ #include "Diagnostics.h" #include "../clang-tidy/ClangTidyDiagnosticConsumer.h" #include "Compiler.h" +#include "NoLintFixes.h" #include "Protocol.h" #include "SourceCode.h" #include "support/Logger.h" @@ -311,8 +312,18 @@ std::string mainMessage(const Diag &D, const ClangdDiagnosticOptions &Opts) { std::string Result; llvm::raw_string_ostream OS(Result); OS << D.Message; - if (Opts.DisplayFixesCount && !D.Fixes.empty()) -OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)"; + + // NOLINT fixes are somewhat not real fixes and to say "(fix available)" when + // the fixes is just to suppress could be misleading. + int RealFixCount = D.Fixes.size(); + for (auto const &Fix : D.Fixes) { +if (isNoLintFixes(Fix)) { + RealFixCount--; +} + } + + if (Opts.DisplayFixesCount && RealFixCount > 0) +OS << " (" << (RealFixCount > 1 ? "fixes" : "fix") << " available)"; // If notes aren't emitted as structured info, add them to the message. if (!Opts.EmitRelatedLocations) for (auto &Note : D.Notes) { @@ -822,8 +833,8 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, LastDiagOriginallyError = OriginallyError; if (!Info.getFixItHints().empty()) AddFix(true /* try to invent a message instead of repeating the diag */); -if (Fixer) { - auto ExtraFixes = Fixer(LastDiag->Severity, Info); +if (MainFixer) { + auto ExtraFixes = MainFixer(*LastDiag, Info); LastDiag->Fixes.insert(LastDiag->Fixes.end(), ExtraFixes.begin(), ExtraFixes.end()); } @@ -841,8 +852,8 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, return; // Give include-fixer a chance to replace a note with a fix. -if (Fixer) { - auto ReplacementFixes = Fixer(LastDiag->Severity, Info); +if (NoteFixer) { + auto ReplacementFixes = NoteFixer(*LastDiag, Info); if (!ReplacementFixes.empty()) { assert(Info.getNumFixItHints() == 0 && "Include-fixer replaced a note
[clang] [LoongArch][Clang] Make the parameters and return value of {x,}vorn.v builti ns `unsigned char` vectors (PR #114514)
https://github.com/xry111 updated https://github.com/llvm/llvm-project/pull/114514 >From 3d65a59473580f1c0e0b57bdd7fb13c9f40d3077 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Fri, 1 Nov 2024 00:07:17 +0800 Subject: [PATCH 1/5] [LoongArch][clang] Use `signed char` vectors instead of `char` vectors for LSX and LASX builtins `-flax-vector-conversions=none` does not allow an implicit conversion from `signed char` vector to `char` vector, and we cannot remove `signed` from `v16i8` or `v32i8` because doing so will break our expectation with `-fno-signed-char`. So to make lsxintrin.h and lasxintrin.h work fine with `-flax-vector-conversions=none`, we must use `signed char` instead of `char`. The change is just done via sed 's/V16c/V16Sc/g' -i BuiltinsLoongArchLSX.def sed 's/V32c/V32Sc/g' -i BuiltinsLoongArchLASX.def --- .../clang/Basic/BuiltinsLoongArchLASX.def | 142 +- .../clang/Basic/BuiltinsLoongArchLSX.def | 128 2 files changed, 135 insertions(+), 135 deletions(-) diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def index 4cf51cc000f6fc..0d7c2df5c5c503 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def @@ -12,29 +12,29 @@ // //===--===// -TARGET_BUILTIN(__builtin_lasx_xvadd_b, "V32cV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvadd_b, "V32ScV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_h, "V16sV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_w, "V8iV8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_d, "V4LLiV4LLiV4LLi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_q, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsub_b, "V32cV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsub_b, "V32ScV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_h, "V16sV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_w, "V8iV8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_d, "V4LLiV4LLiV4LLi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_q, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvaddi_bu, "V32cV32cIUi", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvaddi_bu, "V32ScV32ScIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddi_hu, "V16sV16sIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddi_wu, "V8iV8iIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddi_du, "V4LLiV4LLiIUi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsubi_bu, "V32cV32cIUi", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsubi_bu, "V32ScV32ScIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubi_hu, "V16sV16sIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubi_wu, "V8iV8iIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubi_du, "V4LLiV4LLiIUi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvneg_b, "V32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvneg_b, "V32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvneg_h, "V16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvneg_w, "V8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvneg_d, "V4LLiV4LLi", "nc", "lasx") @@ -79,22 +79,22 @@ TARGET_BUILTIN(__builtin_lasx_xvhsubw_wu_hu, "V8UiV16UsV16Us", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvhsubw_du_wu, "V4ULLiV8UiV8Ui", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvhsubw_qu_du, "V4ULLiV4ULLiV4ULLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvaddwev_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvaddwev_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwev_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwev_d_w, "V4LLiV8SiV8Si", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwev_q_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvaddwod_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvaddwod_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwod_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwod_d_w, "V4LLiV8SiV8Si", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwod_q_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsubwev_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsubwev_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwev_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwev_d_w, "V4LLiV8SiV8Si", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwev_q_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsubwod_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsubwod_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwod_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_
[clang] [LoongArch][Clang] Make the parameters and return value of {x,}vshuf.b builtins `signed char` vectors (PR #114512)
https://github.com/xry111 updated https://github.com/llvm/llvm-project/pull/114512 >From 3d65a59473580f1c0e0b57bdd7fb13c9f40d3077 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Fri, 1 Nov 2024 00:07:17 +0800 Subject: [PATCH 1/3] [LoongArch][clang] Use `signed char` vectors instead of `char` vectors for LSX and LASX builtins `-flax-vector-conversions=none` does not allow an implicit conversion from `signed char` vector to `char` vector, and we cannot remove `signed` from `v16i8` or `v32i8` because doing so will break our expectation with `-fno-signed-char`. So to make lsxintrin.h and lasxintrin.h work fine with `-flax-vector-conversions=none`, we must use `signed char` instead of `char`. The change is just done via sed 's/V16c/V16Sc/g' -i BuiltinsLoongArchLSX.def sed 's/V32c/V32Sc/g' -i BuiltinsLoongArchLASX.def --- .../clang/Basic/BuiltinsLoongArchLASX.def | 142 +- .../clang/Basic/BuiltinsLoongArchLSX.def | 128 2 files changed, 135 insertions(+), 135 deletions(-) diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def index 4cf51cc000f6fc..0d7c2df5c5c503 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def @@ -12,29 +12,29 @@ // //===--===// -TARGET_BUILTIN(__builtin_lasx_xvadd_b, "V32cV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvadd_b, "V32ScV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_h, "V16sV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_w, "V8iV8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_d, "V4LLiV4LLiV4LLi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_q, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsub_b, "V32cV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsub_b, "V32ScV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_h, "V16sV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_w, "V8iV8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_d, "V4LLiV4LLiV4LLi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_q, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvaddi_bu, "V32cV32cIUi", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvaddi_bu, "V32ScV32ScIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddi_hu, "V16sV16sIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddi_wu, "V8iV8iIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddi_du, "V4LLiV4LLiIUi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsubi_bu, "V32cV32cIUi", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsubi_bu, "V32ScV32ScIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubi_hu, "V16sV16sIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubi_wu, "V8iV8iIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubi_du, "V4LLiV4LLiIUi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvneg_b, "V32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvneg_b, "V32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvneg_h, "V16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvneg_w, "V8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvneg_d, "V4LLiV4LLi", "nc", "lasx") @@ -79,22 +79,22 @@ TARGET_BUILTIN(__builtin_lasx_xvhsubw_wu_hu, "V8UiV16UsV16Us", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvhsubw_du_wu, "V4ULLiV8UiV8Ui", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvhsubw_qu_du, "V4ULLiV4ULLiV4ULLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvaddwev_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvaddwev_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwev_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwev_d_w, "V4LLiV8SiV8Si", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwev_q_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvaddwod_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvaddwod_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwod_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwod_d_w, "V4LLiV8SiV8Si", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwod_q_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsubwev_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsubwev_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwev_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwev_d_w, "V4LLiV8SiV8Si", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwev_q_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsubwod_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsubwod_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwod_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_
[clang] b885054 - [LoongArch][clang] Use `signed char` vectors instead of `char` vectors for LSX and LASX builtins (#114510)
Author: Xi Ruoyao Date: 2024-11-02T15:49:40+08:00 New Revision: b88505414d47ca267f4df8823309264f78935686 URL: https://github.com/llvm/llvm-project/commit/b88505414d47ca267f4df8823309264f78935686 DIFF: https://github.com/llvm/llvm-project/commit/b88505414d47ca267f4df8823309264f78935686.diff LOG: [LoongArch][clang] Use `signed char` vectors instead of `char` vectors for LSX and LASX builtins (#114510) `-flax-vector-conversions=none` does not allow an implicit conversion from `signed char` vector to `char` vector, and we cannot remove `signed` from `v16i8` or `v32i8` because doing so will break our expectation with `-fno-signed-char`. So to make lsxintrin.h and lasxintrin.h work fine with `-flax-vector-conversions=none`, we must use `signed char` instead of `char`. The change is just done via sed 's/V16c/V16Sc/g' -i BuiltinsLoongArchLSX.def sed 's/V32c/V32Sc/g' -i BuiltinsLoongArchLASX.def Depends on #114509. Part of #110834 fix. Added: Modified: clang/include/clang/Basic/BuiltinsLoongArchLASX.def clang/include/clang/Basic/BuiltinsLoongArchLSX.def Removed: diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def index 4cf51cc000f6fc..0d7c2df5c5c503 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def @@ -12,29 +12,29 @@ // //===--===// -TARGET_BUILTIN(__builtin_lasx_xvadd_b, "V32cV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvadd_b, "V32ScV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_h, "V16sV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_w, "V8iV8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_d, "V4LLiV4LLiV4LLi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_q, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsub_b, "V32cV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsub_b, "V32ScV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_h, "V16sV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_w, "V8iV8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_d, "V4LLiV4LLiV4LLi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_q, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvaddi_bu, "V32cV32cIUi", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvaddi_bu, "V32ScV32ScIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddi_hu, "V16sV16sIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddi_wu, "V8iV8iIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddi_du, "V4LLiV4LLiIUi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsubi_bu, "V32cV32cIUi", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsubi_bu, "V32ScV32ScIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubi_hu, "V16sV16sIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubi_wu, "V8iV8iIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubi_du, "V4LLiV4LLiIUi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvneg_b, "V32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvneg_b, "V32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvneg_h, "V16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvneg_w, "V8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvneg_d, "V4LLiV4LLi", "nc", "lasx") @@ -79,22 +79,22 @@ TARGET_BUILTIN(__builtin_lasx_xvhsubw_wu_hu, "V8UiV16UsV16Us", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvhsubw_du_wu, "V4ULLiV8UiV8Ui", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvhsubw_qu_du, "V4ULLiV4ULLiV4ULLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvaddwev_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvaddwev_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwev_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwev_d_w, "V4LLiV8SiV8Si", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwev_q_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvaddwod_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvaddwod_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwod_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwod_d_w, "V4LLiV8SiV8Si", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwod_q_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsubwev_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsubwev_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwev_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwev_d_w, "V4LLiV8SiV8Si", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwev_q_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsubwod_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILT
[clang] [LoongArch][clang] Use `signed char` vectors instead of `char` vectors for LSX and LASX builtins (PR #114510)
https://github.com/SixWeining approved this pull request. LGTM. Thanks. https://github.com/llvm/llvm-project/pull/114510 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LoongArch][clang] Use `signed char` vectors instead of `char` vectors for LSX and LASX builtins (PR #114510)
https://github.com/SixWeining closed https://github.com/llvm/llvm-project/pull/114510 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LoongArch][Clang] Make the parameter and return value of {x,}vmsknz.b builtins `signed char` vector (PR #114511)
https://github.com/xry111 updated https://github.com/llvm/llvm-project/pull/114511 >From 3d65a59473580f1c0e0b57bdd7fb13c9f40d3077 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Fri, 1 Nov 2024 00:07:17 +0800 Subject: [PATCH 1/2] [LoongArch][clang] Use `signed char` vectors instead of `char` vectors for LSX and LASX builtins `-flax-vector-conversions=none` does not allow an implicit conversion from `signed char` vector to `char` vector, and we cannot remove `signed` from `v16i8` or `v32i8` because doing so will break our expectation with `-fno-signed-char`. So to make lsxintrin.h and lasxintrin.h work fine with `-flax-vector-conversions=none`, we must use `signed char` instead of `char`. The change is just done via sed 's/V16c/V16Sc/g' -i BuiltinsLoongArchLSX.def sed 's/V32c/V32Sc/g' -i BuiltinsLoongArchLASX.def --- .../clang/Basic/BuiltinsLoongArchLASX.def | 142 +- .../clang/Basic/BuiltinsLoongArchLSX.def | 128 2 files changed, 135 insertions(+), 135 deletions(-) diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def index 4cf51cc000f6fc..0d7c2df5c5c503 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def @@ -12,29 +12,29 @@ // //===--===// -TARGET_BUILTIN(__builtin_lasx_xvadd_b, "V32cV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvadd_b, "V32ScV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_h, "V16sV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_w, "V8iV8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_d, "V4LLiV4LLiV4LLi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_q, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsub_b, "V32cV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsub_b, "V32ScV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_h, "V16sV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_w, "V8iV8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_d, "V4LLiV4LLiV4LLi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_q, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvaddi_bu, "V32cV32cIUi", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvaddi_bu, "V32ScV32ScIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddi_hu, "V16sV16sIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddi_wu, "V8iV8iIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddi_du, "V4LLiV4LLiIUi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsubi_bu, "V32cV32cIUi", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsubi_bu, "V32ScV32ScIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubi_hu, "V16sV16sIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubi_wu, "V8iV8iIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubi_du, "V4LLiV4LLiIUi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvneg_b, "V32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvneg_b, "V32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvneg_h, "V16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvneg_w, "V8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvneg_d, "V4LLiV4LLi", "nc", "lasx") @@ -79,22 +79,22 @@ TARGET_BUILTIN(__builtin_lasx_xvhsubw_wu_hu, "V8UiV16UsV16Us", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvhsubw_du_wu, "V4ULLiV8UiV8Ui", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvhsubw_qu_du, "V4ULLiV4ULLiV4ULLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvaddwev_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvaddwev_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwev_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwev_d_w, "V4LLiV8SiV8Si", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwev_q_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvaddwod_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvaddwod_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwod_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwod_d_w, "V4LLiV8SiV8Si", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwod_q_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsubwev_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsubwev_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwev_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwev_d_w, "V4LLiV8SiV8Si", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwev_q_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsubwod_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsubwod_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwod_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_
[clang] [LoongArch][clang] Use `signed char` vectors instead of `char` vectors for LSX and LASX builtins (PR #114510)
https://github.com/xry111 updated https://github.com/llvm/llvm-project/pull/114510 >From 3d65a59473580f1c0e0b57bdd7fb13c9f40d3077 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Fri, 1 Nov 2024 00:07:17 +0800 Subject: [PATCH] [LoongArch][clang] Use `signed char` vectors instead of `char` vectors for LSX and LASX builtins `-flax-vector-conversions=none` does not allow an implicit conversion from `signed char` vector to `char` vector, and we cannot remove `signed` from `v16i8` or `v32i8` because doing so will break our expectation with `-fno-signed-char`. So to make lsxintrin.h and lasxintrin.h work fine with `-flax-vector-conversions=none`, we must use `signed char` instead of `char`. The change is just done via sed 's/V16c/V16Sc/g' -i BuiltinsLoongArchLSX.def sed 's/V32c/V32Sc/g' -i BuiltinsLoongArchLASX.def --- .../clang/Basic/BuiltinsLoongArchLASX.def | 142 +- .../clang/Basic/BuiltinsLoongArchLSX.def | 128 2 files changed, 135 insertions(+), 135 deletions(-) diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def index 4cf51cc000f6fc..0d7c2df5c5c503 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def @@ -12,29 +12,29 @@ // //===--===// -TARGET_BUILTIN(__builtin_lasx_xvadd_b, "V32cV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvadd_b, "V32ScV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_h, "V16sV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_w, "V8iV8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_d, "V4LLiV4LLiV4LLi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_q, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsub_b, "V32cV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsub_b, "V32ScV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_h, "V16sV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_w, "V8iV8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_d, "V4LLiV4LLiV4LLi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_q, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvaddi_bu, "V32cV32cIUi", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvaddi_bu, "V32ScV32ScIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddi_hu, "V16sV16sIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddi_wu, "V8iV8iIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddi_du, "V4LLiV4LLiIUi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsubi_bu, "V32cV32cIUi", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsubi_bu, "V32ScV32ScIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubi_hu, "V16sV16sIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubi_wu, "V8iV8iIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubi_du, "V4LLiV4LLiIUi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvneg_b, "V32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvneg_b, "V32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvneg_h, "V16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvneg_w, "V8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvneg_d, "V4LLiV4LLi", "nc", "lasx") @@ -79,22 +79,22 @@ TARGET_BUILTIN(__builtin_lasx_xvhsubw_wu_hu, "V8UiV16UsV16Us", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvhsubw_du_wu, "V4ULLiV8UiV8Ui", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvhsubw_qu_du, "V4ULLiV4ULLiV4ULLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvaddwev_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvaddwev_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwev_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwev_d_w, "V4LLiV8SiV8Si", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwev_q_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvaddwod_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvaddwod_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwod_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwod_d_w, "V4LLiV8SiV8Si", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwod_q_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsubwev_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsubwev_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwev_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwev_d_w, "V4LLiV8SiV8Si", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwev_q_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsubwod_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsubwod_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwod_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx
[clang] 96d2196 - [LoongArch][Clang] Add tests for #110834 (#114509)
Author: Xi Ruoyao Date: 2024-11-02T15:39:15+08:00 New Revision: 96d2196f6f73e5712f1df8cd26de8a12c7f24de4 URL: https://github.com/llvm/llvm-project/commit/96d2196f6f73e5712f1df8cd26de8a12c7f24de4 DIFF: https://github.com/llvm/llvm-project/commit/96d2196f6f73e5712f1df8cd26de8a12c7f24de4.diff LOG: [LoongArch][Clang] Add tests for #110834 (#114509) Added: clang/test/Headers/lasxintrin.c clang/test/Headers/lsxintrin.c Modified: Removed: diff --git a/clang/test/Headers/lasxintrin.c b/clang/test/Headers/lasxintrin.c new file mode 100644 index 00..6126c6350455c1 --- /dev/null +++ b/clang/test/Headers/lasxintrin.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 %s -fsyntax-only -triple loongarch64 -target-feature +lasx +// RUN: not %clang_cc1 %s -fsyntax-only -triple loongarch64 -target-feature +lasx -flax-vector-conversions=none +// RUN: not %clang_cc1 %s -fsyntax-only -triple loongarch64 -target-feature +lasx -flax-vector-conversions=none -fno-signed-char +// FIXME: "not" should be removed once we fix GH#110834. + +#include diff --git a/clang/test/Headers/lsxintrin.c b/clang/test/Headers/lsxintrin.c new file mode 100644 index 00..930d3efe62e543 --- /dev/null +++ b/clang/test/Headers/lsxintrin.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 %s -fsyntax-only -triple loongarch64 -target-feature +lsx +// RUN: not %clang_cc1 %s -fsyntax-only -triple loongarch64 -target-feature +lsx -flax-vector-conversions=none +// RUN: not %clang_cc1 %s -fsyntax-only -triple loongarch64 -target-feature +lsx -flax-vector-conversions=none -fno-signed-char +// FIXME: "not" should be removed once we fix GH#110834. + +#include ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LoongArch][Clang] Add tests for #110834 (PR #114509)
https://github.com/SixWeining closed https://github.com/llvm/llvm-project/pull/114509 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LoongArch][Clang] Add tests for #110834 (PR #114509)
https://github.com/SixWeining approved this pull request. https://github.com/llvm/llvm-project/pull/114509 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LoongArch][Clang] Make the parameter and return value of {x,}vmsknz.b builtins `signed char` vector (PR #114511)
https://github.com/xry111 updated https://github.com/llvm/llvm-project/pull/114511 >From ef96a6e483030e649d69ffa778c0b0f229bbb739 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Fri, 1 Nov 2024 00:13:29 +0800 Subject: [PATCH] [LoongArch][Clang] Make the parameter and return value of {x,}vmsknz.b builtins `signed char` vector These builtins operate on int8 vectors, not int16 vectors. So the old definition does not make any sense. --- clang/include/clang/Basic/BuiltinsLoongArchLASX.def | 2 +- clang/include/clang/Basic/BuiltinsLoongArchLSX.def | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def index 0d7c2df5c5c503..477f704860873c 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def @@ -357,7 +357,7 @@ TARGET_BUILTIN(__builtin_lasx_xvmskltz_w, "V8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvmskltz_d, "V4LLiV4LLi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvmskgez_b, "V32ScV32Sc", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvmsknz_b, "V16sV16s", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvmsknz_b, "V32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvldi, "V4LLiIi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvrepli_b, "V32ScIi", "nc", "lasx") diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLSX.def b/clang/include/clang/Basic/BuiltinsLoongArchLSX.def index 25a178e1ca98ab..e847985f390367 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLSX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLSX.def @@ -341,7 +341,7 @@ TARGET_BUILTIN(__builtin_lsx_vmskltz_w, "V4iV4i", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vmskltz_d, "V2LLiV2LLi", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vmskgez_b, "V16ScV16Sc", "nc", "lsx") -TARGET_BUILTIN(__builtin_lsx_vmsknz_b, "V8sV8s", "nc", "lsx") +TARGET_BUILTIN(__builtin_lsx_vmsknz_b, "V16ScV16Sc", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vldi, "V2LLiIi", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vrepli_b, "V16ScIi", "nc", "lsx") ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LoongArch][Clang] Make the parameters and return value of {x,}vxor.v builti ns `unsigned char` vectors (PR #114513)
https://github.com/xry111 updated https://github.com/llvm/llvm-project/pull/114513 >From 3d65a59473580f1c0e0b57bdd7fb13c9f40d3077 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Fri, 1 Nov 2024 00:07:17 +0800 Subject: [PATCH 1/4] [LoongArch][clang] Use `signed char` vectors instead of `char` vectors for LSX and LASX builtins `-flax-vector-conversions=none` does not allow an implicit conversion from `signed char` vector to `char` vector, and we cannot remove `signed` from `v16i8` or `v32i8` because doing so will break our expectation with `-fno-signed-char`. So to make lsxintrin.h and lasxintrin.h work fine with `-flax-vector-conversions=none`, we must use `signed char` instead of `char`. The change is just done via sed 's/V16c/V16Sc/g' -i BuiltinsLoongArchLSX.def sed 's/V32c/V32Sc/g' -i BuiltinsLoongArchLASX.def --- .../clang/Basic/BuiltinsLoongArchLASX.def | 142 +- .../clang/Basic/BuiltinsLoongArchLSX.def | 128 2 files changed, 135 insertions(+), 135 deletions(-) diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def index 4cf51cc000f6fc..0d7c2df5c5c503 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def @@ -12,29 +12,29 @@ // //===--===// -TARGET_BUILTIN(__builtin_lasx_xvadd_b, "V32cV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvadd_b, "V32ScV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_h, "V16sV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_w, "V8iV8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_d, "V4LLiV4LLiV4LLi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvadd_q, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsub_b, "V32cV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsub_b, "V32ScV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_h, "V16sV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_w, "V8iV8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_d, "V4LLiV4LLiV4LLi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsub_q, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvaddi_bu, "V32cV32cIUi", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvaddi_bu, "V32ScV32ScIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddi_hu, "V16sV16sIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddi_wu, "V8iV8iIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddi_du, "V4LLiV4LLiIUi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsubi_bu, "V32cV32cIUi", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsubi_bu, "V32ScV32ScIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubi_hu, "V16sV16sIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubi_wu, "V8iV8iIUi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubi_du, "V4LLiV4LLiIUi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvneg_b, "V32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvneg_b, "V32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvneg_h, "V16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvneg_w, "V8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvneg_d, "V4LLiV4LLi", "nc", "lasx") @@ -79,22 +79,22 @@ TARGET_BUILTIN(__builtin_lasx_xvhsubw_wu_hu, "V8UiV16UsV16Us", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvhsubw_du_wu, "V4ULLiV8UiV8Ui", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvhsubw_qu_du, "V4ULLiV4ULLiV4ULLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvaddwev_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvaddwev_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwev_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwev_d_w, "V4LLiV8SiV8Si", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwev_q_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvaddwod_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvaddwod_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwod_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwod_d_w, "V4LLiV8SiV8Si", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvaddwod_q_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsubwev_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsubwev_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwev_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwev_d_w, "V4LLiV8SiV8Si", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwev_q_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvsubwod_h_b, "V16sV32cV32c", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvsubwod_h_b, "V16sV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvsubwod_w_h, "V8SiV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_
[clang] [LoongArch][Clang] Make the parameters and return value of {x,}vorn.v builti ns `unsigned char` vectors (PR #114514)
https://github.com/xry111 updated https://github.com/llvm/llvm-project/pull/114514 >From ef96a6e483030e649d69ffa778c0b0f229bbb739 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Fri, 1 Nov 2024 00:13:29 +0800 Subject: [PATCH 1/4] [LoongArch][Clang] Make the parameter and return value of {x,}vmsknz.b builtins `signed char` vector These builtins operate on int8 vectors, not int16 vectors. So the old definition does not make any sense. --- clang/include/clang/Basic/BuiltinsLoongArchLASX.def | 2 +- clang/include/clang/Basic/BuiltinsLoongArchLSX.def | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def index 0d7c2df5c5c503..477f704860873c 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def @@ -357,7 +357,7 @@ TARGET_BUILTIN(__builtin_lasx_xvmskltz_w, "V8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvmskltz_d, "V4LLiV4LLi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvmskgez_b, "V32ScV32Sc", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvmsknz_b, "V16sV16s", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvmsknz_b, "V32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvldi, "V4LLiIi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvrepli_b, "V32ScIi", "nc", "lasx") diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLSX.def b/clang/include/clang/Basic/BuiltinsLoongArchLSX.def index 25a178e1ca98ab..e847985f390367 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLSX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLSX.def @@ -341,7 +341,7 @@ TARGET_BUILTIN(__builtin_lsx_vmskltz_w, "V4iV4i", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vmskltz_d, "V2LLiV2LLi", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vmskgez_b, "V16ScV16Sc", "nc", "lsx") -TARGET_BUILTIN(__builtin_lsx_vmsknz_b, "V8sV8s", "nc", "lsx") +TARGET_BUILTIN(__builtin_lsx_vmsknz_b, "V16ScV16Sc", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vldi, "V2LLiIi", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vrepli_b, "V16ScIi", "nc", "lsx") >From 349b79172a1ede63a25173366c1607b001bf1511 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Fri, 1 Nov 2024 00:17:44 +0800 Subject: [PATCH 2/4] [LoongArch][Clang] Make the parameters and return value of {x,}vshuf.b builtins `signed char` vectors The lsxintrin.h and and lasxintrin.h headers uses `signed char` vectors instead of `unsigned char` vectors. GCC also uses `signed char` for them, so align their definition with the headers and GCC. --- clang/include/clang/Basic/BuiltinsLoongArchLASX.def | 2 +- clang/include/clang/Basic/BuiltinsLoongArchLSX.def | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def index 477f704860873c..e6c41dd0974948 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def @@ -935,7 +935,7 @@ TARGET_BUILTIN(__builtin_lasx_xvilvh_h, "V16sV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvilvh_w, "V8iV8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvilvh_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvshuf_b, "V32UcV32UcV32UcV32Uc", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvshuf_b, "V32ScV32ScV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvshuf_h, "V16sV16sV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvshuf_w, "V8iV8iV8iV8i", "nc", "lasx") diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLSX.def b/clang/include/clang/Basic/BuiltinsLoongArchLSX.def index e847985f390367..ded6519f3ef16c 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLSX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLSX.def @@ -910,7 +910,7 @@ TARGET_BUILTIN(__builtin_lsx_vilvh_h, "V8sV8sV8s", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vilvh_w, "V4iV4iV4i", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vilvh_d, "V2LLiV2LLiV2LLi", "nc", "lsx") -TARGET_BUILTIN(__builtin_lsx_vshuf_b, "V16UcV16UcV16UcV16Uc", "nc", "lsx") +TARGET_BUILTIN(__builtin_lsx_vshuf_b, "V16ScV16ScV16ScV16Sc", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vshuf_h, "V8sV8sV8sV8s", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vshuf_w, "V4iV4iV4iV4i", "nc", "lsx") >From bf82a2490d77457f2afd92da7a09020f59d465e4 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Fri, 1 Nov 2024 00:22:09 +0800 Subject: [PATCH 3/4] [LoongArch][Clang] Make the parameters and return value of {x,}vxor.v builtins `unsigned char` vectors The lsxintrin.h and and lasxintrin.h headers uses `unsigned char` vectors instead of `signed char` vectors. GCC also uses `unsigned char` for them, so align their definition with the headers and GCC. Fixes #110834. --- clang/include/clang/Basic/BuiltinsLoongArchLASX.def | 2 +- clang/include/clang/Basic/BuiltinsLoongArchLSX.def | 2 +- clang/test/Head
[clang] [LoongArch][Clang] Make the parameters and return value of {x,}vxor.v builti ns `unsigned char` vectors (PR #114513)
https://github.com/xry111 updated https://github.com/llvm/llvm-project/pull/114513 >From ef96a6e483030e649d69ffa778c0b0f229bbb739 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Fri, 1 Nov 2024 00:13:29 +0800 Subject: [PATCH 1/3] [LoongArch][Clang] Make the parameter and return value of {x,}vmsknz.b builtins `signed char` vector These builtins operate on int8 vectors, not int16 vectors. So the old definition does not make any sense. --- clang/include/clang/Basic/BuiltinsLoongArchLASX.def | 2 +- clang/include/clang/Basic/BuiltinsLoongArchLSX.def | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def index 0d7c2df5c5c503..477f704860873c 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def @@ -357,7 +357,7 @@ TARGET_BUILTIN(__builtin_lasx_xvmskltz_w, "V8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvmskltz_d, "V4LLiV4LLi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvmskgez_b, "V32ScV32Sc", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvmsknz_b, "V16sV16s", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvmsknz_b, "V32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvldi, "V4LLiIi", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvrepli_b, "V32ScIi", "nc", "lasx") diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLSX.def b/clang/include/clang/Basic/BuiltinsLoongArchLSX.def index 25a178e1ca98ab..e847985f390367 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLSX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLSX.def @@ -341,7 +341,7 @@ TARGET_BUILTIN(__builtin_lsx_vmskltz_w, "V4iV4i", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vmskltz_d, "V2LLiV2LLi", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vmskgez_b, "V16ScV16Sc", "nc", "lsx") -TARGET_BUILTIN(__builtin_lsx_vmsknz_b, "V8sV8s", "nc", "lsx") +TARGET_BUILTIN(__builtin_lsx_vmsknz_b, "V16ScV16Sc", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vldi, "V2LLiIi", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vrepli_b, "V16ScIi", "nc", "lsx") >From 349b79172a1ede63a25173366c1607b001bf1511 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Fri, 1 Nov 2024 00:17:44 +0800 Subject: [PATCH 2/3] [LoongArch][Clang] Make the parameters and return value of {x,}vshuf.b builtins `signed char` vectors The lsxintrin.h and and lasxintrin.h headers uses `signed char` vectors instead of `unsigned char` vectors. GCC also uses `signed char` for them, so align their definition with the headers and GCC. --- clang/include/clang/Basic/BuiltinsLoongArchLASX.def | 2 +- clang/include/clang/Basic/BuiltinsLoongArchLSX.def | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def index 477f704860873c..e6c41dd0974948 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def @@ -935,7 +935,7 @@ TARGET_BUILTIN(__builtin_lasx_xvilvh_h, "V16sV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvilvh_w, "V8iV8iV8i", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvilvh_d, "V4LLiV4LLiV4LLi", "nc", "lasx") -TARGET_BUILTIN(__builtin_lasx_xvshuf_b, "V32UcV32UcV32UcV32Uc", "nc", "lasx") +TARGET_BUILTIN(__builtin_lasx_xvshuf_b, "V32ScV32ScV32ScV32Sc", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvshuf_h, "V16sV16sV16sV16s", "nc", "lasx") TARGET_BUILTIN(__builtin_lasx_xvshuf_w, "V8iV8iV8iV8i", "nc", "lasx") diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLSX.def b/clang/include/clang/Basic/BuiltinsLoongArchLSX.def index e847985f390367..ded6519f3ef16c 100644 --- a/clang/include/clang/Basic/BuiltinsLoongArchLSX.def +++ b/clang/include/clang/Basic/BuiltinsLoongArchLSX.def @@ -910,7 +910,7 @@ TARGET_BUILTIN(__builtin_lsx_vilvh_h, "V8sV8sV8s", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vilvh_w, "V4iV4iV4i", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vilvh_d, "V2LLiV2LLiV2LLi", "nc", "lsx") -TARGET_BUILTIN(__builtin_lsx_vshuf_b, "V16UcV16UcV16UcV16Uc", "nc", "lsx") +TARGET_BUILTIN(__builtin_lsx_vshuf_b, "V16ScV16ScV16ScV16Sc", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vshuf_h, "V8sV8sV8sV8s", "nc", "lsx") TARGET_BUILTIN(__builtin_lsx_vshuf_w, "V4iV4iV4iV4i", "nc", "lsx") >From bf82a2490d77457f2afd92da7a09020f59d465e4 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Fri, 1 Nov 2024 00:22:09 +0800 Subject: [PATCH 3/3] [LoongArch][Clang] Make the parameters and return value of {x,}vxor.v builtins `unsigned char` vectors The lsxintrin.h and and lasxintrin.h headers uses `unsigned char` vectors instead of `signed char` vectors. GCC also uses `unsigned char` for them, so align their definition with the headers and GCC. Fixes #110834. --- clang/include/clang/Basic/BuiltinsLoongArchLASX.def | 2 +- clang/include/clang/Basic/BuiltinsLoongArchLSX.def | 2 +- clang/test/Head
[clang-tools-extra] [clang-tidy] Improved readability redundant casting with enums (PR #111424)
=?utf-8?q?F=C3=A9lix-Antoine?= Constantin, =?utf-8?q?F=C3=A9lix-Antoine?= Constantin Message-ID: In-Reply-To: @@ -222,6 +222,12 @@ Changes in existing checks by adding the option `UseUpperCaseLiteralSuffix` to select the case of the literal suffix in fixes. +- Improved :doc:`readability-redundant-casting + ` check by fixing + false negatives related to ``enum`` when setting `IgnoreTypeAliases` + to `true`. + + EugeneZelenko wrote: Excessive newline. https://github.com/llvm/llvm-project/pull/111424 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)
@@ -132,18 +132,97 @@ is a zero-based file offset, assuming ‘utf-8-unix’ coding." (lambda (byte &optional _quality _coding-system) (byte-to-position (1+ byte) -;;;###autoload -(defun clang-format-region (start end &optional style assume-file-name) - "Use clang-format to format the code between START and END according to STYLE. -If called interactively uses the region or the current statement if there is no -no active region. If no STYLE is given uses `clang-format-style'. Use -ASSUME-FILE-NAME to locate a style config file, if no ASSUME-FILE-NAME is given -uses the function `buffer-file-name'." - (interactive - (if (use-region-p) - (list (region-beginning) (region-end)) - (list (point) (point +(defun clang-format--git-diffs-get-diff-lines (file-orig file-new) + "Return all line regions that contain diffs between FILE-ORIG and +FILE-NEW. If there is no diff 'nil' is returned. Otherwise the +return is a 'list' of lines in the format '--lines=:' +which can be passed directly to 'clang-format'" + ;; Temporary buffer for output of diff. + (with-temp-buffer +(let ((status (call-process + "diff" + nil + (current-buffer) + nil + ;; Binary diff has different behaviors that we + ;; aren't interested in. + "-a" + ;; Printout changes as only the line groups. + "--changed-group-format=--lines=%dF:%dL " + ;; Ignore unchanged content. + "--unchanged-group-format=" + file-orig + file-new ideasman42 wrote: \*picky\* don't use dangling parenthesis. https://github.com/llvm/llvm-project/pull/112792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)
@@ -132,18 +132,97 @@ is a zero-based file offset, assuming ‘utf-8-unix’ coding." (lambda (byte &optional _quality _coding-system) (byte-to-position (1+ byte) -;;;###autoload -(defun clang-format-region (start end &optional style assume-file-name) - "Use clang-format to format the code between START and END according to STYLE. -If called interactively uses the region or the current statement if there is no -no active region. If no STYLE is given uses `clang-format-style'. Use -ASSUME-FILE-NAME to locate a style config file, if no ASSUME-FILE-NAME is given -uses the function `buffer-file-name'." - (interactive - (if (use-region-p) - (list (region-beginning) (region-end)) - (list (point) (point +(defun clang-format--git-diffs-get-diff-lines (file-orig file-new) + "Return all line regions that contain diffs between FILE-ORIG and +FILE-NEW. If there is no diff 'nil' is returned. Otherwise the +return is a 'list' of lines in the format '--lines=:' +which can be passed directly to 'clang-format'" + ;; Temporary buffer for output of diff. + (with-temp-buffer +(let ((status (call-process + "diff" + nil + (current-buffer) + nil + ;; Binary diff has different behaviors that we + ;; aren't interested in. + "-a" + ;; Printout changes as only the line groups. + "--changed-group-format=--lines=%dF:%dL " + ;; Ignore unchanged content. + "--unchanged-group-format=" + file-orig + file-new + ) + ) + (stderr (concat (if (zerop (buffer-size)) "" ": ") + (buffer-substring-no-properties + (point-min) (line-end-position) + (when (stringp status) +(error "(diff killed by signal %s%s)" status stderr)) + (unless (= status 0) +(unless (= status 1) + (error "(diff returned unsuccessfully %s%s)" status stderr))) + + + (if (= status 0) + ;; Status == 0 -> no Diff. + nil +(progn + ;; Split "--lines=:... --lines=:" output to + ;; a list for return. + (s-split + " " + (string-trim +(buffer-substring-no-properties + (point-min) (point-max) + +(defun clang-format--git-diffs-get-git-head-file () + "Returns a temporary file with the content of 'buffer-file-name' at +git revision HEAD. If the current buffer is either not a file or not +in a git repo, this results in an error" + ;; Needs current buffer to be a file + (unless (buffer-file-name) +(error "Buffer is not visiting a file")) + ;; Need to be able to find version control (git) root + (unless (vc-root-dir) +(error "File not known to git")) + ;; Need version control to in fact be git + (unless (string-equal (vc-backend (buffer-file-name)) "Git") +(error "Not using git")) + + (let ((tmpfile-git-head (make-temp-file "clang-format-tmp-git-head-content"))) ideasman42 wrote: >From what I can tell this temporary file is never deleted, further, any errors >after creating the temporary file would leave it created. Without attempting to do this myself, I'm not sure of the best solution but suggest: `(with-temp-file ...)` The caller would need to use this and pass in the temporary file file. If the behavior of `with-temp-file` isn't what your after, you could write your own macro that creates a scoped temporary file that gets removed in case of errors. https://github.com/llvm/llvm-project/pull/112792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)
@@ -132,18 +132,97 @@ is a zero-based file offset, assuming ‘utf-8-unix’ coding." (lambda (byte &optional _quality _coding-system) (byte-to-position (1+ byte) -;;;###autoload -(defun clang-format-region (start end &optional style assume-file-name) - "Use clang-format to format the code between START and END according to STYLE. -If called interactively uses the region or the current statement if there is no -no active region. If no STYLE is given uses `clang-format-style'. Use -ASSUME-FILE-NAME to locate a style config file, if no ASSUME-FILE-NAME is given -uses the function `buffer-file-name'." - (interactive - (if (use-region-p) - (list (region-beginning) (region-end)) - (list (point) (point +(defun clang-format--git-diffs-get-diff-lines (file-orig file-new) + "Return all line regions that contain diffs between FILE-ORIG and +FILE-NEW. If there is no diff 'nil' is returned. Otherwise the +return is a 'list' of lines in the format '--lines=:' +which can be passed directly to 'clang-format'" + ;; Temporary buffer for output of diff. + (with-temp-buffer +(let ((status (call-process + "diff" + nil + (current-buffer) + nil + ;; Binary diff has different behaviors that we + ;; aren't interested in. + "-a" + ;; Printout changes as only the line groups. + "--changed-group-format=--lines=%dF:%dL " + ;; Ignore unchanged content. + "--unchanged-group-format=" + file-orig + file-new + ) + ) + (stderr (concat (if (zerop (buffer-size)) "" ": ") + (buffer-substring-no-properties + (point-min) (line-end-position) + (when (stringp status) +(error "(diff killed by signal %s%s)" status stderr)) + (unless (= status 0) +(unless (= status 1) + (error "(diff returned unsuccessfully %s%s)" status stderr))) + + + (if (= status 0) + ;; Status == 0 -> no Diff. + nil +(progn + ;; Split "--lines=:... --lines=:" output to + ;; a list for return. + (s-split + " " + (string-trim +(buffer-substring-no-properties + (point-min) (point-max) + +(defun clang-format--git-diffs-get-git-head-file () + "Returns a temporary file with the content of 'buffer-file-name' at +git revision HEAD. If the current buffer is either not a file or not +in a git repo, this results in an error" + ;; Needs current buffer to be a file + (unless (buffer-file-name) +(error "Buffer is not visiting a file")) + ;; Need to be able to find version control (git) root + (unless (vc-root-dir) ideasman42 wrote: \*picky\* assign this to a variable and reuse it instead of calling twice. https://github.com/llvm/llvm-project/pull/112792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)
https://github.com/ideasman42 edited https://github.com/llvm/llvm-project/pull/112792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)
https://github.com/ideasman42 requested changes to this pull request. Note that I'm not a regular clang contributor, I just submitted a small improvement to clang-format, and maintain some emacs packages in elpa & melpa. Overall the PR looks like it needs more attention to detail, as far as I can tell it's creating temporary files and never removing them, various minor issues noted inline. - This PR needs to be rebased on top of the recently added `clang-format-on-save-mode` commit. - Running `package-lint` reports. ``` 156:19: warning: Closing parens should not be wrapped onto new lines. 157:18: warning: Closing parens should not be wrapped onto new lines. 176:12: error: You should depend on (emacs "24.4") or the compat package if you need `string-trim'. 188:11: error: You should depend on (emacs "25.1") if you need `vc-root-dir'. 198:59: error: You should depend on (emacs "25.1") if you need `vc-root-dir'. ``` https://github.com/llvm/llvm-project/pull/112792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)
@@ -132,18 +132,97 @@ is a zero-based file offset, assuming ‘utf-8-unix’ coding." (lambda (byte &optional _quality _coding-system) (byte-to-position (1+ byte) -;;;###autoload -(defun clang-format-region (start end &optional style assume-file-name) - "Use clang-format to format the code between START and END according to STYLE. -If called interactively uses the region or the current statement if there is no -no active region. If no STYLE is given uses `clang-format-style'. Use -ASSUME-FILE-NAME to locate a style config file, if no ASSUME-FILE-NAME is given -uses the function `buffer-file-name'." - (interactive - (if (use-region-p) - (list (region-beginning) (region-end)) - (list (point) (point +(defun clang-format--git-diffs-get-diff-lines (file-orig file-new) + "Return all line regions that contain diffs between FILE-ORIG and +FILE-NEW. If there is no diff 'nil' is returned. Otherwise the +return is a 'list' of lines in the format '--lines=:' +which can be passed directly to 'clang-format'" + ;; Temporary buffer for output of diff. + (with-temp-buffer +(let ((status (call-process + "diff" + nil + (current-buffer) + nil + ;; Binary diff has different behaviors that we + ;; aren't interested in. + "-a" + ;; Printout changes as only the line groups. + "--changed-group-format=--lines=%dF:%dL " + ;; Ignore unchanged content. + "--unchanged-group-format=" + file-orig + file-new + ) + ) + (stderr (concat (if (zerop (buffer-size)) "" ": ") + (buffer-substring-no-properties + (point-min) (line-end-position) + (when (stringp status) +(error "(diff killed by signal %s%s)" status stderr)) + (unless (= status 0) +(unless (= status 1) + (error "(diff returned unsuccessfully %s%s)" status stderr))) + + + (if (= status 0) + ;; Status == 0 -> no Diff. + nil +(progn + ;; Split "--lines=:... --lines=:" output to + ;; a list for return. + (s-split ideasman42 wrote: `s-split` is not part of emacs standard library, depending on https://github.com/magnars/s.el doesn't seem worthwhile, use built-in emacs functionality. https://github.com/llvm/llvm-project/pull/112792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)
@@ -132,18 +132,97 @@ is a zero-based file offset, assuming ‘utf-8-unix’ coding." (lambda (byte &optional _quality _coding-system) (byte-to-position (1+ byte) -;;;###autoload -(defun clang-format-region (start end &optional style assume-file-name) - "Use clang-format to format the code between START and END according to STYLE. -If called interactively uses the region or the current statement if there is no -no active region. If no STYLE is given uses `clang-format-style'. Use -ASSUME-FILE-NAME to locate a style config file, if no ASSUME-FILE-NAME is given -uses the function `buffer-file-name'." - (interactive - (if (use-region-p) - (list (region-beginning) (region-end)) - (list (point) (point +(defun clang-format--git-diffs-get-diff-lines (file-orig file-new) + "Return all line regions that contain diffs between FILE-ORIG and +FILE-NEW. If there is no diff 'nil' is returned. Otherwise the +return is a 'list' of lines in the format '--lines=:' +which can be passed directly to 'clang-format'" + ;; Temporary buffer for output of diff. + (with-temp-buffer +(let ((status (call-process + "diff" + nil + (current-buffer) + nil + ;; Binary diff has different behaviors that we + ;; aren't interested in. + "-a" + ;; Printout changes as only the line groups. + "--changed-group-format=--lines=%dF:%dL " + ;; Ignore unchanged content. + "--unchanged-group-format=" + file-orig + file-new + ) + ) + (stderr (concat (if (zerop (buffer-size)) "" ": ") + (buffer-substring-no-properties + (point-min) (line-end-position) + (when (stringp status) ideasman42 wrote: \*picky\* I think a `(cond ...)` would read better than unless & if statements. example: ```elisp (cond ((stringp status) ...snip...) ((= status 0) nil) ((= status 1) ...snip...) (t (error ...snip...))) ``` https://github.com/llvm/llvm-project/pull/112792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)
https://github.com/ideasman42 edited https://github.com/llvm/llvm-project/pull/112792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)
https://github.com/ideasman42 edited https://github.com/llvm/llvm-project/pull/112792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)
https://github.com/ideasman42 edited https://github.com/llvm/llvm-project/pull/112792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)
@@ -205,14 +288,60 @@ uses the function `buffer-file-name'." (delete-file temp-file) (when (buffer-name temp-buffer) (kill-buffer temp-buffer) +;;;###autoload +(defun clang-format-git-diffs (&optional style assume-file-name) + "The same as 'clang-format-buffer' but only operates on the git +diffs from HEAD in the buffer. If no STYLE is given uses +`clang-format-style'. Use ASSUME-FILE-NAME to locate a style config +file. If no ASSUME-FILE-NAME is given uses the function +`buffer-file-name'." + (interactive) + (let ((tmpfile-git-head + (clang-format--git-diffs-get-git-head-file)) +(tmpfile-curbuf (make-temp-file "clang-format-git-tmp"))) ideasman42 wrote: It looks like this temporary file isn't removed either. https://github.com/llvm/llvm-project/pull/112792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)
@@ -205,14 +288,60 @@ uses the function `buffer-file-name'." (delete-file temp-file) (when (buffer-name temp-buffer) (kill-buffer temp-buffer) +;;;###autoload +(defun clang-format-git-diffs (&optional style assume-file-name) ideasman42 wrote: A more general point, would it make sense to call this `clang-format-vc-diffs` - which currently only supports git? This way we wouldn't need `clang-format-hg-diffs` or separate commands to support other version control systems in the future. https://github.com/llvm/llvm-project/pull/112792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)
https://github.com/ideasman42 edited https://github.com/llvm/llvm-project/pull/112792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)
https://github.com/ideasman42 edited https://github.com/llvm/llvm-project/pull/112792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix clang-format-test.el past 625841c (PR #106398)
owenca wrote: > Race condition! Will update the other PR. @dklimkin can you link to "the other PR"? Should we revert this one now? cc @mydeveloperday @HazardyKnusperkeks https://github.com/llvm/llvm-project/pull/106398 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)
owenca wrote: @ideasman42 can you review this PR? Thanks! https://github.com/llvm/llvm-project/pull/112792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)
goldsteinn wrote: @luke957 as well also can probably review the elisp code for quality. https://github.com/llvm/llvm-project/pull/112792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Allow -fuse-lld=lld-link when lto is enabled on *windows-msvc targets (PR #113966)
https://github.com/MaskRay approved this pull request. https://github.com/llvm/llvm-project/pull/113966 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Allow -fuse-lld=lld-link when lto is enabled on *windows-msvc targets (PR #113966)
@@ -0,0 +1,9 @@ +// RUN: %clang --target=aarch64-pc-windows-msvc -O3 -flto -fuse-ld=lld -### %s 2>&1 | FileCheck %s +// RUN: %clang --target=aarch64-pc-windows-msvc -O3 -flto=thin -fuse-ld=lld -### %s 2>&1 | FileCheck %s +// MaskRay wrote: delete `^//$` lines https://github.com/llvm/llvm-project/pull/113966 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [XRay][AArch64] Support -fxray-shared (PR #114431)
@@ -67,8 +67,12 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) { false)) { XRayShared = true; -// DSO instrumentation is currently limited to x86_64 -if (Triple.getArch() != llvm::Triple::x86_64) { +// DSO instrumentation is currently limited to x86_64 and aarch64 MaskRay wrote: you can say "Certain targets support ..." so that this comment doesn't need to be updated again. https://github.com/llvm/llvm-project/pull/114431 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [XRay][AArch64] Support -fxray-shared (PR #114431)
@@ -67,8 +67,12 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) { false)) { XRayShared = true; -// DSO instrumentation is currently limited to x86_64 -if (Triple.getArch() != llvm::Triple::x86_64) { +// DSO instrumentation is currently limited to x86_64 and aarch64 +switch (Triple.getArch()) { +case llvm::Triple::x86_64: MaskRay wrote: place aarch64 before x86_64 https://github.com/llvm/llvm-project/pull/114431 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [XRay][AArch64] Support -fxray-shared (PR #114431)
https://github.com/MaskRay approved this pull request. https://github.com/llvm/llvm-project/pull/114431 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114661)
https://github.com/chomosuke updated https://github.com/llvm/llvm-project/pull/114661 >From 311c752356617d768f0bdc8599e765ae42272329 Mon Sep 17 00:00:00 2001 From: chomosuke Date: Sat, 2 Nov 2024 09:18:38 + Subject: [PATCH] Add quick fix to automatically adds NOLINTNEXTLINE comment above clang-tidy warnings --- clang-tools-extra/clangd/CMakeLists.txt | 1 + clang-tools-extra/clangd/ClangdServer.cpp | 3 +- clang-tools-extra/clangd/Diagnostics.cpp | 23 +++- clang-tools-extra/clangd/Diagnostics.h| 12 +- clang-tools-extra/clangd/NoLintFixes.cpp | 99 +++ clang-tools-extra/clangd/NoLintFixes.h| 36 ++ clang-tools-extra/clangd/ParsedAST.cpp| 19 ++- .../fixits-codeaction-documentchanges.test| 47 .../clangd/test/fixits-codeaction.test| 41 +++ .../test/fixits-command-documentchanges.test | 62 ++ .../clangd/test/fixits-command.test | 50 .../clangd/unittests/ClangdLSPServerTests.cpp | 18 ++- .../clangd/unittests/DiagnosticsTests.cpp | 113 -- 13 files changed, 492 insertions(+), 32 deletions(-) create mode 100644 clang-tools-extra/clangd/NoLintFixes.cpp create mode 100644 clang-tools-extra/clangd/NoLintFixes.h diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt index d797ddce8c44d1..2a6433a5c3effd 100644 --- a/clang-tools-extra/clangd/CMakeLists.txt +++ b/clang-tools-extra/clangd/CMakeLists.txt @@ -98,6 +98,7 @@ add_clang_library(clangDaemon STATIC InlayHints.cpp JSONTransport.cpp ModulesBuilder.cpp + NoLintFixes.cpp PathMapping.cpp Protocol.cpp Quality.cpp diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 9b38be04e7ddd7..7f73b61b12c63f 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -15,6 +15,7 @@ #include "Format.h" #include "HeaderSourceSwitch.h" #include "InlayHints.h" +#include "NoLintFixes.h" #include "ParsedAST.h" #include "Preamble.h" #include "Protocol.h" @@ -661,7 +662,7 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) { bool IsClangTidyRename = Diag->Source == Diag::ClangTidy && Diag->Name == "readability-identifier-naming" && !Fix.Edits.empty(); - if (IsClangTidyRename && Diag->InsideMainFile) { + if (IsClangTidyRename && !isNoLintFixes(Fix) && Diag->InsideMainFile) { ClangdServer::CodeActionResult::Rename R; R.NewName = Fix.Edits.front().newText; R.FixMessage = Fix.Message; diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index a59d1e7ac84096..6948e12995bed1 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -9,6 +9,7 @@ #include "Diagnostics.h" #include "../clang-tidy/ClangTidyDiagnosticConsumer.h" #include "Compiler.h" +#include "NoLintFixes.h" #include "Protocol.h" #include "SourceCode.h" #include "support/Logger.h" @@ -311,8 +312,18 @@ std::string mainMessage(const Diag &D, const ClangdDiagnosticOptions &Opts) { std::string Result; llvm::raw_string_ostream OS(Result); OS << D.Message; - if (Opts.DisplayFixesCount && !D.Fixes.empty()) -OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)"; + + // NOLINT fixes are somewhat not real fixes and to say "(fix available)" when + // the fixes is just to suppress could be misleading. + int RealFixCount = D.Fixes.size(); + for (auto const &Fix : D.Fixes) { +if (isNoLintFixes(Fix)) { + RealFixCount--; +} + } + + if (Opts.DisplayFixesCount && RealFixCount > 0) +OS << " (" << (RealFixCount > 1 ? "fixes" : "fix") << " available)"; // If notes aren't emitted as structured info, add them to the message. if (!Opts.EmitRelatedLocations) for (auto &Note : D.Notes) { @@ -822,8 +833,8 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, LastDiagOriginallyError = OriginallyError; if (!Info.getFixItHints().empty()) AddFix(true /* try to invent a message instead of repeating the diag */); -if (Fixer) { - auto ExtraFixes = Fixer(LastDiag->Severity, Info); +if (MainFixer) { + auto ExtraFixes = MainFixer(*LastDiag, Info); LastDiag->Fixes.insert(LastDiag->Fixes.end(), ExtraFixes.begin(), ExtraFixes.end()); } @@ -841,8 +852,8 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, return; // Give include-fixer a chance to replace a note with a fix. -if (Fixer) { - auto ReplacementFixes = Fixer(LastDiag->Severity, Info); +if (NoteFixer) { + auto ReplacementFixes = NoteFixer(*LastDiag, Info); if (!ReplacementFixes.empty()) { assert(Info.getNumFixItHints() == 0 && "Include-fixer replaced a note with clang fix
[clang] [clang][Driver] Allow -fuse-lld=lld-link when lto is enabled on *windows-msvc targets (PR #113966)
https://github.com/zhaoshiz updated https://github.com/llvm/llvm-project/pull/113966 >From 5259a3b00fe1b841e8548443036a943b169970dc Mon Sep 17 00:00:00 2001 From: Zhaoshi Zheng Date: Mon, 28 Oct 2024 14:35:35 -0700 Subject: [PATCH 1/4] [clang][Driver] Allow -fuse-lld=lld-link when lto is enabled on *windows-msvc targets Follow-up on https://github.com/llvm/llvm-project/pull/109607, we have a use case on WoA where `cmake -G "Unix Makefiles"` generates -fuse-ld=lld-link, which is disallowed by PR#109607. --- clang/lib/Driver/Driver.cpp | 2 +- clang/test/Driver/clang_f_opts.c | 1 + clang/test/Driver/woa-lto.c | 15 +++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 clang/test/Driver/woa-lto.c diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 9878a9dad78d40..c1c581e6c6df7c 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -4035,7 +4035,7 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args, if (C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment() && LTOMode != LTOK_None && !Args.getLastArgValue(options::OPT_fuse_ld_EQ) - .equals_insensitive("lld")) + .starts_with_insensitive("lld")) Diag(clang::diag::err_drv_lto_without_lld); // If -dumpdir is not specified, give a default prefix derived from the link diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c index fd15552715cb35..2cfbe256bc7456 100644 --- a/clang/test/Driver/clang_f_opts.c +++ b/clang/test/Driver/clang_f_opts.c @@ -606,6 +606,7 @@ // RUN: %clang -### -S -fjmc -g --target=x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_JMC %s // RUN: %clang -### -S -fjmc -g -fno-jmc --target=x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC %s // RUN: %clang -### -fjmc -g -flto -fuse-ld=lld --target=x86_64-pc-windows-msvc %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s +// RUN: %clang -### -fjmc -g -flto -fuse-ld=lld-link --target=x86_64-pc-windows-msvc %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s // RUN: %clang -### -fjmc -g -flto --target=x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_JMC_LTO %s // RUN: %clang -### -fjmc -g -flto -fno-jmc --target=x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s // CHECK_JMC_WARN: -fjmc requires debug info. Use -g or debug options that enable debugger's stepping function; option ignored diff --git a/clang/test/Driver/woa-lto.c b/clang/test/Driver/woa-lto.c new file mode 100644 index 00..25c42374c4d449 --- /dev/null +++ b/clang/test/Driver/woa-lto.c @@ -0,0 +1,15 @@ +// REQUIRES: aarch64-registered-target +// +// RUN: echo "int main() {} " > %t.c +// +// RUN: %clang --target=aarch64-pc-windows-msvc -O3 -flto -fuse-ld=lld -c %t.c -o %t.o +// RUN: %clang --target=aarch64-pc-windows-msvc -O3 -flto -fuse-ld=lld -### %t.o 2>&1 | FileCheck %s +// RUN: %clang --target=aarch64-pc-windows-msvc -O3 -flto=thin -fuse-ld=lld -c %t.c -o %t.o +// RUN: %clang --target=aarch64-pc-windows-msvc -O3 -flto=thin -fuse-ld=lld -### %t.o 2>&1 | FileCheck %s +// +// RUN: %clang --target=aarch64-pc-windows-msvc -O3 -flto -fuse-ld=lld-link -c %t.c -o %t.o +// RUN: %clang --target=aarch64-pc-windows-msvc -O3 -flto -fuse-ld=lld-link -### %t.o 2>&1 | FileCheck %s +// RUN: %clang --target=aarch64-pc-windows-msvc -O3 -flto=thin -fuse-ld=lld-link -c %t.c -o %t.o +// RUN: %clang --target=aarch64-pc-windows-msvc -O3 -flto=thin -fuse-ld=lld-link -### %t.o 2>&1 | FileCheck %s +// +// CHECK: "{{.*}}lld-link" "-out:a.exe" "-defaultlib:libcmt" "-defaultlib:oldnames" >From 70454559165840f7c4e261bf5ed24b1c317d5b86 Mon Sep 17 00:00:00 2001 From: Zhaoshi Zheng Date: Mon, 28 Oct 2024 20:38:43 -0700 Subject: [PATCH 2/4] Update test case to allow possible '.exe' extension --- clang/test/Driver/woa-lto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Driver/woa-lto.c b/clang/test/Driver/woa-lto.c index 25c42374c4d449..7f4ecefd6b4b37 100644 --- a/clang/test/Driver/woa-lto.c +++ b/clang/test/Driver/woa-lto.c @@ -12,4 +12,4 @@ // RUN: %clang --target=aarch64-pc-windows-msvc -O3 -flto=thin -fuse-ld=lld-link -c %t.c -o %t.o // RUN: %clang --target=aarch64-pc-windows-msvc -O3 -flto=thin -fuse-ld=lld-link -### %t.o 2>&1 | FileCheck %s // -// CHECK: "{{.*}}lld-link" "-out:a.exe" "-defaultlib:libcmt" "-defaultlib:oldnames" +// CHECK: "{{.*}}lld-link{{(.exe)?}}" "-out:a.exe" "-defaultlib:libcmt" "-defaultlib:oldnames" >From 123300855169329c9d14d80374500065a39530b8 Mon Sep 17 00:00:00 2001 From: Zhaoshi Zheng Date: Thu, 31 Oct 2024 09:49:30 -0700 Subject: [PATCH 3/4] Update test case to conform with naming and RUN conventions --- clang/test/Driver/windows-lto.c | 9 + clang/test/Driver/woa-lto.c | 15 --- 2 files changed, 9 insertions(+), 15 deletions(-) create mode 100644 clang
[clang] [clang] Diagnose for implicit boolean conversions in assignments (PR #114687)
https://github.com/PhilippRados created https://github.com/llvm/llvm-project/pull/114687 This is an unfinished implementation of #33528. I have a couple of questions since I'm new to the codebase: This warning should be issued for both C and C++. For C++ it is pretty straightforward since I can check this when calling `PerformImplicitConversion`. However this function isn't called in C and right now I issue the warning for C in `Sema::ImpCastExprToType`, but I don't know if this function also might be called in C++ resulting in the same warning issued twice. Ideally I would just have to issue this once for both languages but I can't seem to find the correct `ImplicitCast` function that gets invoked for both langs. I also found another already existing warning when running the tests (warn_condition_is_assignment) that is similar to this warning but only gets issued on assignments in conditional-expressions, as opposed to all assignment expressions. In C++ this results in the new and old warning both being displayed even though they both suggest the same thing. How should this be handled? Should I manually check if the broader warning has already been issued and then remove it or maybe just keep the more general warning as they mean the same thing (-Wparentheses)? Any feedback is appreciated! >From b8244b346c7a97c2eb35ccfea23675b8df4f046e Mon Sep 17 00:00:00 2001 From: PhilippR Date: Sat, 2 Nov 2024 18:51:26 +0100 Subject: [PATCH] [clang] adding diagnose for impl-cast (draft) This is an unfinished implementation of #33528 --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ clang/include/clang/Sema/Sema.h | 2 ++ clang/lib/Sema/Sema.cpp | 14 ++ clang/lib/Sema/SemaExprCXX.cpp | 3 +++ 4 files changed, 21 insertions(+) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index d697e6d61afa9a..51879c359b3060 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8477,6 +8477,8 @@ def err_incomplete_object_call : Error< def warn_condition_is_assignment : Warning<"using the result of an " "assignment as a condition without parentheses">, InGroup; +def warn_parens_bool_assign : Warning<"suggest parentheses around assignment used as truth value">, +InGroup; def warn_free_nonheap_object : Warning<"attempt to call %0 on non-heap %select{object %2|object: block expression|object: lambda-to-function-pointer conversion}1">, InGroup; diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 93d98e1cbb9c81..30767b11998bb7 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -7232,6 +7232,8 @@ class Sema final : public SemaBase { /// being used as a boolean condition, warn if it's an assignment. void DiagnoseAssignmentAsCondition(Expr *E); + void DiagnoseImplicitCastBoolAssignment(Expr *E, QualType ToType); + /// Redundant parentheses over an equality comparison can indicate /// that the user intended an assignment used as condition. void DiagnoseEqualityWithExtraParens(ParenExpr *ParenE); diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index 2b51765e80864a..cc9cb173c01480 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -687,6 +687,18 @@ void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E) { << FixItHint::CreateReplacement(E->getSourceRange(), "nullptr"); } +void Sema::DiagnoseImplicitCastBoolAssignment(Expr* E,QualType Ty) { + if (Ty->isBooleanType()) { +if (BinaryOperator* Op = dyn_cast(E)) { + // should only be issued for regular assignment `=`, not for e.g `+=` + if (Op->getOpcode() == BO_Assign) { +SourceLocation Loc = Op->getOperatorLoc(); +Diag(Loc,diag::warn_parens_bool_assign) << E->getSourceRange(); + } +} + } +} + /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast. /// If there is already an implicit cast, merge into the existing one. /// The result is of the given category. @@ -761,6 +773,8 @@ ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty, } } + DiagnoseImplicitCastBoolAssignment(E,Ty); + if (ImplicitCastExpr *ImpCast = dyn_cast(E)) { if (ImpCast->getCastKind() == Kind && (!BasePath || BasePath->empty())) { ImpCast->setType(Ty); diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 50c1b24fce6da7..14ca6a743049e4 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -18,6 +18,7 @@ #include "clang/AST/CXXInheritance.h" #include "clang/AST/CharUnits.h" #include "clang/AST/DeclObjC.h" +#include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/ExprConcepts.h" #include "clang/AST/ExprObjC.h" @@ -4392,6 +4393,8 @@ Sema::PerformImp
[clang] [clang] Diagnose for implicit boolean conversions in assignments (PR #114687)
https://github.com/PhilippRados edited https://github.com/llvm/llvm-project/pull/114687 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits