Bug creation and email sending has been disabled, file new bugs at gcc.gnu.org/bugzilla
Bug 24 - GDC backend uses invalid type when using deferencing toPtr on a static array inside of a struct.
Summary: GDC backend uses invalid type when using deferencing toPtr on a static array ...
Status: RESOLVED FIXED
Alias: None
Product: GDC
Classification: Unclassified
Component: gdc (show other bugs)
Version: 4.8.x
Hardware: x86 Other
: --- normal
Assignee: Iain Buclaw
URL:
Depends on:
Blocks:
 
Reported: 2012-10-29 21:40 CET by Daniel Green
Modified: 2013-03-01 17:23 CET (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Green 2012-10-29 21:40:14 CET
The following code snippet will cause an ICE within the compiler.  This occurred with GDC 4.8 head as of October 4th.

====

struct a
{
    char[1] b;
}

a c;

void main()
{
	pragma(msg, typeof(*c.b.ptr));
	pragma(msg, typeof(c.b.ptr));
	pragma(msg, typeof(c.b));
	if (*c.b.ptr)
		return;
	return;
}

====

The type used by GCC for *c.b.ptr is char[1LU] when it should be char as reported by D's type system.


$ gdc test.d 
char
char*
char[1LU]
test.d: In function ‘D main’:
test.d:8: error: mismatching comparison operand types
char[1]
int
if (D.2039 != 0) goto <D.2040>; else goto <D.2041>;

test.d:8: internal compiler error: verify_gimple failed
0x98f4af verify_gimple_in_seq(gimple_statement_d*)
	../../gcc-4.8-20121007/gcc/tree-cfg.c:4531
0x828cb4 gimplify_body(tree_node*, bool)
	../../gcc-4.8-20121007/gcc/gimplify.c:8232
0x829005 gimplify_function_tree(tree_node*)
	../../gcc-4.8-20121007/gcc/gimplify.c:8319
0x6d1147 cgraph_analyze_function
	../../gcc-4.8-20121007/gcc/cgraphunit.c:643
0x6d3f8e cgraph_analyze_functions
	../../gcc-4.8-20121007/gcc/cgraphunit.c:928
0x6d4e50 finalize_compilation_unit()
	../../gcc-4.8-20121007/gcc/cgraphunit.c:2071
0x61c704 d_write_global_declarations
	../../gcc-4.8-20121007/gcc/d/d-lang.cc:643
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 1 Iain Buclaw 2012-10-30 13:27:56 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.
Comment 2 Daniel Green 2012-11-01 20:23:11 CET
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].
Comment 3 Iain Buclaw 2012-11-01 22:32:17 CET
(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
Comment 5 Johannes Pfau 2013-02-03 10:33:30 CET
Can we close this?
Comment 6 Johannes Pfau 2013-03-01 17:23:46 CET
Fixed with recent frontend merge.