forked from CTSRD-CHERI/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang] Do not discard cleanups while processing immediate invocation
Since an immediate invocation is a full expression itself - it requires an additional ExprWithCleanups node, but it can participate to a bigger full expression which actually requires cleanups to be run after. Thanks @ilya-biryukov for helping reducing the reproducer and confirming that the analysis is correct. Fixes llvm/llvm-project#60709 Reviewed By: ilya-biryukov Differential Revision: https://reviews.llvm.org/D153962
- Loading branch information
Showing
4 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// RUN: %clang_cc1 -std=c++20 -Wno-unused-value -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s | ||
|
||
struct P { | ||
consteval P() {} | ||
}; | ||
|
||
struct A { | ||
A(int v) { this->data = new int(v); } | ||
~A() { delete data; } | ||
private: | ||
int *data; | ||
}; | ||
|
||
void foo() { | ||
for (;A(1), P(), false;); | ||
// CHECK: foo | ||
// CHECK: for.cond: | ||
// CHECK: call void @_ZN1AC1Ei | ||
// CHECK: call void @_ZN1AD1Ev | ||
// CHECK: for.body | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// RUN: %clang_cc1 -fblocks -Wno-unused-value -std=c++20 -ast-dump -verify %s -ast-dump | FileCheck %s | ||
|
||
// expected-no-diagnostics | ||
|
||
struct P { | ||
consteval P() {} | ||
}; | ||
|
||
struct A { | ||
A(int v) { this->data = new int(v); } | ||
const int& get() const { | ||
return *this->data; | ||
} | ||
~A() { delete data; } | ||
private: | ||
int *data; | ||
}; | ||
|
||
void foo() { | ||
for (;A(1), P(), false;); | ||
// CHECK: foo | ||
// CHECK: ExprWithCleanups | ||
// CHECK-NEXT: BinaryOperator {{.*}} 'bool' ',' | ||
// CHECK-NEXT: BinaryOperator {{.*}} 'P':'P' ',' | ||
// CHECK-NEXT: CXXFunctionalCastExpr {{.*}} 'A':'A' | ||
// CHECK-NEXT: CXXBindTemporaryExpr {{.*}} 'A':'A' | ||
// CHECK-NEXT: CXXConstructExpr {{.*}} 'A':'A' | ||
// CHECK: ConstantExpr {{.*}} 'P':'P' | ||
// CHECK-NEXT: value: | ||
// CHECK-NEXT: ExprWithCleanups | ||
} | ||
|
||
void foobar() { | ||
A a(1); | ||
for (; ^{ auto ptr = &a.get(); }(), P(), false;); | ||
// CHECK: ExprWithCleanups | ||
// CHECK-NEXT: cleanup Block | ||
// CHECK-NEXT: BinaryOperator {{.*}} 'bool' ',' | ||
// CHECK-NEXT: BinaryOperator {{.*}} 'P':'P' ',' | ||
// CHECK-NEXT: CallExpr | ||
// CHECK-NEXT: BlockExpr | ||
// CHECK: ConstantExpr {{.*}} 'P':'P' | ||
// CHECK-NEXT: value: | ||
// CHECK-NEXT: ExprWithCleanups | ||
// CHECK-NOT: cleanup Block | ||
} | ||
|
||
struct B { | ||
int *p = new int(38); | ||
consteval int get() { return *p; } | ||
constexpr ~B() { delete p; } | ||
}; | ||
|
||
void bar() { | ||
// CHECK: bar | ||
// CHECK: ExprWithCleanups | ||
// CHECK: ConstantExpr | ||
// CHECK-NEXT: value: | ||
// CHECK-NEXT: ExprWithCleanups | ||
int k = B().get(); | ||
} |