llvm-cbe icon indicating copy to clipboard operation
llvm-cbe copied to clipboard

flexible array members broken

Open spth opened this issue 9 years ago • 0 comments

The C backend currently omits members of size zero in structs. I.e. if I compile this test.c with clang:

struct tst {
  int a, b;
  int p[];
};

struct tst w;

Getting e.g. this test.ll:

; ModuleID = 'test.c'
target datalayout = "E-p:16:8:8-i1:8:8-i8:8:8-i16:8:8-i32:8:8-i64:8:8-f32:8:8-a:8:8"
target triple = "sdcc-stm8"

%struct.tst = type { i16, i16, [0 x i16] }

@w = common global %struct.tst zeroinitializer, align 1

!llvm.ident = !{!0}

!0 = !{!"clang version 3.8.1 "}

The C backend generates code containing:

/* Types Definitions */
struct l_struct_struct_OC_tst {
  uint16_t field0;
  uint16_t field1;
  /* void field2 */};

/* Function definitions */

/* External Global Variable Declarations */
extern struct l_struct_struct_OC_tst w;

But it will generate code that refers to field2, if the original input did refer to the flexible array member. Thus the output from the C backend will not compile. The C backend should instead emit field2 as a flexible array member.

Philipp

spth avatar Oct 23 '16 20:10 spth