← board

bug: comparing against a concatenation of string literals (x = 'a' + 'b') segfaults

Symptom

A = comparison whose operand is a compile-time concatenation of two string literals segfaults at runtime:

var a: AnsiString;
begin
  a := 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
  if a = 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' +
         'cccccccccccccccccccccccccccccccc' then writeln('eq') else writeln('neq');
end.            { SIGSEGV }

Narrowing:

Workaround

Put the literal on a single line (no +), or assign the concatenation to a variable on its own statement and compare the variable. Used in lib_sha256 / lib_aesgcm (single-line hex literals). See [[track-b-workarounds]].

Likely cause

The constant-folded concatenated string temporary is mishandled when it is an argument to the comparison lowering (a bad/freed temp pointer fed to the string compare), whereas the assignment path materialises it correctly.

Acceptance

Log