From 7866bae173953ecaf44a69eb71a0e2a34f079b4a Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Tue, 23 Jun 2015 21:23:29 +0000 Subject: [PATCH] * don't crash when trying to access the call_self_node in case it doesn't exit, but instead give an error (bug introduced in r30950, mantis #28338) git-svn-id: trunk@31150 - --- .gitattributes | 1 + compiler/ncal.pas | 20 ++++++++++++++++---- tests/webtbf/tw28338.pp | 17 +++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 tests/webtbf/tw28338.pp diff --git a/.gitattributes b/.gitattributes index 73ba5fa736..cff1a24600 100644 --- a/.gitattributes +++ b/.gitattributes @@ -13180,6 +13180,7 @@ tests/webtbf/tw2751.pp svneol=native#text/plain tests/webtbf/tw2752.pp svneol=native#text/plain tests/webtbf/tw2787.pp svneol=native#text/plain tests/webtbf/tw2795.pp svneol=native#text/plain +tests/webtbf/tw28338.pp svneol=native#text/plain tests/webtbf/tw2853.pp svneol=native#text/plain tests/webtbf/tw2853a.pp svneol=native#text/plain tests/webtbf/tw2853b.pp svneol=native#text/plain diff --git a/compiler/ncal.pas b/compiler/ncal.pas index 8a6372d918..089b9f9dd0 100644 --- a/compiler/ncal.pas +++ b/compiler/ncal.pas @@ -84,6 +84,7 @@ interface procedure register_created_object_types; function get_expect_loc: tcgloc; protected + function safe_call_self_node: tnode; procedure gen_vmt_entry_load; virtual; procedure gen_syscall_para(para: tcallparanode); virtual; procedure objc_convert_to_message_send;virtual; @@ -2102,7 +2103,7 @@ implementation { inherited } else if (cnf_inherited in callnodeflags) then begin - selftree:=call_self_node.getcopy; + selftree:=safe_call_self_node.getcopy; { we can call an inherited class static/method from a regular method -> self node must change from instance pointer to vmt pointer) } @@ -2158,7 +2159,7 @@ implementation end; end else - selftree:=call_self_node.getcopy + selftree:=safe_call_self_node.getcopy else selftree:=methodpointer.getcopy; end; @@ -2195,7 +2196,7 @@ implementation else begin if methodpointer.nodetype=typen then - selftree:=call_self_node.getcopy + selftree:=safe_call_self_node.getcopy else selftree:=methodpointer.getcopy; end; @@ -2333,6 +2334,17 @@ implementation end; + function tcallnode.safe_call_self_node: tnode; + begin + if not assigned(call_self_node) then + begin + CGMessage(parser_e_illegal_expression); + call_self_node:=cerrornode.create; + end; + result:=call_self_node; + end; + + procedure tcallnode.gen_vmt_entry_load; var vmt_def: trecorddef; @@ -2468,7 +2480,7 @@ implementation temp:=ctempcreatenode.create(objcsupertype,objcsupertype.size,tt_persistent,false); addstatement(statements,temp); { initialize objc_super record } - selftree:=call_self_node.getcopy; + selftree:=safe_call_self_node.getcopy; { we can call an inherited class static/method from a regular method -> self node must change from instance pointer to vmt pointer) diff --git a/tests/webtbf/tw28338.pp b/tests/webtbf/tw28338.pp new file mode 100644 index 0000000000..86bab12fa0 --- /dev/null +++ b/tests/webtbf/tw28338.pp @@ -0,0 +1,17 @@ +{ %fail } + +{$mode objfpc} + +program Project1; +type +tmyobj=object + a:integer; + function getsize:integer; + end; +function tmyobj.getsize:integer; +begin + result:=sizeof(self); +end; +begin + writeln(tmyobj.getsize); +end.