elliotchance/c2go

`array_filler` prefix of AST ImplicitValueInitExpr node not yet supported; as used to implicitly initialize arrays

mewmew opened this issue · 0 comments

The array_filler prefix of the ImplicitValueInitExpr AST node is yet to be supported by c2go. This AST node is emitted by Clang when the input source file contains array variables that are initialized with an array literal, but the array literal has fewer elements than the array length. Thus an implicit initialization is required, as denoted by the ImplicitValueInitExpr AST node.

Example

Contents of l.c:

int f(int x) {
	int foo[4] = {1, 2, 3};
	return 42;
}

Panic

$ c2go transpile l.c
panic: unknown node type: 'array_filler: ImplicitValueInitExpr 0x5652b1a1faf8 <<invalid sloc>> 'int''

goroutine 25 [running]:
github.com/elliotchance/c2go/ast.Parse(0xc00016e5b4, 0x49, 0x6aff59, 0x5)

AST output

The AST of l.c looks as follows:

$ c2go ast l.c
TranslationUnitDecl 0x55eab61739f8 <<invalid sloc>> <invalid sloc>
|-TypedefDecl 0x55eab6174290 <<invalid sloc>> <invalid sloc> implicit __int128_t '__int128'
| `-BuiltinType 0x55eab6173f90 '__int128'
|-TypedefDecl 0x55eab6174300 <<invalid sloc>> <invalid sloc> implicit __uint128_t 'unsigned __int128'
| `-BuiltinType 0x55eab6173fb0 'unsigned __int128'
|-TypedefDecl 0x55eab61745e8 <<invalid sloc>> <invalid sloc> implicit __NSConstantString 'struct __NSConstantString_tag'
| `-RecordType 0x55eab61743e0 'struct __NSConstantString_tag'
|   `-Record 0x55eab6174358 '__NSConstantString_tag'
|-TypedefDecl 0x55eab6174680 <<invalid sloc>> <invalid sloc> implicit __builtin_ms_va_list 'char *'
| `-PointerType 0x55eab6174640 'char *'
|   `-BuiltinType 0x55eab6173a90 'char'
|-TypedefDecl 0x55eab6174958 <<invalid sloc>> <invalid sloc> implicit __builtin_va_list 'struct __va_list_tag [1]'
| `-ConstantArrayType 0x55eab6174900 'struct __va_list_tag [1]' 1 
|   `-RecordType 0x55eab6174760 'struct __va_list_tag'
|     `-Record 0x55eab61746d8 '__va_list_tag'
`-FunctionDecl 0x55eab61d27d0 </home/u/Desktop/ccc/l/l.c:1:1, line:4:1> line:1:5 f 'int (int)'
  |-ParmVarDecl 0x55eab61d2700 <col:7, col:11> col:11 x 'int'
  `-CompoundStmt 0x55eab61d2b50 <col:14, line:4:1>
    |-DeclStmt 0x55eab61d2b08 <line:2:2, col:24>
    | `-VarDecl 0x55eab61d2960 <col:2, col:23> col:6 foo 'int [4]' cinit
    |   `-InitListExpr 0x55eab61d2a80 <col:15, col:23> 'int [4]'
    |     |-array_filler: ImplicitValueInitExpr 0x55eab61d2af8 <<invalid sloc>> 'int'
    |     |-IntegerLiteral 0x55eab61d29c8 <col:16> 'int' 1
    |     |-IntegerLiteral 0x55eab61d29e8 <col:19> 'int' 2
    |     `-IntegerLiteral 0x55eab61d2a08 <col:22> 'int' 3
    `-ReturnStmt 0x55eab61d2b40 <line:3:2, col:9>
      `-IntegerLiteral 0x55eab61d2b20 <col:9> 'int' 42

Additional information

For comparison, the following source file which is almost identical to l.c does not produce the ImplicitValueInitExpr AST node (as it does not require implicit initialization of the array).

int f(int x) {
	int foo[4] = {1, 2, 3, 4};
	return 42;
}