linuxPackages_latest.broadcom_sta: add patch to compile on Kernel 6.12 (#359484)
[NixPkgs.git] / pkgs / development / python-modules / pyside2 / shiboken2-clang-Fix-build-with-clang-16.patch
blobb07cc33526f7667a84eaa3e3be10e6d5f2e342c5
1 From: Friedemann Kleint <Friedemann.Kleint@qt.io>
2 Date: Tue, 25 Apr 2023 14:01:45 +0200
3 Subject: shiboken2/clang: Fix build with clang 16
5 clang 16 returns more elaborated types instead of fully qualified type
6 names. Qualify elaborated types when retrieving the type name.
8 [ChangeLog][shiboken6] Support for libclang version 16 has been added.
10 Task-number: PYSIDE-2288
11 Pick-to: 6.5 5.15
12 Change-Id: Ibd428280180967f11d82a72159e744c016afc927
13 Reviewed-by: Christian Tismer <tismer@stackless.com>
14 (cherry picked from commit 44ef1859214c66861a251d4a0faf5c38dc050850)
15 ---
16 .../ApiExtractor/clangparser/clangbuilder.cpp | 2 +-
17 .../ApiExtractor/clangparser/clangutils.cpp | 23 ++++++++++++++++++++++
18 .../ApiExtractor/clangparser/clangutils.h | 1 +
19 .../shiboken2/ApiExtractor/tests/testtemplates.cpp | 3 +--
20 4 files changed, 26 insertions(+), 3 deletions(-)
22 diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
23 index 332f1da..ed1e15d 100644
24 --- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
25 +++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
26 @@ -524,7 +524,7 @@ TypeInfo BuilderPrivate::createTypeInfoHelper(const CXType &type) const
27 typeInfo.setConstant(clang_isConstQualifiedType(nestedType) != 0);
28 typeInfo.setVolatile(clang_isVolatileQualifiedType(nestedType) != 0);
30 - QString typeName = getTypeName(nestedType);
31 + QString typeName = getResolvedTypeName(nestedType);
32 while (TypeInfo::stripLeadingConst(&typeName)
33 || TypeInfo::stripLeadingVolatile(&typeName)) {
35 diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp
36 index 57271ef..295ede3 100644
37 --- a/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp
38 +++ b/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp
39 @@ -130,6 +130,23 @@ QString getCursorDisplayName(const CXCursor &cursor)
40 return result;
43 +static inline bool isBuiltinType(CXTypeKind kind)
45 + return kind >= CXType_FirstBuiltin && kind <= CXType_LastBuiltin;
48 +// Resolve elaborated types occurring with clang 16
49 +static CXType resolveType(const CXType &type)
51 + if (!isBuiltinType(type.kind)) {
52 + CXCursor decl = clang_getTypeDeclaration(type);
53 + auto resolvedType = clang_getCursorType(decl);
54 + if (resolvedType.kind != CXType_Invalid && resolvedType.kind != type.kind)
55 + return resolvedType;
56 + }
57 + return type;
60 QString getTypeName(const CXType &type)
62 CXString typeSpelling = clang_getTypeSpelling(type);
63 @@ -138,6 +155,12 @@ QString getTypeName(const CXType &type)
64 return result;
67 +// Resolve elaborated types occurring with clang 16
68 +QString getResolvedTypeName(const CXType &type)
70 + return getTypeName(resolveType(type));
73 Diagnostic::Diagnostic(const QString &m, const CXCursor &c, CXDiagnosticSeverity s)
74 : message(m), source(Other), severity(s)
76 diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangutils.h b/sources/shiboken2/ApiExtractor/clangparser/clangutils.h
77 index f7c230a..aacaf63 100644
78 --- a/sources/shiboken2/ApiExtractor/clangparser/clangutils.h
79 +++ b/sources/shiboken2/ApiExtractor/clangparser/clangutils.h
80 @@ -52,6 +52,7 @@ QString getCursorKindName(CXCursorKind cursorKind);
81 QString getCursorSpelling(const CXCursor &cursor);
82 QString getCursorDisplayName(const CXCursor &cursor);
83 QString getTypeName(const CXType &type);
84 +QString getResolvedTypeName(const CXType &type);
85 inline QString getCursorTypeName(const CXCursor &cursor)
86 { return getTypeName(clang_getCursorType(cursor)); }
87 inline QString getCursorResultTypeName(const CXCursor &cursor)
88 diff --git a/sources/shiboken2/ApiExtractor/tests/testtemplates.cpp b/sources/shiboken2/ApiExtractor/tests/testtemplates.cpp
89 index 9f929c4..fbc5c4c 100644
90 --- a/sources/shiboken2/ApiExtractor/tests/testtemplates.cpp
91 +++ b/sources/shiboken2/ApiExtractor/tests/testtemplates.cpp
92 @@ -236,7 +236,6 @@ struct List {
93 const AbstractMetaFunction *erase = list->findFunction(QStringLiteral("erase"));
94 QVERIFY(erase);
95 QCOMPARE(erase->arguments().size(), 1);
96 - QEXPECT_FAIL("", "Clang: Some other code changes the parameter type", Abort);
97 QCOMPARE(erase->arguments().at(0)->type()->cppSignature(), QLatin1String("List::Iterator"));
100 @@ -389,7 +388,7 @@ typedef BaseTemplateClass<TypeOne> TypeOneClass;
101 const ComplexTypeEntry* oneType = one->typeEntry();
102 const ComplexTypeEntry* baseType = base->typeEntry();
103 QCOMPARE(oneType->baseContainerType(), baseType);
104 - QCOMPARE(one->baseClassNames(), QStringList(QLatin1String("BaseTemplateClass<TypeOne>")));
105 + QCOMPARE(one->baseClassNames(), QStringList(QLatin1String("NSpace::BaseTemplateClass<NSpace::TypeOne>")));
107 QVERIFY(one->hasTemplateBaseClassInstantiations());
108 AbstractMetaTypeList instantiations = one->templateBaseClassInstantiations();