Closed aaronjeline closed 4 years ago
I'm not sure I understand this syntax. What's the difference between this and int *coef[10]
which presumably is no problem?
Referencing cdecl.org
:
int *ceof[10];
-> "declare ceof as array 10 of pointer to int"
int (*coef)[10];
-> "declare ceof as pointer to array 10 of int"
And yes, the no-parens type converts fine. This behavior was found looking at libtiff, which references libjpeg, which uses this syntax.
Here's what I see with -ast-dump
int *x[10];
int (*y)[10];
|-VarDecl 0x7fd5fd0906a0 <a.c:1:1, col:10> col:6 x 'int *[10]'
`-VarDecl 0x7fd5fd090890 <line:2:1, col:12> col:7 y 'int (*)[10]'
Maybe this means that y
is equivalent to
int arr[10];
int *y = arr;
(i.e., it's the same as auto-promoting to a pointer to an array) ???
But in ast-dump
it looks different:
|-VarDecl 0x7ff33a890660 <a.c:1:1, col:11> col:5 used arr 'int [10]'
`-VarDecl 0x7ff33a890750 <line:2:1, col:10> col:6 y 'int *' cinit
`-ImplicitCastExpr 0x7ff33a8907d8 <col:10> 'int *' <ArrayToPointerDecay>
`-DeclRefExpr 0x7ff33a8907b8 <col:10> 'int [10]' lvalue Var 0x7ff33a890660 'arr' 'int [10]'
So: We obviously need to figure out what this is, exactly, to know how to handle it. Wacky.
void foo(void) {
int (*coef)[10];
int *other[10];
}
Dumps to the following:
`-FunctionDecl 0x55bc5922ad70 <array.c:3:1, line:6:1> line:3:6 foo 'void (void)'
`-CompoundStmt 0x55bc5922b1a8 <col:16, line:6:1>
|-DeclStmt 0x55bc5922b030 <line:4:3, col:18>
| `-VarDecl 0x55bc5922afb8 <col:3, col:17> col:9 coef 'int (*)[10]'
`-DeclStmt 0x55bc5922b190 <line:5:3, col:17>
`-VarDecl 0x55bc5922b118 <col:3, col:16> col:8 other 'int *[10]'
This is #110
Converting:
int (*coef)[10];
Causes the tool to crash with the following: