Skip to content

Commit ffca4ef

Browse files
authored
[clang] Remove a pointer union from the lifetime bound analysis (llvm#97327)
Since all callers of the API is called with the same type, we do not actually need the pointer union.
1 parent 03e4647 commit ffca4ef

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

clang/lib/Sema/CheckExprLifetime.cpp

+13-23
Original file line numberDiff line numberDiff line change
@@ -966,27 +966,11 @@ static bool pathOnlyInitializesGslPointer(IndirectLocalPath &Path) {
966966
return false;
967967
}
968968

969-
static void checkExprLifetimeImpl(
970-
Sema &SemaRef,
971-
llvm::PointerUnion<const InitializedEntity *, const AssignedEntity *>
972-
CEntity,
973-
Expr *Init) {
974-
LifetimeKind LK = LK_FullExpression;
975-
976-
const AssignedEntity *AEntity = nullptr;
977-
// Local variables for initialized entity.
978-
const InitializedEntity *InitEntity = nullptr;
979-
const InitializedEntity *ExtendingEntity = nullptr;
980-
if (CEntity.is<const InitializedEntity *>()) {
981-
InitEntity = CEntity.get<const InitializedEntity *>();
982-
auto LTResult = getEntityLifetime(InitEntity);
983-
LK = LTResult.getInt();
984-
ExtendingEntity = LTResult.getPointer();
985-
} else {
986-
AEntity = CEntity.get<const AssignedEntity *>();
987-
if (AEntity->LHS->getType()->isPointerType()) // builtin pointer type
988-
LK = LK_Extended;
989-
}
969+
static void checkExprLifetimeImpl(Sema &SemaRef,
970+
const InitializedEntity *InitEntity,
971+
const InitializedEntity *ExtendingEntity,
972+
LifetimeKind LK,
973+
const AssignedEntity *AEntity, Expr *Init) {
990974
// If this entity doesn't have an interesting lifetime, don't bother looking
991975
// for temporaries within its initializer.
992976
if (LK == LK_FullExpression)
@@ -1292,12 +1276,18 @@ static void checkExprLifetimeImpl(
12921276

12931277
void checkExprLifetime(Sema &SemaRef, const InitializedEntity &Entity,
12941278
Expr *Init) {
1295-
checkExprLifetimeImpl(SemaRef, &Entity, Init);
1279+
auto LTResult = getEntityLifetime(&Entity);
1280+
LifetimeKind LK = LTResult.getInt();
1281+
const InitializedEntity *ExtendingEntity = LTResult.getPointer();
1282+
checkExprLifetimeImpl(SemaRef, &Entity, ExtendingEntity, LK, nullptr, Init);
12961283
}
12971284

12981285
void checkExprLifetime(Sema &SemaRef, const AssignedEntity &Entity,
12991286
Expr *Init) {
1300-
checkExprLifetimeImpl(SemaRef, &Entity, Init);
1287+
LifetimeKind LK = LK_FullExpression;
1288+
if (Entity.LHS->getType()->isPointerType()) // builtin pointer type
1289+
LK = LK_Extended;
1290+
checkExprLifetimeImpl(SemaRef, nullptr, nullptr, LK, &Entity, Init);
13011291
}
13021292

13031293
} // namespace clang::sema

0 commit comments

Comments
 (0)