-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Guard against nullptr #94084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Sterling-Augustine
merged 1 commit into
llvm:main
from
Sterling-Augustine:segfault_qualtype_name
Jun 1, 2024
Merged
Guard against nullptr #94084
Sterling-Augustine
merged 1 commit into
llvm:main
from
Sterling-Augustine:segfault_qualtype_name
Jun 1, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-clang Author: None (Sterling-Augustine) ChangesFull diff: https://github.com/llvm/llvm-project/pull/94084.diff 1 Files Affected:
diff --git a/clang/lib/AST/QualTypeNames.cpp b/clang/lib/AST/QualTypeNames.cpp
index 066377423df76..18ac4b1eb57e7 100644
--- a/clang/lib/AST/QualTypeNames.cpp
+++ b/clang/lib/AST/QualTypeNames.cpp
@@ -65,8 +65,9 @@ static bool getFullyQualifiedTemplateName(const ASTContext &Ctx,
assert(ArgTDecl != nullptr);
QualifiedTemplateName *QTName = TName.getAsQualifiedTemplateName();
- if (QTName && !QTName->hasTemplateKeyword()) {
- NNS = QTName->getQualifier();
+ if (QTName &&
+ !QTName->hasTemplateKeyword() &&
+ (NNS = QTName->getQualifier())) {
NestedNameSpecifier *QNNS = getFullyQualifiedNestedNameSpecifier(
Ctx, NNS, WithGlobalNsPrefix);
if (QNNS != NNS) {
|
You can test this locally with the following command:git-clang-format --diff bba5ee47e63298d61f6ea441a140144ce370ba92 169e09f2aa403676873a440d8496356cefe69b9e -- clang/lib/AST/QualTypeNames.cpp View the diff from clang-format here.diff --git a/clang/lib/AST/QualTypeNames.cpp b/clang/lib/AST/QualTypeNames.cpp
index 18ac4b1eb5..737092b156 100644
--- a/clang/lib/AST/QualTypeNames.cpp
+++ b/clang/lib/AST/QualTypeNames.cpp
@@ -65,8 +65,7 @@ static bool getFullyQualifiedTemplateName(const ASTContext &Ctx,
assert(ArgTDecl != nullptr);
QualifiedTemplateName *QTName = TName.getAsQualifiedTemplateName();
- if (QTName &&
- !QTName->hasTemplateKeyword() &&
+ if (QTName && !QTName->hasTemplateKeyword() &&
(NNS = QTName->getQualifier())) {
NestedNameSpecifier *QNNS = getFullyQualifiedNestedNameSpecifier(
Ctx, NNS, WithGlobalNsPrefix);
|
qtprojectorg
pushed a commit
to qt/qttools
that referenced
this pull request
Sep 17, 2024
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. 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 Change-Id: I5863ca213a35042ed325971b42de2bc1e86c6457 Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
qtprojectorg
pushed a commit
to qt/qttools
that referenced
this pull request
Sep 18, 2024
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 <luca.disera@qt.io> Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
qtprojectorg
pushed a commit
to qt/qttools
that referenced
this pull request
Sep 18, 2024
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 Change-Id: I5863ca213a35042ed325971b42de2bc1e86c6457 Reviewed-by: Luca Di Sera <luca.disera@qt.io> Reviewed-by: Topi Reiniö <topi.reinio@qt.io> (cherry picked from commit a2f478b) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Protect against nullptr after #93926