[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
master
Josh Berdine 4 years ago committed by Facebook GitHub Bot
parent 68c15476c3
commit 200668b3b6

@ -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;

@ -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);
}

@ -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;

Loading…
Cancel
Save