New issue
Advanced search Search tips

Issue 793189 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: Dec 2017
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 1
Type: Bug

Blocking:
issue 787920



Sign in to add a comment

Clang ToT bots failing with -Wtautological-constant-out-of-range-compare

Project Member Reported by h...@chromium.org, Dec 8 2017

Issue description

From https://ci.chromium.org/buildbot/chromium.clang/ToTLinux%20%28dbg%29/1242

FAILED: obj/base/base/trace_log.o 
../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/base/base/trace_log.o.d -DUSE_SYMBOLIZE -DV8_DEPRECATION_WARNINGS -DUSE_UDEV -DUSE_AURA=1 -DUSE_GLIB=1 -DUSE_NSS_CERTS=1 -DUSE_X11=1 -DFULL_SAFE_BROWSING -DSAFE_BROWSING_CSD -DSAFE_BROWSING_DB_LOCAL -DCHROMIUM_BUILD -DFIELDTRIAL_TESTING_ENABLED -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -DCR_CLANG_REVISION=\"320130\" -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -DCOMPONENT_BUILD -D_DEBUG -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DWTF_USE_DYNAMIC_ANNOTATIONS=1 -D_GLIBCXX_DEBUG=1 -DBASE_IMPLEMENTATION -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32 -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_26 -I../.. -Igen -I../../build/linux/debian_stretch_amd64-sysroot/usr/include/glib-2.0 -I../../build/linux/debian_stretch_amd64-sysroot/usr/lib/x86_64-linux-gnu/glib-2.0/include -fno-strict-aliasing --param=ssp-buffer-size=4 -fstack-protector -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -funwind-tables -fPIC -pipe -B../../third_party/binutils/Linux_x64/Release/bin -pthread -fcolor-diagnostics -Xclang -mllvm -Xclang -instcombine-lower-dbg-declare=0 -no-canonical-prefixes -m64 -march=x86-64 -Wall -Werror -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -Wno-c++11-narrowing -Wno-covered-switch-default -Wno-unneeded-internal-declaration -Wno-inconsistent-missing-override -Wno-undefined-var-template -Wno-nonportable-include-path -Wno-address-of-packed-member -Wno-unused-lambda-capture -Wno-user-defined-warnings -Wno-enum-compare-switch -Wno-tautological-unsigned-zero-compare -Wno-null-pointer-arithmetic -Wno-tautological-constant-compare -Wtautological-constant-out-of-range-compare -O0 -fno-omit-frame-pointer -g2 -gsplit-dwarf -ggnu-pubnames -fvisibility=hidden -Wheader-hygiene -Wstring-conversion -Wtautological-overlap-compare -Wno-char-subscripts -Wexit-time-destructors -Wshadow -Wexit-time-destructors -Wno-undefined-bool-conversion -Wno-tautological-undefined-compare -std=gnu++14 -fno-exceptions -fno-rtti -nostdinc++ -isystem../../buildtools/third_party/libc++/trunk/include -isystem../../buildtools/third_party/libc++abi/trunk/include --sysroot=../../build/linux/debian_stretch_amd64-sysroot -fvisibility-inlines-hidden -c ../../base/trace_event/trace_log.cc -o obj/base/base/trace_log.o
../../base/trace_event/trace_log.cc:1545:29: error: comparison of constant 64 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
  DCHECK(handle.event_index < TraceBufferChunk::kTraceBufferChunkSize);
         ~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../base/logging.h:859:57: note: expanded from macro 'DCHECK'
  LAZY_STREAM(LOG_STREAM(DCHECK), !ANALYZER_ASSUME_TRUE(condition)) \
                                                        ^~~~~~~~~
../../base/logging.h:331:36: note: expanded from macro 'ANALYZER_ASSUME_TRUE'
#define ANALYZER_ASSUME_TRUE(arg) (arg)
                                   ^~~
../../base/logging.h:408:5: note: expanded from macro 'LAZY_STREAM'
  !(condition) ? (void) 0 : ::logging::LogMessageVoidify() & (stream)
    ^~~~~~~~~
1 error generated.



That doesn't sound right at all.
 

Comment 1 by h...@chromium.org, Dec 8 2017

Suspects:

------------------------------------------------------------------------
r320122 | rsmith | 2017-12-07 16:45:25 -0800 (Thu, 07 Dec 2017) | 6 lines

Unify implementation of our two different flavours of -Wtautological-compare.

In so doing, fix a handful of remaining bugs where we would report false
positives or false negatives if we promote a signed value to an unsigned type
for the comparison.

------------------------------------------------------------------------
r320124 | rsmith | 2017-12-07 17:00:27 -0800 (Thu, 07 Dec 2017) | 2 lines

Fold together the in-range and out-of-range portions of -Wtautological-compare.

------------------------------------------------------------------------

Comment 2 by h...@chromium.org, Dec 8 2017

Status: Fixed (was: Assigned)
It's the "fold together" one. Reverted in r320133.

Comment 3 by h...@chromium.org, Dec 8 2017

Status: Started (was: Fixed)
That didn't fix all of them, we're getting warnings from r320122 too, and this one is interesting.

../../chrome/browser/extensions/launch_util.cc:140:14: error: comparison of constant -1 with expression of type 'extensions::LaunchContainer' is always false [-Werror,-Wtautological-constant-out-of-range-compare]
  if (result == kInvalidLaunchContainer) {
      ~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.


I wonder how many more there are :-/

Comment 4 by h...@chromium.org, Dec 8 2017

Actually my revert didn't fix the trace_log.cc one either. That's what I get for sheriffing after-hours I guess.

Reverted r320122 in r320162.

I'll look at what other warnings we've got from this today.

Comment 5 by h...@chromium.org, Dec 8 2017

These five are all the warnings from a full Linux build:

[887/59786] CXX obj/base/base/trace_log.o
../../base/trace_event/trace_log.cc:1545:29: warning: comparison of constant 64 with expression of type 'unsigned int' is always true [-Wtautological-constant-out-of-range-compare]
  DCHECK(handle.event_index < TraceBufferChunk::kTraceBufferChunkSize);
         ~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


[18679/59786] CXX obj/skia/skia/GrSurfaceProxy.o
../../third_party/skia/src/gpu/GrSurfaceProxy.cpp:547:38: warning: comparison of constant -1 with expression of type 'GrSurfaceOrigin' is always true [-Wtautological-constant-out-of-range-compare]
    SkASSERT(kGrUnknownSurfaceOrigin != fProxy->origin());
             ~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~


[18775/59786] CXX obj/skia/skia/GrTextureDomain.o
../../third_party/skia/src/gpu/effects/GrTextureDomain.cpp:70:23: warning: comparison of constant -1 with expression of type 'GrTextureDomain::Mode' is always false [-Wtautological-constant-out-of-range-compare]
    SkASSERT((Mode)-1 == fMode || textureDomain.mode() == fMode);
             ~~~~~~~~ ^  ~~~~~


[36518/59786] CXX obj/chrome/browser/extensions/extensions/launch_util.o
../../chrome/browser/extensions/launch_util.cc:140:14: warning: comparison of constant -1 with expression of type 'extensions::LaunchContainer' is always false [-Wtautological-constant-out-of-range-compare]
  if (result == kInvalidLaunchContainer) {
      ~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~


[46485/59786] CXX obj/third_party/WebKit/Source/core/exported/exported/WebImageCache.o
../../third_party/WebKit/Source/platform/graphics/ImageDecodingStore.h:204:32: warning: comparison of constant -1 with expression of type 'const blink::ImageDecoder::AlphaOption' is always false [-Wtautological-constant-out-of-range-compare]
           value.alpha_option_ ==
           ~~~~~~~~~~~~~~~~~~~ ^



Project Member

Comment 7 by bugdroid1@chromium.org, Dec 9 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/d3f6afbde4432d42e80b5e7e2d3f26cd738e668a

commit d3f6afbde4432d42e80b5e7e2d3f26cd738e668a
Author: Hans Wennborg <hans@chromium.org>
Date: Sat Dec 09 00:16:37 2017

Fix tautological compare in launch_util.cc

-1 is not a valid value for the extensions::LaunchContainer enum. We can
use base::Optional instead.

Recent Clang versions were warning like this:

  ../../chrome/browser/extensions/launch_util.cc:140:14: warning: comparison of
  constant -1 with expression of type 'extensions::LaunchContainer' is always
  false [-Wtautological-constant-out-of-range-compare]
    if (result == kInvalidLaunchContainer) {
	~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~

Bug:  793189 
Change-Id: I82322dfe363606c37468856929420334a9cd1b3e
Reviewed-on: https://chromium-review.googlesource.com/817941
Reviewed-by: Dan Erat <derat@chromium.org>
Reviewed-by: Ken Rockot <rockot@chromium.org>
Commit-Queue: Hans Wennborg <hans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522931}
[modify] https://crrev.com/d3f6afbde4432d42e80b5e7e2d3f26cd738e668a/chrome/browser/extensions/launch_util.cc

Project Member

Comment 8 by bugdroid1@chromium.org, Dec 9 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1

commit 1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1
Author: Hans Wennborg <hans@chromium.org>
Date: Sat Dec 09 00:42:30 2017

Fix tautological compare in trace_log.cc

Recent Clang versions were warning:

  ../../base/trace_event/trace_log.cc:1545:29: warning: comparison of constant 64
  with expression of type 'unsigned int' is always true
  [-Wtautological-constant-out-of-range-compare]
    DCHECK(handle.event_index < TraceBufferChunk::kTraceBufferChunkSize
	   ~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Note that event_index is a 6-bit bitfield. This patch changes the comparison to

  handle.event_index <= TraceBufferChunk::kTraceBufferChunkSize -1

which brings the right-hand side value in range for the left-hand side type,
and also more naturally expresses the intent I think: checking that event_index
is less than or equal to the maximum allowed index, i.e. size minus one.

Bug:  793189 
Change-Id: I340f67f118b612e92ccfe6735161820d645c5a9a
Reviewed-on: https://chromium-review.googlesource.com/817900
Reviewed-by: Primiano Tucci <primiano@chromium.org>
Commit-Queue: Hans Wennborg <hans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522940}
[modify] https://crrev.com/1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1/base/trace_event/trace_log.cc

Project Member

Comment 9 by bugdroid1@chromium.org, Dec 9 2017

The following revision refers to this bug:
  https://skia.googlesource.com/skia/+/42b6cffaad4897d1d5a45bf9087a3b1a881591f4

commit 42b6cffaad4897d1d5a45bf9087a3b1a881591f4
Author: Hans Wennborg <hans@chromium.org>
Date: Sat Dec 09 01:31:48 2017

Fix tautological compare in GrSurfaceProxy.cpp

-1 is not a valid value for the GrSurfaceOrigin enum, and certain
versions of Clang warn that the comparison is effectively a no-op:

  ../../third_party/skia/src/gpu/GrSurfaceProxy.cpp:547:38: warning: comparison
  of constant -1 with expression of type 'GrSurfaceOrigin' is always true
  [-Wtautological-constant-out-of-range-compare]
      SkASSERT(kGrUnknownSurfaceOrigin != fProxy->origin());
	       ~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~

Instead of trying to force -1 in there, drop the assert and initialize with
top-left as origin.

Bug:  chromium:793189 
Change-Id: I4cb6720d567f6c5650a19df33d3c77f2d738a516
Reviewed-on: https://skia-review.googlesource.com/82961
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>

[modify] https://crrev.com/42b6cffaad4897d1d5a45bf9087a3b1a881591f4/src/gpu/GrSurfaceProxy.cpp
[modify] https://crrev.com/42b6cffaad4897d1d5a45bf9087a3b1a881591f4/include/private/GrTypesPriv.h

Project Member

Comment 10 by bugdroid1@chromium.org, Dec 9 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/8eb73cbebd6b83abbca4fc131413901ec8f8a1f5

commit 8eb73cbebd6b83abbca4fc131413901ec8f8a1f5
Author: Hans Wennborg <hans@chromium.org>
Date: Sat Dec 09 04:03:42 2017

Fix tautological compare warning in ImageDecodingStore.h

The ImageDecoder::AlphaOption enum cannot hold a value of -1, so recent
version of Clang warn:

  ../../third_party/WebKit/Source/platform/graphics/ImageDecodingStore.h:204:32:
warning: comparison of constant -1 with expression of type 'const
blink::ImageDecoder::AlphaOption' is always false
[-Wtautological-constant-out-of-range-compare]
	     value.alpha_option_ ==
	     ~~~~~~~~~~~~~~~~~~~ ^

The purpose of the comparison, and trying to set the value to -1 in the first
place, is to create tombstones in the hash table. I expect that setting the
SkISize to (-1,-1) is enough for that purpose, so just check against
that.

Bug:  793189 
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: I3cde8131c27de702f558d5f723355cc2cb18d865
Reviewed-on: https://chromium-review.googlesource.com/817938
Reviewed-by: Kenneth Russell <kbr@chromium.org>
Commit-Queue: Hans Wennborg <hans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522976}
[modify] https://crrev.com/8eb73cbebd6b83abbca4fc131413901ec8f8a1f5/third_party/WebKit/Source/platform/graphics/ImageDecodingStore.h

Project Member

Comment 11 by bugdroid1@chromium.org, Dec 9 2017

The following revision refers to this bug:
  https://skia.googlesource.com/skia/+/c63ec5ca64074dcc264a43bd1c1fdfb26e009410

commit c63ec5ca64074dcc264a43bd1c1fdfb26e009410
Author: Hans Wennborg <hans@chromium.org>
Date: Sat Dec 09 04:28:39 2017

Fix tautological comparison in GrTextureDomain.cpp

-1 is not a valid value for the GrTextureDomain::Mode enum, so certain
versions of Clang warn that the comparison is a no-op:

  ../../third_party/skia/src/gpu/effects/GrTextureDomain.cpp:70:23: warning:
  comparison of constant -1 with expression of type 'GrTextureDomain::Mode' is
  always false [-Wtautological-constant-out-of-range-compare]
      SkASSERT((Mode)-1 == fMode || textureDomain.mode() == fMode);
	       ~~~~~~~~ ^  ~~~~~

Bug:  chromium:793189 
Change-Id: Iba49ae15622285a62ad218dbdd78b0846338b7cb
Reviewed-on: https://skia-review.googlesource.com/82962
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>

[modify] https://crrev.com/c63ec5ca64074dcc264a43bd1c1fdfb26e009410/src/gpu/effects/GrTextureDomain.h
[modify] https://crrev.com/c63ec5ca64074dcc264a43bd1c1fdfb26e009410/src/gpu/effects/GrTextureDomain.cpp

Comment 12 by h...@chromium.org, Dec 12 2017

Status: Fixed (was: Started)

Sign in to add a comment