diff --git a/gcc/testsuite/gnat.dg/opt64.adb b/gcc/testsuite/gnat.dg/opt64.adb
new file mode 100644
index 0000000..6d287d3
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/opt64.adb
@@ -0,0 +1,25 @@
+-- { dg-do run }
+-- { dg-options "-O2" }
+
+-- The issue which prompted the test is a compilation failure. Might
+-- as well verify that the generated code performs as expected.
+
+with opt64_pkg; use opt64_pkg;
+
+procedure opt64 is
+  procedure assert (T : boolean) is
+  begin
+    if not T then
+      raise program_error;
+    end if;
+  end;
+begin
+  Encode (1);
+  assert (last_hash = "1");
+  Encode (2);
+  assert (last_hash = "2");
+  Encode (3);
+  assert (last_hash = "3");
+  Encode (6);
+  assert (last_hash = "?");
+end;
diff --git a/gcc/testsuite/gnat.dg/opt64_pkg.adb b/gcc/testsuite/gnat.dg/opt64_pkg.adb
new file mode 100644
index 0000000..5235e73
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/opt64_pkg.adb
@@ -0,0 +1,14 @@
+package body Opt64_PKG is
+   
+   procedure Encode (X : Integer) is
+      result : Hash;
+   begin
+      case X is
+         when 1 => result := "1";
+         when 2 => result := "2";
+         when 3 => result := "3";
+         when others => Result := "?";
+      end case;     
+      Last_Hash := Result;
+   end;
+end;
diff --git a/gcc/testsuite/gnat.dg/opt64_pkg.ads b/gcc/testsuite/gnat.dg/opt64_pkg.ads
new file mode 100644
index 0000000..e4b09fc
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/opt64_pkg.ads
@@ -0,0 +1,6 @@
+package Opt64_PKG is
+   type Hash is new string (1 .. 1);   
+   Last_Hash : Hash;
+     
+   procedure Encode (X : Integer);
+end;
