Skip to content

Commit 6a18135

Browse files
sitio-coutolanza
authored andcommitted
[CIR][CIRGen] Support for struct call arguments
Essentially emits an LValue for the struct and then passes it as a call argument.
1 parent bd8a486 commit 6a18135

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenCall.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,12 +654,15 @@ void CIRGenFunction::buildCallArg(CallArgList &args, const Expr *E,
654654
// we make it to the call.
655655
if (type->isRecordType() &&
656656
type->castAs<RecordType>()->getDecl()->isParamDestroyedInCallee()) {
657-
llvm_unreachable("NYI");
657+
llvm_unreachable("Microsoft C++ ABI is NYI");
658658
}
659659

660660
if (HasAggregateEvalKind && isa<ImplicitCastExpr>(E) &&
661661
cast<CastExpr>(E)->getCastKind() == CK_LValueToRValue) {
662-
assert(0 && "NYI");
662+
LValue L = buildLValue(cast<CastExpr>(E)->getSubExpr());
663+
assert(L.isSimple());
664+
args.addUncopiedAggregate(L, type);
665+
return;
663666
}
664667

665668
args.add(buildAnyExprToTemp(E), type);

clang/lib/CIR/CodeGen/CIRGenCall.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ struct CallArg {
210210
: RV(rv), HasLV(false), IsUsed(false), Ty(ty) {
211211
(void)IsUsed;
212212
}
213+
CallArg(LValue lv, clang::QualType ty)
214+
: LV(lv), HasLV(true), IsUsed(false), Ty(ty) {}
213215

214216
/// \returns an independent RValue. If the CallArg contains an LValue,
215217
/// a temporary copy is returned.
@@ -242,6 +244,10 @@ class CallArgList : public llvm::SmallVector<CallArg, 8> {
242244
push_back(CallArg(rvalue, type));
243245
}
244246

247+
void addUncopiedAggregate(LValue LV, clang::QualType type) {
248+
push_back(CallArg(LV, type));
249+
}
250+
245251
/// Add all the arguments from another CallArgList to this one. After doing
246252
/// this, the old CallArgList retains its list of arguments, but must not
247253
/// be used to emit a call.

clang/test/CIR/CodeGen/struct.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,10 @@ struct S3 {
6161
int a;
6262
} s3[3] = {{1}, {2}, {3}};
6363
// CHECK-DAG: cir.global external @s3 = #cir.const_array<[#cir.const_struct<{#cir.int<1> : !s32i}> : !ty_22struct2ES322, #cir.const_struct<{#cir.int<2> : !s32i}> : !ty_22struct2ES322, #cir.const_struct<{#cir.int<3> : !s32i}> : !ty_22struct2ES322]> : !cir.array<!ty_22struct2ES322 x 3>
64+
65+
void shouldCopyStructAsCallArg(struct S1 s) {
66+
// CHECK-DAG: cir.func @shouldCopyStructAsCallArg
67+
shouldCopyStructAsCallArg(s);
68+
// CHECK-DAG: %[[#LV:]] = cir.load %{{.+}} : cir.ptr <!ty_22struct2ES122>, !ty_22struct2ES122
69+
// CHECK-DAG: cir.call @shouldCopyStructAsCallArg(%[[#LV]]) : (!ty_22struct2ES122) -> ()
70+
}

0 commit comments

Comments
 (0)