C language-oriented compiling error automatic repair method and system

By combining the finely tuned CodeT5 model with UniXcoder and the GCC compiler, and utilizing multi-granularity mask templates and normalized edit distance, the problems of meaningless patches and semantic changes in existing technologies are solved, achieving efficient and accurate automatic repair of compilation errors.

CN121166520APending Publication Date: 2025-12-19WUHAN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511226133.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-29
Publication Date
2025-12-19

AI Technical Summary

Technical Problem

Existing deep learning-based automatic compilation error repair methods generate a large number of meaningless patches and tend to over-modify the code, leading to changes in the semantics of the original program and making it difficult to effectively handle complex compilation errors.

Method used

A fine-tuned CodeT5 model was used for initial repairs. Combined with the GCC compiler and the pre-trained code model UniXcoder, high-confidence candidate repair patches were selected through multi-granularity mask templates and normalized edit distance to ensure the accuracy and semantic preservation of the repair process.

Benefits of technology

It reduces meaningless operations, lowers the risk of introducing semantic biases during the repair process, improves the efficiency and accuracy of compilation error repair, and reduces the burden of subsequent fine-grained repair.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121166520A_ABST
    Figure CN121166520A_ABST
Patent Text Reader

Abstract

The invention provides a C language-oriented compiling error automatic repair method and system. The method comprises the following steps of: performing preliminary repair on an error program by using a fine-tuned CodeT5 model; calling a GCC compiler to process the preliminarily repaired program, and outputting a to-be-repaired error code line, an error position and error diagnosis information of the to-be-repaired error code line; according to the error position and the error diagnosis information, performing mask processing on the error code line to be repaired by using a preset mask template; inputting the error code line to be repaired after mask processing into a pre-training code model UniXcoder, and outputting a plurality of candidate repair patches and probability scores thereof; a token-based normalized editing distance of the candidate repair patches is calculated, a comprehensive evaluation score is calculated in combination with the probability scores of the candidate repair patches, and k candidate repair patches with the highest score are screened out; and repairing the error code line to be repaired by using the screened k candidate repair patches.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of information technology, specifically relating to an automatic compilation error repair method and system for C language. Background Technology

[0002] In software development, code compilability is a fundamental prerequisite for ensuring the normal operation of a program. Incompilable code not only cannot be directly applied to the development process but also hinders the implementation of software quality assurance techniques (such as program analysis), severely restricting the productivity of software development and quality assurance. The process of converting incompilable code into a compilable state (i.e., compilability recovery) is currently mainly done manually by programmers. This repair method not only relies on human expertise but also leads to a significant waste of human and time resources. Therefore, researching automated compilability recovery techniques is of great importance, as it can assist developers in efficiently and accurately locating and resolving compilation errors in the code.

[0003] While existing automated error correction technologies have made some progress, they still face significant challenges. Syntax analysis-based methods are highly rule-dependent and struggle to handle complex compilation errors. In complex real-world projects, these methods are often used to generate error messages to help developers locate and manually correct errors. In recent years, deep learning-based error correction methods have gradually become a research hotspot. However, these methods generate numerous seemingly correct but ultimately meaningless patches and operations during the correction process, and tend to over-modify the code, potentially significantly altering the original program's semantics. Summary of the Invention

[0004] To overcome the shortcomings of existing deep learning-based repair methods, which generate numerous seemingly plausible patches and meaningless operations, and tend to over-modify code, potentially significantly altering the semantics of the original program, this invention provides an automatic compilation error repair method and system for C language. By leveraging the powerful learning and code generation capabilities of the CodeT5 model, it performs initial repairs on compilation errors, reducing the burden of subsequent finer-grained error repair. The design incorporates multi-granularity mask templates to comprehensively address various error types at different granularities. By combining probability scores assigned by the pre-trained code model and normalized edit distance, it ensures that candidate repair patches not only have high confidence but also reduce meaningless operations, thereby lowering the risk of introducing semantic bias during the repair process.

[0005] According to one aspect of the present invention, an automatic compilation error repair method for the C language is provided, comprising:

[0006] The finely tuned CodeT5 model was used to perform initial repairs on the faulty program;

[0007] The program is processed by the GCC compiler after initial repair, and the lines of code with errors to be repaired, along with their locations and diagnostic information, are output.

[0008] Based on the error location and error diagnosis information, the line of code with the error to be repaired is masked using a preset mask template;

[0009] Input the masked error code line to be repaired into the pre-trained code model UniXcoder, and output several candidate repair patches and their probability scores;

[0010] Calculate the normalized edit distance of candidate patch based on token, combine it with the probability score of candidate patch to calculate a comprehensive evaluation score, and select the k candidate patches with the highest scores.

[0011] The selected k candidate patches are used to fix the lines of code with errors that need to be fixed.

[0012] As a further technical solution, the fine-tuning process of the CodeT5 model is as follows:

[0013] Collect an experience dataset of compilation error repair, construct a fine-tuning dataset in the form of <error code, correct code>, and fine-tune the CodeT5 model.

[0014] As a further technical solution, there are six mask templates, including: masking only the token at the error location; masking the code at the error location and after it; masking the code at the error location and before it; keeping only the last token; keeping only the first token; and masking the entire line of error code.

[0015] As a further technical solution, the input structure of the pre-trained code model is as follows:

[0016] <Previous context><Commented line of code with error><Mask line><Back context>

[0017] Here, <previous context> and <postvous context> represent the code content before and after the error code line, respectively, providing contextual semantic information; <commented error code line> is in the format " / / buggy line:error code line code"; and <mask line> is the code line obtained by masking the error code line.

[0018] As a further technical solution, the formula for calculating the normalized edit distance of candidate fix patches based on tokens is as follows:

[0019]

[0020] in, This represents the token-based normalized edit distance between strings s1 and s2. This represents the edit distance between strings s1 and s2; This indicates the number of tokens in string s.

[0021] As a further technical solution, the comprehensive evaluation score is the weighted sum of the probability scores of candidate repair patches and the normalized edit distance.

[0022] As a further technical solution, the process of fixing the error code is as follows:

[0023] Replace the line of code with the selected k candidate patches with the line of code that is to be repaired, and call the GCC compiler to process it. If the error position moves to the end of the current line of code, it is considered to be repaired successfully. The candidate patch with the highest comprehensive evaluation score among the successful repair patches is retained as the final repair patch. If none of the selected k candidate patches can repair the line of code, it is considered that the line of code cannot be repaired.

[0024] As a further technical solution, after the initial repair of the faulty program, the faulty code line to be repaired is located according to the error location of the faulty code line to be repaired output by the GCC compiler, and repaired in sequence. After the current faulty code line to be repaired is repaired, the GCC compiler is called again to locate the next faulty code line to be repaired and repair it, until the GCC compiler can no longer locate the next faulty code line to be repaired.

[0025] According to another aspect of this specification, an automatic compilation error repair system for the C language is provided, comprising:

[0026] The initial repair module is used to perform initial repairs on faulty programs using the finely tuned CodeT5 model;

[0027] The error location and diagnosis module is used to call the GCC compiler to process the program after initial repair, and output the line of code with the error to be repaired, as well as the error location and error diagnosis information;

[0028] The mask generation module uses a preset mask template to mask the lines of code with errors to be fixed, based on the error location and error diagnosis information.

[0029] The candidate patch generation module takes the masked error code line to be repaired and combines it with the context input to the pre-trained code model UniXcoder, and outputs several candidate patches and their probability scores.

[0030] The candidate patch filtering module calculates the normalized edit distance of the candidate patches based on the token, combines the probability scores of the candidate patches to calculate a comprehensive evaluation score, and filters out the k candidate patches with the highest scores.

[0031] Compile the error repair module and apply the selected k candidate patches to fix the lines of code with errors.

[0032] According to another aspect of this specification, an electronic device is provided, including a memory and a processor, the memory storing program instructions executed by the processor, the processor invoking the program instructions to execute an automatic compilation error repair method for the C language.

[0033] According to another aspect of this specification, a non-transitory computer-readable storage medium is provided, the non-transitory computer-readable storage medium storing computer instructions that cause the computer to execute a C language-oriented automatic compilation error repair method.

[0034] Compared with existing technologies, the beneficial effects of this invention are as follows: This invention utilizes the powerful learning and code generation capabilities of the CodeT5 model to perform preliminary repairs on compilation errors, reducing the burden of subsequent finer-grained compilation error repairs; it designs mask templates that consider multiple granularities to more comprehensively address various error types at different granularities, and uses existing error line tokens to narrow the search space for generating effective patches; by combining the probability scores assigned by the pre-trained code model and the normalized edit distance, it can ensure that candidate repair patches not only have high confidence, but also maintain similarity to the original code in structure and content, reducing meaningless operations and thus reducing the risk of introducing semantic biases during the repair process. Attached Figure Description

[0035] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0036] Figure 1 A flowchart illustrating an automatic compilation error repair method for C language provided in an embodiment of the present invention;

[0037] Figure 2 A flowchart of an automatic compilation error repair method for C language according to an embodiment of the present invention;

[0038] Figure 3 This is an example diagram of a C language program containing compilation errors in an embodiment of the present invention;

[0039] Figure 4 This is an example diagram of compilation error diagnosis information output by the GCC compiler in an embodiment of the present invention;

[0040] Figure 5This is a schematic diagram of the mask rows obtained using a mask template in an embodiment of the present invention;

[0041] Figure 6 This is a schematic diagram illustrating the generation of candidate repair patches by a pre-trained code model in an embodiment of the present invention;

[0042] Figure 7 This is a schematic diagram of the candidate repair patch selection in an embodiment of the present invention;

[0043] Figure 8 A schematic diagram of the structure of an automatic compilation error repair system for C language provided in an embodiment of the present invention;

[0044] Figure 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation

[0045] It should be noted that:

[0046] The terms “comprising” and “having”, and any variations thereof, in the specification, claims, and accompanying drawings of this invention are intended to cover a non-exclusive inclusion, such as a process, method, system, product, or apparatus that includes a series of steps or units, not necessarily limited to those explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0047] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices. The flowcharts shown in the accompanying drawings are merely illustrative and do not necessarily include all content and operations / steps, nor do they necessarily have to be performed in the described order. For example, some operations / steps can be decomposed, while others can be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.

[0048] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention. In addition, the technical features of the various embodiments or individual embodiments provided by the present invention can be arbitrarily combined to form new technical solutions. Such combinations are not bound by the order of steps and / or structural composition patterns, but must be based on the ability of those skilled in the art to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed by the present invention.

[0049] like Figure 1 , Figure 2 As shown, an automatic compilation error repair method for the C language includes:

[0050] Step 1: Use the finely tuned CodeT5 model to perform initial repairs on the faulty program;

[0051] Step 2: Call the GCC compiler (GNU Compiler Collection) to process the initially repaired program, and output the line of code with the error to be repaired, its error location, and error diagnosis information;

[0052] Step 3: Based on the error location and error diagnosis information, use a preset mask template to mask the lines of code with errors to be repaired;

[0053] Step 4: Combine the masked error code lines to be repaired with the context input into the pre-trained code model UniXcoder, and output several candidate repair patches and their probability scores.

[0054] Step 5: Calculate the normalized edit distance of the candidate patch based on the token, combine it with the probability score of the candidate patch to calculate the comprehensive evaluation score, and select the k candidate patches with the highest scores.

[0055] Step 6: Apply the selected k candidate patches to fix the lines of code with errors.

[0056] Furthermore, in step 1, the fine-tuning process of the CodeT5 model is as follows:

[0057] Collect an experience dataset of compilation error repair, construct a fine-tuning dataset in the form of <error code, correct code>, and fine-tune the CodeT5 model.

[0058] As a specific implementation method, firstly, a large number of <error codes, correct codes> are collected to fine-tune the CodeT5 model, allowing it to learn how to fix compilation errors. The aim is to leverage the powerful learning and code generation capabilities of the CodeT5 model to perform initial repairs on compilation errors in faulty programs. Considering the diversity of compilation errors, a single fine-tuning cannot solve all problems, so more granular repairs are needed.

[0059] CodeT5 is a pre-trained code generation model designed specifically for code understanding and generation tasks. For details, please refer to the paper published at EMNLP 2021: "CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation".

[0060] As a specific implementation method, in step 2, the GCC compiler is called to locate errors in the program, thereby obtaining potential error locations (line numbers, column numbers) and related error diagnosis information to guide the subsequent code repair process. Figure 3 Line 8 of the program contains a compilation error, which writes the multiplication operator "*" as "x". Figure 4 This is the error diagnosis information given by the GCC compiler after compiling the program, which includes natural language prompts and the location of the error. In this example, the compiler successfully located the error location (although the prompt given is not the root cause of the error).

[0061] Furthermore, in step 3, there are six types of mask templates, including:

[0062] 1) Only mask the token at the error location, such as before_code. <mask>after_code;

[0063] 2) Cover up the error location and the code that follows it, such as before_code <mask>;

[0064] 3) Cover up the error location and the code preceding it, such as... <mask>after_code;

[0065] 4) Only keep the last token, in the form of: <mask>last_token;

[0066] 5) Only keep the first token, in the form of first_token <mask>;

[0067] 6) Cover up the entire line of error code, like this: <mask>.

[0068] As a specific implementation method, based on the error diagnosis information reported by the compiler, potential erroneous segments in the code lines are masked (i.e., masking processing). Mask lines are generated according to six preset templates. Figure 3 The line of code with the error to be fixed (line 8) is processed using the six template masks mentioned above to obtain the masked line. Figure 5 As shown. The six preset templates serve two purposes: they handle various error types at different granularities for comprehensive repair, and they utilize existing error code line tokens to narrow down the search space for generating effective patches.

[0069] Furthermore, in step 4, the masked code is input into the pre-trained code model UniXcoder. The model predicts the potentially correct replacement code based on the context, thereby generating multiple candidate fix patches for the erroneous lines of code, such as... Figure 5 As shown. The input structure of the pre-trained code model is as follows:

[0070] <Previous context><Commented line of code with error><Mask line><Back context>

[0071] Here, <pre-context> and <post-context> represent the code content before and after the erroneous code line, respectively, and are used to provide contextual semantic information; <annotated erroneous code line> is in the format " / / buggy line: erroneous code line code", in order to preserve the original erroneous code line information for the model to refer to; <mask line> is the code line obtained by masking the potential error positions in the erroneous code line, which aims to guide the model to generate targeted repair content.

[0072] The masked code is fed into the pre-trained code model UniXcoder to predict the correct replacement code, thereby generating multiple candidate patch fixes for the erroneous lines of code to be fixed.

[0073] Furthermore, in step 5, the formula for calculating the normalized edit distance of the candidate repair patch based on the token is as follows:

[0074]

[0075] in, This represents the token-based normalized edit distance between strings s1 and s2. This represents the edit distance between strings s1 and s2; This indicates the number of tokens in string s.

[0076] Specifically, Levenshtein distance (LD) refers to the minimum number of editing operations required to transform string s1 into string s2. Editing operations include inserting a character, deleting a character, or replacing an original character with another character. LD quantitatively measures the similarity between s1 and s2. After normalization, its value ranges from 0 to 1 and can be regarded as the percentage of similarity between s1 and s2. When the NLD value is 0, it means that s1 and s2 are completely different; conversely, when the NLD value is 1, it means that s1 and s2 are completely identical.

[0077] However, traditional edit distance measures the difference between strings based on characters. In code, the meaningful unit is the token, which carries specific semantics and functionality. This contrasts with character-based Normalized Edit Distance (NLD). char In comparison, token-based normalized edit distance (NLD) token It has significant advantages when dealing with programming languages. Therefore, this invention employs NLD in the patch selection process. token .

[0078] Furthermore, in step 5, the comprehensive evaluation score is the weighted sum of the probability scores of candidate repair patches and the normalized edit distance, calculated using the following formula:

[0079]

[0080] Where F represents the overall evaluation score; score represents the final score; and α represents the weighting coefficient.

[0081] As a specific implementation method, all candidate patches are comprehensively evaluated based on the probability score assigned to each candidate patch by the UniXcoder model and the normalized Levenshtein distance (NLD) between the patch and the original erroneous code line, and the k patches with the highest scores are selected. By combining the probability score assigned by the model and the normalized edit distance, it can be ensured that the selected patches not only have high confidence in the model prediction, but also maintain similarity to the original code in structure and content, thereby reducing the risk of introducing semantic bias during the repair process.

[0082] As a preferred implementation, special handling can be applied to syntax errors (a subset of compilation errors) when selecting candidate patch repairs. In some cases, the parser can determine whether the token at the error location is the expected token and provide the expected token(s) for that location. When the parser identifies an unexpected token at the error location, it considers a syntax error to have occurred. The expected token(s) provided by the parser can be added to the error location as an additional patch.

[0083] Furthermore, in step 6, the process of fixing the error code is as follows:

[0084] The selected k candidate repair patches are used to replace the lines of code in the program that are not yet repaired after the initial repair. The GCC compiler is then called to process the repair. If the error position moves to the end of the current line, the repair is considered successful, and the candidate repair patch with the highest overall evaluation score is retained as the final repair patch. If none of the selected k candidate repair patches can repair the error, the error is considered unrepairable, and the remaining errors are then processed.

[0085] The selected Top-k candidate patches are used to fix the error code. Since the six mask templates designed in step 2 may cause changes to the entire line of code with the error, errors within the same line may all be fixed with a single patch application. If all candidate patches fail to fix the error, it is determined that the error cannot be resolved using the current method.

[0086] Furthermore, in this invention, after the initial repair of the erroneous program, the error line to be repaired is located according to the error position of the error line to be repaired output by the GCC compiler, and repaired in sequence. After the current error line to be repaired is repaired, the GCC compiler is called again to locate the next error line to be repaired and repair it, until the GCC compiler can no longer locate the next error line to be repaired.

[0087] The implementation of the various embodiments of this invention is based on programmed processing through a system with processor functionality. Therefore, in practical engineering, the technical solutions and functions of the various embodiments of this invention are encapsulated into various modules. Based on this reality, and building upon the above embodiments, the embodiments of this invention provide an automatic compilation error repair system for the C language, which is used to execute an automatic compilation error repair method for the C language from the above method embodiments.

[0088] See Figure 8 The system includes:

[0089] The code is divided into four modules: Preliminary Repair Module (PCM), Error Location and Diagnosis Module (PCD), and Compilation Module. PCM uses a fine-tuned CodeT5 model to perform initial repairs on the erroneous code. The PCD module calls the GCC compiler to process the initially repaired code, outputting the line of code to be repaired, its location, and diagnostic information. The Compilation Module masks the line of code to be repaired using a pre-defined mask template based on the error location and diagnostic information. The Candidate Patch Generation Module takes the masked line of code and its context, inputs it into the pre-trained UniXcoder code model, and outputs several candidate patches and their probability scores. The Candidate Patch Selection Module calculates the token-based normalized edit distance of each candidate patch, combines it with their probability scores to calculate a comprehensive evaluation score, and selects the k highest-scoring candidate patches. Finally, the Compilation Error Repair Module applies the selected k candidate patches to repair the line of code to be repaired.

[0090] It should be noted that the system embodiments provided by the present invention are used not only to implement the methods in the above method embodiments, but also to implement the methods in other method embodiments provided by the present invention. The only difference is that corresponding functional modules are set. The principle is basically the same as that of the above system embodiments provided by the present invention. As long as those skilled in the art can improve the modules in the above system embodiments by referring to the specific technical solutions in other method embodiments and combining technical features to obtain corresponding technical means and technical solutions composed of these technical means, on the basis of the above system embodiments, and on the premise of ensuring the practicality of the technical solutions, they can obtain corresponding system-like embodiments for implementing the methods in other method-like embodiments.

[0091] The method in this embodiment of the invention is implemented using an electronic device; therefore, it is necessary to introduce the relevant electronic device. For this purpose, embodiments of the present invention provide an electronic device, such as... Figure 9 As shown, the electronic device includes: at least one processor, a communication interface, at least one memory, and a communication bus, wherein the at least one processor, the communication interface, and the at least one memory communicate with each other via the communication bus. The at least one processor invokes logical instructions stored in the at least one memory to execute all or part of the steps of the methods provided in the foregoing method embodiments.

[0092] Furthermore, when the logical instructions in at least one of the aforementioned memories are implemented as software functional units and sold or used as independent products, they are stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a part of the technical solution, is embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (a personal computer, server, or network device) to execute all or part of the steps of the methods described in the various method embodiments of the present invention. The aforementioned storage medium includes: USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks—various media for storing program code.

[0093] The system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, located in one place, or distributed across multiple network units. The purpose of this embodiment is achieved by selecting some or all of the modules according to actual needs. Those skilled in the art will understand and implement this without any inventive effort.

[0094] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0095] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0096] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0097] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0098] Based on the same technical concept as the foregoing embodiments, the present invention provides a non-transitory computer-readable storage medium that stores computer instructions that cause the computer to execute an automatic compilation error repair method for the C language.

[0099] In summary, the overall process of the automatic compilation error repair method in this invention is as follows: First, the program containing compilation errors is input into a fine-tuned CodeT5 model to obtain preliminary repair results. Next, for a single error location, the compiler is used to locate the error in the program, and based on the error diagnosis information provided by the compiler, potential error segments in the erroneous code lines are masked. Then, the masked code is input into a pre-trained code model, which predicts and generates potentially correct replacement code, obtaining multiple candidate repair patches. Finally, the candidate repair patches are selected, and the optimal patch is applied to complete the repair of the error location. For multiple errors that may exist in the code, the above process iteratively processes each error location until all errors are repaired or it is confirmed that they cannot be resolved by the current method. This method supports multiple error scenarios and achieves progressive code repair through an iterative mechanism.

[0100] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the technical solutions of the embodiments of the present invention.< / mask> < / mask> < / mask> < / mask> < / mask> < / mask>

Claims

1. An automatic compilation error repair method for C language, characterized in that, include: The finely tuned CodeT5 model was used to perform initial repairs on the faulty program; The program is processed by the GCC compiler after initial repair, and the lines of code with errors to be repaired, along with their locations and diagnostic information, are output. Based on the error location and error diagnosis information, the line of code with the error to be repaired is masked using a preset mask template; Input the masked error code line to be repaired into the pre-trained code model UniXcoder, and output several candidate repair patches and their probability scores; Calculate the normalized edit distance of candidate patch based on token, combine it with the probability score of candidate patch to calculate a comprehensive evaluation score, and select the k candidate patches with the highest scores. The selected k candidate patches are used to fix the lines of code with errors that need to be fixed.

2. The automatic compilation error repair method for C language as described in claim 1, characterized in that, The fine-tuning process of the CodeT5 model is as follows: Collect an experience dataset of compilation error repair, construct a fine-tuning dataset in the form of <error code, correct code>, and fine-tune the CodeT5 model.

3. The automatic compilation error repair method for C language as described in claim 1, characterized in that, There are six mask templates, including: masking only the token at the error location; masking the code at the error location and after it; masking the code at the error location and before it; keeping only the last token; keeping only the first token; and masking the entire line of error code.

4. The automatic compilation error repair method for C language as described in claim 1, characterized in that, The formula for calculating the normalized edit distance of the candidate repair patch based on the token is as follows: ; in, This represents the token-based normalized edit distance between strings s1 and s2. This represents the edit distance between strings s1 and s2; This indicates the number of tokens in string s.

5. The automatic compilation error repair method for C language as described in claim 1, characterized in that, The comprehensive evaluation score is a weighted sum of the probability scores of candidate repair patches and the normalized edit distance.

6. The automatic compilation error repair method for C language as described in claim 1, characterized in that, The process for fixing error codes is as follows: Replace the error line to be fixed with the selected k candidate patch and call the GCC compiler. If the error position moves to the end of the current error line, the fix is ​​considered successful. The candidate patch with the highest comprehensive evaluation score among the successful fix patches is retained as the final fix patch. If none of the selected k candidate patches can fix the error, then the line of code is considered unfixable.

7. The automatic compilation error repair method for C language as described in claim 1, characterized in that, The initially repaired error program locates the line of code to be repaired based on the error location of the line of code to be repaired output by the GCC compiler, and repairs it in sequence. After the current line of code to be repaired is repaired, the GCC compiler is called again to locate the next line of code to be repaired and repair it, until the GCC compiler can no longer locate the next line of code to be repaired.

8. An automatic compilation error repair system for C language, characterized in that, include: The initial repair module is used to perform initial repairs on faulty programs using the finely tuned CodeT5 model; The error location and diagnosis module is used to call the GCC compiler to process the program after initial repair, and output the line of code with the error to be repaired, as well as the error location and error diagnosis information; The mask generation module uses a preset mask template to mask the lines of code with errors to be fixed, based on the error location and error diagnosis information. The candidate patch generation module takes the masked error code line to be repaired and combines it with the context input to the pre-trained code model UniXcoder, and outputs several candidate patches and their probability scores. The candidate patch filtering module calculates the normalized edit distance of the candidate patches based on the token, combines the probability scores of the candidate patches to calculate a comprehensive evaluation score, and filters out the k candidate patches with the highest scores. Compile the error repair module and apply the selected k candidate patches to fix the lines of code with errors.

9. An electronic device, characterized in that, The method includes a memory and a processor, the memory storing program instructions that are executed by the processor, the processor invoking the program instructions to perform the method according to any one of claims 1 to 7.

10. A non-transitory computer-readable storage medium, characterized in that, The non-transitory computer-readable storage medium stores computer instructions that cause the computer to perform the method described in any one of claims 1 to 7.