summaryrefslogtreecommitdiff
path: root/support/regression/tests/structscope.c
diff options
context:
space:
mode:
authorXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
committerXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
commit268a53de823a6750d6256ee1fb1e7707b4b45740 (patch)
tree42c1799a9a82b2f7d9790ee9fe181d72a7274751 /support/regression/tests/structscope.c
downloadsdcc-gas-268a53de823a6750d6256ee1fb1e7707b4b45740.tar.gz
sdcc-3.9.0 fork implementing GNU assembler syntax
This fork aims to provide better support for stm8-binutils
Diffstat (limited to 'support/regression/tests/structscope.c')
-rw-r--r--support/regression/tests/structscope.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/support/regression/tests/structscope.c b/support/regression/tests/structscope.c
new file mode 100644
index 0000000..599af4a
--- /dev/null
+++ b/support/regression/tests/structscope.c
@@ -0,0 +1,72 @@
+/* Test struct scoping rules
+
+ */
+
+#include <testfwk.h>
+
+/* declare an incomplete struct type */
+struct tag2;
+
+struct tag1 {
+ struct tag1 *mykind;
+ unsigned char x;
+ unsigned char y;
+ struct tag2 *other;
+} s1;
+
+/* complete the previously incomplete type */
+struct tag2 {
+ unsigned char z;
+ struct tag1 *other;
+} s2;
+
+void
+test_global(void)
+{
+ s1.mykind = &s1;
+ s1.other = &s2;
+ s2.other = &s1;
+ s1.x = 1;
+ s1.y = 2;
+ s2.z = 3;
+ ASSERT(s2.other->x == 1);
+ ASSERT(s1.other->z == 3);
+ ASSERT(s1.other->other->y == 2);
+ ASSERT(s1.mykind->y == 2);
+}
+
+void
+test_nested(void)
+{
+ {
+ struct tag1 {
+ unsigned char a;
+ } ls1;
+ ls1.a=1;
+ }
+ {
+ struct tag1 ls2; /* should bind to global level tag1 */
+ ls2.x=2;
+ }
+ {
+ struct tag1 {
+ unsigned char b;
+ struct tag2 *globals2; /* should bind to global level tag2 */
+ } ls3;
+ ls3.b = 3;
+ ls3.globals2 = &s2;
+ }
+ {
+ struct tag2; /* incomplete local tag */
+ struct tag1 {
+ struct tag2 *locals2; /* should bind to local level s2 tag */
+ } ls4;
+ struct tag2 {
+ unsigned char c;
+ } ls5;
+
+ ls4.locals2 = &ls5;
+ ls4.locals2->c = 9;
+ }
+ s1.x = 0;
+}