Abstract
ChatGPT demonstrates significant potential to revolutionize software engineering (SE) by exhibiting outstanding performance in SE tasks such as code and document generation. However, the high reliability and risk control requirements in software engineering raise concerns about the lack of interpretability of ChatGPT. To address this concern, we conducted a study to evaluate the capabilities of ChatGPT and its limitations for code analysis in SE. We break down the abilities needed for artificial intelligence (AI) models to address SE tasks related to code analysis into three categories: 1) syntax understanding, 2) static behavior understanding, and 3) dynamic behavior understanding. Our investigation focused on the ability of ChatGPT to comprehend code syntax and semantic structures, which include abstract syntax trees (AST), control flow graphs (CFG), and call graphs (CG). We assessed the performance of ChatGPT on cross-language tasks involving C, Java, Python, and Solidity. Our findings revealed that while ChatGPT has a talent for understanding code syntax, it struggles with comprehending code semantics, particularly dynamic semantics. We conclude that ChatGPT possesses capabilities similar to an Abstract Syntax Tree (AST) parser, demonstrating initial competencies in static code analysis. Furthermore, our study highlights that ChatGPT is susceptible to hallucinations when interpreting code semantic structures and fabricating nonexistent facts. These results indicate the need to explore methods to verify the correctness of ChatGPT output to ensure its dependability in SE.
Introduction
In the world of Software Engineering (SE), reliability is paramount. As Large Language Models (LLMs) are increasingly integrated into workflows for code generation and automated repair, understanding the "black box" of their reasoning becomes critical. A fundamental question remains: does an LLM truly understand the semantics—the underlying meaning and behavior—of the code it produces, or is it merely a sophisticated pattern-matching engine? This study investigates the depth of LLM comprehension by categorizing code analysis capabilities into a hierarchical framework of syntax, static behavior, and dynamic behavior.
Research Methodology
To systematically evaluate LLM performance, the researchers established a framework that decomposes software engineering tasks into three distinct levels of understanding. This approach allows for the isolation of specific cognitive failures in AI models.
The study evaluated four state-of-the-art models: GPT-4, GPT-3.5, StarCoder, and CodeLlama-13b-instruct. The evaluation was structured around nine core tasks:
- Syntax Understanding: Generating Abstract Syntax Trees (AST) and matching mathematical expressions.
- Static Behavior Understanding: Constructing Control Flow Graphs (CFG) and Call Graphs (CG), alongside data dependency, taint, and pointer analysis.
- Dynamic Behavior Understanding: Detecting equivalent mutants and reasoning about flaky tests.
Experimental Setup and Datasets
The investigation utilized a diverse collection of 2,560 data points across 217 programs in four languages: Python, Java, C, and Solidity. The researchers leveraged established benchmarks like QuixBugs and SVF, while also introducing new datasets for specialized tasks.
One notable addition was a dataset for Expression Matching, created by extracting reward-computing equations from Decentralized Finance (DeFi) whitepapers and matching them to real-world Solidity smart contracts. Ground truth for these tasks was established using professional static analysis tools such as Tree-Sitter, Slither, and Frama-C.
Key Insights and Results
The "AST Parser" Level
The study found that LLMs, particularly GPT-4, are exceptionally proficient at syntax. They can effectively function as an AST parser, identifying token roles with high accuracy. This explains why LLM-generated code is frequently syntactically correct even when it is logically flawed.
The Semantic Wall and Structural Hallucinations
A sharp performance decline occurs when moving from syntax to semantics. Models struggle significantly with Taint Analysis—tracking potentially malicious user input through a system—often performing no better than a random guess. Furthermore, when tasked with building structural graphs like CFGs, LLMs frequently "hallucinate," inventing non-existent code blocks or execution paths that do not exist in the source file.
Performance Metrics
- Model Leadership: GPT-4 consistently outperformed competitors, especially in complex reasoning tasks like Call Graph generation.
- Syntax Success: In expression matching, GPT-4 and GPT-3.5 achieved high hit rates (27/32 and 28/32), while open-source models like StarCoder lagged significantly (5/32).
- Static and Dynamic Failures: While GPT-4 achieved an F1 score of 0.69 for Data Dependency, its performance plummeted to 0.44 for Taint Analysis. In dynamic analysis, such as detecting equivalent mutants, CodeLlama failed entirely (F1 of 0), while GPT-4 reached only 0.67.
Conclusion and Future Work
The findings suggest that current LLMs are "syntax savants"—they possess a sophisticated grasp of code structure but a fragile understanding of logic and execution flow. Their sensitivity to data shifts and propensity for structural hallucinations highlight the risks of unverified LLM integration in SE.
Future research should focus on hybrid approaches that combine the creative generative power of LLMs with the rigorous verification of traditional formal methods. By using LLMs for initial drafting and traditional tools for safety checks, the industry can move toward more dependable AI-assisted software engineering.
Summary updated