summaryrefslogtreecommitdiff
path: root/tests/diagnostics
diff options
context:
space:
mode:
Diffstat (limited to 'tests/diagnostics')
-rw-r--r--tests/diagnostics/float-literal.slang23
-rw-r--r--tests/diagnostics/float-literal.slang.expected9
-rw-r--r--tests/diagnostics/int-literal.slang32
-rw-r--r--tests/diagnostics/int-literal.slang.expected7
4 files changed, 71 insertions, 0 deletions
diff --git a/tests/diagnostics/float-literal.slang b/tests/diagnostics/float-literal.slang
new file mode 100644
index 000000000..46ce048b9
--- /dev/null
+++ b/tests/diagnostics/float-literal.slang
@@ -0,0 +1,23 @@
+//DIAGNOSTIC_TEST:SIMPLE:
+
+
+float doSomething(float a)
+{
+ // Too large with become +inf
+ a += 5e+40;
+ // Will be narrowed to 0
+ a += 9e-50;
+
+ double b = 0.0f;
+
+ // These shouldn't produce warning as they can fit
+ b += 5e+40l;
+ b += 9e-50l;
+
+ // Cos these don't have l suffix they should also produce warnings
+ // and produce -inf and 0
+ b += -5e+40;
+ b += -9e-50;
+
+ return a + float(b);
+}
diff --git a/tests/diagnostics/float-literal.slang.expected b/tests/diagnostics/float-literal.slang.expected
new file mode 100644
index 000000000..347317666
--- /dev/null
+++ b/tests/diagnostics/float-literal.slang.expected
@@ -0,0 +1,9 @@
+result code = 0
+standard error = {
+tests/diagnostics/float-literal.slang(7): warning 39999: float literal '5e+40' unrepresentable, converted to 'inf'
+tests/diagnostics/float-literal.slang(9): warning 39999: '9e-50' is smaller than the smallest representable value for type float, converted to '0'
+tests/diagnostics/float-literal.slang(19): warning 39999: float literal '5e+40' unrepresentable, converted to 'inf'
+tests/diagnostics/float-literal.slang(20): warning 39999: '9e-50' is smaller than the smallest representable value for type float, converted to '0'
+}
+standard output = {
+}
diff --git a/tests/diagnostics/int-literal.slang b/tests/diagnostics/int-literal.slang
new file mode 100644
index 000000000..3724d0e14
--- /dev/null
+++ b/tests/diagnostics/int-literal.slang
@@ -0,0 +1,32 @@
+//DIAGNOSTIC_TEST:SIMPLE:
+
+int doSomething(int a)
+{
+ // Warning can't fit
+ int c0 = 0x800000000;
+
+ // No warning as top bits are just ignored
+ int c1 = -1ll;
+
+ int c2 = int(-1u);
+
+ // 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;
+
+ //
+ a += c0 + c1 + c2;
+
+ int64_t b = 0;
+
+ // Ok
+ b += 0x800000000ll;
+
+ uint64_t c5 = -2ull;
+
+ return a + int(b);
+}
+
diff --git a/tests/diagnostics/int-literal.slang.expected b/tests/diagnostics/int-literal.slang.expected
new file mode 100644
index 000000000..ffc5ff6d2
--- /dev/null
+++ b/tests/diagnostics/int-literal.slang.expected
@@ -0,0 +1,7 @@
+result code = 0
+standard error = {
+tests/diagnostics/int-literal.slang(6): warning 39999: integer literal '0x800000000' too large for type 'int' truncated to '0'
+tests/diagnostics/int-literal.slang(18): warning 39999: integer literal '0xfffffffff' too large for type 'int' truncated to '-1'
+}
+standard output = {
+}