diff options
| author | Richard Brooksby | 2012-09-10 15:43:02 +0100 |
|---|---|---|
| committer | Richard Brooksby | 2012-09-10 15:43:02 +0100 |
| commit | 59587ca812a6dc897b0e850a1272d0b30d29d85d (patch) | |
| tree | 7e1cc4d4a6d19351773522c69d7c5e2e46ecaa94 /mps/code | |
| parent | 1ece8c4ccb23e7cda087e366f97f139cdb4ea948 (diff) | |
| download | emacs-59587ca812a6dc897b0e850a1272d0b30d29d85d.tar.gz emacs-59587ca812a6dc897b0e850a1272d0b30d29d85d.zip | |
Eliminating type puns that cause strict aliasing violations in some tests.
Copied from Perforce
Change: 179394
ServerID: perforce.ravenbrook.com
Diffstat (limited to 'mps/code')
| -rw-r--r-- | mps/code/finaltest.c | 6 | ||||
| -rw-r--r-- | mps/code/qs.c | 54 | ||||
| -rw-r--r-- | mps/code/zmess.c | 4 |
3 files changed, 38 insertions, 26 deletions
diff --git a/mps/code/finaltest.c b/mps/code/finaltest.c index 9351688a9ce..069a737d708 100644 --- a/mps/code/finaltest.c +++ b/mps/code/finaltest.c | |||
| @@ -75,7 +75,8 @@ static void register_numbered_tree(mps_word_t tree, mps_arena_t arena) | |||
| 75 | { | 75 | { |
| 76 | /* don't finalize ints */ | 76 | /* don't finalize ints */ |
| 77 | if ((tree & 1) == 0) { | 77 | if ((tree & 1) == 0) { |
| 78 | mps_finalize(arena, (mps_addr_t *)&tree); | 78 | mps_addr_t tree_ref = (mps_addr_t)tree; |
| 79 | mps_finalize(arena, &tree_ref); | ||
| 79 | register_numbered_tree(DYLAN_VECTOR_SLOT(tree, 0), arena); | 80 | register_numbered_tree(DYLAN_VECTOR_SLOT(tree, 0), arena); |
| 80 | register_numbered_tree(DYLAN_VECTOR_SLOT(tree, 1), arena); | 81 | register_numbered_tree(DYLAN_VECTOR_SLOT(tree, 1), arena); |
| 81 | } | 82 | } |
| @@ -114,7 +115,8 @@ static void register_indirect_tree(mps_word_t tree, mps_arena_t arena) | |||
| 114 | /* don't finalize ints */ | 115 | /* don't finalize ints */ |
| 115 | if ((tree & 1) == 0) { | 116 | if ((tree & 1) == 0) { |
| 116 | mps_word_t indirect = DYLAN_VECTOR_SLOT(tree,2); | 117 | mps_word_t indirect = DYLAN_VECTOR_SLOT(tree,2); |
| 117 | mps_finalize(arena, (mps_addr_t *)&indirect); | 118 | mps_addr_t indirect_ref = (mps_addr_t)indirect; |
| 119 | mps_finalize(arena, &indirect_ref); | ||
| 118 | register_indirect_tree(DYLAN_VECTOR_SLOT(tree, 0), arena); | 120 | register_indirect_tree(DYLAN_VECTOR_SLOT(tree, 0), arena); |
| 119 | register_indirect_tree(DYLAN_VECTOR_SLOT(tree, 1), arena); | 121 | register_indirect_tree(DYLAN_VECTOR_SLOT(tree, 1), arena); |
| 120 | } | 122 | } |
diff --git a/mps/code/qs.c b/mps/code/qs.c index 3d8d730490b..2859523e9bc 100644 --- a/mps/code/qs.c +++ b/mps/code/qs.c | |||
| @@ -18,6 +18,8 @@ | |||
| 18 | * list length 1000 makes 40404 conses (by experiment). | 18 | * list length 1000 makes 40404 conses (by experiment). |
| 19 | * | 19 | * |
| 20 | * Some registers are not nulled out when they could be. | 20 | * Some registers are not nulled out when they could be. |
| 21 | * | ||
| 22 | * TODO: There should be fewer casts and more unions. | ||
| 21 | */ | 23 | */ |
| 22 | 24 | ||
| 23 | #include "testlib.h" | 25 | #include "testlib.h" |
| @@ -64,7 +66,7 @@ enum {QSInt, QSRef, QSEvac, QSPadOne, QSPadMany}; | |||
| 64 | typedef struct QSCellStruct *QSCell; | 66 | typedef struct QSCellStruct *QSCell; |
| 65 | typedef struct QSCellStruct { | 67 | typedef struct QSCellStruct { |
| 66 | mps_word_t tag; | 68 | mps_word_t tag; |
| 67 | mps_word_t value; | 69 | mps_addr_t value; |
| 68 | QSCell tail; | 70 | QSCell tail; |
| 69 | } QSCellStruct; | 71 | } QSCellStruct; |
| 70 | 72 | ||
| @@ -89,7 +91,7 @@ static mps_word_t listl; | |||
| 89 | 91 | ||
| 90 | static QSCell activationStack; | 92 | static QSCell activationStack; |
| 91 | #define NREGS 3 | 93 | #define NREGS 3 |
| 92 | static mps_word_t reg[NREGS]; | 94 | static mps_addr_t reg[NREGS]; |
| 93 | static mps_word_t regtag[NREGS]; | 95 | static mps_word_t regtag[NREGS]; |
| 94 | 96 | ||
| 95 | 97 | ||
| @@ -102,7 +104,7 @@ static mps_word_t regtag[NREGS]; | |||
| 102 | */ | 104 | */ |
| 103 | 105 | ||
| 104 | /* should cons return in reg[0] or should it return via C? */ | 106 | /* should cons return in reg[0] or should it return via C? */ |
| 105 | static void cons(mps_word_t tag0, mps_word_t value0, QSCell tail) | 107 | static void cons(mps_word_t tag0, mps_addr_t value0, QSCell tail) |
| 106 | { | 108 | { |
| 107 | mps_addr_t p; | 109 | mps_addr_t p; |
| 108 | QSCell new; | 110 | QSCell new; |
| @@ -116,7 +118,7 @@ static void cons(mps_word_t tag0, mps_word_t value0, QSCell tail) | |||
| 116 | new->tail = tail; | 118 | new->tail = tail; |
| 117 | } while(!mps_commit(ap, p, sizeof(QSCellStruct))); | 119 | } while(!mps_commit(ap, p, sizeof(QSCellStruct))); |
| 118 | 120 | ||
| 119 | reg[0] = (mps_word_t)new; | 121 | reg[0] = (mps_addr_t)new; |
| 120 | regtag[0] = QSRef; | 122 | regtag[0] = QSRef; |
| 121 | return; | 123 | return; |
| 122 | } | 124 | } |
| @@ -146,7 +148,7 @@ static void append(void) | |||
| 146 | reg[0] = activationStack->tail->value; | 148 | reg[0] = activationStack->tail->value; |
| 147 | regtag[0] = activationStack->tail->tag; | 149 | regtag[0] = activationStack->tail->tag; |
| 148 | cdie(regtag[0] == QSRef, "append tail"); | 150 | cdie(regtag[0] == QSRef, "append tail"); |
| 149 | reg[0] = (mps_word_t)((QSCell)reg[0])->tail; /* (cdr x) */ | 151 | reg[0] = (mps_addr_t)((QSCell)reg[0])->tail; /* (cdr x) */ |
| 150 | regtag[0] = QSRef; | 152 | regtag[0] = QSRef; |
| 151 | append(); | 153 | append(); |
| 152 | reg[1] = reg[0]; | 154 | reg[1] = reg[0]; |
| @@ -162,7 +164,7 @@ static void append(void) | |||
| 162 | ret: | 164 | ret: |
| 163 | /* null out reg[1] */ | 165 | /* null out reg[1] */ |
| 164 | regtag[1] = QSRef; | 166 | regtag[1] = QSRef; |
| 165 | reg[1] = (mps_word_t)0; | 167 | reg[1] = (mps_addr_t)0; |
| 166 | return; | 168 | return; |
| 167 | } | 169 | } |
| 168 | 170 | ||
| @@ -177,7 +179,7 @@ static void swap(void) | |||
| 177 | regtag[1]=regtag[2]; | 179 | regtag[1]=regtag[2]; |
| 178 | reg[1]=reg[2]; | 180 | reg[1]=reg[2]; |
| 179 | regtag[2]=QSRef; | 181 | regtag[2]=QSRef; |
| 180 | reg[2]=(mps_word_t)0; | 182 | reg[2]=(mps_addr_t)0; |
| 181 | } | 183 | } |
| 182 | 184 | ||
| 183 | 185 | ||
| @@ -194,11 +196,13 @@ static void makerndlist(int l) | |||
| 194 | listl = l; | 196 | listl = l; |
| 195 | die(mps_alloc((mps_addr_t *)&list, mpool, (l * sizeof(mps_word_t))), | 197 | die(mps_alloc((mps_addr_t *)&list, mpool, (l * sizeof(mps_word_t))), |
| 196 | "Alloc List"); | 198 | "Alloc List"); |
| 197 | reg[0] = (mps_word_t)0; | 199 | reg[0] = (mps_addr_t)0; |
| 198 | regtag[0] = QSRef; | 200 | regtag[0] = QSRef; |
| 199 | for(i = 0; i < l; ++i) { | 201 | for(i = 0; i < l; ++i) { |
| 200 | r = rnd(); | 202 | r = rnd(); |
| 201 | cons(QSInt, r, (QSCell)reg[0]); | 203 | cons(QSInt, |
| 204 | (mps_addr_t)r, /* TODO: dirty cast */ | ||
| 205 | (QSCell)reg[0]); | ||
| 202 | list[i] = r; | 206 | list[i] = r; |
| 203 | } | 207 | } |
| 204 | } | 208 | } |
| @@ -213,25 +217,25 @@ static void part(mps_word_t p) | |||
| 213 | reg[2]=reg[0]; | 217 | reg[2]=reg[0]; |
| 214 | cdie(regtag[2] == QSRef, "part 0"); | 218 | cdie(regtag[2] == QSRef, "part 0"); |
| 215 | regtag[0]=QSRef; | 219 | regtag[0]=QSRef; |
| 216 | reg[0]=(mps_word_t)0; | 220 | reg[0]=(mps_addr_t)0; |
| 217 | regtag[1]=QSRef; | 221 | regtag[1]=QSRef; |
| 218 | reg[1]=(mps_word_t)0; | 222 | reg[1]=(mps_addr_t)0; |
| 219 | 223 | ||
| 220 | while(reg[2] != (mps_word_t)0) { | 224 | while(reg[2] != (mps_word_t)0) { |
| 221 | cdie(((QSCell)reg[2])->tag == QSInt, "part int"); | 225 | cdie(((QSCell)reg[2])->tag == QSInt, "part int"); |
| 222 | if(((QSCell)reg[2])->value < p) { | 226 | if((mps_word_t)((QSCell)reg[2])->value < p) { |
| 223 | /* cons onto reg[0] */ | 227 | /* cons onto reg[0] */ |
| 224 | cons(QSInt, ((QSCell)reg[2])->value, (QSCell)reg[0]); | 228 | cons(QSInt, ((QSCell)reg[2])->value, (QSCell)reg[0]); |
| 225 | } else { | 229 | } else { |
| 226 | /* cons onto reg[1] */ | 230 | /* cons onto reg[1] */ |
| 227 | cons(QSRef, (mps_word_t)reg[0], activationStack); /* save reg0 */ | 231 | cons(QSRef, reg[0], activationStack); /* save reg0 */ |
| 228 | activationStack = (QSCell)reg[0]; | 232 | activationStack = (QSCell)reg[0]; |
| 229 | cons(QSInt, ((QSCell)reg[2])->value, (QSCell)reg[1]); | 233 | cons(QSInt, ((QSCell)reg[2])->value, (QSCell)reg[1]); |
| 230 | reg[1]=reg[0]; | 234 | reg[1]=reg[0]; |
| 231 | reg[0]=activationStack->value; | 235 | reg[0]=activationStack->value; |
| 232 | activationStack = activationStack->tail; | 236 | activationStack = activationStack->tail; |
| 233 | } | 237 | } |
| 234 | reg[2]=(mps_word_t)((QSCell)reg[2])->tail; | 238 | reg[2]=(mps_addr_t)((QSCell)reg[2])->tail; |
| 235 | } | 239 | } |
| 236 | } | 240 | } |
| 237 | 241 | ||
| @@ -251,8 +255,8 @@ static void qs(void) | |||
| 251 | /* check that we have an int list */ | 255 | /* check that we have an int list */ |
| 252 | cdie(((QSCell)reg[0])->tag == QSInt, "qs int"); | 256 | cdie(((QSCell)reg[0])->tag == QSInt, "qs int"); |
| 253 | 257 | ||
| 254 | pivot = ((QSCell)reg[0])->value; | 258 | pivot = (mps_word_t)((QSCell)reg[0])->value; |
| 255 | reg[0] = (mps_word_t)((QSCell)reg[0])->tail; | 259 | reg[0] = (mps_addr_t)((QSCell)reg[0])->tail; |
| 256 | part(pivot); | 260 | part(pivot); |
| 257 | 261 | ||
| 258 | cons(QSRef, reg[0], activationStack); | 262 | cons(QSRef, reg[0], activationStack); |
| @@ -264,9 +268,9 @@ static void qs(void) | |||
| 264 | regtag[0] = regtag[1]; | 268 | regtag[0] = regtag[1]; |
| 265 | cdie(regtag[0] == QSRef, "qs 1"); | 269 | cdie(regtag[0] == QSRef, "qs 1"); |
| 266 | qs(); | 270 | qs(); |
| 267 | cons(QSInt, pivot, (QSCell)reg[0]); | 271 | cons(QSInt, (mps_addr_t)pivot, (QSCell)reg[0]); |
| 268 | activationStack = activationStack->tail; | 272 | activationStack = activationStack->tail; |
| 269 | cons(QSRef, (mps_word_t)reg[0], activationStack); | 273 | cons(QSRef, reg[0], activationStack); |
| 270 | activationStack = (QSCell)reg[0]; | 274 | activationStack = (QSCell)reg[0]; |
| 271 | reg[0] = activationStack->tail->value; | 275 | reg[0] = activationStack->tail->value; |
| 272 | regtag[0] = activationStack->tail->tag; | 276 | regtag[0] = activationStack->tail->tag; |
| @@ -309,13 +313,13 @@ static void validate(void) | |||
| 309 | reg[1] = reg[0]; | 313 | reg[1] = reg[0]; |
| 310 | for(i = 0; i < listl; ++i) { | 314 | for(i = 0; i < listl; ++i) { |
| 311 | cdie(((QSCell)reg[1])->tag == QSInt, "validate int"); | 315 | cdie(((QSCell)reg[1])->tag == QSInt, "validate int"); |
| 312 | if(((QSCell)reg[1])->value != list[i]) { | 316 | if((mps_word_t)((QSCell)reg[1])->value != list[i]) { |
| 313 | fprintf(stdout, | 317 | fprintf(stdout, |
| 314 | "mps_res_t: Element %"PRIuLONGEST" of the two lists do not match.\n", | 318 | "mps_res_t: Element %"PRIuLONGEST" of the two lists do not match.\n", |
| 315 | (ulongest_t)i); | 319 | (ulongest_t)i); |
| 316 | return; | 320 | return; |
| 317 | } | 321 | } |
| 318 | reg[1] = (mps_word_t)((QSCell)reg[1])->tail; | 322 | reg[1] = (mps_addr_t)((QSCell)reg[1])->tail; |
| 319 | } | 323 | } |
| 320 | cdie(reg[1] == (mps_word_t)0, "validate end"); | 324 | cdie(reg[1] == (mps_word_t)0, "validate end"); |
| 321 | fprintf(stdout, "Note: Lists compare equal.\n"); | 325 | fprintf(stdout, "Note: Lists compare equal.\n"); |
| @@ -339,8 +343,12 @@ static void *go(void *p, size_t s) | |||
| 339 | die(mps_pool_create(&pool, arena, mps_class_amc(), format, chain), | 343 | die(mps_pool_create(&pool, arena, mps_class_amc(), format, chain), |
| 340 | "AMCCreate"); | 344 | "AMCCreate"); |
| 341 | die(mps_ap_create(&ap, pool, mps_rank_exact()), "APCreate"); | 345 | die(mps_ap_create(&ap, pool, mps_rank_exact()), "APCreate"); |
| 342 | die(mps_root_create_table(®root, arena, mps_rank_ambig(), 0, | 346 | die(mps_root_create_table(®root, |
| 343 | (mps_addr_t *)reg, NREGS), | 347 | arena, |
| 348 | mps_rank_ambig(), | ||
| 349 | 0, | ||
| 350 | reg, | ||
| 351 | NREGS), | ||
| 344 | "RootCreateTable"); | 352 | "RootCreateTable"); |
| 345 | die(mps_root_create_table(&actroot, arena, mps_rank_ambig(), 0, | 353 | die(mps_root_create_table(&actroot, arena, mps_rank_ambig(), 0, |
| 346 | (mps_addr_t *)&activationStack, sizeof(QSCell)/sizeof(mps_addr_t)), | 354 | (mps_addr_t *)&activationStack, sizeof(QSCell)/sizeof(mps_addr_t)), |
| @@ -474,7 +482,7 @@ static void move(mps_addr_t object, mps_addr_t to) | |||
| 474 | cell = (QSCell)object; | 482 | cell = (QSCell)object; |
| 475 | 483 | ||
| 476 | cell->tag = QSEvac; | 484 | cell->tag = QSEvac; |
| 477 | cell->value = (mps_word_t)to; | 485 | cell->value = to; |
| 478 | } | 486 | } |
| 479 | 487 | ||
| 480 | 488 | ||
diff --git a/mps/code/zmess.c b/mps/code/zmess.c index 88f84d2a1af..13d2aea8fe7 100644 --- a/mps/code/zmess.c +++ b/mps/code/zmess.c | |||
| @@ -341,10 +341,12 @@ static void *testscriptB(void *arg, size_t s) | |||
| 341 | /* Each is a dylan vector with 2 slots, inited to: (index, NULL) */ | 341 | /* Each is a dylan vector with 2 slots, inited to: (index, NULL) */ |
| 342 | for(i = 0; i < myrootCOUNT; ++i) { | 342 | for(i = 0; i < myrootCOUNT; ++i) { |
| 343 | mps_word_t v; | 343 | mps_word_t v; |
| 344 | mps_addr_t v_ref; | ||
| 344 | die(make_dylan_vector(&v, ap, 2), "make_dylan_vector"); | 345 | die(make_dylan_vector(&v, ap, 2), "make_dylan_vector"); |
| 345 | DYLAN_VECTOR_SLOT(v, 0) = DYLAN_INT(i); | 346 | DYLAN_VECTOR_SLOT(v, 0) = DYLAN_INT(i); |
| 346 | DYLAN_VECTOR_SLOT(v, 1) = (mps_word_t)NULL; | 347 | DYLAN_VECTOR_SLOT(v, 1) = (mps_word_t)NULL; |
| 347 | die(mps_finalize(arena, (mps_addr_t*)&v), "finalize"); | 348 | v_ref = (mps_addr_t)v; |
| 349 | die(mps_finalize(arena, &v_ref), "finalize"); | ||
| 348 | myroot[i] = (void*)v; | 350 | myroot[i] = (void*)v; |
| 349 | state[i] = rootSTATE; | 351 | state[i] = rootSTATE; |
| 350 | } | 352 | } |