diff options
author | Iris Shi <0.0@owo.li> | 2025-05-14 00:47:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-13 09:47:21 -0700 |
commit | 3f6ef4ecfbb1597dc818cf2819907ab12799ade4 (patch) | |
tree | 65f3b22c13f6ba6653b2d3384d728d68d85b73c5 /clang/lib/CIR/CodeGen/CIRGenModule.cpp | |
parent | e7547b25f594eda1325f7e9e0adb364faf5d4db1 (diff) | |
download | llvm-3f6ef4ecfbb1597dc818cf2819907ab12799ade4.zip llvm-3f6ef4ecfbb1597dc818cf2819907ab12799ade4.tar.gz llvm-3f6ef4ecfbb1597dc818cf2819907ab12799ade4.tar.bz2 |
[CIR] Cleanup support for C functions (#136854)
This adds basic handling for non-prototype functions in C.
Closes #130200.
Diffstat (limited to 'clang/lib/CIR/CodeGen/CIRGenModule.cpp')
-rw-r--r-- | clang/lib/CIR/CodeGen/CIRGenModule.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index 6899e49..b4e27bc 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -23,6 +23,7 @@ #include "clang/CIR/Dialect/IR/CIRDialect.h" #include "clang/CIR/MissingFeatures.h" +#include "CIRGenFunctionInfo.h" #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/Location.h" #include "mlir/IR/MLIRContext.h" @@ -247,8 +248,22 @@ void CIRGenModule::emitGlobalFunctionDefinition(clang::GlobalDecl gd, "function definition with a non-identifier for a name"); return; } - cir::FuncType funcType = - cast<cir::FuncType>(convertType(funcDecl->getType())); + + cir::FuncType funcType; + // TODO: Move this to arrangeFunctionDeclaration when it is + // implemented. + // When declaring a function without a prototype, always use a + // non-variadic type. + if (CanQual<FunctionNoProtoType> noProto = + funcDecl->getType() + ->getCanonicalTypeUnqualified() + .getAs<FunctionNoProtoType>()) { + const CIRGenFunctionInfo &fi = getTypes().arrangeCIRFunctionInfo( + noProto->getReturnType(), {}, RequiredArgs::All); + funcType = getTypes().getFunctionType(fi); + } else { + funcType = cast<cir::FuncType>(convertType(funcDecl->getType())); + } cir::FuncOp funcOp = dyn_cast_if_present<cir::FuncOp>(op); if (!funcOp || funcOp.getFunctionType() != funcType) { |