2017-03-15 27 views
2

我們最近更新了GCC版本(4.8.2至5.3.0),並在某些Ada應用程序中開始接收意外的約束錯誤。我已經將它歸納爲以下:GCC更新後出現意外的CONSTRAINT_ERROR

-- moo.adb 
with text_io; 
procedure moo is 
    type thing_type is (something1,something2,something3,something4,something5,something6); 
    for thing_type use (something1 => 1,something2 => 2,something3 => 
     3,something4 => 4,something5 => 5,something6 => 6); 
    for thing_type'size use 32; 
    type thing_array_t is array (0 .. 5) of thing_type; 
    thing_array : thing_array_t := (others => something1); 
begin 
    text_io.put_line("item 0 = " & thing_type'image(thing_array(0))); 
end moo; 

該程序將彙編要麼版本的GCC當與4.8.2興建,預期輸出(簡單地加上「gnatmake moo.adb」編譯。)就好了:

item 0 = SOMETHING1 

當與5.0.3建成,我們代替接收

raised CONSTRAINT_ERROR : moo.adb:13 invalid data 

有趣的是,當如32和64位彙編的結果是完全一樣的。爲了使程序在5.3.0下正常工作,可以改變許多東西:刪除thing_type'size子句,向枚舉器添加或刪除值,更改數組中項目的數量,使用不同的值來初始化數組等等。這個代碼有什麼明顯的問題可以解釋這種行爲嗎?

+0

什麼是第13行? (您的列表只有12行) –

+0

對不起,我在粘貼時刪除了原來的一些空白行。第13行是text_io行。 – Kevin

回答

6

這個錯誤在GCC 7.0.1中仍然存在。調試器下運行,輸出稍編輯,

(gdb) catch exception 
Catchpoint 2: all Ada exceptions 
(gdb) run 
Starting program: /Users/simon/tmp/so/moo 
[New Thread 0x1703 of process 75511] 

Catchpoint 2, CONSTRAINT_ERROR (moo.adb:10 invalid data) at 0x0000000100001abe in _ada_moo() at moo.adb:10 
10  text_io.put_line("item 0 = " & thing_type'image(thing_array(0))); 
(gdb) p thing_array 
$5 = (0 => 16843009, 16843009, 16843009, 16843009, 16843009, 16843009) 
(gdb) p/x thing_array 
$6 = (0 => 0x1010101, 0x1010101, 0x1010101, 0x1010101, 0x1010101, 0x1010101) 

所以GNAT thing_array元件中的每一個字節錯誤地設置爲16#01#,而不是整個元件。

如果something1設置爲2(並且後面的值同樣增加),則會發生同樣的情況。

我能找到幫助的唯一的事情是聲明,例如,

type base_thing_type is (invalid, something1,something2,something3,something4,something5,something6); 
for base_thing_type use (invalid => 0, something1 => 1,something2 => 2,something3 => 
         3,something4 => 4,something5 => 5,something6 => 6); 
for base_thing_type'size use 32; 
type thing_type is new base_thing_type range something1 .. something6; 
+0

謝謝西蒙,我會向GCC提交一個錯誤報告。 – Kevin

+0

凱文,你曾經報告過這個錯誤嗎?它仍然存在於GCC 8.0.0 20171216 –

4

它看起來像GCC/GNAT中的錯誤。 我可以在標準兼容模式(-gnato -fstack-check -gnat12)下使用GNAT-GPL-2016複製不正確的行爲。關鍵部分似乎是Something1表示爲1而不是更典型的0。 我建議你向GCC開發者報告錯誤。

+0

謝謝,錯誤報告是:( – Kevin