Skip to content
This repository was archived by the owner on Jun 20, 2019. It is now read-only.

Commit e887689

Browse files
authored
Merge pull request #578 from ibuclaw/bug252
Fix Bug 252: ICE when compiling with -flto
2 parents d9d6233 + 443aa3c commit e887689

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

gcc/d/ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2017-12-10 Iain Buclaw <ibuclaw@gdcproject.org>
2+
3+
* d-codegen.cc (build_alignment_field): Set DECL_PADDING_P and
4+
DECL_FIELD_CONTEXT on generated fields.
5+
(build_struct_literal): Use build_zero_cst to generate padding.
6+
* decl.cc (build_type_decl): Set public and decl assembler name.
7+
18
2017-12-10 Iain Buclaw <ibuclaw@gdcproject.org>
29

310
* types.cc (TypeVisitor::visit(TypeClass)): Check for duplicate

gcc/d/d-codegen.cc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -978,14 +978,16 @@ build_array_struct_comparison (tree_code code, StructDeclaration *sd,
978978
the alignment hole between OFFSET and FIELDPOS. */
979979

980980
static tree
981-
build_alignment_field (HOST_WIDE_INT offset, HOST_WIDE_INT fieldpos)
981+
build_alignment_field (tree type, HOST_WIDE_INT offset, HOST_WIDE_INT fieldpos)
982982
{
983-
tree type = make_array_type (Type::tuns8, fieldpos - offset);
984-
tree field = create_field_decl (type, NULL, 1, 1);
983+
tree atype = make_array_type (Type::tuns8, fieldpos - offset);
984+
tree field = create_field_decl (atype, NULL, 1, 1);
985985

986-
SET_DECL_OFFSET_ALIGN (field, TYPE_ALIGN (type));
986+
SET_DECL_OFFSET_ALIGN (field, TYPE_ALIGN (atype));
987987
DECL_FIELD_OFFSET (field) = size_int (offset);
988988
DECL_FIELD_BIT_OFFSET (field) = bitsize_zero_node;
989+
DECL_FIELD_CONTEXT (field) = type;
990+
DECL_PADDING_P (field) = 1;
989991

990992
layout_decl (field, 0);
991993

@@ -1063,8 +1065,8 @@ build_struct_literal (tree type, vec<constructor_elt, va_gc> *init)
10631065
alignment holes in-place between fields. */
10641066
if (fillholes && offset < fieldpos)
10651067
{
1066-
tree pfield = build_alignment_field (offset, fieldpos);
1067-
tree pvalue = build_constructor (TREE_TYPE (pfield), NULL);
1068+
tree pfield = build_alignment_field (type, offset, fieldpos);
1069+
tree pvalue = build_zero_cst (TREE_TYPE (pfield));
10681070
CONSTRUCTOR_APPEND_ELT (ve, pfield, pvalue);
10691071
}
10701072

@@ -1113,8 +1115,9 @@ build_struct_literal (tree type, vec<constructor_elt, va_gc> *init)
11131115
/* Finally pad out the end of the record. */
11141116
if (fillholes && offset < int_size_in_bytes (type))
11151117
{
1116-
tree pfield = build_alignment_field (offset, int_size_in_bytes (type));
1117-
tree pvalue = build_constructor (TREE_TYPE (pfield), NULL);
1118+
tree pfield = build_alignment_field (type, offset,
1119+
int_size_in_bytes (type));
1120+
tree pvalue = build_zero_cst (TREE_TYPE (pfield));
11181121
CONSTRUCTOR_APPEND_ELT (ve, pfield, pvalue);
11191122
}
11201123

gcc/d/decl.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,6 +2085,8 @@ build_type_decl (tree type, Dsymbol *dsym)
20852085

20862086
tree decl = build_decl (get_linemap (dsym->loc), TYPE_DECL,
20872087
get_identifier (dsym->ident->toChars ()), type);
2088+
SET_DECL_ASSEMBLER_NAME (decl, get_identifier (mangle_decl (dsym)));
2089+
TREE_PUBLIC (decl) = 1;
20882090
DECL_ARTIFICIAL (decl) = 1;
20892091
DECL_CONTEXT (decl) = d_decl_context (dsym);
20902092

gcc/testsuite/gdc.dg/lto/ltotests_0.d

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import core.stdc.stdio;
55

66
/******************************************/
77

8-
/+ XBUG: lto1: internal compiler error: in get_odr_type
98
interface I284
109
{
1110
void m284();
@@ -15,17 +14,14 @@ class C284 : I284
1514
{
1615
void m284() { }
1716
}
18-
+/
1917

2018
/******************************************/
2119

22-
/+ XBUG: lto1: internal compiler error: in get_odr_type
2320
class C304
2421
{
2522
}
2623

2724
C304 c304;
28-
+/
2925

3026
/******************************************/
3127

@@ -68,9 +64,29 @@ void test88()
6864

6965
/******************************************/
7066

67+
// Bug 252
68+
69+
class C252
70+
{
71+
struct S252
72+
{
73+
int i;
74+
ubyte u;
75+
}
76+
S252 s;
77+
}
78+
79+
void test252()
80+
{
81+
C252 c = new C252();
82+
}
83+
84+
/******************************************/
85+
7186
void main(string[])
7287
{
7388
test88();
89+
test252();
7490

7591
printf("Success!\n");
7692
}

0 commit comments

Comments
 (0)