extend.texi: Document C++ restricted pointers and references.
* extend.texi: Document C++ restricted pointers and references. * cp-tree.h (grok_method_quals): Return this pointer qualifiers. * decl.c (grokdeclarator): Adjust calls to grok_method_quals. * decl2.c (grok_method_quals): Accept `restrict' as applying to the object pointer. Return such qualifiers. (grokclassfn): Apply this pointer qualifiers. Cleanup unused variables. From-SVN: r30587
This commit is contained in:
parent
73d65336b7
commit
535233a89f
@ -1,12 +1,17 @@
|
|||||||
|
Fri Nov 19 10:41:15 GMT 1999 Nathan Sidwell <nathan@acm.org>
|
||||||
|
|
||||||
|
* extend.texi: Document C++ restricted pointers and references.
|
||||||
|
|
||||||
1999-11-19 Bernd Schmidt <bernds@cygnus.co.uk>
|
1999-11-19 Bernd Schmidt <bernds@cygnus.co.uk>
|
||||||
|
|
||||||
* cse.c (addr_affects_sp): No longer conditional on AUTO_INC_DEC.
|
* cse.c (addr_affects_sp): No longer conditional on AUTO_INC_DEC.
|
||||||
(invalidate_skipped_set): Call it unconditionally.
|
(invalidate_skipped_set): Call it unconditionally.
|
||||||
(cse_set_around_loop): Likewise.
|
(cse_set_around_loop): Likewise.
|
||||||
|
|
||||||
Fri Nov 18 13:39:22 CET 1999 Jam Hubicka <hubicka@freesoft.cz>
|
Fri Nov 18 13:39:22 CET 1999 Jan Hubicka <hubicka@freesoft.cz>
|
||||||
* i386.h (struct_processor_costs): New fileds int_load, int_store, fp_move,
|
|
||||||
fp_load and fp_store
|
* i386.h (struct_processor_costs): New fileds int_load, int_store,
|
||||||
|
fp_move, fp_load and fp_store
|
||||||
(REGISTER_MOVE_COST): Fix comment, calculate exactly the cost of
|
(REGISTER_MOVE_COST): Fix comment, calculate exactly the cost of
|
||||||
fp->int moves
|
fp->int moves
|
||||||
(MEMORY_MOVE_COST): New macro.
|
(MEMORY_MOVE_COST): New macro.
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
1999-11-19 Nathan Sidwell <nathan@acm.org>
|
||||||
|
|
||||||
|
* cp-tree.h (grok_method_quals): Return this pointer qualifiers.
|
||||||
|
* decl.c (grokdeclarator): Adjust calls to grok_method_quals.
|
||||||
|
* decl2.c (grok_method_quals): Accept `restrict' as applying to
|
||||||
|
the object pointer. Return such qualifiers.
|
||||||
|
(grokclassfn): Apply this pointer qualifiers. Cleanup unused
|
||||||
|
variables.
|
||||||
|
|
||||||
1999-11-18 Mark Mitchell <mark@codesourcery.com>
|
1999-11-18 Mark Mitchell <mark@codesourcery.com>
|
||||||
|
|
||||||
* except.c (expand_end_catch_block): Fix typo.
|
* except.c (expand_end_catch_block): Fix typo.
|
||||||
|
@ -3529,7 +3529,7 @@ extern void make_rtl_for_local_static PROTO((tree));
|
|||||||
extern void init_decl2 PROTO((void));
|
extern void init_decl2 PROTO((void));
|
||||||
extern int check_java_method PROTO((tree));
|
extern int check_java_method PROTO((tree));
|
||||||
extern int lang_decode_option PROTO((int, char **));
|
extern int lang_decode_option PROTO((int, char **));
|
||||||
extern tree grok_method_quals PROTO((tree, tree, tree));
|
extern int grok_method_quals PROTO((tree, tree, tree));
|
||||||
extern void warn_if_unknown_interface PROTO((tree));
|
extern void warn_if_unknown_interface PROTO((tree));
|
||||||
extern void grok_x_components PROTO((tree));
|
extern void grok_x_components PROTO((tree));
|
||||||
extern void maybe_retrofit_in_chrg PROTO((tree));
|
extern void maybe_retrofit_in_chrg PROTO((tree));
|
||||||
|
@ -8919,7 +8919,8 @@ create_array_type_for_decl (name, type, size)
|
|||||||
is erroneous, NULL_TREE is returned.
|
is erroneous, NULL_TREE is returned.
|
||||||
|
|
||||||
QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member
|
QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member
|
||||||
function, these are the qualifiers to give to the `this' pointer.
|
function, these are the qualifiers to give to the `this' pointer. We
|
||||||
|
apply TYPE_QUAL_RESTRICT to the this ptr, not the object.
|
||||||
|
|
||||||
May return void_type_node if the declarator turned out to be a friend.
|
May return void_type_node if the declarator turned out to be a friend.
|
||||||
See grokfield for details. */
|
See grokfield for details. */
|
||||||
@ -9836,8 +9837,9 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
|
|||||||
if (ctype != NULL_TREE)
|
if (ctype != NULL_TREE)
|
||||||
{
|
{
|
||||||
tree dummy = build_decl (TYPE_DECL, NULL_TREE, type);
|
tree dummy = build_decl (TYPE_DECL, NULL_TREE, type);
|
||||||
ctype = grok_method_quals (ctype, dummy, quals);
|
grok_method_quals (ctype, dummy, quals);
|
||||||
type = TREE_TYPE (dummy);
|
type = TREE_TYPE (dummy);
|
||||||
|
ctype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type)));
|
||||||
quals = NULL_TREE;
|
quals = NULL_TREE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -780,9 +780,11 @@ lang_decode_option (argc, argv)
|
|||||||
|
|
||||||
/* Incorporate `const' and `volatile' qualifiers for member functions.
|
/* Incorporate `const' and `volatile' qualifiers for member functions.
|
||||||
FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
|
FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
|
||||||
QUALS is a list of qualifiers. */
|
QUALS is a list of qualifiers. Returns any explicit
|
||||||
|
top-level qualifiers of the method's this pointer, anything other than
|
||||||
|
TYPE_UNQUALIFIED will be an extension. */
|
||||||
|
|
||||||
tree
|
int
|
||||||
grok_method_quals (ctype, function, quals)
|
grok_method_quals (ctype, function, quals)
|
||||||
tree ctype, function, quals;
|
tree ctype, function, quals;
|
||||||
{
|
{
|
||||||
@ -790,13 +792,16 @@ grok_method_quals (ctype, function, quals)
|
|||||||
tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
|
tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
|
||||||
int type_quals = TYPE_UNQUALIFIED;
|
int type_quals = TYPE_UNQUALIFIED;
|
||||||
int dup_quals = TYPE_UNQUALIFIED;
|
int dup_quals = TYPE_UNQUALIFIED;
|
||||||
|
int this_quals = TYPE_UNQUALIFIED;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
int tq = cp_type_qual_from_rid (TREE_VALUE (quals));
|
int tq = cp_type_qual_from_rid (TREE_VALUE (quals));
|
||||||
|
|
||||||
if (type_quals & tq)
|
if ((type_quals | this_quals) & tq)
|
||||||
dup_quals |= tq;
|
dup_quals |= tq;
|
||||||
|
else if (tq & TYPE_QUAL_RESTRICT)
|
||||||
|
this_quals |= tq;
|
||||||
else
|
else
|
||||||
type_quals |= tq;
|
type_quals |= tq;
|
||||||
quals = TREE_CHAIN (quals);
|
quals = TREE_CHAIN (quals);
|
||||||
@ -817,7 +822,7 @@ grok_method_quals (ctype, function, quals)
|
|||||||
fntype = build_exception_variant (fntype, raises);
|
fntype = build_exception_variant (fntype, raises);
|
||||||
|
|
||||||
TREE_TYPE (function) = fntype;
|
TREE_TYPE (function) = fntype;
|
||||||
return ctype;
|
return this_quals;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Warn when -fexternal-templates is used and #pragma
|
/* Warn when -fexternal-templates is used and #pragma
|
||||||
@ -961,9 +966,7 @@ grokclassfn (ctype, function, flags, quals)
|
|||||||
tree quals;
|
tree quals;
|
||||||
{
|
{
|
||||||
tree fn_name = DECL_NAME (function);
|
tree fn_name = DECL_NAME (function);
|
||||||
tree arg_types;
|
int this_quals = TYPE_UNQUALIFIED;
|
||||||
tree parm;
|
|
||||||
tree qualtype;
|
|
||||||
|
|
||||||
if (fn_name == NULL_TREE)
|
if (fn_name == NULL_TREE)
|
||||||
{
|
{
|
||||||
@ -973,26 +976,23 @@ grokclassfn (ctype, function, flags, quals)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (quals)
|
if (quals)
|
||||||
qualtype = grok_method_quals (ctype, function, quals);
|
this_quals = grok_method_quals (ctype, function, quals);
|
||||||
else
|
|
||||||
qualtype = ctype;
|
|
||||||
|
|
||||||
arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
|
|
||||||
if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
|
if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
|
||||||
{
|
{
|
||||||
/* Must add the class instance variable up front. */
|
/* Must add the class instance variable up front. */
|
||||||
/* Right now we just make this a pointer. But later
|
/* Right now we just make this a pointer. But later
|
||||||
we may wish to make it special. */
|
we may wish to make it special. */
|
||||||
tree type = TREE_VALUE (arg_types);
|
tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (function)));
|
||||||
|
|
||||||
parm = build_decl (PARM_DECL, this_identifier, type);
|
tree parm = build_decl (PARM_DECL, this_identifier,
|
||||||
|
cp_build_qualified_type (type, this_quals | TYPE_QUAL_CONST));
|
||||||
/* Mark the artificial `this' parameter as "artificial". */
|
/* Mark the artificial `this' parameter as "artificial". */
|
||||||
SET_DECL_ARTIFICIAL (parm);
|
SET_DECL_ARTIFICIAL (parm);
|
||||||
DECL_ARG_TYPE (parm) = type;
|
DECL_ARG_TYPE (parm) = type;
|
||||||
/* We can make this a register, so long as we don't
|
/* We can make this a register, so long as we don't
|
||||||
accidentally complain if someone tries to take its address. */
|
accidentally complain if someone tries to take its address. */
|
||||||
DECL_REGISTER (parm) = 1;
|
DECL_REGISTER (parm) = 1;
|
||||||
TREE_READONLY (parm) = 1;
|
|
||||||
TREE_CHAIN (parm) = last_function_parms;
|
TREE_CHAIN (parm) = last_function_parms;
|
||||||
last_function_parms = parm;
|
last_function_parms = parm;
|
||||||
}
|
}
|
||||||
@ -1003,10 +1003,7 @@ grokclassfn (ctype, function, flags, quals)
|
|||||||
DECL_CLASS_CONTEXT (function) = ctype;
|
DECL_CLASS_CONTEXT (function) = ctype;
|
||||||
|
|
||||||
if (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function))
|
if (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function))
|
||||||
{
|
maybe_retrofit_in_chrg (function);
|
||||||
maybe_retrofit_in_chrg (function);
|
|
||||||
arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags == DTOR_FLAG)
|
if (flags == DTOR_FLAG)
|
||||||
{
|
{
|
||||||
|
@ -3219,6 +3219,7 @@ Predefined Macros,cpp.info,The C Preprocessor}).
|
|||||||
* Naming Results:: Giving a name to C++ function return values.
|
* Naming Results:: Giving a name to C++ function return values.
|
||||||
* Min and Max:: C++ Minimum and maximum operators.
|
* Min and Max:: C++ Minimum and maximum operators.
|
||||||
* Volatiles:: What constitutes an access to a volatile object.
|
* Volatiles:: What constitutes an access to a volatile object.
|
||||||
|
* Restricted Pointers:: C9X restricted pointers and references.
|
||||||
* C++ Interface:: You can use a single C++ header file for both
|
* C++ Interface:: You can use a single C++ header file for both
|
||||||
declarations and definitions.
|
declarations and definitions.
|
||||||
* Template Instantiation:: Methods for ensuring that exactly one copy of
|
* Template Instantiation:: Methods for ensuring that exactly one copy of
|
||||||
@ -3466,6 +3467,55 @@ possible to ignore the return value from functions returning volatile
|
|||||||
references. Again, if you wish to force a read, cast the reference to
|
references. Again, if you wish to force a read, cast the reference to
|
||||||
an rvalue.
|
an rvalue.
|
||||||
|
|
||||||
|
@node Restricted Pointers
|
||||||
|
@section Restricting Pointer Aliasing
|
||||||
|
@cindex restricted pointers
|
||||||
|
@cindex restricted references
|
||||||
|
@cindex restricted this pointer
|
||||||
|
|
||||||
|
As with gcc, g++ understands the C9X proposal of restricted pointers,
|
||||||
|
specified with the @code{__restrict__}, or @code{__restrict} type
|
||||||
|
qualifier. Because you cannot compile C++ by specifying the -flang-isoc9x
|
||||||
|
language flag, @code{restrict} is not a keyword in C++.
|
||||||
|
|
||||||
|
In addition to allowing restricted pointers, you can specify restricted
|
||||||
|
references, which indicate that the reference is not aliased in the local
|
||||||
|
context.
|
||||||
|
|
||||||
|
@example
|
||||||
|
void fn (int *__restrict__ rptr, int &__restrict__ rref)
|
||||||
|
@{
|
||||||
|
@dots{}
|
||||||
|
@}
|
||||||
|
@end example
|
||||||
|
|
||||||
|
@noindent
|
||||||
|
In the body of @code{fn}, @var{rptr} points to an unaliased integer and
|
||||||
|
@var{rref} refers to a (different) unaliased integer.
|
||||||
|
|
||||||
|
You may also specify whether a member function's @var{this} pointer is
|
||||||
|
unaliased by using @code{__restrict__} as a member function qualifier.
|
||||||
|
|
||||||
|
@example
|
||||||
|
void T::fn () __restrict__
|
||||||
|
@{
|
||||||
|
@dots{}
|
||||||
|
@}
|
||||||
|
@end example
|
||||||
|
|
||||||
|
@noindent
|
||||||
|
Within the body of @code{T::fn}, @var{this} will have the effective
|
||||||
|
definition @code{T *__restrict__ const this}. Notice that the
|
||||||
|
interpretation of a @code{__restrict__} member function qualifier is
|
||||||
|
different to that of @code{const} or @code{volatile} qualifier, in that it
|
||||||
|
is applied to the pointer rather than the object. This is consistent with
|
||||||
|
other compilers which implement restricted pointers.
|
||||||
|
|
||||||
|
As with all outermost parameter qualifiers, @code{__restrict__} is
|
||||||
|
ignored in function definition matching. This means you only need to
|
||||||
|
specify @code{__restrict__} in a function definition, rather than
|
||||||
|
in a function prototype as well.
|
||||||
|
|
||||||
@node C++ Interface
|
@node C++ Interface
|
||||||
@section Declarations and Definitions in One Header
|
@section Declarations and Definitions in One Header
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user