소스 검색

* prevent warning for val with second parameter not being a longint

git-svn-id: trunk@1463 -
peter 20 년 전
부모
커밋
5abb9d68f6
3개의 변경된 파일68개의 추가작업 그리고 4개의 파일을 삭제
  1. 1 0
      .gitattributes
  2. 6 4
      compiler/ninl.pas
  3. 61 0
      tests/webtbs/tw4006.pp

+ 1 - 0
.gitattributes

@@ -6273,6 +6273,7 @@ tests/webtbs/tw3971.pp svneol=native#text/plain
 tests/webtbs/tw3973.pp svneol=native#text/plain
 tests/webtbs/tw3977.pp svneol=native#text/plain
 tests/webtbs/tw3977.txt svneol=native#text/plain
+tests/webtbs/tw4006.pp svneol=native#text/plain
 tests/webtbs/tw4007.pp svneol=native#text/plain
 tests/webtbs/tw4009.pp svneol=native#text/plain
 tests/webtbs/tw4010.pp svneol=native#text/plain

+ 6 - 4
compiler/ninl.pas

@@ -1037,11 +1037,13 @@ implementation
         { its right field is nil                                               }
         sourcepara.right := sizepara;
 
-        { create the call and assign the result to dest  }
-        { (val helpers are functions)                    }
-        { the assignment will take care of rangechecking }
+        { create the call and assign the result to dest (val helpers are functions).
+          Use a trick to prevent a type size mismatch warning to be generated by the
+          assignment node. First convert implicitly to the resulttype. This will insert
+          the range check. The Second conversion is done explicitly to hide the implicit conversion
+          for the assignment node and therefor preventing the warning (PFV) }
         addstatement(newstatement,cassignmentnode.create(
-          destpara.left,ccallnode.createintern(procname,newparas)));
+          destpara.left,ctypeconvnode.create_internal(ctypeconvnode.create(ccallnode.createintern(procname,newparas),destpara.left.resulttype),destpara.left.resulttype)));
 
         { dispose of the enclosing paranode of the destination }
         destpara.left := nil;

+ 61 - 0
tests/webtbs/tw4006.pp

@@ -0,0 +1,61 @@
+{ %opt=-Sew }
+
+{ Source provided for Free Pascal Bug Report 4006 }
+{ Submitted by "Torsten Kildal" on  2005-05-23 }
+{ e-mail: kildal@mx }
+program Val_Test;
+{$IFDEF FPC}
+  {$MODE TP}  {BP/TP compatible}
+  {$H-}       {short strings!}
+{$ENDIF}
+
+{$R+}
+
+VAR
+  s     : string;
+  iVar  : smallint;
+  lVar  : longint;             { BP7  = Borland Pascal }
+  rVar  : real;                { 1010 = FPC 1.0.10     }
+  iCode : integer;             { 196  = FPC 1.9.6      }
+  wCode : word;                { 200  = FPC 2.0.0      }
+
+begin
+  s:='3.14'; {content plays no roll}
+
+  VAL(s,iVar,iCode);
+  {BP7 : ok}
+  {1010: ok}
+  {196 : Warning: Type size mismatch, possible loss of data / range check error}
+  {200 : Warning: Type size mismatch, possible loss of data / range check error}
+
+  VAL(s,lVar,iCode);
+  {BP7 : ok}
+  {1010: ok}
+  {196 : ok}
+  {200 : ok}
+
+  VAL(s,rVar,iCode);
+  {BP7 : ok}
+  {1010: ok}
+  {196 : Warning: Type size mismatch, possible loss of data / range check error}
+  {200 : Warning: Type size mismatch, possible loss of data / range check error}
+(*
+  VAL(s,iVar,wCode);
+  {BP7 : ok}
+  {1010: ok}
+  {196 : Warning: Type size mismatch, possible loss of data / range check error}
+  {200 : Warning: Type size mismatch, possible loss of data / range check error}
+
+  VAL(s,lVar,wCode);
+  {BP7 : ok}
+  {1010: ok}
+  {196 : ok}
+  {200 : ok}
+
+  VAL(s,rVar,wCode);
+  {BP7 : ok}
+  {1010: ok}
+  {196 : Warning: Type size mismatch, possible loss of data / range check error}
+  {200 : Warning: Type size mismatch, possible loss of data / range check error}
+*)
+end.