Skip to content

Commit c371f1a

Browse files
authored
Merge branch 'main' into feat/attr-scope
2 parents 7a97e93 + 0ba5958 commit c371f1a

File tree

536 files changed

+11066
-3015
lines changed

Some content is hidden

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

536 files changed

+11066
-3015
lines changed

.github/workflows/libclang-python-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ on:
1010
- 'main'
1111
paths:
1212
- 'clang/bindings/python/**'
13-
- 'clang/test/bindings/python/**'
1413
- 'clang/tools/libclang/**'
14+
- 'clang/CMakeList.txt'
1515
- '.github/workflows/libclang-python-tests.yml'
1616
- '.github/workflows/llvm-project-tests.yml'
1717
pull_request:
1818
paths:
1919
- 'clang/bindings/python/**'
20-
- 'clang/test/bindings/python/**'
2120
- 'clang/tools/libclang/**'
21+
- 'clang/CMakeList.txt'
2222
- '.github/workflows/libclang-python-tests.yml'
2323
- '.github/workflows/llvm-project-tests.yml'
2424

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,17 @@ static llvm::Error addReference(T I, Reference &&R, FieldId F) {
569569
"invalid type cannot contain Reference");
570570
}
571571

572+
template <> llvm::Error addReference(VarInfo *I, Reference &&R, FieldId F) {
573+
switch (F) {
574+
case FieldId::F_namespace:
575+
I->Namespace.emplace_back(std::move(R));
576+
return llvm::Error::success();
577+
default:
578+
return llvm::createStringError(llvm::inconvertibleErrorCode(),
579+
"VarInfo cannot contain this Reference");
580+
}
581+
}
582+
572583
template <> llvm::Error addReference(TypeInfo *I, Reference &&R, FieldId F) {
573584
switch (F) {
574585
case FieldId::F_type:

clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,27 @@ getFixIt(const tooling::Diagnostic &Diagnostic, bool AnyFix) {
358358

359359
} // namespace clang::tidy
360360

361+
void ClangTidyDiagnosticConsumer::BeginSourceFile(const LangOptions &LangOpts,
362+
const Preprocessor *PP) {
363+
DiagnosticConsumer::BeginSourceFile(LangOpts, PP);
364+
365+
assert(!InSourceFile);
366+
InSourceFile = true;
367+
}
368+
369+
void ClangTidyDiagnosticConsumer::EndSourceFile() {
370+
assert(InSourceFile);
371+
InSourceFile = false;
372+
373+
DiagnosticConsumer::EndSourceFile();
374+
}
375+
361376
void ClangTidyDiagnosticConsumer::HandleDiagnostic(
362377
DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) {
378+
// A diagnostic should not be reported outside of a
379+
// BeginSourceFile()/EndSourceFile() pair if it has a source location.
380+
assert(InSourceFile || Info.getLocation().isInvalid());
381+
363382
if (LastErrorWasIgnored && DiagLevel == DiagnosticsEngine::Note)
364383
return;
365384

clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,11 @@ class ClangTidyDiagnosticConsumer : public DiagnosticConsumer {
292292
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
293293
const Diagnostic &Info) override;
294294

295+
void BeginSourceFile(const LangOptions &LangOpts,
296+
const Preprocessor *PP = nullptr) override;
297+
298+
void EndSourceFile() override;
299+
295300
// Retrieve the diagnostics that were captured.
296301
std::vector<ClangTidyError> take();
297302

@@ -326,6 +331,11 @@ class ClangTidyDiagnosticConsumer : public DiagnosticConsumer {
326331
bool LastErrorRelatesToUserCode = false;
327332
bool LastErrorPassesLineFilter = false;
328333
bool LastErrorWasIgnored = false;
334+
/// Tracks whether we're currently inside a
335+
/// `BeginSourceFile()/EndSourceFile()` pair. Outside of a source file, we
336+
/// should only receive diagnostics that have to source location, such as
337+
/// command-line warnings.
338+
bool InSourceFile = false;
329339
};
330340

331341
} // end namespace tidy

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,26 @@ using namespace clang::ast_matchers;
1515
namespace clang::tidy::cppcoreguidelines {
1616

1717
void ProBoundsPointerArithmeticCheck::registerMatchers(MatchFinder *Finder) {
18-
if (!getLangOpts().CPlusPlus)
19-
return;
20-
2118
const auto AllPointerTypes =
22-
anyOf(hasType(pointerType()),
19+
anyOf(hasType(hasUnqualifiedDesugaredType(pointerType())),
2320
hasType(autoType(
2421
hasDeducedType(hasUnqualifiedDesugaredType(pointerType())))),
2522
hasType(decltypeType(hasUnderlyingType(pointerType()))));
2623

27-
// Flag all operators +, -, +=, -=, ++, -- that result in a pointer
24+
// Flag all operators +, -, +=, -= that result in a pointer
2825
Finder->addMatcher(
2926
binaryOperator(
3027
hasAnyOperatorName("+", "-", "+=", "-="), AllPointerTypes,
3128
unless(hasLHS(ignoringImpCasts(declRefExpr(to(isImplicit()))))))
3229
.bind("expr"),
3330
this);
3431

32+
// Flag all operators ++, -- that result in a pointer
3533
Finder->addMatcher(
36-
unaryOperator(hasAnyOperatorName("++", "--"), hasType(pointerType()))
34+
unaryOperator(hasAnyOperatorName("++", "--"),
35+
hasType(hasUnqualifiedDesugaredType(pointerType())),
36+
unless(hasUnaryOperand(
37+
ignoringImpCasts(declRefExpr(to(isImplicit()))))))
3738
.bind("expr"),
3839
this);
3940

clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class ProBoundsPointerArithmeticCheck : public ClangTidyCheck {
2323
public:
2424
ProBoundsPointerArithmeticCheck(StringRef Name, ClangTidyContext *Context)
2525
: ClangTidyCheck(Name, Context) {}
26+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
27+
return LangOpts.CPlusPlus;
28+
}
2629
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
2730
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
2831
};

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: rm -rf %t && mkdir -p %t
2+
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
3+
// RUN: FileCheck %s < %t/nested/index.json --check-prefix=NESTED
4+
// RUN: FileCheck %s < %t/nested/inner/index.json --check-prefix=INNER
5+
6+
namespace nested {
7+
int Global;
8+
namespace inner {
9+
int InnerGlobal;
10+
} // namespace inner
11+
} // namespace nested
12+
13+
// NESTED: "Variables": [
14+
// NESTED-NEXT: {
15+
// NESTED-NEXT: "IsStatic": false,
16+
// NESTED-NEXT: "Location": {
17+
// NESTED-NEXT: "Filename": "{{.*}}nested-namespace.cpp",
18+
// NESTED-NEXT: "LineNumber": 7
19+
// NESTED-NEXT: },
20+
// NESTED-NEXT: "Name": "Global",
21+
// NESTED-NEXT: "Namespace": [
22+
// NESTED-NEXT: "nested"
23+
// NESTED-NEXT: ],
24+
25+
// INNER: "Variables": [
26+
// INNER-NEXT: {
27+
// INNER-NEXT: "IsStatic": false,
28+
// INNER-NEXT: "Location": {
29+
// INNER-NEXT: "Filename": "{{.*}}nested-namespace.cpp",
30+
// INNER-NEXT: "LineNumber": 9
31+
// INNER-NEXT: },
32+
// INNER-NEXT: "Name": "InnerGlobal",
33+
// INNER-NEXT: "Namespace": [
34+
// INNER-NEXT: "inner",
35+
// INNER-NEXT: "nested"
36+
// INNER-NEXT: ],

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-pointer-arithmetic-pr36489.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
// RUN: %check_clang_tidy -std=c++14-or-later %s cppcoreguidelines-pro-bounds-pointer-arithmetic %t
22

33
// Fix PR36489 and detect auto-deduced value correctly.
4+
typedef char* charPtr;
5+
46
char *getPtr();
57
auto getPtrAuto() { return getPtr(); }
68
decltype(getPtr()) getPtrDeclType();
79
decltype(auto) getPtrDeclTypeAuto() { return getPtr(); }
810
auto getPtrWithTrailingReturnType() -> char *;
11+
charPtr getCharPtr() { return getPtr(); }
912

1013
void auto_deduction_binary() {
1114
auto p1 = getPtr() + 1;
@@ -28,6 +31,10 @@ void auto_deduction_binary() {
2831
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: do not use pointer arithmetic
2932
auto *p9 = getPtrDeclTypeAuto() + 1;
3033
// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: do not use pointer arithmetic
34+
auto p10 = getCharPtr() + 1;
35+
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use pointer
36+
auto* p11 = getCharPtr() + 1;
37+
// CHECK-MESSAGES: :[[@LINE-1]]:28: warning: do not use pointer arithmetic
3138
}
3239

3340
void auto_deduction_subscript() {
@@ -50,4 +57,6 @@ void auto_deduction_subscript() {
5057
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic
5158
auto p8 = getPtrDeclTypeAuto()[9];
5259
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic
60+
auto p9 = getCharPtr()[10];
61+
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic
5362
}

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-pointer-arithmetic.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ enum E {
44
ENUM_LITERAL = 1
55
};
66

7+
typedef int* IntPtr;
8+
79
int i = 4;
810
int j = 1;
911
int *p = 0;
1012
int *q = 0;
13+
IntPtr ip = 0;
1114

1215
void fail() {
1316
q = p + 4;
@@ -50,6 +53,32 @@ void fail() {
5053

5154
i = p[1];
5255
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use pointer arithmetic
56+
57+
p = ip + 1;
58+
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: do not use pointer arithmetic
59+
ip++;
60+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use pointer arithmetic
61+
i = ip[1];
62+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use pointer arithmetic
63+
}
64+
65+
template <typename T>
66+
void template_fail() {
67+
T* p;
68+
T* q;
69+
70+
p = q + 1;
71+
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not use pointer arithmetic
72+
q = p - 1;
73+
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not use pointer arithmetic
74+
p++;
75+
// CHECK-MESSAGES: :[[@LINE-1]]:4: warning: do not use pointer arithmetic
76+
i = p[1];
77+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use pointer arithmetic
78+
}
79+
80+
void instantiate() {
81+
template_fail<int>();
5382
}
5483

5584
struct S {

0 commit comments

Comments
 (0)