Skip to content

Commit 7c4daea

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:ba8565fbcb97 into amd-gfx:ee21db2b70bf
Local branch amd-gfx ee21db2 Merged main:b99f7e695469 into amd-gfx:a485974c4c95 Remote branch main ba8565f [LIT] Print discovered tests and percentages (llvm#66057)
2 parents ee21db2 + ba8565f commit 7c4daea

File tree

23 files changed

+367
-91
lines changed

23 files changed

+367
-91
lines changed

clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,15 @@ def main():
187187
"parameter is a directory, the fixes of each compilation unit are "
188188
"stored in individual yaml files in the directory.",
189189
)
190+
else:
191+
parser.add_argument(
192+
"-export-fixes",
193+
metavar="DIRECTORY",
194+
dest="export_fixes",
195+
help="A directory to store suggested fixes in, which can be applied "
196+
"with clang-apply-replacements. The fixes of each compilation unit are "
197+
"stored in individual yaml files in the directory.",
198+
)
190199
parser.add_argument(
191200
"-extra-arg",
192201
dest="extra_arg",
@@ -270,7 +279,12 @@ def main():
270279
):
271280
os.makedirs(args.export_fixes)
272281

273-
if not os.path.isdir(args.export_fixes) and yaml:
282+
if not os.path.isdir(args.export_fixes):
283+
if not yaml:
284+
raise RuntimeError(
285+
"Cannot combine fixes in one yaml file. Either install PyYAML or specify an output directory."
286+
)
287+
274288
combine_fixes = True
275289

276290
if os.path.isdir(args.export_fixes):

clang-tools-extra/clang-tidy/tool/run-clang-tidy.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,15 @@ def main():
315315
"parameter is a directory, the fixes of each compilation unit are "
316316
"stored in individual yaml files in the directory.",
317317
)
318+
else:
319+
parser.add_argument(
320+
"-export-fixes",
321+
metavar="directory",
322+
dest="export_fixes",
323+
help="A directory to store suggested fixes in, which can be applied "
324+
"with clang-apply-replacements. The fixes of each compilation unit are "
325+
"stored in individual yaml files in the directory.",
326+
)
318327
parser.add_argument(
319328
"-j",
320329
type=int,
@@ -401,7 +410,12 @@ def main():
401410
):
402411
os.makedirs(args.export_fixes)
403412

404-
if not os.path.isdir(args.export_fixes) and yaml:
413+
if not os.path.isdir(args.export_fixes):
414+
if not yaml:
415+
raise RuntimeError(
416+
"Cannot combine fixes in one yaml file. Either install PyYAML or specify an output directory."
417+
)
418+
405419
combine_fixes = True
406420

407421
if os.path.isdir(args.export_fixes):

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5224,6 +5224,33 @@ the configuration (without a prefix: ``Auto``).
52245224
void operator++ (int a); vs. void operator++(int a);
52255225
object.operator++ (10); object.operator++(10);
52265226

5227+
* ``AfterPlacementOperatorStyle AfterPlacementOperator`` :versionbadge:`clang-format 18`
5228+
5229+
Defines in which cases to put a space between ``new/delete`` operators
5230+
and opening parentheses.
5231+
5232+
Possible values:
5233+
5234+
* ``APO_Never`` (in configuration: ``Never``)
5235+
Remove space after ``new/delete`` operators and before ``(``.
5236+
5237+
.. code-block:: c++
5238+
5239+
new(buf) T;
5240+
delete(buf) T;
5241+
5242+
* ``APO_Always`` (in configuration: ``Always``)
5243+
Always add space after ``new/delete`` operators and before ``(``.
5244+
5245+
.. code-block:: c++
5246+
5247+
new (buf) T;
5248+
delete (buf) T;
5249+
5250+
* ``APO_Leave`` (in configuration: ``Leave``)
5251+
Leave placement ``new/delete`` expressions as they are.
5252+
5253+
52275254
* ``bool AfterRequiresInClause`` If ``true``, put space between requires keyword in a requires clause and
52285255
opening parentheses, if there is one.
52295256

clang/docs/tools/dump_format_style.py

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,18 @@ def __str__(self):
143143

144144

145145
class NestedField(object):
146-
def __init__(self, name, comment):
146+
def __init__(self, name, comment, version):
147147
self.name = name
148148
self.comment = comment.strip()
149+
self.version = version
149150

150151
def __str__(self):
152+
if self.version:
153+
return "\n* ``%s`` :versionbadge:`clang-format %s`\n%s" % (
154+
self.name,
155+
self.version,
156+
doxygen2rst(indent(self.comment, 2, indent_first_line=False)),
157+
)
151158
return "\n* ``%s`` %s" % (
152159
self.name,
153160
doxygen2rst(indent(self.comment, 2, indent_first_line=False)),
@@ -165,18 +172,28 @@ def __str__(self):
165172

166173

167174
class NestedEnum(object):
168-
def __init__(self, name, enumtype, comment, values):
175+
def __init__(self, name, enumtype, comment, version, values):
169176
self.name = name
170177
self.comment = comment
171178
self.values = values
172179
self.type = enumtype
180+
self.version = version
173181

174182
def __str__(self):
175-
s = "\n* ``%s %s``\n%s" % (
176-
to_yaml_type(self.type),
177-
self.name,
178-
doxygen2rst(indent(self.comment, 2)),
179-
)
183+
s = ""
184+
if self.version:
185+
s = "\n* ``%s %s`` :versionbadge:`clang-format %s`\n\n%s" % (
186+
to_yaml_type(self.type),
187+
self.name,
188+
self.version,
189+
doxygen2rst(indent(self.comment, 2)),
190+
)
191+
else:
192+
s = "\n* ``%s %s``\n%s" % (
193+
to_yaml_type(self.type),
194+
self.name,
195+
doxygen2rst(indent(self.comment, 2)),
196+
)
180197
s += indent("\nPossible values:\n\n", 2)
181198
s += indent("\n".join(map(str, self.values)), 2)
182199
return s
@@ -278,7 +295,9 @@ class State:
278295
InFieldComment,
279296
InEnum,
280297
InEnumMemberComment,
281-
) = range(8)
298+
InNestedEnum,
299+
InNestedEnumMemberComment,
300+
) = range(10)
282301

283302
state = State.BeforeStruct
284303

@@ -344,27 +363,38 @@ class State:
344363
state = State.InStruct
345364
nested_structs[nested_struct.name] = nested_struct
346365
elif state == State.InNestedFieldComment:
347-
if line.startswith("///"):
366+
if line.startswith(r"/// \version"):
367+
match = re.match(r"/// \\version\s*(?P<version>[0-9.]+)*", line)
368+
if match:
369+
version = match.group("version")
370+
elif line.startswith("///"):
348371
comment += self.__clean_comment_line(line)
372+
elif line.startswith("enum"):
373+
state = State.InNestedEnum
374+
name = re.sub(r"enum\s+(\w+)\s*(:((\s*\w+)+)\s*)?\{", "\\1", line)
375+
enum = Enum(name, comment)
349376
else:
350377
state = State.InNestedStruct
351378
field_type, field_name = re.match(
352379
r"([<>:\w(,\s)]+)\s+(\w+);", line
353380
).groups()
381+
# if not version:
382+
# self.__warning(f"missing version for {field_name}", line)
354383
if field_type in enums:
355384
nested_struct.values.append(
356385
NestedEnum(
357386
field_name,
358387
field_type,
359388
comment,
389+
version,
360390
enums[field_type].values,
361391
)
362392
)
363393
else:
364394
nested_struct.values.append(
365-
NestedField(field_type + " " + field_name, comment)
395+
NestedField(field_type + " " + field_name, comment, version)
366396
)
367-
397+
version = None
368398
elif state == State.InEnum:
369399
if line.startswith("///"):
370400
state = State.InEnumMemberComment
@@ -376,6 +406,17 @@ class State:
376406
# Enum member without documentation. Must be documented where the enum
377407
# is used.
378408
pass
409+
elif state == State.InNestedEnum:
410+
if line.startswith("///"):
411+
state = State.InNestedEnumMemberComment
412+
comment = self.__clean_comment_line(line)
413+
elif line == "};":
414+
state = State.InNestedStruct
415+
enums[enum.name] = enum
416+
else:
417+
# Enum member without documentation. Must be
418+
# documented where the enum is used.
419+
pass
379420
elif state == State.InEnumMemberComment:
380421
if line.startswith("///"):
381422
comment += self.__clean_comment_line(line)
@@ -389,6 +430,19 @@ class State:
389430
else:
390431
config = val
391432
enum.values.append(EnumValue(val, comment, config))
433+
elif state == State.InNestedEnumMemberComment:
434+
if line.startswith("///"):
435+
comment += self.__clean_comment_line(line)
436+
else:
437+
state = State.InNestedEnum
438+
val = line.replace(",", "")
439+
pos = val.find(" // ")
440+
if pos != -1:
441+
config = val[pos + 4 :]
442+
val = val[:pos]
443+
else:
444+
config = val
445+
enum.values.append(EnumValue(val, comment, config))
392446
if state != State.Finished:
393447
raise Exception("Not finished by the end of file")
394448

clang/include/clang/Format/Format.h

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4128,6 +4128,28 @@ struct FormatStyle {
41284128
/// object.operator++ (10); object.operator++(10);
41294129
/// \endcode
41304130
bool AfterOverloadedOperator;
4131+
/// Styles for adding spacing between ``new/delete`` operators and opening
4132+
/// parentheses.
4133+
enum AfterPlacementOperatorStyle : int8_t {
4134+
/// Remove space after ``new/delete`` operators and before ``(``.
4135+
/// \code
4136+
/// new(buf) T;
4137+
/// delete(buf) T;
4138+
/// \endcode
4139+
APO_Never,
4140+
/// Always add space after ``new/delete`` operators and before ``(``.
4141+
/// \code
4142+
/// new (buf) T;
4143+
/// delete (buf) T;
4144+
/// \endcode
4145+
APO_Always,
4146+
/// Leave placement ``new/delete`` expressions as they are.
4147+
APO_Leave,
4148+
};
4149+
/// Defines in which cases to put a space between ``new/delete`` operators
4150+
/// and opening parentheses.
4151+
/// \version 18
4152+
AfterPlacementOperatorStyle AfterPlacementOperator;
41314153
/// If ``true``, put space between requires keyword in a requires clause and
41324154
/// opening parentheses, if there is one.
41334155
/// \code
@@ -4160,8 +4182,9 @@ struct FormatStyle {
41604182
: AfterControlStatements(false), AfterForeachMacros(false),
41614183
AfterFunctionDeclarationName(false),
41624184
AfterFunctionDefinitionName(false), AfterIfMacros(false),
4163-
AfterOverloadedOperator(false), AfterRequiresInClause(false),
4164-
AfterRequiresInExpression(false), BeforeNonEmptyParentheses(false) {}
4185+
AfterOverloadedOperator(false), AfterPlacementOperator(APO_Leave),
4186+
AfterRequiresInClause(false), AfterRequiresInExpression(false),
4187+
BeforeNonEmptyParentheses(false) {}
41654188

41664189
bool operator==(const SpaceBeforeParensCustom &Other) const {
41674190
return AfterControlStatements == Other.AfterControlStatements &&
@@ -4171,6 +4194,7 @@ struct FormatStyle {
41714194
AfterFunctionDefinitionName == Other.AfterFunctionDefinitionName &&
41724195
AfterIfMacros == Other.AfterIfMacros &&
41734196
AfterOverloadedOperator == Other.AfterOverloadedOperator &&
4197+
AfterPlacementOperator == Other.AfterPlacementOperator &&
41744198
AfterRequiresInClause == Other.AfterRequiresInClause &&
41754199
AfterRequiresInExpression == Other.AfterRequiresInExpression &&
41764200
BeforeNonEmptyParentheses == Other.BeforeNonEmptyParentheses;

clang/lib/Format/Format.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,22 @@ struct ScalarEnumerationTraits<FormatStyle::QualifierAlignmentStyle> {
504504
}
505505
};
506506

507+
template <>
508+
struct MappingTraits<
509+
FormatStyle::SpaceBeforeParensCustom::AfterPlacementOperatorStyle> {
510+
static void
511+
mapping(IO &IO,
512+
FormatStyle::SpaceBeforeParensCustom::AfterPlacementOperatorStyle
513+
&Value) {
514+
IO.enumCase(Value, "Always",
515+
FormatStyle::SpaceBeforeParensCustom::APO_Always);
516+
IO.enumCase(Value, "Never",
517+
FormatStyle::SpaceBeforeParensCustom::APO_Never);
518+
IO.enumCase(Value, "Leave",
519+
FormatStyle::SpaceBeforeParensCustom::APO_Leave);
520+
}
521+
};
522+
507523
template <> struct MappingTraits<FormatStyle::RawStringFormat> {
508524
static void mapping(IO &IO, FormatStyle::RawStringFormat &Format) {
509525
IO.mapOptional("Language", Format.Language);
@@ -679,6 +695,7 @@ template <> struct MappingTraits<FormatStyle::SpaceBeforeParensCustom> {
679695
Spacing.AfterFunctionDeclarationName);
680696
IO.mapOptional("AfterIfMacros", Spacing.AfterIfMacros);
681697
IO.mapOptional("AfterOverloadedOperator", Spacing.AfterOverloadedOperator);
698+
IO.mapOptional("AfterPlacementOperator", Spacing.AfterPlacementOperator);
682699
IO.mapOptional("AfterRequiresInClause", Spacing.AfterRequiresInClause);
683700
IO.mapOptional("AfterRequiresInExpression",
684701
Spacing.AfterRequiresInExpression);
@@ -1369,6 +1386,8 @@ static void expandPresetsSpaceBeforeParens(FormatStyle &Expanded) {
13691386

13701387
switch (Expanded.SpaceBeforeParens) {
13711388
case FormatStyle::SBPO_Never:
1389+
Expanded.SpaceBeforeParensOptions.AfterPlacementOperator =
1390+
FormatStyle::SpaceBeforeParensCustom::APO_Never;
13721391
break;
13731392
case FormatStyle::SBPO_ControlStatements:
13741393
Expanded.SpaceBeforeParensOptions.AfterControlStatements = true;

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4234,6 +4234,19 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
42344234
return Style.SpaceBeforeParensOptions.AfterIfMacros ||
42354235
spaceRequiredBeforeParens(Right);
42364236
}
4237+
if (Style.SpaceBeforeParens == FormatStyle::SBPO_Custom &&
4238+
Left.isOneOf(tok::kw_new, tok::kw_delete) &&
4239+
Right.isNot(TT_OverloadedOperatorLParen) &&
4240+
!(Line.MightBeFunctionDecl && Left.is(TT_FunctionDeclarationName))) {
4241+
if (Style.SpaceBeforeParensOptions.AfterPlacementOperator ==
4242+
FormatStyle::SpaceBeforeParensCustom::APO_Always ||
4243+
(Style.SpaceBeforeParensOptions.AfterPlacementOperator ==
4244+
FormatStyle::SpaceBeforeParensCustom::APO_Leave &&
4245+
Right.hasWhitespaceBefore())) {
4246+
return true;
4247+
}
4248+
return false;
4249+
}
42374250
if (Line.Type == LT_ObjCDecl)
42384251
return true;
42394252
if (Left.is(tok::semi))

clang/unittests/Format/ConfigParseTest.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,24 @@ TEST(ConfigParseTest, ParsesConfiguration) {
591591
SpaceBeforeParens,
592592
FormatStyle::SBPO_ControlStatementsExceptControlMacros);
593593

594+
Style.SpaceBeforeParens = FormatStyle::SBPO_Custom;
595+
Style.SpaceBeforeParensOptions.AfterPlacementOperator =
596+
FormatStyle::SpaceBeforeParensCustom::APO_Always;
597+
CHECK_PARSE("SpaceBeforeParensOptions:\n"
598+
" AfterPlacementOperator: Never",
599+
SpaceBeforeParensOptions.AfterPlacementOperator,
600+
FormatStyle::SpaceBeforeParensCustom::APO_Never);
601+
602+
CHECK_PARSE("SpaceBeforeParensOptions:\n"
603+
" AfterPlacementOperator: Always",
604+
SpaceBeforeParensOptions.AfterPlacementOperator,
605+
FormatStyle::SpaceBeforeParensCustom::APO_Always);
606+
607+
CHECK_PARSE("SpaceBeforeParensOptions:\n"
608+
" AfterPlacementOperator: Leave",
609+
SpaceBeforeParensOptions.AfterPlacementOperator,
610+
FormatStyle::SpaceBeforeParensCustom::APO_Leave);
611+
594612
// For backward compatibility:
595613
Style.SpacesInParens = FormatStyle::SIPO_Never;
596614
Style.SpacesInParensOptions = {};

0 commit comments

Comments
 (0)