fix(cl): defer incomplete enum declarations instead of querying an invalid underlying type

Đã đóng
#1,133 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Một pull request liên quan đã được merge.

  • #1145 của @MeteorsLiu — đã merge

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
75/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c, go
Lĩnh vực
compilers, tooling

Hướng nghiên cứu

Start with cl/enum.go, especially loadEnum and its call to newEnumType, then use the supplied rpc_enum.h reproduction and source/llcppg.cfg. Run GOOS=darwin GOARCH=arm64 llcppg ./generated ./source to reproduce the panic. Done means the incomplete declaration is deferred until its definition is available, the final integer type and constants are preserved, and an unavailable definition produces a clear error rather than a panic.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

An enum forward declaration causes a panic before a following complete definition can be processed. The libc survey first encountered this at enum clnt_stat in rpc/pmap_clnt.h.

Minimal reproduction

rpc_enum.h:

enum clnt_stat;
enum clnt_stat { RPC_SUCCESS = 0 };

Use a source Go module requiring github.com/goplus/lib v0.7.0, with this configuration in source/llcppg.cfg:

{
  "Name": "libc",
  "Language": "c",
  "Dir": "$GOOS-$GOARCH/include",
  "Files": [
    "rpc_enum.h"
  ],
  "FailFast": 0,
  "IgnoreInline": true
}

Put the selected inputs under source/darwin-arm64/include, with the macOS 14.0 SDK headers available there where included. Leave Stdlib unset, and run:

GOOS=darwin GOARCH=arm64 llcppg ./generated ./source

Actual result

Generation exits 2 at the first line:

panic: rpc_enum.h:1:1: enum clnt_stat: unsupported underlying type  (0: )

The 0 is CXType_Invalid for the incomplete enum's underlying type. In cl/enum.go, loadEnum calls newEnumType before checking decl.IsCursorDefinition(). The incomplete declaration is therefore materialized too early.

Expected behavior

An incomplete declaration accepted by the selected C parser should not be converted into a completed enum until its definition is available. Preserve the final definition's underlying integer type and constants. If a usable definition is unavailable, report that condition without panicking or inventing an integer type.

#1032 covers enum declarations nested in records and their registration/reuse. This reproduction is a top-level forward declaration followed by its definition, and fails earlier in newEnumType.

Environment

Reproduced on macOS/arm64 with LLVM/libclang 22.1.8, LLGo 1.0.9 and github.com/goplus/lib v0.7.0. The relevant installed generator sources were checked byte-for-byte against current main 90bd72cf. SDK-dependent cases use macOS 14.0 headers. These are generation-stage results, not cross-platform or ABI certification.

Ngôn ngữ chính
Go
Star
40
Fork
13
Merge trung bình
2 giờ 48 phút
Pull request đã merge (30 ngày)
109

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của goplus/llcppg

Tất cả issue của goplus/llcppg

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.