Skip to content

Commit cea69fa

Browse files
committed
[SVE] Add fatal error for unnamed SVE variadic arguments
We don't currently support passing unnamed variadic SVE arguments so I've added a fatal error if we hit such cases to prevent any silent ABI issues in future. Differential Revision: https://reviews.llvm.org/D90230
1 parent d14db8c commit cea69fa

File tree

6 files changed

+94
-0
lines changed

6 files changed

+94
-0
lines changed

clang/lib/CodeGen/TargetInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5480,6 +5480,11 @@ class AArch64ABIInfo : public SwiftABIInfo {
54805480

54815481
Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
54825482
QualType Ty) const override {
5483+
llvm::Type *BaseTy = CGF.ConvertType(Ty);
5484+
if (isa<llvm::ScalableVectorType>(BaseTy))
5485+
llvm::report_fatal_error("Passing SVE types to variadic functions is "
5486+
"currently not supported");
5487+
54835488
return Kind == Win64 ? EmitMSVAArg(CGF, VAListAddr, Ty)
54845489
: isDarwinPCS() ? EmitDarwinVAArg(VAListAddr, Ty, CGF)
54855490
: EmitAAPCSVAArg(VAListAddr, Ty, CGF);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// REQUIRES: aarch64-registered-target
2+
// RUN: not %clang_cc1 -triple aarch64-linux-gnu -target-feature +sve -fallow-half-arguments-and-returns -emit-llvm -o - %s 2>&1 | FileCheck %s
3+
// RUN: not %clang_cc1 -triple arm64-apple-ios7 -target-abi darwinpcs -target-feature +sve -fallow-half-arguments-and-returns -emit-llvm -o - %s 2>&1 | FileCheck %s
4+
5+
// CHECK: Passing SVE types to variadic functions is currently not supported
6+
7+
#include <arm_sve.h>
8+
#include <stdarg.h>
9+
10+
double foo(char *str, ...) {
11+
va_list ap;
12+
svfloat64_t v;
13+
double x;
14+
15+
va_start(ap, str);
16+
v = va_arg(ap, svfloat64_t);
17+
x = va_arg(ap, double);
18+
va_end(ap);
19+
20+
return x + svaddv(svptrue_b8(), v);
21+
}

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4807,6 +4807,10 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
48074807

48084808
for (unsigned i = 0; i != NumArgs; ++i) {
48094809
MVT ArgVT = Outs[i].VT;
4810+
if (!Outs[i].IsFixed && ArgVT.isScalableVector())
4811+
report_fatal_error("Passing SVE types to variadic functions is "
4812+
"currently not supported");
4813+
48104814
ISD::ArgFlagsTy ArgFlags = Outs[i].Flags;
48114815
CCAssignFn *AssignFn = CCAssignFnForCall(CallConv,
48124816
/*IsVarArg=*/ !Outs[i].IsFixed);
@@ -6606,6 +6610,10 @@ SDValue AArch64TargetLowering::LowerVAARG(SDValue Op, SelectionDAG &DAG) const {
66066610
Chain = VAList.getValue(1);
66076611
VAList = DAG.getZExtOrTrunc(VAList, DL, PtrVT);
66086612

6613+
if (VT.isScalableVector())
6614+
report_fatal_error("Passing SVE types to variadic functions is "
6615+
"currently not supported");
6616+
66096617
if (Align && *Align > MinSlotSize) {
66106618
VAList = DAG.getNode(ISD::ADD, DL, PtrVT, VAList,
66116619
DAG.getConstant(Align->value() - 1, DL, PtrVT));
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: not --crash llc -mtriple arm64-apple-ios7 -mattr=+sve < %s 2>&1 | FileCheck %s
2+
3+
; CHECK: Passing SVE types to variadic functions is currently not supported
4+
5+
@.str = private unnamed_addr constant [4 x i8] c"fmt\00", align 1
6+
define void @foo(i8* %fmt, ...) nounwind {
7+
entry:
8+
%fmt.addr = alloca i8*, align 8
9+
%args = alloca i8*, align 8
10+
%vc = alloca i32, align 4
11+
%vv = alloca <vscale x 4 x i32>, align 16
12+
store i8* %fmt, i8** %fmt.addr, align 8
13+
%args1 = bitcast i8** %args to i8*
14+
call void @llvm.va_start(i8* %args1)
15+
%0 = va_arg i8** %args, i32
16+
store i32 %0, i32* %vc, align 4
17+
%1 = va_arg i8** %args, <vscale x 4 x i32>
18+
store <vscale x 4 x i32> %1, <vscale x 4 x i32>* %vv, align 16
19+
ret void
20+
}
21+
22+
declare void @llvm.va_start(i8*) nounwind
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; RUN: not --crash llc -mtriple aarch64-linux-gnu -mattr=+sve <%s 2>&1 | FileCheck %s
2+
3+
declare i32 @sve_printf(i8*, <vscale x 4 x i32>, ...)
4+
5+
@.str_1 = internal constant [6 x i8] c"boo!\0A\00"
6+
7+
; CHECK: Passing SVE types to variadic functions is currently not supported
8+
define void @foo(<vscale x 4 x i32> %x) {
9+
%f = getelementptr [6 x i8], [6 x i8]* @.str_1, i64 0, i64 0
10+
call i32 (i8*, <vscale x 4 x i32>, ...) @sve_printf(i8* %f, <vscale x 4 x i32> %x, <vscale x 4 x i32> %x)
11+
ret void
12+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=aarch64--linux-gnu -mattr=+sve < %s 2>%t | FileCheck %s
3+
; RUN: FileCheck --check-prefix=WARN --allow-empty %s <%t
4+
5+
; If this check fails please read test/CodeGen/AArch64/README for instructions on how to resolve it.
6+
; WARN-NOT: warning
7+
8+
declare i32 @sve_printf(i8*, <vscale x 4 x i32>, ...)
9+
10+
@.str_1 = internal constant [6 x i8] c"boo!\0A\00"
11+
12+
define void @foo(<vscale x 4 x i32> %x) {
13+
; CHECK-LABEL: foo:
14+
; CHECK: // %bb.0:
15+
; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill
16+
; CHECK-NEXT: .cfi_def_cfa_offset 16
17+
; CHECK-NEXT: .cfi_offset w30, -16
18+
; CHECK-NEXT: adrp x0, .str_1
19+
; CHECK-NEXT: add x0, x0, :lo12:.str_1
20+
; CHECK-NEXT: bl sve_printf
21+
; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
22+
; CHECK-NEXT: ret
23+
%f = getelementptr [6 x i8], [6 x i8]* @.str_1, i64 0, i64 0
24+
call i32 (i8*, <vscale x 4 x i32>, ...) @sve_printf(i8* %f, <vscale x 4 x i32> %x)
25+
ret void
26+
}

0 commit comments

Comments
 (0)