Skip to main content
QUICK REVIEW

[Paper Review] Lost in Translation: A Study of Bugs Introduced by Large Language Models while Translating Code

Rangeet Pan, Ali Reza Ibrahimzada|arXiv (Cornell University)|Aug 6, 2023
Natural Language Processing TechniquesComputer Science7 citations
TL;DR

This study investigates the reliability of large language models (LLMs) in translating code across five programming languages, revealing that LLMs produce correct translations in only 2.1% to 47.3% of cases. It identifies 15 distinct categories of translation bugs, compares LLM-based methods with traditional non-LLM techniques, and proposes a context-aware prompt-crafting strategy that improves translation accuracy by 5.5% on average.

ABSTRACT

Code translation aims to convert source code from one programming language (PL) to another. Given the promising abilities of large language models (LLMs) in code synthesis, researchers are exploring their potential to automate code translation. The prerequisite for advancing the state of LLM-based code translation is to understand their promises and limitations over existing techniques. To that end, we present a large-scale empirical study to investigate the ability of general LLMs and code LLMs for code translation across pairs of different languages, including C, C++, Go, Java, and Python. Our study, which involves the translation of 1,700 code samples from three benchmarks and two real-world projects, reveals that LLMs are yet to be reliably used to automate code translation -- with correct translations ranging from 2.1% to 47.3% for the studied LLMs. Further manual investigation of unsuccessful translations identifies 15 categories of translation bugs. We also compare LLM-based code translation with traditional non-LLM-based approaches. Our analysis shows that these two classes of techniques have their own strengths and weaknesses. Finally, insights from our study suggest that providing more context to LLMs during translation can help them produce better results. To that end, we propose a prompt-crafting approach based on the symptoms of erroneous translations; this improves the performance of LLM-based code translation by 5.5% on average. Our study is the first of its kind, in terms of scale and breadth, that provides insights into the current limitations of LLMs in code translation and opportunities for improving them. Our dataset -- consisting of 1,700 code samples in five PLs with 10K+ tests, 43K+ translated code, 1,748 manually labeled bugs, and 1,365 bug-fix pairs -- can help drive research in this area.

Motivation & Objective

  • To evaluate the effectiveness of general and code-specific LLMs in translating code across five programming languages (C, C++, Go, Java, Python).
  • To identify and categorize the root causes of translation failures introduced by LLMs in source code translation.
  • To compare LLM-based code translation with non-LLM-based approaches in terms of correctness and bug profiles.
  • To investigate whether providing contextual feedback about translation errors can improve LLM performance through iterative prompt engineering.
  • To release a comprehensive dataset of 1,700 code samples, 10,000+ test cases, 43,000+ translations, 1,748 labeled bugs, and 1,365 bug-fix pairs to support future research in LLM-based code translation.

Proposed method

  • Collected 1,700 executable code samples from three benchmarks and two real-world projects across five programming languages.
  • Used state-of-the-art general and code-specific LLMs to translate each code sample into multiple target languages.
  • Evaluated translation correctness using automated test suites provided in the datasets, with manual validation for edge cases.
  • Conducted manual analysis on 1,748 failed translations to identify and label 15 distinct categories of translation bugs.
  • Designed and evaluated a prompt-crafting technique that uses symptoms of prior errors to provide contextual feedback to LLMs during re-translation.
  • Compared LLM-based translation with non-LLM-based approaches (e.g., transpilers) to assess relative strengths and weaknesses in translation quality and error profiles.
Figure 1 . Vanilla prompting templates.
Figure 1 . Vanilla prompting templates.

Experimental results

Research questions

  • RQ1RQ1.1: How do state-of-the-art general and code LLMs perform in code translation across multiple programming languages?
  • RQ2RQ1.2: What are the outcomes of unsuccessful translations, and what types of errors do they exhibit?
  • RQ3RQ2.1: What are the underlying root causes (translation bugs) of failed LLM-based code translations?
  • RQ4RQ2.2: How prevalent are these bug categories in failed translations?
  • RQ5RQ2.3: How do translation bugs in real-world projects differ from those in synthetic benchmarks?
  • RQ6RQ3: How do non-LLM-based translation techniques compare in correctness and error profiles to LLM-based methods?
  • RQ7RQ4: To what extent can iterative prompt-crafting based on error symptoms improve LLM-based code translation performance?

Key findings

  • LLM-based code translation achieves correct functionality in only 2.1% to 47.3% of test cases across the studied models and language pairs.
  • A total of 15 distinct categories of translation bugs were identified, including semantic misinterpretations, incorrect type handling, and incorrect control flow structures.
  • Real-world projects exhibited more complex and diverse bug patterns compared to synthetic benchmarks, indicating that real code poses greater challenges for LLMs.
  • Non-LLM-based approaches (e.g., transpilers) outperformed LLMs in terms of correctness and introduced fewer semantic bugs, particularly in complex code constructs.
  • The proposed prompt-crafting technique—using symptoms of prior errors to guide re-translation—improved average translation accuracy by 5.5%.
  • The study’s dataset, comprising 1,700 code samples, 10,000+ test cases, 43,000+ translations, 1,748 labeled bugs, and 1,365 bug-fix pairs, is publicly available to support future research in LLM-based code translation.
Figure 2 . Outcome of code translations using subject LLMs.
Figure 2 . Outcome of code translations using subject LLMs.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.