Skip to content

Commit

Permalink
[CIR][Codegen] Fixes function ptrs in recursive types (llvm#328)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gitoleg authored and lanza committed Jun 20, 2024
1 parent 5d8b1ca commit 60a1cb1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 0 additions & 5 deletions clang/lib/CIR/CodeGen/CIRGenTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,6 @@ mlir::Type CIRGenTypes::ConvertFunctionTypeInternal(QualType QFT) {
// the function type.
assert(isFuncTypeConvertible(FT) && "NYI");

// While we're converting the parameter types for a function, we don't want to
// recursively convert any pointed-to structs. Converting directly-used
// structs is ok though.
assert(RecordsBeingLaidOut.insert(Ty).second && "NYI");

// The function type can be built; call the appropriate routines to build it
const CIRGenFunctionInfo *FI;
if (const auto *FPT = dyn_cast<FunctionProtoType>(FT)) {
Expand Down
10 changes: 10 additions & 0 deletions clang/test/CIR/CodeGen/fun-ptr.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ typedef struct {

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

struct A;
typedef int (*fun_typ)(struct A*);

typedef struct A {
fun_typ fun;
} A;

// 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>
A a = {(fun_typ)0};

int extract_a(Data* d) {
return d->a;
}
Expand Down

0 comments on commit 60a1cb1

Please sign in to comment.