バグ報告
状況:
Cygwinでjostarディレクトリに移動して、以下のコマンドを実行します
java -cp coins/classes jostarfront.JostarDriver -coins:target=x86_64 sample/classtest.j
すると、以下のNULLポインタの例外が出力されます
Exception in thread "Thread-0" java.lang.NullPointerException: Cannot invoke "coins.sym.Type.getAlignment()" because the return value of "coins.sym.Sym.getSymType()" is null
at coins.hir2lir.ConvToNewLIR.getAlignment(ConvToNewLIR.java:272)
at coins.hir2lir.ConvToNewLIR.staticEntBase(ConvToNewLIR.java:3443)
at coins.hir2lir.ConvToNewLIR.staticEnt(ConvToNewLIR.java:3449)
at coins.hir2lir.ConvToNewLIR.symEnt(ConvToNewLIR.java:3672)
at coins.hir2lir.ConvToNewLIR.convertSubpDef(ConvToNewLIR.java:1252)
at coins.hir2lir.ConvToNewLIR.doConvert(ConvToNewLIR.java:1011)
at coins.driver.Driver.makeNewLirFromHir(Driver.java:1044)
at coins.driver.Driver.compile(Driver.java:2143)
at coins.driver.CompileThread.doCompile(CompileThread.java:229)
at coins.driver.CompileThread$Compiler.go(CompileThread.java:355)
at coins.driver.CompileThread$PassGroup.go(CompileThread.java:276)
at coins.driver.CompileThread.callPassGroup(CompileThread.java:535)
at coins.driver.CompileThread.run(CompileThread.java:594)
原因:
出力メッセージにもあるようにgetSymTypeメソッドがnullを返すことが原因です。
ソースコードcoins.sym.Sym.javaのコメントを眺めますと、
Until closeSubpHeader() is called for the subprogram lSubp,
* lSubp.getSymType() is null
(中略)
getSymType
* Get the type of this symbol.
* @return type symbol representing the type of this symbol;
* If this is a symbol that has no type (label, key words,
* etc.), return null.
とあり、明らかにコーディング以前の段階で矛盾が生じています。
対策:
原因で触れたgetSymTypeメソッドが返すnullについて、どちらの意味を取るにせよ、nullチェックをします。けれども、そのためにはgetAlignmentメソッドがどんな機能なのかを調べる必要があります。
そこで、getAlignmentメソッドの機能を調べたうえで、そのコードを修正します。