From 3628228dab174b0d033da02fcb96bfbd677b821a Mon Sep 17 00:00:00 2001 From: gitoleg Date: Wed, 22 Nov 2023 22:43:10 +0300 Subject: [PATCH] [CIR][Codegen] Fixes function ptrs in recursive types (#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. --- clang/lib/CIR/CodeGen/CIRGenTypes.cpp | 5 ----- clang/test/CIR/CodeGen/fun-ptr.c | 10 ++++++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp index 6240539377a7b0..9f417018284c43 100644 --- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp @@ -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(FT)) { diff --git a/clang/test/CIR/CodeGen/fun-ptr.c b/clang/test/CIR/CodeGen/fun-ptr.c index bda1a2fc233ebc..ae4f1ac8d3d6de 100644 --- a/clang/test/CIR/CodeGen/fun-ptr.c +++ b/clang/test/CIR/CodeGen/fun-ptr.c @@ -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 (!cir.ptr>)>>} #cir.record.decl.ast> +A a = {(fun_typ)0}; + int extract_a(Data* d) { return d->a; }