On Fri, 15 Feb 2019, Michael Stefaniuc wrote:

> On 2/15/19 10:04 PM, Julia Lawall wrote:
> >
> >
> > On Thu, 14 Feb 2019, Michael Stefaniuc wrote:
> >
> >> Hello,
> >>
> >> I have this trivial script to remove useless casts to self:
> >> @ disable drop_cast @
> >> type T;
> >> T E;
> >> @@
> >> - (T)
> >>      E
> >>
> >> It works but I'm hitting false positives when the code casts away
> >> qualifiers for field types. Please see the attached test case:
> >> - Good: Cast is kept in foo()
> >> - Bad: Cast is dropped in baz()
> >>
> >> Applying the generated diff will lead to a gcc warning:
> >> $ gcc -c  qualifier.c
> >> qualifier.c: In function ‘baz’:
> >> qualifier.c:12:12: warning: return discards ‘const’ qualifier from
> >> pointer target type [-Wdiscarded-qualifiers]
> >>      return &b->i;
> >>             ^~~~~
> >>
> >> I tried disabling the optional_qualifier iso but that has no effect:
> >> - Not needed for the foo() case
> >> - No effect for the baz() case
> >>
> >> I even tried prepending an alternation with "const T good;" but the cast
> >> still gets removed.
> >
> > The const is now propagated to the fields.  Let me know if there are
> > further problems.
> Many thanks!
>
> I tested it and it removed all but 1 false positive.
> I have also validated that it removed only false positives.
>
> There's a qualifier propagation issue left in the case the field is an
> array. I have attached a patch that extends the tests/qualifier.c test
> case to demonstrate the problem.

Thanks for the report.  I will add that case.

> But actually I am happy about that leftover false positive as that gave
> me a new idea of how to remove some more casts:
> https://source.winehq.org/patches/data/158631

Indeed, this looks like a good idea.

julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to