aboutsummaryrefslogtreecommitdiff
path: root/gcc/d
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2020-08-31 13:31:04 +0200
committerIain Buclaw <ibuclaw@gdcproject.org>2020-08-31 15:53:44 +0200
commit6940c20bbb3b5864e8b510de162d1a618aecca88 (patch)
tree687831cd276e5ea6f4c438ddb455886d1cfbe0a7 /gcc/d
parentf089569851ca9c8a81400dd8a159f86636ed20ec (diff)
downloadgcc-6940c20bbb3b5864e8b510de162d1a618aecca88.zip
gcc-6940c20bbb3b5864e8b510de162d1a618aecca88.tar.gz
gcc-6940c20bbb3b5864e8b510de162d1a618aecca88.tar.bz2
d: Fix ICEs in the front-end when pointer size is 16-bit.
In the lowering of `bt*' intrinsics, some integer constants had mismatched types, and bitsize was set to the wrong value. In base_vtable_offset, the base offset value was calculated incorrectly. The TypeInfo_Class object is comprised of 18 pointers and 1 uint field, so now the internal classinfo type size is used instead. gcc/d/ChangeLog: * d-target.cc (Target::_init): Don't set classinfosize. * d-tree.h (base_vtable_offset): Move under typeinfo.cc section. * decl.cc (base_vtable_offset): Move to... * typeinfo.cc (base_vtable_offset): ...here. Get base offset from internal TypeInfo_Class type. * intrinsics.cc (expand_intrinsic_bt): Use pointer TYPE_SIZE for setting bitsize value. Build integer constants of correct type.
Diffstat (limited to 'gcc/d')
-rw-r--r--gcc/d/d-target.cc3
-rw-r--r--gcc/d/d-tree.h2
-rw-r--r--gcc/d/decl.cc36
-rw-r--r--gcc/d/intrinsics.cc7
-rw-r--r--gcc/d/typeinfo.cc36
5 files changed, 41 insertions, 43 deletions
diff --git a/gcc/d/d-target.cc b/gcc/d/d-target.cc
index 71156e3..ea425ad 100644
--- a/gcc/d/d-target.cc
+++ b/gcc/d/d-target.cc
@@ -115,9 +115,6 @@ Target::_init (const Param &)
(TYPE_PRECISION (long_double_type_node) / BITS_PER_UNIT));
this->realalignsize = TYPE_ALIGN_UNIT (long_double_type_node);
- /* Size of run-time TypeInfo object. */
- this->classinfosize = 19 * this->ptrsize;
-
/* Much of the dmd front-end uses ints for sizes and offsets, and cannot
handle any larger data type without some pervasive rework. */
this->maxStaticDataSize = tree_to_shwi (TYPE_MAX_VALUE (integer_type_node));
diff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h
index b01a133..31fe518 100644
--- a/gcc/d/d-tree.h
+++ b/gcc/d/d-tree.h
@@ -622,7 +622,6 @@ extern tree make_thunk (FuncDeclaration *, int);
extern tree start_function (FuncDeclaration *);
extern void finish_function (tree);
extern void mark_needed (tree);
-extern unsigned base_vtable_offset (ClassDeclaration *, BaseClass *);
extern tree get_vtable_decl (ClassDeclaration *);
extern tree build_new_class_expr (ClassReferenceExp *);
extern tree aggregate_initializer_decl (AggregateDeclaration *);
@@ -660,6 +659,7 @@ extern tree build_libcall (libcall_fn, Type *, int ...);
extern bool have_typeinfo_p (ClassDeclaration *);
extern tree layout_typeinfo (TypeInfoDeclaration *);
extern tree layout_classinfo (ClassDeclaration *);
+extern unsigned base_vtable_offset (ClassDeclaration *, BaseClass *);
extern tree get_typeinfo_decl (TypeInfoDeclaration *);
extern tree get_classinfo_decl (ClassDeclaration *);
extern tree build_typeinfo (const Loc &, Type *);
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 008a2bb..8e4237d 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -1991,42 +1991,6 @@ mark_needed (tree decl)
}
}
-/* Get the offset to the BC's vtbl[] initializer from the start of CD.
- Returns "~0u" if the base class is not found in any vtable interfaces. */
-
-unsigned
-base_vtable_offset (ClassDeclaration *cd, BaseClass *bc)
-{
- unsigned csymoffset = target.classinfosize;
- unsigned interfacesize = int_size_in_bytes (vtbl_interface_type_node);
- csymoffset += cd->vtblInterfaces->length * interfacesize;
-
- for (size_t i = 0; i < cd->vtblInterfaces->length; i++)
- {
- BaseClass *b = (*cd->vtblInterfaces)[i];
- if (b == bc)
- return csymoffset;
- csymoffset += b->sym->vtbl.length * target.ptrsize;
- }
-
- /* Check all overriding interface vtbl[]s. */
- for (ClassDeclaration *cd2 = cd->baseClass; cd2; cd2 = cd2->baseClass)
- {
- for (size_t k = 0; k < cd2->vtblInterfaces->length; k++)
- {
- BaseClass *bs = (*cd2->vtblInterfaces)[k];
- if (bs->fillVtbl (cd, NULL, 0))
- {
- if (bc == bs)
- return csymoffset;
- csymoffset += bs->sym->vtbl.length * target.ptrsize;
- }
- }
- }
-
- return ~0u;
-}
-
/* Get the VAR_DECL of the vtable symbol for DECL. If this does not yet exist,
create it. The vtable is accessible via ClassInfo, but since it is needed
frequently (like for rtti comparisons), make it directly accessible. */
diff --git a/gcc/d/intrinsics.cc b/gcc/d/intrinsics.cc
index 486db12..1b12a3e 100644
--- a/gcc/d/intrinsics.cc
+++ b/gcc/d/intrinsics.cc
@@ -303,7 +303,7 @@ expand_intrinsic_bt (intrinsic_code intrinsic, tree callexp)
tree type = TREE_TYPE (TREE_TYPE (ptr));
/* size_t bitsize = sizeof(*ptr) * BITS_PER_UNIT; */
- tree bitsize = fold_convert (type, TYPE_SIZE (type));
+ tree bitsize = fold_convert (type, TYPE_SIZE (TREE_TYPE (ptr)));
/* ptr[bitnum / bitsize] */
ptr = build_array_index (ptr, fold_build2 (TRUNC_DIV_EXPR, type,
@@ -312,14 +312,15 @@ expand_intrinsic_bt (intrinsic_code intrinsic, tree callexp)
/* mask = 1 << (bitnum % bitsize); */
bitnum = fold_build2 (TRUNC_MOD_EXPR, type, bitnum, bitsize);
- bitnum = fold_build2 (LSHIFT_EXPR, type, size_one_node, bitnum);
+ bitnum = fold_build2 (LSHIFT_EXPR, type, build_one_cst (type), bitnum);
/* cond = ptr[bitnum / size] & mask; */
tree cond = fold_build2 (BIT_AND_EXPR, type, ptr, bitnum);
/* cond ? -1 : 0; */
cond = build_condition (TREE_TYPE (callexp), d_truthvalue_conversion (cond),
- integer_minus_one_node, integer_zero_node);
+ build_minus_one_cst (TREE_TYPE (callexp)),
+ build_zero_cst (TREE_TYPE (callexp)));
/* Update the bit as needed, only testing the bit for bt(). */
tree_code code;
diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc
index ae281d5..2120dab 100644
--- a/gcc/d/typeinfo.cc
+++ b/gcc/d/typeinfo.cc
@@ -1173,6 +1173,42 @@ layout_classinfo (ClassDeclaration *cd)
return v.result ();
}
+/* Get the offset to the BC's vtbl[] initializer from the start of CD.
+ Returns "~0u" if the base class is not found in any vtable interfaces. */
+
+unsigned
+base_vtable_offset (ClassDeclaration *cd, BaseClass *bc)
+{
+ unsigned csymoffset = int_size_in_bytes (tinfo_types[TK_CLASSINFO_TYPE]);
+ unsigned interfacesize = int_size_in_bytes (vtbl_interface_type_node);
+ csymoffset += cd->vtblInterfaces->length * interfacesize;
+
+ for (size_t i = 0; i < cd->vtblInterfaces->length; i++)
+ {
+ BaseClass *b = (*cd->vtblInterfaces)[i];
+ if (b == bc)
+ return csymoffset;
+ csymoffset += b->sym->vtbl.length * target.ptrsize;
+ }
+
+ /* Check all overriding interface vtbl[]s. */
+ for (ClassDeclaration *cd2 = cd->baseClass; cd2; cd2 = cd2->baseClass)
+ {
+ for (size_t k = 0; k < cd2->vtblInterfaces->length; k++)
+ {
+ BaseClass *bs = (*cd2->vtblInterfaces)[k];
+ if (bs->fillVtbl (cd, NULL, 0))
+ {
+ if (bc == bs)
+ return csymoffset;
+ csymoffset += bs->sym->vtbl.length * target.ptrsize;
+ }
+ }
+ }
+
+ return ~0u;
+}
+
/* Layout fields that immediately come after the classinfo type for DECL if
there's any interfaces or interface vtables to be added.
This must be mirrored with base_vtable_offset(). */