| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: tree.c,v 1.128 2021/01/04 22:33:47 rillig Exp $ */ | | 1 | /* $NetBSD: tree.c,v 1.129 2021/01/04 22:41:56 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1994, 1995 Jochen Pohl | | 4 | * Copyright (c) 1994, 1995 Jochen Pohl |
5 | * All Rights Reserved. | | 5 | * All Rights Reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -27,27 +27,27 @@ | | | @@ -27,27 +27,27 @@ |
27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
32 | */ | | 32 | */ |
33 | | | 33 | |
34 | #if HAVE_NBTOOL_CONFIG_H | | 34 | #if HAVE_NBTOOL_CONFIG_H |
35 | #include "nbtool_config.h" | | 35 | #include "nbtool_config.h" |
36 | #endif | | 36 | #endif |
37 | | | 37 | |
38 | #include <sys/cdefs.h> | | 38 | #include <sys/cdefs.h> |
39 | #if defined(__RCSID) && !defined(lint) | | 39 | #if defined(__RCSID) && !defined(lint) |
40 | __RCSID("$NetBSD: tree.c,v 1.128 2021/01/04 22:33:47 rillig Exp $"); | | 40 | __RCSID("$NetBSD: tree.c,v 1.129 2021/01/04 22:41:56 rillig Exp $"); |
41 | #endif | | 41 | #endif |
42 | | | 42 | |
43 | #include <float.h> | | 43 | #include <float.h> |
44 | #include <limits.h> | | 44 | #include <limits.h> |
45 | #include <math.h> | | 45 | #include <math.h> |
46 | #include <signal.h> | | 46 | #include <signal.h> |
47 | #include <stdlib.h> | | 47 | #include <stdlib.h> |
48 | #include <string.h> | | 48 | #include <string.h> |
49 | | | 49 | |
50 | #include "lint1.h" | | 50 | #include "lint1.h" |
51 | #include "cgram.h" | | 51 | #include "cgram.h" |
52 | | | 52 | |
53 | static tnode_t *new_integer_constant_node(tspec_t, int64_t); | | 53 | static tnode_t *new_integer_constant_node(tspec_t, int64_t); |
| @@ -4006,26 +4006,39 @@ check_precedence_confusion(tnode_t *tn) | | | @@ -4006,26 +4006,39 @@ check_precedence_confusion(tnode_t *tn) |
4006 | | | 4006 | |
4007 | dprint_node(tn); | | 4007 | dprint_node(tn); |
4008 | | | 4008 | |
4009 | if (mp->m_binary) { | | 4009 | if (mp->m_binary) { |
4010 | rparn = 0; | | 4010 | rparn = 0; |
4011 | /* | | 4011 | /* |
4012 | * FIXME: There is a typo "tn->tn_op == CVT", which should | | 4012 | * FIXME: There is a typo "tn->tn_op == CVT", which should |
4013 | * rather be "rn->tn_op". Since tn must be a binary operator, | | 4013 | * rather be "rn->tn_op". Since tn must be a binary operator, |
4014 | * it can never be CVT. | | 4014 | * it can never be CVT. |
4015 | * | | 4015 | * |
4016 | * Before fixing this though, there should be a unit test | | 4016 | * Before fixing this though, there should be a unit test |
4017 | * that demonstrates an actual change in behavior when this | | 4017 | * that demonstrates an actual change in behavior when this |
4018 | * bug gets fixed. | | 4018 | * bug gets fixed. |
| | | 4019 | * |
| | | 4020 | * Right now, the condition is always false. To make it true |
| | | 4021 | * after fixing the typo, the right-hand operand must be an |
| | | 4022 | * explicit cast or an implicit conversion that is |
| | | 4023 | * parenthesized. For the right-hand operand itself, this |
| | | 4024 | * would already be done using the line below the loop. |
| | | 4025 | * |
| | | 4026 | * To make a difference, the right-hand operand must not be |
| | | 4027 | * parenthesized, but its indirect cast or conversion must be. |
| | | 4028 | * |
| | | 4029 | * An implicit conversion is never parenthesized. Therefore |
| | | 4030 | * this must be a cast that is later converted, to build a |
| | | 4031 | * chain. |
4019 | */ | | 4032 | */ |
4020 | for (rn = tn->tn_right; tn->tn_op == CVT; rn = rn->tn_left) | | 4033 | for (rn = tn->tn_right; tn->tn_op == CVT; rn = rn->tn_left) |
4021 | rparn |= rn->tn_parenthesized; | | 4034 | rparn |= rn->tn_parenthesized; |
4022 | rparn |= rn->tn_parenthesized; | | 4035 | rparn |= rn->tn_parenthesized; |
4023 | rop = rn->tn_op; | | 4036 | rop = rn->tn_op; |
4024 | } | | 4037 | } |
4025 | | | 4038 | |
4026 | dowarn = 0; | | 4039 | dowarn = 0; |
4027 | | | 4040 | |
4028 | switch (tn->tn_op) { | | 4041 | switch (tn->tn_op) { |
4029 | case SHL: | | 4042 | case SHL: |
4030 | case SHR: | | 4043 | case SHR: |
4031 | if (!lparn && (lop == PLUS || lop == MINUS)) { | | 4044 | if (!lparn && (lop == PLUS || lop == MINUS)) { |