Skip to content

Commit a2f478b

Browse files
committed
QDoc: Adapt clang/AST/QualTypeNames.h to upstream changes
For compatibility reasons, QDoc carries a custom implementation of `llvm-project.git/clang/lib/AST/QualTypeNames.cpp`. When QDoc is built against Clang libraries from LLVM 19, a segmentation fault occurs when generating the documentation for the Qt 3D module as part of a qt5.git super-module documentation build. The segmentation fault is the result of a `nullptr` being passed to `clang::TypeName::getFullyQualifiedNestedNameSpecifier` for the `Scope` parameter. Upon investigation, it became clear that two changes have been made upstream to the implementation QDoc carries a customized version of, one of which adds a `nullptr` check. Due to the small footprint of both changes, this patch applies both of them to QDoc's `clang/AST/QualTypeNames.h`: - The upstream change 16832eb58563f77d917198ad9f86db1c2ee162c9 adds a `nullptr` check, see llvm/llvm-project#94084 for details. - The upstream change 35bfbb3b21e9874d03b730e8ce4eb98b1dcd2d28 replaces `dyn_cast_or_null<T>(foo)` with `dyn_cast<T>(foo)` for never-null arguments. See llvm/llvm-project@35bfbb3 for details. The changes apply also when QDoc is built against Clang libraries from LLVM 17 and 18, with both end-to-end tests passing. Given the nature of the changes, this means these adaptations do not require being wrapped in `#if LIBCLANG_VERSION_MAJOR` checks. Fixes: QTBUG-128926 Pick-to: 6.8 Change-Id: I5863ca213a35042ed325971b42de2bc1e86c6457 Reviewed-by: Luca Di Sera <[email protected]> Reviewed-by: Topi Reiniö <[email protected]>
1 parent 1083d1d commit a2f478b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/qdoc/qdoc/src/qdoc/clang/AST/QualTypeNames.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ static inline bool getFullyQualifiedTemplateName(const ASTContext &Ctx,
8484
assert(ArgTDecl != nullptr);
8585
QualifiedTemplateName *QTName = TName.getAsQualifiedTemplateName();
8686

87-
if (QTName && !QTName->hasTemplateKeyword()) {
88-
NNS = QTName->getQualifier();
87+
if (QTName &&
88+
!QTName->hasTemplateKeyword() &&
89+
(NNS = QTName->getQualifier())) {
8990
NestedNameSpecifier *QNNS = getFullyQualifiedNestedNameSpecifier(
9091
Ctx, NNS, WithGlobalNsPrefix);
9192
if (QNNS != NNS) {
@@ -288,8 +289,8 @@ static inline NestedNameSpecifier *createNestedNameSpecifierForScopeOf(
288289
assert(Decl);
289290

290291
const DeclContext *DC = Decl->getDeclContext()->getRedeclContext();
291-
const auto *Outer = dyn_cast_or_null<NamedDecl>(DC);
292-
const auto *OuterNS = dyn_cast_or_null<NamespaceDecl>(DC);
292+
const auto *Outer = dyn_cast<NamedDecl>(DC);
293+
const auto *OuterNS = dyn_cast<NamespaceDecl>(DC);
293294
if (Outer && !(OuterNS && OuterNS->isAnonymousNamespace())) {
294295
if (OuterNS) {
295296
return createNestedNameSpecifier(Ctx, OuterNS, WithGlobalNsPrefix);

0 commit comments

Comments
 (0)