[논문 리뷰] LMs: Understanding Code Syntax and Semantics for Code Analysis
본 연구는 다수의 언어에서 정적 및 동적 분석을 위한 코드 구문과 의미를 LLM이 얼마나 잘 이해하는지 평가하며, 강한 구문 이해를 보이나 제한된 동적 의미 해석을 보이고, 데이터-시프트 및 환각 위험이 두드러지는 것으로 나타났다.
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.
연구 동기 및 목표
- LLM이 코드 구문(구문 트리(AST)와 표현식 역할)을 이해할 수 있는지 평가한다.
- LLM의 정적 동작 이해(CFG, CG, 데이터 의존성, 오염 분석, 포인터 분석)를 평가한다.
- LLM의 동적 동작 이해(동등 돌연변이 탐지, 불안정한 테스트에 대한 이해)를 조사한다.
- 프롬프트와 데이터 소스를 분석하여 코드 분석 작업의 신뢰성과 한계를 결정한다.
제안 방법
- 네 가지 최첨단 LLM(GPT-4, GPT-3.5, StarCoder, CodeLlama-13b-instruct)을 9개 작업에 걸쳐 평가한다.
- 구문 이해를 테스트하기 위한 작업 디자인(구문 트리(AST) 생성, 표현식 매칭).
- 정적 분석 능력 테스트(CFG, CG, 데이터 의존성, 오염 분석, 포인터 분석).
- 동적 행동 이해를 평가하기 위한 동등 돌연변이 탐지 및 불안정한 테스트 추론 테스트.
- curated 데이터셋(2,560 데이터 포인트, 151,633 LoC, 217 프로그램)와 다양한 언어(Python, Java, C, Solidity)를 사용한다.
- 프롬프트 기반 역할 및 지시 프롬프트를 사용하고 GPT 기반 도구를 통한 프롬프트 최적화를 수행하며, 출력은 AST 파서, 전문가 리뷰, 실측 도구(Tree-Sitter, Slither, Frama-C)와 대조 평가한다.
실험 결과
연구 질문
- RQ1RQ1: LLM이 코드 구문을 잘 이해할 수 있는가?
- RQ2RQ2: LLM이 코드의 정적 동작을 이해할 수 있는가?
- RQ3RQ3: LLM이 코드의 동적 동작을 이해할 수 있는가?
주요 결과
- GPT-4와 GPT-3.5는 코드 구문 이해에서 강한 성능을 보이며 AST 파서 역할을 할 수 있다.
- LLMs는 정적 분석에 부분적인 능력을 보이며, 초보 수준의 CFG 및 CG 생성과 데이터 흐름 같은 분석이 가능하다.
- LLMs는 동적 의미 작업(동등 돌연변이 탐지 및 불안정한 테스트 추론)에서 어려움을 겪는다.
- 프로젝트 간 성능 차이(data-shift)가 있으며 데이터 의존성 및 오염 분석에 대해 F1이 0에서 0.8까지 변동한다.
- 오픈 소스 모델(CodeLlama, StarCoder)은 이러한 작업에서 OpenAI 모델에 비해 성능이 떨어진다.
- LLMs는 구문적으로는 올바른 코드를 생성할 수 있지만 의미를 망상할 수 있어 SE 맥락에서 출력 검증이 필요하다는 점을 강조한다.
더 나은 연구,지금 바로 시작하세요
연구 설계부터 논문 작성까지, 연구 시간을 획기적으로 줄여보세요.
카드 등록 없음 · 무료 플랜 제공
이 리뷰는 AI가 만들고, 인간 에디터가 검토했습니다.