diff --git a/toolchain/lexer/BUILD b/toolchain/lexer/BUILD index 124ceba8b230..53643ded60d2 100644 --- a/toolchain/lexer/BUILD +++ b/toolchain/lexer/BUILD @@ -65,6 +65,7 @@ cc_test( deps = [ ":numeric_literal", ":test_helpers", + "//common:check", "//common:ostream", "//toolchain/diagnostics:diagnostic_emitter", "@com_google_googletest//:gtest_main", @@ -117,6 +118,7 @@ cc_test( deps = [ ":string_literal", ":test_helpers", + "//common:check", "//common:ostream", "//toolchain/diagnostics:diagnostic_emitter", "@com_google_googletest//:gtest_main", @@ -160,6 +162,7 @@ cc_library( hdrs = ["tokenized_buffer_test_helpers.h"], deps = [ ":tokenized_buffer", + "//common:check", "@com_google_googletest//:gtest", "@llvm-project//llvm:Support", ], diff --git a/toolchain/lexer/numeric_literal_test.cpp b/toolchain/lexer/numeric_literal_test.cpp index fcc63a357f1b..a247584ec9cc 100644 --- a/toolchain/lexer/numeric_literal_test.cpp +++ b/toolchain/lexer/numeric_literal_test.cpp @@ -11,6 +11,7 @@ #include #include +#include "common/check.h" #include "common/ostream.h" #include "toolchain/diagnostics/diagnostic_emitter.h" #include "toolchain/lexer/test_helpers.h" @@ -30,7 +31,7 @@ class NumericLiteralTest : public ::testing::Test { auto Lex(llvm::StringRef text) -> LexedNumericLiteral { llvm::Optional result = LexedNumericLiteral::Lex(text); - assert(result); + CHECK(result); EXPECT_EQ(result->Text(), text); return *result; } diff --git a/toolchain/lexer/string_literal_test.cpp b/toolchain/lexer/string_literal_test.cpp index 051dc5b001b6..644c14b3ada3 100644 --- a/toolchain/lexer/string_literal_test.cpp +++ b/toolchain/lexer/string_literal_test.cpp @@ -7,6 +7,7 @@ #include #include +#include "common/check.h" #include "common/ostream.h" #include "toolchain/diagnostics/diagnostic_emitter.h" #include "toolchain/lexer/test_helpers.h" @@ -20,7 +21,7 @@ class StringLiteralTest : public ::testing::Test { auto Lex(llvm::StringRef text) -> LexedStringLiteral { llvm::Optional result = LexedStringLiteral::Lex(text); - assert(result); + CHECK(result); EXPECT_EQ(result->Text(), text); return *result; } diff --git a/toolchain/lexer/tokenized_buffer.cpp b/toolchain/lexer/tokenized_buffer.cpp index 12d6f6f1731e..197410394673 100644 --- a/toolchain/lexer/tokenized_buffer.cpp +++ b/toolchain/lexer/tokenized_buffer.cpp @@ -169,7 +169,7 @@ class TokenizedBuffer::Lexer { default: // If we find a non-whitespace character without exhausting the // buffer, return true to continue lexing. - assert(!IsSpace(source_text.front())); + CHECK(!IsSpace(source_text.front())); if (whitespace_start != source_text.begin()) { NoteWhitespace(); } @@ -243,8 +243,8 @@ class TokenizedBuffer::Lexer { buffer_.literal_int_storage_.size(); buffer_.literal_int_storage_.push_back(std::move(value.mantissa)); buffer_.literal_int_storage_.push_back(std::move(value.exponent)); - assert(buffer_.GetRealLiteral(token).IsDecimal() == - (value.radix == 10)); + CHECK(buffer_.GetRealLiteral(token).IsDecimal() == + (value.radix == 10)); return token; }, [&](LexedNumericLiteral::UnrecoverableError) { @@ -876,9 +876,9 @@ auto TokenizedBuffer::TokenIterator::Print(llvm::raw_ostream& output) const auto TokenizedBuffer::SourceBufferLocationTranslator::GetLocation( const char* loc) -> Diagnostic::Location { - assert(llvm::is_sorted(std::array{buffer_->source_->Text().begin(), loc, - buffer_->source_->Text().end()}) && - "location not within buffer"); + CHECK(llvm::is_sorted(std::array{buffer_->source_->Text().begin(), loc, + buffer_->source_->Text().end()})) + << "location not within buffer"; int64_t offset = loc - buffer_->source_->Text().begin(); // Find the first line starting after the given location. Note that we can't diff --git a/toolchain/lexer/tokenized_buffer_test_helpers.h b/toolchain/lexer/tokenized_buffer_test_helpers.h index ec8cc2c6362b..d46beec3ad3f 100644 --- a/toolchain/lexer/tokenized_buffer_test_helpers.h +++ b/toolchain/lexer/tokenized_buffer_test_helpers.h @@ -7,6 +7,7 @@ #include +#include "common/check.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/Casting.h" #include "llvm/Support/YAMLParser.h" @@ -130,8 +131,8 @@ MATCHER_P(HasTokens, raw_all_expected, "") { matches = false; } - assert(!expected.string_contents || - expected.kind == TokenKind::StringLiteral()); + CHECK(!expected.string_contents || + expected.kind == TokenKind::StringLiteral()); if (expected.string_contents && actual_kind == TokenKind::StringLiteral()) { llvm::StringRef actual_contents = buffer.GetStringLiteral(token); if (actual_contents != *expected.string_contents) { diff --git a/toolchain/parser/parser_impl.cpp b/toolchain/parser/parser_impl.cpp index 84965f4ed90e..64ddfdbef449 100644 --- a/toolchain/parser/parser_impl.cpp +++ b/toolchain/parser/parser_impl.cpp @@ -1216,7 +1216,7 @@ auto ParseTree::Parser::ParseKeywordStatement(ParseNodeKind kind, -> llvm::Optional { RETURN_IF_STACK_LIMITED(llvm::None); auto keyword_kind = NextTokenKind(); - assert(keyword_kind.IsKeyword()); + CHECK(keyword_kind.IsKeyword()); auto start = GetSubtreeStartPosition(); auto keyword = Consume(keyword_kind);