cgo: shared macro expressions cause internal errors

オープン
#6,226 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
半日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c, go
領域
compilers

調査の方向性

The failure comes from cgoPackage.isEquivalentAST, which compares cgo declarations across files but has no case for *ast.ParenExpr or *ast.BinaryExpr. Start by reproducing with the two-file example (a.go and b.go each defining C.VALUE from #define VALUE (1)) using tinygo build .. Done means both files build, the same macro expressions compare as equivalent, and conflicting definitions are still rejected.

索引モデルが issue の本文から書いたものです。

説明

When two Go files in the same package refer to the same C macro, TinyGo fails if the macro contains a parenthesized expression.

a.go:

package main

/*
#define VALUE (1)
*/
import "C"

const first = C.VALUE

func main() {
	println(first, second)
}

b.go:

package main

/*
#define VALUE (1)
*/
import "C"

const second = C.VALUE

In a new directory, run:

go mod init example.com/cgo-ast-repro
tinygo build .

TinyGo reports:

# example.com/cgo-ast-repro
a.go:4:15: internal error: unknown AST node: *ast.ParenExpr

The same program builds with go build .. Using #define VALUE 1 + 2 in both files also fails, with unknown AST node: *ast.BinaryExpr.

cgoPackage.isEquivalentAST compares declarations across cgo files but does not handle these expression nodes. It should compare them and continue to reject conflicting definitions.

Reproduced on dev at bf8bb7ca with TinyGo 0.45.0-dev, Go 1.27.3, and LLVM 23.1.5 on macOS arm64.

主要言語
Go
スター
17.8k
フォーク
1.1k
平均マージ
1日 4時間
マージ済み PR(30日)
380

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

tinygo-org/tinygo のほかの issue

tinygo-org/tinygo の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。