代码之家  ›  专栏  ›  技术社区  ›  LambdaBeta

Ada标记比较导致编译器崩溃

  •  1
  • LambdaBeta  · 技术社区  · 6 年前

    我不确定这是否是gcc(4.8.5)或gprbuild(2.2.0)版本中的一个bug,但是当我试图编译一个项目时,有一个特定的函数,它的主体会导致编译器崩溃 STORAGE_ERROR . 当我用 -cargs -v gnatl -quiet ... 是崩溃前最近输出的命令。

    function Tag_To_String (From : Ada.Tags.Tag) return String is (
        if From = A'Tag then "This is tag A"
        elsif From = B'Tag then "This is tag B"
        --  ...
        elsif From = Z'Tag then "This is tag Z"
        else "");
    

    然而,如果我将主体更改为:

    function Tag_To_String (From : Ada.Tags.Tag) return String is ("");
    

    我得到的错误正好是:

    gcc -c -gnat12 sourcefile.adb
    
    raised STORAGE_ERROR : stack overflow or erroneous memory access
    gprbuild: *** compilation phase failed
    

    你知道为什么gcc不能编译这个函数吗?

    1 回复  |  直到 6 年前
        1
  •  5
  •   Jim Rogers    6 年前

    with Ada.text_IO; use Ada.Text_IO;
    with Ada.Tags; use Ada.Tags;
    
    procedure Tag_Main is
       package foo is
          type A is tagged private;
          type B is tagged private;
       private
          type A is tagged null record;
          type B is tagged null record;
       end foo;
    
       use Foo;
    
       function Tag_To_String(From : Ada.Tags.Tag) return String is(
          if From = A'Tag then
             "This is tag A"
          else
             "This is tag B"
          );
    
    begin
       Put_Line(Tag_To_String(A'Tag));
       Put_Line(Tag_To_String(B'Tag));
    end Tag_Main;
    

    注意,我已经编辑了使用函数表达式的代码。它仍然适用于GNAT/GPS 2018版本。 这个版本是用gprbuild-d-PD编译的