Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ void FactsGenerator::VisitUnaryOperator(const UnaryOperator *UO) {
// origin of this UnaryOperator expression.
killAndFlowOrigin(*UO, *SubExpr);
}
if (UO->getOpcode() == UO_Deref) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: move to a switch now that you have 2 cases.

const Expr *SubExpr = UO->getSubExpr();
killAndFlowOrigin(*UO, *SubExpr);
}
}

void FactsGenerator::VisitReturnStmt(const ReturnStmt *RS) {
Expand Down
6 changes: 6 additions & 0 deletions clang/test/Sema/warn-lifetime-safety-dataflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ void pointer_indirection() {
// CHECK-NEXT: Dest: {{[0-9]+}} (Expr: ImplicitCastExpr, Type : int *)
// CHECK-NEXT: Src: [[O_PP_INNER]] (Decl: pp, Type : int *)
// CHECK: OriginFlow:
// CHECK-NEXT: Dest: {{[0-9]+}} (Expr: UnaryOperator, Type : int *&)
// CHECK-NEXT: Src: {{[0-9]+}} (Expr: ImplicitCastExpr, Type : int **)
// CHECK: OriginFlow:
// CHECK-NEXT: Dest: {{[0-9]+}} (Expr: UnaryOperator, Type : int *)
// CHECK-NEXT: Src: {{[0-9]+}} (Expr: ImplicitCastExpr, Type : int *)
// CHECK: OriginFlow:
// CHECK-NEXT: Dest: {{[0-9]+}} (Expr: ImplicitCastExpr, Type : int *)
// CHECK-NEXT: Src: {{[0-9]+}} (Expr: UnaryOperator, Type : int *)
// CHECK: OriginFlow:
Expand Down
9 changes: 6 additions & 3 deletions clang/test/Sema/warn-lifetime-safety-suggestions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ MyObj* return_ptr_to_ref(MyObj& a) { // expected-warning {{param should be marke
return &a; // expected-note {{param returned here}}
}

// FIXME: Dereference does not propagate loans.
MyObj& return_ref_to_ptr(MyObj* a) {
return *a;
MyObj& return_ref_to_ptr(MyObj* a) { // expected-warning {{param should be marked [[clang::lifetimebound]]}}
return *a; // expected-note {{param returned here}}
}

View return_ref_to_ptr_multiple(MyObj* a) { // expected-warning {{param should be marked [[clang::lifetimebound]]}}
return *(&(*(&(*a)))); // expected-note {{param returned here}}
}

View return_view_from_reference(MyObj& p) { // expected-warning {{param should be marked [[clang::lifetimebound]]}}
Expand Down
22 changes: 11 additions & 11 deletions clang/test/Sema/warn-lifetime-safety.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,10 @@ const int* return_pointer_to_parameter_via_reference(int a, int b, bool cond) {
const int* d = &c;
return d; // expected-note 2 {{returned here}}
}
// FIXME: Dereference of a pointer does not track the reference.

const int& return_pointer_to_parameter_via_reference_1(int a) {
const int* d = &a;
return *d;
const int* d = &a; // expected-warning {{address of stack memory is returned later}}
return *d; // expected-note {{returned here}}
}

const int& get_ref_to_local() {
Expand Down Expand Up @@ -1118,24 +1118,24 @@ struct MyObjStorage {
const MyObj *end() const { return objs + 1; }
};

// FIXME: Detect use-after-scope. Dereference pointer does not propagate the origins.
void range_based_for_use_after_scope() {
View v;
{
MyObjStorage s;
for (const MyObj &o : s) {
for (const MyObj &o : s) { // expected-warning {{object whose reference is captured does not live long enough}}
v = o;
}
}
v.use();
} // expected-note {{destroyed here}}
v.use(); // expected-note {{later used here}}
}
// FIXME: Detect use-after-return. Dereference pointer does not propagate the origins.

View range_based_for_use_after_return() {
MyObjStorage s;
for (const MyObj &o : s) {
return o;
for (const MyObj &o : s) { // expected-warning {{address of stack memory is returned later}}
return o; // expected-note {{returned here}}
}
return *s.begin();
return *s.begin(); // expected-warning {{address of stack memory is returned later}}
// expected-note@-1 {{returned here}}
}

void range_based_for_not_reference() {
Expand Down
Loading