Skip to content

Commit 48b2c2a

Browse files
author
Victoria Nguyen
committed
created simple test to check if worker function is inlined; expected to fail
1 parent cb6a02d commit 48b2c2a

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: %clang_analyze_cc1 -Wno-strict-prototypes -Wno-error=implicit-int -verify %s \
2+
// RUN: -I /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include \
3+
// RUN: -analyzer-checker=debug.ExprInspection
4+
5+
#define NULL ((void*) 0)
6+
#include <stdbool.h>
7+
8+
typedef unsigned long int pthread_t;
9+
typedef struct __pthread_attr pthread_attr_t;
10+
11+
int pthread_create(pthread_t *restrict thread,
12+
13+
const pthread_attr_t *restrict attr,
14+
15+
void *(*start_routine)(void*), void *restrict arg);
16+
17+
18+
19+
int pthread_join(pthread_t thread, void **retval);
20+
21+
22+
23+
void clang_analyzer_checkInlined(bool);
24+
25+
void* thread_function(void* arg){
26+
// should expect to fail the test at this line if you set the checkInlined to true
27+
clang_analyzer_checkInlined(false); // no-warning
28+
return NULL;
29+
}
30+
31+
int foo_no_pthread(void)
32+
{
33+
// should expect to pass at this line
34+
clang_analyzer_checkInlined(true); // expected-warning{{TRUE}}
35+
return 0;
36+
}
37+
38+
int main(){
39+
pthread_t p1;
40+
pthread_create(&p1, NULL, &thread_function, NULL);
41+
pthread_join(p1, NULL);
42+
foo_no_pthread();
43+
return 1;
44+
}
45+

0 commit comments

Comments
 (0)