Bug 1172 – Inline assembler: cannot access member of templated aggregate directly
Status
RESOLVED
Resolution
WONTFIX
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2007-04-21T02:54:37Z
Last change time
2020-03-21T03:56:39Z
Keywords
iasm, rejects-valid
Assigned to
No Owner
Creator
Matti Niemenmaa
Comments
Comment #0 by matti.niemenmaa+dbugzilla — 2007-04-21T02:54:37Z
struct Foo(T) {
int a;
}
void main() {
Foo!(int) f;
asm {
mov EBX, f;
mov EAX, Foo!(int).a[EBX];
}
}
The code above is essentially the same as what is under "Struct/Union/Class Member Offsets" at http://www.digitalmars.com/d/iasm.html but fails with the error "bad type/size of operands 'Foo(T)'".
The workaround is to use an alias:
alias Foo!(int) Foo_int;
asm {
mov EBX, f;
mov EAX, Foo_int.a[EBX];
}
Comment #2 by razvan.nitu1305 — 2019-07-12T11:01:58Z
You can also use f instead of the type as a workaround:
struct Foo(T) {
int a;
}
void main() {
Foo!(int)* f;
asm {
mov EBX, f;
mov EAX, f.a.offsetof[EBX];
}
}
It is actually easier to type the name of the variable.
It seems that the ASM parser is really simple, it doesn't support all the complex grammar that D has to offer. You can take a look at the grammar [1] and see that it only accepts simple dotIdentifiers (templates not included).
I suggest we close this as WONTFIX.
[1] https://dlang.org/spec/iasm.html#operands
Comment #3 by b2.temp — 2019-07-12T15:02:30Z
I agree. Generally speaking in asm D expressions allowed must give either a constant or variable. member function access is already more complex.