cgo: struct attributes such as packed and aligned are rejected

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

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
c, go
領域
backend, compilers

調査の方向性

Start by reproducing the reported failure with the Go example using tinygo run main.go; compare its handling of attributed C structs and unions with the go run output. The issue does not name TinyGo source files or tests, so trace the cgo parsing path from the reported diagnostics. Done means the reproducer compiles and prints the reported sizes and opaque pointer result.

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

説明

TinyGo cgo rejects a struct or union that has an attribute. Go accepts these structs.

Reproducer

main.go:

package main

/*
struct plain { char a; int b; };
struct trailing { char a; int b; } __attribute__((packed));
struct __attribute__((packed)) leading { char a; int b; };
struct __attribute__((aligned(16))) aligned { char a; };
typedef const struct __attribute__((objc_bridge(id))) opaque *OpaqueRef;
*/
import "C"

import "unsafe"

func main() {
	println("plain", unsafe.Sizeof(C.struct_plain{}))
	println("trailing", unsafe.Sizeof(C.struct_trailing{}))
	println("leading", unsafe.Sizeof(C.struct_leading{}))
	println("aligned", unsafe.Sizeof(C.struct_aligned{}))
	var r C.OpaqueRef
	println("opaque", r == nil)
}
$ go run main.go
plain 8
trailing 5
leading 5
aligned 16
opaque true
$ tinygo run main.go
# command-line-arguments
main.go:5:31: expected a bitfield
main.go:5:51: expected FieldDecl in struct or union, not attribute(packed)
main.go:6:23: expected FieldDecl in struct or union, not attribute(packed)
main.go:6:54: expected a bitfield
main.go:7:23: expected FieldDecl in struct or union, not attribute(aligned)
main.go:8:37: expected FieldDecl in struct or union, not UnexposedAttr

TinyGo built from dev at 2661154a, darwin/arm64, LLVM 23.1.5, go 1.27.4.

主要言語
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 を短くまとめたダイジェスト。