Skip to content

[LifetimeSafety] Two loans created from the same expression #153592

@usx95

Description

@usx95
#include <string>

void foo() {
    std::string a;
    const std::string* p = {&a};
    const std::string* q = p;
}

https://godbolt.org/z/b4nKKGccE

Debug output:

[B2 (ENTRY)]
   Succs (1): B1
 [B1]
   1:  (CXXConstructExpr, std::string)
   2: std::string a;
   3: a
   4: &[B1.3]
   5: [B1.4] (ImplicitCastExpr, NoOp, const std::string *)
   6: const std::string *p = {&a};
   7: p
   8: [B1.7] (ImplicitCastExpr, LValueToRValue, const std::string *)
   9: const std::string *q = p;
  10: [B1.2].~std::string() (Implicit destructor)
   Preds (1): B2
   Succs (1): B0
 [B0 (EXIT)]
   Preds (1): B1

==========================================
       Lifetime Analysis Facts:
==========================================
Function: foo
  Block B2:
  End of Block
  Block B1:
    Issue (LoanID: 0, OriginID: 0)
    Issue (LoanID: 1, OriginID: 0)
    AssignOrigin (DestID: 1, SrcID: 0)
    AssignOrigin (DestID: 2, SrcID: 3)
    AssignOrigin (DestID: 4, SrcID: 2)
    AssignOrigin (DestID: 5, SrcID: 4)
    Expire (LoanID: 0)
    Expire (LoanID: 1)
  End of Block
  Block B0:
  End of Block

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:temporal-safetyIssue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr)

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions