Bug 80050 - gcc/genmatch.c: PVS-Studio: V590
Summary: gcc/genmatch.c: PVS-Studio: V590
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 7.0.1
: P3 normal
Target Milestone: ---
Assignee: Richard Biener
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-15 15:06 UTC by Phillip Khandeliants
Modified: 2020-04-17 09:32 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-03-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Phillip Khandeliants 2017-03-15 15:06:27 UTC
We have found a bug using PVS-Studio tool. PVS-Studio is a static code analyzer for C, C++ and C#: https://www.viva64.com/en/pvs-studio/

Analyzer warning: V590 Consider inspecting this expression. The expression is excessive or contains a misprint. genmatch.c 3829

const cpp_token * parser::next ()
{
  const cpp_token *token;
  do
  {
    token = cpp_get_token (r);
  }
  while (   token->type == CPP_PADDING
         && token->type != CPP_EOF);    // <=
  return token;
}
Comment 1 Richard Biener 2017-03-16 14:49:33 UTC
Mine.
Comment 2 Manuel López-Ibáñez 2017-03-17 01:15:28 UTC
Strange that -Wlogical-op does not catch this.
Comment 3 Martin Sebor 2017-03-17 03:12:02 UTC
I thought the same thing.  It looks like a deficiency in the implementation.  The following is a simple test case for the missing warning.  I'm undecided whether to open a separate bug for it or if this bug should track it.

$ cat u.c && gcc -S -Wall -Wextra -Wpedantic -Wlogical-op u.c
int f (int i)
{
  if (i == 123 && i != 456)
    return 1;

  return 2;
}
Comment 4 rguenther@suse.de 2017-03-17 07:41:26 UTC
On Fri, 17 Mar 2017, msebor at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80050
> 
> Martin Sebor <msebor at gcc dot gnu.org> changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|                            |msebor at gcc dot gnu.org
> 
> --- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
> I thought the same thing.  It looks like a deficiency in the implementation. 
> The following is a simple test case for the missing warning.  I'm undecided
> whether to open a separate bug for it or if this bug should track it.

Separate bug please.

> $ cat u.c && gcc -S -Wall -Wextra -Wpedantic -Wlogical-op u.c
> int f (int i)
> {
>   if (i == 123 && i != 456)
>     return 1;
> 
>   return 2;
> }
Comment 5 Richard Biener 2017-03-17 11:04:21 UTC
Fixed.
Comment 6 Richard Biener 2017-03-17 11:04:32 UTC
Author: rguenth
Date: Fri Mar 17 11:04:00 2017
New Revision: 246218

URL: https://gcc.gnu.org/viewcvs?rev=246218&root=gcc&view=rev
Log:
2017-03-17  Richard Biener  <rguenther@suse.de>

	PR middle-end/80050
	* genmatch.c (parser::next): Remove pointless check for CPP_EOF.
	(parser::peek): Likewise.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/genmatch.c
Comment 7 Martin Sebor 2017-03-17 15:46:01 UTC
I've raised bug 80085 for the missing -Wlogical-op warning.