Expand initializers when testing them for being constant
PATCH 1/1 Expand initializers when testing them for being constant
Signed-off-by Pavel Roskin <[email protected]>
---
expand.c | 2 ++ validation/array-size-known.c | 9 +++++++++ validation/array-size-unknown.c | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 0 deletions(-) create mode 100644 validation/array-size-known.c create mode 100644 validation/array-size-unknown.c
expand.c +2 -0
@@ -620,6 +620,8 @@ static int expand_dereference(struct expression *expr)/* Const symbol with a constant initializer? */ if (value) { +expand_expression (value); +/* FIXME! We should check that the size is right! */ if (value->type ==EXPR_VALUE ) { expr->type =EXPR_VALUE ;
validation/array-size-known.c new file +9 -0
@@ -0,0 +1,9 @@ +void foo (void ); +void foo (void ) { +const int len =32 +32 ; +int buf[len]; + buf[0 ] =0 ; +} +/* +* check-name: Array size known at the compile time +*/
validation/array-size-unknown.c new file +14 -0
@@ -0,0 +1,14 @@ +extern int extra; +void foo (void ); +void foo (void ) { +const int len =32 + extra; +int buf[len]; + buf[0 ] =0 ; +} +/* +* check-name: Array size unknown at the compile time +* +* check-error-start +array-size-unknown.c:5:10: error: bad constant expression +* check-error-end +*/