xref: /llvm-project/clang/test/Analysis/OSAtomic_mac.c (revision 7d644e1215b376ec5e915df9ea2eeb56e2d94626)
1 // RUN: %clang_analyze_cc1 -w -analyzer-checker=core,debug.ExprInspection \
2 // RUN:                    -analyzer-output=text -verify %s
3 
4 extern void clang_analyzer_eval(int);
5 
6 int OSAtomicCompareAndSwapPtrBarrier(void *, void *, void **);
OSAtomicCompareAndSwapPtrBarrier(void *,void *,void **)7 int OSAtomicCompareAndSwapPtrBarrier(void *, void *, void **) {
8   // There is some body in the actual header,
9   // but we should trust our BodyFarm instead.
10 }
11 
invalidSLocOnRedecl(void)12 int *invalidSLocOnRedecl(void) {
13   // Was crashing when trying to throw a report about returning an uninitialized
14   // value to the caller. FIXME: We should probably still throw that report,
15   // something like "The "compare" part of CompareAndSwap depends on an
16   // undefined value".
17   int *b;
18   OSAtomicCompareAndSwapPtrBarrier(0, 0, &b); // no-crash
19   return b;
20 }
21 
testThatItActuallyWorks(void)22 void testThatItActuallyWorks(void) {
23   void *x = 0;
24   int res = OSAtomicCompareAndSwapPtrBarrier(0, &x, &x);
25   clang_analyzer_eval(res); // expected-warning{{TRUE}}
26                             // expected-note@-1{{TRUE}}
27   clang_analyzer_eval(x == &x); // expected-warning{{TRUE}}
28                                 // expected-note@-1{{TRUE}}
29 }
30