The memory model is not implementable on strict-alignment targets
that do not have a byte store operation. But we previously said that ;)
Yes. I think we should issue an error when we have such a target and
the user tries -fmemory-model=c++0x. However, how many strict-alignment
targets are not byte addressable nowadays?
Also consider global vars
char a;
char b;
accessing them on strict-align targets may access adjacent globals
(that's a problem anyway, also with alias analysis).
Good point. I am adding a test to that effect (see attached patch).
BTW, I assume you mean strict-align targets WITHOUT byte-addressability
as above. I have spot-checked your scenario on a handful of important
targets that have strict alignment, and all of them work without
touching adjacent global vars:
arm-elf OK
sparc-linux OK
ia64-linux OK
alpha-linux OK, but only with -mbwx (byte addressability)
rth tells me that we shouldn't worry about ancient non-byte addressable
Alphas, so the last isn't an issue.
So... do you have any important targets in mind, because I don't see
this being a problem for most targets? As can be expected, I am only
interested in x86*, powerpc*, and s390, especially since a cursory
glance on other important targets didn't exhibit any problems. However,
given my target bias, I am willing to look into any important targets
that are problematic (I'm hoping none :)).
Let me know if you see anything else, and please take a quick peek at
the attached patch below, which I will be committing shortly.
As usual, thanks.
Aldy
Index: testsuite/gcc.dg/memmodel/strict-align-global.c
===================================================================
--- testsuite/gcc.dg/memmodel/strict-align-global.c (revision 0)
+++ testsuite/gcc.dg/memmodel/strict-align-global.c (revision 0)
@@ -0,0 +1,46 @@
+/* { dg-do link } */
+/* { dg-options "-O2 --param allow-packed-store-data-races=0" } */
+/* { dg-final { memmodel-gdb-test } } */
+
+#include <stdio.h>
+#include "memmodel.h"
+
+/* This test verifies writes to globals do not write to adjacent
+ globals. This mostly happens on strict-align targets that are not
+ byte addressable (old Alphas, etc). */
+
+char a = 0;
+char b = 77;
+
+void memmodel_other_threads()
+{
+}
+
+int memmodel_step_verify()
+{
+ if (b != 77)
+ {
+ printf("FAIL: Unexpected value. <b> is %d, should be 77\n", b);
+ return 1;
+ }
+ return 0;
+}
+
+/* Verify that every variable has the correct value. */
+int memmodel_final_verify()
+{
+ int ret = memmodel_step_verify ();
+ if (a != 66)
+ {
+ printf("FAIL: Unexpected value. <a> is %d, should be 66\n", a);
+ return 1;
+ }
+ return ret;
+}
+
+int main ()
+{
+ a = 66;
+ memmodel_done();
+ return 0;
+}