Browse Source

+ initialise managed string function results with an error string when
compiling with -gt (mantis #28948)

git-svn-id: trunk@33198 -

Jonas Maebe 9 năm trước cách đây
mục cha
commit
0e97811b50
3 tập tin đã thay đổi với 30 bổ sung2 xóa
  1. 1 0
      .gitattributes
  2. 18 2
      compiler/ngenutil.pas
  3. 11 0
      tests/webtbs/tw28948.pp

+ 1 - 0
.gitattributes

@@ -14927,6 +14927,7 @@ tests/webtbs/tw2891.pp svneol=native#text/plain
 tests/webtbs/tw28916.pp svneol=native#text/pascal
 tests/webtbs/tw28916.pp svneol=native#text/pascal
 tests/webtbs/tw2892.pp svneol=native#text/plain
 tests/webtbs/tw2892.pp svneol=native#text/plain
 tests/webtbs/tw28934.pp svneol=native#text/plain
 tests/webtbs/tw28934.pp svneol=native#text/plain
+tests/webtbs/tw28948.pp svneol=native#text/plain
 tests/webtbs/tw28964.pp svneol=native#text/plain
 tests/webtbs/tw28964.pp svneol=native#text/plain
 tests/webtbs/tw2897.pp svneol=native#text/plain
 tests/webtbs/tw2897.pp svneol=native#text/plain
 tests/webtbs/tw2899.pp svneol=native#text/plain
 tests/webtbs/tw2899.pp svneol=native#text/plain

+ 18 - 2
compiler/ngenutil.pas

@@ -443,7 +443,11 @@ implementation
           ((vo_is_funcret in tabstractnormalvarsym(p).varoptions) or
           ((vo_is_funcret in tabstractnormalvarsym(p).varoptions) or
            (tabstractnormalvarsym(p).varspez=vs_out)))) and
            (tabstractnormalvarsym(p).varspez=vs_out)))) and
          not (vo_is_default_var in tabstractnormalvarsym(p).varoptions) and
          not (vo_is_default_var in tabstractnormalvarsym(p).varoptions) and
-         not is_managed_type(tabstractnormalvarsym(p).vardef) and
+         (not is_managed_type(tabstractnormalvarsym(p).vardef) or
+          (is_string(tabstractnormalvarsym(p).vardef) and
+           (vo_is_funcret in tabstractnormalvarsym(p).varoptions)
+          )
+         ) and
          not assigned(tabstractnormalvarsym(p).defaultconstsym);
          not assigned(tabstractnormalvarsym(p).defaultconstsym);
     end;
     end;
 
 
@@ -468,7 +472,19 @@ implementation
                   the procedure address -> cast to tmethod instead }
                   the procedure address -> cast to tmethod instead }
                 trashn:=ctypeconvnode.create_explicit(trashn,methodpointertype);
                 trashn:=ctypeconvnode.create_explicit(trashn,methodpointertype);
             end;
             end;
-          if ((p.typ=localvarsym) and
+          if is_managed_type(p.vardef) then
+            begin
+              if is_string(p.vardef) then
+                trash_small(stat,trashn,
+                  cstringconstnode.createstr(
+                    'uninitialized function result in '+
+                    tprocdef(p.owner.defowner).customprocname([pno_proctypeoption, pno_paranames,pno_ownername, pno_noclassmarker])
+                  )
+                )
+              else
+                internalerror(2016030601);
+            end
+          else if ((p.typ=localvarsym) and
               (not(vo_is_funcret in p.varoptions) or
               (not(vo_is_funcret in p.varoptions) or
                not is_shortstring(p.vardef))) or
                not is_shortstring(p.vardef))) or
              ((p.typ=paravarsym) and
              ((p.typ=paravarsym) and

+ 11 - 0
tests/webtbs/tw28948.pp

@@ -0,0 +1,11 @@
+{ %OPT=-gt }
+
+function f: ansistring;
+begin
+end;
+
+begin
+  writeln(f);
+  if pos('uninitialized function result',f)=0 then
+    halt(1);
+end.