From 200668b3b6c47cec453cdc669edfb758bd465218 Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Fri, 26 Mar 2021 14:53:43 -0700 Subject: [PATCH] [sledge][llvm] Resolve const and unsigned compilation warnings Summary: There are a number of compilation warnings regarding disregarding const qualifiers, and casting between pointers to integer types with different sign. The incompatible sign warnings are due to treating the result of `LLVMGetModuleIdentifier` as `const unsigned char *`, but it is declared as `const char *`. The dropped const qualifiers are due to the code pattern `memcpy(String_val(_),_,_)` which ought to be (following the implementation of the OCaml runtime) `memcpy((char *)String_val(_),_,_)`. The issue is that `String_val` is usually used to get the value of an immutable string. But in the context of the `memcpy` calls, the string is in the process of being initialized, so is not yet constant. Upstream Differential Revision: https://reviews.llvm.org/D99392 Reviewed By: ngorogiannis Differential Revision: D27360846 fbshipit-source-id: d045ad7c0 --- .../llvm/bindings/ocaml/llvm/llvm_ocaml.c | 12 ++++++------ .../llvm/bindings/ocaml/target/target_ocaml.c | 2 +- .../llvm/bindings/ocaml/transforms/ipo/ipo_ocaml.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sledge/vendor/llvm-dune/llvm-project/llvm/bindings/ocaml/llvm/llvm_ocaml.c b/sledge/vendor/llvm-dune/llvm-project/llvm/bindings/ocaml/llvm/llvm_ocaml.c index a1c201a3e..96cb0e0d5 100644 --- a/sledge/vendor/llvm-dune/llvm-project/llvm/bindings/ocaml/llvm/llvm_ocaml.c +++ b/sledge/vendor/llvm-dune/llvm-project/llvm/bindings/ocaml/llvm/llvm_ocaml.c @@ -76,7 +76,7 @@ CAMLprim value llvm_enable_pretty_stacktrace(value Unit) { } CAMLprim value llvm_parse_command_line_options(value Overview, value Args) { - char *COverview; + const char *COverview; if (Overview == Val_int(0)) { COverview = NULL; } else { @@ -247,7 +247,7 @@ CAMLprim value llvm_get_string_attr_kind(LLVMAttributeRef A) { unsigned Length; const char *String = LLVMGetStringAttributeKind(A, &Length); value Result = caml_alloc_string(Length); - memcpy(String_val(Result), String, Length); + memcpy((char *)String_val(Result), String, Length); return Result; } @@ -256,7 +256,7 @@ CAMLprim value llvm_get_string_attr_value(LLVMAttributeRef A) { unsigned Length; const char *String = LLVMGetStringAttributeValue(A, &Length); value Result = caml_alloc_string(Length); - memcpy(String_val(Result), String, Length); + memcpy((char *)String_val(Result), String, Length); return Result; } @@ -839,7 +839,7 @@ CAMLprim value llvm_get_mdstring(LLVMValueRef V) { if ((S = LLVMGetMDString(V, &Len))) { Str = caml_alloc_string(Len); - memcpy(String_val(Str), S, Len); + memcpy((char *)String_val(Str), S, Len); Option = alloc(1,0); Store_field(Option, 0, Str); CAMLreturn(Option); @@ -1117,7 +1117,7 @@ CAMLprim value llvm_string_of_const(LLVMValueRef Const) { if(LLVMIsAConstantDataSequential(Const) && LLVMIsConstantString(Const)) { S = LLVMGetAsString(Const, &Len); Str = caml_alloc_string(Len); - memcpy(String_val(Str), S, Len); + memcpy((char *)String_val(Str), S, Len); Option = alloc(1, 0); Field(Option, 0) = Str; @@ -2640,7 +2640,7 @@ CAMLprim LLVMMemoryBufferRef llvm_memorybuffer_of_string(value Name, value Strin /* llmemorybuffer -> string */ CAMLprim value llvm_memorybuffer_as_string(LLVMMemoryBufferRef MemBuf) { value String = caml_alloc_string(LLVMGetBufferSize(MemBuf)); - memcpy(String_val(String), LLVMGetBufferStart(MemBuf), + memcpy((char *)String_val(String), LLVMGetBufferStart(MemBuf), LLVMGetBufferSize(MemBuf)); return String; diff --git a/sledge/vendor/llvm-dune/llvm-project/llvm/bindings/ocaml/target/target_ocaml.c b/sledge/vendor/llvm-dune/llvm-project/llvm/bindings/ocaml/target/target_ocaml.c index cf48fbe45..efe7ea20b 100644 --- a/sledge/vendor/llvm-dune/llvm-project/llvm/bindings/ocaml/target/target_ocaml.c +++ b/sledge/vendor/llvm-dune/llvm-project/llvm/bindings/ocaml/target/target_ocaml.c @@ -314,7 +314,7 @@ CAMLprim value llvm_targetmachine_emit_to_file(LLVMModuleRef Module, char *ErrorMessage; if(LLVMTargetMachineEmitToFile(TargetMachine_val(Machine), Module, - String_val(FileName), Int_val(FileType), + (char *)String_val(FileName), Int_val(FileType), &ErrorMessage)) { llvm_raise(*caml_named_value("Llvm_target.Error"), ErrorMessage); } diff --git a/sledge/vendor/llvm-dune/llvm-project/llvm/bindings/ocaml/transforms/ipo/ipo_ocaml.c b/sledge/vendor/llvm-dune/llvm-project/llvm/bindings/ocaml/transforms/ipo/ipo_ocaml.c index 729b54dc6..3ee5ae791 100644 --- a/sledge/vendor/llvm-dune/llvm-project/llvm/bindings/ocaml/transforms/ipo/ipo_ocaml.c +++ b/sledge/vendor/llvm-dune/llvm-project/llvm/bindings/ocaml/transforms/ipo/ipo_ocaml.c @@ -123,7 +123,7 @@ LLVMBool MustPreserveCallBack(LLVMValueRef Val, void* Ctx) { /* [`Module] Llvm.PassManager.t -> unit */ CAMLprim value llvm_add_internalize_predicate(LLVMPassManagerRef PM) { - predicate_f = caml_named_value("LLVMInternalizePredicateCallback"); + predicate_f = (value *)caml_named_value("LLVMInternalizePredicateCallback"); LLVMAddInternalizePassWithMustPreservePredicate(PM, NULL, &MustPreserveCallBack); return Val_unit;