On Wed, Jul 7, 2010 at 10:25 AM, Julia Lawall <[email protected]> wrote:
> I'm not completely sure to understand what the code looks like, so perhaps
> you could send an example.

See the test-pure.c example attached. Function h is an example of a
function that can not be declared as pure since the result will be
returned as argument. Doing so will result in wrong results for some
optimization levels.

What I want to do is to search for functions declared with this
attribute (by means of the #define EINA_PURE, as in the example) and
emit a warning if the function should not be declared that way. The
second part I can deal with, but I couldn't find a way to search for
functions with a certain attribute.


Lucas De Marchi
#include <stdio.h>
#define EINA_PURE __attribute__((pure))

struct a {
    float b;
};

int  f(float a) EINA_PURE;
int  g(struct a *a) EINA_PURE;
int h(struct a *a, int *b) EINA_PURE;


int f(float a) {
    if (a > 6.0)
        return 0;
    else
        return 1;
}

int g(struct a *a)
{
    if (a->b > 6.0)
        return 0;
    else
        return 1;
}

int h(struct a *a, int *b) {
    if (a->b > 6.0)
        *b = 0;
    else
        *b = 1;

    return 0;
}

int main(void)
{
    struct a a;
    int ret;
    float d;

    printf("f --------------\n");
    ret = -100;

    a.b = 10.0;
    ret = f(a.b);
    printf("%d\n", ret);

    a.b = 0.0;
    ret = f(a.b);
    printf("%d\n", ret);

//--------------
    printf("g --------------\n");
    ret = -100;

    a.b = 10.0;
    ret = g(&a);
    printf("%d\n", ret);

    a.b = 0.0;
    ret = g(&a);
    printf("%d\n", ret);

//--------------
    printf("h --------------\n");
    ret = -100;

    a.b = 10.0;
    h(&a, &ret);
    printf("%d\n", ret);

    a.b = 0.0;
    h(&a, &ret);
    printf("%d\n", ret);

    return 0;
}
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to