[論文レビュー] LMs: Understanding Code Syntax and Semantics for Code Analysis
本研究は、複数の言語にわたる静的および動的分析のために、LLMs がコードの構文と意味論をどれほど理解しているかを評価し、構文理解は強力だが動的意味論には限界があり、データシフトと幻覚リスクが顕著であることを示した。
Large language models~(LLMs) demonstrate 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 LLMs. To address this concern, we conducted a study to evaluate the capabilities of LLMs and their 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 LLMs to comprehend code syntax and semantic structures, which include abstract syntax trees (AST), control flow graphs (CFG), and call graphs (CG). We employed four state-of-the-art foundational models, GPT4, GPT3.5, StarCoder and CodeLlama-13b-instruct. We assessed the performance of LLMs on cross-language tasks involving C, Java, Python, and Solidity. Our findings revealed that while LLMs have a talent for understanding code syntax, they struggle with comprehending code semantics, particularly dynamic semantics. We conclude that LLMs possess capabilities similar to an Abstract Syntax Tree (AST) parser, demonstrating initial competencies in static code analysis. Furthermore, our study highlights that LLMs are 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 LLM output to ensure its dependability in SE. More importantly, our study provides an initial answer to why the codes generated by LLM are usually syntax-correct but vulnerable.
研究の動機と目的
- LLMs がコード構文(ASTと式の役割)を理解できるかを評価する。
- 静的挙動(CFG、CG、データ依存、タイント、ポインター解析)を理解する能力を評価する。
- 等価変異体、フレークテストなどの動的挙動の理解を調査する。
- コード分析タスクの信頼性と限界を決定するために、プロンプトとデータソースを分析する。
提案手法
- 最先端のLLMを四つ評価して9つのタスクに跨って評価する(GPT-4、GPT-3.5、StarCoder、CodeLlama-13b-instruct)。
- 構文理解をテストするタスクを設計する(AST生成、式の照合)。
- 静的解析能力をテストする(CFG、CG、データ依存、タイント解析、ポインター解析)。
- 等価変異体検出とフレークテスト推論を通じた動的挙動理解の評価。
- 厳選されたデータセットを使用(2,560データポイント、151,633 LoC、217プログラム)と多様な言語(Python、Java、C、Solidity)。
- 役割ベースおよび指示型プロンプトを活用し、GPTベースのツールを用いたプロンプト最適化を行う。出力を AST パーサー、専門家レビュー、グラウンドトゥルースツール(Tree-Sitter、Slither、Frama-C)と比較して評価する。
実験結果
リサーチクエスチョン
- RQ1RQ1: LLMs はコード構文を十分に理解できるか?
- RQ2RQ2: LLMs はコードの静的挙動を理解できるか?
- RQ3RQ3: LLMs はコードの動的挙動を理解できるか?
主な発見
- GPT-4 と GPT-3.5 はコード構文理解において高い性能を示し、AST パーサーとしても機能できる。
- LLMs は静的解析に部分的な能力を持ち、CFG や CG の生成、データフロー類の解析を初級レベルで実行できる。
- LLMs は等価変異体検出やフレークテスト推論など、動的意味論タスクには苦労する。
- データシフトのあるプロジェクト間で性能が異なり、データ依存およびタイント解析の F1 は 0 から 0.8 の範囲。
- オープンソースモデル(CodeLlama、StarCoder)は、これらのタスクで OpenAI モデルよりも低パフォーマンス。
- LLMs は構文的に正しいコードを生成できるが、意味論を幻覚する可能性がある。SE コンテキストでは出力検証の強調が必要。
より良い研究を、今すぐ始めましょう
論文設計から論文執筆まで、研究時間を劇的に削減しましょう。
クレジットカード登録不要
このレビューはAIが作成し、人間の編集者が確認しました。