Skip to content

Commit

Permalink
Merge pull request #584 from goblint/preprocessor_exclude_stdlib
Browse files Browse the repository at this point in the history
Preprocessor directives to disable Goblint includes
  • Loading branch information
michael-schwarz authored Feb 1, 2022
2 parents 1eb0db3 + e1b052a commit 5ecb6c5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions includes/pthread.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifndef GOBLINT_NO_PTHREAD_ONCE
#include <pthread.h>

int pthread_once(pthread_once_t *once_control,void (*init_routine)(void)) __attribute__((goblint_stub));
Expand All @@ -7,3 +8,4 @@ int pthread_once(pthread_once_t *once_control,void (*init_routine)(void)) {
init_routine();
return top;
}
#endif
7 changes: 6 additions & 1 deletion includes/stdlib.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#if !defined(GOBLINT_NO_QSORT) || !defined(GOBLINT_NO_BSEARCH)
#include <stddef.h>
#endif

#ifndef GOBLINT_NO_QSORT
void qsort(void *ptr, size_t count, size_t size, int (*comp)(const void*, const void*)) __attribute__((goblint_stub));
void qsort(void *ptr, size_t count, size_t size, int (*comp)(const void*, const void*)) {
// call all possible compares first, before invalidating array elements
Expand Down Expand Up @@ -28,8 +31,9 @@ void qsort(void *ptr, size_t count, size_t size, int (*comp)(const void*, const

// array isn't actually sorted! just pretend calls for Goblint
}
#endif


#ifndef GOBLINT_NO_BSEARCH
void* bsearch(const void *key, const void *ptr, size_t count, size_t size, int (*comp)(const void*, const void*)) __attribute__((goblint_stub));
void* bsearch(const void *key, const void *ptr, size_t count, size_t size, int (*comp)(const void*, const void*)) {
// linear search for simplicity
Expand All @@ -42,3 +46,4 @@ void* bsearch(const void *key, const void *ptr, size_t count, size_t size, int (

return NULL;
}
#endif
10 changes: 10 additions & 0 deletions tests/regression/41-stdlib/03-noqsort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// PARAM: --set cppflags[+] -DGOBLINT_NO_QSORT
#include<stddef.h>

// There should be no CIL warning about multiple definitions here
void qsort(void *ptr, size_t count, size_t size, int (*comp)(const void*, const void*), int more) {
}

int main() {

}

0 comments on commit 5ecb6c5

Please sign in to comment.