Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does this code fail to build because of a compiler bug?

Tags:

delphi

Building, not just compiling, the following fails with an internal compiler error when using Delphi 6 if optimization is on. Using the assignment instead of the inc() works. Is this a compiler bug? The weird record structures are because the original code has been reduced to this minimal example.

program Project1;

type
  requestCountsType = array[0..1] of
    record
    processed: int64;
    end;

  talliestype = record
    counts: requestCountsType;
    end;

  healthtype = record
    charged: talliestype;
    end;

procedure computeProcessed(const h: healthtype; var requests, bytesin, bytesout: int64);
var i: byte;
begin
requests := 0; bytesin := 0; bytesout := 0;
for i := 0 to 1 do
  begin
  inc(requests, h.charged.counts[i].processed); // including this generates compiler internal error C1405 when optimization is on
  // requests := requests + h.charged.counts[i].processed; // this works
  end;
end;

var ht: healthtype; var r, b1, b2: int64;

begin
computeProcessed(ht, r, b1, b2);
end.
like image 964
Witness Protection ID 44583292 Avatar asked Sep 05 '14 01:09

Witness Protection ID 44583292


People also ask

What causes the compiler to fail?

The most common cause of compilation errors is a syntax error. Syntax errors are errors in the form of the raw source code, usually caused by some violation of the computer language's principles.

What happens when a compiler finds an error?

Errors in the program should be detected and reported by the parser. Whenever an error occurs, the parser can handle it and continue to parse the rest of the input. Although the parser is mostly responsible for checking for errors, errors may occur at various stages of the compilation process.

What errors can be detected by compiler?

All syntax errors and some of the semantic errors (the static semantic errors) are detected by the compiler, which generates a message indicating the type of error and the position in the Java source file where the error occurred (notice that the actual error could have occurred before the position signaled by the ...


1 Answers

See bug report #109124. I can confirm the problem in Delphi XE; the bug report says it was fixed in Delphi XE4.

like image 76
kludg Avatar answered Oct 14 '22 15:10

kludg