@@ -370,6 +370,34 @@ bool InsertFunctionStrategy::isUnsupportedFunction(Function *F) {
370
370
return true ;
371
371
}
372
372
373
+ // ABI attributes must be specified both at the function
374
+ // declaration/definition and call-site, otherwise the
375
+ // behavior may be undefined.
376
+ // We don't call those functions for now to prevent UB from happening.
377
+ auto IsABIAttribute = [](AttributeSet A) {
378
+ static const Attribute::AttrKind ABIAttrs[] = {
379
+ Attribute::StructRet, Attribute::ByVal,
380
+ Attribute::InAlloca, Attribute::InReg,
381
+ Attribute::StackAlignment, Attribute::SwiftSelf,
382
+ Attribute::SwiftAsync, Attribute::SwiftError,
383
+ Attribute::Preallocated, Attribute::ByRef,
384
+ Attribute::ZExt, Attribute::SExt};
385
+
386
+ return std::any_of (
387
+ std::begin (ABIAttrs), std::end (ABIAttrs),
388
+ [&](Attribute::AttrKind kind) { return A.hasAttribute (kind); });
389
+ };
390
+
391
+ auto FuncAttrs = F->getAttributes ();
392
+ if (IsABIAttribute (FuncAttrs.getRetAttrs ())) {
393
+ return true ;
394
+ }
395
+ for (size_t i = 0 ; i < F->arg_size (); i++) {
396
+ if (IsABIAttribute (FuncAttrs.getParamAttrs (i))) {
397
+ return true ;
398
+ }
399
+ }
400
+
373
401
// If it is not satisfied, the IR will be invalid.
374
402
if (!isCallableCC (F->getCallingConv ())) {
375
403
return true ;
0 commit comments