Skip to content

Commit ac6b4c6

Browse files
Reapply "[Verifier] Reject va_start in non-variadic function (#88809)"
This reverts commit f4960da. Includes a fix for the MLIR test case.
1 parent 92e96c7 commit ac6b4c6

File tree

6 files changed

+16
-13
lines changed

6 files changed

+16
-13
lines changed

llvm/lib/Analysis/Lint.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,7 @@ void Lint::visitCallBase(CallBase &I) {
350350
}
351351

352352
case Intrinsic::vastart:
353-
Check(I.getParent()->getParent()->isVarArg(),
354-
"Undefined behavior: va_start called in a non-varargs function",
355-
&I);
356-
353+
// vastart in non-varargs function is rejected by the verifier
357354
visitMemoryReference(I, MemoryLocation::getForArgument(&I, 0, TLI),
358355
std::nullopt, nullptr, MemRef::Read | MemRef::Write);
359356
break;

llvm/lib/IR/Verifier.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5798,6 +5798,11 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
57985798

57995799
break;
58005800
}
5801+
case Intrinsic::vastart: {
5802+
Check(Call.getFunction()->isVarArg(),
5803+
"va_start called in a non-varargs function");
5804+
break;
5805+
}
58015806
case Intrinsic::vector_reduce_and:
58025807
case Intrinsic::vector_reduce_or:
58035808
case Intrinsic::vector_reduce_xor:

llvm/test/CodeGen/AArch64/GlobalISel/vastart.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
declare void @llvm.va_start(ptr)
6-
define void @test_va_start(ptr %list) {
6+
define void @test_va_start(ptr %list, ...) {
77
; CHECK-LABEL: name: test_va_start
88
; CHECK: [[LIST:%[0-9]+]]:_(p0) = COPY $x0
99
; CHECK-IOS: G_VASTART [[LIST]](p0) :: (store (s64) into %ir.list, align 1)

llvm/test/Other/lint.ll

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,6 @@ define void @0() nounwind {
124124
ret void
125125
}
126126

127-
; CHECK: va_start called in a non-varargs function
128-
declare void @llvm.va_start(ptr)
129-
define void @not_vararg(ptr %p) nounwind {
130-
call void @llvm.va_start(ptr %p)
131-
ret void
132-
}
133-
134127
; CHECK: Undefined behavior: Branch to non-blockaddress
135128
define void @use_indbr() {
136129
indirectbr ptr @foo, [label %block]

llvm/test/Verifier/variadic.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
; RUN: not opt -S -passes=verify 2>&1 < %s | FileCheck %s
2+
3+
; CHECK: va_start called in a non-varargs function
4+
declare void @llvm.va_start(ptr)
5+
define void @not_vararg(ptr %p) nounwind {
6+
call void @llvm.va_start(ptr %p)
7+
ret void
8+
}

mlir/test/Target/LLVMIR/Import/intrinsic.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ define void @ushl_sat_test(i32 %0, i32 %1, <8 x i32> %2, <8 x i32> %3) {
597597
}
598598

599599
; CHECK-LABEL: llvm.func @va_intrinsics_test
600-
define void @va_intrinsics_test(ptr %0, ptr %1) {
600+
define void @va_intrinsics_test(ptr %0, ptr %1, ...) {
601601
; CHECK: llvm.intr.vastart %{{.*}}
602602
call void @llvm.va_start.p0(ptr %0)
603603
; CHECK: llvm.intr.vacopy %{{.*}} to %{{.*}}

0 commit comments

Comments
 (0)