diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2021-04-14 17:33:07 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2021-04-14 17:33:07 +0300 |
commit | a8f16ebdef4e43fcda9a4956e8ef528c33728047 (patch) | |
tree | 20c7b903104970098337a1f322c8b05ed2c67ece /awkgram.c | |
parent | f271311ac33d44e68da147a273847c3ce8552bb8 (diff) | |
download | egawk-a8f16ebdef4e43fcda9a4956e8ef528c33728047.tar.gz egawk-a8f16ebdef4e43fcda9a4956e8ef528c33728047.tar.bz2 egawk-a8f16ebdef4e43fcda9a4956e8ef528c33728047.zip |
Fixes for lint check of no effect.
Diffstat (limited to 'awkgram.c')
-rw-r--r-- | awkgram.c | 36 |
1 files changed, 27 insertions, 9 deletions
@@ -7845,6 +7845,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 */ } @@ -8658,6 +8668,7 @@ add_lint(INSTRUCTION *list, LINTTYPE linttype) { #ifndef NO_LINT INSTRUCTION *ip; + bool no_effect = true; switch (linttype) { case LINT_assign_in_cond: @@ -8678,26 +8689,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; |