Skip to content

Commit 2213fae

Browse files
committed
Fix dump-c output involving typedef names
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
1 parent 66fd36f commit 2213fae

File tree

10 files changed

+502
-5
lines changed

10 files changed

+502
-5
lines changed
+69
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+
}
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.
+16
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+
}
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.
+30
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+
}
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.

0 commit comments

Comments
 (0)