|Title||mps_root_create_table is hard to use without punning|
|Assigned user||Gareth Rees|
|Description||The functions mps_root_create_table and mps_root_create_table_masked are hard to use without type-punning.|
For example, qs.c contains the lines:
die(mps_root_create_table(&actroot, arena, mps_rank_ambig(), 0,
(mps_addr_t *)&activationStack, sizeof(QSCell)/sizeof(mps_addr_t)),
(where activationStack has type struct QSCellStruct *) which fails to compile under gcc 4.4.3 , with the error:
qs.c:354: error: dereferencing type-punned pointer will break strict-aliasing rules
qs.c: In function 'scan1':
In order to get this to work without puns, you need to write it like this:
base = &activationStack;
die(mps_root_create_table(&actroot, arena, mps_rank_ambig(), 0, base, 1),
which seems difficult to get right. Also, the manual entry for mps_root_create_table_masked has a buggy example!
|Analysis||It would be better if the 'base' argument to mps_root_create_table and mps_root_create_table_masked were just an mps_addr_t. Then it would be easy to get right, as any pointer can safely be cast to an mps_addr_t.|
(If we are concerned to maintain API compatibility, we would have to deprecate these two functions and make two more.)
Further evidence in support of this is that MMQA test function/96.c  makes the same mistake.
But without breaking backward compatibility I think the best thing to do is to put a warning in the manual.
|Created by||Gareth Rees|
|Created on||2013-05-06 18:37:51|
|Last modified by||Gareth Rees|
|Last modified on||2014-04-04 11:49:19|
|History||2013-05-06 GDR Created.|
|185223||closed||2014-04-04 11:49:19||Gareth Rees||Explain how to call mps_root_create_table() safely (avoiding type punning). Fix example for mps_root_create_table_masked(). Use the recommended approach in qs.c.|