Skip to contentSkip to conversation

Analysis challenges with SmPL for pass-through functions?

cocci Markus Elfring 2 participants 12 messages Oct 19, 2025 – Oct 24, 2025

lore
Share & tools
lore
#0 lore raw

Hello,

I am curious if further developers will become interested to discuss technical details like the following (in combination with the software “Coccinelle 1.3.0”).

Another source file example:
#include <string.h>

void my_test_copy(void)
{
char text[123];
char* target = strcpy(text, "Hello!");
target = strcpy(target, "Bye");
}

A)
SmPL script variant:
@display@
constant char[] input;
identifier x, y;
@@
*y = strcpy(x, input)

Test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> /usr/bin/spatch show_selected_strcpy_calls.cocci test-copy_literal_to_buffer2.c …
@@ -3,6 +3,4 @@
void my_test_copy(void)
{
char text[123];
- char* target = strcpy(text, "Hello!");
- target = strcpy(target, "Bye");
}

B)
SmPL script variant:
@display2@
constant char[] literal;
identifier i;
@@
*i = strcpy(i, literal)

Test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> /usr/bin/spatch show_selected_strcpy_calls2.cocci test-copy_literal_to_buffer2.c …
@@ -4,5 +4,4 @@ void my_test_copy(void)
{
char text[123];
char* target = strcpy(text, "Hello!");
- target = strcpy(target, "Bye");
}

The variable definition was not matched by the second source code search approach because the used identifiers are obviously different there.
This aspect did not hinder an additional match by the first source code search approach according to another assignment for the variable “target” while the same identifier was found by two metavariables.

Will further clarifications become more interesting for corresponding case distinctions?

Regards,
Markus

#1 lore raw
Quoted 55 lines · Markus Elfring

Hello,

I am curious if further developers will become interested to discuss technical details like the following (in combination with the software “Coccinelle 1.3.0”).

Another source file example:
#include <string.h>

void my_test_copy(void)
{
char text[123];
char* target = strcpy(text, "Hello!");
target = strcpy(target, "Bye");
}

A)
SmPL script variant:
@display@
constant char[] input;
identifier x, y;
@@
*y = strcpy(x, input)

Test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> /usr/bin/spatch show_selected_strcpy_calls.cocci test-copy_literal_to_buffer2.c …

(quoted diff) +0 -2
@@ -3,6 +3,4 @@
 void my_test_copy(void)
 {
  char text[123];
- char* target = strcpy(text, "Hello!");
- target = strcpy(target, "Bye");
 }

B)
SmPL script variant:
@display2@
constant char[] literal;
identifier i;
@@
*i = strcpy(i, literal)

Test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> /usr/bin/spatch show_selected_strcpy_calls2.cocci test-copy_literal_to_buffer2.c …

(quoted diff) +0 -1
@@ -4,5 +4,4 @@ void my_test_copy(void)
 {
  char text[123];
  char* target = strcpy(text, "Hello!");
- target = strcpy(target, "Bye");
 }
Quoted 7 lines

The variable definition was not matched by the second source code search approach because the used identifiers are obviously different there.
This aspect did not hinder an additional match by the first source code search approach according to another assignment for the variable “target” while the same identifier was found by two metavariables.

Will further clarifications become more interesting for corresponding case distinctions?

There is no guarantee that two metavariables don't match the same thing. If you don't want them to match the same thing, then you need to use a disjunction. In the first branch, the same metavariable should be used twice, and then in the second branch there would be the two different metavariables. The match should only be indicated for the second branch.

julia

#2 lore raw
Quoted 2 lines
Quoted 1 line

Will further clarifications become more interesting for corresponding case distinctions?

There is no guarantee that two metavariables don't match the same thing.

Will such information become helpful for better software documentation?

Quoted 4 lines

If you don't want them to match the same thing, then you need to use a disjunction. In the first branch, the same metavariable should be used twice, and then in the second branch there would be the two different metavariables. The match should only be indicated for the second branch.

Does such a solution approach indicate a data processing requirement for multiple source code searches so that anything would be excluded finally?

Regards,
Markus

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

Will further clarifications become more interesting for corresponding case distinctions?

There is no guarantee that two metavariables don't match the same thing.

Will such information become helpful for better software documentation?

I guess documentation doesn't usually invalidate all random wrong hypotheses that users may have...

Quoted 9 lines
Quoted 6 lines

If you don't want them to match the same thing, then you need to use a disjunction. In the first branch, the same metavariable should be used twice, and then in the second branch there would be the two different metavariables. The match should only be indicated for the second branch.

Does such a solution approach indicate a data processing requirement for multiple source code searches so that anything would be excluded finally?

No idea what this means.

julia

#4 lore raw
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

If you don't want them to match the same thing, then you need to use a disjunction. In the first branch, the same metavariable should be used twice, and then in the second branch there would be the two different metavariables. The match should only be indicated for the second branch.

Does such a solution approach indicate a data processing requirement for multiple source code searches so that anything would be excluded finally?

No idea what this means.

How many searches would need to be performed for the evaluation of SmPL disjunction elements?

Regards,
Markus

#5 lore raw
Quoted 10 lines · Markus Elfring
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

If you don't want them to match the same thing, then you need to use a disjunction. In the first branch, the same metavariable should be used twice, and then in the second branch there would be the two different metavariables. The match should only be indicated for the second branch.

Does such a solution approach indicate a data processing requirement for multiple source code searches so that anything would be excluded finally?

No idea what this means.

How many searches would need to be performed for the evaluation of SmPL disjunction elements?

I don't know what you mean by counting searches. How is one search defined?

julia

#6 lore raw
Quoted 3 lines
Quoted 2 lines

How many searches would need to be performed for the evaluation of SmPL disjunction elements?

I don't know what you mean by counting searches.

Data processing statistics can become clearer.

Quoted 1 line

How is one search defined?

I guess that distinctions would become helpful according to the granularity.

1. SmPL rules

2. SmPL disjunction elements

Some data processing is probably repeated then.

Regards,
Markus

#7 lore raw
In reply to Julia Lawall
Quoted 2 lines
Quoted 1 line

Will further clarifications become more interesting for corresponding case distinctions?

There is no guarantee that two metavariables don't match the same thing.

Some test cases seem to indicate that a source code search gets restricted to unique data if only a single metavariable is affected.
Are there further constraints to consider for the processing of data types and corresponding contents of (meta-)variables?

Regards,
Markus

#8 lore raw

Sent from my iPhone

Quoted 11 lines · Markus Elfring



Quoted 3 lines
Quoted 2 lines

Will further clarifications become more interesting for corresponding case distinctions?

There is no guarantee that two metavariables don't match the same thing.

Some test cases seem to indicate that a source code search gets restricted to unique data if only a single metavariable is affected.
Are there further constraints to consider for the processing of data types and corresponding contents of (meta-)variables?

I have no idea what this means.

If a maetavariable is inherited into another rule it has to have one value. Otherwise it needs one value per control flow path. But if thee are two occurrences of a metavariable in a pattern , they have to have the same value.

Quoted 3 lines

Regards,
Markus

#9 lore raw
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 1 line

Will further clarifications become more interesting for corresponding case distinctions?

There is no guarantee that two metavariables don't match the same thing.

Some test cases seem to indicate that a source code search gets restricted to unique data if only a single metavariable is affected.

I assume that the initially mentioned SmPL rule “display2” can influence development ideas (for this discussion topic).

Quoted 4 lines
Quoted 2 lines

Are there further constraints to consider for the processing of data types and corresponding contents of (meta-)variables?

I have no idea what this means.

Variables have got some properties.

Including:
* Data type

* Value

Quoted 1 line

If a maetavariable is inherited into another rule it has to have one value.

The data determination is usually needed.

Quoted 1 line

Otherwise it needs one value per control flow path.

Would related options become relevant?

Quoted 1 line

But if thee are two occurrences of a metavariable in a pattern , they have to have the same value.

This aspect is influenced by the number of metavariable identifiers according to a type (or kind) in special ways, isn't it?

Regards,
Markus

#10 lore raw

Re: [cocci] Terminology evolution for SmPL?

In reply to Julia Lawall
Quoted 1 line

There is no guarantee that two metavariables don't match the same thing.

Can such information also mean that some metavariables would be treated as aliases?

I imagine there are further consequences to consider for the involved terminology. Will chances grow to achieve related improvements?

Quoted 1 line

If you don't want them to match the same thing, then you need to use a disjunction.

It seems that there are logical constraints.

Quoted 1 line

In the first branch,

Unwanted source code parts can be excluded at the beginning so that the “gems” would be left over at the end.

Quoted 1 line

the same metavariable should be used twice,

Some processing efforts were needed already for such a condition check. Would it be nice if further symbol information can be reused?

Quoted 1 line

and then in the second branch there would be the two different metavariables.

Can a name registry be helpful here?

Quoted 1 line

The match should only be indicated for the second branch.

Would it eventually become affected by combinatorial explosion?

Regards,
Markus

#11 lore raw
In reply to Markus Elfring
Quoted 5 lines

@display2@
constant char[] literal;
identifier i;
@@
*i = strcpy(i, literal)

Such an SmPL script example can look promising.
How will software refinements evolve for this source code search pattern?

1. Which function (or macro) names would you like to add according to calls where an input parameter gets forwarded to the return value?

2. How many variable reassignments would be avoidable then?

3. Is there a need to exclude the possibility for volatile data accesses?
https://cppreference.com/w/c/language/volatile.html

Regards,
Markus