Commit 19526d40 authored by Daniel Kochmański's avatar Daniel Kochmański

cmpffi: produce-inline-loc: do not return uninitialized variable

For functions without returned value we did return cl_object value0
which was not initialized. That could lead to segmentation faults if
we have used result of calling a function defined as such location.

SFFI definition like this:

(ffi:def-function ("my_test_function3" sffi-test-3)
    ((x :float) (y :double))
  :returning :void)

was previously compiled to

/*      function definition for SFFI-TEST-3                     */
/*      optimize speed 3, debug 0, space 0, safety 2            */
static cl_object L6sffi_test_3(cl_object v1x, cl_object v2y)
{
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
 {
TTL:
  my_test_function3(ecl_to_float(v1x),ecl_to_double(v2y));
  cl_env_copy->nvalues = 0;
  return value0;
 }
}

and now it is compiled to

/*      function definition for SFFI-TEST-3                       */
/*      optimize speed 3, debug 0, space 0, safety 2              */
static cl_object L6sffi_test_3(cl_object v1x, cl_object v2y)
{
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
 {
TTL:
  my_test_function3(ecl_to_float(v1x),ecl_to_double(v2y));
  value0 = ECL_NIL;
  cl_env_copy->nvalues = 0;
  return value0;
 }
}

void functions are treated the same as when *destionation* is 'RETURN
in cmpmulti.lsp.
parent b2b6548a
......@@ -449,6 +449,7 @@
(wt-c-inline-loc output-rep-type c-expression coerced-arguments t nil)
(when one-liner (wt ";")))
(cmpnote "Ignoring form ~S" c-expression))
(wt-nl "value0 = ECL_NIL;")
(wt-nl "cl_env_copy->nvalues = 0;")
(return-from produce-inline-loc 'RETURN))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment