Skip to content

Commit a9e7fa0

Browse files
committed
Merge remote-tracking branch 'origin/main' into laa-nonconst-dist-forward
2 parents 0a1509f + 0accda7 commit a9e7fa0

File tree

1,319 files changed

+64980
-21814
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,319 files changed

+64980
-21814
lines changed

.ci/generate-buildkite-pipeline-premerge

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function add-dependencies() {
108108
compiler-rt|libc|openmp)
109109
echo clang lld
110110
;;
111-
flang|lldb)
111+
flang|lldb|libclc)
112112
for p in llvm clang; do
113113
echo $p
114114
done

.github/CODEOWNERS

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,15 @@ clang/test/AST/Interp/ @tbaederr
113113

114114
# MLIR NVVM Dialect in MLIR
115115
/mlir/**/LLVMIR/**/BasicPtxBuilderInterface* @grypp
116-
/mlir/**/NVVM*/ @grypp
116+
/mlir/**/NVVM* @grypp
117117

118118
# MLIR Python Bindings
119-
/mlir/test/python/ @makslevental @stellaraccident
120-
/mlir/python/ @makslevental @stellaraccident
119+
/mlir/test/python/ @ftynse @makslevental @stellaraccident
120+
/mlir/python/ @ftynse @makslevental @stellaraccident
121+
122+
# MLIR Mem2Reg/SROA
123+
/mlir/**/Transforms/Mem2Reg.* @moxinilian
124+
/mlir/**/Transforms/SROA.* @moxinilian
121125

122126
# BOLT
123127
/bolt/ @aaupov @maksfb @rafaelauler @ayermolo @dcci

.github/new-prs-labeler.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
ClangIR:
2+
- clang/include/clang/CIR/**/*
3+
- clang/lib/CIR/**/*
4+
- clang/tools/cir-*/**/*
5+
- clang/test/CIR/**/*
6+
17
clang:dataflow:
28
- clang/include/clang/Analysis/FlowSensitive/**/*
39
- clang/lib/Analysis/FlowSensitive/**/*
@@ -938,3 +944,6 @@ openmp:libomptarget:
938944

939945
bazel:
940946
- utils/bazel/**
947+
948+
offload:
949+
- offload/**

bolt/test/AArch64/constant_island_pie_update.s

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# RUN: llvm-objdump -j .text -d --show-all-symbols %t.relr.bolt | FileCheck %s
1919
# RUN: llvm-objdump -j .text -d %t.relr.bolt | \
2020
# RUN: FileCheck %s --check-prefix=ADDENDCHECK
21-
# RUN: llvm-readelf -rsW %t.relr.bolt | FileCheck --check-prefix=ELFCHECK %s
21+
# RUN: llvm-readelf -rsW %t.relr.bolt | FileCheck --check-prefix=RELRELFCHECK %s
2222
# RUN: llvm-readelf -SW %t.relr.bolt | FileCheck --check-prefix=RELRSZCHECK %s
2323

2424
// Check that the CI value was updated
@@ -51,6 +51,12 @@
5151
# ELFCHECK-NEXT: {{.*}} R_AARCH64_RELATIVE
5252
# ELFCHECK: {{.*}}[[#OFF]] {{.*}} $d
5353

54+
# RELRELFCHECK: $d{{$}}
55+
# RELRELFCHECK-NEXT: $d + 0x8{{$}}
56+
# RELRELFCHECK-NEXT: $d + 0x18{{$}}
57+
# RELRELFCHECK-NEXT: mytextP
58+
# RELRELFCHECK-EMPTY:
59+
5460
// Check that .relr.dyn size is 2 bytes to ensure that last 3 relocations were
5561
// encoded as a bitmap so the total section size for 3 relocations is 2 bytes.
5662
# RELRSZCHECK: .relr.dyn RELR [[#%x,ADDR:]] [[#%x,OFF:]] {{0*}}10

clang-tools-extra/clang-doc/Representation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ ClangDocContext::ClangDocContext(tooling::ExecutionContext *ECtx,
380380
this->SourceRoot = std::string(SourceRootDir);
381381
if (!RepositoryUrl.empty()) {
382382
this->RepositoryUrl = std::string(RepositoryUrl);
383-
if (!RepositoryUrl.empty() && RepositoryUrl.find("http://") != 0 &&
384-
RepositoryUrl.find("https://") != 0)
383+
if (!RepositoryUrl.empty() && !RepositoryUrl.starts_with("http://") &&
384+
!RepositoryUrl.starts_with("https://"))
385385
this->RepositoryUrl->insert(0, "https://");
386386
}
387387
}

clang-tools-extra/clang-tidy/add_new_check.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def adapt_module(module_path, module, check_name, check_name_camel):
211211
f.write(check_decl)
212212
else:
213213
match = re.search(
214-
'registerCheck<(.*)> *\( *(?:"([^"]*)")?', line
214+
r'registerCheck<(.*)> *\( *(?:"([^"]*)")?', line
215215
)
216216
prev_line = None
217217
if match:
@@ -383,7 +383,7 @@ def filename_from_module(module_name, check_name):
383383
if stmt_start_pos == -1:
384384
return ""
385385
stmt = code[stmt_start_pos + 1 : stmt_end_pos]
386-
matches = re.search('registerCheck<([^>:]*)>\(\s*"([^"]*)"\s*\)', stmt)
386+
matches = re.search(r'registerCheck<([^>:]*)>\(\s*"([^"]*)"\s*\)', stmt)
387387
if matches and matches[2] == full_check_name:
388388
class_name = matches[1]
389389
if "::" in class_name:
@@ -401,8 +401,8 @@ def filename_from_module(module_name, check_name):
401401
# Examine code looking for a c'tor definition to get the base class name.
402402
def get_base_class(code, check_file):
403403
check_class_name = os.path.splitext(os.path.basename(check_file))[0]
404-
ctor_pattern = check_class_name + "\([^:]*\)\s*:\s*([A-Z][A-Za-z0-9]*Check)\("
405-
matches = re.search("\s+" + check_class_name + "::" + ctor_pattern, code)
404+
ctor_pattern = check_class_name + r"\([^:]*\)\s*:\s*([A-Z][A-Za-z0-9]*Check)\("
405+
matches = re.search(r"\s+" + check_class_name + "::" + ctor_pattern, code)
406406

407407
# The constructor might be inline in the header.
408408
if not matches:
@@ -476,7 +476,7 @@ def process_doc(doc_file):
476476
# Orphan page, don't list it.
477477
return "", ""
478478

479-
match = re.search(".*:http-equiv=refresh: \d+;URL=(.*).html(.*)", content)
479+
match = re.search(r".*:http-equiv=refresh: \d+;URL=(.*).html(.*)", content)
480480
# Is it a redirect?
481481
return check_name, match
482482

@@ -505,7 +505,7 @@ def format_link_alias(doc_file):
505505
ref_begin = ""
506506
ref_end = "_"
507507
else:
508-
redirect_parts = re.search("^\.\./([^/]*)/([^/]*)$", match.group(1))
508+
redirect_parts = re.search(r"^\.\./([^/]*)/([^/]*)$", match.group(1))
509509
title = redirect_parts[1] + "-" + redirect_parts[2]
510510
target = redirect_parts[1] + "/" + redirect_parts[2]
511511
autofix = has_auto_fix(title)

clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void ForwardingReferenceOverloadCheck::registerMatchers(MatchFinder *Finder) {
7272

7373
DeclarationMatcher FindOverload =
7474
cxxConstructorDecl(
75-
hasParameter(0, ForwardingRefParm),
75+
hasParameter(0, ForwardingRefParm), unless(isDeleted()),
7676
unless(hasAnyParameter(
7777
// No warning: enable_if as constructor parameter.
7878
parmVarDecl(hasType(isEnableIf())))),

clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
#include "LambdaFunctionNameCheck.h"
1010
#include "clang/AST/ASTContext.h"
11+
#include "clang/AST/DeclCXX.h"
1112
#include "clang/ASTMatchers/ASTMatchFinder.h"
13+
#include "clang/ASTMatchers/ASTMatchers.h"
1214
#include "clang/Frontend/CompilerInstance.h"
1315
#include "clang/Lex/MacroInfo.h"
1416
#include "clang/Lex/Preprocessor.h"
@@ -56,6 +58,8 @@ class MacroExpansionsWithFileAndLine : public PPCallbacks {
5658
LambdaFunctionNameCheck::SourceRangeSet* SuppressMacroExpansions;
5759
};
5860

61+
AST_MATCHER(CXXMethodDecl, isInLambda) { return Node.getParent()->isLambda(); }
62+
5963
} // namespace
6064

6165
LambdaFunctionNameCheck::LambdaFunctionNameCheck(StringRef Name,
@@ -69,9 +73,13 @@ void LambdaFunctionNameCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
6973
}
7074

7175
void LambdaFunctionNameCheck::registerMatchers(MatchFinder *Finder) {
72-
// Match on PredefinedExprs inside a lambda.
73-
Finder->addMatcher(predefinedExpr(hasAncestor(lambdaExpr())).bind("E"),
74-
this);
76+
Finder->addMatcher(
77+
cxxMethodDecl(isInLambda(),
78+
hasBody(forEachDescendant(
79+
predefinedExpr(hasAncestor(cxxMethodDecl().bind("fn")))
80+
.bind("E"))),
81+
equalsBoundNode("fn")),
82+
this);
7583
}
7684

7785
void LambdaFunctionNameCheck::registerPPCallbacks(

clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
444444
if (!F->hasInClassInitializer() &&
445445
utils::type_traits::isTriviallyDefaultConstructible(F->getType(),
446446
Context) &&
447-
!isEmpty(Context, F->getType()) && !F->isUnnamedBitfield() &&
447+
!isEmpty(Context, F->getType()) && !F->isUnnamedBitField() &&
448448
!AnyMemberHasInitPerUnion)
449449
FieldsToInit.insert(F);
450450
});

clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ getAllNamedFields(const CXXRecordDecl *Record) {
2626
std::set<const FieldDecl *> Result;
2727
for (const auto *Field : Record->fields()) {
2828
// Static data members are not in this range.
29-
if (Field->isUnnamedBitfield())
29+
if (Field->isUnnamedBitField())
3030
continue;
3131
Result.insert(Field);
3232
}

clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ ExceptionSpecAnalyzer::analyzeRecord(const CXXRecordDecl *RecordDecl,
9999
}
100100

101101
for (const auto *FDecl : RecordDecl->fields())
102-
if (!FDecl->isInvalidDecl() && !FDecl->isUnnamedBitfield()) {
102+
if (!FDecl->isInvalidDecl() && !FDecl->isUnnamedBitField()) {
103103
State Result = analyzeFieldDecl(FDecl, Kind);
104104
if (Result == State::Throwing || Result == State::Unknown)
105105
return Result;

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "refactor/Rename.h"
3131
#include "refactor/Tweak.h"
3232
#include "support/Cancellation.h"
33+
#include "support/Context.h"
3334
#include "support/Logger.h"
3435
#include "support/MemoryTree.h"
3536
#include "support/ThreadsafeFS.h"
@@ -112,7 +113,12 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
112113
// Index outlives TUScheduler (declared first)
113114
FIndex(FIndex),
114115
// shared_ptr extends lifetime
115-
Stdlib(Stdlib)]() mutable {
116+
Stdlib(Stdlib),
117+
// We have some FS implementations that rely on information in
118+
// the context.
119+
Ctx(Context::current().clone())]() mutable {
120+
// Make sure we install the context into current thread.
121+
WithContext C(std::move(Ctx));
116122
clang::noteBottomOfStack();
117123
IndexFileIn IF;
118124
IF.Symbols = indexStandardLibrary(std::move(CI), Loc, *TFS);

clang-tools-extra/clangd/Preamble.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
700700
Result->Marks = CapturedInfo.takeMarks();
701701
Result->StatCache = StatCache;
702702
Result->MainIsIncludeGuarded = CapturedInfo.isMainFileIncludeGuarded();
703+
Result->TargetOpts = CI.TargetOpts;
703704
if (PreambleCallback) {
704705
trace::Span Tracer("Running PreambleCallback");
705706
auto Ctx = CapturedInfo.takeLife();
@@ -913,6 +914,12 @@ PreamblePatch PreamblePatch::createMacroPatch(llvm::StringRef FileName,
913914
}
914915

915916
void PreamblePatch::apply(CompilerInvocation &CI) const {
917+
// Make sure the compilation uses same target opts as the preamble. Clang has
918+
// no guarantees around using arbitrary options when reusing PCHs, and
919+
// different target opts can result in crashes, see
920+
// ParsedASTTest.PreambleWithDifferentTarget.
921+
CI.TargetOpts = Baseline->TargetOpts;
922+
916923
// No need to map an empty file.
917924
if (PatchContents.empty())
918925
return;

clang-tools-extra/clangd/Preamble.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "clang-include-cleaner/Record.h"
3131
#include "support/Path.h"
3232
#include "clang/Basic/SourceManager.h"
33+
#include "clang/Basic/TargetOptions.h"
3334
#include "clang/Frontend/CompilerInvocation.h"
3435
#include "clang/Frontend/PrecompiledPreamble.h"
3536
#include "clang/Lex/Lexer.h"
@@ -97,6 +98,10 @@ struct PreambleData {
9798
// Version of the ParseInputs this preamble was built from.
9899
std::string Version;
99100
tooling::CompileCommand CompileCommand;
101+
// Target options used when building the preamble. Changes in target can cause
102+
// crashes when deserializing preamble, this enables consumers to use the
103+
// same target (without reparsing CompileCommand).
104+
std::shared_ptr<TargetOptions> TargetOpts = nullptr;
100105
PrecompiledPreamble Preamble;
101106
std::vector<Diag> Diags;
102107
// Processes like code completions and go-to-definitions will need #include

clang-tools-extra/clangd/unittests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ set(LLVM_LINK_COMPONENTS
22
support
33
AllTargetsInfos
44
FrontendOpenMP
5+
TargetParser
56
)
67

78
if(CLANG_BUILT_STANDALONE)

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4160,7 +4160,32 @@ TEST(CompletionTest, DoNotCrash) {
41604160
auto Completions = completions(Case);
41614161
}
41624162
}
4163+
TEST(CompletionTest, PreambleFromDifferentTarget) {
4164+
constexpr std::string_view PreambleTarget = "x86_64";
4165+
constexpr std::string_view Contents =
4166+
"int foo(int); int num; int num2 = foo(n^";
41634167

4168+
Annotations Test(Contents);
4169+
auto TU = TestTU::withCode(Test.code());
4170+
TU.ExtraArgs.emplace_back("-target");
4171+
TU.ExtraArgs.emplace_back(PreambleTarget);
4172+
auto Preamble = TU.preamble();
4173+
ASSERT_TRUE(Preamble);
4174+
// Switch target to wasm.
4175+
TU.ExtraArgs.pop_back();
4176+
TU.ExtraArgs.emplace_back("wasm32");
4177+
4178+
MockFS FS;
4179+
auto Inputs = TU.inputs(FS);
4180+
auto Result = codeComplete(testPath(TU.Filename), Test.point(),
4181+
Preamble.get(), Inputs, {});
4182+
auto Signatures =
4183+
signatureHelp(testPath(TU.Filename), Test.point(), *Preamble, Inputs, {});
4184+
4185+
// Make sure we don't crash.
4186+
EXPECT_THAT(Result.Completions, Not(testing::IsEmpty()));
4187+
EXPECT_THAT(Signatures.signatures, Not(testing::IsEmpty()));
4188+
}
41644189
} // namespace
41654190
} // namespace clangd
41664191
} // namespace clang

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

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "../../clang-tidy/ClangTidyCheck.h"
15-
#include "../../clang-tidy/ClangTidyModule.h"
16-
#include "../../clang-tidy/ClangTidyModuleRegistry.h"
1715
#include "AST.h"
18-
#include "CompileCommands.h"
1916
#include "Compiler.h"
2017
#include "Config.h"
2118
#include "Diagnostics.h"
@@ -32,7 +29,6 @@
3229
#include "clang/Basic/SourceLocation.h"
3330
#include "clang/Basic/SourceManager.h"
3431
#include "clang/Basic/TokenKinds.h"
35-
#include "clang/Lex/PPCallbacks.h"
3632
#include "clang/Tooling/Syntax/Tokens.h"
3733
#include "llvm/ADT/StringRef.h"
3834
#include "llvm/Testing/Annotations/Annotations.h"
@@ -41,6 +37,7 @@
4137
#include "gmock/gmock.h"
4238
#include "gtest/gtest.h"
4339
#include <memory>
40+
#include <string_view>
4441
#include <utility>
4542
#include <vector>
4643

@@ -347,9 +344,8 @@ TEST(ParsedASTTest, CollectsMainFileMacroExpansions) {
347344
}
348345
for (const auto &R : AST.getMacros().UnknownMacros)
349346
MacroExpansionPositions.push_back(R.StartOffset);
350-
EXPECT_THAT(
351-
MacroExpansionPositions,
352-
testing::UnorderedElementsAreArray(TestCase.points()));
347+
EXPECT_THAT(MacroExpansionPositions,
348+
testing::UnorderedElementsAreArray(TestCase.points()));
353349
}
354350

355351
MATCHER_P(withFileName, Inc, "") { return arg.FileName == Inc; }
@@ -768,6 +764,35 @@ TEST(ParsedASTTest, GracefulFailureOnAssemblyFile) {
768764
<< "Should not try to build AST for assembly source file";
769765
}
770766

767+
TEST(ParsedASTTest, PreambleWithDifferentTarget) {
768+
constexpr std::string_view kPreambleTarget = "x86_64";
769+
// Specifically picking __builtin_va_list as it triggers crashes when
770+
// switching to wasm.
771+
// It's due to different predefined types in different targets.
772+
auto TU = TestTU::withHeaderCode("void foo(__builtin_va_list);");
773+
TU.Code = "void bar() { foo(2); }";
774+
TU.ExtraArgs.emplace_back("-target");
775+
TU.ExtraArgs.emplace_back(kPreambleTarget);
776+
const auto Preamble = TU.preamble();
777+
778+
// Switch target to wasm.
779+
TU.ExtraArgs.pop_back();
780+
TU.ExtraArgs.emplace_back("wasm32");
781+
782+
IgnoreDiagnostics Diags;
783+
MockFS FS;
784+
auto Inputs = TU.inputs(FS);
785+
auto CI = buildCompilerInvocation(Inputs, Diags);
786+
ASSERT_TRUE(CI) << "Failed to build compiler invocation";
787+
788+
auto AST = ParsedAST::build(testPath(TU.Filename), std::move(Inputs),
789+
std::move(CI), {}, Preamble);
790+
791+
ASSERT_TRUE(AST);
792+
// We use the target from preamble, not with the most-recent flags.
793+
EXPECT_EQ(AST->getASTContext().getTargetInfo().getTriple().getArchName(),
794+
llvm::StringRef(kPreambleTarget));
795+
}
771796
} // namespace
772797
} // namespace clangd
773798
} // namespace clang

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,18 @@ Changes in existing checks
147147
<clang-tidy/checks/bugprone/assert-side-effect>` check by detecting side
148148
effect from calling a method with non-const reference parameters.
149149

150+
- Improved :doc:`bugprone-forwarding-reference-overload
151+
<clang-tidy/checks/bugprone/forwarding-reference-overload>`
152+
check to ignore deleted constructors which won't hide other overloads.
153+
150154
- Improved :doc:`bugprone-inc-dec-in-conditions
151155
<clang-tidy/checks/bugprone/inc-dec-in-conditions>` check to ignore code
152156
within unevaluated contexts, such as ``decltype``.
153157

158+
- Improved :doc:`bugprone-lambda-function-name<clang-tidy/checks/bugprone/lambda-function-name>`
159+
check by ignoring ``__func__`` macro in lambda captures, initializers of
160+
default parameters and nested function declarations.
161+
154162
- Improved :doc:`bugprone-non-zero-enum-to-bool-conversion
155163
<clang-tidy/checks/bugprone/non-zero-enum-to-bool-conversion>` check by
156164
eliminating false positives resulting from direct usage of bitwise operators

0 commit comments

Comments
 (0)