From 4863af7c895c0165de9137155bebb8a9d4948212 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Fri, 7 Nov 2014 11:15:58 +0300 Subject: [PATCH] validation, struct_assignment: add some tests Signed-off-by: Dan Carpenter --- validation/sm_inline3.c | 40 ++++++++++++++++++++++++++++++++++++++++ validation/sm_struct_assign1.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 validation/sm_inline3.c create mode 100644 validation/sm_struct_assign1.c diff --git a/validation/sm_inline3.c b/validation/sm_inline3.c new file mode 100644 index 00000000..fbf900bd --- /dev/null +++ b/validation/sm_inline3.c @@ -0,0 +1,40 @@ +#include "check_debug.h" +#include "test.h" + +void memset(void *p, char pat, int size); + +struct foo { + int a, b; +}; + +void my_func(struct foo *p) +{ + memset(p, 0, sizeof(*p)); + p->a = 1; +} + +struct foo *my_pointer; + +void test(void) +{ + struct foo foo; + + my_func(my_pointer); + my_func(&foo); + __smatch_implied(my_pointer->a); + __smatch_implied(my_pointer->b); + __smatch_implied(foo.a); + __smatch_implied(foo.b); +} + +/* + * check-name: smatch: inline #3 + * check-command: smatch -I.. sm_inline3.c + * + * check-output-start +sm_inline3.c:24 test() implied: my_pointer->a = '1' +sm_inline3.c:25 test() implied: my_pointer->b = '0' +sm_inline3.c:26 test() implied: foo.a = '1' +sm_inline3.c:27 test() implied: foo.b = '0' + * check-output-end + */ diff --git a/validation/sm_struct_assign1.c b/validation/sm_struct_assign1.c new file mode 100644 index 00000000..aa3067ec --- /dev/null +++ b/validation/sm_struct_assign1.c @@ -0,0 +1,31 @@ +#include "check_debug.h" + +void memcpy(void *dest, void *src, int size); +void memset(void *dest, char c, int size); + + +struct foo { + int x, y; +}; + +void test(void) +{ + struct foo src = {1, 41}; + struct foo dest; + + memcpy(&dest, &src, sizeof(dest)); + __smatch_implied(dest.x + dest.y); + memset(&dest, 0, sizeof(dest)); + __smatch_implied(dest.x + dest.y); + +} + +/* + * check-name: smatch struct assignment #1 + * check-command: smatch -I.. sm_struct_assign1.c + * + * check-output-start +sm_struct_assign1.c:17 test() implied: dest.x + dest.y = '42' +sm_struct_assign1.c:19 test() implied: dest.x + dest.y = '0' + * check-output-end + */ -- 2.11.4.GIT