Skip to content

Commit 82b836e

Browse files
authored
merge main into amd-staging (llvm#1417)
2 parents e00728b + b8ab101 commit 82b836e

File tree

244 files changed

+3636
-1802
lines changed

Some content is hidden

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

244 files changed

+3636
-1802
lines changed

clang-tools-extra/test/clang-tidy/check_clang_tidy.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,16 @@
4848
import re
4949
import subprocess
5050
import sys
51+
from typing import List, Tuple
5152

5253

53-
def write_file(file_name, text):
54+
def write_file(file_name: str, text: str) -> None:
5455
with open(file_name, "w", encoding="utf-8") as f:
5556
f.write(text)
5657
f.truncate()
5758

5859

59-
def try_run(args, raise_error=True):
60+
def try_run(args: List[str], raise_error: bool = True) -> str:
6061
try:
6162
process_output = subprocess.check_output(args, stderr=subprocess.STDOUT).decode(
6263
errors="ignore"
@@ -71,12 +72,12 @@ def try_run(args, raise_error=True):
7172

7273
# This class represents the appearance of a message prefix in a file.
7374
class MessagePrefix:
74-
def __init__(self, label):
75+
def __init__(self, label: str) -> None:
7576
self.has_message = False
76-
self.prefixes = []
77+
self.prefixes: List[str] = []
7778
self.label = label
7879

79-
def check(self, file_check_suffix, input_text):
80+
def check(self, file_check_suffix: str, input_text: str) -> bool:
8081
self.prefix = self.label + file_check_suffix
8182
self.has_message = self.prefix in input_text
8283
if self.has_message:
@@ -85,7 +86,7 @@ def check(self, file_check_suffix, input_text):
8586

8687

8788
class CheckRunner:
88-
def __init__(self, args, extra_args):
89+
def __init__(self, args: argparse.Namespace, extra_args: List[str]) -> None:
8990
self.resource_dir = args.resource_dir
9091
self.assume_file_name = args.assume_filename
9192
self.input_file_name = args.input_file_name
@@ -143,11 +144,11 @@ def __init__(self, args, extra_args):
143144
if self.resource_dir is not None:
144145
self.clang_extra_args.append("-resource-dir=%s" % self.resource_dir)
145146

146-
def read_input(self):
147+
def read_input(self) -> None:
147148
with open(self.input_file_name, "r", encoding="utf-8") as input_file:
148149
self.input_text = input_file.read()
149150

150-
def get_prefixes(self):
151+
def get_prefixes(self) -> None:
151152
for suffix in self.check_suffix:
152153
if suffix and not re.match("^[A-Z0-9\\-]+$", suffix):
153154
sys.exit(
@@ -189,7 +190,7 @@ def get_prefixes(self):
189190
)
190191
assert expect_diagnosis or self.expect_no_diagnosis
191192

192-
def prepare_test_inputs(self):
193+
def prepare_test_inputs(self) -> None:
193194
# Remove the contents of the CHECK lines to avoid CHECKs matching on
194195
# themselves. We need to keep the comments to preserve line numbers while
195196
# avoiding empty lines which could potentially trigger formatting-related
@@ -198,7 +199,7 @@ def prepare_test_inputs(self):
198199
write_file(self.temp_file_name, cleaned_test)
199200
write_file(self.original_file_name, cleaned_test)
200201

201-
def run_clang_tidy(self):
202+
def run_clang_tidy(self) -> str:
202203
args = (
203204
[
204205
"clang-tidy",
@@ -238,11 +239,11 @@ def run_clang_tidy(self):
238239
print("------------------------------------------------------------------")
239240
return clang_tidy_output
240241

241-
def check_no_diagnosis(self, clang_tidy_output):
242+
def check_no_diagnosis(self, clang_tidy_output: str) -> None:
242243
if clang_tidy_output != "":
243244
sys.exit("No diagnostics were expected, but found the ones above")
244245

245-
def check_fixes(self):
246+
def check_fixes(self) -> None:
246247
if self.has_check_fixes:
247248
try_run(
248249
[
@@ -254,7 +255,7 @@ def check_fixes(self):
254255
]
255256
)
256257

257-
def check_messages(self, clang_tidy_output):
258+
def check_messages(self, clang_tidy_output: str) -> None:
258259
if self.has_check_messages:
259260
messages_file = self.temp_file_name + ".msg"
260261
write_file(messages_file, clang_tidy_output)
@@ -268,7 +269,7 @@ def check_messages(self, clang_tidy_output):
268269
]
269270
)
270271

271-
def check_notes(self, clang_tidy_output):
272+
def check_notes(self, clang_tidy_output: str) -> None:
272273
if self.has_check_notes:
273274
notes_file = self.temp_file_name + ".notes"
274275
filtered_output = [
@@ -287,7 +288,7 @@ def check_notes(self, clang_tidy_output):
287288
]
288289
)
289290

290-
def run(self):
291+
def run(self) -> None:
291292
self.read_input()
292293
if self.export_fixes is None:
293294
self.get_prefixes()
@@ -313,7 +314,7 @@ def run(self):
313314
C_STANDARDS = ["c99", ("c11", "c1x"), "c17", ("c23", "c2x"), "c2y"]
314315

315316

316-
def expand_std(std):
317+
def expand_std(std: str) -> List[str]:
317318
split_std, or_later, _ = std.partition("-or-later")
318319

319320
if not or_later:
@@ -335,11 +336,11 @@ def expand_std(std):
335336
return [std]
336337

337338

338-
def csv(string):
339+
def csv(string: str) -> List[str]:
339340
return string.split(",")
340341

341342

342-
def parse_arguments():
343+
def parse_arguments() -> Tuple[argparse.Namespace, List[str]]:
343344
parser = argparse.ArgumentParser(
344345
prog=pathlib.Path(__file__).stem,
345346
description=__doc__,
@@ -374,7 +375,7 @@ def parse_arguments():
374375
return parser.parse_known_args()
375376

376377

377-
def main():
378+
def main() -> None:
378379
args, extra_args = parse_arguments()
379380

380381
abbreviated_stds = args.std

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3976,6 +3976,47 @@ the configuration (without a prefix: ``Auto``).
39763976

39773977

39783978

3979+
.. _EnumTrailingComma:
3980+
3981+
**EnumTrailingComma** (``EnumTrailingCommaStyle``) :versionbadge:`clang-format 21` :ref:`<EnumTrailingComma>`
3982+
Insert a comma (if missing) or remove the comma at the end of an ``enum``
3983+
enumerator list.
3984+
3985+
.. warning::
3986+
3987+
Setting this option to any value other than ``Leave`` could lead to
3988+
incorrect code formatting due to clang-format's lack of complete semantic
3989+
information. As such, extra care should be taken to review code changes
3990+
made by this option.
3991+
3992+
Possible values:
3993+
3994+
* ``ETC_Leave`` (in configuration: ``Leave``)
3995+
Don't insert or remove trailing commas.
3996+
3997+
.. code-block:: c++
3998+
3999+
enum { a, b, c, };
4000+
enum Color { red, green, blue };
4001+
4002+
* ``ETC_Insert`` (in configuration: ``Insert``)
4003+
Insert trailing commas.
4004+
4005+
.. code-block:: c++
4006+
4007+
enum { a, b, c, };
4008+
enum Color { red, green, blue, };
4009+
4010+
* ``ETC_Remove`` (in configuration: ``Remove``)
4011+
Remove trailing commas.
4012+
4013+
.. code-block:: c++
4014+
4015+
enum { a, b, c };
4016+
enum Color { red, green, blue };
4017+
4018+
4019+
39794020
.. _ExperimentalAutoDetectBinPacking:
39804021

39814022
**ExperimentalAutoDetectBinPacking** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`<ExperimentalAutoDetectBinPacking>`

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ Windows Support
450450
- Clang now can process the `i128` and `ui128` integeral suffixes when MSVC
451451
extensions are enabled. This allows for properly processing ``intsafe.h`` in
452452
the Windows SDK.
453+
- Clang now supports MSVC vector deleting destructors (GH19772).
453454

454455
LoongArch Support
455456
^^^^^^^^^^^^^^^^^
@@ -508,6 +509,8 @@ clang-format
508509
- Allow specifying the language (C, C++, or Objective-C) for a ``.h`` file by
509510
adding a special comment (e.g. ``// clang-format Language: ObjC``) near the
510511
top of the file.
512+
- Add ``EnumTrailingComma`` option for inserting/removing commas at the end of
513+
``enum`` enumerator lists.
511514

512515
libclang
513516
--------

clang/include/clang/AST/VTableBuilder.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class VTableComponent {
150150

151151
bool isRTTIKind() const { return isRTTIKind(getKind()); }
152152

153-
GlobalDecl getGlobalDecl() const {
153+
GlobalDecl getGlobalDecl(bool HasVectorDeletingDtors) const {
154154
assert(isUsedFunctionPointerKind() &&
155155
"GlobalDecl can be created only from virtual function");
156156

@@ -161,7 +161,9 @@ class VTableComponent {
161161
case CK_CompleteDtorPointer:
162162
return GlobalDecl(DtorDecl, CXXDtorType::Dtor_Complete);
163163
case CK_DeletingDtorPointer:
164-
return GlobalDecl(DtorDecl, CXXDtorType::Dtor_Deleting);
164+
return GlobalDecl(DtorDecl, (HasVectorDeletingDtors)
165+
? CXXDtorType::Dtor_VectorDeleting
166+
: CXXDtorType::Dtor_Deleting);
165167
case CK_VCallOffset:
166168
case CK_VBaseOffset:
167169
case CK_OffsetToTop:

clang/include/clang/Basic/ABI.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ enum CXXCtorType {
3131

3232
/// C++ destructor types.
3333
enum CXXDtorType {
34-
Dtor_Deleting, ///< Deleting dtor
35-
Dtor_Complete, ///< Complete object dtor
36-
Dtor_Base, ///< Base object dtor
37-
Dtor_Comdat ///< The COMDAT used for dtors
34+
Dtor_Deleting, ///< Deleting dtor
35+
Dtor_Complete, ///< Complete object dtor
36+
Dtor_Base, ///< Base object dtor
37+
Dtor_Comdat, ///< The COMDAT used for dtors
38+
Dtor_VectorDeleting ///< Vector deleting dtor
3839
};
3940

4041
} // end namespace clang

clang/include/clang/Format/Format.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,6 +2704,39 @@ struct FormatStyle {
27042704
/// \version 12
27052705
EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier;
27062706

2707+
/// Styles for ``enum`` trailing commas.
2708+
enum EnumTrailingCommaStyle : int8_t {
2709+
/// Don't insert or remove trailing commas.
2710+
/// \code
2711+
/// enum { a, b, c, };
2712+
/// enum Color { red, green, blue };
2713+
/// \endcode
2714+
ETC_Leave,
2715+
/// Insert trailing commas.
2716+
/// \code
2717+
/// enum { a, b, c, };
2718+
/// enum Color { red, green, blue, };
2719+
/// \endcode
2720+
ETC_Insert,
2721+
/// Remove trailing commas.
2722+
/// \code
2723+
/// enum { a, b, c };
2724+
/// enum Color { red, green, blue };
2725+
/// \endcode
2726+
ETC_Remove,
2727+
};
2728+
2729+
/// Insert a comma (if missing) or remove the comma at the end of an ``enum``
2730+
/// enumerator list.
2731+
/// \warning
2732+
/// Setting this option to any value other than ``Leave`` could lead to
2733+
/// incorrect code formatting due to clang-format's lack of complete semantic
2734+
/// information. As such, extra care should be taken to review code changes
2735+
/// made by this option.
2736+
/// \endwarning
2737+
/// \version 21
2738+
EnumTrailingCommaStyle EnumTrailingComma;
2739+
27072740
/// If ``true``, clang-format detects whether function calls and
27082741
/// definitions are formatted with one parameter per line.
27092742
///
@@ -5323,6 +5356,7 @@ struct FormatStyle {
53235356
DisableFormat == R.DisableFormat &&
53245357
EmptyLineAfterAccessModifier == R.EmptyLineAfterAccessModifier &&
53255358
EmptyLineBeforeAccessModifier == R.EmptyLineBeforeAccessModifier &&
5359+
EnumTrailingComma == R.EnumTrailingComma &&
53265360
ExperimentalAutoDetectBinPacking ==
53275361
R.ExperimentalAutoDetectBinPacking &&
53285362
FixNamespaceComments == R.FixNamespaceComments &&

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6004,6 +6004,8 @@ void CXXNameMangler::mangleCXXDtorType(CXXDtorType T) {
60046004
case Dtor_Comdat:
60056005
Out << "D5";
60066006
break;
6007+
case Dtor_VectorDeleting:
6008+
llvm_unreachable("Itanium ABI does not use vector deleting dtors");
60076009
}
60086010
}
60096011

clang/lib/AST/MicrosoftMangle.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,8 +1484,9 @@ void MicrosoftCXXNameMangler::mangleCXXDtorType(CXXDtorType T) {
14841484
// <operator-name> ::= ?_G # scalar deleting destructor
14851485
case Dtor_Deleting: Out << "?_G"; return;
14861486
// <operator-name> ::= ?_E # vector deleting destructor
1487-
// FIXME: Add a vector deleting dtor type. It goes in the vtable, so we need
1488-
// it.
1487+
case Dtor_VectorDeleting:
1488+
Out << "?_E";
1489+
return;
14891490
case Dtor_Comdat:
14901491
llvm_unreachable("not expecting a COMDAT");
14911492
}
@@ -2886,9 +2887,12 @@ void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T,
28862887
// ::= @ # structors (they have no declared return type)
28872888
if (IsStructor) {
28882889
if (isa<CXXDestructorDecl>(D) && isStructorDecl(D)) {
2889-
// The scalar deleting destructor takes an extra int argument which is not
2890-
// reflected in the AST.
2891-
if (StructorType == Dtor_Deleting) {
2890+
// The deleting destructors take an extra argument of type int that
2891+
// indicates whether the storage for the object should be deleted and
2892+
// whether a single object or an array of objects is being destroyed. This
2893+
// extra argument is not reflected in the AST.
2894+
if (StructorType == Dtor_Deleting ||
2895+
StructorType == Dtor_VectorDeleting) {
28922896
Out << (PointersAre64Bit ? "PEAXI@Z" : "PAXI@Z");
28932897
return;
28942898
}
@@ -3861,10 +3865,10 @@ void MicrosoftMangleContextImpl::mangleCXXDtorThunk(const CXXDestructorDecl *DD,
38613865
const ThunkInfo &Thunk,
38623866
bool /*ElideOverrideInfo*/,
38633867
raw_ostream &Out) {
3864-
// FIXME: Actually, the dtor thunk should be emitted for vector deleting
3865-
// dtors rather than scalar deleting dtors. Just use the vector deleting dtor
3866-
// mangling manually until we support both deleting dtor types.
3867-
assert(Type == Dtor_Deleting);
3868+
// The dtor thunk should use vector deleting dtor mangling, however as an
3869+
// optimization we may end up emitting only scalar deleting dtor body, so just
3870+
// use the vector deleting dtor mangling manually.
3871+
assert(Type == Dtor_Deleting || Type == Dtor_VectorDeleting);
38683872
msvc_hashing_ostream MHO(Out);
38693873
MicrosoftCXXNameMangler Mangler(*this, MHO, DD, Type);
38703874
Mangler.getStream() << "??_E";

0 commit comments

Comments
 (0)