comp.lang.ada
 help / color / mirror / Atom feed
* BUG in Ada compiler?
@ 1988-11-11  2:48 Bob Argyle
  1988-11-14 13:07 ` Robert Firth
  1988-11-19 17:14 ` Jim Near
  0 siblings, 2 replies; 3+ messages in thread
From: Bob Argyle @ 1988-11-11  2:48 UTC (permalink / raw)



greetings Ada wizards, 

The following program on a VAX 8700 prints out:
"Hello, your program is exceptional!"
but if I change either 32767 to 32768, it runs fine: "Hello, World"
Two questions: 1. Am I overlooking something very basic?  Or, 
2.  Is the compiler here broken? Is _yours_?

with text_io; use text_io;
procedure bug is
   m:array (0..32767,0..32767) of character;
   begin
      m(0,8) := 'c';
      put("Hello, ");
      m(1,8) := 'c';
      put_line("World");
   exception
      when numeric_error | constraint_error => 
         put_line("numeric_error | constraint_error"); 
         -- must have same handler or compiler complains.
      when program_error => put_line("program_error");
      when storage_error => put_line("storage_error");
      when tasking_error => put_line("tasking_error");
      when data_error	 => put_line("data_error");
      when status_error	 => put_line("status_error");
      when mode_error	 => put_line("mode_error");
      when name_error	 => put_line("name_error");
      when use_error	 => put_line("use_error");
      when device_error	 => put_line("device_error");
      when end_error	 => put_line("end_error");
      when layout_error	 => put_line("layout_error");
      when others 	 => put_line("your program is exceptional!");
      -- no known named exception raised
   end bug;

-- 
bob argyle @ wsccs      void where prohibited.  int where not declared.
#ifndef disclaimer
	/*
#endif

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: BUG in Ada compiler?
  1988-11-11  2:48 BUG in Ada compiler? Bob Argyle
@ 1988-11-14 13:07 ` Robert Firth
  1988-11-19 17:14 ` Jim Near
  1 sibling, 0 replies; 3+ messages in thread
From: Robert Firth @ 1988-11-14 13:07 UTC (permalink / raw)


In article <781@wsccs.UUCP> rargyle@wsccs.UUCP (Bob Argyle) writes:

>The following program on a VAX 8700 prints out:
>"Hello, your program is exceptional!"
>but if I change either 32767 to 32768, it runs fine: "Hello, World"
>Two questions: 1. Am I overlooking something very basic?  Or, 
>2.  Is the compiler here broken? Is _yours_?
>
>with text_io; use text_io;
>procedure bug is
>   m:array (0..32767,0..32767) of character;
>   begin
>      m(0,8) := 'c';
>      put("Hello, ");
>      m(1,8) := 'c';

[at which point the exception occurs]

The program is legal (though certainly exceptional), and so one suspects
that the compiler has a bug here.

Wild conjecture: as shown, the array M has an index type that is
implicitly WORD, ie 16 bits.  The compiler expands the two-dimensional
array index expression by the multiplicative method into

	(mbase + index1 * stride + index2)

Because the indices are considered to be of type word, the compiler
resolves the "*" and "+" operations to be also of type word, ie 16
bits.  This works by sheer chance for the first expression, which stays
within 16-bit range, but blows up on the second expression.

If the upper bounds are changed to 32768 the index type becomes
implicitly longword, which works.

Source of problem: the premature expansion of the array index expression
before overload resolution, followed by application of Ada's resolution
rules to an expression that isn't in Ada and shouldn't follow those rules.

Hope that helps - remember: a wild conjecture, no more.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: BUG in Ada compiler?
  1988-11-11  2:48 BUG in Ada compiler? Bob Argyle
  1988-11-14 13:07 ` Robert Firth
@ 1988-11-19 17:14 ` Jim Near
  1 sibling, 0 replies; 3+ messages in thread
From: Jim Near @ 1988-11-19 17:14 UTC (permalink / raw)


/ hpclove:comp.lang.ada / rargyle@wsccs.UUCP (Bob Argyle) /  6:48 pm  Nov 10, 1988 /

greetings Ada wizards, 

The following program on a VAX 8700 prints out:
"Hello, your program is exceptional!"
but if I change either 32767 to 32768, it runs fine: "Hello, World"
Two questions: 1. Am I overlooking something very basic?  Or, 
2.  Is the compiler here broken? Is _yours_?

with text_io; use text_io;
procedure bug is
   m:array (0..32767,0..32767) of character;
   begin
      m(0,8) := 'c';
      put("Hello, ");
      m(1,8) := 'c';
      put_line("World");
   exception
      when numeric_error | constraint_error => 
         put_line("numeric_error | constraint_error"); 
         -- must have same handler or compiler complains.
      when program_error => put_line("program_error");
      when storage_error => put_line("storage_error");
      when tasking_error => put_line("tasking_error");
      when data_error	 => put_line("data_error");
      when status_error	 => put_line("status_error");
      when mode_error	 => put_line("mode_error");
      when name_error	 => put_line("name_error");
      when use_error	 => put_line("use_error");
      when device_error	 => put_line("device_error");
      when end_error	 => put_line("end_error");
      when layout_error	 => put_line("layout_error");
      when others 	 => put_line("your program is exceptional!");
      -- no known named exception raised
   end bug;

-- 
bob argyle @ wsccs      void where prohibited.  int where not declared.
#ifndef disclaimer
	/*
#endif
----------

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1988-11-19 17:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1988-11-11  2:48 BUG in Ada compiler? Bob Argyle
1988-11-14 13:07 ` Robert Firth
1988-11-19 17:14 ` Jim Near

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox