Skip to content

Instantly share code, notes, and snippets.

@dschwen
Created October 21, 2017 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dschwen/29a7a49e0f99c6f891af4bd0ff27779a to your computer and use it in GitHub Desktop.
Save dschwen/29a7a49e0f99c6f891af4bd0ff27779a to your computer and use it in GitHub Desktop.
Small code to demonstrate a LibJIT bug
#include <stdio.h>
#include <jit/jit.h>
#include <jit/jit-dump.h>
typedef double (*JITFunctionPtr)();
int main(int argc, char **argv)
{
jit_context_t context;
jit_type_t signature;
jit_function_t function;
jit_value_t temp1;
context = jit_context_create();
jit_context_build_start(context);
signature = jit_type_create_signature(jit_abi_cdecl, jit_type_float64, NULL, 0, 1);
function = jit_function_create(context, signature);
// jit_function_set_optimization_level(function, JIT_OPTLEVEL_NONE);
jit_type_free(signature);
/* This is broken */
temp1 = jit_insn_to_bool(function, jit_value_create_float64_constant(function, jit_type_float64, (jit_float64)2.0));
jit_insn_return(function, temp1);
jit_dump_function(stdout, function, 0);
jit_function_compile(function);
jit_dump_function(stdout, function, 0);
jit_context_build_end(context);
JITFunctionPtr closure = (JITFunctionPtr)(jit_function_to_closure(function));
printf("result = %f\n", closure());
jit_context_destroy(context);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment