[dmd-internals] Testcase in test42.d

Walter Bright walter at digitalmars.com
Fri Apr 5 15:06:23 PDT 2013


On 4/5/2013 2:16 PM, David Nadlinger wrote:
> On 5 Apr 2013, at 22:23, Walter Bright wrote:
>> On 4/5/2013 12:24 PM, David Nadlinger wrote:
>>> On 5 Apr 2013, at 21:16, Walter Bright wrote:
>>>> I am reluctant to change that, because it would break existing code.
>>>
>>> Change what? As far as I can see, the test case and any code that relies on 
>>> that behavior is simply invalid given the "like the host C compiler" clause. 
>>> Chances are that any such "existing" code doesn't work (reliably) on GDC and 
>>> LDC today.
>>>
>>> If you want different behavior, you *do* have to change the spec.
>>
>> This behavior was a frequent request from those doing SIMD code, which is why 
>> it's there, and why I'm reluctant to remove it and break their code.
>
> Sorry, but I don't think this is a sensible argument at all. We can either
>   1) decide that static arrays should be aligned to some special number of 
> bytes, and adapt the spec accordingly, addressing any issues like C ABI 
> compatibility
> — or —
>   2) remove the (invalid) unit test, and ask any people relying on this 
> undocumented feature to adapt their code.
>
> Doing nothing is certainly not an option.
>
> I'd argue that 2) is the better choice – isn't just using vector types (e.g. 
> core.simd.int4) for storage the best idea in cases where you want to, well, 
> use the data in vector operations?
>
> In related news, I think that telling people that it is okay to rely on 
> undocumented DMD implementation quirks is jeopardizing the future of D in more 
> ways than you might realize, and certainly sends all the wrong signals to 
> people working on alternative implementations.

It's C ABI compatible. Note that:

struct S { int[4] a; }
struct T { int x; S s; }

has a size of 20 bytes. What's going on is when the statically allocated data is 
emitted, it is aligned to 16 bytes. This does not break the C ABI.

The reason it is marked as "shared" is so it goes into a section in the object 
file. TLS doesn't always go into a section.


More information about the dmd-internals mailing list