Skip to content

Commit 317e2ee

Browse files
committed
[FuzzMutate] Prevent UB caused by parameter ABI attributes.
We make those cases unsupported as it happens now for functions accepting metadata or token types.
1 parent 2ee6223 commit 317e2ee

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

llvm/lib/FuzzMutate/IRMutator.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,34 @@ bool InsertFunctionStrategy::isUnsupportedFunction(Function *F) {
370370
return true;
371371
}
372372

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+
373401
// If it is not satisfied, the IR will be invalid.
374402
if (!isCallableCC(F->getCallingConv())) {
375403
return true;

0 commit comments

Comments
 (0)