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

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

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

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
70/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c, cpp, go
領域
compilers, tooling

調査の方向性

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.

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

説明

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.

主要言語
Go
スター
40
フォーク
13
平均マージ
2時間
マージ済み PR(30日)
150

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

goplus/llcppg のほかの issue

goplus/llcppg の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。