Treatment of __restrict__

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Treatment of __restrict__

Roberto Bagnara

void f(const char *__restrict__ out) {
   out++;
}

The above testcase brings to the generation of the
following dump:

void f(char const *restrict out) (CompoundStmt 0x27ce5b0 <d.c:1:38, line:4:1>
   (DeclStmt 0x27be5a0 <line:2:3, col:29>
     0x27d2bc0 "char const *restrict d"
   (BinaryOperator 0x27d2d20 <line:3:3, col:7> 'char const *' '='
     (DeclRefExpr 0x27d2c20 <col:3> 'char const *restrict' Var='d' 0x27d2bc0)
     (ImplicitCastExpr 0x27d2ce0 <col:7> 'char const *restrict' <Unknown>
       (ImplicitCastExpr 0x27d2ca0 <col:7> 'char const *' <NoOp>
         (DeclRefExpr 0x27d2c60 <col:7> 'char const *restrict' ParmVar='out' 0x27cf800)))))

This indicates that:

- two apparently useless implicit casts are generated;
- the BinaryOperator node's type has lost the restrict qualifier.

Are these wanted?
Best regards,

     Roberto

--
Prof. Roberto Bagnara
Applied Formal Methods Laboratory
Department of Mathematics, University of Parma, Italy
http://www.cs.unipr.it/~bagnara/
mailto:[hidden email]
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Treatment of __restrict__

Roberto Bagnara
On 05/22/2010 11:20 AM, Roberto Bagnara wrote:

>
> void f(const char *__restrict__ out) {
>     out++;
> }
>
> The above testcase brings to the generation of the
> following dump:
>
> void f(char const *restrict out) (CompoundStmt 0x27ce5b0<d.c:1:38, line:4:1>
>     (DeclStmt 0x27be5a0<line:2:3, col:29>
>       0x27d2bc0 "char const *restrict d"
>     (BinaryOperator 0x27d2d20<line:3:3, col:7>  'char const *' '='
>       (DeclRefExpr 0x27d2c20<col:3>  'char const *restrict' Var='d' 0x27d2bc0)
>       (ImplicitCastExpr 0x27d2ce0<col:7>  'char const *restrict'<Unknown>
>         (ImplicitCastExpr 0x27d2ca0<col:7>  'char const *'<NoOp>
>           (DeclRefExpr 0x27d2c60<col:7>  'char const *restrict' ParmVar='out' 0x27cf800)))))
>
> This indicates that:
>
> - two apparently useless implicit casts are generated;
> - the BinaryOperator node's type has lost the restrict qualifier.
>
> Are these wanted?
> Best regards,
>
>       Roberto
>

Ping.

--
Prof. Roberto Bagnara
Applied Formal Methods Laboratory
Department of Mathematics, University of Parma, Italy
http://www.cs.unipr.it/~bagnara/
mailto:[hidden email]
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Treatment of __restrict__

Roberto Bagnara
On 06/07/2010 01:57 PM, Roberto Bagnara wrote:

> On 05/22/2010 11:20 AM, Roberto Bagnara wrote:
>>
>> void f(const char *__restrict__ out) {
>>      out++;
>> }
>>
>> The above testcase brings to the generation of the
>> following dump:
>>
>> void f(char const *restrict out) (CompoundStmt 0x27ce5b0<d.c:1:38, line:4:1>
>>      (DeclStmt 0x27be5a0<line:2:3, col:29>
>>        0x27d2bc0 "char const *restrict d"
>>      (BinaryOperator 0x27d2d20<line:3:3, col:7>   'char const *' '='
>>        (DeclRefExpr 0x27d2c20<col:3>   'char const *restrict' Var='d' 0x27d2bc0)
>>        (ImplicitCastExpr 0x27d2ce0<col:7>   'char const *restrict'<Unknown>
>>          (ImplicitCastExpr 0x27d2ca0<col:7>   'char const *'<NoOp>
>>            (DeclRefExpr 0x27d2c60<col:7>   'char const *restrict' ParmVar='out' 0x27cf800)))))
>>
>> This indicates that:
>>
>> - two apparently useless implicit casts are generated;
>> - the BinaryOperator node's type has lost the restrict qualifier.
>>
>> Are these wanted?
>> Best regards,
>>
>>        Roberto
>>
>
> Ping.

Ping^2

--
Prof. Roberto Bagnara
Applied Formal Methods Laboratory
Department of Mathematics, University of Parma, Italy
http://www.cs.unipr.it/~bagnara/
mailto:[hidden email]
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Treatment of __restrict__

Douglas Gregor
In reply to this post by Roberto Bagnara

On May 22, 2010, at 2:20 AM, Roberto Bagnara wrote:

>
> void f(const char *__restrict__ out) {
>   out++;
> }
>
> The above testcase brings to the generation of the
> following dump:
>
> void f(char const *restrict out) (CompoundStmt 0x27ce5b0 <d.c:1:38, line:4:1>
>   (DeclStmt 0x27be5a0 <line:2:3, col:29>
>     0x27d2bc0 "char const *restrict d"
>   (BinaryOperator 0x27d2d20 <line:3:3, col:7> 'char const *' '='
>     (DeclRefExpr 0x27d2c20 <col:3> 'char const *restrict' Var='d' 0x27d2bc0)
>     (ImplicitCastExpr 0x27d2ce0 <col:7> 'char const *restrict' <Unknown>
>       (ImplicitCastExpr 0x27d2ca0 <col:7> 'char const *' <NoOp>
>         (DeclRefExpr 0x27d2c60 <col:7> 'char const *restrict' ParmVar='out' 0x27cf800)))))

I think your actual test case was:

        void f(const char *__restrict__ out) {
          const char *restrict d;
          d = out;
        }

> This indicates that:
>
> - two apparently useless implicit casts are generated;

The innercast is from the lvalue-to-rvalue conversion, which strips qualifiers (C99 6.3.2.1p2). The outer cast adjusts the type of the right-hand side to match that of the left-hand side. I don't like the fact that we have an "unknown" conversion there, but otherwise this looks fine.

> - the BinaryOperator node's type has lost the restrict qualifier.


The result of assignment is the unqualified type of the left-hand side (C99 6.5.16p3), so this is also correct.

        - Doug
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev