Skip to contentSkip to conversation

Checking the isomorphism “ptr_to_array”

cocci Markus Elfring 3 participants 7 messages Mar 6, 2022 – Mar 13, 2022

lore
Share & tools
lore
#0 lore raw

Hello,

I have taken another look at the following code.
https://github.com/coccinelle/coccinelle/blob/57cbff0c5768e22bb2d8c20e8dae74294515c6b3/standard.iso#L556

“…
//
---------------------------------------------------------------------------
// Pointer/Field isomorphisms
//
---------------------------------------------------------------------------

Expression
@ ptr_to_array @
expression E1, E2; // was pure, not sure why that's needed, not good for rule27
identifier fld;
@@

E1->fld => E1[E2].fld
…”

I would interpret such a specification in the way that this SmPL code transformation
can be valid only if the expression “E2” will be represented by something that will be resolved to a zero value.
How do you think about such an implementation detail?

Regards,
Markus

#1 lore raw
Quoted 19 lines · Markus Elfring

Hello,

I have taken another look at the following code.
https://github.com/coccinelle/coccinelle/blob/57cbff0c5768e22bb2d8c20e8dae74294515c6b3/standard.iso#L556

“…
//
---------------------------------------------------------------------------
// Pointer/Field isomorphisms
//
---------------------------------------------------------------------------

Expression
@ ptr_to_array @
expression E1, E2; // was pure, not sure why that's needed, not good for rule27
identifier fld;
@@

Quoted 8 lines

E1->fld => E1[E2].fld
…”

I would interpret such a specification in the way that this SmPL code transformation can be valid only if the expression “E2” will be represented by something that will be resolved to a zero value. How do you think about such an implementation detail?

Seems reasonable iif E2 == 0. Is E2==0 enforced somehow? What is rule27?

Here are some other equivalent transforms I can think of for E1->fld where E2 == 0. Also + could be - when E2==0:

E1->fld = ((&E1)+E2)->fld
E1->fld = (&E1[E2])->fld
E1->fld = (*(E1+E2)).fld
E1->fld = (E1+E2)->fld
E1->fld = (E1+=E2)->fld
E1->fld = (E1++)->fld // but not ++E1

--
Eric Wheeler

Quoted 6 lines

Regards,
Markus

#2 lore raw
Quoted 2 lines

Is E2==0 enforced somehow?

I guess ‒ not yet.

Will any more extensions become relevant for the Coccinelle software so that the semantic patch (or isomorphism) language would be safer for the shown use case?

Quoted 1 line

What is rule27?

I suggest to take another look at a representation for the development history.

https://github.com/coccinelle/coccinelle/blame/57cbff0c5768e22bb2d8c20e8dae74294515c6b3/standard.iso#L560

Thus I imagine that other software developers could tell a bit more about corresponding background information.

Regards,
Markus

#3 lore raw
Quoted 4 lines · Markus Elfring
Quoted 2 lines

Is E2==0 enforced somehow?

Quoted 10 lines

I guess ‒ not yet.

Will any more extensions become relevant for the Coccinelle software so that the semantic patch (or isomorphism) language would be safer for the shown use case?

Quoted 1 line

What is rule27?

There is a dataset called bigtests that was derived from the EuroSys 2008 paper that has a collection of rules with names with numbers, such as 27.

FWIW, rule27 is as follows:

@@
struct BCState *b;
struct IsdnCardState *i;
identifier f,g;
@@

<... // needed to get f and g bound at the same time
(
- b->BC_SetStack = f;
|
- i->bcs->BC_SetStack = f; // have to help the type checker along |
- b->BC_Close = g;
|
- i->bcs->BC_Close = g;
)
...>

@@
identifier str;
struct BCState *b;
struct IsdnCardState *i;
@@

(
i->bc_l1_ops = &str;
|
b->cs->bc_l1_ops = &str;
)

@@
@@

struct bc_l1_ops str = {
...
+ .open = f,
+ .close = g,
};

julia

#4 lore raw
In reply to Eric Wheeler
Quoted 3 lines

Here are some other equivalent transforms I can think of for E1->fld where E2 == 0.

…

Quoted 1 line

E1->fld = (E1++)->fld // but not ++E1

I find that this idea does not refer to an equivalent transformation for such an expression because increment and decrement operators modify their corresponding object.

I would expect that the object should be kept unmodified under all circumstances and independent from special values in this use case.
(Such a transformation might look interesting if you would like to take dynamic constraints better into account accordingly.)

Thus I propose to delete the specification “ptr_to_array” from the file “standard.iso” so that only safe source code searches and adjustments will be performed.

Regards,
Markus

#5 lore raw
Quoted 11 lines · Markus Elfring
Quoted 3 lines

Here are some other equivalent transforms I can think of for E1->fld where E2 == 0.

…

Quoted 1 line

E1->fld = (E1++)->fld // but not ++E1

I find that this idea does not refer to an equivalent transformation for such an expression because increment and decrement operators modify their corresponding object.

Quoted 8 lines

I would expect that the object should be kept unmodified under all circumstances and independent from special values in this use case.
(Such a transformation might look interesting if you would like to take dynamic constraints better into account accordingly.)

Thus I propose to delete the specification “ptr_to_array” from the file “standard.iso” so that only safe source code searches and adjustments will be performed.

Te idea of an isomorphism is that one may related X and Y if transforming one means that one would likely want to transform the other too. It doesn't mean that X and Y are semantically equivalent.

julia

#6 lore raw
Quoted 5 lines
Quoted 2 lines

Thus I propose to delete the specification “ptr_to_array” from the file “standard.iso” so that only safe source code searches and adjustments will be performed.

Te idea of an isomorphism is that one may related X and Y if transforming one means that one would likely want to transform the other too. It doesn't mean that X and Y are semantically equivalent.

I got an other understanding for the term “isomorphism”.

Are there any variations to clarify for involved meanings?

Regards,
Markus