[clang] [clang] Don't emit the warn_dangling_lifetime_pointer diagnostic for the assignment case. (PR #97408)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 2 05:46:33 PDT 2024


================
@@ -1023,7 +1023,7 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
         return false;
       }
 
-      if (IsGslPtrInitWithGslTempOwner && DiagLoc.isValid()) {
+      if (InitEntity && IsGslPtrInitWithGslTempOwner && DiagLoc.isValid()) {
----------------
usx95 wrote:

I think it would be simpler to just handle `AEntity` before:
```cpp
if(AEntity) {
  assert(shouldLifetimeExtendThroughPath(Path) == PathLifetimeKind::NoExtend);
  assert(LK == LK_Extended);
  if (!pathContainsInit(path)) {
    SemaRef.Diag(DiagLoc, diag::warn_dangling_pointer_assignment)
              << AEntity->LHS << DiagRange;
  }
  return;
}
assert(InitEntity);
switch (LK) {
...
<remove assert(InitEntity*) checks>
```

https://github.com/llvm/llvm-project/pull/97408


More information about the cfe-commits mailing list