Skip to content

Commit

Permalink
[CIR][CodeGen] Support FullExpression storage duration cleanup (llvm#846
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lanza committed Oct 14, 2024
1 parent 229ebc1 commit 3a95d58
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion clang/lib/CIR/CodeGen/CIRGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "CIRGenModule.h"
#include "CIRGenOpenMPRuntime.h"
#include "CIRGenValue.h"
#include "EHScopeStack.h"
#include "TargetInfo.h"

#include "clang/AST/ExprCXX.h"
Expand Down Expand Up @@ -2210,7 +2211,9 @@ static void pushTemporaryCleanup(CIRGenFunction &CGF,
}

case SD_FullExpression:
llvm_unreachable("SD_FullExpression not implemented");
CGF.pushDestroy(NormalAndEHCleanup, ReferenceTemporary, E->getType(),
CIRGenFunction::destroyCXXObject,
CGF.getLangOpts().Exceptions);
break;

case SD_Automatic:
Expand Down
27 changes: 27 additions & 0 deletions clang/test/CIR/CodeGen/temporaries.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s

struct E {
~E();
E operator!();
};

void f() {
!E();
}

// CHECK: cir.func private @_ZN1EC1Ev(!cir.ptr<!ty_E>) extra(#fn_attr)
// CHECK-NEXT: cir.func private @_ZN1EntEv(!cir.ptr<!ty_E>) -> !ty_E
// CHECK-NEXT: cir.func private @_ZN1ED1Ev(!cir.ptr<!ty_E>) extra(#fn_attr)
// CHECK-NEXT: cir.func @_Z1fv() extra(#fn_attr1) {
// CHECK-NEXT: cir.scope {
// CHECK-NEXT: %[[ONE:[0-9]+]] = cir.alloca !ty_E, !cir.ptr<!ty_E>, ["agg.tmp.ensured"] {alignment = 1 : i64}
// CHECK-NEXT: %[[TWO:[0-9]+]] = cir.alloca !ty_E, !cir.ptr<!ty_E>, ["ref.tmp0"] {alignment = 1 : i64}
// CHECK-NEXT: cir.call @_ZN1EC1Ev(%1) : (!cir.ptr<!ty_E>) -> () extra(#fn_attr)
// CHECK-NEXT: %[[THREE:[0-9]+]] = cir.call @_ZN1EntEv(%[[TWO]]) : (!cir.ptr<!ty_E>) -> !ty_E
// CHECK-NEXT: cir.store %[[THREE]], %[[ONE]] : !ty_E, !cir.ptr<!ty_E>
// CHECK-NEXT: cir.call @_ZN1ED1Ev(%[[ONE]]) : (!cir.ptr<!ty_E>) -> () extra(#fn_attr)
// CHECK-NEXT: cir.call @_ZN1ED1Ev(%[[TWO]]) : (!cir.ptr<!ty_E>) -> () extra(#fn_attr)
// CHECK-NEXT: }
// CHECK-NEXT: cir.return
// CHECK-NEXT: }

0 comments on commit 3a95d58

Please sign in to comment.