diff --git a/examples/array5.c b/examples/array5.c new file mode 100644 index 0000000..02120d9 --- /dev/null +++ b/examples/array5.c @@ -0,0 +1,11 @@ +int main() { + int init = 1; + int a[5] = {init, 2, 3, 4, -5}; + int sum = 0; + + for(int i = 0; i < 5; i++) { + sum += a[i]; + } + + return sum; +} diff --git a/src/c/ast_equiv.rs b/src/c/ast_equiv.rs index aee2977..f1d32b6 100644 --- a/src/c/ast_equiv.rs +++ b/src/c/ast_equiv.rs @@ -88,11 +88,20 @@ impl IsEquiv for Initializer { fn is_equiv(&self, other: &Self) -> bool { match (self, other) { (Self::Expression(expr), Self::Expression(other_expr)) => expr.is_equiv(other_expr), + (Self::List(items), Self::List(other_items)) => items.is_equiv(other_items), _ => false, } } } +impl IsEquiv for InitializerListItem { + fn is_equiv(&self, other: &Self) -> bool { + self.designation.is_empty() + && other.designation.is_empty() + && self.initializer.is_equiv(&other.initializer) + } +} + impl IsEquiv for Declarator { fn is_equiv(&self, other: &Self) -> bool { self.kind.is_equiv(&other.kind) && self.derived.is_equiv(&other.derived) diff --git a/src/c/parse.rs b/src/c/parse.rs index 9b46237..16eba49 100644 --- a/src/c/parse.rs +++ b/src/c/parse.rs @@ -208,11 +208,18 @@ impl AssertSupported for Initializer { fn assert_supported(&self) { match self { Self::Expression(expr) => expr.assert_supported(), - Self::List(_) => panic!("Initializer::List"), + Self::List(items) => items.assert_supported(), } } } +impl AssertSupported for InitializerListItem { + fn assert_supported(&self) { + assert!(self.designation.is_empty()); + self.initializer.assert_supported(); + } +} + impl AssertSupported for Declarator { fn assert_supported(&self) { self.kind.assert_supported(); diff --git a/src/ir/mod.rs b/src/ir/mod.rs index 486ae93..7eef6e7 100644 --- a/src/ir/mod.rs +++ b/src/ir/mod.rs @@ -611,10 +611,9 @@ impl TryFrom<&ast::Initializer> for Constant { type Error = (); fn try_from(initializer: &ast::Initializer) -> Result { - if let ast::Initializer::Expression(expr) = &initializer { - Self::try_from(&expr.node) - } else { - Err(()) + match initializer { + ast::Initializer::Expression(expr) => Self::try_from(&expr.node), + ast::Initializer::List(_) => todo!(), } } } diff --git a/tests/fuzz.py b/tests/fuzz.py index 7c7f27d..ee3d61c 100644 --- a/tests/fuzz.py +++ b/tests/fuzz.py @@ -57,6 +57,9 @@ REPLACE_DICT = { # "typedef struct[^\n]*\n{[^}]*}[^;]*;": "", # "typedef struct[^{]{[^}]*}": "typedef int", # "struct _IO_FILE": "int", + # "FILE *": "void *", + # "typedef __fpos_t fpos_t;": "", + # "fpos_t *": "void *", } CSMITH_DIR = "csmith-2.3.0"