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

Chiusa
#1,133 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Una pull request collegata è già stata integrata.

  • #1145 di @MeteorsLiu — integrata

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
75/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
c, go
Ambito
compilers, tooling

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Go
Stelle
40
Fork
13
Merge medio
2h 44m
PR unite (30g)
112

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di goplus/llcppg

Tutte le issue di goplus/llcppg

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.