From b1e6b969fe72b5b616d3a169955d95cc0fb16a1e Mon Sep 17 00:00:00 2001
From: Dan Gohman The 'ret' instruction is used to return control flow (and a
-value) from a function back to the caller. The 'ret' instruction is used to return control flow (and
+optionally a value) from a function back to the caller. There are two forms of the 'ret' instruction: one that
-returns value(s) and then causes control flow, and one that just causes
+returns a value and then causes control flow, and one that just causes
control flow to occur. The 'ret' instruction may return zero, one or multiple values.
-The type of each return value must be a 'first
-class' type. Note that a function is not well
-formed if there exists a 'ret' instruction inside of the
-function that returns values that do not match the return type of the
-function. The 'ret' instruction optionally accepts a single argument,
+the return value. The type of the return value must be a
+'first class' type. A function is not well formed if
+it it has a non-void return type and contains a 'ret'
+instruction with no return value or a return value with a type that
+does not match its type, or if it has a void return type and contains
+a 'ret' instruction with a return value.Syntax:
- ret <type> <value> ; Return a value from a non-void function
+
+ ret <type> <value> ; Return a value from a non-void function
ret void ; Return from void function
- ret <type> <value>, <type> <value> ; Return two values from a non-void function
Overview:
-Arguments:
-Semantics:
@@ -1930,16 +1932,14 @@ the instruction after the call. If the caller was an "invoke" instruction, execution continues
at the beginning of the "normal" destination block. If the instruction
returns a value, that value shall set the call or invoke instruction's
-return value. If the instruction returns multiple values then these
-values can only be accessed through a 'getresult
-' instruction.
+return value.
Example:
ret i32 5 ; Return an integer value of 5
ret void ; Return from a void function
- ret i32 4, i8 2 ; Return two values 4 and 2
+ ret { i32, i8 } { i32 4, i8 2 } ; Return an aggregate of values 4 and 2
- <resultval> = getresult <type> <retval>, <index> -- -
The 'getresult' instruction is used to extract individual values -from a 'call' -or 'invoke' instruction that returns multiple -results.
- -The 'getresult' instruction takes a call or invoke value as its -first argument, or an undef value. The value must have structure type. The second argument is a constant -unsigned index value which must be in range for the number of values returned -by the call.
- -The 'getresult' instruction extracts the element identified by -'index' from the aggregate value.
- -- %struct.A = type { i32, i8 } - - %r = call %struct.A @foo() - %gr = getresult %struct.A %r, 0 ; yields i32:%gr - %gr1 = getresult %struct.A %r, 1 ; yields i8:%gr1 - add i32 %gr, 42 - add i8 %gr1, 41 -- -