"inline" function specifier causes reference counting errors
Original Reporter info from Mantis: ahydra
-
Reporter name: Colin Haywood
Original Reporter info from Mantis: ahydra
- Reporter name: Colin Haywood
Description:
See attached program. The use of "inline" in a function that has an otherwise-useless temporary variable seems to cause the compiler to mess up the code for handling the temporary variable.
When run, the output of the program should be
Reference count of a is 2
Reference count of b is 2
since both these variables have two references at the point we do the writeln(): one inside m.FMap, and the other of course the variable (a or b) itself.
But instead it prints
Reference count of a is 3
Reference count of b is 2
The only difference between what happens to "a" and what happens to "b" is the use of inline: a gets passed out to InlineGet, but b gets passed out to Get. Looking at the assembler, the compiler generates a "finalize" call for both but puts the one for "a" BEFORE the call to I_ActualGet rather than after (where it should be).
(Note that although this program is rather useless, this is adapted from a real-world example in which there are two variants of Get(): one which takes an out parameter, and one which does not. The Get without the out parameter calls the Get with the out parameter, passing a useless temporary variable.)
Steps to reproduce:
Compile attached program for 32-bit OS.
Mantis conversion info:
- Mantis ID: 27049
- OS: Windows
- OS Build: 7
- Platform: x86
- Version: 2.6.4