{
if (TYPE_PRECISION (intype) == POINTER_SIZE)
return build1 (CONVERT_EXPR, type, expr);
- expr = cp_convert (c_common_type_for_size (POINTER_SIZE, 0), expr,
+ expr = cp_convert (c_common_type_for_size (TYPE_PRECISION (type), 0), expr,
complain);
/* Modes may be different but sizes should be the same. There
is supposed to be some integral type that is the same width
return false;
}
-/* Return a reference type node referring to TO_TYPE. If RVAL is
+
+/* Return a reference type node of MODE referring to TO_TYPE. If MODE
+ is VOIDmode the standard pointer mode will be picked. If RVAL is
true, return an rvalue reference type, otherwise return an lvalue
reference type. If a type node exists, reuse it, otherwise create
a new one. */
tree
-cp_build_reference_type (tree to_type, bool rval)
+cp_build_reference_type_for_mode (tree to_type, machine_mode mode, bool rval)
{
tree lvalue_ref, t;
to_type = TREE_TYPE (to_type);
}
- lvalue_ref = build_reference_type (to_type);
+ lvalue_ref = build_reference_type_for_mode (to_type, mode, false);
+
if (!rval)
return lvalue_ref;
SET_TYPE_STRUCTURAL_EQUALITY (t);
else if (TYPE_CANONICAL (to_type) != to_type)
TYPE_CANONICAL (t)
- = cp_build_reference_type (TYPE_CANONICAL (to_type), rval);
+ = cp_build_reference_type_for_mode (TYPE_CANONICAL (to_type), mode, rval);
else
TYPE_CANONICAL (t) = t;
}
+/* Return a reference type node referring to TO_TYPE. If RVAL is
+ true, return an rvalue reference type, otherwise return an lvalue
+ reference type. If a type node exists, reuse it, otherwise create
+ a new one. */
+tree
+cp_build_reference_type (tree to_type, bool rval)
+{
+ return cp_build_reference_type_for_mode (to_type, VOIDmode, rval);
+}
+
/* Returns EXPR cast to rvalue reference type, like std::move. */
tree
{
case POINTER_TYPE:
type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
- result = build_pointer_type (type);
+ result = build_pointer_type_for_mode (type, TYPE_MODE (t), false);
break;
case REFERENCE_TYPE:
type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
- result = cp_build_reference_type (type, TYPE_REF_IS_RVALUE (t));
+ result = cp_build_reference_type_for_mode (type, TYPE_MODE (t), TYPE_REF_IS_RVALUE (t));
break;
case OFFSET_TYPE:
t0 = strip_typedefs (TYPE_OFFSET_BASETYPE (t), remove_attributes, flags);
--- /dev/null
+// PR C++/100281
+// { dg-do compile }
+
+typedef void * __attribute__((mode (SI))) __ptr32_t;
+
+void foo () {
+ unsigned int b = 100;
+ __ptr32_t a;
+ a = b; /* { dg-error "invalid conversion from 'unsigned int' to '__ptr32_t'.*" } */
+}
--- /dev/null
+// PR C++/100281
+// { dg-do compile }
+
+typedef int & __attribute__((mode (SI))) __ref32_t;
+
+void foo () {
+ unsigned int b = 100;
+ __ref32_t a = b; /* { dg-error "cannot bind non-const lvalue reference of type '__ref32_t'.*" } */
+}
constructed by language-dependent code, not here.) */
/* Construct, lay out and return the type of pointers to TO_TYPE with
- mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
- reference all of memory. If such a type has already been
- constructed, reuse it. */
+ mode MODE. If MODE is VOIDmode, a pointer mode for the address
+ space of TO_TYPE will be picked. If CAN_ALIAS_ALL is TRUE,
+ indicate this type can reference all of memory. If such a type has
+ already been constructed, reuse it. */
tree
build_pointer_type_for_mode (tree to_type, machine_mode mode,
if (to_type == error_mark_node)
return error_mark_node;
+ if (mode == VOIDmode)
+ {
+ addr_space_t as = TYPE_ADDR_SPACE (to_type);
+ mode = targetm.addr_space.pointer_mode (as);
+ }
+
/* If the pointed-to type has the may_alias attribute set, force
a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
tree
build_pointer_type (tree to_type)
{
- addr_space_t as = to_type == error_mark_node? ADDR_SPACE_GENERIC
- : TYPE_ADDR_SPACE (to_type);
- machine_mode pointer_mode = targetm.addr_space.pointer_mode (as);
- return build_pointer_type_for_mode (to_type, pointer_mode, false);
+ return build_pointer_type_for_mode (to_type, VOIDmode, false);
}
/* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
if (to_type == error_mark_node)
return error_mark_node;
+ if (mode == VOIDmode)
+ {
+ addr_space_t as = TYPE_ADDR_SPACE (to_type);
+ mode = targetm.addr_space.pointer_mode (as);
+ }
+
/* If the pointed-to type has the may_alias attribute set, force
a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
tree
build_reference_type (tree to_type)
{
- addr_space_t as = to_type == error_mark_node? ADDR_SPACE_GENERIC
- : TYPE_ADDR_SPACE (to_type);
- machine_mode pointer_mode = targetm.addr_space.pointer_mode (as);
- return build_reference_type_for_mode (to_type, pointer_mode, false);
+ return build_reference_type_for_mode (to_type, VOIDmode, false);
}
#define MAX_INT_CACHED_PREC \