Skip to content

Commit

Permalink
Increase maximum object size to 2^31 bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
MikePopoloski committed Nov 20, 2023
1 parent a041e12 commit b813486
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion include/slang/ast/types/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ SLANG_BITMASK(IntegralFlags, Reg)
class SLANG_EXPORT Type : public Symbol {
public:
/// The maximum size in bits of any fixed size type.
static constexpr uint64_t MaxBitWidth = uint64_t(INT32_MAX);
static constexpr uint64_t MaxBitWidth = uint64_t(INT32_MAX) * 8;

/// Gets the canonical type for this type, which involves unwrapping any type aliases.
const Type& getCanonicalType() const {
Expand Down
2 changes: 1 addition & 1 deletion scripts/diagnostics.txt
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ error InvalidAssociativeIndexType "index type cannot be or contain floating poin
error PackedArrayNotIntegral "packed array elements must be of integral type (not {})"
error PackedTypeTooLarge "packed type of {} bits is too large; maximum width is {} bits"
error ArrayDimTooLarge "array dimension of {} is too large; maximum number of elements is {}"
error ObjectTooLarge "object size exceeds implementation limit of {} bits"
error ObjectTooLarge "object size exceeds implementation limit of 2^31 bytes"
error InvalidUnionMember "untagged unions cannot have members of type {}"
error VirtualInterfaceUnionMember "virtual interfaces cannot be used as members of unions"
error InvalidArrayElemType "cannot declare an array with elements of type {}"
Expand Down
3 changes: 1 addition & 2 deletions source/ast/Bitstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,7 @@ static bool unpackConcatenation(const StreamingConcatenationExpression& lhs, Pac

auto withSize = checkedMulU64(elemType->getBitstreamWidth(), with.width());
if (!withSize || withSize > Type::MaxBitWidth) {
context.addDiag(diag::ObjectTooLarge, stream.withExpr->sourceRange)
<< Type::MaxBitWidth;
context.addDiag(diag::ObjectTooLarge, stream.withExpr->sourceRange);
return false;
}

Expand Down
5 changes: 2 additions & 3 deletions source/ast/expressions/OperatorExpressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1800,8 +1800,7 @@ Expression& StreamingConcatenationExpression::fromSyntax(
auto rangeBits = checkedMulU64(argType->getArrayElementType()->getBitstreamWidth(),
*constantWithWidth);
if (!rangeBits || rangeBits > Type::MaxBitWidth) {
context.addDiag(diag::ObjectTooLarge, withExpr->sourceRange)
<< Type::MaxBitWidth;
context.addDiag(diag::ObjectTooLarge, withExpr->sourceRange);
return badResult();
}

Expand All @@ -1814,7 +1813,7 @@ Expression& StreamingConcatenationExpression::fromSyntax(

bitstreamWidth += argWidth;
if (bitstreamWidth > Type::MaxBitWidth) {
context.addDiag(diag::ObjectTooLarge, syntax.sourceRange()) << Type::MaxBitWidth;
context.addDiag(diag::ObjectTooLarge, syntax.sourceRange());
return badResult();
}

Expand Down
2 changes: 1 addition & 1 deletion source/ast/symbols/ClassSymbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ void ClassType::computeSize() const {

totalWidth += width;
if (totalWidth > MaxBitWidth) {
context.addDiag(diag::ObjectTooLarge, location) << MaxBitWidth;
context.addDiag(diag::ObjectTooLarge, location);
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/ast/types/AllTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ const Type& FixedSizeUnpackedArrayType::fromDim(const Scope& scope, const Type&

if (!selectableWidth || selectableWidth > MaxBitWidth || !bitstreamWidth ||
bitstreamWidth > MaxBitWidth) {
scope.addDiag(diag::ObjectTooLarge, sourceRange.get()) << MaxBitWidth;
scope.addDiag(diag::ObjectTooLarge, sourceRange.get());
return comp.getErrorType();
}

Expand Down Expand Up @@ -894,7 +894,7 @@ const Type& UnpackedStructType::fromSyntax(const ASTContext& context,
bitOffset += field->getType().getSelectableWidth();
bitstreamWidth += field->getType().getBitstreamWidth();
if (bitOffset > MaxBitWidth || bitstreamWidth > MaxBitWidth) {
context.addDiag(diag::ObjectTooLarge, syntax.sourceRange()) << MaxBitWidth;
context.addDiag(diag::ObjectTooLarge, syntax.sourceRange());
return comp.getErrorType();
}
}
Expand Down
16 changes: 8 additions & 8 deletions tests/unittests/ast/ExpressionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2976,19 +2976,19 @@ TEST_CASE("Stream operator size overflow") {
auto tree = SyntaxTree::fromText(R"(
module m;
int i[];
int j[9999999];
assign i = {<< {j, j, j with [0+:50000000]}};
int j[99999999];
assign i = {<< {j, j, j with [0+:400000000]}};
int k[$];
int l[];
always_comb l = {<< {k with [0+:999999999]}};
typedef struct { int i[50000000]; logic l[$]; } asdf;
typedef struct { int i[400000000]; logic l[$]; } asdf;
asdf n [999999][][999999][];
int o[];
always {<< {o}} = {<< {n}};
struct { asdf a[]; int i[50000000]; logic l; } p;
struct { asdf a[]; int i[400000000]; logic l; } p;
always {<< {p}} = {<< {o}};
class C;
Expand All @@ -2999,22 +2999,22 @@ module m;
class D;
int a[];
int b[50000000];
int b[400000000];
endclass
D d;
always {<< {o}} = {<< {d, d, d}};
endmodule
function automatic int func1;
typedef struct { int a[]; int i[50000000]; logic l; } asdf;
typedef struct { int a[]; int i[400000000]; logic l; } asdf;
struct { asdf a[]; bit b; asdf c; } p[];
int o[] = {1};
{<< {p}} = {<< {o}};
return 0;
endfunction
function automatic int func2;
typedef struct { int a[]; int i[50000000]; logic l; } asdf;
typedef struct { int a[]; int i[400000000]; logic l; } asdf;
struct { asdf a[]; bit b; asdf c; } p[];
int o[] = {1};
{<< {p}} = o;
Expand All @@ -3029,7 +3029,7 @@ endfunction
module n;
localparam int q = func1();
localparam int r = func2();
localparam int s = func3(1, 100000000);
localparam int s = func3(1, 1000000000);
endmodule
)");

Expand Down
6 changes: 3 additions & 3 deletions tests/unittests/ast/TypeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2011,9 +2011,9 @@ TEST_CASE("Max object size tests") {
auto tree = SyntaxTree::fromText(R"(
module m;
logic [7:0] foo;
logic bar[];
logic [7:0] bar[];
int baz[999999999];
struct { logic a[2147483647]; logic b[2147483647]; } biz;
struct { logic a[2147483647]; logic [7:0] b[2147483647]; } biz;
struct packed { logic [16777214:0] a; logic [16777214:0] b; } boz;
initial begin
Expand All @@ -2024,7 +2024,7 @@ endmodule
class C;
logic a[2147483647];
logic b[2147483647];
logic [7:0] b[2147483647];
endclass
class D;
Expand Down

0 comments on commit b813486

Please sign in to comment.