Fatal error: exception Coccinelle_modules.Common.Impossible(126)
Bonsoir,
we just found a simple reproducer for an issue that was affecting a few of our files. At least I hope that this is the only issue
bschubert2@imesrv6 red>spatch --sp-file find_bug.cocci --c++=17 coccinelle_bug_example.cppinit_defs_builtins: /usr/lib/coccinelle/standard.h
Starting the test...
HANDLING: coccinelle_bug_example.cpp
Fatal error: exception Coccinelle_modules.Common.Impossible(126)
Issue is here:
// This struct definition with combined variable declaration fails Coccinelle parsing
struct example_struct_t : public base_type_t {
example_struct_t() : base_type_t()
{ }
void do_something() {
REDTRC(0, 0, 0, "Testing %s %d", member1.c_str(), member2);
}
std::string member1 = {"test"};
int member2 = {42};
} global_instance1; // This form causes Coccinelle to failIt works fine if we rewrite it as:
// This struct definition with combined variable declaration fails Coccinelle parsing
struct example_struct_t : public base_type_t {
example_struct_t() : base_type_t()
{ }
void do_something() {
REDTRC(0, 0, 0, "Testing %s %d", member1.c_str(), member2);
}
std::string member1 = {"test"};
int member2 = {42};
};struct example_struct_t global_instance1; // This form works fine
bschubert2@imesrv6 red>spatch --sp-file find_bug.cocci --c++=17 coccinelle_bug_example.cppinit_defs_builtins: /usr/lib/coccinelle/standard.h
Starting the test...
HANDLING: coccinelle_bug_example.cpp
coccinelle_bug_example.cpp:18: Found REDTRC
coccinelle_bug_example.cpp:32: Found REDTRC
coccinelle_bug_example.cpp:8: Found REDTRC
We are using Agument AI and without knowing myself anything about coccinelle, I just let the Agent go over it and it suggested this change, which indeed fixes the issue for me
parsing_c/type_c.ml +3 -1
@@ -224,7 +224,9 @@ let structdef_to_struct_name ty = qu, attr, Ast_c.mk_tybis (StructUnionName (su, s)) [i1;i2] | None, _ -> ty - | x -> raise (Impossible 126) + (* Handle the case of combined struct definition with variable declaration *) + | Some s, _ -> + qu, attr, Ast_c.mk_tybis (StructUnionName (su, s)) (Common.take 2 iis) ) | _ -> raise (Impossible 127)
Thanks,
Bernd
#include <string>
// Base class
class base_type_t {
public:
base_type_t() {}
void log_something() {
REDTRC(0, 0, 0, "Test message %s", "test");
}
};// This struct definition with combined variable declaration fails Coccinelle parsing
struct example_struct_t : public base_type_t {
example_struct_t() : base_type_t()
{ }
void do_something() {
REDTRC(0, 0, 0, "Testing %s %d", member1.c_str(), member2);
}
std::string member1 = {"test"};
int member2 = {42};
} global_instance1; // This form causes Coccinelle to fail// This equivalent separated form works fine with Coccinelle
struct example_struct2_t : public base_type_t {
example_struct2_t() : base_type_t()
{ }
void do_something() {
REDTRC(0, 0, 0, "Testing %s %d", member1.c_str(), member2);
}
std::string member1 = {"test"};
int member2 = {42};
};struct example_struct2_t global_instance2;
@initialize:python@
@@
print('Starting the test...')
@find_redtrc@
expression e1, e2, e3, fmt;
expression list args;
position pos;
@@
REDTRC@pos(e1, e2, e3, fmt, args);
@script:python@
pos << find_redtrc.pos;
@@print("%s:%s: Found REDTRC" % (pos[0].file, pos[0].line))
Quoted 2 lines
we just found a simple reproducer for an issue that was affecting a few of our files. At least I hope that this is the only issue
Thanks for your bug report.
It will trigger further development considerations.
…
Quoted 1 line
}
global_instance1; // This form causes Coccinelle to fail
The test case can be reduced another bit.
SmPL script variant:
@display@
format list fl;
@@
*MY_REDTRC(..., "@fl@", ...);
Another source file example:
struct my_example : public my_base
{
my_example() : my_base()
{ }
void do_something()
{
MY_REDTRC("Testing %d", my_member);
}
int my_member = {42};
} my_var;
Questionable test result (also with the software combination “Coccinelle 1.3-00083-g4093aad2d”):
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> spatch --c++=17 test2_for_Bernd_Schubert-20250426.cocci bug_example3_for_Bernd_Schubert-20250426.cpp …
warning: display: metavariable fl not used in the - or context code
…
Fatal error: exception Coccinelle_modules.Common.Impossible(126)
How will development interests evolve further?
Regards,
Markus
Quoted 11 lines · Bernd Schubert
Bonsoir,
we just found a simple reproducer for an issue that was affecting a few of our files. At least I hope that this is the only issue
bschubert2@imesrv6 red>spatch --sp-file
find_bug.cocci--c++=17 coccinelle_bug_example.cppinit_defs_builtins:/usr/lib/coccinelle/standard.h
Starting the test...
HANDLING: coccinelle_bug_example.cpp
Fatal error: exceptionCoccinelle_modules.Common.Impossible(126)
Thanks for the report. The problem was that the : in : public base_type_t was not being accounted for. I didn't use the provided patch as is, but rather made something more specific to this case. But using the provided patch will also not cause any harm. I will update the version in github shortly.
julia
Quoted 69 lines
Issue is here:
// This struct definition with combined variable declaration fails Coccinelle parsing
struct example_struct_t : public base_type_t { example_struct_t() : base_type_t() { } void do_something() { REDTRC(0, 0, 0, "Testing %s %d", member1.c_str(), member2); } std::string member1 = {"test"}; int member2 = {42}; } global_instance1; // This form causes Coccinelle to failIt works fine if we rewrite it as:
// This struct definition with combined variable declaration fails Coccinelle parsing
struct example_struct_t : public base_type_t { example_struct_t() : base_type_t() { } void do_something() { REDTRC(0, 0, 0, "Testing %s %d", member1.c_str(), member2); } std::string member1 = {"test"}; int member2 = {42}; };struct
example_struct_tglobal_instance1; // This form works finebschubert2@imesrv6 red>spatch --sp-file
find_bug.cocci--c++=17 coccinelle_bug_example.cppinit_defs_builtins:/usr/lib/coccinelle/standard.h
Starting the test...
HANDLING: coccinelle_bug_example.cpp
coccinelle_bug_example.cpp:18: Found REDTRC
coccinelle_bug_example.cpp:32: Found REDTRC
coccinelle_bug_example.cpp:8: Found REDTRCWe are using Agument AI and without knowing myself anything about coccinelle, I just let the Agent go over it and it suggested this change, which indeed fixes the issue for me
parsing_c/type_c.ml +3
-1@@ -224,7 +224,9 @@ let structdef_to_struct_name ty = qu, attr, Ast_c.mk_tybis (StructUnionName (su, s)) [i1;i2] | None, _ -> ty - | x -> raise (Impossible 126) + (* Handle the case of combined struct definition with variable declaration *) + | Some s, _ -> + qu, attr, Ast_c.mk_tybis (StructUnionName (su, s)) (Common.take 2 iis) ) | _ -> raise (Impossible 127)Thanks,
Bernd
Quoted 16 lines · Julia Lawall
Quoted 11 lines · Bernd Schubert
Bonsoir,
we just found a simple reproducer for an issue that was affecting a few of our files. At least I hope that this is the only issue
bschubert2@imesrv6 red>spatch --sp-file
find_bug.cocci--c++=17 coccinelle_bug_example.cppinit_defs_builtins:/usr/lib/coccinelle/standard.h
Starting the test...
HANDLING: coccinelle_bug_example.cpp
Fatal error: exceptionCoccinelle_modules.Common.Impossible(126)
Quoted 6 lines
Thanks for the report. The problem was that the : in : public
base_type_twas not being accounted for. I didn't use the provided patch as is, but rather made something more specific to this case. But using the provided patch will also not cause any harm. I will update the version in github shortly.
Thank you very much!
Bernd