D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2080 - ICE(mangle.c) alias corrupts type inference of static variables
Summary: ICE(mangle.c) alias corrupts type inference of static variables
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 critical
Assignee: Walter Bright
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: 340
  Show dependency treegraph
 
Reported: 2008-05-08 06:54 UTC by Max Samukha
Modified: 2014-02-24 15:33 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Max Samukha 2008-05-08 06:54:47 UTC
const s = foo(); // compiles if type of s is specified explicitly

char[] foo() // seems to fail only if the return type is char[]
{        
    return null;
}
Comment 1 Max Samukha 2008-05-09 07:07:10 UTC
Compiles if the declaration of s goes after foo definition
Comment 2 Walter Bright 2008-05-11 18:45:11 UTC
This does work with dmd 2.013.
Comment 3 Max Samukha 2008-05-12 00:59:47 UTC
Right, but the bug is in the 1.x branch, which is still in use :) 
Comment 4 Don 2009-05-26 11:35:06 UTC
The test case is a bit misleading. It requires an alias to the type which is being inferred. With the original test case, it was provided by alias char[] string; in std.object.

Here's a complete test case. Remove the alias, and it will be fine.
---
alias int * any_old_alias;
const bar = foo;
int * foo = null;
---

The alias creates a corrupt type (it doesn't have the 'deco' member set), and this gets picked by 'bar' instead of the type of foo.

The behaviour is quite similar to 2672. Marking as critical, because subtle changes in ordering in different modules can control whether the segfault occurs.
Comment 5 Don 2009-05-26 11:57:36 UTC
Aargh, I'm wrong, it just has to be any forward reference. This really simple test case segfaults in a completely different place (cast.c), with a much more obviously corrupt type.

const bar = foo;
const int * foo = null;
Comment 6 Don 2009-11-10 02:06:45 UTC
I've moved the new test case to bug#3493 (segfault, cast.c). The original bug now generates a forward reference error; the reduced test case (below) is now an ICE instead of a segfault. This should be considered as the test-case for this bug.
----
alias int * any_old_alias;
const bar = foo;
int * foo = null;
----
Comment 7 Don 2009-11-17 23:56:15 UTC
This applies to D2 as well. The D2 test case (below) generates:
 "Error: forward reference to type int*" on D1. 
On D2 it ICEs in mangle.c(81)  fd && fd->inferRetType
Removing the alias fixes both the ICE and the forward reference error.
Happens with typedef as well as alias.

-----
alias int * any_old_alias;
typeof(foo) bar = foo;
const int * foo = null;
Comment 8 Don 2010-11-15 00:04:15 UTC
Fixed svn 755.