From 8122defbd85bee5b9ca4a2561f5ca189d40acbcb Mon Sep 17 00:00:00 2001 From: Pierre Muller Date: Wed, 29 Nov 2023 23:14:18 +0000 Subject: [PATCH] Add test for bug report 40537 --- tests/webtbs/tw40537.pp | 62 ++++++++++++++++++++++++++++++++++++++++ tests/webtbs/tw40537a.pp | 3 ++ tests/webtbs/tw40537b.pp | 3 ++ 3 files changed, 68 insertions(+) create mode 100644 tests/webtbs/tw40537.pp create mode 100644 tests/webtbs/tw40537a.pp create mode 100644 tests/webtbs/tw40537b.pp diff --git a/tests/webtbs/tw40537.pp b/tests/webtbs/tw40537.pp new file mode 100644 index 0000000000..2b70a01954 --- /dev/null +++ b/tests/webtbs/tw40537.pp @@ -0,0 +1,62 @@ +type +{$ifdef USE_RECORD} + trec = record + y : longint; + end; +{$else} +{$ifdef USE_PTRINT} + trec = ptrint; +{$else USE_PTRINT} + trec = pointer; +{$endif USE_PTRINT} +{$endif} + prec = ^trec; + +const + value_version_used : longint = 0; + var_version_used : longint = 0; + has_error : boolean = false; + +function test(p : prec;l : longint; k: dword) : boolean; overload; +begin + test:=(p<>nil); + inc(value_version_used); +end; + +function test(var p : trec;l : longint; k: dword) : boolean; overload; +begin + test:=(@p<>nil); + inc(var_version_used); +end; + +var + pt : trec; + i : trec; + +begin + pt:=i; + test(@pt,23,56); + if (var_version_used>0) then + begin + writeln('call with @pt uses var version, which is wrong'); + has_error:=true; + end + else + writeln('call with @pt uses value version'); + + var_version_used:=0; + value_version_used:=0; + + test(pt,678,567890); + if (var_version_used>0) then + writeln('direct call uses var version') + else + writeln('direct call uses value version'); + + if has_error then + begin + writeln('This test revealed a problem'); + halt(1); + end; +end. + diff --git a/tests/webtbs/tw40537a.pp b/tests/webtbs/tw40537a.pp new file mode 100644 index 0000000000..55a3988491 --- /dev/null +++ b/tests/webtbs/tw40537a.pp @@ -0,0 +1,3 @@ +{$define USE_RECORD} +{$i tw40537.pp} + diff --git a/tests/webtbs/tw40537b.pp b/tests/webtbs/tw40537b.pp new file mode 100644 index 0000000000..c5880af8c8 --- /dev/null +++ b/tests/webtbs/tw40537b.pp @@ -0,0 +1,3 @@ +{$define USE_PTRINT} +{$i tw40537.pp} +