[erlang-bugs] Core Erlang Binary Literals in Clause Nodes Breaks the Compiler

Eric Merritt ericbmerritt@REDACTED
Mon Jan 16 17:31:05 CET 2012


Guys,

I believe this is a bug. I hope the included information sufficient
and useful. If
not I can provide some more programmably testable result. A binary
literal in a pattern breaks the 'from_core' compiler.  The erlang to
core compiler does not produce binary literals for patterns, so I
suspect this code has simply never been tested. Binary literals
({c_literal, [],
<<"ok">>} for example) in the pattern part of a c_clause causes the
compiler to error out. Here are two versions of the same AST one of
which works, the other causes the compiler to error.

You can compile both of these with

   compile:forms(AST, [binary, from_core]).

Working AST:

CerlAST = {c_module,
            [1,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
            {c_literal,
             [1,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
             test},
            [{c_var,[compiler_generated],{module_info,1}},
             {c_var,
              [3,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
              {test,1}},
             {c_var,[compiler_generated],{module_info,0}}],
            [],
            [{{c_var,[compiler_generated],{module_info,0}},
              {c_fun,
               [compiler_generated],
               [],
               {c_call,[],
                {c_literal,[],erlang},
                {c_literal,[],get_module_info},
                [{c_literal,[],test}]}}},
             {{c_var,[compiler_generated],{module_info,1}},
              {c_fun,
               [compiler_generated],
               [{c_var,[],mdetail}],
               {c_call,[],
                {c_literal,[],erlang},
                {c_literal,[],get_module_info},
                [{c_literal,[],test},{c_var,[],mdetail}]}}},
             {{c_var,
               [3,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
               {test,1}},
              {c_fun,
               [3,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
               [{c_var,

[3,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                 el}],
               {c_case,

[4,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                {c_var,

[4,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                 el},
                [{c_clause,

[5,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                  [{c_binary,

[5,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                    [{c_bitstr,

[5,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                      {c_literal,
                       [5,

{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                       111},
                      {c_literal,
                       [5,

{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                       8},
                      {c_literal,[compiler_generated],1},
                      {c_literal,
                       [5,

{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                       integer},
                      {c_literal,
                       [5,

{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                       [unsigned,big]}},
                     {c_bitstr,

[5,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                      {c_literal,
                       [5,

{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                       107},
                      {c_literal,
                       [5,

{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                       8},
                      {c_literal,[compiler_generated],1},
                      {c_literal,
                       [5,

{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                       integer},
                      {c_literal,
                       [5,

{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                       [unsigned,big]}}]}],
                  {c_literal,

[5,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                   true},
                  {c_binary,

[6,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                   [{c_bitstr,

[6,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                     {c_literal,

[6,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                      34},
                     {c_literal,

[6,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                      8},
                     {c_literal,[compiler_generated],1},
                     {c_literal,

[6,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                      integer},
                     {c_literal,

[6,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                      [unsigned,big]}}]}},
                 {c_clause,

[7,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                  [{c_var,

[7,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                    '_GENSYM_727BDA1'}],
                  {c_literal,

[7,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                   true},
                  {c_literal,

[8,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                   foo}}]}}}]}




Broken AST:

CerlAST = {c_module,
            [1,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
            {c_literal,
             [1,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
             test},
            [{c_var,[compiler_generated],{module_info,1}},
             {c_var,
              [3,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
              {test,1}},
             {c_var,[compiler_generated],{module_info,0}}],
            [],
            [{{c_var,[compiler_generated],{module_info,0}},
              {c_fun,
               [compiler_generated],
               [],
               {c_call,[],
                {c_literal,[],erlang},
                {c_literal,[],get_module_info},
                [{c_literal,[],test}]}}},
             {{c_var,[compiler_generated],{module_info,1}},
              {c_fun,
               [compiler_generated],
               [{c_var,[],mdetail}],
               {c_call,[],
                {c_literal,[],erlang},
                {c_literal,[],get_module_info},
                [{c_literal,[],test},{c_var,[],mdetail}]}}},
             {{c_var,
               [3,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
               {test,1}},
              {c_fun,
               [3,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
               [{c_var,

[3,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                 el}],
               {c_case,

[4,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                {c_var,

[4,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                 el},
                [{c_clause,

[5,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                  [{c_literal,

[5,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                   <<"ok">>}],
                  {c_literal,

[5,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                   true},
                  {c_binary,

[6,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                   [{c_bitstr,

[6,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                     {c_literal,

[6,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                      34},
                     {c_literal,

[6,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                      8},
                     {c_literal,[compiler_generated],1},
                     {c_literal,

[6,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                      integer},
                     {c_literal,

[6,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                      [unsigned,big]}}]}},
                 {c_clause,

[7,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                  [{c_var,

[7,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                    '_GENSYM_727BDA1'}],
                  {c_literal,

[7,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                   true},
                  {c_literal,

[8,{file,"/home/emerritt/workspace/joxa/src/test.jxa"}],
                   foo}}]}}}]}



More information about the erlang-bugs mailing list