mirror of
				https://gitlab.com/freepascal.org/fpc/source.git
				synced 2025-11-04 14:39:36 +01:00 
			
		
		
		
	* fixed pred/succ for integer constants that equal the low/high bound of a
built-in integer type (reported by Stefan Kisdaroczi) git-svn-id: trunk@14537 -
This commit is contained in:
		
							parent
							
								
									40cea8d4d5
								
							
						
					
					
						commit
						83c3e7a94b
					
				
							
								
								
									
										1
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
								
							@ -8254,6 +8254,7 @@ tests/tbs/tb0561b.pp svneol=native#text/plain
 | 
				
			|||||||
tests/tbs/tb0564.pp svneol=native#text/plain
 | 
					tests/tbs/tb0564.pp svneol=native#text/plain
 | 
				
			||||||
tests/tbs/tb0565.pp svneol=native#text/plain
 | 
					tests/tbs/tb0565.pp svneol=native#text/plain
 | 
				
			||||||
tests/tbs/tb0566.pp svneol=native#text/plain
 | 
					tests/tbs/tb0566.pp svneol=native#text/plain
 | 
				
			||||||
 | 
					tests/tbs/tb0567.pp svneol=native#text/plain
 | 
				
			||||||
tests/tbs/tb205.pp svneol=native#text/plain
 | 
					tests/tbs/tb205.pp svneol=native#text/plain
 | 
				
			||||||
tests/tbs/ub0060.pp svneol=native#text/plain
 | 
					tests/tbs/ub0060.pp svneol=native#text/plain
 | 
				
			||||||
tests/tbs/ub0069.pp svneol=native#text/plain
 | 
					tests/tbs/ub0069.pp svneol=native#text/plain
 | 
				
			||||||
 | 
				
			|||||||
@ -1413,7 +1413,6 @@ implementation
 | 
				
			|||||||
        hp        : tnode;
 | 
					        hp        : tnode;
 | 
				
			||||||
        vl,vl2    : TConstExprInt;
 | 
					        vl,vl2    : TConstExprInt;
 | 
				
			||||||
        vr        : bestreal;
 | 
					        vr        : bestreal;
 | 
				
			||||||
        checkrange: boolean;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      begin { simplify }
 | 
					      begin { simplify }
 | 
				
			||||||
         result:=nil;
 | 
					         result:=nil;
 | 
				
			||||||
@ -1635,16 +1634,20 @@ implementation
 | 
				
			|||||||
              in_pred_x,
 | 
					              in_pred_x,
 | 
				
			||||||
              in_succ_x:
 | 
					              in_succ_x:
 | 
				
			||||||
                begin
 | 
					                begin
 | 
				
			||||||
                  { only perform range checking if the result is an enum }
 | 
					 | 
				
			||||||
                  checkrange:=(resultdef.typ=enumdef);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                  if (left.nodetype=ordconstn) then
 | 
					                  if (left.nodetype=ordconstn) then
 | 
				
			||||||
                   begin
 | 
					                    begin
 | 
				
			||||||
                     if (inlinenumber=in_succ_x) then
 | 
					                      if (inlinenumber=in_succ_x) then
 | 
				
			||||||
                       result:=cordconstnode.create(tordconstnode(left).value+1,left.resultdef,checkrange)
 | 
					                        vl:=tordconstnode(left).value+1
 | 
				
			||||||
                     else
 | 
					                      else
 | 
				
			||||||
                       result:=cordconstnode.create(tordconstnode(left).value-1,left.resultdef,checkrange);
 | 
					                        vl:=tordconstnode(left).value-1;
 | 
				
			||||||
                   end;
 | 
					                      if is_integer(left.resultdef) then
 | 
				
			||||||
 | 
					                      { the type of the original integer constant is irrelevant,
 | 
				
			||||||
 | 
					                        it should be automatically adapted to the new value }
 | 
				
			||||||
 | 
					                        result:=genintconstnode(vl)
 | 
				
			||||||
 | 
					                      else
 | 
				
			||||||
 | 
					                        { check the range for enums, chars, booleans }
 | 
				
			||||||
 | 
					                        result:=cordconstnode.create(vl,left.resultdef,true)
 | 
				
			||||||
 | 
					                    end
 | 
				
			||||||
                end;
 | 
					                end;
 | 
				
			||||||
              in_low_x,
 | 
					              in_low_x,
 | 
				
			||||||
              in_high_x:
 | 
					              in_high_x:
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										31
									
								
								tests/tbs/tb0567.pp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								tests/tbs/tb0567.pp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					begin
 | 
				
			||||||
 | 
					  if (pred(-128)<>-129) or
 | 
				
			||||||
 | 
					     (succ(127)<>128) then
 | 
				
			||||||
 | 
					    halt(1);
 | 
				
			||||||
 | 
					  if (pred(0)<>-1) or
 | 
				
			||||||
 | 
					     (succ(255)<>256) then
 | 
				
			||||||
 | 
					    halt(2);
 | 
				
			||||||
 | 
					  if (pred(-32768)<>-32769) or
 | 
				
			||||||
 | 
					     (succ(32767)<>32768) then
 | 
				
			||||||
 | 
					    halt(3);
 | 
				
			||||||
 | 
					  if (succ(65535)<>65536) then
 | 
				
			||||||
 | 
					    halt(4);
 | 
				
			||||||
 | 
					  if (pred(-2147483648)<>-2147483649) or
 | 
				
			||||||
 | 
					     (succ(2147483647)<>2147483648) then
 | 
				
			||||||
 | 
					    halt(5);
 | 
				
			||||||
 | 
					  if (succ(4294967295)<>4294967296) then
 | 
				
			||||||
 | 
					    halt(6);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (pred(bytebool(false))<>bytebool(true)) then
 | 
				
			||||||
 | 
					    halt(7);
 | 
				
			||||||
 | 
					  if (succ(bytebool(true))<>bytebool(false)) then
 | 
				
			||||||
 | 
					    halt(8);
 | 
				
			||||||
 | 
					  if (pred(wordbool(false))<>wordbool(true)) then
 | 
				
			||||||
 | 
					    halt(9);
 | 
				
			||||||
 | 
					  if (succ(wordbool(true))<>wordbool(false)) then
 | 
				
			||||||
 | 
					    halt(10);
 | 
				
			||||||
 | 
					  if (pred(longbool(false))<>longbool(true)) then
 | 
				
			||||||
 | 
					    halt(11);
 | 
				
			||||||
 | 
					  if (succ(longbool(true))<>longbool(false)) then
 | 
				
			||||||
 | 
					    halt(12);
 | 
				
			||||||
 | 
					end.
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user