# An Empirical Study of the Code Generation of Safety-Critical Software Using LLMs
## 1 Introduction  
The software development and verification in safety-critical domains such as nuclear energy, aviation, the automotive industry, and rail transportation have been hot topics of interest in both academia and industry. Enhancing the trustworthiness and development efficiency of safety-critical software is a challenging task. Model-driven and formal methods have emerged as mainstream techniques to address this challenge [1, 2]. In the industry, model-driven code generation tools such as SCADE software have been widely applied in domains such as nuclear energy, aviation, the automotive industry, and rail transportation [3, 4, 5]. However, as dedicated tools for safety software development, they also face issues such as steep learning curves, usability challenges, and high costs.  
Since 2022, Generative pre-training large language models (LLMs) technology, represented by ChatGPT, has attracted attention in various fields [6]. Due to its powerful natural language understanding and content generation capabilities, LLMs technologyhas great potential in code generation. Microsoft conducted detailed testing and research on code generation using LLMs, specifically GPT-4, in some general algorithms, HTML game development, and graphical user interface programming [7]. So far, code generation research based on LLMs is still in the preliminary exploration stage and lacks practical cases from industrial domains. The current research [8; 9] mainly focus on the ability of code LLMs to handle basic programming elements (such as integers and strings) with general-purpose algorithms. However, industrial software containing domain-specific features is more complex than basic algorithms and requires a different approach to prompt engineering. Especially, there is no relevant research on code generation using LLMs for safety-critical software in domains such as nuclear energy and the automotive industry. For a long time, the development of safety-critical software was difficult and long-term work, which has been faced with low development efficiency, verification difficulties, a lack of experienced personnel, and other problems. The demand for new development tools is very urgent. LLMs can be significant for safety-critical development if they can significantly improve development efficiency while ensuring good quality. This paper explores the application of LLMs technology in safety-critical software development, taking into consideration the practical requirements in domains such as nuclear energy and the automotive industry.  
The contributions of this study are as follows:  
* A first ever study that demonstrates that GPT-based large language models can generate safety-critical software code that meets the requirements of the safety-critical industry domain.
* This study compares different approaches and methods for code generation, including overall requirement-based code generation, specific requirement-based code generation, and augmented prompt-based code generation. It proposes a new augmented prompt method called Prompt-FDC, which is suitable for generating safety-critical software code.
* This research presents a new software development process and lifecycle V model based on LLMs code generation for safety-critical software.
* This study provides two specific examples of safety-critical software from the industrial domain, which can be used by other researchers to explore further code generation methods.