From 0f9d4355a03d000938d87d71ba62f0ac2717334a Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sat, 20 May 2017 22:28:59 +0300 Subject: Make lint checking for "no effect" case smarter about line numbers. --- awkgram.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'awkgram.c') diff --git a/awkgram.c b/awkgram.c index 1d06c4d9..4325e77d 100644 --- a/awkgram.c +++ b/awkgram.c @@ -8324,12 +8324,22 @@ add_lint(INSTRUCTION *list, LINTTYPE linttype) case LINT_no_effect: if (list->lasti->opcode == Op_pop && list->nexti != list->lasti) { - for (ip = list->nexti; ip->nexti != list->lasti; ip = ip->nexti) - ; + int line = 0; + + // Get down to the last instruction (FIXME: why?) + for (ip = list->nexti; ip->nexti != list->lasti; ip = ip->nexti) { + // 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; + } if (do_lint) { /* compile-time warning */ - if (isnoeffect(ip->opcode)) - lintwarn_ln(ip->source_line, ("statement may have no effect")); + if (isnoeffect(ip->opcode)) { + if (ip->source_line != 0) + line = ip->source_line; + lintwarn_ln(line, ("statement may have no effect")); + } } if (ip->opcode == Op_push) { /* run-time warning */ -- cgit v1.2.3