Skip to content

Commit 489f316

Browse files
committed
C library: add __builtin_unreachable to functions that do not return
These calls are wrapped in #ifdef LIBRARY_CHECK and exist for the sole purpose of making library_check.sh not warn about `noreturn` functions seemingly returning.
1 parent 3b16c63 commit 489f316

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

src/ansi-c/library/pthread_lib.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ inline void pthread_exit(void *value_ptr)
314314
#endif
315315
__CPROVER_threads_exited[__CPROVER_thread_id]=1;
316316
__CPROVER_assume(0);
317+
#ifdef LIBRARY_CHECK
318+
__builtin_unreachable();
319+
#endif
317320
}
318321

319322
/* FUNCTION: pthread_join */

src/ansi-c/library/setjmp.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ inline void longjmp(jmp_buf env, int val)
1212
(void)env;
1313
(void)val;
1414
__CPROVER_assume(0);
15+
#ifdef LIBRARY_CHECK
16+
__builtin_unreachable();
17+
#endif
1518
}
1619

1720
/* FUNCTION: _longjmp */
@@ -27,6 +30,9 @@ inline void _longjmp(jmp_buf env, int val)
2730
(void)env;
2831
(void)val;
2932
__CPROVER_assume(0);
33+
#ifdef LIBRARY_CHECK
34+
__builtin_unreachable();
35+
#endif
3036
}
3137

3238
/* FUNCTION: siglongjmp */
@@ -42,6 +48,9 @@ inline void siglongjmp(sigjmp_buf env, int val)
4248
(void)env;
4349
(void)val;
4450
__CPROVER_assume(0);
51+
#ifdef LIBRARY_CHECK
52+
__builtin_unreachable();
53+
#endif
4554
}
4655

4756
/* FUNCTION: setjmp */

src/ansi-c/library/stdlib.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ inline void exit(int status)
3636
{
3737
(void)status;
3838
__CPROVER_assume(0);
39+
#ifdef LIBRARY_CHECK
40+
__builtin_unreachable();
41+
#endif
3942
}
4043

4144
/* FUNCTION: _Exit */
@@ -46,6 +49,9 @@ inline void _Exit(int status)
4649
{
4750
(void)status;
4851
__CPROVER_assume(0);
52+
#ifdef LIBRARY_CHECK
53+
__builtin_unreachable();
54+
#endif
4955
}
5056

5157
/* FUNCTION: abort */
@@ -55,6 +61,9 @@ inline void _Exit(int status)
5561
inline void abort(void)
5662
{
5763
__CPROVER_assume(0);
64+
#ifdef LIBRARY_CHECK
65+
__builtin_unreachable();
66+
#endif
5867
}
5968

6069
/* FUNCTION: calloc */

src/ansi-c/library_check.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ for f in "$@"; do
77
echo "Checking ${f}"
88
cp "${f}" __libcheck.c
99
perl -p -i -e 's/(__builtin_[^v])/s$1/' __libcheck.c
10+
perl -p -i -e 's/s(__builtin_unreachable)/$1/' __libcheck.c
1011
perl -p -i -e 's/(_mm_.fence)/s$1/' __libcheck.c
1112
perl -p -i -e 's/(__sync_)/s$1/' __libcheck.c
1213
perl -p -i -e 's/(__atomic_)/s$1/' __libcheck.c

0 commit comments

Comments
 (0)