Skip to content

goto-instrument: anonymous structs in typedefs #964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
stahlbauer opened this issue May 24, 2017 · 4 comments
Closed

goto-instrument: anonymous structs in typedefs #964

stahlbauer opened this issue May 24, 2017 · 4 comments

Comments

@stahlbauer
Copy link
Contributor

stahlbauer commented May 24, 2017

The problem is caused by not dumping names of anonymous structs in typedefs. Example:

Input for goto-cc:

#define UNUSED_PARAM __attribute__ ((__unused__))

#  define mbstate_t bb_mbstate_t
#  define wcrtomb   bb_wcrtomb

typedef struct {                
    char bogus;                 
} mbstate_t;

int wcrtomb(char *s, char wc, mbstate_t *ps);

int wcrtomb(char *s, char wc, mbstate_t *ps UNUSED_PARAM)
{
    return 1; 
}

int main() {
    wcrtomb("foo", 'Z', (void*)1);
    return 0;
}

Output of goto-instrument:

typedef struct bb_mbstate_t;

// tag-#anon#ST[S8'bogus']
// file example_collisions1.c line 6
struct anonymous;


// bb_wcrtomb
// file example_collisions1.c line 12
signed int bb_wcrtomb(char *s, char wc, bb_mbstate_t *ps);

typedef struct anonymous
{
  // bogus
  char bogus;
} bb_mbstate_t;


// bb_wcrtomb
// file example_collisions1.c line 12
signed int bb_wcrtomb(char *s, char wc, bb_mbstate_t *ps)
{
  return 1;
}

// main
// file example_collisions1.c line 17
signed int main()
{
  bb_wcrtomb("foo", 'Z', (bb_mbstate_t *)(void *)1);
  return 0;
}

GCC output:

error: unknown type name ‘bb_mbstate_t’
 signed int bb_wcrtomb(char *s, char wc, bb_mbstate_t *ps);

clang output:

example_collisions1.i:1:1: warning: typedef requires a name [-Wmissing-declarations]
typedef struct bb_mbstate_t;
^~~~~~~
example_collisions1.i:10:41: error: must use 'struct' tag to refer to type 'bb_mbstate_t'
signed int bb_wcrtomb(char *s, char wc, bb_mbstate_t *ps);
                                        ^
                                        struct 
example_collisions1.i:21:12: error: conflicting types for 'bb_wcrtomb'
signed int bb_wcrtomb(char *s, char wc, bb_mbstate_t *ps)

@stahlbauer
Copy link
Contributor Author

@tautschnig: FYI

@stahlbauer stahlbauer changed the title goto-instrument: name collision macros not handled correctly goto-instrument: anonymous structs in typedefs May 24, 2017
@tautschnig
Copy link
Collaborator

I have just confirmed that this is already addressed by #858, and have added the above as a regression test.

@tautschnig
Copy link
Collaborator

I'm sorry, I have spoken too soon as it does only work when using an older version of goto-cc. I'll take a look and will provide an update once properly fixed.

@tautschnig
Copy link
Collaborator

This is now fixed, and #858 is updated to include that fix. As such this issue will auto-resolve when #858 is reviewed and merged.

tautschnig added a commit to tautschnig/cbmc that referenced this issue Jun 8, 2017
Follow-up to 99067de, which made expr2c prefer typedef names over
original type expressions.

Thanks Andreas Stahlbauer for providing the regression tests and help in
debugging.

Fixes: diffblue#882
Fixes: diffblue#964
Fixes: diffblue#972
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants