This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: restrict and pointer casting


"John Graley" <jgraley@broadcom.com> writes:

> I've been looking around for info about the "restrict" keyword. I have found a document titled:
>
> Restricted Pointers in C
> Numerical C Extensions Group, Aliasing Subcommittee
> Final Report: Draft 2, X3J11/94-019, WG14/N334
>
> But I'm not sure if this is actually part of the c99 standard. Is this the definitive document?

No, the definitive document is the C99 standard, section 6.7.3.1.  I
don't know whether the standard is different from that document, but
from your description it seems that it is.


> In section 3.8 it discusses the assignment of a restricted pointer
> value to a pointer not declared as restricted, and the text reads "If
> a compiler tracks pointer values, it should be able to optimize the
> loop as effectively as if the restricted pointers ... were used
> directly." Presumably, therefore, the propagation of restrict in such
> cases is implementation dependent. Can we assume GCC versions from 4
> onwards will implement this?

No, you can't.  gcc's handling of restrict pointers is improving but is
still imperfect.  See, e.g., http://gcc.gnu.org/PR14187 .


> Section 3.9 explains that casting a non-restricted pointer to a
> restricted pointer type does not have any effect. However, it is not
> clear in this section what the behaviour should be when we cast a
> restricted pointer to another pointer type (with or without the
> restrict keyword). Should I read "...the two casts make no assertion
> about aliasing of the references through the pointers..." to mean the
> casted pointer has the same restrictedness property as the original
> pointer? Or that casted pointers are non-restricted in all cases?

The standard is written in terms of pointer expressions which are based
on restrict qualified pointers.  If I'm reading the standard correctly,
then casting the pointer to remove the restrict qualifier does not
eliminate the requirements imposed by the restrict qualifier.  Those
requirements are very subtle, by the way.


> As a final question, how tractable is the gcc implementation in this
> area? Are these choices just simple policy code or are they locked
> into complicated algorithms?

Both statements are true, I suppose.  The aliasing algorithms are fairly
complex, but the way in which they use the restrict qualifier is
relative simple.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]