I started this PR hoping to complete it with the bug report, but it seems that slang first parses 16'sd32768, correctly assigning it a width of 17, and only then applies the unary minus, or at least that's what I think I figured out from the AST and printf-style debug code:
module t;
int t = -1;
wire [15:0]x = -16'sd32768;
endmodule
The code above only triggered the "pos" code path.
When is the "neg" code path ever used?
My best guess so far is a fix around here in OperatorExpressions.cpp:
case SyntaxKind::UnaryMinusExpression:
// Supported for both integral and real types. Result is same as input type.
good = type->isNumeric();
result->type = type;
break;
Probably need to check the type and if it is constant integral type reduce its width by 1 if it is -2^N.
I started this PR hoping to complete it with the bug report, but it seems that slang first parses 16'sd32768, correctly assigning it a width of 17, and only then applies the unary minus, or at least that's what I think I figured out from the AST and printf-style debug code:
I put this in SVint.h:171 onwards:
And ran the following code:
The code above only triggered the "pos" code path. When is the "neg" code path ever used?
My best guess so far is a fix around here in OperatorExpressions.cpp:
Probably need to check the type and if it is constant integral type reduce its width by 1 if it is -2^N.