@@ -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+
98399852void 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::
98409887verifyNarrowIntegerArgs (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}
0 commit comments