[OCaml] Fix incorrect use of CAMLlocal in nested blocks

Summary:
The OCaml manual states:

> Local variables of type value must be declared with one of the
> CAMLlocal macros. [...] These macros must be used at the beginning
> of the function, not in a nested block.

This patch moves several instances of CAMLlocal macros from nested
blocks to the function beginning.

Reviewers: whitequark

Reviewed By: whitequark

Subscribers: CodaFi, llvm-commits

Differential Revision: https://reviews.llvm.org/D53841

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346387 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
whitequark 2018-11-08 04:00:18 +00:00
parent 19a9621221
commit 9ac4c44c94

View File

@ -483,9 +483,9 @@ CAMLprim value llvm_struct_set_body(LLVMTypeRef Ty,
CAMLprim value llvm_struct_name(LLVMTypeRef Ty) CAMLprim value llvm_struct_name(LLVMTypeRef Ty)
{ {
CAMLparam0(); CAMLparam0();
CAMLlocal1(result);
const char *C = LLVMGetStructName(Ty); const char *C = LLVMGetStructName(Ty);
if (C) { if (C) {
CAMLlocal1(result);
result = caml_alloc_small(1, 0); result = caml_alloc_small(1, 0);
Store_field(result, 0, caml_copy_string(C)); Store_field(result, 0, caml_copy_string(C));
CAMLreturn(result); CAMLreturn(result);
@ -636,6 +636,7 @@ enum ValueKind {
CAMLprim value llvm_classify_value(LLVMValueRef Val) { CAMLprim value llvm_classify_value(LLVMValueRef Val) {
CAMLparam0(); CAMLparam0();
CAMLlocal1(result);
if (!Val) if (!Val)
CAMLreturn(Val_int(NullValue)); CAMLreturn(Val_int(NullValue));
if (LLVMIsAConstant(Val)) { if (LLVMIsAConstant(Val)) {
@ -652,7 +653,6 @@ CAMLprim value llvm_classify_value(LLVMValueRef Val) {
DEFINE_CASE(Val, ConstantVector); DEFINE_CASE(Val, ConstantVector);
} }
if (LLVMIsAInstruction(Val)) { if (LLVMIsAInstruction(Val)) {
CAMLlocal1(result);
result = caml_alloc_small(1, 0); result = caml_alloc_small(1, 0);
Store_field(result, 0, Val_int(LLVMGetInstructionOpcode(Val))); Store_field(result, 0, Val_int(LLVMGetInstructionOpcode(Val)));
CAMLreturn(result); CAMLreturn(result);
@ -822,12 +822,11 @@ CAMLprim LLVMValueRef llvm_mdnull(LLVMContextRef C) {
/* llvalue -> string option */ /* llvalue -> string option */
CAMLprim value llvm_get_mdstring(LLVMValueRef V) { CAMLprim value llvm_get_mdstring(LLVMValueRef V) {
CAMLparam0(); CAMLparam0();
CAMLlocal2(Option, Str);
const char *S; const char *S;
unsigned Len; unsigned Len;
if ((S = LLVMGetMDString(V, &Len))) { if ((S = LLVMGetMDString(V, &Len))) {
CAMLlocal2(Option, Str);
Str = caml_alloc_string(Len); Str = caml_alloc_string(Len);
memcpy(String_val(Str), S, Len); memcpy(String_val(Str), S, Len);
Option = alloc(1,0); Option = alloc(1,0);