Martin Brænne | bb7e4bc | 2023-04-03 05:42:00 -0700 | [diff] [blame] | 1 | // 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 McCall | ef6dc92 | 2023-06-06 05:50:23 -0700 | [diff] [blame] | 5 | // Tests for control flow involving binary operators. |
Martin Brænne | bb7e4bc | 2023-04-03 05:42:00 -0700 | [diff] [blame] | 6 | |
Sam McCall | ef6dc92 | 2023-06-06 05:50:23 -0700 | [diff] [blame] | 7 | #include "nullability_test.h" |
Martin Brænne | bb7e4bc | 2023-04-03 05:42:00 -0700 | [diff] [blame] | 8 | |
Sam McCall | ef6dc92 | 2023-06-06 05:50:23 -0700 | [diff] [blame] | 9 | TEST 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ænne | bb7e4bc | 2023-04-03 05:42:00 -0700 | [diff] [blame] | 22 | } |
| 23 | |
Sam McCall | ef6dc92 | 2023-06-06 05:50:23 -0700 | [diff] [blame] | 24 | TEST 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 | |
| 36 | TEST 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 | |
| 48 | TEST 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 | } |