Predicting Program Exit Code with LLMs and Programming Language Semantics
Large language models (LLMs) have shown proficiency in various software engineering tasks, such as code generation and translation. However, a key limitation in their performance may be their understanding of programming-language semantics. Only one other paper has supplied explicit operational semantics to test whether LLMs reason from formal rules rather than surface patterns. Even when explicit semantics are provided, it remains unclear whether LLMs apply those rules or lean on priors learned during pre-training instead. We study if LLMs lean on priors or given semantics with a novel task–Program Executability Prediction (PredExe)–that asks models to predict whether a program is semantically valid or invalid (and, if invalid, which formal rule it violates) given the program’s syntax and operational semantics. Because PredExe requires both valid and invalid programs, we build a dataset with systematically generated invalid transformations derived from valid programs. We evaluate open-source coding LLMs under two semantic formalisms and two semantic shifts across Human-Written, LLM-Translated, and Fuzzer-Generated program splits. Our findings show that LLMs lean on pre-training priors rather than systematically applying the supplied rules, performing especially poorly on modified semantics and degrading further as program complexity increases on LLM-Translated and Fuzzer-Generated programs.