Bug 67030 - [6 Regression] ARM bootstrap failure due to [-Werror=tautological-compare]
Summary: [6 Regression] ARM bootstrap failure due to [-Werror=tautological-compare]
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: bootstrap (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: 6.0
Assignee: Marek Polacek
URL:
Keywords: build
Depends on:
Blocks:
 
Reported: 2015-07-27 15:58 UTC by ktkachov
Modified: 2015-07-28 16:57 UTC (History)
2 users (show)

See Also:
Host:
Target: arm
Build:
Known to work:
Known to fail: 6.0
Last reconfirmed: 2015-07-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ktkachov 2015-07-27 15:58:48 UTC
I'm getting a bootstrap failure in stage 2 on arm-none-linux-gnueabihf due to the new warning:
$SRC/gcc/cfgexpand.c: In function 'long long int expand_one_var(tree, bool, bool)':
$SRC/gcc/defaults.h:1156:55: error: self-comparison always evaluates to false [-Werror=tautological-compare]
 #define SUPPORTS_STACK_ALIGNMENT (MAX_STACK_ALIGNMENT > STACK_BOUNDARY)

Seems we need to be a bit smarter when it comes to macro expansions?
Comment 1 Marek Polacek 2015-07-27 16:05:51 UTC
Could you please try whether this patch helps?

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 6a79b95..9fe9c5e 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -1890,6 +1890,10 @@ warn_tautological_cmp (location_t loc, enum tree_code code, tree lhs, tree rhs)
   if (TREE_CODE_CLASS (code) != tcc_comparison)
     return;
 
+  if (from_macro_expansion_at (EXPR_LOCATION (lhs))
+      || from_macro_expansion_at (EXPR_LOCATION (rhs)))
+    return;
+
   /* We do not warn for constants because they are typical of macro
      expansions that test for features, sizeof, and similar.  */
   if (CONSTANT_CLASS_P (lhs) || CONSTANT_CLASS_P (rhs))
Comment 2 ktkachov 2015-07-27 16:08:45 UTC
(In reply to Marek Polacek from comment #1)
> Could you please try whether this patch helps?
> 

Trying it out now...
Comment 3 ktkachov 2015-07-27 16:43:13 UTC
(In reply to ktkachov from comment #2)
> (In reply to Marek Polacek from comment #1)
> > Could you please try whether this patch helps?
> > 
> 
> Trying it out now...

Unfortunately still getting the error.
One thing I missed out from the original error message is this note:

error: self-comparison always evaluates to false [-Werror=tautological-compare]
 #define SUPPORTS_STACK_ALIGNMENT (MAX_STACK_ALIGNMENT > STACK_BOUNDARY)

$SRC/gcc/cfgexpand.c:1268:7: note: in expansion of macro 'SUPPORTS_STACK_ALIGNMENT'
   if (SUPPORTS_STACK_ALIGNMENT
       ^

Don't know if that helps.
Comment 4 Marek Polacek 2015-07-27 16:51:28 UTC
(In reply to ktkachov from comment #3)
> Unfortunately still getting the error.

Sorry about that.

> One thing I missed out from the original error message is this note:
> 
> error: self-comparison always evaluates to false
> [-Werror=tautological-compare]
>  #define SUPPORTS_STACK_ALIGNMENT (MAX_STACK_ALIGNMENT > STACK_BOUNDARY)
> 
> $SRC/gcc/cfgexpand.c:1268:7: note: in expansion of macro
> 'SUPPORTS_STACK_ALIGNMENT'
>    if (SUPPORTS_STACK_ALIGNMENT
>        ^
> 
> Don't know if that helps.

Actually, that helps.  I bet the following works.  Mind giving this one a spin?

--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -1890,6 +1890,11 @@ warn_tautological_cmp (location_t loc, enum tree_code code, tree lhs, tree rhs)
   if (TREE_CODE_CLASS (code) != tcc_comparison)
     return;
 
+  if (from_macro_expansion_at (loc)
+      || from_macro_expansion_at (EXPR_LOCATION (lhs))
+      || from_macro_expansion_at (EXPR_LOCATION (rhs)))
+    return;
+
   /* We do not warn for constants because they are typical of macro
      expansions that test for features, sizeof, and similar.  */
   if (CONSTANT_CLASS_P (lhs) || CONSTANT_CLASS_P (rhs))
Comment 5 Marek Polacek 2015-07-27 16:51:50 UTC
Testcase:

#define A a
#define B A
#define FOO (A > B)
int
main ()
{
  int a = 4;
  if (FOO)
    return 5;
}
Comment 6 ktkachov 2015-07-27 17:01:06 UTC
(In reply to Marek Polacek from comment #4)
> (In reply to ktkachov from comment #3)

> 
> Actually, that helps.  I bet the following works.  Mind giving this one a
> spin?

Yes, that seems to work. Bootstrap proceeds from that point i.e. cfgexpand.c compiles.

I have to go offline for the day, so I'll have the full bootstrap result tomorrow but from what I can see this is an obvious fix (to my limited C frontend experience) and it would be nice to have it in ASAP to fix arm bootstrap.

Thanks for the quick response.

> 
> --- a/gcc/c-family/c-common.c
> +++ b/gcc/c-family/c-common.c
> @@ -1890,6 +1890,11 @@ warn_tautological_cmp (location_t loc, enum tree_code
> code, tree lhs, tree rhs)
>    if (TREE_CODE_CLASS (code) != tcc_comparison)
>      return;
>  
> +  if (from_macro_expansion_at (loc)
> +      || from_macro_expansion_at (EXPR_LOCATION (lhs))
> +      || from_macro_expansion_at (EXPR_LOCATION (rhs)))
> +    return;
> +
>    /* We do not warn for constants because they are typical of macro
>       expansions that test for features, sizeof, and similar.  */
>    if (CONSTANT_CLASS_P (lhs) || CONSTANT_CLASS_P (rhs))
Comment 7 Marek Polacek 2015-07-27 17:09:25 UTC
(In reply to ktkachov from comment #6)
> Yes, that seems to work. Bootstrap proceeds from that point i.e. cfgexpand.c
> compiles.
> 
> I have to go offline for the day, so I'll have the full bootstrap result
> tomorrow but from what I can see this is an obvious fix (to my limited C
> frontend experience) and it would be nice to have it in ASAP to fix arm
> bootstrap.

Thanks, glad to hear that.  I'll commit the patch after doing some testing on x86_64 (give me ~2 hours).
Comment 8 Tom de Vries 2015-07-27 17:31:13 UTC
FYI, I'm running into this bootstrap failure on x86_64 (r226251):
...
src/gcc/ipa-devirt.c: In function ‘bool types_same_for_odr(const_tree, const_tree, bool)’:
src/gcc/ipa-devirt.c:553:8: error: self-comparison always evaluates to false [-Werror=tautological-compare]
        != (TYPE_BINFO (type1) == NULL_TREE))
...
Comment 9 Marek Polacek 2015-07-27 18:20:13 UTC
(In reply to vries from comment #8)
> FYI, I'm running into this bootstrap failure on x86_64 (r226251):

Weird I don't see this myself.

> ...
> src/gcc/ipa-devirt.c: In function ‘bool types_same_for_odr(const_tree,
> const_tree, bool)’:
> src/gcc/ipa-devirt.c:553:8: error: self-comparison always evaluates to false
> [-Werror=tautological-compare]
>         != (TYPE_BINFO (type1) == NULL_TREE))
> ...

 551       if (TREE_CODE (type1) == RECORD_TYPE
 552           && (TYPE_BINFO (type1) == NULL_TREE)
 553               != (TYPE_BINFO (type1) == NULL_TREE))

Ok, that's a clear typo; something that this warning is designed to detect.  I'm fixing this separately.  Thanks for reporting.
Comment 10 Marek Polacek 2015-07-27 19:09:58 UTC
Author: mpolacek
Date: Mon Jul 27 19:09:27 2015
New Revision: 226264

URL: https://gcc.gnu.org/viewcvs?rev=226264&root=gcc&view=rev
Log:
	PR bootstrap/67030
	* c-common.c (warn_tautological_cmp): Don't warn for macro expansion.

	* c-c++-common/Wtautological-compare-2.c: New test.

Added:
    trunk/gcc/testsuite/c-c++-common/Wtautological-compare-2.c
Modified:
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-common.c
    trunk/gcc/testsuite/ChangeLog
Comment 11 Marek Polacek 2015-07-27 19:15:37 UTC
Fixed (fingers crossed).
Comment 12 Christian Joensson 2015-07-27 19:22:26 UTC
Still...
../../gcc/ipa-devirt.c: In function ‘bool types_same_for_odr(const_tree, const_tree, bool ’:
../../gcc/ipa-devirt.c:553:8: error: self-comparison always evaluates to false [-Werror=tautological-compare]
        != (TYPE_BINFO (type1) == NULL_TREE))
        ^
Comment 13 Marek Polacek 2015-07-27 19:37:29 UTC
That is fixed as well now.
Comment 14 Christian Joensson 2015-07-27 19:42:25 UTC
(In reply to Marek Polacek from comment #13)
> That is fixed as well now.

Yep. Thanks.
Comment 15 ktkachov 2015-07-28 08:14:04 UTC
Yeah, that problem is fixed.
Now bootstrap fails due to:
gcc/vec.h:307:3: error: attempt to free a non-heap object 'intersecting' [-Werror=free-nonheap-object]
   ::free (v);
   ^


But that must be a different problem.
Will analyze and file a separate PR...
Comment 16 Marek Polacek 2015-07-28 08:24:08 UTC
Yeah, that doesn't look related to this warning at all.  Thanks for checking.
Comment 17 ktkachov 2015-07-28 16:57:38 UTC
(In reply to Marek Polacek from comment #16)
> Yeah, that doesn't look related to this warning at all.  Thanks for checking.

Yeah, turns out that was due to a private patch of mine.
Clean trunk bootstraps ok.
Sorry for the noise.