Euphoria Ticket #607: integer constant overflow

Euphoria Interpreter v4.0.0
Linux, Using System Memory
Revision Date: 2010-12-22, Id: 115714454200

the following code crashes when run after translation

the translation commands are

$ euc -con test.ex
$ ./test

constant MINVAL_1 = 2.0  
atom     MINVAL_2 = 2.0  
  
function doit()  
  
   atom amt1 = 0  
   atom amt2 = 0  
   atom amt3 = 0  
   atom amt4 = 0  
  
   amt1 += MINVAL_1  
   amt2 -= MINVAL_1  
  
   amt3 += MINVAL_2  
   amt4 -= MINVAL_2  
  
   return 0  
  
end function  
  
? doit()  


part of the generated code 'test.c' contains

 /**  amt1 += MINVAL_1*/  
    _amt1_145 = NewDouble((double)0 + DBL_PTR(-1295837195 etc ... ->dbl); 
  
    /**  amt2 -= MINVAL_1*/  
    _amt2_146 = NewDouble((double)0 - DBL_PTR(-1295837195 etc ... ->dbl); 
  
    /**  amt3 += MINVAL_2*/  
    _amt3_147 = NewDouble((double)0 + DBL_PTR(_1MINVAL_2_142)->dbl);  
  
    /**  amt4 -= MINVAL_2*/  
    _amt4_148 = NewDouble((double)0 - DBL_PTR(_1MINVAL_2_142)->dbl);  


gcc compiles fine without error, but the app crashes when run.

tcc (Tiny CC, Fabrice Bellard) does not compile, and crashes
with integer constant overflow error

Details

Type: Bug Report Severity: Normal Category: Translator
Assigned To: mattlewis Status: Fixed Reported Release: 4.0.0
Fixed in SVN #: View VCS: none Milestone:

1. Comment by jaygade Feb 08, 2011

Here's a minimal example which exhibits the same failure, at least on Linux and gcc:

constant MINVAL_1 = 2.0 
  
atom amt1  
  
amt1 = MINVAL_1  
  
? amt1 
? MINVAL_1 

2. Comment by jaygade Feb 09, 2011

The problem is there is no code generated to assign the constant double "2.0" to the symbol MINVAL_1. The constant double "2.0" is being made with NewDouble. For some reason an empty string is being made, too, with NewString but that is probably unrelated. (Yeah, I found that that is even with a simple "Hello World" program.

Running the 3.1 translator, this initialization of assigning "2.0" to MINVAL1 is put into main-.c. I hand-corrected main-.c and I could make the program work.

Now to figure out why it's not getting initialized.

3. Comment by mattlewis Feb 12, 2011

The issue is how the translator determines when to write a constant value vs using the named, declared constant. A literal like "2.0" returns true when passed to integer(), however the intent was to use a double, and in fact, the translator tracks it as a double.

The fix appears to be to test not only for integer(), but the tracked S_GTYPE, to see if even though it looks like an integer, it's really a double.

4. Comment by mattlewis Feb 13, 2011

See: hg:euphoria/rev/8839461c69d6

changeset: 4636:8839461c69d6 branch: 4.0 parent: 4612:938c23da4322 user: Matt Lewis date: Sun Feb 13 09:37:28 2011 -0500 files: docs/release/4.0.1.txt source/c_decl.e source/compile.e tests/t_literals.e description:

  • Fixed translation of integers with decimals (e.g., 2.0) when assigned to constants
  • Fixes ticket 607

5. Comment by mattlewis Feb 13, 2011

See: hg:euphoria/rev/ef19b289c846

changeset: 4637:ef19b289c846 parent: 4613:8e661acb655e parent: 4636:8839461c69d6 user: Matt Lewis date: Sun Feb 13 09:40:12 2011 -0500 files: docs/release/4.0.1.txt source/c_decl.e source/compile.e tests/t_literals.e description:

  • merge fix for ticket 607 into trunk

Search



Quick Links

User menu

Not signed in.

Misc Menu