Răsfoiți Sursa

* convert function like used new into a appropriate nodes only in pass_1 so proper error checking can be carried out, resolves #24495

git-svn-id: trunk@24667 -
florian 12 ani în urmă
părinte
comite
0968d095ed
4 a modificat fișierele cu 54 adăugiri și 34 ștergeri
  1. 1 0
      .gitattributes
  2. 41 2
      compiler/ninl.pas
  3. 3 32
      compiler/pinline.pas
  4. 9 0
      tests/webtbf/tw24495.pp

+ 1 - 0
.gitattributes

@@ -12333,6 +12333,7 @@ tests/webtbf/tw2414.pp svneol=native#text/plain
 tests/webtbf/tw24184.pp svneol=native#text/plain
 tests/webtbf/tw24428.pp svneol=native#text/plain
 tests/webtbf/tw24428a.pp svneol=native#text/plain
+tests/webtbf/tw24495.pp svneol=native#text/pascal
 tests/webtbf/tw2478.pp svneol=native#text/plain
 tests/webtbf/tw2562.pp svneol=native#text/plain
 tests/webtbf/tw2657.pp svneol=native#text/plain

+ 41 - 2
compiler/ninl.pas

@@ -2988,6 +2988,9 @@ implementation
                       tcallparanode(tcallparanode(left).right).left.resultdef.typename);
                 end;
 
+              in_new_x:
+                resultdef:=left.resultdef;
+
               in_low_x,
               in_high_x:
                 begin
@@ -3931,12 +3934,48 @@ implementation
         left:=nil;
      end;
 
+
      function tinlinenode.first_new: tnode;
+       var
+         newstatement : tstatementnode;
+         newblock     : tblocknode;
+         temp         : ttempcreatenode;
+         para         : tcallparanode;
        begin
-         internalerror(2011012201);
-         result:=nil;
+         { create statements with call to getmem+initialize }
+         newblock:=internalstatements(newstatement);
+
+         { create temp for result }
+         temp := ctempcreatenode.create(left.resultdef,left.resultdef.size,tt_persistent,true);
+         addstatement(newstatement,temp);
+
+         { create call to fpc_getmem }
+         para := ccallparanode.create(cordconstnode.create
+             (tpointerdef(left.resultdef).pointeddef.size,s32inttype,true),nil);
+         addstatement(newstatement,cassignmentnode.create(
+             ctemprefnode.create(temp),
+             ccallnode.createintern('fpc_getmem',para)));
+
+         { create call to fpc_initialize }
+         if is_managed_type(tpointerdef(left.resultdef).pointeddef) then
+          begin
+            para := ccallparanode.create(caddrnode.create_internal(crttinode.create
+                       (tstoreddef(tpointerdef(left.resultdef).pointeddef),initrtti,rdt_normal)),
+                    ccallparanode.create(ctemprefnode.create
+                       (temp),nil));
+            addstatement(newstatement,ccallnode.createintern('fpc_initialize',para));
+          end;
+
+         { the last statement should return the value as
+           location and type, this is done be referencing the
+           temp and converting it first from a persistent temp to
+           normal temp }
+         addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
+         addstatement(newstatement,ctemprefnode.create(temp));
+         result:=newblock;
        end;
 
+
      function tinlinenode.first_length: tnode;
        begin
          result:=nil;

+ 3 - 32
compiler/pinline.pas

@@ -447,39 +447,10 @@ implementation
                (oo_has_vmt in tobjectdef(tpointerdef(p1.resultdef).pointeddef).objectoptions)  then
               Message(parser_w_use_extended_syntax_for_objects);
 
-            { create statements with call to getmem+initialize }
-            newblock:=internalstatements(newstatement);
-
-            { create temp for result }
-            temp := ctempcreatenode.create(p1.resultdef,p1.resultdef.size,tt_persistent,true);
-            addstatement(newstatement,temp);
-
-            { create call to fpc_getmem }
-            para := ccallparanode.create(cordconstnode.create
-                (tpointerdef(p1.resultdef).pointeddef.size,s32inttype,true),nil);
-            addstatement(newstatement,cassignmentnode.create(
-                ctemprefnode.create(temp),
-                ccallnode.createintern('fpc_getmem',para)));
-
-            { create call to fpc_initialize }
-            if is_managed_type(tpointerdef(p1.resultdef).pointeddef) then
-             begin
-               para := ccallparanode.create(caddrnode.create_internal(crttinode.create
-                          (tstoreddef(tpointerdef(p1.resultdef).pointeddef),initrtti,rdt_normal)),
-                       ccallparanode.create(ctemprefnode.create
-                          (temp),nil));
-               addstatement(newstatement,ccallnode.createintern('fpc_initialize',para));
-             end;
-
-            { the last statement should return the value as
-              location and type, this is done be referencing the
-              temp and converting it first from a persistent temp to
-              normal temp }
-            addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
-            addstatement(newstatement,ctemprefnode.create(temp));
+            if p1.nodetype=typen then
+              ttypenode(p1).allowed:=true;
 
-            p1.destroy;
-            p1:=newblock;
+            p1:=cinlinenode.create(in_new_x,false,p1);
           end
         else
           begin

+ 9 - 0
tests/webtbf/tw24495.pp

@@ -0,0 +1,9 @@
+{ %fail }
+program Project1;
+type
+  PFoo = ^Integer;
+var
+  a: Pointer;
+begin
+  a:= @New(PFoo);
+end.