OCamlPro / owi

WebAssembly Swissknife & cross-language bugfinder
https://ocamlpro.github.io/owi/
GNU Affero General Public License v3.0
136 stars 17 forks source link

warning: function signature mismatch #270

Closed zapashcanon closed 1 month ago

zapashcanon commented 5 months ago
$ owi c --debug -O1 sv-benchmarks/c/busybox-1.22.0/ls-incomplete-2.i 
wasm-ld-18: warning: function signature mismatch: time
>>> defined as (i32) -> i32 in lto.tmp
>>> defined as (i32) -> i64 in /home/zapashcanon/.config/opam/5.1.0/share/owi/binc/libc.wasm
typechecking ...
type mismatch (typecheck_expr 1)
zapashcanon commented 1 month ago

I'm also getting:

$ owi c ./ptr.c --fail-on-assertion-only
wasm-ld-18: warning: function signature mismatch: free
>>> defined as (i32) -> i32 in lto.tmp
>>> defined as (i32) -> void in /home/zapashcanon/.config/opam/5.1.0/share/owi/binc/libc.wasm
All OK

With this code:

#include <stddef.h>
#include <owi.h>

double fabs(double x) {
  return x < 0 ? -x : x;
}

double *map(double (*f)(double), double *array, size_t len) {

  double *new_array = malloc(sizeof(double) * len);
  for (int i = 0; i < len; i++) {
    new_array[i] = f(array[i]);
  }
  return new_array;
}

void main(void) {
  size_t len = 16;
  double *array = malloc(sizeof(double) * len);

  for (int i = 0; i < len; i++) {
    array[i] = owi_f64();
  }

  double *new_array = map(fabs, array, len);

  free(array);

  for (int i = 0; i < len; i++) {
    owi_assert(new_array[i] >= 0);
  }

  free(new_array);

  return 0;
}
filipeom commented 1 month ago

The first one is probably because the program is specifying a time function with another type or it's not importing the function through its standard .h.

For your example use #include <stdlib.h> instead of stddef.h

zapashcanon commented 1 month ago

OK, and it seems that the first example is no more giving a type error so I'm closing. :)