-
Notifications
You must be signed in to change notification settings - Fork 13.8k
[clang] AST Visitor: skip empty qualifiers in QualifiedTemplateName #93926
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
[clang] AST Visitor: skip empty qualifiers in QualifiedTemplateName #93926
Conversation
@llvm/pr-subscribers-clang Author: Matheus Izvekov (mizvekov) ChangesThis change was missed in #93433. Full diff: https://github.com/llvm/llvm-project/pull/93926.diff 1 Files Affected:
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h
index 4bbb4380cdd7f..28a90dffcb8dc 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -855,10 +855,13 @@ bool RecursiveASTVisitor<Derived>::TraverseDeclarationNameInfo(
template <typename Derived>
bool RecursiveASTVisitor<Derived>::TraverseTemplateName(TemplateName Template) {
- if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
+ if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
- else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
- TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
+ } else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) {
+ if (T->getQualifier()) {
+ TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
+ }
+ }
return true;
}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
dd8839b
to
db56ac3
Compare
This change was missed in llvm#93433.
db56ac3
to
55d9466
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (modulo suggestion)
} else if (QualifiedTemplateName *QTN = | ||
Template.getAsQualifiedTemplateName()) { | ||
if (QTN->getQualifier()) { | ||
TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier())); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} else if (QualifiedTemplateName *QTN = | |
Template.getAsQualifiedTemplateName()) { | |
if (QTN->getQualifier()) { | |
TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier())); | |
} | |
} | |
} else if (QualifiedTemplateName *QTN = | |
Template.getAsQualifiedTemplateName(); QTN && QTN->getQualifier()) { | |
TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier())); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that looks cleaner at first glance, but the intention in the original code was for each arm to match each kind of TemplateName
.
For example, this doesn't traverse OverloadTemplateName
right now, but if we wanted to add it after this change, this would necessitate to refactor the if branches once again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to merge since this fixes broken build bot.
Let's continue in post.
Even with this fix, I'm seeing a segfault in clang/lib/AST/QualTypeNames.cpp at line 216.
Scope is nullptr. The call is from line 70:
which means that the I have a fix in testing that adds this check, but if you would double check it after it goes in, that would be helpful. Unfortunately the failure is in an internal tool, against internal sources, which makes getting a reproducer a long process. I'm also working on that. |
Protect against nullptr after #93926
The fix gets the intended behavior right. There are |
This change was missed in #93433.
This fixes a problem detected by UBSAN build bots.