Skip to content

Commit c7ce527

Browse files
author
Daniel Kroening
authored
Merge pull request #858 from tautschnig/dump-c-typedef
Fix dump-c output involving typedef names
2 parents 7ef0091 + 34a476f commit c7ce527

File tree

23 files changed

+741
-68
lines changed

23 files changed

+741
-68
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* GOTO-ANALYZER: New option --unreachable-functions, --reachable-functions
99
* GOTO-INSTRUMENT: New option --undefined-function-is-assume-false
1010
* GOTO-INSTRUMENT: New option --remove-function-body
11+
* GOTO-INSTRUMENT: New option --use-all-headers, changed --use-system-headers to
12+
--no-system-headers
1113

1214

1315
5.7
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include<stdarg.h>
2+
#include<stdlib.h>
3+
4+
void bb_verror_msg(const char *s, va_list p, const char *strerr) {
5+
}
6+
7+
void bb_error_msg(const char *s, ...)
8+
{
9+
va_list p;
10+
va_start(p, s);
11+
bb_verror_msg(s, p, NULL);
12+
va_end(p);
13+
}
14+
15+
int main() {
16+
bb_error_msg("FOOO");
17+
return 0;
18+
}
19+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--dump-c
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
va_list
7+
--
8+
^warning: ignoring
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
typedef long int off_t;
2+
typedef signed char smallint;
3+
4+
typedef struct chain_s {
5+
struct node_s *first;
6+
struct node_s *last;
7+
const char *programname;
8+
} chain;
9+
10+
typedef struct func_s {
11+
struct chain_s body;
12+
} func;
13+
14+
typedef struct node_s {
15+
struct node_s *n;
16+
} node;
17+
18+
typedef struct dumper_t_x {
19+
node n;
20+
off_t dump_skip;
21+
signed int dump_length;
22+
smallint dump_vflag;
23+
} dumper_t;
24+
25+
typedef struct FS_x {
26+
struct FS *nextfs;
27+
signed int bcnt;
28+
} FS;
29+
30+
dumper_t * alloc_dumper(void) {
31+
return (void*) 0;
32+
}
33+
34+
typedef unsigned int uint32_t;
35+
36+
const uint32_t xx[2];
37+
38+
typedef struct node_s2 {
39+
uint32_t info;
40+
} node2;
41+
42+
typedef struct {
43+
int x;
44+
} anon_name;
45+
46+
typedef struct node_s3 {
47+
union {
48+
struct node_s *n;
49+
func *f;
50+
} r;
51+
} node3;
52+
53+
typedef int x_int;
54+
typedef int y_int;
55+
typedef x_int *p_int;
56+
57+
int main() {
58+
node n;
59+
chain c;
60+
dumper_t a;
61+
dumper_t b[3];
62+
node2* sn;
63+
anon_name d;
64+
node3* s3;
65+
y_int y;
66+
p_int p;
67+
alloc_dumper();
68+
return 0;
69+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--dump-c
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
This test should be run via chain.sh, which will try to recompile the dumped C
10+
code. Missing/incomplete typedef output would cause a failure.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
typedef struct
2+
{
3+
char bogus;
4+
} bb_mbstate_t;
5+
6+
int bb_wcrtomb(char *s, char wc, bb_mbstate_t *ps);
7+
8+
int bb_wcrtomb(char *s, char wc, bb_mbstate_t *ps)
9+
{
10+
return 1;
11+
}
12+
13+
int main() {
14+
bb_wcrtomb("foo", 'Z', (void*)1);
15+
return 0;
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--dump-c
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
This test should be run via chain.sh, which will try to recompile the dumped C
10+
code. Missing/incomplete typedef output would cause a failure.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
extern void* memset(void *, int, unsigned long);
2+
3+
typedef void (*__sighandler_t) (int);
4+
5+
typedef __sighandler_t sighandler_t;
6+
7+
typedef struct siginfo {
8+
int si_signo;
9+
} siginfo_t;
10+
11+
struct sigaction {
12+
union {
13+
__sighandler_t _sa_handler;
14+
void (*_sa_sigaction)(int, struct siginfo *, void *);
15+
} _u;
16+
};
17+
18+
#define sa_sigaction _u._sa_sigaction
19+
#define sa_handler _u._sa_handler
20+
21+
static void askpass_timeout(signed int ignore) {
22+
;
23+
}
24+
25+
int main() {
26+
struct sigaction sa, oldsa;
27+
memset(&sa, 0, sizeof(sa));
28+
sa.sa_handler = askpass_timeout;
29+
return 0;
30+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--dump-c
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
This test should be run via chain.sh, which will try to recompile the dumped C
10+
code. Missing/incomplete typedef output would cause a failure.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef _WIN32
2+
3+
#include <signal.h>
4+
#include <stdlib.h>
5+
6+
void sig_block(int sig)
7+
{
8+
sigset_t ss;
9+
sigemptyset(&ss);
10+
sigaddset(&ss, sig);
11+
sigprocmask(SIG_BLOCK, &ss, NULL);
12+
}
13+
14+
int main() {
15+
sig_block(0);
16+
return 0;
17+
}
18+
#else
19+
int main()
20+
{
21+
return 0;
22+
}
23+
#endif
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--dump-c
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
This test should be run via chain.sh, which will try to recompile the dumped C
10+
code. Missing/incomplete typedef output would cause a failure.

src/ansi-c/expr2c.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,14 @@ std::string expr2ct::convert_rec(
558558

559559
c_qualifierst ret_qualifiers;
560560
ret_qualifiers.read(code_type.return_type());
561+
// _Noreturn should go with the return type
562+
if(new_qualifiers.is_noreturn)
563+
{
564+
ret_qualifiers.is_noreturn=true;
565+
new_qualifiers.is_noreturn=false;
566+
q=new_qualifiers.as_string();
567+
}
568+
561569
const typet &return_type=code_type.return_type();
562570

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

18341842
if(dest!="" && isdigit(dest[dest.size()-1]))
18351843
{
1844+
if(dest.find('.')==std::string::npos)
1845+
dest+=".0";
1846+
1847+
// ANSI-C: double is default; float/long-double require annotation
18361848
if(src.type()==float_type())
18371849
dest+='f';
1838-
else if(src.type()==double_type())
1839-
dest+=""; // ANSI-C: double is default
18401850
else if(src.type()==long_double_type())
18411851
dest+='l';
18421852
}
@@ -3522,7 +3532,11 @@ std::string expr2ct::convert_with_precedence(
35223532
return convert_function(src, "isinf", precedence=16);
35233533

35243534
else if(src.id()==ID_bswap)
3525-
return convert_function(src, "bswap", precedence=16);
3535+
return convert_function(
3536+
src,
3537+
"__builtin_bswap"+
3538+
integer2string(pointer_offset_bits(src.op0().type(), ns)),
3539+
precedence=16);
35263540

35273541
else if(src.id()==ID_isnormal)
35283542
return convert_function(src, "isnormal", precedence=16);

src/clobber/clobber_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ int clobber_parse_optionst::doit()
146146
if(!out)
147147
throw std::string("failed to create file simulator.c");
148148

149-
dump_c(goto_functions, true, ns, out);
149+
dump_c(goto_functions, true, false, ns, out);
150150

151151
status() << "instrumentation complete; compile and execute simulator.c"
152152
<< eom;

src/goto-cc/compile.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ void compilet::convert_symbols(goto_functionst &dest)
714714

715715
if(s_it->second.type.id()==ID_code &&
716716
!s_it->second.is_macro &&
717+
!s_it->second.is_type &&
717718
s_it->second.value.id()!="compiled" &&
718719
s_it->second.value.is_not_nil())
719720
{

0 commit comments

Comments
 (0)