Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Commit

Permalink
Fix 0xFFFFFFFF enum value crash.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 457749966
  • Loading branch information
Sean Purser-Haskell authored and copybara-github committed Jun 28, 2022
1 parent eeacef1 commit c9aa259
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions xls/contrib/xlscc/translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1687,9 +1687,9 @@ absl::StatusOr<CValue> Translator::GetIdentifier(const clang::NamedDecl* decl,
if (enum_decl != nullptr) {
const llvm::APSInt& aps = enum_decl->getInitVal();

std::shared_ptr<CType> type(std::make_shared<CIntType>(32, true));
std::shared_ptr<CType> type(std::make_shared<CIntType>(32, false));
xls::BValue bval =
context().fb->Literal(xls::SBits(aps.getExtValue(), 32), global_loc);
context().fb->Literal(xls::UBits(aps.getExtValue(), 32), global_loc);

value = CValue(bval, type);
} else {
Expand Down
17 changes: 14 additions & 3 deletions xls/contrib/xlscc/translator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,18 @@ TEST_F(TranslatorTest, GlobalEnum) {
Run({{"a", 11}}, 11 + 3 + 3, content);
}

TEST_F(TranslatorTest, MaximumEnum) {
const std::string content = R"(
enum BlahE {
A=2,
B=0xFFFFFFFF
};
long long my_package(long long a) {
return a+B+B;
})";
Run({{"a", 11}}, 11L + 0xFFFFFFFFL + 0xFFFFFFFFL, content);
}

TEST_F(TranslatorTest, SetGlobal) {
const std::string content = R"(
int off = 60;
Expand Down Expand Up @@ -1777,8 +1789,6 @@ TEST_F(TranslatorTest, CapitalizeFirstLetter) {
ParsePackage(ir_src));
XLS_ASSERT_OK(package->SetTopByName("my_package"));

// std::vector<xls::Value> st_elem;
// st_elem.push_back(xls::Value(xls::UBits(1, 1)));
auto state =
xls::Value(xls::Value::TupleOwned({xls::Value(xls::UBits(1, 1))}));

Expand Down Expand Up @@ -3029,7 +3039,8 @@ TEST_F(TranslatorTest, IOSubroutineDeclMissing) {
})";

ASSERT_THAT(SourceToIr(content, /*func=*/nullptr, /* clang_argv= */ {},
/* io_test_mode= */ true).status(),
/* io_test_mode= */ true)
.status(),
xls::status_testing::StatusIs(
absl::StatusCode::kNotFound,
testing::HasSubstr("sub_recv used but has no body")));
Expand Down

0 comments on commit c9aa259

Please sign in to comment.