🤖 AI Summary
Traditional control flow graph (CFG) generation methods rely on syntactically complete code and language-specific tooling, making them ill-suited for handling erroneous or incomplete code fragments and lacking unified support across multiple programming languages. This work proposes the first approach to leverage lightweight large language models—such as CodeLlama and QwenCoder—for robust CFG construction from such low-quality inputs. By employing instruction fine-tuning, a unified serialization format, and an automatically curated, error-augmented dataset derived from LeetCode, the method achieves strong parsing performance even on malformed or partial code. Notably, it not only excels on languages seen during training but also demonstrates cross-lingual generalization to unseen programming languages, establishing a new paradigm for static analysis of multilingual, low-quality code.
📝 Abstract
Control Flow Graph (CFG) is an important program representations for software analysis, code understanding, and software maintenance. Traditional CFG generation techniques mainly rely on bytecode or abstract syntax trees. However, these approaches usually require complete, compilable, and syntax error-free code, which limits their applicability to incomplete or erroneous code. Furthermore, they often depend on language specific tools, making it difficult to support multiple programming languages in a unified manner. To address these limitations, this paper investigates the use of fine-tuned lightweight large language models (LLMs) for CFG generation. We first design a unified CFG output format and a task-specific fine-tuning prompt for CFG generation. Then, we construct a dataset based on an existing LeetCode dataset through automatic CFG generation and error augmentation. We evaluate the proposed approach on six lightweight LLM models, including three code-specific LLMs: CodeLlama, QwenCoder, and DeepSeekCoder; and three general purpose LLMs: Llama3.2-3B, Qwen-4B, and Phi-4B. The experimental results show that, through fine-tuning, lightweight LLMs achieve promising results for CFG generation, particularly when the input code is incomplete or erroneous. It also demonstrates cross-language generalization capability on programming language not included in the fine-tuning data.