diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2021-04-14 17:37:11 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2021-04-14 17:37:11 +0300 |
commit | 0a59aaa174784ed6ef7166332670b860ee8054bb (patch) | |
tree | 09a15315b735cb364b40d1b3768465137a2b47db /awkgram.c | |
parent | 752de8b1a557d3ff7f7c1e3c17104fa165b4c6ca (diff) | |
parent | 7d775b9560e8ad2eb1f55a843e27f3b929e35223 (diff) | |
download | egawk-0a59aaa174784ed6ef7166332670b860ee8054bb.tar.gz egawk-0a59aaa174784ed6ef7166332670b860ee8054bb.tar.bz2 egawk-0a59aaa174784ed6ef7166332670b860ee8054bb.zip |
Merge branch 'master' into feature/bool
Diffstat (limited to 'awkgram.c')
-rw-r--r-- | awkgram.c | 36 |
1 files changed, 27 insertions, 9 deletions
@@ -7846,6 +7846,16 @@ isnoeffect(OPCODE type) case Op_not: case Op_in_array: return true; + // Additional opcodes that can be part of an expression + // that has no effect: + case Op_and: + case Op_or: + case Op_push: + case Op_push_i: + case Op_push_array: + case Op_pop: + case Op_lint_plus: + return true; default: break; /* keeps gcc -Wall happy */ } @@ -8659,6 +8669,7 @@ add_lint(INSTRUCTION *list, LINTTYPE linttype) { #ifndef NO_LINT INSTRUCTION *ip; + bool no_effect = true; switch (linttype) { case LINT_assign_in_cond: @@ -8679,26 +8690,33 @@ add_lint(INSTRUCTION *list, LINTTYPE linttype) if (list->lasti->opcode == Op_pop && list->nexti != list->lasti) { int line = 0; - // Get down to the last instruction (FIXME: why?) + // Get down to the last instruction ... for (ip = list->nexti; ip->nexti != list->lasti; ip = ip->nexti) { - // along the way track line numbers, we will use the line + // ... along the way track line numbers, we will use the line // closest to the opcode if that opcode doesn't have one if (ip->source_line != 0) line = ip->source_line; + + // And check each opcode for no effect + no_effect = no_effect && isnoeffect(ip->opcode); } - if (do_lint) { /* compile-time warning */ - if (isnoeffect(ip->opcode)) { + // check the last one also + no_effect = no_effect && isnoeffect(ip->opcode); + + // Only if all the traversed opcodes have no effect do we + // produce a warning. This avoids warnings for things like + // a == b && b = c. + if (do_lint) { /* parse-time warning */ + if (no_effect) { if (ip->source_line != 0) line = ip->source_line; - lintwarn_ln(line, ("statement may have no effect")); + lintwarn_ln(line, _("statement has no effect")); } } - if (ip->opcode == Op_push || ip->opcode == Op_push_i) { /* run-time warning */ - list_append(list, instruction(Op_lint)); - list->lasti->lint_type = linttype; - } + // We no longer place a run-time warning also. One warning + // at parse time is enough. } break; |