Skip to content

Commit 0020f9d

Browse files
committed
Only allow captures attribute on pointer types
1 parent cc27832 commit 0020f9d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

llvm/lib/IR/Attributes.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2381,7 +2381,8 @@ AttributeMask AttributeFuncs::typeIncompatible(Type *Ty, AttributeSet AS,
23812381
.addAttribute(Attribute::DereferenceableOrNull)
23822382
.addAttribute(Attribute::Writable)
23832383
.addAttribute(Attribute::DeadOnUnwind)
2384-
.addAttribute(Attribute::Initializes);
2384+
.addAttribute(Attribute::Initializes)
2385+
.addAttribute(Attribute::Captures);
23852386
if (ASK & ASK_UNSAFE_TO_DROP)
23862387
Incompatible.addAttribute(Attribute::Nest)
23872388
.addAttribute(Attribute::SwiftError)

llvm/test/Assembler/captures-errors.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
; RUN: not llvm-as < %t/duplicate-ret.ll 2>&1 | FileCheck %s --check-prefix=CHECK-DUPLICATE-RET
88
; RUN: not llvm-as < %t/none-after.ll 2>&1 | FileCheck %s --check-prefix=CHECK-NONE-AFTER
99
; RUN: not llvm-as < %t/none-before.ll 2>&1 | FileCheck %s --check-prefix=CHECK-NONE-BEFORE
10+
; RUN: not opt -disable-output < %t/non-pointer-type.ll 2>&1 | FileCheck %s --check-prefix=CHECK-NON-POINTER-TYPE
1011

1112
;--- missing-lparen.ll
1213

@@ -63,3 +64,10 @@ define void @test(ptr captures(address, none) %p) {
6364
define void @test(ptr captures(none, address) %p) {
6465
ret void
6566
}
67+
68+
;--- non-pointer-type.ll
69+
70+
; CHECK-NON-POINTER-TYPE: Attribute 'captures(none)' applied to incompatible type!
71+
define void @test(i32 captures(none) %p) {
72+
ret void
73+
}

0 commit comments

Comments
 (0)