[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] Warning message issued with no source line number [PATCH]
From: |
Arnold Robbins |
Subject: |
Re: [bug-gawk] Warning message issued with no source line number [PATCH] |
Date: |
Fri, 19 May 2017 13:26:31 +0300 |
User-agent: |
Heirloom mailx 12.5 6/20/10 |
Hi.
> Date: Wed, 17 May 2017 13:41:49 -0400
> From: "Andrew J. Schorr" <address@hidden>
> To: "Peter J. Farley III" <address@hidden>
> Subject: Re: [bug-gawk] Warning message issued with no source line number
> [PATCH]
> Cc: address@hidden
> Errors-To: address@hidden
>
> On Tue, May 16, 2017 at 11:34:25PM -0400, Peter J. Farley III wrote:
> > > Here's a simpler version:
> > >
> > > bash-4.2$ cat /tmp/test.awk
> > > BEGIN {
> > > "a" 1
> > > }
> > > bash-4.2$ gawk --lint -f /tmp/test.awk
> > > gawk: warning: statement may have no effect
> > >
> > > Interestingly, if the "1" is removed, there is no warning at all:
> > >
> > > bash-4.2$ cat /tmp/test.awk
> > > BEGIN {
> > > "a"
> > > }
> > > bash-4.2$ gawk --lint -f /tmp/test.awk
> > > bash-4.2$
> > >
> > > But still we need to find the bug...
> >
> > Interesting bug. Thanks for the update.
>
> The problem is due to an Op_concat instruction that has source_line set to 0.
> The message printed by msg.c:err includes the source filename and line only if
> sourceline is positive. The attached patch seems to fix this particular
> problem, but it seems like a bit of a hack. I await confirmation from Arnold
> that this is the right way to solve this issue.
>
> Regards,
> Andy
Hi Andy,
Your patch fixes the problem locally. The following change looks to be more
general and catches the issue.
The byte code for 'BEGIN { "a" }' seems to not be caught by add_lint().
That's more work than I have time for right now.
Andy - does this look OK to you to commit?
Thanks,
Arnold
-----------------------------------------------------
diff --git a/awkgram.y b/awkgram.y
index b72d1c8..e4cedca 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -5886,6 +5886,7 @@ add_lint(INSTRUCTION *list, LINTTYPE linttype)
{
#ifndef NO_LINT
INSTRUCTION *ip;
+ int line = 0;
switch (linttype) {
case LINT_assign_in_cond:
@@ -5904,12 +5905,16 @@ 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)
- ;
-
+ for (ip = list->nexti; ip->nexti != list->lasti; ip =
ip->nexti) {
+ if (line == 0 && 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 */
- [bug-gawk] Warning message issued with no source line number, Peter J. Farley III, 2017/05/16
- Re: [bug-gawk] Warning message issued with no source line number, Andrew J. Schorr, 2017/05/16
- Re: [bug-gawk] Warning message issued with no source line number, Peter J. Farley III, 2017/05/16
- Re: [bug-gawk] Warning message issued with no source line number, Andrew J. Schorr, 2017/05/16
- Re: [bug-gawk] Warning message issued with no source line number, Peter J. Farley III, 2017/05/16
- Re: [bug-gawk] Warning message issued with no source line number [PATCH], Andrew J. Schorr, 2017/05/17
- Re: [bug-gawk] Warning message issued with no source line number [PATCH],
Arnold Robbins <=
- Re: [bug-gawk] Warning message issued with no source line number [PATCH], Andrew J. Schorr, 2017/05/19
- Re: [bug-gawk] Warning message issued with no source line number [PATCH], arnold, 2017/05/19