Skip to content

Commit

Permalink
[OCaml] Fix incorrect use of CAMLlocal in nested blocks
Browse files Browse the repository at this point in the history
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

llvm-svn: 346387
  • Loading branch information
whitequark committed Nov 8, 2018
1 parent 73cb978 commit c07f8c1
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions llvm/bindings/ocaml/llvm/llvm_ocaml.c
Expand Up @@ -483,9 +483,9 @@ CAMLprim value llvm_struct_set_body(LLVMTypeRef Ty,
CAMLprim value llvm_struct_name(LLVMTypeRef Ty)
{
CAMLparam0();
CAMLlocal1(result);
const char *C = LLVMGetStructName(Ty);
if (C) {
CAMLlocal1(result);
result = caml_alloc_small(1, 0);
Store_field(result, 0, caml_copy_string(C));
CAMLreturn(result);
Expand Down Expand Up @@ -636,6 +636,7 @@ enum ValueKind {

CAMLprim value llvm_classify_value(LLVMValueRef Val) {
CAMLparam0();
CAMLlocal1(result);
if (!Val)
CAMLreturn(Val_int(NullValue));
if (LLVMIsAConstant(Val)) {
Expand All @@ -652,7 +653,6 @@ CAMLprim value llvm_classify_value(LLVMValueRef Val) {
DEFINE_CASE(Val, ConstantVector);
}
if (LLVMIsAInstruction(Val)) {
CAMLlocal1(result);
result = caml_alloc_small(1, 0);
Store_field(result, 0, Val_int(LLVMGetInstructionOpcode(Val)));
CAMLreturn(result);
Expand Down Expand Up @@ -822,12 +822,11 @@ CAMLprim LLVMValueRef llvm_mdnull(LLVMContextRef C) {
/* llvalue -> string option */
CAMLprim value llvm_get_mdstring(LLVMValueRef V) {
CAMLparam0();
CAMLlocal2(Option, Str);
const char *S;
unsigned Len;

if ((S = LLVMGetMDString(V, &Len))) {
CAMLlocal2(Option, Str);

Str = caml_alloc_string(Len);
memcpy(String_val(Str), S, Len);
Option = alloc(1,0);
Expand Down

0 comments on commit c07f8c1

Please sign in to comment.