Skip to content

[Lint] Lint mismatch in ABI attributes #121929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions llvm/lib/Analysis/Lint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,30 @@ void Lint::visitCallBase(CallBase &I) {
visitMemoryReference(I, Loc, DL->getABITypeAlign(Ty), Ty,
MemRef::Read | MemRef::Write);
}

// Check that ABI attributes for the function and call-site match.
unsigned ArgNo = AI->getOperandNo();
Attribute::AttrKind ABIAttributes[] = {
Attribute::ZExt, Attribute::SExt, Attribute::InReg,
Attribute::ByVal, Attribute::ByRef, Attribute::InAlloca,
Attribute::Preallocated, Attribute::StructRet};
AttributeList CallAttrs = I.getAttributes();
for (Attribute::AttrKind Attr : ABIAttributes) {
Attribute CallAttr = CallAttrs.getParamAttr(ArgNo, Attr);
Attribute FnAttr = F->getParamAttribute(ArgNo, Attr);
Check(CallAttr.isValid() == FnAttr.isValid(),
Twine("Undefined behavior: ABI attribute ") +
Attribute::getNameFromAttrKind(Attr) +
" not present on both function and call-site",
&I);
if (CallAttr.isValid() && FnAttr.isValid()) {
Check(CallAttr == FnAttr,
Twine("Undefined behavior: ABI attribute ") +
Attribute::getNameFromAttrKind(Attr) +
" does not have same argument for function and call-site",
&I);
}
}
}
}
}
Expand Down
106 changes: 106 additions & 0 deletions llvm/test/Analysis/Lint/abi-attrs.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
; RUN: opt < %s -passes=lint -disable-output 2>&1 | FileCheck %s

declare void @fn_nothing_i8(i8 %x)
declare void @fn_zeroext(i8 zeroext %x)
declare void @fn_signext(i8 signext %x)
declare void @fn_inreg(i8 inreg %x)

declare void @fn_nothing_ptr(ptr %x)
declare void @fn_byval(ptr byval(i8) %x)
declare void @fn_byref(ptr byref(i8) %x)
declare void @fn_inalloca(ptr inalloca(i8) %x)
declare void @fn_preallocated(ptr preallocated(i8) %x)
declare void @fn_sret(ptr sret(i8) %x)

define void @caller_zeroext(i8 %x) {
; CHECK: Undefined behavior: ABI attribute zeroext not present on both function and call-site
; CHECK: call void @fn_zeroext(i8 %x)
call void @fn_zeroext(i8 %x)

; CHECK: Undefined behavior: ABI attribute zeroext not present on both function and call-site
; CHECK: call void @fn_nothing_i8(i8 zeroext %x)
call void @fn_nothing_i8(i8 zeroext %x)
ret void
}

define void @caller_signext(i8 %x) {
; CHECK: Undefined behavior: ABI attribute signext not present on both function and call-site
; CHECK: call void @fn_signext(i8 %x)
call void @fn_signext(i8 %x)

; CHECK: Undefined behavior: ABI attribute signext not present on both function and call-site
; CHECK: call void @fn_nothing_i8(i8 signext %x)
call void @fn_nothing_i8(i8 signext %x)
ret void
}

define void @caller_inreg(i8 %x) {
; CHECK: Undefined behavior: ABI attribute inreg not present on both function and call-site
; CHECK: call void @fn_inreg(i8 %x)
call void @fn_inreg(i8 %x)

; CHECK: Undefined behavior: ABI attribute inreg not present on both function and call-site
; CHECK: call void @fn_nothing_i8(i8 inreg %x)
call void @fn_nothing_i8(i8 inreg %x)
ret void
}

define void @caller_byval(ptr %x) {
; CHECK: Undefined behavior: ABI attribute byval not present on both function and call-site
; CHECK: call void @fn_byval(ptr %x)
call void @fn_byval(ptr %x)

; CHECK: Undefined behavior: ABI attribute byval not present on both function and call-site
; CHECK: call void @fn_nothing_ptr(ptr byval(i8) %x)
call void @fn_nothing_ptr(ptr byval(i8) %x)

; CHECK: Undefined behavior: ABI attribute byval does not have same argument for function and call-site
; CHECK: call void @fn_byval(ptr byval(i16) %x)
call void @fn_byval(ptr byval(i16) %x)
ret void
}

define void @caller_byref(ptr %x) {
; CHECK: Undefined behavior: ABI attribute byref not present on both function and call-site
; CHECK: call void @fn_byref(ptr %x)
call void @fn_byref(ptr %x)

; CHECK: Undefined behavior: ABI attribute byref not present on both function and call-site
; CHECK: call void @fn_nothing_ptr(ptr byref(i8) %x)
call void @fn_nothing_ptr(ptr byref(i8) %x)

; CHECK: Undefined behavior: ABI attribute byref does not have same argument for function and call-site
; CHECK: call void @fn_byref(ptr byref(i16) %x)
call void @fn_byref(ptr byref(i16) %x)
ret void
}

define void @caller_inalloca(ptr %x) {
; CHECK: Undefined behavior: ABI attribute inalloca not present on both function and call-site
; CHECK: call void @fn_inalloca(ptr %x)
call void @fn_inalloca(ptr %x)

; CHECK: Undefined behavior: ABI attribute inalloca not present on both function and call-site
; CHECK: call void @fn_nothing_ptr(ptr inalloca(i8) %x)
call void @fn_nothing_ptr(ptr inalloca(i8) %x)

; CHECK: Undefined behavior: ABI attribute inalloca does not have same argument for function and call-site
; CHECK: call void @fn_inalloca(ptr inalloca(i16) %x)
call void @fn_inalloca(ptr inalloca(i16) %x)
ret void
}

define void @caller_sret(ptr %x) {
; CHECK: Undefined behavior: ABI attribute sret not present on both function and call-site
; CHECK: call void @fn_sret(ptr %x)
call void @fn_sret(ptr %x)

; CHECK: Undefined behavior: ABI attribute sret not present on both function and call-site
; CHECK: call void @fn_nothing_ptr(ptr sret(i8) %x)
call void @fn_nothing_ptr(ptr sret(i8) %x)

; CHECK: Undefined behavior: ABI attribute sret does not have same argument for function and call-site
; CHECK: call void @fn_sret(ptr sret(i16) %x)
call void @fn_sret(ptr sret(i16) %x)
ret void
}
Loading