Search code examples
ccall-graphcflow

gnu cflow - not recognizing "typedef struct"


GNU cflow analyzes a collection of C source files and prints a graph, charting control flow within the program.

My .c or .cpp file

typedef struct _type_1{
    int a;
} type_1_t;


typedef struct _type_2{
    int a;
} type_2_t;

int main()
{
    type_1_t t1;
    type_2_t t2;

    t1.a = 55;
    t2.a = 99;

    return 0;
}

The command is cflow.exe test.c -i s -i x > test.graph 2>&1 and the output is:

cflow.exe:test.c:7: a redefined
cflow.exe:test.c:2: this is the place of previous definition
main() <int main () at test.c:11>:
    type_1_t <type_1_t at test.c:3>
    t1
    type_2_t <type_2_t at test.c:8>
    t2

QUESTION

Why does it say "a redefined"?
It can only be because it doesn't recognize the typedef struct construct so how do I fix it?

UPDATE

I ran cflow again with --debug=1 and it gave me this:

test.c:3: type _type_1
test.c:3: a/-1 defined to int a
test.c:3: type_1_t/-1 defined to type_1_t
test.c:8: type _type_2
cflow.exe:test.c:7: a redefined
cflow.exe:test.c:2: this is the place of previous definition
main() <int main () at test.c:15>:
    type_1_t <type_1_t at test.c:3>
    t1
    type_2_t <type_2_t at test.c:8>
    t2
    f1() <int f1 () at test.c:10>
test.c:8: a/-1 defined to int a
test.c:8: type_2_t/-1 defined to type_2_t
test.c:11: f1/0 defined to int f1 ()
test.c:16: main/0 defined to int main ()

Just as we suspected: it's not treating each struct . . . as a struct i.e. the ability to have the exact same identifier in two different structs.

So how to fix this? I'm emailing cflow mailing list. Hopefully will hear back soon. Until then, I'm going to play around with the syntactic classes and see if I can't trigger the correct behavior.

I'll post my own answer if I get an answer back from mailing list.


Solution

  • This is clearly a bug in cflow.

    I just built cflow versions 1.3, 1.4, and 1.5 on my system (Ubuntu 17.04). Versions 1.3 and 1.4 do not exhibit the problem you describe. Version 1.5 does.

    Here's a simpler test case that exhibits the problem:

    $ cat c.c
    typedef struct type1 { int a; } type1;
    typedef struct type2 { int a; } type2;
    $ cflow --version | head -n 1
    cflow (GNU cflow) 1.5
    $ cflow c.c
    cflow:c.c:2: a redefined
    cflow:c.c:1: this is the place of previous definition
    $ 
    

    (typedef struct and separate namespaces for different structure types have been features of C for about three decades. It's not plausible that cflow would fail to support them -- and in fact earlier versions handle them with no problem.)

    As a workaround, use cflow 1.4. I also suggest submitting a bug report. It doesn't appear that this one has been reported. (The OP has now reported it to the [email protected] mailing list and received an acknowledgement.)