-
Notifications
You must be signed in to change notification settings - Fork 188
[CIR][CIRGen] Support a defined pure virtual destructor #825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,58 @@ | ||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir | ||
| // RUN: FileCheck --input-file=%t.cir %s | ||
|
|
||
| // Pure virtual functions are allowed to be defined, but the vtable should still | ||
| // point to __cxa_pure_virtual instead of the definition. For destructors, the | ||
| // base object destructor (which is not included in the vtable) should be | ||
| // defined as usual. The complete object destructors and deleting destructors | ||
| // should contain a trap, and the vtable entries for them should point to | ||
| // __cxa_pure_virtual. | ||
| class C { | ||
| C(); | ||
| virtual ~C() = 0; | ||
| virtual void pure() = 0; | ||
| }; | ||
|
|
||
| C::C() = default; | ||
| C::~C() = default; | ||
| void C::pure() {} | ||
|
|
||
| // CHECK: @_ZTV1C = #cir.vtable<{#cir.const_array<[#cir.ptr<null> : !cir.ptr<!u8i>, #cir.global_view<@_ZTI1C> : !cir.ptr<!u8i> | ||
| // complete object destructor (D1) | ||
| // CHECK-SAME: #cir.global_view<@__cxa_pure_virtual> : !cir.ptr<!u8i>, | ||
| // deleting destructor (D0) | ||
| // CHECK-SAME: #cir.global_view<@__cxa_pure_virtual> : !cir.ptr<!u8i>, | ||
| // C::pure | ||
| // CHECK-SAME: #cir.global_view<@__cxa_pure_virtual> : !cir.ptr<!u8i>]> | ||
|
|
||
| // The base object destructor should be emitted as normal. | ||
| // CHECK-LABEL: cir.func @_ZN1CD2Ev(%arg0: !cir.ptr<!ty_C> loc({{[^)]+}})) {{.*}} { | ||
| // CHECK-NEXT: %0 = cir.alloca !cir.ptr<!ty_C>, !cir.ptr<!cir.ptr<!ty_C>>, ["this", init] {alignment = 8 : i64} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, the tests should use regex for the SSA values, should make them a little more resistant to overall CIR changes. |
||
| // CHECK-NEXT: cir.store %arg0, %0 : !cir.ptr<!ty_C>, !cir.ptr<!cir.ptr<!ty_C>> | ||
| // CHECK-NEXT: %1 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_C>>, !cir.ptr<!ty_C> | ||
| // CHECK-NEXT: cir.return | ||
| // CHECK-NEXT: } | ||
|
|
||
| // The complete object destructor should trap. | ||
| // CHECK-LABEL: cir.func @_ZN1CD1Ev(%arg0: !cir.ptr<!ty_C> loc({{[^)]+}})) {{.*}} { | ||
| // CHECK-NEXT: %0 = cir.alloca !cir.ptr<!ty_C>, !cir.ptr<!cir.ptr<!ty_C>>, ["this", init] {alignment = 8 : i64} | ||
| // CHECK-NEXT: cir.store %arg0, %0 : !cir.ptr<!ty_C>, !cir.ptr<!cir.ptr<!ty_C>> | ||
| // CHECK-NEXT: %1 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_C>>, !cir.ptr<!ty_C> | ||
| // CHECK-NEXT: cir.trap | ||
| // CHECK-NEXT: } | ||
|
|
||
| // The deleting destructor should trap. | ||
| // CHECK-LABEL: cir.func @_ZN1CD0Ev(%arg0: !cir.ptr<!ty_C> loc({{[^)]+}})) {{.*}} { | ||
| // CHECK-NEXT: %0 = cir.alloca !cir.ptr<!ty_C>, !cir.ptr<!cir.ptr<!ty_C>>, ["this", init] {alignment = 8 : i64} | ||
| // CHECK-NEXT: cir.store %arg0, %0 : !cir.ptr<!ty_C>, !cir.ptr<!cir.ptr<!ty_C>> | ||
| // CHECK-NEXT: %1 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_C>>, !cir.ptr<!ty_C> | ||
| // CHECK-NEXT: cir.trap | ||
| // CHECK-NEXT: } | ||
|
|
||
| // C::pure should be emitted as normal. | ||
| // CHECK-LABEL: cir.func @_ZN1C4pureEv(%arg0: !cir.ptr<!ty_C> loc({{[^)]+}})) {{.*}} { | ||
| // CHECK-NEXT: %0 = cir.alloca !cir.ptr<!ty_C>, !cir.ptr<!cir.ptr<!ty_C>>, ["this", init] {alignment = 8 : i64} | ||
| // CHECK-NEXT: cir.store %arg0, %0 : !cir.ptr<!ty_C>, !cir.ptr<!cir.ptr<!ty_C>> | ||
| // CHECK-NEXT: %1 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_C>>, !cir.ptr<!ty_C> | ||
| // CHECK-NEXT: cir.return | ||
| // CHECK-NEXT: } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd make slightly more sense if the trap is has the
getEndLocinstead.