aboutsummaryrefslogtreecommitdiff
path: root/tests/tcctest.c
diff options
context:
space:
mode:
authorMichael Matz <matz@suse.de>2012-04-15 19:29:45 +0200
committerMichael Matz <matz@suse.de>2012-04-18 20:57:13 +0200
commit1d0a5c251553d8d9199ad18d4780bf356f456298 (patch)
tree1b15ed00535f7cbbff15a9e2ec5f3acbfa08654b /tests/tcctest.c
parent86ac6b9beec1c142867b53350006c02e20e4a7ef (diff)
downloadtinycc-1d0a5c251553d8d9199ad18d4780bf356f456298.tar.gz
tinycc-1d0a5c251553d8d9199ad18d4780bf356f456298.tar.bz2
x86_64: Fix segfault for global data
When offsetted addresses of global non-static data are computed multiple times in the same statement the x86_64 backend uses gen_gotpcrel with offset, which implements an add insn on the register given. load() uses the R member of the to-be-loaded value, which doesn't yet have a reg assigned in all cases. So use the register we're supposed to load the value into as that register.
Diffstat (limited to 'tests/tcctest.c')
-rw-r--r--tests/tcctest.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/tcctest.c b/tests/tcctest.c
index fcd9822..03be501 100644
--- a/tests/tcctest.c
+++ b/tests/tcctest.c
@@ -85,6 +85,7 @@ void statement_expr_test(void);
void asm_test(void);
void builtin_test(void);
void weak_test(void);
+void global_data_test(void);
int fib(int n);
void num(int n);
@@ -583,6 +584,7 @@ int main(int argc, char **argv)
asm_test();
builtin_test();
weak_test();
+ global_data_test();
return 0;
}
@@ -2509,3 +2511,31 @@ int getme (struct condstruct *s, int i)
int i4 = (i == 0 ? s : (void*)0)->i;
return i1 + i2 + i3 + i4;
}
+
+struct global_data
+{
+ int a[40];
+ int *b[40];
+};
+
+struct global_data global_data;
+
+int global_data_getstuff (int *, int);
+
+void global_data_callit (int i)
+{
+ *global_data.b[i] = global_data_getstuff (global_data.b[i], 1);
+}
+
+int global_data_getstuff (int *p, int i)
+{
+ return *p + i;
+}
+
+void global_data_test (void)
+{
+ global_data.a[0] = 42;
+ global_data.b[0] = &global_data.a[0];
+ global_data_callit (0);
+ printf ("%d\n", global_data.a[0]);
+}