arXiv:2610.28675cs.SEOct 2026

Manuscript Offprint

arXiv:2610.28675

Compilation Is Not Correctness: Scan-by-Scan Evaluation of LLM-Generated PLC Programs

Jinyun Chen, Juntao Hu, Haochen Li, Wentao Song, Ningbo Gu, Jianwei Niu, Qing Gao, Rui Wang

Jinyun Chen 1^{1}, Juntao Hu 2,∗^{2,*}, Haochen Li 1^{1}, Wentao Song 1^{1}, Ningbo Gu 2^{2}, Jianwei Niu 1^{1}, Qing Gao 1^{1}, Rui Wang 1^{1}

1^{1}Beihang University, Beijing, China

2^{2}Hangzhou Innovation Institute, Beihang University, Hangzhou, China

Programmable logic controllers (PLCs) automate industrial processes through repeated scans, each reading inputs, executing control logic, and updating outputs. Engineers typically write this logic in Structured Text (ST), a high-level textual language defined in IEC 61131-3. Large language models (LLMs) can now generate ST from natural-language requirements, yet compilation success and checks on selected properties or sampled scans can leave behavioral errors undetected. To close this evaluation gap, we introduce CycleBench, a benchmark of 301 ST tasks with behavioral requirements, public interfaces, reference programs, and executable scenarios. Its runtime executes each generated program and its reference under aligned inputs, initialization, and logical time, comparing their outputs after every scan. Across eight LLMs and baseline generation methods, execution pass rate trails compilation pass rate by 11.92 percentage points; observed failures include output-update, arithmetic, and timing errors. On fixed traces of programs directly generated by five LLMs, checking outputs only at every fifth scan misses 21.66% of the 157 failures detected by per-scan comparison; across sampling phases, the missed-failure rate ranges from 12.10% to 28.03%. These misses stem from transient output discrepancies, whose detection depends on the sampling phase. Building on this evaluation, we propose CycleGen, which generates multiple candidate ST programs, repairs their compilation errors with bounded compiler feedback, and selects one using runtime self-tests generated in a separate model context. CycleGen improves the execution pass rate over direct generation by 8.68 percentage points. Component ablations distinguish repair and self-test selection; candidate-count analysis shows diminishing returns, with no execution-pass-rate improvement beyond five candidates in our experiments despite 38.8% higher token consumption at eight.

CCS Concepts: • Software and its engineering → Software testing and debugging; Automatic programming.

Additional Key Words and Phrases: Structured Text, programmable logic controllers, large language models, LLMs for software engineering, code generation, benchmarking

1 Introduction

Programmable logic controllers (PLCs) serve as core control devices in industrial manufacturing, automating industrial processes in repeated scans: each scan reads inputs, executes control logic, and updates outputs. Structured Text (ST) [15], a high-level textual language defined by IEC 61131-3, is widely used for PLC programming. ST's Pascal-like syntax supports control algorithms, computation, and data processing; function-block instances retain state across calls [39]. ST is also a target of model-based code generation: Simulink PLC Coder generates ST from Simulink models, Stateflow charts, and MATLAB functions [36]. With advances in large language models (LLMs), generating code from natural-language requirements has become an active research direction [7]. This progress has also motivated research on ST code generation for PLCs. However, reliably translating control requirements into behaviorally correct ST programs remains an important challenge [23, 37].

To address this challenge, existing LLM-based PLC generation methods incorporate compilation, formal verification, or runtime testing into their workflows. LLM4PLC [12] and Agents4PLC [29] use formal-verification feedback, AutoPLC [40] repairs code using vendor-compiler diagnostics, and SemaPLC combines specification, compilation, and runtime checks [38]. These mechanisms provide

∗^{*}Corresponding author.

different kinds of evidence: compilation establishes that a program builds, property checking addresses the encoded properties, and runtime testing checks behavior on the executions and scans observed. However, differences in task sets and acceptance criteria make their reported success rates difficult to compare directly. Moreover, agreement at selected scans can conceal incorrect intermediate outputs in stateful PLC programs. This motivates a common benchmark that evaluates generated programs on shared tasks and checks their outputs against the same behavioral requirements after every scan.

Specifically, Fig. 1 illustrates how compilation and checks on selected properties or scans can miss incorrect intermediate outputs. On a rising edge, a shift register copies D0 into Q0 and the previous Q0-Q2 into Q1-Q3; set and reset override shifting. The reference assigns outputs in reverse order to preserve old values. A program generated directly by GPT-4o assigns them forward, starting with Q0 := D0, so the new value propagates through all four bits. After set yields 1111 at scan 11, a shift with D0= 0 produces 0000 instead of 0111 at scan 12 (bits ordered Q0-Q3); reset at scan 14 restores agreement. The program compiles, completes execution, and ends with the reference's outputs, yet scans 12–13 differ. A specification of the shift relation could also detect this error: the verdict depends on which behavior is checked and when.

Prompt: Implement a four-stage shift register.

Figure

Fig. 1. A shift-register failure. The reference preserves old bits; forward assignments propagate a new value. Panel A illustrates a property-checking pipeline, not a measured model-checker result. Panel B shows set, shift, hold, and reset; reset conceals intermediate disagreement. Bits are ordered Q0–Q3.

To measure these differences consistently, we introduce CycleBench: 301 ST tasks with reviewed public specifications, hidden references, and 684 scenarios spanning 61,424 scans. A separate evaluator compares every declared output after each scan under aligned inputs, initialization, and logical time. Across eight LLMs and four baseline configurations, 83.99% of 9,632 outcomes compile but only 72.07% pass execution, a gap of 11.92 percentage points. On fixed traces of 157 Direct behavioral failures from five models, final-scan checking misses 98 failures; checking every fifth scan at phase zero misses 34, even with scenario endpoints retained. We then investigate whether runtime feedback can improve ST code generation when the generator does not have access to hidden references or evaluation scenarios. Therefore, we propose CycleGen, which adapts generated-test selection and feedback-guided repair [6, 8]. It generates multiple candidates, repairs compilation failures, and selects one using runtime self-tests authored beforehand in a separate model context. The tests are withheld from code generation, and the reference evaluator stays hidden. CycleGen raises execution pass rate from Direct's 74.63% to 83.31%; controlled-pool ablations and candidate-count analyses separate component effects and inference cost.

In particular, this work makes the following contributions:

• CycleBench. To our knowledge, the first benchmark for LLM-based Structured Text generation with comprehensive per-scan behavioral evaluation against hidden references, comprising 301 tasks with reviewed specifications.

• CycleGen. A framework combining multiple candidates, compiler repair, and runtime self-tests, with shared-pool component comparisons and analyses of candidate-count gains and inference cost.

• Empirical evidence. An eight-model comparison of Direct and three adaptations (9,632 outcomes) quantifying the compile-execution gap, plus a five-model fixed-trace analysis showing how transient discrepancies and sampling phase hide behavioral failures.

References (17)