Skip to content

Commit dbde9c1

Browse files
committed
Merge from 'main' to 'sycl-web' (#5)
Also removed the workaround for D99173, and updated vc-intrinsics to use a version with the fix it. CONFLICT (content): Merge conflict in clang/lib/CodeGen/CodeGenFunction.cpp
2 parents 8e0c4b0 + 193e41c commit dbde9c1

File tree

1,192 files changed

+37166
-10810
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,192 files changed

+37166
-10810
lines changed

clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "../utils/LexerUtils.h"
1313
#include "../utils/Matchers.h"
1414
#include "../utils/OptionsUtils.h"
15+
#include "clang/AST/Decl.h"
1516
#include "clang/Basic/Diagnostic.h"
1617

1718
namespace clang {
@@ -72,14 +73,14 @@ AST_MATCHER_FUNCTION(StatementMatcher, isConstRefReturningFunctionCall) {
7273
.bind(InitFunctionCallId);
7374
}
7475

75-
AST_MATCHER_FUNCTION(StatementMatcher, isInitializedFromReferenceToConst) {
76+
AST_MATCHER_FUNCTION(StatementMatcher, initializerReturnsReferenceToConst) {
7677
auto OldVarDeclRef =
7778
declRefExpr(to(varDecl(hasLocalStorage()).bind(OldVarDeclId)));
78-
return declStmt(has(varDecl(hasInitializer(
79+
return expr(
7980
anyOf(isConstRefReturningFunctionCall(), isConstRefReturningMethodCall(),
8081
ignoringImpCasts(OldVarDeclRef),
81-
ignoringImpCasts(unaryOperator(
82-
hasOperatorName("&"), hasUnaryOperand(OldVarDeclRef))))))));
82+
ignoringImpCasts(unaryOperator(hasOperatorName("&"),
83+
hasUnaryOperand(OldVarDeclRef)))));
8384
}
8485

8586
// This checks that the variable itself is only used as const, and also makes
@@ -106,18 +107,14 @@ static bool isInitializingVariableImmutable(const VarDecl &InitializingVar,
106107
if (!isa<ReferenceType, PointerType>(T))
107108
return true;
108109

109-
auto Matches =
110-
match(findAll(declStmt(has(varDecl(equalsNode(&InitializingVar))))
111-
.bind("declStmt")),
112-
BlockStmt, Context);
113-
// The reference or pointer is not initialized in the BlockStmt. We assume
114-
// its pointee is not modified then.
115-
if (Matches.empty())
110+
// The reference or pointer is not declared and hence not initialized anywhere
111+
// in the function. We assume its pointee is not modified then.
112+
if (!InitializingVar.isLocalVarDecl() || !InitializingVar.hasInit()) {
116113
return true;
114+
}
117115

118-
const auto *Initialization = selectFirst<DeclStmt>("declStmt", Matches);
119-
Matches =
120-
match(isInitializedFromReferenceToConst(), *Initialization, Context);
116+
auto Matches = match(initializerReturnsReferenceToConst(),
117+
*InitializingVar.getInit(), Context);
121118
// The reference is initialized from a free function without arguments
122119
// returning a const reference. This is a global immutable object.
123120
if (selectFirst<CallExpr>(InitFunctionCallId, Matches) != nullptr)

clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_INITIALIZATION_H
1111

1212
#include "../ClangTidyCheck.h"
13+
#include "clang/AST/Decl.h"
1314

1415
namespace clang {
1516
namespace tidy {

clang-tools-extra/clangd/CompileCommands.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "llvm/Support/MemoryBuffer.h"
2121
#include "llvm/Support/Path.h"
2222
#include "llvm/Support/Program.h"
23+
#include <string>
24+
#include <vector>
2325

2426
namespace clang {
2527
namespace clangd {
@@ -209,14 +211,20 @@ void CommandMangler::adjust(std::vector<std::string> &Cmd) const {
209211
Cmd = tooling::getStripPluginsAdjuster()(Cmd, "");
210212
Cmd = tooling::getClangSyntaxOnlyAdjuster()(Cmd, "");
211213

214+
std::vector<std::string> ToAppend;
212215
if (ResourceDir && !Has("-resource-dir"))
213-
Cmd.push_back(("-resource-dir=" + *ResourceDir));
216+
ToAppend.push_back(("-resource-dir=" + *ResourceDir));
214217

215218
// Don't set `-isysroot` if it is already set or if `--sysroot` is set.
216219
// `--sysroot` is a superset of the `-isysroot` argument.
217220
if (Sysroot && !Has("-isysroot") && !Has("--sysroot")) {
218-
Cmd.push_back("-isysroot");
219-
Cmd.push_back(*Sysroot);
221+
ToAppend.push_back("-isysroot");
222+
ToAppend.push_back(*Sysroot);
223+
}
224+
225+
if (!ToAppend.empty()) {
226+
Cmd = tooling::getInsertArgumentAdjuster(
227+
std::move(ToAppend), tooling::ArgumentInsertPosition::END)(Cmd, "");
220228
}
221229

222230
if (!Cmd.empty()) {
@@ -504,7 +512,6 @@ void ArgStripper::process(std::vector<std::string> &Args) const {
504512
Args.resize(Write);
505513
}
506514

507-
508515
std::string printArgv(llvm::ArrayRef<llvm::StringRef> Args) {
509516
std::string Buf;
510517
llvm::raw_string_ostream OS(Buf);

clang-tools-extra/clangd/ConfigCompile.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "llvm/Support/Regex.h"
4848
#include "llvm/Support/SMLoc.h"
4949
#include "llvm/Support/SourceMgr.h"
50+
#include <algorithm>
5051
#include <string>
5152

5253
namespace clang {
@@ -270,7 +271,9 @@ struct FragmentCompiler {
270271
Add.push_back(std::move(*A));
271272
Out.Apply.push_back([Add(std::move(Add))](const Params &, Config &C) {
272273
C.CompileFlags.Edits.push_back([Add](std::vector<std::string> &Args) {
273-
Args.insert(Args.end(), Add.begin(), Add.end());
274+
// The point to insert at. Just append when `--` isn't present.
275+
auto It = llvm::find(Args, "--");
276+
Args.insert(It, Add.begin(), Add.end());
274277
});
275278
});
276279
}

clang-tools-extra/clangd/Diagnostics.cpp

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ bool mentionsMainFile(const Diag &D) {
7676
return false;
7777
}
7878

79-
bool isExcluded(const Diag &D) {
79+
bool isExcluded(unsigned DiagID) {
8080
// clang will always fail parsing MS ASM, we don't link in desc + asm parser.
81-
if (D.ID == clang::diag::err_msasm_unable_to_create_target ||
82-
D.ID == clang::diag::err_msasm_unsupported_arch)
81+
if (DiagID == clang::diag::err_msasm_unable_to_create_target ||
82+
DiagID == clang::diag::err_msasm_unsupported_arch)
8383
return true;
8484
return false;
8585
}
@@ -726,44 +726,42 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
726726
// Handle the new main diagnostic.
727727
flushLastDiag();
728728

729-
if (Adjuster) {
729+
LastDiag = Diag();
730+
// FIXME: Merge with feature modules.
731+
if (Adjuster)
730732
DiagLevel = Adjuster(DiagLevel, Info);
731-
if (DiagLevel == DiagnosticsEngine::Ignored) {
732-
LastPrimaryDiagnosticWasSuppressed = true;
733-
return;
734-
}
735-
}
736-
LastPrimaryDiagnosticWasSuppressed = false;
737733

738-
LastDiag = Diag();
739734
FillDiagBase(*LastDiag);
735+
if (isExcluded(LastDiag->ID))
736+
LastDiag->Severity = DiagnosticsEngine::Ignored;
737+
if (DiagCB)
738+
DiagCB(Info, *LastDiag);
739+
// Don't bother filling in the rest if diag is going to be dropped.
740+
if (LastDiag->Severity == DiagnosticsEngine::Ignored)
741+
return;
742+
740743
LastDiagLoc.emplace(Info.getLocation(), Info.getSourceManager());
741744
LastDiagOriginallyError = OriginallyError;
742-
743745
if (!Info.getFixItHints().empty())
744746
AddFix(true /* try to invent a message instead of repeating the diag */);
745747
if (Fixer) {
746-
auto ExtraFixes = Fixer(DiagLevel, Info);
748+
auto ExtraFixes = Fixer(LastDiag->Severity, Info);
747749
LastDiag->Fixes.insert(LastDiag->Fixes.end(), ExtraFixes.begin(),
748750
ExtraFixes.end());
749751
}
750-
if (DiagCB)
751-
DiagCB(Info, *LastDiag);
752752
} else {
753753
// Handle a note to an existing diagnostic.
754-
755-
// If a diagnostic was suppressed due to the suppression filter,
756-
// also suppress notes associated with it.
757-
if (LastPrimaryDiagnosticWasSuppressed) {
758-
return;
759-
}
760-
761754
if (!LastDiag) {
762755
assert(false && "Adding a note without main diagnostic");
763756
IgnoreDiagnostics::log(DiagLevel, Info);
764757
return;
765758
}
766759

760+
// If a diagnostic was suppressed due to the suppression filter,
761+
// also suppress notes associated with it.
762+
if (LastDiag->Severity == DiagnosticsEngine::Ignored)
763+
return;
764+
767765
if (!Info.getFixItHints().empty()) {
768766
// A clang note with fix-it is not a separate diagnostic in clangd. We
769767
// attach it as a Fix to the main diagnostic instead.
@@ -788,7 +786,7 @@ void StoreDiags::flushLastDiag() {
788786
LastDiag.reset();
789787
});
790788

791-
if (isExcluded(*LastDiag))
789+
if (LastDiag->Severity == DiagnosticsEngine::Ignored)
792790
return;
793791
// Move errors that occur from headers into main file.
794792
if (!LastDiag->InsideMainFile && LastDiagLoc && LastDiagOriginallyError) {

clang-tools-extra/clangd/Diagnostics.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ class StoreDiags : public DiagnosticConsumer {
171171
SourceManager *OrigSrcMgr = nullptr;
172172

173173
llvm::DenseSet<std::pair<unsigned, unsigned>> IncludedErrorLocations;
174-
bool LastPrimaryDiagnosticWasSuppressed = false;
175174
};
176175

177176
/// Determine whether a (non-clang-tidy) diagnostic is suppressed by config.

clang-tools-extra/clangd/tool/ClangdMain.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,11 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
909909

910910
if (CheckFile.getNumOccurrences()) {
911911
llvm::SmallString<256> Path;
912-
llvm::sys::fs::real_path(CheckFile, Path, /*expand_tilde=*/true);
912+
if (auto Error =
913+
llvm::sys::fs::real_path(CheckFile, Path, /*expand_tilde=*/true)) {
914+
elog("Failed to resolve path {0}: {1}", CheckFile, Error.message());
915+
return 1;
916+
}
913917
log("Entering check mode (no LSP server)");
914918
uint32_t Begin = 0, End = std::numeric_limits<uint32_t>::max();
915919
if (!CheckFileLines.empty()) {

clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ TEST(CommandMangler, Everything) {
4141
Mangler.ClangPath = testPath("fake/clang");
4242
Mangler.ResourceDir = testPath("fake/resources");
4343
Mangler.Sysroot = testPath("fake/sysroot");
44-
std::vector<std::string> Cmd = {"clang++", "-Xclang", "-load", "-Xclang",
45-
"plugin", "-MF", "dep", "foo.cc"};
44+
std::vector<std::string> Cmd = {"clang++", "-Xclang", "-load",
45+
"-Xclang", "plugin", "-MF",
46+
"dep", "--", "foo.cc"};
4647
Mangler.adjust(Cmd);
47-
EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"), "foo.cc",
48-
"-fsyntax-only",
48+
EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"), "-fsyntax-only",
4949
"-resource-dir=" + testPath("fake/resources"),
50-
"-isysroot", testPath("fake/sysroot")));
50+
"-isysroot", testPath("fake/sysroot"), "--",
51+
"foo.cc"));
5152
}
5253

5354
TEST(CommandMangler, ResourceDir) {
@@ -378,4 +379,3 @@ TEST(PrintArgvTest, All) {
378379
} // namespace
379380
} // namespace clangd
380381
} // namespace clang
381-

clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ TEST_F(ConfigCompileTests, Condition) {
123123
TEST_F(ConfigCompileTests, CompileCommands) {
124124
Frag.CompileFlags.Add.emplace_back("-foo");
125125
Frag.CompileFlags.Remove.emplace_back("--include-directory=");
126-
std::vector<std::string> Argv = {"clang", "-I", "bar/", "a.cc"};
126+
std::vector<std::string> Argv = {"clang", "-I", "bar/", "--", "a.cc"};
127127
EXPECT_TRUE(compileAndApply());
128128
EXPECT_THAT(Conf.CompileFlags.Edits, SizeIs(2));
129129
for (auto &Edit : Conf.CompileFlags.Edits)
130130
Edit(Argv);
131-
EXPECT_THAT(Argv, ElementsAre("clang", "a.cc", "-foo"));
131+
EXPECT_THAT(Argv, ElementsAre("clang", "-foo", "--", "a.cc"));
132132
}
133133

134134
TEST_F(ConfigCompileTests, CompilationDatabase) {

clang-tools-extra/clangd/unittests/FeatureModulesTests.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "Annotations.h"
910
#include "FeatureModule.h"
1011
#include "Selection.h"
1112
#include "TestTU.h"
@@ -53,6 +54,37 @@ TEST(FeatureModulesTest, ContributesTweak) {
5354
EXPECT_EQ(Actual->get()->id(), TweakID);
5455
}
5556

57+
TEST(FeatureModulesTest, SuppressDiags) {
58+
struct DiagModifierModule final : public FeatureModule {
59+
struct Listener : public FeatureModule::ASTListener {
60+
void sawDiagnostic(const clang::Diagnostic &Info,
61+
clangd::Diag &Diag) override {
62+
Diag.Severity = DiagnosticsEngine::Ignored;
63+
}
64+
};
65+
std::unique_ptr<ASTListener> astListeners() override {
66+
return std::make_unique<Listener>();
67+
};
68+
};
69+
FeatureModuleSet FMS;
70+
FMS.add(std::make_unique<DiagModifierModule>());
71+
72+
Annotations Code("[[test]]; /* error-ok */");
73+
TestTU TU;
74+
TU.Code = Code.code().str();
75+
76+
{
77+
auto AST = TU.build();
78+
EXPECT_THAT(*AST.getDiagnostics(), testing::Not(testing::IsEmpty()));
79+
}
80+
81+
TU.FeatureModules = &FMS;
82+
{
83+
auto AST = TU.build();
84+
EXPECT_THAT(*AST.getDiagnostics(), testing::IsEmpty());
85+
}
86+
}
87+
5688
} // namespace
5789
} // namespace clangd
5890
} // namespace clang

clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
// RUN: %check_clang_tidy %s performance-unnecessary-copy-initialization %t
22

3+
template <typename T>
4+
struct Iterator {
5+
void operator++();
6+
const T &operator*() const;
7+
bool operator!=(const Iterator &) const;
8+
typedef const T &const_reference;
9+
};
10+
311
struct ExpensiveToCopyType {
412
ExpensiveToCopyType();
513
virtual ~ExpensiveToCopyType();
614
const ExpensiveToCopyType &reference() const;
715
const ExpensiveToCopyType *pointer() const;
16+
Iterator<ExpensiveToCopyType> begin() const;
17+
Iterator<ExpensiveToCopyType> end() const;
818
void nonConstMethod();
919
bool constMethod() const;
1020
};
@@ -589,3 +599,41 @@ void positiveUnusedReferenceIsRemoved() {
589599
// CHECK-FIXES-NOT: auto TrailingCommentRemoved = ExpensiveTypeReference(); // Trailing comment.
590600
// clang-format on
591601
}
602+
603+
void negativeloopedOverObjectIsModified() {
604+
ExpensiveToCopyType Orig;
605+
for (const auto &Element : Orig) {
606+
const auto Copy = Element;
607+
Orig.nonConstMethod();
608+
Copy.constMethod();
609+
}
610+
611+
auto Lambda = []() {
612+
ExpensiveToCopyType Orig;
613+
for (const auto &Element : Orig) {
614+
const auto Copy = Element;
615+
Orig.nonConstMethod();
616+
Copy.constMethod();
617+
}
618+
};
619+
}
620+
621+
void negativeReferenceIsInitializedOutsideOfBlock() {
622+
ExpensiveToCopyType Orig;
623+
const auto &E2 = Orig;
624+
if (1 != 2 * 3) {
625+
const auto C2 = E2;
626+
Orig.nonConstMethod();
627+
C2.constMethod();
628+
}
629+
630+
auto Lambda = []() {
631+
ExpensiveToCopyType Orig;
632+
const auto &E2 = Orig;
633+
if (1 != 2 * 3) {
634+
const auto C2 = E2;
635+
Orig.nonConstMethod();
636+
C2.constMethod();
637+
}
638+
};
639+
}

0 commit comments

Comments
 (0)