Skip to content

Bug: Ultimate C translation fails to annotate function contracts containing references to an array #753

@bahnwaerter

Description

@bahnwaerter

The current C translation fails to annotate function contracts that contain references to a statically allocated array. The references can come from a function contract that is either manually specified for a function in the program or retrieved automatically from a witness for witness validation. This issue can be reproduced with Ultimate Automizer (0.3.0-dev-8447f03 with OpenJDK 21.0.8) using the following input:

//#include <stdio.h>
/*-----------------------------------------------------------------------------
 * START included content from stdio.h
 *---------------------------------------------------------------------------*/
struct __sbuf {
  unsigned char *_base;
  int _size;
};

typedef long _fpos_t;

struct __sFILE {
  unsigned char *_p;
  int _r;
  int _w;
  short _flags;
  short _file;
  struct __sbuf _bf;
  int _lbfsize;
  void *_cookie;
  /* ... */
};
typedef struct __sFILE __FILE;
extern __FILE __sf[3];

struct _glue {
  struct _glue *_next;
  int _niobs;
  __FILE *_iobs;
};
extern struct _glue __sglue;
/*-----------------------------------------------------------------------------
 * END included content from stdio.h
 *---------------------------------------------------------------------------*/

int x = 0;

//@ ensures ((__sf == \old(__sf)) && (__sglue == \old(__sglue)));
void func(int i)
{
  /* ... */
}

int main()
{
  int ret;
  while (ret) {
    func(x);
  }
  //@ assert (x >= 0);
  return ret;
}

The example program demonstrates a problem that occurs when validating witnesses. The function contract for function func is retrieved from a witness and uses the postcondition pattern of the form x == \old(x) to express that the function does not modify the variable or memory x. If a statically allocated array must be referenced here, Ultimate crashes with the following stack trace:

The Plugin de.uni_freiburg.informatik.ultimate.plugins.generator.cacsl2boogietranslator has thrown an exception:
java.lang.AssertionError: on-heap/off-heap bug: array has to be on-heap
	at de.uni_freiburg.informatik.ultimate.cdt.translation.implementation.base.CHandler.moveArrayAndStructIdsOnHeap(CHandler.java:3058)
	at de.uni_freiburg.informatik.ultimate.cdt.translation.implementation.result.ExpressionResultTransformer.switchToRValue(ExpressionResultTransformer.java:240)
	at de.uni_freiburg.informatik.ultimate.cdt.translation.implementation.result.ExpressionResultTransformer.switchToRValueUnchecked(ExpressionResultTransformer.java:306)
	at de.uni_freiburg.informatik.ultimate.cdt.translation.implementation.base.ACSLHandler.dispatchSwitch(ACSLHandler.java:414)
	at de.uni_freiburg.informatik.ultimate.cdt.translation.implementation.base.ACSLHandler.visit(ACSLHandler.java:421)
	at de.uni_freiburg.informatik.ultimate.cdt.translation.implementation.base.MainDispatcher.dispatch(MainDispatcher.java:305)

Following the ACSL standard, this should be possible and Ultimate should not crash.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions