Skip to content

Fix dump-c output involving typedef names #858

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

Merged
merged 16 commits into from
Jul 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* GOTO-ANALYZER: New option --unreachable-functions, --reachable-functions
* GOTO-INSTRUMENT: New option --undefined-function-is-assume-false
* GOTO-INSTRUMENT: New option --remove-function-body
* GOTO-INSTRUMENT: New option --use-all-headers, changed --use-system-headers to
--no-system-headers


5.7
Expand Down
19 changes: 19 additions & 0 deletions regression/goto-instrument/dump-vararg1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include<stdarg.h>
#include<stdlib.h>

void bb_verror_msg(const char *s, va_list p, const char *strerr) {
}

void bb_error_msg(const char *s, ...)
{
va_list p;
va_start(p, s);
bb_verror_msg(s, p, NULL);
va_end(p);
}

int main() {
bb_error_msg("FOOO");
return 0;
}

8 changes: 8 additions & 0 deletions regression/goto-instrument/dump-vararg1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--dump-c
^EXIT=0$
^SIGNAL=0$
va_list
--
^warning: ignoring
69 changes: 69 additions & 0 deletions regression/goto-instrument/typedef1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
typedef long int off_t;
typedef signed char smallint;

typedef struct chain_s {
struct node_s *first;
struct node_s *last;
const char *programname;
} chain;

typedef struct func_s {
struct chain_s body;
} func;

typedef struct node_s {
struct node_s *n;
} node;

typedef struct dumper_t_x {
node n;
off_t dump_skip;
signed int dump_length;
smallint dump_vflag;
} dumper_t;

typedef struct FS_x {
struct FS *nextfs;
signed int bcnt;
} FS;

dumper_t * alloc_dumper(void) {
return (void*) 0;
}

typedef unsigned int uint32_t;

const uint32_t xx[2];

typedef struct node_s2 {
uint32_t info;
} node2;

typedef struct {
int x;
} anon_name;

typedef struct node_s3 {
union {
struct node_s *n;
func *f;
} r;
} node3;

typedef int x_int;
typedef int y_int;
typedef x_int *p_int;

int main() {
node n;
chain c;
dumper_t a;
dumper_t b[3];
node2* sn;
anon_name d;
node3* s3;
y_int y;
p_int p;
alloc_dumper();
return 0;
}
10 changes: 10 additions & 0 deletions regression/goto-instrument/typedef1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
main.c
--dump-c
^EXIT=0$
^SIGNAL=0$
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't clear to me what this test actually checks - could you perhaps add some matching lines

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added comments in the test to clarify!

--
^warning: ignoring
--
This test should be run via chain.sh, which will try to recompile the dumped C
code. Missing/incomplete typedef output would cause a failure.
16 changes: 16 additions & 0 deletions regression/goto-instrument/typedef2/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
typedef struct
{
char bogus;
} bb_mbstate_t;

int bb_wcrtomb(char *s, char wc, bb_mbstate_t *ps);

int bb_wcrtomb(char *s, char wc, bb_mbstate_t *ps)
{
return 1;
}

int main() {
bb_wcrtomb("foo", 'Z', (void*)1);
return 0;
}
10 changes: 10 additions & 0 deletions regression/goto-instrument/typedef2/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
main.c
--dump-c
^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
--
This test should be run via chain.sh, which will try to recompile the dumped C
code. Missing/incomplete typedef output would cause a failure.
30 changes: 30 additions & 0 deletions regression/goto-instrument/typedef3/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
extern void* memset(void *, int, unsigned long);

typedef void (*__sighandler_t) (int);

typedef __sighandler_t sighandler_t;

typedef struct siginfo {
int si_signo;
} siginfo_t;

struct sigaction {
union {
__sighandler_t _sa_handler;
void (*_sa_sigaction)(int, struct siginfo *, void *);
} _u;
};

#define sa_sigaction _u._sa_sigaction
#define sa_handler _u._sa_handler

static void askpass_timeout(signed int ignore) {
;
}

int main() {
struct sigaction sa, oldsa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = askpass_timeout;
return 0;
}
10 changes: 10 additions & 0 deletions regression/goto-instrument/typedef3/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
main.c
--dump-c
^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
--
This test should be run via chain.sh, which will try to recompile the dumped C
code. Missing/incomplete typedef output would cause a failure.
23 changes: 23 additions & 0 deletions regression/goto-instrument/typedef4/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef _WIN32

#include <signal.h>
#include <stdlib.h>

void sig_block(int sig)
{
sigset_t ss;
sigemptyset(&ss);
sigaddset(&ss, sig);
sigprocmask(SIG_BLOCK, &ss, NULL);
}

int main() {
sig_block(0);
return 0;
}
#else
int main()
{
return 0;
}
#endif
10 changes: 10 additions & 0 deletions regression/goto-instrument/typedef4/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
main.c
--dump-c
^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
--
This test should be run via chain.sh, which will try to recompile the dumped C
code. Missing/incomplete typedef output would cause a failure.
20 changes: 17 additions & 3 deletions src/ansi-c/expr2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,14 @@ std::string expr2ct::convert_rec(

c_qualifierst ret_qualifiers;
ret_qualifiers.read(code_type.return_type());
// _Noreturn should go with the return type
if(new_qualifiers.is_noreturn)
{
ret_qualifiers.is_noreturn=true;
new_qualifiers.is_noreturn=false;
q=new_qualifiers.as_string();
}

const typet &return_type=code_type.return_type();

// return type may be a function pointer or array
Expand Down Expand Up @@ -1833,10 +1841,12 @@ std::string expr2ct::convert_constant(

if(dest!="" && isdigit(dest[dest.size()-1]))
{
if(dest.find('.')==std::string::npos)
dest+=".0";

// ANSI-C: double is default; float/long-double require annotation
if(src.type()==float_type())
dest+='f';
else if(src.type()==double_type())
dest+=""; // ANSI-C: double is default
else if(src.type()==long_double_type())
dest+='l';
}
Expand Down Expand Up @@ -3522,7 +3532,11 @@ std::string expr2ct::convert_with_precedence(
return convert_function(src, "isinf", precedence=16);

else if(src.id()==ID_bswap)
return convert_function(src, "bswap", precedence=16);
return convert_function(
src,
"__builtin_bswap"+
integer2string(pointer_offset_bits(src.op0().type(), ns)),
precedence=16);

else if(src.id()==ID_isnormal)
return convert_function(src, "isnormal", precedence=16);
Expand Down
2 changes: 1 addition & 1 deletion src/clobber/clobber_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ int clobber_parse_optionst::doit()
if(!out)
throw std::string("failed to create file simulator.c");

dump_c(goto_functions, true, ns, out);
dump_c(goto_functions, true, false, ns, out);

status() << "instrumentation complete; compile and execute simulator.c"
<< eom;
Expand Down
1 change: 1 addition & 0 deletions src/goto-cc/compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ void compilet::convert_symbols(goto_functionst &dest)

if(s_it->second.type.id()==ID_code &&
!s_it->second.is_macro &&
!s_it->second.is_type &&
s_it->second.value.id()!="compiled" &&
s_it->second.value.is_not_nil())
{
Expand Down
Loading