Skip to content

Commit fe4de72

Browse files
committed
Merge remote-tracking branch 'upstream/main' into delayed_privatization_15
2 parents d71bc1b + 3785d74 commit fe4de72

File tree

340 files changed

+9716
-14005
lines changed

Some content is hidden

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

340 files changed

+9716
-14005
lines changed

.github/CODEOWNERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
clang/lib/AST/Interp/ @tbaederr
3636
clang/test/AST/Interp/ @tbaederr
3737

38+
/clang/include/clang/CIR @lanza @bcardosolopes
39+
/clang/lib/CIR @lanza @bcardosolopes
40+
/clang/tools/cir-* @lanza @bcardosolopes
41+
3842
/lldb/ @JDevlieghere
3943

4044
# MLIR Interfaces.

clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class UseNullptrCheck : public ClangTidyCheck {
1919
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
2020
// FIXME this should be CPlusPlus11 but that causes test cases to
2121
// erroneously fail.
22-
return LangOpts.CPlusPlus;
22+
return LangOpts.CPlusPlus || LangOpts.C23;
2323
}
2424
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
2525
void registerMatchers(ast_matchers::MatchFinder *Finder) override;

clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ void AvoidReturnWithVoidValueCheck::check(
6464
<< BraceInsertionHints.closingBraceFixIt();
6565
}
6666
Diag << FixItHint::CreateRemoval(VoidReturn->getReturnLoc());
67-
if (!Result.Nodes.getNodeAs<FunctionDecl>("function_parent") ||
68-
SurroundingBlock->body_back() != VoidReturn)
67+
const auto *FunctionParent =
68+
Result.Nodes.getNodeAs<FunctionDecl>("function_parent");
69+
if (!FunctionParent ||
70+
(SurroundingBlock && SurroundingBlock->body_back() != VoidReturn))
71+
// If this is not the last statement in a function body, we add a `return`.
6972
Diag << FixItHint::CreateInsertion(SemicolonPos.getLocWithOffset(1),
7073
" return;", true);
7174
}

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,15 @@ Improvements to clang-tidy
100100
- Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter`
101101
to filter source files from the compilation database, via a RegEx. In a
102102
similar fashion to what `-header-filter` does for header files.
103+
103104
- Improved :program:`check_clang_tidy.py` script. Added argument `-export-fixes`
104105
to aid in clang-tidy and test development.
106+
105107
- Fixed bug where big values for unsigned check options overflowed into negative values
106-
when being printed with ``--dump-config``.
108+
when being printed with `--dump-config`.
107109

108-
- Fixed ``--verify-config`` option not properly parsing checks when using the
109-
literal operator in the ``.clang-tidy`` config.
110+
- Fixed `--verify-config` option not properly parsing checks when using the
111+
literal operator in the `.clang-tidy` config.
110112

111113
New checks
112114
^^^^^^^^^^
@@ -236,7 +238,7 @@ Changes in existing checks
236238

237239
- Improved :doc:`google-explicit-constructor
238240
<clang-tidy/checks/google/explicit-constructor>` check to better handle
239-
``C++-20`` `explicit(bool)`.
241+
C++20 `explicit(bool)`.
240242

241243
- Improved :doc:`google-global-names-in-headers
242244
<clang-tidy/checks/google/global-names-in-headers>` check by replacing the local
@@ -249,6 +251,10 @@ Changes in existing checks
249251
check by ignoring other functions with same prefixes as the target specific
250252
functions.
251253

254+
- Improved :doc:`linuxkernel-must-check-errs
255+
<clang-tidy/checks/linuxkernel/must-check-errs>` check documentation to
256+
consistently use the check's proper name.
257+
252258
- Improved :doc:`llvm-header-guard
253259
<clang-tidy/checks/llvm/header-guard>` check by replacing the local
254260
option `HeaderFileExtensions` by the global option of the same name.
@@ -281,6 +287,10 @@ Changes in existing checks
281287
don't remove parentheses used in ``sizeof`` calls when they have array index
282288
accesses as arguments.
283289

290+
- Improved :doc:`modernize-use-nullptr
291+
<clang-tidy/checks/modernize/use-nullptr>` check to include support for C23,
292+
which also has introduced the ``nullptr`` keyword.
293+
284294
- Improved :doc:`modernize-use-override
285295
<clang-tidy/checks/modernize/use-override>` check to also remove any trailing
286296
whitespace when deleting the ``virtual`` keyword.
@@ -336,13 +346,9 @@ Miscellaneous
336346
^^^^^^^^^^^^^
337347

338348
- Fixed incorrect formatting in :program:`clang-apply-replacements` when no
339-
``--format`` option is specified. Now :program:`clang-apply-replacements`
349+
`--format` option is specified. Now :program:`clang-apply-replacements`
340350
applies formatting only with the option.
341351

342-
- Fixed the :doc:`linuxkernel-must-check-errs
343-
<clang-tidy/checks/linuxkernel/must-check-errs>` documentation to consistently
344-
use the check's proper name.
345-
346352
Improvements to include-fixer
347353
-----------------------------
348354

clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ modernize-use-nullptr
44
=====================
55

66
The check converts the usage of null pointer constants (e.g. ``NULL``, ``0``)
7-
to use the new C++11 ``nullptr`` keyword.
7+
to use the new C++11 and C23 ``nullptr`` keyword.
88

99
Example
1010
-------
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// RUN: %check_clang_tidy %s modernize-use-nullptr %t -- -- -std=c23
2+
3+
#define NULL 0
4+
5+
void test_assignment() {
6+
int *p1 = 0;
7+
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use nullptr [modernize-use-nullptr]
8+
// CHECK-FIXES: int *p1 = nullptr;
9+
p1 = 0;
10+
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use nullptr
11+
// CHECK-FIXES: p1 = nullptr;
12+
13+
int *p2 = NULL;
14+
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use nullptr
15+
// CHECK-FIXES: int *p2 = nullptr;
16+
17+
p2 = p1;
18+
// CHECK-FIXES: p2 = p1;
19+
20+
const int null = 0;
21+
int *p3 = &null;
22+
23+
p3 = NULL;
24+
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use nullptr
25+
// CHECK-FIXES: p3 = nullptr;
26+
27+
int *p4 = p3;
28+
29+
int i1 = 0;
30+
31+
int i2 = NULL;
32+
33+
int i3 = null;
34+
35+
int *p5, *p6, *p7;
36+
p5 = p6 = p7 = NULL;
37+
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr
38+
// CHECK-FIXES: p5 = p6 = p7 = nullptr;
39+
}
40+
41+
void test_function(int *p) {}
42+
43+
void test_function_no_ptr_param(int i) {}
44+
45+
void test_function_call() {
46+
test_function(0);
47+
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use nullptr
48+
// CHECK-FIXES: test_function(nullptr);
49+
50+
test_function(NULL);
51+
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use nullptr
52+
// CHECK-FIXES: test_function(nullptr);
53+
54+
test_function_no_ptr_param(0);
55+
}
56+
57+
char *test_function_return1() {
58+
return 0;
59+
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use nullptr
60+
// CHECK-FIXES: return nullptr;
61+
}
62+
63+
void *test_function_return2() {
64+
return NULL;
65+
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use nullptr
66+
// CHECK-FIXES: return nullptr;
67+
}
68+
69+
int test_function_return4() {
70+
return 0;
71+
}
72+
73+
int test_function_return5() {
74+
return NULL;
75+
}
76+
77+
int *test_function_return_cast1() {
78+
return(int)0;
79+
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use nullptr
80+
// CHECK-FIXES: return nullptr;
81+
}
82+
83+
int *test_function_return_cast2() {
84+
#define RET return
85+
RET(int)0;
86+
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use nullptr
87+
// CHECK-FIXES: RET nullptr;
88+
#undef RET
89+
}
90+
91+
// Test parentheses expressions resulting in a nullptr.
92+
int *test_parentheses_expression1() {
93+
return(0);
94+
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use nullptr
95+
// CHECK-FIXES: return(nullptr);
96+
}
97+
98+
int *test_parentheses_expression2() {
99+
return((int)(0.0f));
100+
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use nullptr
101+
// CHECK-FIXES: return(nullptr);
102+
}
103+
104+
int *test_nested_parentheses_expression() {
105+
return((((0))));
106+
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use nullptr
107+
// CHECK-FIXES: return((((nullptr))));
108+
}
109+
110+
void test_const_pointers() {
111+
const int *const_p1 = 0;
112+
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use nullptr
113+
// CHECK-FIXES: const int *const_p1 = nullptr;
114+
const int *const_p2 = NULL;
115+
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use nullptr
116+
// CHECK-FIXES: const int *const_p2 = nullptr;
117+
const int *const_p3 = (int)0;
118+
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use nullptr
119+
// CHECK-FIXES: const int *const_p3 = nullptr;
120+
const int *const_p4 = (int)0.0f;
121+
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use nullptr
122+
// CHECK-FIXES: const int *const_p4 = nullptr;
123+
}
124+
125+
void test_nested_implicit_cast_expr() {
126+
int func0(void*, void*);
127+
int func1(int, void*, void*);
128+
129+
(double)func1(0, 0, 0);
130+
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use nullptr
131+
// CHECK-MESSAGES: :[[@LINE-2]]:23: warning: use nullptr
132+
// CHECK-FIXES: (double)func1(0, nullptr, nullptr);
133+
(double)func1(func0(0, 0), 0, 0);
134+
// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: use nullptr
135+
// CHECK-MESSAGES: :[[@LINE-2]]:26: warning: use nullptr
136+
// CHECK-MESSAGES: :[[@LINE-3]]:30: warning: use nullptr
137+
// CHECK-MESSAGES: :[[@LINE-4]]:33: warning: use nullptr
138+
// CHECK-FIXES: (double)func1(func0(nullptr, nullptr), nullptr, nullptr);
139+
}

clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: clang-tidy %s -checks=-*,modernize-use-nullptr -- | count 0
1+
// RUN: clang-tidy %s -checks=-*,modernize-use-nullptr -- -std=c17 | count 0
22

33
// Note: this test expects no diagnostics, but FileCheck cannot handle that,
44
// hence the use of | count 0.

clang/cmake/caches/Release.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ set(LLVM_ENABLE_PROJECTS ${STAGE1_PROJECTS} CACHE STRING "")
8282
# stage2-instrumented and Final Stage Config:
8383
# Options that need to be set in both the instrumented stage (if we are doing
8484
# a pgo build) and the final stage.
85+
set_instrument_and_final_stage_var(CMAKE_POSITION_INDEPENDENT_CODE "ON" STRING)
8586
set_instrument_and_final_stage_var(LLVM_ENABLE_LTO "${LLVM_RELEASE_ENABLE_LTO}" STRING)
8687
if (LLVM_RELEASE_ENABLE_LTO)
8788
set_instrument_and_final_stage_var(LLVM_ENABLE_LLD "ON" BOOL)

clang/docs/LanguageExtensions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,7 @@ Conditional ``explicit`` __cpp_conditional_explicit C+
14931493
``if consteval`` __cpp_if_consteval C++23 C++20
14941494
``static operator()`` __cpp_static_call_operator C++23 C++03
14951495
Attributes on Lambda-Expressions C++23 C++11
1496+
Attributes on Structured Bindings __cpp_structured_bindings C++26 C++03
14961497
``= delete ("should have a reason");`` __cpp_deleted_function C++26 C++03
14971498
-------------------------------------------- -------------------------------- ------------- -------------
14981499
Designated initializers (N494) C99 C89

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ C++2c Feature Support
143143

144144
- Implemented `P2573R2: = delete("should have a reason"); <https://wg21.link/P2573R2>`_
145145

146+
- Implemented `P0609R3: Attributes for Structured Bindings <https://wg21.link/P0609R3>`_
147+
146148

147149
Resolutions to C++ Defect Reports
148150
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/DeclContextInternals.h

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ class StoredDeclsList {
4242
/// external declarations.
4343
DeclsAndHasExternalTy Data;
4444

45-
template<typename Fn>
46-
void erase_if(Fn ShouldErase) {
45+
template <typename Fn> DeclListNode::Decls *erase_if(Fn ShouldErase) {
4746
Decls List = Data.getPointer();
47+
4848
if (!List)
49-
return;
49+
return nullptr;
50+
5051
ASTContext &C = getASTContext();
5152
DeclListNode::Decls NewHead = nullptr;
5253
DeclListNode::Decls *NewLast = nullptr;
@@ -79,6 +80,17 @@ class StoredDeclsList {
7980
Data.setPointer(NewHead);
8081

8182
assert(llvm::none_of(getLookupResult(), ShouldErase) && "Still exists!");
83+
84+
if (!Data.getPointer())
85+
// All declarations are erased.
86+
return nullptr;
87+
else if (NewHead.is<NamedDecl *>())
88+
// The list only contains a declaration, the header itself.
89+
return (DeclListNode::Decls *)&Data;
90+
else {
91+
assert(NewLast && NewLast->is<NamedDecl *>() && "Not the tail?");
92+
return NewLast;
93+
}
8294
}
8395

8496
void erase(NamedDecl *ND) {
@@ -160,12 +172,16 @@ class StoredDeclsList {
160172

161173
void replaceExternalDecls(ArrayRef<NamedDecl*> Decls) {
162174
// Remove all declarations that are either external or are replaced with
163-
// external declarations.
164-
erase_if([Decls](NamedDecl *ND) {
175+
// external declarations with higher visibilities.
176+
DeclListNode::Decls *Tail = erase_if([Decls](NamedDecl *ND) {
165177
if (ND->isFromASTFile())
166178
return true;
179+
// FIXME: Can we get rid of this loop completely?
167180
for (NamedDecl *D : Decls)
168-
if (D->declarationReplaces(ND, /*IsKnownNewer=*/false))
181+
// Only replace the local declaration if the external declaration has
182+
// higher visibilities.
183+
if (D->getModuleOwnershipKind() <= ND->getModuleOwnershipKind() &&
184+
D->declarationReplaces(ND, /*IsKnownNewer=*/false))
169185
return true;
170186
return false;
171187
});
@@ -185,24 +201,15 @@ class StoredDeclsList {
185201
DeclsAsList = Node;
186202
}
187203

188-
DeclListNode::Decls Head = Data.getPointer();
189-
if (Head.isNull()) {
204+
if (!Data.getPointer()) {
190205
Data.setPointer(DeclsAsList);
191206
return;
192207
}
193208

194-
// Find the end of the existing list.
195-
// FIXME: It would be possible to preserve information from erase_if to
196-
// avoid this rescan looking for the end of the list.
197-
DeclListNode::Decls *Tail = &Head;
198-
while (DeclListNode *Node = Tail->dyn_cast<DeclListNode *>())
199-
Tail = &Node->Rest;
200-
201209
// Append the Decls.
202210
DeclListNode *Node = C.AllocateDeclListNode(Tail->get<NamedDecl *>());
203211
Node->Rest = DeclsAsList;
204212
*Tail = Node;
205-
Data.setPointer(Head);
206213
}
207214

208215
/// Return the list of all the decls.

clang/include/clang/Basic/Attr.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3211,7 +3211,7 @@ def ObjCRequiresPropertyDefs : InheritableAttr {
32113211
def Unused : InheritableAttr {
32123212
let Spellings = [CXX11<"", "maybe_unused", 201603>, GCC<"unused">,
32133213
C23<"", "maybe_unused", 202106>];
3214-
let Subjects = SubjectList<[Var, ObjCIvar, Type, Enum, EnumConstant, Label,
3214+
let Subjects = SubjectList<[Var, Binding, ObjCIvar, Type, Enum, EnumConstant, Label,
32153215
Field, ObjCMethod, FunctionLike]>;
32163216
let Documentation = [WarnMaybeUnusedDocs];
32173217
}

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,15 @@ def ext_decomp_decl_empty : ExtWarn<
478478
"ISO C++17 does not allow a decomposition group to be empty">,
479479
InGroup<DiagGroup<"empty-decomposition">>;
480480

481+
// C++26 structured bindings
482+
def ext_decl_attrs_on_binding : ExtWarn<
483+
"an attribute specifier sequence attached to a structured binding declaration "
484+
"is a C++2c extension">, InGroup<CXX26>;
485+
def warn_cxx23_compat_decl_attrs_on_binding : Warning<
486+
"an attribute specifier sequence attached to a structured binding declaration "
487+
"is incompatible with C++ standards before C++2c">,
488+
InGroup<CXXPre26Compat>, DefaultIgnore;
489+
481490
/// Objective-C parser diagnostics
482491
def err_expected_minus_or_plus : Error<
483492
"method type specifier must start with '-' or '+'">;

0 commit comments

Comments
 (0)