Issue 162862
Summary Detect expiry of loans to trivially destructed types
Labels clang:temporal-safety
Assignees
Reporter usx95
    ```cpp
#include <string_view>

class S {
    std::string_view a, b;
};

void foo() {
 S* ptr;
    {
        S s;
        ptr = &s;
    }
 (void)ptr;
}
```
We do not have destructor calls and therefore no expiry facts for the loans created.

CFG and LifetimeFacts
```
[B2 (ENTRY)]
 Succs (1): B1
 [B1]
   1: S *ptr;
   2:  (CXXConstructExpr, S)
   3: S s;
   4: s
   5: &[B1.4]
   6: ptr
   7: [B1.6] = [B1.5]
   8: ptr
 9: (void)[B1.8] (CStyleCastExpr, ToVoid, void)
   Preds (1): B2
   Succs (1): B0
 [B0 (EXIT)]
   Preds (1): B1

==========================================
       Lifetime Analysis Facts:
==========================================
Function: foo
  Block B2:
  End of Block
  Block B1:
    Issue (0 (Path: s), ToOrigin: 0 (Expr: DeclRefExpr))
    OriginFlow (Dest: 1 (Expr: UnaryOperator), Src: 0 (Expr: DeclRefExpr))
    Use (2 (Decl: ptr), Write)
    OriginFlow (Dest: 2 (Decl: ptr), Src: 1 (Expr: UnaryOperator))
    Use (2 (Decl: ptr), Read)
  End of Block
  Block B0:
  End of Block
Compiler returned: 0
```
We can use `AddLifetime` to make CFG add lifetime related events where destructor calls are not in the CFG.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to