Skip to content

Commit 2a42deb

Browse files
committed
test case
1 parent 83844f4 commit 2a42deb

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| test.c:5:8:5:46 | atomic_compare_exchange_weak(a,b,c) | Function that can spuriously fail not wrapped in a loop. |
2+
| test.c:9:3:9:41 | atomic_compare_exchange_weak(a,b,c) | Function that can spuriously fail not wrapped in a loop. |
3+
| test.c:11:8:12:47 | atomic_compare_exchange_weak_explicit(a,b,c,d,e) | Function that can spuriously fail not wrapped in a loop. |
4+
| test.c:16:3:16:56 | atomic_compare_exchange_weak_explicit(a,b,c,d,e) | Function that can spuriously fail not wrapped in a loop. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/CON41-C/WrapFunctionsThatCanFailSpuriouslyInLoop.ql

c/cert/test/rules/CON41-C/test.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include "stdatomic.h"
2+
3+
void f1() {
4+
int a, b, c;
5+
if (!atomic_compare_exchange_weak(&a, &b, c)) { // NON_COMPLIANT
6+
(void)0; /* no-op */
7+
}
8+
9+
atomic_compare_exchange_weak(&a, &b, c); // NON_COMPLIANT
10+
11+
if (!atomic_compare_exchange_weak_explicit(&a, &b, c, 0,
12+
0)) { // NON_COMPLIANT
13+
(void)0; /* no-op */
14+
}
15+
16+
atomic_compare_exchange_weak_explicit(&a, &b, c, 0, 0); // NON_COMPLIANT
17+
}
18+
19+
void f2() {
20+
int a, b, c;
21+
while (1 == 1) {
22+
if (!atomic_compare_exchange_weak(&a, &b, c)) { // COMPLIANT
23+
(void)0; /* no-op */
24+
}
25+
}
26+
27+
while (!atomic_compare_exchange_weak(&a, &b, c)) { // COMPLIANT
28+
(void)0; /* no-op */
29+
}
30+
31+
do {
32+
(void)0; /* no-op */
33+
} while (!atomic_compare_exchange_weak(&a, &b, c)); // COMPLIANT
34+
35+
while (1 == 1) {
36+
if (!atomic_compare_exchange_weak_explicit(&a, &b, c, 0, 0)) { // COMPLIANT
37+
(void)0; /* no-op */
38+
}
39+
}
40+
41+
while (!atomic_compare_exchange_weak_explicit(&a, &b, c, 0, 0)) { // COMPLIANT
42+
(void)0; /* no-op */
43+
}
44+
45+
do {
46+
(void)0; /* no-op */
47+
} while (
48+
!atomic_compare_exchange_weak_explicit(&a, &b, c, 0, 0)); // COMPLIANT
49+
}

0 commit comments

Comments
 (0)