Beyond Functional Correctness: A Knowledge-Enhanced Iterative Framework for Generating Criteria-Compliant Code

While Large Language Models (LLMs) show great potential in code generation, their application in safety-critical domains is strictly constrained by mandatory standards like MISRA C. Our empirical study confirms this critical gap: state-of-the-art LLMs universally fail to comply with MISRA C criteria, and naïve self-refinement often leads to a “refinement-worsens-violation” dilemma. To address the dual challenge, we propose HI-MISRA, a Hybrid Iterative Refinement Framework. HI-MISRA tackles these challenges through two key innovations: (1) Knowledge-Enhanced Prioritized Refinement, which first applies deterministic fixes for simple violations, then guides the LLM to refine severity-prioritized batches of complex violations by injecting dynamic knowledge; and (2) Iterative Refinement with Regression Prevention, which employs a three-stage “compilation-functionality-compliance” verification pipeline to ensure that each modification yields a net improvement, while a dynamic suspension strategy prevents the refinement from getting stuck in ineffective loops. Experiments across LLMs, including GPT-5, Gemini-2.5-Flash, Claude-3.7-Sonnet, and DeepSeek-V3.1, demonstrate the superior performance of HI-MISRA. For instance, HI-MISRA achieves a 92.5% triple-pass rate (compilation, functionality, compliance) based on GPT-5, far surpassing the baseline (62.0%) at a similar cost and outperforming the best existing method (78.5% with higher costs). Experimental results offer a practical pathway for the deployment of LLMs in the safety-critical domain.

Authors

Institutions

Publication Details

Journal
ACM Transactions on Software Engineering and Methodology
Published
2026-05-23
DOI
https://doi.org/10.1145/3817057
Primary Topic
Topic Modeling
Type
article
Field-Weighted Citation Impact
0.00
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

Beyond Functional Correctness: A Knowledge-Enhanced Iterative Framework for Generating Criteria-Compliant Code

J Zhang, Y Zhang, J Liu, Siyu Zhang et al.
ACM Transactions on Software Engineering and Methodology
Topic Modeling
article

Beyond Functional Correctness: A Knowledge-Enhanced Iterative Framework for Generating Criteria-Compliant Code

J Zhang, Y Zhang, J Liu, Siyu Zhang, Wei Dong, Shangwen Wang
article en

Abstract

While Large Language Models (LLMs) show great potential in code generation, their application in safety-critical domains is strictly constrained by mandatory standards like MISRA C. Our empirical study confirms this critical gap: state-of-the-art LLMs universally fail to comply with MISRA C criteria, and naïve self-refinement often leads to a “refinement-worsens-violation” dilemma. To address the dual challenge, we propose HI-MISRA, a Hybrid Iterative Refinement Framework. HI-MISRA tackles these challenges through two key innovations: (1) Knowledge-Enhanced Prioritized Refinement, which first applies deterministic fixes for simple violations, then guides the LLM to refine severity-prioritized batches of complex violations by injecting dynamic knowledge; and (2) Iterative Refinement with Regression Prevention, which employs a three-stage “compilation-functionality-compliance” verification pipeline to ensure that each modification yields a net improvement, while a dynamic suspension strategy prevents the refinement from getting stuck in ineffective loops. Experiments across LLMs, including GPT-5, Gemini-2.5-Flash, Claude-3.7-Sonnet, and DeepSeek-V3.1, demonstrate the superior performance of HI-MISRA. For instance, HI-MISRA achieves a 92.5% triple-pass rate (compilation, functionality, compliance) based on GPT-5, far surpassing the baseline (62.0%) at a similar cost and outperforming the best existing method (78.5% with higher costs). Experimental results offer a practical pathway for the deployment of LLMs in the safety-critical domain.

ACM Transactions on Software Engineering and Methodology
National University of Defense Technology (CN)
Peace, Justice and strong institutions
Openalex Percentile: Top 3%
Topic Modeling
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.