Skip to content

Commit a456d22

Browse files
committed
rebase
Created using spr 1.3.4
2 parents ca7816a + 9c2de99 commit a456d22

File tree

96 files changed

+3042
-561
lines changed

Some content is hidden

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

96 files changed

+3042
-561
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static bool maxCondition(const BinaryOperator::Opcode Op, const Expr *CondLhs,
5959
return false;
6060
}
6161

62-
QualType getNonTemplateAlias(QualType QT) {
62+
static QualType getNonTemplateAlias(QualType QT) {
6363
while (true) {
6464
// cast to a TypedefType
6565
if (const TypedefType *TT = dyn_cast<TypedefType>(QT)) {
@@ -92,15 +92,15 @@ static std::string createReplacement(const Expr *CondLhs, const Expr *CondRhs,
9292
const llvm::StringRef AssignLhsStr = Lexer::getSourceText(
9393
Source.getExpansionRange(AssignLhs->getSourceRange()), Source, LO);
9494

95-
clang::QualType GlobalImplicitCastType;
96-
clang::QualType LhsType = CondLhs->getType()
97-
.getCanonicalType()
98-
.getNonReferenceType()
99-
.getUnqualifiedType();
100-
clang::QualType RhsType = CondRhs->getType()
101-
.getCanonicalType()
102-
.getNonReferenceType()
103-
.getUnqualifiedType();
95+
QualType GlobalImplicitCastType;
96+
QualType LhsType = CondLhs->getType()
97+
.getCanonicalType()
98+
.getNonReferenceType()
99+
.getUnqualifiedType();
100+
QualType RhsType = CondRhs->getType()
101+
.getCanonicalType()
102+
.getNonReferenceType()
103+
.getUnqualifiedType();
104104
if (LhsType != RhsType) {
105105
GlobalImplicitCastType = getNonTemplateAlias(BO->getLHS()->getType());
106106
}

clang/bindings/python/clang/cindex.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,6 +1770,16 @@ def spelling(self):
17701770

17711771
return self._spelling
17721772

1773+
def pretty_printed(self, policy):
1774+
"""
1775+
Pretty print declarations.
1776+
Parameters:
1777+
policy -- The policy to control the entities being printed.
1778+
"""
1779+
return _CXString.from_result(
1780+
conf.lib.clang_getCursorPrettyPrinted(self, policy)
1781+
)
1782+
17731783
@property
17741784
def displayname(self):
17751785
"""
@@ -3699,6 +3709,72 @@ def write_main_file_to_stdout(self):
36993709
conf.lib.clang_CXRewriter_writeMainFileToStdOut(self)
37003710

37013711

3712+
class PrintingPolicyProperty(BaseEnumeration):
3713+
3714+
"""
3715+
A PrintingPolicyProperty identifies a property of a PrintingPolicy.
3716+
"""
3717+
3718+
Indentation = 0
3719+
SuppressSpecifiers = 1
3720+
SuppressTagKeyword = 2
3721+
IncludeTagDefinition = 3
3722+
SuppressScope = 4
3723+
SuppressUnwrittenScope = 5
3724+
SuppressInitializers = 6
3725+
ConstantArraySizeAsWritten = 7
3726+
AnonymousTagLocations = 8
3727+
SuppressStrongLifetime = 9
3728+
SuppressLifetimeQualifiers = 10
3729+
SuppressTemplateArgsInCXXConstructors = 11
3730+
Bool = 12
3731+
Restrict = 13
3732+
Alignof = 14
3733+
UnderscoreAlignof = 15
3734+
UseVoidForZeroParams = 16
3735+
TerseOutput = 17
3736+
PolishForDeclaration = 18
3737+
Half = 19
3738+
MSWChar = 20
3739+
IncludeNewlines = 21
3740+
MSVCFormatting = 22
3741+
ConstantsAsWritten = 23
3742+
SuppressImplicitBase = 24
3743+
FullyQualifiedName = 25
3744+
3745+
3746+
class PrintingPolicy(ClangObject):
3747+
"""
3748+
The PrintingPolicy is a wrapper class around clang::PrintingPolicy
3749+
3750+
It allows specifying how declarations, expressions, and types should be
3751+
pretty-printed.
3752+
"""
3753+
3754+
@staticmethod
3755+
def create(cursor):
3756+
"""
3757+
Creates a new PrintingPolicy
3758+
Parameters:
3759+
cursor -- Any cursor for a translation unit.
3760+
"""
3761+
return PrintingPolicy(conf.lib.clang_getCursorPrintingPolicy(cursor))
3762+
3763+
def __init__(self, ptr):
3764+
ClangObject.__init__(self, ptr)
3765+
3766+
def __del__(self):
3767+
conf.lib.clang_PrintingPolicy_dispose(self)
3768+
3769+
def get_property(self, property):
3770+
"""Get a property value for the given printing policy."""
3771+
return conf.lib.clang_PrintingPolicy_getProperty(self, property.value)
3772+
3773+
def set_property(self, property, value):
3774+
"""Set a property value for the given printing policy."""
3775+
conf.lib.clang_PrintingPolicy_setProperty(self, property.value, value)
3776+
3777+
37023778
# Now comes the plumbing to hook up the C library.
37033779

37043780
# Register callback types
@@ -3801,6 +3877,8 @@ def write_main_file_to_stdout(self):
38013877
("clang_getCursorExtent", [Cursor], SourceRange),
38023878
("clang_getCursorLexicalParent", [Cursor], Cursor),
38033879
("clang_getCursorLocation", [Cursor], SourceLocation),
3880+
("clang_getCursorPrettyPrinted", [Cursor, PrintingPolicy], _CXString),
3881+
("clang_getCursorPrintingPolicy", [Cursor], c_object_p),
38043882
("clang_getCursorReferenced", [Cursor], Cursor),
38053883
("clang_getCursorReferenceNameRange", [Cursor, c_uint, c_uint], SourceRange),
38063884
("clang_getCursorResultType", [Cursor], Type),
@@ -3924,6 +4002,9 @@ def write_main_file_to_stdout(self):
39244002
("clang_Cursor_isAnonymousRecordDecl", [Cursor], bool),
39254003
("clang_Cursor_isBitField", [Cursor], bool),
39264004
("clang_Location_isInSystemHeader", [SourceLocation], bool),
4005+
("clang_PrintingPolicy_dispose", [PrintingPolicy]),
4006+
("clang_PrintingPolicy_getProperty", [PrintingPolicy, c_int], c_uint),
4007+
("clang_PrintingPolicy_setProperty", [PrintingPolicy, c_int, c_uint]),
39274008
("clang_Type_getAlignOf", [Type], c_longlong),
39284009
("clang_Type_getClassType", [Type], Type),
39294010
("clang_Type_getNumTemplateArguments", [Type], c_int),
@@ -4104,6 +4185,8 @@ def function_exists(self, name: str) -> bool:
41044185
"FixIt",
41054186
"Index",
41064187
"LinkageKind",
4188+
"PrintingPolicy",
4189+
"PrintingPolicyProperty",
41074190
"RefQualifierKind",
41084191
"SourceLocation",
41094192
"SourceRange",

clang/bindings/python/tests/cindex/test_cursor.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
BinaryOperator,
66
Config,
77
CursorKind,
8+
PrintingPolicy,
9+
PrintingPolicyProperty,
810
StorageClass,
911
TemplateArgumentKind,
1012
TranslationUnit,
@@ -981,3 +983,15 @@ def test_from_result_null(self):
981983
def test_from_cursor_result_null(self):
982984
tu = get_tu("")
983985
self.assertEqual(tu.cursor.semantic_parent, None)
986+
987+
def test_pretty_print(self):
988+
tu = get_tu("struct X { int x; }; void f(bool x) { }", lang="cpp")
989+
f = get_cursor(tu, "f")
990+
991+
self.assertEqual(f.displayname, "f(bool)")
992+
pp = PrintingPolicy.create(f)
993+
self.assertEqual(pp.get_property(PrintingPolicyProperty.Bool), True)
994+
self.assertEqual(f.pretty_printed(pp), "void f(bool x) {\n}\n")
995+
pp.set_property(PrintingPolicyProperty.Bool, False)
996+
self.assertEqual(pp.get_property(PrintingPolicyProperty.Bool), False)
997+
self.assertEqual(f.pretty_printed(pp), "void f(_Bool x) {\n}\n")

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3441,7 +3441,7 @@ the configuration (without a prefix: ``Auto``).
34413441
.. _BreakBinaryOperations:
34423442

34433443
**BreakBinaryOperations** (``BreakBinaryOperationsStyle``) :versionbadge:`clang-format 20` :ref:`<BreakBinaryOperations>`
3444-
The break constructor initializers style to use.
3444+
The break binary operations style to use.
34453445

34463446
Possible values:
34473447

@@ -3764,6 +3764,7 @@ the configuration (without a prefix: ``Auto``).
37643764
lists.
37653765

37663766
Important differences:
3767+
37673768
* No spaces inside the braced list.
37683769
* No line break before the closing brace.
37693770
* Indentation with the continuation indent, not with the block indent.

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,8 @@ Sanitizers
12981298
Python Binding Changes
12991299
----------------------
13001300
- Fixed an issue that led to crashes when calling ``Type.get_exception_specification_kind``.
1301+
- Added bindings for ``clang_getCursorPrettyPrinted`` and related functions,
1302+
which allow changing the formatting of pretty-printed code.
13011303
- Added binding for ``clang_Cursor_isAnonymousRecordDecl``, which allows checking if
13021304
a declaration is an anonymous union or anonymous struct.
13031305

clang/include/clang/AST/ASTContext.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3360,6 +3360,16 @@ class ASTContext : public RefCountedBase<ASTContext> {
33603360
/// this function.
33613361
void registerSYCLEntryPointFunction(FunctionDecl *FD);
33623362

3363+
/// Given a type used as a SYCL kernel name, returns a reference to the
3364+
/// metadata generated from the corresponding SYCL kernel entry point.
3365+
/// Aborts if the provided type is not a registered SYCL kernel name.
3366+
const SYCLKernelInfo &getSYCLKernelInfo(QualType T) const;
3367+
3368+
/// Returns a pointer to the metadata generated from the corresponding
3369+
/// SYCLkernel entry point if the provided type corresponds to a registered
3370+
/// SYCL kernel name. Returns a null pointer otherwise.
3371+
const SYCLKernelInfo *findSYCLKernelInfo(QualType T) const;
3372+
33633373
//===--------------------------------------------------------------------===//
33643374
// Statistics
33653375
//===--------------------------------------------------------------------===//

clang/include/clang/Basic/Attr.td

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,11 +1516,22 @@ def SYCLKernel : InheritableAttr {
15161516

15171517
def SYCLKernelEntryPoint : InheritableAttr {
15181518
let Spellings = [Clang<"sycl_kernel_entry_point">];
1519-
let Args = [TypeArgument<"KernelName">];
1519+
let Args = [
1520+
// KernelName is required and specifies the kernel name type.
1521+
TypeArgument<"KernelName">,
1522+
// InvalidAttr is a fake argument used to track whether the
1523+
// semantic requirements of the attribute have been satisified.
1524+
// A fake argument is used to enable serialization support.
1525+
DefaultBoolArgument<"Invalid", /*default=*/0, /*fake=*/1>
1526+
];
15201527
let Subjects = SubjectList<[Function], ErrorDiag>;
15211528
let TemplateDependent = 1;
15221529
let LangOpts = [SYCLHost, SYCLDevice];
15231530
let Documentation = [SYCLKernelEntryPointDocs];
1531+
let AdditionalMembers = [{
1532+
void setInvalidAttr() { invalid = true; }
1533+
bool isInvalidAttr() const { return invalid; }
1534+
}];
15241535
}
15251536

15261537
def SYCLSpecialClass: InheritableAttr {

clang/include/clang/Basic/AttrDocs.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ not first appear on a declaration that follows a definition of the function.
475475
The attribute only appertains to functions and only those that meet the
476476
following requirements.
477477

478-
* Has a ``void`` return type.
478+
* Has a non-deduced ``void`` return type.
479479
* Is not a non-static member function, constructor, or destructor.
480480
* Is not a C variadic function.
481481
* Is not a coroutine.

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ def PoundPragmaMessage : DiagGroup<"#pragma-messages">,
648648
def : DiagGroup<"redundant-decls">;
649649
def RedeclaredClassMember : DiagGroup<"redeclared-class-member">;
650650
def GNURedeclaredEnum : DiagGroup<"gnu-redeclared-enum">;
651+
def RedundantAttribute : DiagGroup<"redundant-attribute">;
651652
def RedundantMove : DiagGroup<"redundant-move">;
652653
def Register : DiagGroup<"register", [DeprecatedRegister]>;
653654
def ReturnTypeCLinkage : DiagGroup<"return-type-c-linkage">;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12429,6 +12429,33 @@ def err_sycl_special_type_num_init_method : Error<
1242912429
"types with 'sycl_special_class' attribute must have one and only one '__init' "
1243012430
"method defined">;
1243112431

12432+
// SYCL kernel entry point diagnostics
12433+
def err_sycl_entry_point_invalid : Error<
12434+
"'sycl_kernel_entry_point' attribute cannot be applied to a"
12435+
" %select{non-static member function|variadic function|deleted function|"
12436+
"defaulted function|constexpr function|consteval function|"
12437+
"function declared with the 'noreturn' attribute|coroutine}0">;
12438+
def err_sycl_entry_point_invalid_redeclaration : Error<
12439+
"'sycl_kernel_entry_point' kernel name argument does not match prior"
12440+
" declaration%diff{: $ vs $|}0,1">;
12441+
def err_sycl_kernel_name_conflict : Error<
12442+
"'sycl_kernel_entry_point' kernel name argument conflicts with a previous"
12443+
" declaration">;
12444+
def warn_sycl_kernel_name_not_a_class_type : Warning<
12445+
"%0 is not a valid SYCL kernel name type; a non-union class type is required">,
12446+
InGroup<DiagGroup<"nonportable-sycl">>, DefaultError;
12447+
def warn_sycl_entry_point_redundant_declaration : Warning<
12448+
"redundant 'sycl_kernel_entry_point' attribute">, InGroup<RedundantAttribute>;
12449+
def err_sycl_entry_point_after_definition : Error<
12450+
"'sycl_kernel_entry_point' attribute cannot be added to a function after the"
12451+
" function is defined">;
12452+
def err_sycl_entry_point_return_type : Error<
12453+
"'sycl_kernel_entry_point' attribute only applies to functions with a"
12454+
" 'void' return type">;
12455+
def err_sycl_entry_point_deduced_return_type : Error<
12456+
"'sycl_kernel_entry_point' attribute only applies to functions with a"
12457+
" non-deduced 'void' return type">;
12458+
1243212459
def warn_cuda_maxclusterrank_sm_90 : Warning<
1243312460
"maxclusterrank requires sm_90 or higher, CUDA arch provided: %0, ignoring "
1243412461
"%1 attribute">, InGroup<IgnoredAttributes>;

0 commit comments

Comments
 (0)