blob: c976ae806c877e5be714b7a8f3f52d6c6801cc9a [file] [log] [blame]
Martin Brænnebb7e4bc2023-04-03 05:42:00 -07001// Part of the Crubit project, under the Apache License v2.0 with LLVM
2// Exceptions. See /LICENSE for license information.
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
Sam McCallef6dc922023-06-06 05:50:23 -07005// Tests for control flow involving binary operators.
Martin Brænnebb7e4bc2023-04-03 05:42:00 -07006
Sam McCallef6dc922023-06-06 05:50:23 -07007#include "nullability_test.h"
Martin Brænnebb7e4bc2023-04-03 05:42:00 -07008
Sam McCallef6dc922023-06-06 05:50:23 -07009TEST void testAnd(Nullable<int*> x, Nullable<int*> y) {
10 if (x && y) {
11 nonnull(x);
12 nonnull(y);
13 // Type hasn't changed, even though we know x and y are nonnull.
14 type<Nullable<int*>>(x);
15 type<Nullable<int*>>(y);
16 } else {
17 nullable(x);
18 nullable(y);
19 }
20 nullable(x);
21 nullable(y);
Martin Brænnebb7e4bc2023-04-03 05:42:00 -070022}
23
Sam McCallef6dc922023-06-06 05:50:23 -070024TEST void testOr(Nullable<int*> x, Nullable<int*> y) {
25 if (x || y) {
26 nullable(x);
27 nullable(y);
28 } else {
29 nullable(x);
30 nullable(y);
31 }
32 nullable(x);
33 nullable(y);
34}
35
36TEST void testNeither(Nullable<int*> x, Nullable<int*> y) {
37 if (!x && !y) {
38 nullable(x);
39 nullable(y);
40 } else {
41 nullable(x);
42 nullable(y);
43 }
44 nullable(x);
45 nullable(y);
46}
47
48TEST void testNotBoth(Nullable<int*> x, Nullable<int*> y) {
49 if (!x || !y) {
50 nullable(x);
51 nullable(y);
52 } else {
53 nonnull(x);
54 nonnull(y);
55 }
56 nullable(x);
57 nullable(y);
58}