Skip to content

[LifetimeSafety] False-negative for return of pointer to a parameter #169014

@usx95

Description

@usx95

https://godbolt.org/z/M5v3j6W84

#include <string> #include <string_view> std::string_view foo(std::string param) { std::string_view res = param; return res; }

We do not see the expired loans for the param (no destructors)

========================================== Lifetime Analysis Facts: ========================================== Function: foo Block B2: End of Block Block B1: Issue (0 (Path: param), ToOrigin: 0 (Expr: DeclRefExpr)) OriginFlow (Dest: 1 (Expr: ImplicitCastExpr), Src: 0 (Expr: DeclRefExpr)) OriginFlow (Dest: 2 (Expr: CXXMemberCallExpr), Src: 1 (Expr: ImplicitCastExpr)) OriginFlow (Dest: 3 (Expr: ImplicitCastExpr), Src: 2 (Expr: CXXMemberCallExpr)) OriginFlow (Dest: 4 (Decl: res), Src: 3 (Expr: ImplicitCastExpr)) Use (4 (Decl: res), Read) OriginFlow (Dest: 5 (Expr: ImplicitCastExpr), Src: 4 (Decl: res)) OriginFlow (Dest: 6 (Expr: CXXConstructExpr), Src: 5 (Expr: ImplicitCastExpr)) OriginEscapes (6 (Expr: CXXConstructExpr)) 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)false-negativeWarning doesn't fire when it should

    Type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions