Skip to content

Commit 48777f9

Browse files
gitoleglanza
authored andcommitted
[CIR][Codegen] Fixes function ptrs in recursive types (llvm#328)
Since recursive types were perfectly fixed, we can safely remove the assert that prevented functons types generation for the case of incomplete types. The test is added - just to show that everything is ok for such kind of functions.
1 parent f4c0bdf commit 48777f9

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,6 @@ mlir::Type CIRGenTypes::ConvertFunctionTypeInternal(QualType QFT) {
260260
// the function type.
261261
assert(isFuncTypeConvertible(FT) && "NYI");
262262

263-
// While we're converting the parameter types for a function, we don't want to
264-
// recursively convert any pointed-to structs. Converting directly-used
265-
// structs is ok though.
266-
assert(RecordsBeingLaidOut.insert(Ty).second && "NYI");
267-
268263
// The function type can be built; call the appropriate routines to build it
269264
const CIRGenFunctionInfo *FI;
270265
if (const auto *FPT = dyn_cast<FunctionProtoType>(FT)) {

clang/test/CIR/CodeGen/fun-ptr.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ typedef struct {
1111

1212
typedef int (*fun_t)(Data* d);
1313

14+
struct A;
15+
typedef int (*fun_typ)(struct A*);
16+
17+
typedef struct A {
18+
fun_typ fun;
19+
} A;
20+
21+
// CIR: !ty_22A22 = !cir.struct<struct "A" {!cir.ptr<!cir.func<!cir.int<s, 32> (!cir.ptr<!cir.struct<struct "A">>)>>} #cir.record.decl.ast>
22+
A a = {(fun_typ)0};
23+
1424
int extract_a(Data* d) {
1525
return d->a;
1626
}

0 commit comments

Comments
 (0)