Skip to content

Commit

Permalink
Address some -Wsign-compare warnings.
Browse files Browse the repository at this point in the history
Fixes #499.

Change-Id: I076d4fb4a51e0589176fdd175045ac90b0e361cb
Reviewed-on: https://code-review.googlesource.com/c/re2/ /63350
Reviewed-by: Paul Wankadia <[email protected]>
Reviewed-by: Alex Chernyakhovsky <[email protected]>
  • Loading branch information
junyer committed Jun 20, 2024
1 parent 4a8cee3 commit 67570de
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 135,7 @@ cc_library(
":re2",
"@abseil-cpp//absl/base",
"@abseil-cpp//absl/base:core_headers",
"@abseil-cpp//absl/container:flat_hash_set",
"@abseil-cpp//absl/flags:flag",
"@abseil-cpp//absl/log:absl_check",
"@abseil-cpp//absl/log:absl_log",
Expand Down
2 changes: 1 addition & 1 deletion re2/bitmap256.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 51,7 @@ class Bitmap256 {
private:
// Finds the least significant non-zero bit in n.
static int FindLSBSet(uint64_t n) {
ABSL_DCHECK_NE(n, 0);
ABSL_DCHECK_NE(n, uint64_t{0});
#if defined(__GNUC__)
return __builtin_ctzll(n);
#elif defined(_MSC_VER) && defined(_M_X64)
Expand Down
18 changes: 9 additions & 9 deletions re2/prog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,44 37,44 @@ namespace re2 {
// Constructors per Inst opcode

void Prog::Inst::InitAlt(uint32_t out, uint32_t out1) {
ABSL_DCHECK_EQ(out_opcode_, 0);
ABSL_DCHECK_EQ(out_opcode_, uint32_t{0});
set_out_opcode(out, kInstAlt);
out1_ = out1;
}

void Prog::Inst::InitByteRange(int lo, int hi, int foldcase, uint32_t out) {
ABSL_DCHECK_EQ(out_opcode_, 0);
ABSL_DCHECK_EQ(out_opcode_, uint32_t{0});
set_out_opcode(out, kInstByteRange);
lo_ = lo & 0xFF;
hi_ = hi & 0xFF;
hint_foldcase_ = foldcase&1;
}

void Prog::Inst::InitCapture(int cap, uint32_t out) {
ABSL_DCHECK_EQ(out_opcode_, 0);
ABSL_DCHECK_EQ(out_opcode_, uint32_t{0});
set_out_opcode(out, kInstCapture);
cap_ = cap;
}

void Prog::Inst::InitEmptyWidth(EmptyOp empty, uint32_t out) {
ABSL_DCHECK_EQ(out_opcode_, 0);
ABSL_DCHECK_EQ(out_opcode_, uint32_t{0});
set_out_opcode(out, kInstEmptyWidth);
empty_ = empty;
}

void Prog::Inst::InitMatch(int32_t id) {
ABSL_DCHECK_EQ(out_opcode_, 0);
ABSL_DCHECK_EQ(out_opcode_, uint32_t{0});
set_opcode(kInstMatch);
match_id_ = id;
}

void Prog::Inst::InitNop(uint32_t out) {
ABSL_DCHECK_EQ(out_opcode_, 0);
ABSL_DCHECK_EQ(out_opcode_, uint32_t{0});
set_opcode(kInstNop);
}

void Prog::Inst::InitFail() {
ABSL_DCHECK_EQ(out_opcode_, 0);
ABSL_DCHECK_EQ(out_opcode_, uint32_t{0});
set_opcode(kInstFail);
}

Expand Down Expand Up @@ -1113,7 1113,7 @@ const void* Prog::PrefixAccel_ShiftDFA(const void* data, size_t size) {
#if defined(__AVX2__)
// Finds the least significant non-zero bit in n.
static int FindLSBSet(uint32_t n) {
ABSL_DCHECK_NE(n, 0);
ABSL_DCHECK_NE(n, uint32_t{0});
#if defined(__GNUC__)
return __builtin_ctz(n);
#elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
Expand All @@ -1135,7 1135,7 @@ static int FindLSBSet(uint32_t n) {
#endif

const void* Prog::PrefixAccel_FrontAndBack(const void* data, size_t size) {
ABSL_DCHECK_GE(prefix_size_, 2);
ABSL_DCHECK_GE(prefix_size_, size_t{2});
if (size < prefix_size_)
return NULL;
// Don't bother searching the last prefix_size_-1 bytes for prefix_front_.
Expand Down
2 changes: 1 addition & 1 deletion re2/re2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 332,7 @@ int RE2::ReverseProgramSize() const {

// Finds the most significant non-zero bit in n.
static int FindMSBSet(uint32_t n) {
ABSL_DCHECK_NE(n, 0);
ABSL_DCHECK_NE(n, uint32_t{0});
#if defined(__GNUC__)
return 31 ^ __builtin_clz(n);
#elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
Expand Down
2 changes: 1 addition & 1 deletion re2/regexp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 498,7 @@ bool Regexp::Equal(Regexp* a, Regexp* b) {
if (n == 0)
break;

ABSL_DCHECK_GE(n, 2);
ABSL_DCHECK_GE(n, size_t{2});
a = stk[n-2];
b = stk[n-1];
stk.resize(n-2);
Expand Down

0 comments on commit 67570de

Please sign in to comment.