Skip to content

Commit 10c997b

Browse files
committed
Add a CL option for verification (default off) + tests
1 parent 99116cb commit 10c997b

File tree

10 files changed

+171
-8
lines changed

10 files changed

+171
-8
lines changed

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ using namespace llvm;
3434

3535
#define DEBUG_TYPE "systemz-lower"
3636

37+
// Temporarily let this be disabled by default until all known problems
38+
// related to argument extensions are fixed.
39+
static cl::opt<bool> EnableIntArgExtCheck(
40+
"argext-abi-check", cl::init(false),
41+
cl::desc("Verify that narrow int args are properly extended per the "
42+
"SystemZ ABI."));
43+
3744
namespace {
3845
// Represents information about a comparison.
3946
struct Comparison {
@@ -1918,11 +1925,11 @@ SystemZTargetLowering::LowerCall(CallLoweringInfo &CLI,
19181925
IsTailCall = false;
19191926

19201927
// Integer args <=32 bits should have an extension attribute.
1921-
bool HasLocalLinkage = false;
1928+
bool IsInternal = false;
19221929
if (auto *G = dyn_cast<GlobalAddressSDNode>(Callee))
19231930
if (const Function *Fn = dyn_cast<Function>(G->getGlobal()))
1924-
HasLocalLinkage = Fn->hasLocalLinkage();
1925-
verifyNarrowIntegerArgs(Outs, HasLocalLinkage);
1931+
IsInternal = isFullyInternal(Fn);
1932+
verifyNarrowIntegerArgs(Outs, IsInternal);
19261933

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

21872194
// Integer args <=32 bits should have an extension attribute.
2188-
verifyNarrowIntegerArgs(Outs, MF.getFunction().hasLocalLinkage());
2195+
verifyNarrowIntegerArgs(Outs, isFullyInternal(&MF.getFunction()));
21892196

21902197
// Assign locations to each returned value.
21912198
SmallVector<CCValAssign, 16> RetLocs;
@@ -9811,12 +9818,33 @@ SDValue SystemZTargetLowering::lowerVECREDUCE_ADD(SDValue Op,
98119818
DAG.getConstant(OpVT.getVectorNumElements() - 1, DL, MVT::i32));
98129819
}
98139820

9821+
// Only consider a function fully internal as long as it has local linkage
9822+
// and is not used in any other way than acting as the called function at
9823+
// call sites. TODO: Remove this when/if all internal functions adhere to
9824+
// the ABI.
9825+
bool SystemZTargetLowering::isFullyInternal(const Function *Fn) const {
9826+
if (!Fn->hasLocalLinkage())
9827+
return false;
9828+
for (const User *U : Fn->users()) {
9829+
if (auto *CB = dyn_cast<CallBase>(U)) {
9830+
if (CB->getCalledFunction() != Fn)
9831+
return false;
9832+
} else
9833+
return false;
9834+
}
9835+
return true;
9836+
}
9837+
98149838
// Verify that narrow integer arguments are extended as required by the ABI.
98159839
void SystemZTargetLowering::
98169840
verifyNarrowIntegerArgs(const SmallVectorImpl<ISD::OutputArg> &Outs,
9817-
bool HasLocalLinkage) const {
9818-
if (!getTargetMachine().Options.VerifyArgABICompliance || HasLocalLinkage ||
9819-
!Subtarget.isTargetELF())
9841+
bool IsInternal) const {
9842+
if (IsInternal || !Subtarget.isTargetELF())
9843+
return;
9844+
9845+
// Temporarily only do the check when explicitly requested.
9846+
if (/* !getTargetMachine().Options.VerifyArgABICompliance && */
9847+
!EnableIntArgExtCheck)
98209848
return;
98219849

98229850
for (unsigned i = 0; i < Outs.size(); ++i) {

llvm/lib/Target/SystemZ/SystemZISelLowering.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,8 +805,9 @@ class SystemZTargetLowering : public TargetLowering {
805805
getTargetMMOFlags(const Instruction &I) const override;
806806
const TargetRegisterClass *getRepRegClassFor(MVT VT) const override;
807807

808+
bool isFullyInternal(const Function *Fn) const;
808809
void verifyNarrowIntegerArgs(const SmallVectorImpl<ISD::OutputArg> &Outs,
809-
bool HasLocalLinkage) const;
810+
bool IsInternal) const;
810811
};
811812

812813
struct SystemZVectorConstantInfo {

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
; RUN: llc < %s -mtriple=s390x-linux-gnu -argext-abi-check
2+
3+
; Test that it works to pass structs as outgoing call arguments when the
4+
; NoExt attribute is given, either in the call instruction or in the
5+
; prototype of the called function.
6+
define void @caller() {
7+
call void @bar_Struct_32(i32 noext 123)
8+
call void @bar_Struct_16(i16 123)
9+
call void @bar_Struct_8(i8 noext 123)
10+
ret void
11+
}
12+
13+
declare void @bar_Struct_32(i32 %Arg)
14+
declare void @bar_Struct_16(i16 noext %Arg)
15+
declare void @bar_Struct_8(i8 %Arg)
16+
17+
; Test that it works to return values with the NoExt attribute.
18+
define noext i8 @callee_NoExtRet_i8() {
19+
ret i8 -1
20+
}
21+
22+
define noext i16 @callee_NoExtRet_i16() {
23+
ret i16 -1
24+
}
25+
26+
define noext i32 @callee_NoExtRet_i32() {
27+
ret i32 -1
28+
}
29+
30+
; An internal function is not checked for an extension attribute.
31+
define internal i32 @callee_NoExtRet_internal(i32 %Arg) {
32+
ret i32 %Arg
33+
}
34+
35+
; A call to an internal function is ok without argument extension.
36+
define void @caller_internal() {
37+
call i32 @callee_NoExtRet_internal(i32 0)
38+
ret void
39+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; RUN: not --crash llc < %s -mtriple=s390x-linux-gnu -argext-abi-check 2>&1 \
2+
; RUN: | FileCheck %s
3+
; REQUIRES: asserts
4+
;
5+
; Test detection of missing extension of an i32 return value.
6+
7+
define i32 @callee_MissingRetAttr() {
8+
ret i32 -1
9+
}
10+
11+
; CHECK: Narrow integer argument must have a valid extension type.

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; RUN: not --crash llc < %s -mtriple=s390x-linux-gnu -argext-abi-check 2>&1 \
2+
; RUN: | FileCheck %s
3+
; REQUIRES: asserts
4+
;
5+
; Test detection of missing extension of an i16 return value.
6+
7+
define i16 @callee_MissingRetAttr() {
8+
ret i16 -1
9+
}
10+
11+
; CHECK: Narrow integer argument must have a valid extension type.
12+

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; RUN: not --crash llc < %s -mtriple=s390x-linux-gnu -argext-abi-check 2>&1 \
2+
; RUN: | FileCheck %s
3+
; REQUIRES: asserts
4+
;
5+
; Test detection of missing extension of an i8 return value.
6+
7+
define i8 @callee_MissingRetAttr() {
8+
ret i8 -1
9+
}
10+
11+
; CHECK: Narrow integer argument must have a valid extension type.

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; RUN: not --crash llc < %s -mtriple=s390x-linux-gnu -argext-abi-check 2>&1 \
2+
; RUN: | FileCheck %s
3+
; REQUIRES: asserts
4+
;
5+
; Test detection of missing extension of an outgoing i32 call argument.
6+
7+
define void @caller() {
8+
call void @bar_Struct(i32 123)
9+
ret void
10+
}
11+
12+
declare void @bar_Struct(i32 %Arg)
13+
14+
; CHECK: Narrow integer argument must have a valid extension type

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; RUN: not --crash llc < %s -mtriple=s390x-linux-gnu -argext-abi-check 2>&1 \
2+
; RUN: | FileCheck %s
3+
; REQUIRES: asserts
4+
;
5+
; Test detection of missing extension of an outgoing i16 call argument.
6+
7+
define void @caller() {
8+
call void @bar_Struct(i16 123)
9+
ret void
10+
}
11+
12+
declare void @bar_Struct(i16 %Arg)
13+
14+
; CHECK: Narrow integer argument must have a valid extension type

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; RUN: not --crash llc < %s -mtriple=s390x-linux-gnu -argext-abi-check 2>&1 \
2+
; RUN: | FileCheck %s
3+
; REQUIRES: asserts
4+
;
5+
; Test detection of missing extension of an outgoing i8 call argument.
6+
7+
define void @caller() {
8+
call void @bar_Struct(i8 123)
9+
ret void
10+
}
11+
12+
declare void @bar_Struct(i8 %Arg)
13+
14+
; CHECK: Narrow integer argument must have a valid extension type

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; RUN: not --crash llc < %s -mtriple=s390x-linux-gnu -argext-abi-check 2>&1 \
2+
; RUN: | FileCheck %s
3+
; REQUIRES: asserts
4+
;
5+
; Test detection of missing extension involving an internal function which is
6+
; passed as a function pointer to an external function.
7+
8+
define internal i32 @bar(i32 %Arg) {
9+
ret i32 %Arg
10+
}
11+
12+
declare void @ExtFun(ptr %FunPtr);
13+
14+
define void @foo() {
15+
call void @ExtFun(ptr @bar)
16+
ret void
17+
}
18+
19+
; CHECK: Narrow integer argument must have a valid extension type

0 commit comments

Comments
 (0)