From c855b7b59fbc250b9266bc5cc6935aac411db717 Mon Sep 17 00:00:00 2001 From: thk123 Date: Thu, 26 Jan 2017 12:41:47 +0000 Subject: [PATCH 1/3] Keep track of types for structs and unions When dealing withs structs (and unions) we replace the type with a symbol for that type (that may or may not be new). However, if a struct is declared, we still need to track any qualifiers (e.g. a variable that is introduced as a const struct). --- src/ansi-c/c_typecheck_type.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ansi-c/c_typecheck_type.cpp b/src/ansi-c/c_typecheck_type.cpp index 879fbc34efc..3ee77eba3b0 100644 --- a/src/ansi-c/c_typecheck_type.cpp +++ b/src/ansi-c/c_typecheck_type.cpp @@ -820,7 +820,9 @@ void c_typecheck_baset::typecheck_compound_type(struct_union_typet &type) symbol_type.add_source_location()=type.source_location(); symbol_type.set_identifier(identifier); + c_qualifierst original_qualifiers(type); type.swap(symbol_type); + original_qualifiers.write(type); } /*******************************************************************\ From 286a19dca19685374888af6440229fe264dffa4c Mon Sep 17 00:00:00 2001 From: thk123 Date: Thu, 26 Jan 2017 12:45:55 +0000 Subject: [PATCH 2/3] Correcting test and adding to the suite The known bug related to this issue was checking the output was wrong, so made it check the correct output. Since it is now fixed, swapped it from KNOWNBUG to CORE. --- regression/goto-instrument/const-struct1/test.desc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/regression/goto-instrument/const-struct1/test.desc b/regression/goto-instrument/const-struct1/test.desc index 40306e23153..8575824dbcb 100644 --- a/regression/goto-instrument/const-struct1/test.desc +++ b/regression/goto-instrument/const-struct1/test.desc @@ -1,7 +1,7 @@ -KNOWNBUG +CORE main.c --show-symbol-table -^Type\.*: struct struct_tag_name$ +^Type\.*: const struct struct_tag_name$ ^Type\.*: const double$ ^EXIT=0$ ^SIGNAL=0$ From 0befb9d384b03d32eaca75930031ffdf748ff367 Mon Sep 17 00:00:00 2001 From: thk123 Date: Thu, 26 Jan 2017 14:05:32 +0000 Subject: [PATCH 3/3] Added tests for different cases Added cases for union types, for anonymous structs and for volatile variables (as opposed to const variables). Also added test for verifying the dump C output --- regression/goto-instrument/const-struct2/main.c | 10 ++++++++++ regression/goto-instrument/const-struct2/test.desc | 9 +++++++++ regression/goto-instrument/const-struct3/main.c | 13 +++++++++++++ regression/goto-instrument/const-struct3/test.desc | 9 +++++++++ regression/goto-instrument/const-union1/main.c | 13 +++++++++++++ regression/goto-instrument/const-union1/test.desc | 9 +++++++++ regression/goto-instrument/volatile-struct1/main.c | 13 +++++++++++++ .../goto-instrument/volatile-struct1/test.desc | 9 +++++++++ 8 files changed, 85 insertions(+) create mode 100644 regression/goto-instrument/const-struct2/main.c create mode 100644 regression/goto-instrument/const-struct2/test.desc create mode 100644 regression/goto-instrument/const-struct3/main.c create mode 100644 regression/goto-instrument/const-struct3/test.desc create mode 100644 regression/goto-instrument/const-union1/main.c create mode 100644 regression/goto-instrument/const-union1/test.desc create mode 100644 regression/goto-instrument/volatile-struct1/main.c create mode 100644 regression/goto-instrument/volatile-struct1/test.desc diff --git a/regression/goto-instrument/const-struct2/main.c b/regression/goto-instrument/const-struct2/main.c new file mode 100644 index 00000000000..adf97faf658 --- /dev/null +++ b/regression/goto-instrument/const-struct2/main.c @@ -0,0 +1,10 @@ + +int main() +{ + const struct struct_tag_name { + int x; + float y; + } my_struct_var = {.x = 1, .y = 3.15}; + const double z = 4; + return 0; +} diff --git a/regression/goto-instrument/const-struct2/test.desc b/regression/goto-instrument/const-struct2/test.desc new file mode 100644 index 00000000000..8575824dbcb --- /dev/null +++ b/regression/goto-instrument/const-struct2/test.desc @@ -0,0 +1,9 @@ +CORE +main.c +--show-symbol-table +^Type\.*: const struct struct_tag_name$ +^Type\.*: const double$ +^EXIT=0$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-instrument/const-struct3/main.c b/regression/goto-instrument/const-struct3/main.c new file mode 100644 index 00000000000..fda2dc345f6 --- /dev/null +++ b/regression/goto-instrument/const-struct3/main.c @@ -0,0 +1,13 @@ + +struct struct_tag_name +{ + int x; + float y; +}; + +int main() +{ + const struct struct_tag_name my_struct_var = {.x = 1, .y = 3.15}; + const double z = 4; + return 0; +} diff --git a/regression/goto-instrument/const-struct3/test.desc b/regression/goto-instrument/const-struct3/test.desc new file mode 100644 index 00000000000..430dcf89321 --- /dev/null +++ b/regression/goto-instrument/const-struct3/test.desc @@ -0,0 +1,9 @@ +CORE +main.c +--dump-c +^\s*const struct struct_tag_name my_struct_var +^\s*const double z +^EXIT=0$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-instrument/const-union1/main.c b/regression/goto-instrument/const-union1/main.c new file mode 100644 index 00000000000..1ba8ba29675 --- /dev/null +++ b/regression/goto-instrument/const-union1/main.c @@ -0,0 +1,13 @@ + +union union_tag_name +{ + int x; + float y; +}; + +int main() +{ + const union union_tag_name my_union_var = {.y = 3.15}; + const double z = 4; + return 0; +} diff --git a/regression/goto-instrument/const-union1/test.desc b/regression/goto-instrument/const-union1/test.desc new file mode 100644 index 00000000000..01de23cf56d --- /dev/null +++ b/regression/goto-instrument/const-union1/test.desc @@ -0,0 +1,9 @@ +CORE +main.c +--show-symbol-table +^Type\.*: const union union_tag_name$ +^Type\.*: const double$ +^EXIT=0$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/goto-instrument/volatile-struct1/main.c b/regression/goto-instrument/volatile-struct1/main.c new file mode 100644 index 00000000000..7f788eacc21 --- /dev/null +++ b/regression/goto-instrument/volatile-struct1/main.c @@ -0,0 +1,13 @@ + +struct struct_tag_name +{ + int x; + float y; +}; + +int main() +{ + volatile struct struct_tag_name my_struct_var = {.x = 1, .y = 3.15}; + const double z = 4; + return 0; +} diff --git a/regression/goto-instrument/volatile-struct1/test.desc b/regression/goto-instrument/volatile-struct1/test.desc new file mode 100644 index 00000000000..ced4d5c8ddd --- /dev/null +++ b/regression/goto-instrument/volatile-struct1/test.desc @@ -0,0 +1,9 @@ +CORE +main.c +--show-symbol-table +^Type\.*: volatile struct struct_tag_name$ +^Type\.*: const double$ +^EXIT=0$ +^SIGNAL=0$ +-- +^warning: ignoring