[Cocci] new to cocci, help needed

Michael Stefaniuc mstefani at mykolab.com
Fri Apr 21 17:11:16 CEST 2017


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


More information about the Cocci mailing list