[clang] ffca4ef - [clang] Remove a pointer union from the lifetime bound analysis (#97327)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 1 15:57:04 PDT 2024
Author: Gábor Horváth
Date: 2024-07-01T23:56:59+01:00
New Revision: ffca4ef5b1a8eff6097454df4b0f212e2393e41e
URL: https://github.com/llvm/llvm-project/commit/ffca4ef5b1a8eff6097454df4b0f212e2393e41e
DIFF: https://github.com/llvm/llvm-project/commit/ffca4ef5b1a8eff6097454df4b0f212e2393e41e.diff
LOG: [clang] Remove a pointer union from the lifetime bound analysis (#97327)
Since all callers of the API is called with the same type, we do not
actually need the pointer union.
Added:
Modified:
clang/lib/Sema/CheckExprLifetime.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/CheckExprLifetime.cpp b/clang/lib/Sema/CheckExprLifetime.cpp
index be77949e8b547..fea0239f7bc36 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -966,27 +966,11 @@ static bool pathOnlyInitializesGslPointer(IndirectLocalPath &Path) {
return false;
}
-static void checkExprLifetimeImpl(
- Sema &SemaRef,
- llvm::PointerUnion<const InitializedEntity *, const AssignedEntity *>
- CEntity,
- Expr *Init) {
- LifetimeKind LK = LK_FullExpression;
-
- const AssignedEntity *AEntity = nullptr;
- // Local variables for initialized entity.
- const InitializedEntity *InitEntity = nullptr;
- const InitializedEntity *ExtendingEntity = nullptr;
- if (CEntity.is<const InitializedEntity *>()) {
- InitEntity = CEntity.get<const InitializedEntity *>();
- auto LTResult = getEntityLifetime(InitEntity);
- LK = LTResult.getInt();
- ExtendingEntity = LTResult.getPointer();
- } else {
- AEntity = CEntity.get<const AssignedEntity *>();
- if (AEntity->LHS->getType()->isPointerType()) // builtin pointer type
- LK = LK_Extended;
- }
+static void checkExprLifetimeImpl(Sema &SemaRef,
+ const InitializedEntity *InitEntity,
+ const InitializedEntity *ExtendingEntity,
+ LifetimeKind LK,
+ const AssignedEntity *AEntity, Expr *Init) {
// If this entity doesn't have an interesting lifetime, don't bother looking
// for temporaries within its initializer.
if (LK == LK_FullExpression)
@@ -1292,12 +1276,18 @@ static void checkExprLifetimeImpl(
void checkExprLifetime(Sema &SemaRef, const InitializedEntity &Entity,
Expr *Init) {
- checkExprLifetimeImpl(SemaRef, &Entity, Init);
+ auto LTResult = getEntityLifetime(&Entity);
+ LifetimeKind LK = LTResult.getInt();
+ const InitializedEntity *ExtendingEntity = LTResult.getPointer();
+ checkExprLifetimeImpl(SemaRef, &Entity, ExtendingEntity, LK, nullptr, Init);
}
void checkExprLifetime(Sema &SemaRef, const AssignedEntity &Entity,
Expr *Init) {
- checkExprLifetimeImpl(SemaRef, &Entity, Init);
+ LifetimeKind LK = LK_FullExpression;
+ if (Entity.LHS->getType()->isPointerType()) // builtin pointer type
+ LK = LK_Extended;
+ checkExprLifetimeImpl(SemaRef, nullptr, nullptr, LK, &Entity, Init);
}
} // namespace clang::sema
More information about the cfe-commits
mailing list