mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 19:56:06 +00:00

This introduces the `captures` attribute as described in: https://discourse.llvm.org/t/rfc-improvements-to-capture-tracking/81420 This initial patch only introduces the IR/bitcode support for the attribute and its in-memory representation as `CaptureInfo`. This will be followed by a patch to upgrade and remove the `nocapture` attribute, and then by actual inference/analysis support. Based on the RFC feedback, I've used a syntax similar to the `memory` attribute, though the only "location" that can be specified is `ret`. I've added some pretty extensive documentation to LangRef on the semantics. One non-obvious bit here is that using ptrtoint will not result in a "return-only" capture, even if the ptrtoint result is only used in the return value. Without this requirement we wouldn't be able to continue ordinary capture analysis on the return value.
74 lines
2.4 KiB
LLVM
74 lines
2.4 KiB
LLVM
; RUN: split-file --leading-lines %s %t
|
|
; RUN: not llvm-as < %t/missing-lparen.ll 2>&1 | FileCheck %s --check-prefix=CHECK-MISSING-LPAREN
|
|
; RUN: not llvm-as < %t/missing-rparen.ll 2>&1 | FileCheck %s --check-prefix=CHECK-MISSING-RPAREN
|
|
; RUN: not llvm-as < %t/missing-rparen-none.ll 2>&1 | FileCheck %s --check-prefix=CHECK-MISSING-RPAREN-NONE
|
|
; RUN: not llvm-as < %t/missing-colon.ll 2>&1 | FileCheck %s --check-prefix=CHECK-MISSING-COLON
|
|
; RUN: not llvm-as < %t/invalid-component.ll 2>&1 | FileCheck %s --check-prefix=CHECK-INVALID-COMPONENT
|
|
; RUN: not llvm-as < %t/duplicate-ret.ll 2>&1 | FileCheck %s --check-prefix=CHECK-DUPLICATE-RET
|
|
; RUN: not llvm-as < %t/none-after.ll 2>&1 | FileCheck %s --check-prefix=CHECK-NONE-AFTER
|
|
; RUN: not llvm-as < %t/none-before.ll 2>&1 | FileCheck %s --check-prefix=CHECK-NONE-BEFORE
|
|
; RUN: not opt -disable-output < %t/non-pointer-type.ll 2>&1 | FileCheck %s --check-prefix=CHECK-NON-POINTER-TYPE
|
|
|
|
;--- missing-lparen.ll
|
|
|
|
; CHECK-MISSING-LPAREN: <stdin>:[[@LINE+1]]:32: error: expected '('
|
|
define void @test(ptr captures %p) {
|
|
ret void
|
|
}
|
|
|
|
;--- missing-rparen.ll
|
|
|
|
; CHECK-MISSING-RPAREN: <stdin>:[[@LINE+1]]:40: error: expected ',' or ')'
|
|
define void @test(ptr captures(address %p) {
|
|
ret void
|
|
}
|
|
|
|
;--- missing-rparen-none.ll
|
|
|
|
; CHECK-MISSING-RPAREN-NONE: <stdin>:[[@LINE+1]]:37: error: expected ',' or ')'
|
|
define void @test(ptr captures(none %p) {
|
|
ret void
|
|
}
|
|
|
|
;--- missing-colon.ll
|
|
|
|
; CHECK-MISSING-COLON: <stdin>:[[@LINE+1]]:36: error: expected ':'
|
|
define void @test(ptr captures(ret address) %p) {
|
|
ret void
|
|
}
|
|
|
|
;--- invalid-component.ll
|
|
|
|
; CHECK-INVALID-COMPONENT: <stdin>:[[@LINE+1]]:32: error: expected one of 'none', 'address', 'address_is_null', 'provenance' or 'read_provenance'
|
|
define void @test(ptr captures(foo) %p) {
|
|
ret void
|
|
}
|
|
|
|
;--- duplicate-ret.ll
|
|
|
|
; CHECK-DUPLICATE-RET: <stdin>:[[@LINE+1]]:51: error: duplicate 'ret' location
|
|
define void @test(ptr captures(ret: address, ret: provenance) %p) {
|
|
ret void
|
|
}
|
|
|
|
;--- none-after.ll
|
|
|
|
; CHECK-NONE-AFTER: <stdin>:[[@LINE+1]]:45: error: cannot use 'none' with other component
|
|
define void @test(ptr captures(address, none) %p) {
|
|
ret void
|
|
}
|
|
|
|
;--- none-before.ll
|
|
|
|
; CHECK-NONE-BEFORE: <stdin>:[[@LINE+1]]:38: error: cannot use 'none' with other component
|
|
define void @test(ptr captures(none, address) %p) {
|
|
ret void
|
|
}
|
|
|
|
;--- non-pointer-type.ll
|
|
|
|
; CHECK-NON-POINTER-TYPE: Attribute 'captures(none)' applied to incompatible type!
|
|
define void @test(i32 captures(none) %p) {
|
|
ret void
|
|
}
|