fix(tool,clang): fail generation when libclang reports a fatal parse diagnostic

Aperta
#1,137 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Start by reading clang/clang.go:Index.ParseTranslationUnit and tool/gen.go:ParseSources, then reproduce with GOOS=darwin GOARCH=arm64 llcppg ./generated ./source using the issue's missing-header setup. Add or update a regression test around fatal libclang diagnostics so generation exits nonzero, preserves the original diagnostic, and does not continue with the recovered AST. The existing source files and minimal reproduction provide clear starting points, but contributors will need familiarity with the generation pipeline.

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

Descrizione

A missing required include produces a libclang fatal diagnostic, but llcppg still returns success. Checking only the translation-unit API's return code does not establish that its recovered AST is valid for generation.

Minimal reproduction

missing.h:

#include "dependency_missing_for_this_reproducer.h"

Do not create that dependency.

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": [
    "missing.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

missing.h:1:10: fatal error: 'dependency_missing_for_this_reproducer.h' file not found

Despite this diagnostic, the llcppg command exits 0. In the broader libc run, fatal include errors were likewise followed by later generation and an unrelated enum/name panic.

clang/clang.go:Index.ParseTranslationUnit only checks clang_parseTranslationUnit2's error code. tool/gen.go:ParseSources then accepts the returned unit without inspecting its Error/Fatal diagnostics. libclang can return a recoverable translation unit even when its diagnostics include fatal errors.

Expected behavior

Normal generation must fail clearly on a fatal parse diagnostic and must not report a recovered, incomplete AST as a successful conversion. Preserve the original diagnostic rather than allowing later errors to obscure it. No new CLI option or public API is proposed.

This is separate from intentional skipping of an unsupported C type and from #997's context-dependent header discovery: the reproducer uses one explicitly selected input with one missing include.

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
PR unite (30g)
150

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.