Skip to content

Commit f9fbfc5

Browse files
authored
[SystemZ] Dump function signature on missing arg extension. (llvm#109699)
Make it easier to handle detected problems by providing the function signature(s) involved in cases of missing argument extensions.
1 parent 93af9d6 commit f9fbfc5

File tree

9 files changed

+89
-23
lines changed

9 files changed

+89
-23
lines changed

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,11 +1925,7 @@ SystemZTargetLowering::LowerCall(CallLoweringInfo &CLI,
19251925
IsTailCall = false;
19261926

19271927
// Integer args <=32 bits should have an extension attribute.
1928-
bool IsInternal = false;
1929-
if (auto *G = dyn_cast<GlobalAddressSDNode>(Callee))
1930-
if (const Function *Fn = dyn_cast<Function>(G->getGlobal()))
1931-
IsInternal = isFullyInternal(Fn);
1932-
verifyNarrowIntegerArgs(Outs, IsInternal);
1928+
verifyNarrowIntegerArgs_Call(Outs, &MF.getFunction(), Callee);
19331929

19341930
// Analyze the operands of the call, assigning locations to each operand.
19351931
SmallVector<CCValAssign, 16> ArgLocs;
@@ -2192,7 +2188,7 @@ SystemZTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv,
21922188
MachineFunction &MF = DAG.getMachineFunction();
21932189

21942190
// Integer args <=32 bits should have an extension attribute.
2195-
verifyNarrowIntegerArgs(Outs, isFullyInternal(&MF.getFunction()));
2191+
verifyNarrowIntegerArgs_Ret(Outs, &MF.getFunction());
21962192

21972193
// Assign locations to each returned value.
21982194
SmallVector<CCValAssign, 16> RetLocs;
@@ -9835,34 +9831,86 @@ bool SystemZTargetLowering::isFullyInternal(const Function *Fn) const {
98359831
return true;
98369832
}
98379833

9838-
// Verify that narrow integer arguments are extended as required by the ABI.
9834+
static void printFunctionArgExts(const Function *F, raw_fd_ostream &OS) {
9835+
FunctionType *FT = F->getFunctionType();
9836+
const AttributeList &Attrs = F->getAttributes();
9837+
if (Attrs.hasRetAttrs())
9838+
OS << Attrs.getAsString(AttributeList::ReturnIndex) << " ";
9839+
OS << *F->getReturnType() << " @" << F->getName() << "(";
9840+
for (unsigned I = 0, E = FT->getNumParams(); I != E; ++I) {
9841+
if (I)
9842+
OS << ", ";
9843+
OS << *FT->getParamType(I);
9844+
AttributeSet ArgAttrs = Attrs.getParamAttrs(I);
9845+
for (auto A : {Attribute::SExt, Attribute::ZExt, Attribute::NoExt})
9846+
if (ArgAttrs.hasAttribute(A))
9847+
OS << " " << Attribute::getNameFromAttrKind(A);
9848+
}
9849+
OS << ")\n";
9850+
}
9851+
98399852
void SystemZTargetLowering::
9853+
verifyNarrowIntegerArgs_Call(const SmallVectorImpl<ISD::OutputArg> &Outs,
9854+
const Function *F, SDValue Callee) const {
9855+
bool IsInternal = false;
9856+
const Function *CalleeFn = nullptr;
9857+
if (auto *G = dyn_cast<GlobalAddressSDNode>(Callee))
9858+
if (CalleeFn = dyn_cast<Function>(G->getGlobal()))
9859+
IsInternal = isFullyInternal(CalleeFn);
9860+
if (!verifyNarrowIntegerArgs(Outs, IsInternal)) {
9861+
errs() << "ERROR: Missing extension attribute of passed "
9862+
<< "value in call to function:\n" << "Callee: ";
9863+
if (CalleeFn != nullptr)
9864+
printFunctionArgExts(CalleeFn, errs());
9865+
else
9866+
errs() << "-";
9867+
errs() << "Caller: ";
9868+
printFunctionArgExts(F, errs());
9869+
llvm_unreachable("");
9870+
}
9871+
}
9872+
9873+
void SystemZTargetLowering::
9874+
verifyNarrowIntegerArgs_Ret(const SmallVectorImpl<ISD::OutputArg> &Outs,
9875+
const Function *F) const {
9876+
if (!verifyNarrowIntegerArgs(Outs, isFullyInternal(F))) {
9877+
errs() << "ERROR: Missing extension attribute of returned "
9878+
<< "value from function:\n";
9879+
printFunctionArgExts(F, errs());
9880+
llvm_unreachable("");
9881+
}
9882+
}
9883+
9884+
// Verify that narrow integer arguments are extended as required by the ABI.
9885+
// Return false if an error is found.
9886+
bool SystemZTargetLowering::
98409887
verifyNarrowIntegerArgs(const SmallVectorImpl<ISD::OutputArg> &Outs,
98419888
bool IsInternal) const {
98429889
if (IsInternal || !Subtarget.isTargetELF())
9843-
return;
9890+
return true;
98449891

98459892
// Temporarily only do the check when explicitly requested, until it can be
98469893
// enabled by default.
98479894
if (!EnableIntArgExtCheck)
9848-
return;
9895+
return true;
98499896

98509897
if (EnableIntArgExtCheck.getNumOccurrences()) {
98519898
if (!EnableIntArgExtCheck)
9852-
return;
9899+
return true;
98539900
} else if (!getTargetMachine().Options.VerifyArgABICompliance)
9854-
return;
9901+
return true;
98559902

98569903
for (unsigned i = 0; i < Outs.size(); ++i) {
98579904
MVT VT = Outs[i].VT;
98589905
ISD::ArgFlagsTy Flags = Outs[i].Flags;
98599906
if (VT.isInteger()) {
98609907
assert((VT == MVT::i32 || VT.getSizeInBits() >= 64) &&
98619908
"Unexpected integer argument VT.");
9862-
assert((VT != MVT::i32 ||
9863-
(Flags.isSExt() || Flags.isZExt() || Flags.isNoExt())) &&
9864-
"Narrow integer argument must have a valid extension type.");
9865-
(void)Flags;
9909+
if (VT == MVT::i32 &&
9910+
!Flags.isSExt() && !Flags.isZExt() && !Flags.isNoExt())
9911+
return false;
98669912
}
98679913
}
9914+
9915+
return true;
98689916
}

llvm/lib/Target/SystemZ/SystemZISelLowering.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,11 @@ class SystemZTargetLowering : public TargetLowering {
806806
const TargetRegisterClass *getRepRegClassFor(MVT VT) const override;
807807

808808
bool isFullyInternal(const Function *Fn) const;
809-
void verifyNarrowIntegerArgs(const SmallVectorImpl<ISD::OutputArg> &Outs,
809+
void verifyNarrowIntegerArgs_Call(const SmallVectorImpl<ISD::OutputArg> &Outs,
810+
const Function *F, SDValue Callee) const;
811+
void verifyNarrowIntegerArgs_Ret(const SmallVectorImpl<ISD::OutputArg> &Outs,
812+
const Function *F) const;
813+
bool verifyNarrowIntegerArgs(const SmallVectorImpl<ISD::OutputArg> &Outs,
810814
bool IsInternal) const;
811815
};
812816

llvm/test/CodeGen/SystemZ/args-15.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ define i32 @callee_MissingRetAttr() {
88
ret i32 -1
99
}
1010

11-
; CHECK: Narrow integer argument must have a valid extension type.
11+
; CHECK: ERROR: Missing extension attribute of returned value from function:
12+
; CHECK: i32 @callee_MissingRetAttr()
13+
; CHECK: UNREACHABLE executed

llvm/test/CodeGen/SystemZ/args-16.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ define i16 @callee_MissingRetAttr() {
88
ret i16 -1
99
}
1010

11-
; CHECK: Narrow integer argument must have a valid extension type.
11+
; CHECK: ERROR: Missing extension attribute of returned value from function:
12+
; CHECK: i16 @callee_MissingRetAttr()
13+
; CHECK: UNREACHABLE executed
1214

llvm/test/CodeGen/SystemZ/args-17.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ define i8 @callee_MissingRetAttr() {
88
ret i8 -1
99
}
1010

11-
; CHECK: Narrow integer argument must have a valid extension type.
11+
; CHECK: ERROR: Missing extension attribute of returned value from function:
12+
; CHECK: i8 @callee_MissingRetAttr()
13+
; CHECK: UNREACHABLE executed

llvm/test/CodeGen/SystemZ/args-18.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ define void @caller() {
1111

1212
declare void @bar_Struct(i32 %Arg)
1313

14-
; CHECK: Narrow integer argument must have a valid extension type
14+
; CHECK: ERROR: Missing extension attribute of passed value in call to function:
15+
; CHECK: Callee: void @bar_Struct(i32)
16+
; CHECK: Caller: void @caller()

llvm/test/CodeGen/SystemZ/args-19.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ define void @caller() {
1111

1212
declare void @bar_Struct(i16 %Arg)
1313

14-
; CHECK: Narrow integer argument must have a valid extension type
14+
; CHECK: ERROR: Missing extension attribute of passed value in call to function:
15+
; CHECK: Callee: void @bar_Struct(i16)
16+
; CHECK: Caller: void @caller()

llvm/test/CodeGen/SystemZ/args-20.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ define void @caller() {
1111

1212
declare void @bar_Struct(i8 %Arg)
1313

14-
; CHECK: Narrow integer argument must have a valid extension type
14+
; CHECK: ERROR: Missing extension attribute of passed value in call to function:
15+
; CHECK: Callee: void @bar_Struct(i8)
16+
; CHECK: Caller: void @caller()

llvm/test/CodeGen/SystemZ/args-21.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ define void @foo() {
1616
ret void
1717
}
1818

19-
; CHECK: Narrow integer argument must have a valid extension type
19+
; CHECK: ERROR: Missing extension attribute of returned value from function:
20+
; CHECK: i32 @bar(i32)
21+
; CHECK: UNREACHABLE executed

0 commit comments

Comments
 (0)