From 11790583f4fda97bdd44542e15cbb957480820e7 Mon Sep 17 00:00:00 2001 From: Julian Erhard Date: Fri, 2 Dec 2022 10:49:36 +0100 Subject: [PATCH 1/5] Add race test case to incremental benchmarks. --- .../00-basic/13-anonymous-compound.c | 33 +++++++++++++++++++ .../00-basic/13-anonymous-compound.json | 2 ++ .../00-basic/13-anonymous-compound.patch | 29 ++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 tests/incremental/00-basic/13-anonymous-compound.c create mode 100644 tests/incremental/00-basic/13-anonymous-compound.json create mode 100644 tests/incremental/00-basic/13-anonymous-compound.patch diff --git a/tests/incremental/00-basic/13-anonymous-compound.c b/tests/incremental/00-basic/13-anonymous-compound.c new file mode 100644 index 0000000000..69b2e58e83 --- /dev/null +++ b/tests/incremental/00-basic/13-anonymous-compound.c @@ -0,0 +1,33 @@ +#include + +typedef struct foo_struct { + union { + int i; + struct inner_struct { + int head, tail; + } coin; + }; +} foo_t; + +foo_t str; + +void *read(void *ptr){ + int x = str.coin.head; // RACE! + int a = 32; + return NULL; +} + +void *write(void *ptr){ + str.coin.head = 23; // RACE! + return NULL; +} + +int main(){ + pthread_t r; + pthread_t w; + + pthread_create(&r, NULL, read, NULL); + pthread_create(&w, NULL, write, NULL); + + return 0; +} diff --git a/tests/incremental/00-basic/13-anonymous-compound.json b/tests/incremental/00-basic/13-anonymous-compound.json new file mode 100644 index 0000000000..2c63c08510 --- /dev/null +++ b/tests/incremental/00-basic/13-anonymous-compound.json @@ -0,0 +1,2 @@ +{ +} diff --git a/tests/incremental/00-basic/13-anonymous-compound.patch b/tests/incremental/00-basic/13-anonymous-compound.patch new file mode 100644 index 0000000000..244b0657d6 --- /dev/null +++ b/tests/incremental/00-basic/13-anonymous-compound.patch @@ -0,0 +1,29 @@ +diff --git tests/incremental/00-basic/13-anonymous-compound.c tests/incremental/00-basic/13-anonymous-compound.c +index 69b2e58e8..3f3398092 100644 +--- tests/incremental/00-basic/13-anonymous-compound.c ++++ tests/incremental/00-basic/13-anonymous-compound.c +@@ -1,5 +1,15 @@ + #include + ++typedef struct bar { ++ union{ ++ int x; ++ struct inner { ++ int a; ++ int b; ++ } i; ++ }; ++} bar_t; ++ + typedef struct foo_struct { + union { + int i; +@@ -13,7 +23,7 @@ foo_t str; + + void *read(void *ptr){ + int x = str.coin.head; // RACE! +- int a = 32; ++ int a = str.coin.head; // RACE! + return NULL; + } + From e15471016f7a18d34b0d6a231837f7c760a7a373 Mon Sep 17 00:00:00 2001 From: Julian Erhard Date: Mon, 5 Dec 2022 11:04:53 +0100 Subject: [PATCH 2/5] Change test case for issue 678 --- .../00-basic/13-anonymous-compound.c | 2 +- .../00-basic/13-anonymous-compound.patch | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/tests/incremental/00-basic/13-anonymous-compound.c b/tests/incremental/00-basic/13-anonymous-compound.c index 69b2e58e83..3e2d7b527f 100644 --- a/tests/incremental/00-basic/13-anonymous-compound.c +++ b/tests/incremental/00-basic/13-anonymous-compound.c @@ -26,8 +26,8 @@ int main(){ pthread_t r; pthread_t w; - pthread_create(&r, NULL, read, NULL); pthread_create(&w, NULL, write, NULL); + pthread_create(&r, NULL, read, NULL); return 0; } diff --git a/tests/incremental/00-basic/13-anonymous-compound.patch b/tests/incremental/00-basic/13-anonymous-compound.patch index 244b0657d6..d3b656144d 100644 --- a/tests/incremental/00-basic/13-anonymous-compound.patch +++ b/tests/incremental/00-basic/13-anonymous-compound.patch @@ -1,10 +1,16 @@ diff --git tests/incremental/00-basic/13-anonymous-compound.c tests/incremental/00-basic/13-anonymous-compound.c -index 69b2e58e8..3f3398092 100644 +index 3e2d7b527..81f3e704a 100644 --- tests/incremental/00-basic/13-anonymous-compound.c +++ tests/incremental/00-basic/13-anonymous-compound.c -@@ -1,5 +1,15 @@ +@@ -1,5 +1,21 @@ #include - + ++ ++typedef struct foo_bar { ++ int x; ++ int y; ++} foo_bar_t; ++ +typedef struct bar { + union{ + int x; @@ -12,18 +18,17 @@ index 69b2e58e8..3f3398092 100644 + int a; + int b; + } i; -+ }; ++ } un; +} bar_t; + typedef struct foo_struct { union { int i; -@@ -13,7 +23,7 @@ foo_t str; - +@@ -13,6 +29,7 @@ foo_t str; + void *read(void *ptr){ int x = str.coin.head; // RACE! -- int a = 32; -+ int a = str.coin.head; // RACE! ++ int y = str.coin.head; // RACE! + int a = 32; return NULL; } - From 20d01b13fcad94e39f552e38f8b159dcad717aee Mon Sep 17 00:00:00 2001 From: Julian Erhard Date: Mon, 5 Dec 2022 11:12:00 +0100 Subject: [PATCH 3/5] Add another test for issue 678 --- tests/incremental/00-basic/14-struct.c | 33 ++++++++++++++++++++++ tests/incremental/00-basic/14-struct.json | 2 ++ tests/incremental/00-basic/14-struct.patch | 23 +++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 tests/incremental/00-basic/14-struct.c create mode 100644 tests/incremental/00-basic/14-struct.json create mode 100644 tests/incremental/00-basic/14-struct.patch diff --git a/tests/incremental/00-basic/14-struct.c b/tests/incremental/00-basic/14-struct.c new file mode 100644 index 0000000000..6eadc7a577 --- /dev/null +++ b/tests/incremental/00-basic/14-struct.c @@ -0,0 +1,33 @@ +#include + +typedef struct foo_struct { + union { + int i; + struct inner_struct { + int head, tail; + } coin; + } un; +} foo_t; + +foo_t str; + +void *read(void *ptr){ + int x = str.un.coin.head; // RACE! + int a = 32; + return NULL; +} + +void *write(void *ptr){ + str.un.coin.head = 23; // RACE! + return NULL; +} + +int main(){ + pthread_t r; + pthread_t w; + + pthread_create(&w, NULL, write, NULL); + pthread_create(&r, NULL, read, NULL); + + return 0; +} diff --git a/tests/incremental/00-basic/14-struct.json b/tests/incremental/00-basic/14-struct.json new file mode 100644 index 0000000000..2c63c08510 --- /dev/null +++ b/tests/incremental/00-basic/14-struct.json @@ -0,0 +1,2 @@ +{ +} diff --git a/tests/incremental/00-basic/14-struct.patch b/tests/incremental/00-basic/14-struct.patch new file mode 100644 index 0000000000..8232a345e8 --- /dev/null +++ b/tests/incremental/00-basic/14-struct.patch @@ -0,0 +1,23 @@ +diff --git tests/incremental/00-basic/14-struct.c tests/incremental/00-basic/14-struct.c +index 6eadc7a57..568a90aed 100644 +--- tests/incremental/00-basic/14-struct.c ++++ tests/incremental/00-basic/14-struct.c +@@ -1,5 +1,10 @@ + #include + ++typedef struct foo_bar { ++ int x; ++ int y; ++} foo_bar_t; ++ + typedef struct foo_struct { + union { + int i; +@@ -12,6 +17,7 @@ typedef struct foo_struct { + foo_t str; + + void *read(void *ptr){ ++ int x = str.un.coin.head; // RACE! + int x = str.un.coin.head; // RACE! + int a = 32; + return NULL; From fec7d0ea4bedf1ba7cc747d9bc08740a1eb73e85 Mon Sep 17 00:00:00 2001 From: Julian Erhard Date: Mon, 5 Dec 2022 18:01:04 +0100 Subject: [PATCH 4/5] Reset ckeys for anonymous strcuts/unions. The cnames of anonymous structs and unions are fragile between program versions. The cnames were already reset, this also resets the ckeys. --- src/incremental/compareAST.ml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/incremental/compareAST.ml b/src/incremental/compareAST.ml index c0300f9e59..c82edb5d3f 100644 --- a/src/incremental/compareAST.ml +++ b/src/incremental/compareAST.ml @@ -99,10 +99,15 @@ and eq_typ_acc (a: typ) (b: typ) ~(acc: (typ * typ) list) ~(rename_mapping: rena else ( let acc = (a, b) :: acc in let res = eq_compinfo compinfo1 compinfo2 acc rename_mapping && GobList.equal (eq_attribute ~rename_mapping ~acc) attr1 attr2 in - if res && compinfo1.cname <> compinfo2.cname then - compinfo2.cname <- compinfo1.cname; - if res then + if res then begin global_typ_acc := (a, b) :: !global_typ_acc; + + (* Reset cnames and ckeys to the old value. Only affects anonymous structs/unions where names are not checked for equality. *) + if compinfo1.cname <> compinfo2.cname then + compinfo2.cname <- compinfo1.cname; + if compinfo1.ckey <> compinfo2.ckey then + compinfo2.ckey <- compinfo1.ckey; + end; res ) | TEnum (enuminfo1, attr1), TEnum (enuminfo2, attr2) -> let res = eq_enuminfo enuminfo1 enuminfo2 ~rename_mapping ~acc && GobList.equal (eq_attribute ~rename_mapping ~acc) attr1 attr2 in (if res && enuminfo1.ename <> enuminfo2.ename then enuminfo2.ename <- enuminfo1.ename); res From 07ad8f5609cd70fc1cb2c3d614c65e1765d18631 Mon Sep 17 00:00:00 2001 From: Julian Erhard Date: Tue, 6 Dec 2022 11:25:52 +0100 Subject: [PATCH 5/5] Remove checks for in-equality before reseting cname and ckey. If they are already the same, the assignment would have no (negative) effect; so one can avoid the branching. --- src/incremental/compareAST.ml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/incremental/compareAST.ml b/src/incremental/compareAST.ml index c82edb5d3f..671effcad6 100644 --- a/src/incremental/compareAST.ml +++ b/src/incremental/compareAST.ml @@ -103,10 +103,8 @@ and eq_typ_acc (a: typ) (b: typ) ~(acc: (typ * typ) list) ~(rename_mapping: rena global_typ_acc := (a, b) :: !global_typ_acc; (* Reset cnames and ckeys to the old value. Only affects anonymous structs/unions where names are not checked for equality. *) - if compinfo1.cname <> compinfo2.cname then - compinfo2.cname <- compinfo1.cname; - if compinfo1.ckey <> compinfo2.ckey then - compinfo2.ckey <- compinfo1.ckey; + compinfo2.cname <- compinfo1.cname; + compinfo2.ckey <- compinfo1.ckey; end; res )