blob: b09c71f6c6e9de4046a4eda63cd5b3953826dc89 [file] [log] [blame]
Artem Dergacheve2a8e432019-04-23 02:50:38 +00001// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,debug.ExprInspection \
2// RUN: -analyzer-output=text -verify %s
3
4int OSAtomicCompareAndSwapPtrBarrier(*, *, **);
5int OSAtomicCompareAndSwapPtrBarrier() {
6 // There is some body in the actual header,
7 // but we should trust our BodyFarm instead.
8}
9
10int *invalidSLocOnRedecl() {
Artem Dergachev727d6ca2019-04-23 02:56:00 +000011 // Was crashing when trying to throw a report about returning an uninitialized
12 // value to the caller. FIXME: We should probably still throw that report,
13 // something like "The "compare" part of CompareAndSwap depends on an
14 // undefined value".
15 int *b;
Artem Dergacheve2a8e432019-04-23 02:50:38 +000016 OSAtomicCompareAndSwapPtrBarrier(0, 0, &b); // no-crash
Artem Dergachev727d6ca2019-04-23 02:56:00 +000017 return b;
18}
Artem Dergacheve2a8e432019-04-23 02:50:38 +000019
Artem Dergachev727d6ca2019-04-23 02:56:00 +000020void testThatItActuallyWorks() {
21 void *x = 0;
22 int res = OSAtomicCompareAndSwapPtrBarrier(0, &x, &x);
23 clang_analyzer_eval(res); // expected-warning{{TRUE}}
24 // expected-note@-1{{TRUE}}
25 clang_analyzer_eval(x == &x); // expected-warning{{TRUE}}
26 // expected-note@-1{{TRUE}}
Artem Dergacheve2a8e432019-04-23 02:50:38 +000027}