* [Cocci] new to cocci, help needed
@ 2017-04-21 9:05 Kaspar Schleiser
2017-04-21 9:10 ` Julia Lawall
0 siblings, 1 reply; 7+ messages in thread
From: Kaspar Schleiser @ 2017-04-21 9:05 UTC (permalink / raw)
To: cocci
Hello all,
I'm just beginning to write my own semantic patches, and I'm having a
little trouble getting the hang of it.
Currently I'm trying to unify all calls to a function named "f" taking a
pointer to a variable and the variable's size as arguments, which I want
to deduce using sizeof:
f(..., &var, sizeof(var))
My initial approach looks similar to this:
@@
expression E1, E2;
@@
f(...,*E1,
- E2,
+ sizeof(E1))
... but this doesn't find e.g., "f(a, b, &test, whatever);".
What am I doing wrong?
Thanks in advance,
Kaspar
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Cocci] new to cocci, help needed
2017-04-21 9:05 [Cocci] new to cocci, help needed Kaspar Schleiser
@ 2017-04-21 9:10 ` Julia Lawall
2017-04-21 13:23 ` Kaspar Schleiser
0 siblings, 1 reply; 7+ messages in thread
From: Julia Lawall @ 2017-04-21 9:10 UTC (permalink / raw)
To: cocci
On Fri, 21 Apr 2017, Kaspar Schleiser wrote:
> Hello all,
>
> I'm just beginning to write my own semantic patches, and I'm having a
> little trouble getting the hang of it.
>
> Currently I'm trying to unify all calls to a function named "f" taking a
> pointer to a variable and the variable's size as arguments, which I want
> to deduce using sizeof:
>
> f(..., &var, sizeof(var))
>
>
> My initial approach looks similar to this:
>
> @@
> expression E1, E2;
> @@
>
> f(...,*E1,
> - E2,
> + sizeof(E1))
>
> ... but this doesn't find e.g., "f(a, b, &test, whatever);".
>
> What am I doing wrong?
Your pattern has *E1, but you are hoping to match &E1.
If you mean that E1 should be a random pointer-typed expression, then that
constraint should go in the metavariable list, eg
expression *E1;
julia
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Cocci] new to cocci, help needed
2017-04-21 9:10 ` Julia Lawall
@ 2017-04-21 13:23 ` Kaspar Schleiser
2017-04-21 13:27 ` Julia Lawall
0 siblings, 1 reply; 7+ messages in thread
From: Kaspar Schleiser @ 2017-04-21 13:23 UTC (permalink / raw)
To: cocci
On 04/21/2017 11:10 AM, Julia Lawall wrote:
>
>
> On Fri, 21 Apr 2017, Kaspar Schleiser wrote:
>
>> Hello all,
>>
>> I'm just beginning to write my own semantic patches, and I'm having a
>> little trouble getting the hang of it.
>>
>> Currently I'm trying to unify all calls to a function named "f" taking a
>> pointer to a variable and the variable's size as arguments, which I want
>> to deduce using sizeof:
>>
>> f(..., &var, sizeof(var))
>>
>>
>> My initial approach looks similar to this:
>>
>> @@
>> expression E1, E2;
>> @@
>>
>> f(...,*E1,
>> - E2,
>> + sizeof(E1))
>>
>> ... but this doesn't find e.g., "f(a, b, &test, whatever);".
>>
>> What am I doing wrong?
>
> Your pattern has *E1, but you are hoping to match &E1.
>
> If you mean that E1 should be a random pointer-typed expression, then that
> constraint should go in the metavariable list, eg
>
> expression *E1;
That brings me one step further, but now I have "*&", e.g.,
- f(a,b,&E,whatever)
+ f(a,b,&E,sizeof(*&E))
Is there a way to "dereference the type"?
Kaspar
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Cocci] new to cocci, help needed
2017-04-21 13:23 ` Kaspar Schleiser
@ 2017-04-21 13:27 ` Julia Lawall
2017-04-21 13:41 ` Kaspar Schleiser
0 siblings, 1 reply; 7+ messages in thread
From: Julia Lawall @ 2017-04-21 13:27 UTC (permalink / raw)
To: cocci
On Fri, 21 Apr 2017, Kaspar Schleiser wrote:
>
>
> On 04/21/2017 11:10 AM, Julia Lawall wrote:
> >
> >
> > On Fri, 21 Apr 2017, Kaspar Schleiser wrote:
> >
> >> Hello all,
> >>
> >> I'm just beginning to write my own semantic patches, and I'm having a
> >> little trouble getting the hang of it.
> >>
> >> Currently I'm trying to unify all calls to a function named "f" taking a
> >> pointer to a variable and the variable's size as arguments, which I want
> >> to deduce using sizeof:
> >>
> >> f(..., &var, sizeof(var))
> >>
> >>
> >> My initial approach looks similar to this:
> >>
> >> @@
> >> expression E1, E2;
> >> @@
> >>
> >> f(...,*E1,
> >> - E2,
> >> + sizeof(E1))
> >>
> >> ... but this doesn't find e.g., "f(a, b, &test, whatever);".
> >>
> >> What am I doing wrong?
> >
> > Your pattern has *E1, but you are hoping to match &E1.
> >
> > If you mean that E1 should be a random pointer-typed expression, then that
> > constraint should go in the metavariable list, eg
> >
> > expression *E1;
>
> That brings me one step further, but now I have "*&", e.g.,
>
> - f(a,b,&E,whatever)
> + f(a,b,&E,sizeof(*&E))
I think you would want sizeof(E)?
julia
>
> Is there a way to "dereference the type"?
>
> Kaspar
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Cocci] new to cocci, help needed
2017-04-21 13:27 ` Julia Lawall
@ 2017-04-21 13:41 ` Kaspar Schleiser
2017-04-21 15:11 ` Michael Stefaniuc
0 siblings, 1 reply; 7+ messages in thread
From: Kaspar Schleiser @ 2017-04-21 13:41 UTC (permalink / raw)
To: cocci
On 04/21/2017 03:27 PM, Julia Lawall wrote:
>
>
> On Fri, 21 Apr 2017, Kaspar Schleiser wrote:
>
>>
>>
>> On 04/21/2017 11:10 AM, Julia Lawall wrote:
>>>
>>>
>>> On Fri, 21 Apr 2017, Kaspar Schleiser wrote:
>>>
>>>> Hello all,
>>>>
>>>> I'm just beginning to write my own semantic patches, and I'm having a
>>>> little trouble getting the hang of it.
>>>>
>>>> Currently I'm trying to unify all calls to a function named "f" taking a
>>>> pointer to a variable and the variable's size as arguments, which I want
>>>> to deduce using sizeof:
>>>>
>>>> f(..., &var, sizeof(var))
>>>>
>>>>
>>>> My initial approach looks similar to this:
>>>>
>>>> @@
>>>> expression E1, E2;
>>>> @@
>>>>
>>>> f(...,*E1,
>>>> - E2,
>>>> + sizeof(E1))
>>>>
>>>> ... but this doesn't find e.g., "f(a, b, &test, whatever);".
>>>>
>>>> What am I doing wrong?
>>>
>>> Your pattern has *E1, but you are hoping to match &E1.
>>>
>>> If you mean that E1 should be a random pointer-typed expression, then that
>>> constraint should go in the metavariable list, eg
>>>
>>> expression *E1;
>>
>> That brings me one step further, but now I have "*&", e.g.,
>>
>> - f(a,b,&E,whatever)
>> + f(a,b,&E,sizeof(*&E))
>
> I think you would want sizeof(E)?
Exactly.
Kaspar
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Cocci] new to cocci, help needed
2017-04-21 13:41 ` Kaspar Schleiser
@ 2017-04-21 15:11 ` Michael Stefaniuc
2017-04-21 15:12 ` Julia Lawall
0 siblings, 1 reply; 7+ messages in thread
From: Michael Stefaniuc @ 2017-04-21 15:11 UTC (permalink / raw)
To: cocci
On 04/21/2017 03:41 PM, Kaspar Schleiser wrote:
>
>
> On 04/21/2017 03:27 PM, Julia Lawall wrote:
>>
>>
>> On Fri, 21 Apr 2017, Kaspar Schleiser wrote:
>>
>>>
>>>
>>> On 04/21/2017 11:10 AM, Julia Lawall wrote:
>>>>
>>>>
>>>> On Fri, 21 Apr 2017, Kaspar Schleiser wrote:
>>>>
>>>>> Hello all,
>>>>>
>>>>> I'm just beginning to write my own semantic patches, and I'm having a
>>>>> little trouble getting the hang of it.
>>>>>
>>>>> Currently I'm trying to unify all calls to a function named "f" taking a
>>>>> pointer to a variable and the variable's size as arguments, which I want
>>>>> to deduce using sizeof:
>>>>>
>>>>> f(..., &var, sizeof(var))
>>>>>
>>>>>
>>>>> My initial approach looks similar to this:
>>>>>
>>>>> @@
>>>>> expression E1, E2;
>>>>> @@
>>>>>
>>>>> f(...,*E1,
>>>>> - E2,
>>>>> + sizeof(E1))
>>>>>
>>>>> ... but this doesn't find e.g., "f(a, b, &test, whatever);".
>>>>>
>>>>> What am I doing wrong?
>>>>
>>>> Your pattern has *E1, but you are hoping to match &E1.
>>>>
>>>> If you mean that E1 should be a random pointer-typed expression, then that
>>>> constraint should go in the metavariable list, eg
>>>>
>>>> expression *E1;
>>>
>>> That brings me one step further, but now I have "*&", e.g.,
>>>
>>> - f(a,b,&E,whatever)
>>> + f(a,b,&E,sizeof(*&E))
>>
>> I think you would want sizeof(E)?
I normally use a second rule to clean that one up
@@
expression E;
@@
- *&
E
bye
michael
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Cocci] new to cocci, help needed
2017-04-21 15:11 ` Michael Stefaniuc
@ 2017-04-21 15:12 ` Julia Lawall
0 siblings, 0 replies; 7+ messages in thread
From: Julia Lawall @ 2017-04-21 15:12 UTC (permalink / raw)
To: cocci
> >>>> expression *E1;
> >>>
> >>> That brings me one step further, but now I have "*&", e.g.,
> >>>
> >>> - f(a,b,&E,whatever)
> >>> + f(a,b,&E,sizeof(*&E))
> >>
> >> I think you would want sizeof(E)?
> I normally use a second rule to clean that one up
> @@
> expression E;
> @@
> - *&
> E
This is a good option too.
julia
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-04-21 15:12 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-21 9:05 [Cocci] new to cocci, help needed Kaspar Schleiser
2017-04-21 9:10 ` Julia Lawall
2017-04-21 13:23 ` Kaspar Schleiser
2017-04-21 13:27 ` Julia Lawall
2017-04-21 13:41 ` Kaspar Schleiser
2017-04-21 15:11 ` Michael Stefaniuc
2017-04-21 15:12 ` Julia Lawall
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.