Skip to content

Commit 28ae1a4

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 25a71fc commit 28ae1a4

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

src/ansi-c/library/pthread_lib.c

+3
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

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ inline void longjmp(jmp_buf env, int val)
1313
(void)val;
1414
__CPROVER_assert(0, "longjmp requires instrumentation");
1515
__CPROVER_assume(0);
16+
#ifdef LIBRARY_CHECK
17+
__builtin_unreachable();
18+
#endif
1619
}
1720

1821
/* FUNCTION: _longjmp */
@@ -29,6 +32,9 @@ inline void _longjmp(jmp_buf env, int val)
2932
(void)val;
3033
__CPROVER_assert(0, "_longjmp requires instrumentation");
3134
__CPROVER_assume(0);
35+
#ifdef LIBRARY_CHECK
36+
__builtin_unreachable();
37+
#endif
3238
}
3339

3440
/* FUNCTION: siglongjmp */
@@ -47,6 +53,9 @@ inline void siglongjmp(sigjmp_buf env, int val)
4753
(void)val;
4854
__CPROVER_assert(0, "siglongjmp requires instrumentation");
4955
__CPROVER_assume(0);
56+
#ifdef LIBRARY_CHECK
57+
__builtin_unreachable();
58+
#endif
5059
}
5160

5261
#endif

src/ansi-c/library/stdlib.c

+9
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

+1
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)