Summary: | GDC backend uses invalid type when using deferencing toPtr on a static array inside of a struct. | ||
---|---|---|---|
Product: | GDC | Reporter: | Daniel Green <venix1> |
Component: | gdc | Assignee: | Iain Buclaw <ibuclaw> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | johannespfau |
Priority: | --- | ||
Version: | 4.8.x | ||
Hardware: | x86 | ||
OS: | Other |
Description
Daniel Green
2012-10-29 21:40:14 CET
This is a bug in the frontend. It should not be generating code like this: ==== if (c.b) { .... } Where the condition is a non-scalar type. When dealing with "if (c.b)" GDC does the correct thing and throws an error. In this case b is of type char[1] and we're taking the pointer using .ptr . The type then becomes char*. After which we dereference it into what should be a 'char' a valid scalar. However, GDC returns the original type char[1]. Which is what generates the error shown. To help contrast this, if we remove the struct and do === char[1] d; void main() { if (*d.ptr) return; return; } It compiles without an error even though it should be equivalent to the previous operation. Derefencing a pointer of static char[1]. (In reply to comment #2) > When dealing with "if (c.b)" GDC does the correct thing and throws an error. > > In this case b is of type char[1] and we're taking the pointer using .ptr . > The type then becomes char*. After which we dereference it into what should be > a 'char' a valid scalar. > > However, GDC returns the original type char[1]. Which is what generates the > error shown. > > To help contrast this, if we remove the struct and do > > === > > char[1] d; > > void main() > { > if (*d.ptr) return; > return; > } > > It compiles without an error even though it should be equivalent to the > previous operation. Derefencing a pointer of static char[1]. That's because: *d.ptr Becomes: PtrExp (SymOffExp (d)) And: *c.b.ptr Becomes: PtrExp (AddrExp (c.b)) It is the later that suffers this bug, see PtrExp::optimize. http://d.puremagic.com/issues/show_bug.cgi?id=8913 Can we close this? Fixed with recent frontend merge. |