-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang] Add a common definition of isPointerLikeType for lifetime analysis #117315
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
Conversation
@llvm/pr-subscribers-clang Author: Utkarsh Saxena (usx95) ChangesFull diff: https://github.com/llvm/llvm-project/pull/117315.diff 1 Files Affected:
diff --git a/clang/lib/Sema/CheckExprLifetime.cpp b/clang/lib/Sema/CheckExprLifetime.cpp
index 8886e5e307ddf8..64dc4794b6235a 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -253,9 +253,12 @@ static void visitLocalsRetainedByReferenceBinding(IndirectLocalPath &Path,
LocalVisitor Visit);
template <typename T> static bool isRecordWithAttr(QualType Type) {
- if (auto *RD = Type->getAsCXXRecordDecl())
- return RD->hasAttr<T>();
- return false;
+ auto *RD = Type->getAsCXXRecordDecl();
+ if (!RD)
+ return false;
+ if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
+ RD = CTSD->getSpecializedTemplate()->getTemplatedDecl();
+ return RD->hasAttr<T>();
}
// Decl::isInStdNamespace will return false for iterators in some STL
|
clang/include/clang/Sema/Sema.h
Outdated
@@ -1763,6 +1763,18 @@ class Sema final : public SemaBase { | |||
/// Add [[gsl::Pointer]] attributes for std:: types. | |||
void inferGslPointerAttribute(TypedefNameDecl *TD); | |||
|
|||
template <typename T> static bool isRecordWithAttr(QualType Type) { |
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'd avoid expose this function if possible (as it seems only be used in CheckExprLifetime.cpp
and isPointerLikeType
). How about?
- we just keep the
isPointerLikeType
declaration in Sema.h - define
isPointerLikeType
inCheckExprLifetime.cpp
- the
isRecordWithAttr
can still be inCheckExprLifetime.cpp
.
I think it is fine as CheckExprLifetime.cpp
is a part of Sema library.
✅ With the latest revision this PR passed the C/C++ code formatter. |
clang/include/clang/Sema/Sema.h
Outdated
@@ -1763,6 +1763,8 @@ class Sema final : public SemaBase { | |||
/// Add [[gsl::Pointer]] attributes for std:: types. | |||
void inferGslPointerAttribute(TypedefNameDecl *TD); | |||
|
|||
static bool isPointerLikeType(QualType QT); |
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.
nit: please add some comments for this API. I think it is worth clarifying that it is only used for the lifetime analysis (to avoid misuse).
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.
Added comments. Also moved to CheckExprLifetime.h.
I guess that is better to avoid wrong usages.
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.
Oh, nice! Moving to checkExprLifetime.h
makes more sense.
The PR description needs to update as well. |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/171/builds/11264 Here is the relevant piece of the build log for the reference
|
Also checks for annotation for template specializations which sometimes may not have the annotation attached.