Abstract
Modern compilers excel at catching syntax errors but often fail to detect semantic anomalies—code that is syntactically correct but logically flawed. We present MP-CodeCheck (MPCC), a self-supervised system that identifies anomalous logical expressions by learning from billions of lines of existing software. MPCC utilizes a novel structural representation of code and an iterative, human-guided learning loop to achieve high precision. Our evaluation shows that MPCC is significantly faster and more memory-efficient than current state-of-the-art tools, successfully identifying real-world bugs in major open-source projects.
Introduction: Catching the Logic Bugs that Compilers Miss
Software engineers spend upwards of 50% of their time debugging. While modern compilers are excellent at catching syntax errors, they are often blind to semantic anomalies—code that is technically "legal" but logically nonsensical. For example, the C++ expression if (NULL == x == NULL) compiles without error but likely does not reflect the programmer's intent due to left-to-right evaluation. Such "legal but malformed" code frequently leads to crashes and security vulnerabilities. MPCC automates the detection of these brittle logical patterns across massive codebases.
Methods: The MP-CodeCheck Pipeline
MPCC employs a multi-stage pipeline for training and inference, centered on structural analysis rather than raw text.
- Novel Code Representations: MPCC decomposes logic into Basic Expression Blocks (simple predicates like
x < 5) and Complex Expression Blocks (compositions likemin < id && id < max). By normalizing these blocks to remove specific variable names, the system recognizes logical structures regardless of identifier naming. - Iterative Self-Supervision: Trained on over two billion lines of "semi-trusted" code, MPCC incorporates a critical human-guided feedback loop. Early models exhibited high false-positive rates (~90%); by allowing experts to refine heuristics based on model outputs, the system "evolved" to be significantly more precise.
- Anomaly Scoring: During inference, target code is compared against a knowledge base of "nominal" patterns. Expressions that are rare or structurally unique receive high complexity scores and are flagged for manual review.
Key Insights: Normalization and Collaboration
The core innovation of MPCC lies in its approach to code abstraction. By stripping away specific identifiers, the system focuses on the underlying logic.
Furthermore, the paper demonstrates that "pure" self-supervision is often insufficient for programming language nuances. The iterative refinement process resulted in a 3x reduction in false positives, proving that expert-guided heuristics can significantly boost machine learning performance in specialized domains.
Evaluation and Results
MPCC was trained on a corpus of 6,000 GitHub repositories (approx. 1.1 billion lines of C/C++ code) and evaluated against 10 diverse projects, including git, curl, and qemu.
- Efficiency: MPCC represents a major performance leap over the state-of-the-art ControlFlag. It completed training in 54 minutes (vs. 1,658 minutes) and required only 0.31 GB of storage (vs. 15.5 GB).
- Accuracy: The system maintained an average false positive rate of ~31%, a substantial improvement over unrefined models.
- Real-World Impact: MPCC identified a sequence of problematic bitwise operations in the
QEMUrepository. Maintainers agreed with the findings and accepted a proposal to rewrite the logic for better clarity.
Limitations and Future Work
Despite its success, MPCC faces challenges with "semi-trusted" data; if bad patterns are common enough in training sets, the model may learn them as nominal. Additionally, a 31% false positive rate still necessitates manual triage. Future work will focus on expanding support to other programming languages and further automating the heuristic refinement process.
Summary updated