summaryrefslogtreecommitdiff
path: root/tests/diagnostics
diff options
context:
space:
mode:
Diffstat (limited to 'tests/diagnostics')
-rw-r--r--tests/diagnostics/int-literal.slang25
-rw-r--r--tests/diagnostics/int-literal.slang.expected15
2 files changed, 27 insertions, 13 deletions
diff --git a/tests/diagnostics/int-literal.slang b/tests/diagnostics/int-literal.slang
index 3724d0e14..920fb58eb 100644
--- a/tests/diagnostics/int-literal.slang
+++ b/tests/diagnostics/int-literal.slang
@@ -2,8 +2,8 @@
int doSomething(int a)
{
- // Warning can't fit
- int c0 = 0x800000000;
+ // No warning, literal will be interpreted as 64 bit.
+ uint64_t c0 = 0x800000000;
// No warning as top bits are just ignored
int c1 = -1ll;
@@ -13,12 +13,10 @@ int doSomething(int a)
// Should sign extend
int c3 = 0x80000000;
- // Should give a warning (ideally including the preceeding -)
- // Currently we don't have the -, because the lexer lexes - independently
- int c4 = -0xfffffffff;
+ // No warning, hex literal will be interpreted as an unsigned 64 integer then signed with negative operator.
+ int64_t c4 = -0xfffffffff;
- //
- a += c0 + c1 + c2;
+ a += (int)c0 + c1 + c2;
int64_t b = 0;
@@ -26,6 +24,19 @@ int doSomething(int a)
b += 0x800000000ll;
uint64_t c5 = -2ull;
+
+ // Warning, integer literal is too large for signed 64 bit, must be interpreted as unsigned.
+ uint64_t d0 = 18446744073709551615;
+
+ // Warning, integer literal is too small for signed 64 bit, must be interpreted as unsigned.
+ uint64_t d1 = -9223372036854775809;
+
+ // This is INT64_MIN and valid negative signed integer, but warning will be emitted as negative(-) is scanned
+ // separately in the lexer, and the positive literal portion will emit a warning.
+ // The final value will still be correctly set as INT64_MIN.
+ //
+ // To not have this warning the lexer must scan the negative operator and number together.
+ uint64_t d2 = -9223372036854775808;
return a + int(b);
}
diff --git a/tests/diagnostics/int-literal.slang.expected b/tests/diagnostics/int-literal.slang.expected
index 01e7785f6..39ab66d1d 100644
--- a/tests/diagnostics/int-literal.slang.expected
+++ b/tests/diagnostics/int-literal.slang.expected
@@ -1,11 +1,14 @@
result code = 0
standard error = {
-tests/diagnostics/int-literal.slang(6): warning 39999: integer literal '0x800000000' too large for type 'int' truncated to '0'
- int c0 = 0x800000000;
- ^~~~~~~~~~~
-tests/diagnostics/int-literal.slang(18): warning 39999: integer literal '0xfffffffff' too large for type 'int' truncated to '-1'
- int c4 = -0xfffffffff;
- ^~~~~~~~~~~
+tests/diagnostics/int-literal.slang(29): warning 39999: integer literal is too large to be represented in a signed integer type, interpreting as unsigned
+ uint64_t d0 = 18446744073709551615;
+ ^~~~~~~~~~~~~~~~~~~~
+tests/diagnostics/int-literal.slang(32): warning 39999: integer literal is too large to be represented in a signed integer type, interpreting as unsigned
+ uint64_t d1 = -9223372036854775809;
+ ^~~~~~~~~~~~~~~~~~~
+tests/diagnostics/int-literal.slang(39): warning 39999: integer literal is too large to be represented in a signed integer type, interpreting as unsigned
+ uint64_t d2 = -9223372036854775808;
+ ^~~~~~~~~~~~~~~~~~~
}
standard output = {
}