[Piglit] [PATCH] Add more int literal size limit tests.

Eric Anholt eric at anholt.net
Mon Oct 24 13:41:51 PDT 2011


This is based on my interpretation of the spec, and matches up with a
Khronos spec clarification.
---
 .../basic-types/int-literal-size-ok-01.frag        |   23 +++++++++++++++++++
 .../basic-types/int-literal-size-ok-02.frag        |   23 +++++++++++++++++++
 .../basic-types/int-literal-size-ok-03.frag        |   23 +++++++++++++++++++
 .../basic-types/int-literal-size-ok-04.frag        |   24 ++++++++++++++++++++
 .../basic-types/int-literal-too-large-03.frag      |   21 +++++++++++++++++
 5 files changed, 114 insertions(+), 0 deletions(-)
 create mode 100644 tests/spec/glsl-1.30/compiler/basic-types/int-literal-size-ok-01.frag
 create mode 100644 tests/spec/glsl-1.30/compiler/basic-types/int-literal-size-ok-02.frag
 create mode 100644 tests/spec/glsl-1.30/compiler/basic-types/int-literal-size-ok-03.frag
 create mode 100644 tests/spec/glsl-1.30/compiler/basic-types/int-literal-size-ok-04.frag
 create mode 100644 tests/spec/glsl-1.30/compiler/basic-types/int-literal-too-large-03.frag

diff --git a/tests/spec/glsl-1.30/compiler/basic-types/int-literal-size-ok-01.frag b/tests/spec/glsl-1.30/compiler/basic-types/int-literal-size-ok-01.frag
new file mode 100644
index 0000000..0703c70
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/basic-types/int-literal-size-ok-01.frag
@@ -0,0 +1,23 @@
+// [config]
+// expect_result: pass
+// glsl_version: 1.30
+// [end config]
+//
+// Integer literals that are too large should raise an error.
+//
+// From page 22 (28 of PDF) of GLSL 1.30 spec:
+//     It is an error to provide a literal integer whose magnitude is too
+//     large to store in a variable of matching signed or unsigned type.
+//
+//     Unsigned integers have exactly 32 bits of precision.  Signed integers
+//     use 32 bits, including a sign bit, in two's complement form.
+//
+// However, a 32-bit integer literal (whether it has a 'u' suffix or not)
+// is valid.
+
+#version 130
+
+int f() {
+	// Requires 32 bits.
+	return int(0xffffffff);
+}
diff --git a/tests/spec/glsl-1.30/compiler/basic-types/int-literal-size-ok-02.frag b/tests/spec/glsl-1.30/compiler/basic-types/int-literal-size-ok-02.frag
new file mode 100644
index 0000000..5ebe37b
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/basic-types/int-literal-size-ok-02.frag
@@ -0,0 +1,23 @@
+// [config]
+// expect_result: pass
+// glsl_version: 1.30
+// [end config]
+//
+// Integer literals that are too large should raise an error.
+//
+// From page 22 (28 of PDF) of GLSL 1.30 spec:
+//     It is an error to provide a literal integer whose magnitude is too
+//     large to store in a variable of matching signed or unsigned type.
+//
+//     Unsigned integers have exactly 32 bits of precision.  Signed integers
+//     use 32 bits, including a sign bit, in two's complement form.
+//
+// However, a 32-bit integer literal (whether it has a 'u' suffix or not)
+// is valid.
+
+#version 130
+
+uint f() {
+	// Requires 32 bits.
+	return uint(0xffffffff);
+}
diff --git a/tests/spec/glsl-1.30/compiler/basic-types/int-literal-size-ok-03.frag b/tests/spec/glsl-1.30/compiler/basic-types/int-literal-size-ok-03.frag
new file mode 100644
index 0000000..c5ab82f
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/basic-types/int-literal-size-ok-03.frag
@@ -0,0 +1,23 @@
+// [config]
+// expect_result: pass
+// glsl_version: 1.30
+// [end config]
+//
+// Integer literals that are too large should raise an error.
+//
+// From page 22 (28 of PDF) of GLSL 1.30 spec:
+//     It is an error to provide a literal integer whose magnitude is too
+//     large to store in a variable of matching signed or unsigned type.
+//
+//     Unsigned integers have exactly 32 bits of precision.  Signed integers
+//     use 32 bits, including a sign bit, in two's complement form.
+//
+// However, a 32-bit integer literal (whether it has a 'u' suffix or not)
+// is valid.
+
+#version 130
+
+int f() {
+	// Requires 32 bits.
+	return 3000000000;
+}
diff --git a/tests/spec/glsl-1.30/compiler/basic-types/int-literal-size-ok-04.frag b/tests/spec/glsl-1.30/compiler/basic-types/int-literal-size-ok-04.frag
new file mode 100644
index 0000000..a1208db
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/basic-types/int-literal-size-ok-04.frag
@@ -0,0 +1,24 @@
+// [config]
+// expect_result: pass
+// glsl_version: 1.30
+// [end config]
+//
+// Integer literals that are too large should raise an error.
+//
+// From page 22 (28 of PDF) of GLSL 1.30 spec:
+//     It is an error to provide a literal integer whose magnitude is too
+//     large to store in a variable of matching signed or unsigned type.
+//
+//     Unsigned integers have exactly 32 bits of precision.  Signed integers
+//     use 32 bits, including a sign bit, in two's complement form.
+//
+// However, a 32-bit integer literal (whether it has a 'u' suffix or not)
+// is valid.  Warnings generation for large signed decimals has to be careful,
+// because -2147483648 is parsed as -(2147483648).
+
+#version 130
+
+int f() {
+	// Requires 32 bits.
+	return -2147483648;
+}
diff --git a/tests/spec/glsl-1.30/compiler/basic-types/int-literal-too-large-03.frag b/tests/spec/glsl-1.30/compiler/basic-types/int-literal-too-large-03.frag
new file mode 100644
index 0000000..5381205
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/basic-types/int-literal-too-large-03.frag
@@ -0,0 +1,21 @@
+// [config]
+// expect_result: fail
+// glsl_version: 1.30
+// [end config]
+//
+// Integer literals that are too large should raise an error.
+//
+// From page 22 (28 of PDF) of GLSL 1.30 spec:
+//     It is an error to provide a literal integer whose magnitude is too
+//     large to store in a variable of matching signed or unsigned type.
+//
+//     Unsigned integers have exactly 32 bits of precision.  Signed integers
+//     use 32 bits, including a sign bit, in two's complement form.
+
+
+#version 130
+
+int f() {
+	// Requires 33 bits.
+	return 5000000000;
+}
-- 
1.7.7



More information about the Piglit mailing list