Skip to content

Commit cc22448

Browse files
authored
Merge pull request #729 from tautschnig/c-linking
Bug fixes to linking and C/C++ conversion
2 parents 320722f + 3c51152 commit cc22448

26 files changed

+341
-190
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <stddef.h>
2+
3+
struct S
4+
{
5+
int x;
6+
union {
7+
int y;
8+
struct S2
9+
{
10+
int z;
11+
} s[1];
12+
} u[2];
13+
};
14+
15+
int main()
16+
{
17+
int A[offsetof(struct S, u[0].y)==sizeof(int)?1:-1];
18+
#if defined(__GNUC__) && !defined(__clang__)
19+
int B[offsetof(struct S, u->y)==sizeof(int)?1:-1];
20+
int C[offsetof(struct S, u->s[0].z)==sizeof(int)?1:-1];
21+
#endif
22+
return 0;
23+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
^CONVERSION ERROR$

regression/cbmc/Linking6/main.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <stdio.h>
2+
3+
void set();
4+
5+
char buffer[10];
6+
7+
void init() {
8+
int i;
9+
for (i = 0; i < 10; i++) {buffer[i] = 0;}
10+
}
11+
12+
void print() {
13+
printf("buffer = %s\n",buffer);
14+
}
15+
16+
void main () {
17+
init();
18+
set();
19+
print();
20+
}
21+
22+
23+

regression/cbmc/Linking6/module.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <stdlib.h>
2+
3+
extern char buffer[];
4+
5+
static size_t _debug_tempBufferHead = ((size_t)(&buffer));
6+
7+
void set() {
8+
*(char *)_debug_tempBufferHead = 'a';
9+
}

regression/cbmc/Linking6/test.desc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
module.c --pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <assert.h>
2+
3+
#ifdef __GNUC__
4+
int x;
5+
6+
static __attribute__((constructor)) void format_init(void);
7+
8+
static __attribute__((constructor))
9+
void format_init(void)
10+
{
11+
x=42;
12+
return;
13+
}
14+
#endif
15+
16+
int main()
17+
{
18+
#ifdef __GNUC__
19+
assert(x==42);
20+
#endif
21+
return 0;
22+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

regression/cbmc/hex_string1/main.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <assert.h>
2+
3+
#define static_assert(x) ((struct { char some[(x)?1:-1]; }*)0)
4+
5+
int main()
6+
{
7+
static_assert('\xe8'==(char)0xe8);
8+
static_assert(sizeof("abc")==4);
9+
static_assert(sizeof("\u0201")==3);
10+
static_assert(sizeof("\xe8")==2);
11+
static_assert(sizeof("\u0201\xe8")==4);
12+
13+
if("\xe8"[0]!=(char)0xe8)
14+
assert(0);
15+
return 0;
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
^CONVERSION ERROR$

src/ansi-c/ansi_c_convert_type.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,15 @@ void ansi_c_convert_typet::write(typet &type)
272272
throw 0;
273273
}
274274

275+
// asm blocks (cf. regression/ansi-c/asm1) - ignore the asm
276+
if(other.size()==2)
277+
{
278+
if(other.front().id()==ID_asm && other.back().id()==ID_empty)
279+
other.pop_front();
280+
else if(other.front().id()==ID_empty && other.back().id()==ID_asm)
281+
other.pop_back();
282+
}
283+
275284
if(other.size()!=1)
276285
{
277286
error().source_location=source_location;

0 commit comments

Comments
 (0)