Skip to content

Sizeof function causes fatal error

Summary

In certain cases, when a function returns template and the sizeof function is used on the returning template causes FATAL_ERROR in the compiler stopping the code generation completely.

Steps and/or TTCN-3 code to reproduce

The following code reproduces the issue:

// lengthof and sizeof (with functions returning templates)
type record Rec {
  integer a optional,
  boolean b
}

type record of Rec Rec_of;

function f2() return template Rec_of {
  var template Rec_of x;
  x[0].a := 0;
  x[0].b := ?;
  x[1].a := omit;
  x[1].b := false;
  return x;
}

function f3() return template Rec {
  var template Rec t_rec := { ?, true };
  return t_rec;
}

template Rec_of RoIret_global := f2();
template Rec rec_global := f3();

testcase tc_predef_sizeof_lengthof_func_rtemp() runs on CT {
  template Rec_of RoIret_local := f2(); 
  var template Rec_of RoIret_local_var := f2();
  var integer size := lengthof(RoIret_global);
  if (size != 2) {
    setverdict(fail, "#1: ", size);
  }
  
  size := lengthof(RoIret_local);
  if (size != 2) {
    setverdict(fail, "#2: ", size);
  }
  
  size := lengthof(RoIret_local_var);
  if (size != 2) {
    setverdict(fail, "#3: ", size);
  }
  
  size := sizeof(rec_global);
  if (size != 2) {
    setverdict(fail, "#4: ", size);
  }
  
  size := sizeof(RoIret_global);
  if (size != 2) {
    setverdict(fail, "#5: ", size);
  }
  
  size := sizeof(RoIret_local);
  if (size != 2) {
    setverdict(fail, "#6: ", size);
  }
  
  size := sizeof(RoIret_local_var);
  if (size != 2) {
    setverdict(fail, "#7: ", size);
  }
  setverdict(pass);
}

What is the current bug behavior?

FATAL_ERROR happens

What is the expected correct behavior?

Compile without error

Titan version

Titan 9.0.0

/cc @aknappqwt