re PR c++/9043 ([ABI] incorrect name mangling for array dimension in template function)

cp:
	PR c++/9043
	C++ ABI change: Mangling array indices in templates.
	* decl.c (compute_array_index_type): Reorganize for earlier
	template errors. Use value_dependent_expression_p for abi-2.
	* mangle.c (write_array_type): Check broken mangling for
	expression indices on abi-1
testsuite:
	PR c++/9043
	* g++.dg/abi/mangle20-1.C: New test.
	* g++.dg/abi/mangle20-2.C: New test.

From-SVN: r74707
This commit is contained in:
Nathan Sidwell 2003-12-16 19:50:54 +00:00
parent 28690784e2
commit d63b5e9f25
6 changed files with 125 additions and 77 deletions

View File

@ -1,3 +1,12 @@
2003-12-16 Nathan Sidwell <nathan@codesourcery.com>
PR c++/9043
C++ ABI change: Mangling array indices in templates.
* decl.c (compute_array_index_type): Reorganize for earlier
template errors. Use value_dependent_expression_p for abi-2.
* mangle.c (write_array_type): Check broken mangling for
expression indices on abi-1
2003-12-16 Mark Mitchell <mark@codesourcery.com>
PR c++/13275
@ -10,18 +19,18 @@
(cp_parser_unary_expression): Allow the use of "&" in a constant
expression if implementing offsetof.
2003-12-16 Giovanni Bajo <giovannibajo@gcc.gnu.org>
PR c++/2294
2003-12-16 Giovanni Bajo <giovannibajo@gcc.gnu.org>
PR c++/2294
* name-lookup.c (push_overloaded_decl): always construct an OVERLOAD
if the declaration comes from an using declaration.
if the declaration comes from an using declaration.
2003-12-16 Giovanni Bajo <giovannibajo@gcc.gnu.org>
* semantics.c (finish_id_expression): Refactor the code to handle
template parameters, and emit a more informative error message
when they are used within an integral constant expression.
2003-12-16 Nathan Sidwell <nathan@codesourcery.com>
PR c++/13387
@ -17403,7 +17412,7 @@
* parse.y (member_init): Just pass in the type.
* init.c (expand_member_init): Handle getting a type.
2000-07-04 Martin v. Löwis <loewis@informatik.hu-berlin.de>
2000-07-04 Martin v. Löwis <loewis@informatik.hu-berlin.de>
Jason Merrill <jason@redhat.com>
* decl.c (finish_function): Warn if a function has no return
@ -17749,7 +17758,7 @@
* decl.c (pushdecl): Don't set DECL_CONTEXT from current_namespace.
(push_namespace): Set DECL_CONTEXT for a new NAMESPACE_DECL.
2000-06-24 Martin v. Löwis <loewis@informatik.hu-berlin.de>
2000-06-24 Martin v. Löwis <loewis@informatik.hu-berlin.de>
* parse.y (complex_direct_notype_declarator): Support global_scope.
* Makefile.in: Adjust conflict count.
@ -18934,7 +18943,7 @@
* semantics.c (finish_member_declaration): Don't mark members of
classes declared in an extern "C" region as extern "C".
2000-05-22 Martin v. Löwis <loewis@informatik.hu-berlin.de>
2000-05-22 Martin v. Löwis <loewis@informatik.hu-berlin.de>
* decl2.c (qualified_lookup_using_namespace): Look through
namespace aliases.
@ -19388,7 +19397,7 @@
* ir.texi: Correct typo.
2000-04-25 Martin v. Löwis <loewis@informatik.hu-berlin.de>
2000-04-25 Martin v. Löwis <loewis@informatik.hu-berlin.de>
* decl.c (grokdeclarator): Reject VLAs as members.
@ -19687,7 +19696,7 @@
(interface_only): Don't declare.
(interface_unknown): Likewise.
2000-04-11 Martin v. Löwis <loewis@informatik.hu-berlin.de>
2000-04-11 Martin v. Löwis <loewis@informatik.hu-berlin.de>
* tree.h (HAVE_TEMPLATES): Remove definition.
* lang-options.h (-fthis-is-variable): Remove documentation.
@ -19742,7 +19751,7 @@
(__pointer_to_member_type_info::__do_catch): Remove.
(__pointer_to_member_type_info::__pointer_catch): Implement.
2000-04-10 Martin v. Löwis <loewis@informatik.hu-berlin.de>
2000-04-10 Martin v. Löwis <loewis@informatik.hu-berlin.de>
* lex.c (init_parse): Remove traces of classof and headof.
* decl2.c (flag_operator_names): Default to 1.
@ -20455,7 +20464,7 @@ Wed Apr 5 15:12:18 MET DST 2000 Jan Hubicka <jh@suse.cz>
* init.c (build_offset_ref): Handle the case of a templated member
function.
2000-03-19 Martin v. Löwis <loewis@informatik.hu-berlin.de>
2000-03-19 Martin v. Löwis <loewis@informatik.hu-berlin.de>
* except.c (expand_exception_blocks): Clear catch_clauses_last.
@ -20481,7 +20490,7 @@ Wed Apr 5 15:12:18 MET DST 2000 Jan Hubicka <jh@suse.cz>
(layout_class_type): Implement new ABI handling of bitfields
longer than their types.
2000-03-18 Martin v. Löwis <loewis@informatik.hu-berlin.de>
2000-03-18 Martin v. Löwis <loewis@informatik.hu-berlin.de>
* parse.y (extdefs): Call ggc_collect.
* parse.c: Regenerated.
@ -21091,7 +21100,7 @@ Wed Apr 5 15:12:18 MET DST 2000 Jan Hubicka <jh@suse.cz>
* decl.c (decls_match): Remove obsolete static member nadgering.
2000-02-21 Martin v. Löwis <loewis@informatik.hu-berlin.de>
2000-02-21 Martin v. Löwis <loewis@informatik.hu-berlin.de>
* decl.c (grokdeclarator): Change ANSI to ISO.
* lex.c (consume_string, readescape, do_identifier): Likewise.
@ -22118,7 +22127,7 @@ Wed Apr 5 15:12:18 MET DST 2000 Jan Hubicka <jh@suse.cz>
* optimize.c (copy_body_r): Clear the operand three of a
TARGET_EXPR when copying it.
2000-01-14 Martin v. Löwis <loewis@informatik.hu-berlin.de>
2000-01-14 Martin v. Löwis <loewis@informatik.hu-berlin.de>
* method.c (build_decl_overload_real): Check whether we are in ::
before returning __builtin_new/delete.
@ -22415,6 +22424,6 @@ Wed Apr 5 15:12:18 MET DST 2000 Jan Hubicka <jh@suse.cz>
(fixup_vtable_deltas1): Likewise.
(finish_struct_1): Likewise.
2000-01-01 Martin v. Löwis <loewis@informatik.hu-berlin.de>
2000-01-01 Martin v. Löwis <loewis@informatik.hu-berlin.de>
* call.c (build_new_method_call): Also check destructors.

View File

@ -5982,48 +5982,35 @@ check_static_variable_definition (tree decl, tree type)
tree
compute_array_index_type (tree name, tree size)
{
tree type = TREE_TYPE (size);
tree itype;
/* If this involves a template parameter, it will be a constant at
instantiation time, but we don't know what the value is yet.
Even if no template parameters are involved, we may an expression
that is not a constant; we don't even simplify `1 + 2' when
processing a template. */
if (processing_template_decl)
/* The array bound must be an integer type. */
if (!dependent_type_p (type) && !INTEGRAL_TYPE_P (type))
{
/* Resolve a qualified reference to an enumerator or static
const data member of ours. */
if (TREE_CODE (size) == SCOPE_REF
&& TREE_OPERAND (size, 0) == current_class_type)
{
tree t = lookup_field (current_class_type,
TREE_OPERAND (size, 1), 0, false);
if (t)
size = t;
}
return build_index_type (build_min (MINUS_EXPR, sizetype,
size, integer_one_node));
if (name)
error ("size of array `%D' has non-integral type `%T'", name, type);
else
error ("size of array has non-integral type `%T'", type);
size = integer_one_node;
type = TREE_TYPE (size);
}
if (abi_version_at_least (2)
/* We should only handle value dependent expressions specially. */
? value_dependent_expression_p (size)
/* But for abi-1, we handled all instances in templates. This
effects the manglings produced. */
: processing_template_decl)
return build_index_type (build_min (MINUS_EXPR, sizetype,
size, integer_one_node));
/* The size might be the result of a cast. */
STRIP_TYPE_NOPS (size);
/* It might be a const variable or enumeration constant. */
size = decl_constant_value (size);
/* The array bound must be an integer type. */
if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
&& TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE
&& TREE_CODE (TREE_TYPE (size)) != BOOLEAN_TYPE)
{
if (name)
error ("size of array `%D' has non-integer type", name);
else
error ("size of array has non-integer type");
size = integer_one_node;
}
/* Normally, the array-bound will be a constant. */
if (TREE_CODE (size) == INTEGER_CST)
{
@ -6065,38 +6052,36 @@ compute_array_index_type (tree name, tree size)
else
error ("size of array is not an integral constant-expression");
}
/* Compute the index of the largest element in the array. It is
one less than the number of elements in the array. */
itype
= fold (cp_build_binary_op (MINUS_EXPR,
cp_convert (ssizetype, size),
cp_convert (ssizetype,
integer_one_node)));
/* Check for variable-sized arrays. We allow such things as an
extension, even though they are not allowed in ANSI/ISO C++. */
if (!TREE_CONSTANT (itype))
else if (pedantic)
{
if (pedantic)
{
if (name)
pedwarn ("ISO C++ forbids variable-size array `%D'",
name);
else
pedwarn ("ISO C++ forbids variable-size array");
}
/* Create a variable-sized array index type. */
itype = variable_size (itype);
if (name)
pedwarn ("ISO C++ forbids variable-size array `%D'", name);
else
pedwarn ("ISO C++ forbids variable-size array");
}
/* Make sure that there was no overflow when creating to a signed
index type. (For example, on a 32-bit machine, an array with
size 2^32 - 1 is too big.) */
else if (TREE_OVERFLOW (itype))
if (processing_template_decl && !TREE_CONSTANT (size))
/* A variable sized array. */
itype = build_min (MINUS_EXPR, sizetype, size, integer_one_node);
else
{
error ("overflow in array dimension");
TREE_OVERFLOW (itype) = 0;
/* Compute the index of the largest element in the array. It is
one less than the number of elements in the array. */
itype
= fold (cp_build_binary_op (MINUS_EXPR,
cp_convert (ssizetype, size),
cp_convert (ssizetype, integer_one_node)));
if (!TREE_CONSTANT (itype))
/* A variable sized array. */
itype = variable_size (itype);
/* Make sure that there was no overflow when creating to a signed
index type. (For example, on a 32-bit machine, an array with
size 2^32 - 1 is too big.) */
else if (TREE_OVERFLOW (itype))
{
error ("overflow in array dimension");
TREE_OVERFLOW (itype) = 0;
}
}
/* Create and return the appropriate index type. */

View File

@ -2242,7 +2242,20 @@ write_array_type (const tree type)
write_unsigned_number (tree_low_cst (max, 1));
}
else
write_expression (TREE_OPERAND (max, 0));
{
max = TREE_OPERAND (max, 0);
if (!abi_version_at_least (2))
{
/* value_dependent_expression_p presumes nothing is
dependent when PROCESSING_TEMPLATE_DECL is zero. */
++processing_template_decl;
if (!value_dependent_expression_p (max))
G.need_abi_warning = 1;
--processing_template_decl;
}
write_expression (max);
}
}
write_char ('_');
write_type (TREE_TYPE (type));

View File

@ -1,3 +1,9 @@
2003-12-16 Nathan Sidwell <nathan@codesourcery.com>
PR c++/9043
* g++.dg/abi/mangle20-1.C: New test.
* g++.dg/abi/mangle20-2.C: New test.
2003-12-16 Mark Mitchell <mark@codesourcery.com>
PR c++/13275

View File

@ -0,0 +1,19 @@
// { dg-do compile }
// { dg-options "-fabi-version=2" }
// Copyright (C) 2003 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 15 Dec 2003 <nathan@codesourcery.com>
// PR 9043
// mangled array types in templates
template <int I> void f(int (*)[2]) {}
template <int I> void g(int (*)[I+2]) {}
static const int I=1;
static const int J=2;
template void f<1>(int (*)[2]);
// { dg-final { scan-assembler "\n_Z1fILi1EEvPA2_i:" } }
template void g<1>(int (*)[3]);
// { dg-final { scan-assembler "\n_Z1gILi1EEvPAplT_Li2E_i:" } }

View File

@ -0,0 +1,16 @@
// { dg-do compile }
// { dg-options "-fabi-version=1 -Wabi" }
// Copyright (C) 2003 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 15 Dec 2003 <nathan@codesourcery.com>
// PR 9043
// mangled array types in templates
template <int I> void f(int (*)[2]) {}
template <int I> void g(int (*)[I+2]) {}
template void f<1>(int (*)[2]); // { dg-warning "mangled name" }
// { dg-final { scan-assembler "\n_Z1fILi1EEvPALi2E_i:" } }
template void g<1>(int (*)[3]);
// { dg-final { scan-assembler "\n_Z1gILi1EEvPAplT_Li2E_i:" } }