@@ -320,13 +320,22 @@ mlir::convertFuncOpToLLVMFuncOp(FunctionOpInterface funcOp,
320
320
// overriden with an LLVM pointer type for later processing.
321
321
SmallVector<std::optional<NamedAttribute>> byValRefNonPtrAttrs;
322
322
TypeConverter::SignatureConversion result (funcOp.getNumArguments ());
323
- auto llvmType = converter.convertFunctionSignature (
324
- funcOp, varargsAttr && varargsAttr.getValue (),
325
- shouldUseBarePtrCallConv (funcOp, &converter), result,
326
- byValRefNonPtrAttrs);
323
+ auto llvmType = dyn_cast_or_null<LLVM::LLVMFunctionType>(
324
+ converter.convertFunctionSignature (
325
+ funcOp, varargsAttr && varargsAttr.getValue (),
326
+ shouldUseBarePtrCallConv (funcOp, &converter), result,
327
+ byValRefNonPtrAttrs));
327
328
if (!llvmType)
328
329
return rewriter.notifyMatchFailure (funcOp, " signature conversion failed" );
329
330
331
+ // Check for unsupported variadic functions.
332
+ if (!shouldUseBarePtrCallConv (funcOp, &converter))
333
+ if (funcOp->getAttrOfType <UnitAttr>(
334
+ LLVM::LLVMDialect::getEmitCWrapperAttrName ()))
335
+ if (llvmType.isVarArg ())
336
+ return funcOp.emitError (" C interface for variadic functions is not "
337
+ " supported yet." );
338
+
330
339
// Create an LLVM function, use external linkage by default until MLIR
331
340
// functions have linkage.
332
341
LLVM::Linkage linkage = LLVM::Linkage::External;
@@ -342,6 +351,18 @@ mlir::convertFuncOpToLLVMFuncOp(FunctionOpInterface funcOp,
342
351
linkage = attr.getLinkage ();
343
352
}
344
353
354
+ // Check for invalid attributes.
355
+ StringRef readnoneAttrName = LLVM::LLVMDialect::getReadnoneAttrName ();
356
+ if (funcOp->hasAttr (readnoneAttrName)) {
357
+ auto attr = funcOp->getAttrOfType <UnitAttr>(readnoneAttrName);
358
+ if (!attr) {
359
+ funcOp->emitError () << " Contains " << readnoneAttrName
360
+ << " attribute not of type UnitAttr" ;
361
+ return rewriter.notifyMatchFailure (
362
+ funcOp, " Contains readnone attribute not of type UnitAttr" );
363
+ }
364
+ }
365
+
345
366
SmallVector<NamedAttribute, 4 > attributes;
346
367
filterFuncAttributes (funcOp, attributes);
347
368
auto newFuncOp = rewriter.create <LLVM::LLVMFuncOp>(
@@ -352,15 +373,7 @@ mlir::convertFuncOpToLLVMFuncOp(FunctionOpInterface funcOp,
352
373
.setVisibility (funcOp.getVisibility ());
353
374
354
375
// Create a memory effect attribute corresponding to readnone.
355
- StringRef readnoneAttrName = LLVM::LLVMDialect::getReadnoneAttrName ();
356
376
if (funcOp->hasAttr (readnoneAttrName)) {
357
- auto attr = funcOp->getAttrOfType <UnitAttr>(readnoneAttrName);
358
- if (!attr) {
359
- funcOp->emitError () << " Contains " << readnoneAttrName
360
- << " attribute not of type UnitAttr" ;
361
- return rewriter.notifyMatchFailure (
362
- funcOp, " Contains readnone attribute not of type UnitAttr" );
363
- }
364
377
auto memoryAttr = LLVM::MemoryEffectsAttr::get (
365
378
rewriter.getContext (),
366
379
{LLVM::ModRefInfo::NoModRef, LLVM::ModRefInfo::NoModRef,
@@ -447,10 +460,6 @@ mlir::convertFuncOpToLLVMFuncOp(FunctionOpInterface funcOp,
447
460
if (!shouldUseBarePtrCallConv (funcOp, &converter)) {
448
461
if (funcOp->getAttrOfType <UnitAttr>(
449
462
LLVM::LLVMDialect::getEmitCWrapperAttrName ())) {
450
- if (newFuncOp.isVarArg ())
451
- return funcOp.emitError (" C interface for variadic functions is not "
452
- " supported yet." );
453
-
454
463
if (newFuncOp.isExternal ())
455
464
wrapExternalFunction (rewriter, funcOp->getLoc (), converter, funcOp,
456
465
newFuncOp);
0 commit comments