xref: /minix3/external/bsd/llvm/dist/clang/test/Analysis/OSAtomic_mac.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-checker=core,osx -analyzer-store=region -verify -fblocks   -analyzer-opt-analyze-nested-blocks %s
2*f4a2713aSLionel Sambuc // expected-no-diagnostics
3*f4a2713aSLionel Sambuc 
4*f4a2713aSLionel Sambuc // Test handling of OSAtomicCompareAndSwap when C++ inserts "no-op" casts and we
5*f4a2713aSLionel Sambuc // do a forced load and binding to the environment on an expression that would regularly
6*f4a2713aSLionel Sambuc // not have an environment binding.  This previously triggered a crash (<rdar://problem/9339920>).
7*f4a2713aSLionel Sambuc // NOTE: It is critical that the function called is OSAtomicCompareAndSwapIntBarrier.
8*f4a2713aSLionel Sambuc bool OSAtomicCompareAndSwapIntBarrier( int __oldValue, int __newValue, volatile int *__theValue ) ;
9*f4a2713aSLionel Sambuc static int _rdar9339920_x = 0;
10*f4a2713aSLionel Sambuc int rdar9339920_aux();
11*f4a2713aSLionel Sambuc 
rdar9339920_test()12*f4a2713aSLionel Sambuc int rdar9339920_test() {
13*f4a2713aSLionel Sambuc   int rdar9339920_x = rdar9339920_aux();
14*f4a2713aSLionel Sambuc   if (rdar9339920_x != _rdar9339920_x) {
15*f4a2713aSLionel Sambuc     if (OSAtomicCompareAndSwapIntBarrier(_rdar9339920_x, rdar9339920_x, &_rdar9339920_x))
16*f4a2713aSLionel Sambuc       return 1;
17*f4a2713aSLionel Sambuc   }
18*f4a2713aSLionel Sambuc   return 0;
19*f4a2713aSLionel Sambuc }
20*f4a2713aSLionel Sambuc 
21