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

Cerrado
#1,133 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Ya se ha fusionado un pull request relacionado.

  • #1145 de @MeteorsLiu — fusionado

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
75/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
c, go

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Go
Estrellas
40
Forks
13
Merge medio
2 h 44 min
PR fusionados (30 d)
112

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de goplus/llcppg

Todos los issues de goplus/llcppg

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.