Skip to content

Commit 6203cf7

Browse files
authored
Merge branch 'main' into OffloadTargets
2 parents 46ca9ec + 6a94814 commit 6203cf7

File tree

886 files changed

+61924
-50349
lines changed

Some content is hidden

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

886 files changed

+61924
-50349
lines changed

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
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ Changes in existing checks
219219
- Improved :doc:`cppcoreguidelines-pro-bounds-pointer-arithmetic
220220
<clang-tidy/checks/cppcoreguidelines/pro-bounds-pointer-arithmetic>` check by
221221
fixing false positives when calling indexing operators that do not perform
222-
pointer arithmetic in template, for example ``std::map::operator[]``.
222+
pointer arithmetic in template, for example ``std::map::operator[]`` and
223+
when pointer arithmetic was used through type aliases.
223224

224225
- Improved :doc:`cppcoreguidelines-rvalue-reference-param-not-moved
225226
<clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved>` check
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 {

clang/docs/DebuggingCoroutines.rst

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,24 @@ important. This member identifies the suspension point at which the coroutine
209209
is currently suspended.
210210

211211
However, it is non-trivial to map this number back to a source code location.
212-
In simple cases, one might correctly guess the source code location. In more
213-
complex cases, we can modify the C++ code to store additional information in
214-
the promise type:
212+
The compiler emits debug info labels for the suspension points. This allows us
213+
to map the suspension point index back to a source code location. In gdb, we
214+
can use the ``info line`` command to get the source code location of the
215+
suspension point.
216+
217+
::
218+
219+
(gdb) info line -function coro_task -label __coro_resume_2
220+
Line 45 of "llvm-example.cpp" starts at address 0x1b1b <_ZL9coro_taski.resume+555> and ends at 0x1b46 <_ZL9coro_taski.resume+598>.
221+
Line 45 of "llvm-example.cpp" starts at address 0x201b <_ZL9coro_taski.destroy+555> and ends at 0x2046 <_ZL9coro_taski.destroy+598>.
222+
Line 45 of "llvm-example.cpp" starts at address 0x253b <_ZL9coro_taski.cleanup+555> and ends at 0x2566 <_ZL9coro_taski.cleanup+598>.
223+
224+
LLDB does not support looking up labels. Furthmore, those labels are only emitted
225+
starting with clang 21.0.
226+
227+
For simple cases, you might still be able to guess the suspension point correctly.
228+
Alternatively, you might also want to modify your coroutine library to store
229+
the line number of the current suspension point in the promise:
215230

216231
.. code-block:: c++
217232

@@ -221,8 +236,6 @@ the promise type:
221236
void* _coro_return_address = nullptr;
222237
};
223238

224-
#include <source_location>
225-
226239
// For all the awaiter types we need:
227240
class awaiter {
228241
...

0 commit comments

Comments
 (0)