Shape graph generation method and device for program verification of mutable data structure

By refining the volatile data structure assertion and shape graph construction method, the problem of insufficient logical description ability of shape graphs in the existing technology is solved, pointer path delooping and alias elimination are achieved, and the accuracy and efficiency of C language program verification are improved. .

CN112241258BActive Publication Date: 2024-09-13USTC SINOVATE SOFTWARE +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202011105846.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-10-15
Publication Date
2024-09-13
Estimated Expiration
2040-10-15

AI Technical Summary

Technical Problem

In the current C language program verification, the shape graph has insufficient logical description capabilities, cannot effectively handle pointer rings and pointer aliases in volatile data structures, and user-defined predicates lack support in logical calculations.

Method used

By refining the volatile data structure assertions, the shape graph construction method is adopted, including pointer folding fields, table and ring length assertions, dangling pointer assertions, etc., the shape graph construction sequence is optimized, the basic shape built-in predicates are extracted, and the spanning tree is constructed to remove loops and eliminate aliases. , to achieve lazy expansion of the predicate description range.

Benefits of technology

It expands the description ability of shape graph logic, simplifies shape graph construction, realizes pointer path delooping and alias elimination, and improves the accuracy and efficiency of program verification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112241258B
    Figure CN112241258B
Patent Text Reader

Abstract

The present invention discloses a shape graph generation method and device for mutable data structure program verification, including refining different types of mutable data structure assertions, and simplifying the assertion description method for the refined assertion types; constructing shape graphs for different assertion types according to a preset optimization order to obtain a preliminary shape graph of the program, wherein the construction method for the different assertion types includes a shape graph construction method corresponding to the refined assertion types; and performing correction and optimization based on the preliminary constructed shape graph to obtain a precise shape graph. The present invention makes the description of complex shape graphs more standardized and concise, simplifies the shape graph construction process, optimizes the pointer alias elimination process, and reduces the number of aliases that need to be modified during the calculation of pointer operation statements.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of C language program verification, and in particular to a shape graph generation method and device for program verification of mutable data structures. Background Art

[0002] Formal verification based on deductive reasoning is mainly used to improve the credibility of software. In the process of verifying C language programs by formal verification systems, various mutable data structures will be encountered. However, such programs are difficult to be described by first-order logic formulas due to their dynamic generation and complex structure. Therefore, Professor Chen Yiyun and his research team proposed shape graph logic for describing various mutable data structures.

[0003] A shape graph is a directed graph that describes the pointing direction of a pointer-type domain variable in a mutable data structure. It accurately expresses the existence of the memory block pointed to by the pointer and the equality / inequality relationship between pointers, and can therefore be used as an assertion of pointer validity and equality in a program that operates pointers. Shape graph logic is an extension of Hoare logic. Shape graph logic abstracts the assertion of the relationship between a large number of pointers on a mutable data structure into an equivalent shape graph, and adds the logical rules of the shape graph on the basis of Hoare logic. The shape graph participates in the corresponding logical calculation of each program statement as part of the assertion, thereby greatly simplifying the verification of programs containing mutable data structures.

[0004] Problems with shape graph logic in the prior art include:

[0005] 1. The assertions describing shape graphs only have basic shape built-in predicates such as \c_dlist and \tree_seg_l, which are too weak to describe. They cannot meet the requirements for shape graph description in actual programs.

[0006] 2. When the pointer path in the data assertion of the shape graph contains a cycle, there is a problem that the corresponding structure cannot be translated into an algebraic data type.

[0007] 3. The implementation of pointer alias judgment is not optimized. Although only a small number of pointer aliases actually need to be modified, each time the shape graph caused by a pointer operation statement changes, all pointer paths in the assertion need to be aliased, which increases the complexity of the implementation and the verification time.

[0008] 4. It does not mention how the predicate is logically calculated under shape graph logic when the user-defined predicate involves a pointer. Summary of the invention

[0009] In view of the problems existing in the above-mentioned prior art, the present invention provides a shape graph generation method for program verification of mutable data structure, comprising the following steps:

[0010] Refine different types of mutable data structure assertions, and simplify the assertion description method for the refined assertion types;

[0011] Constructing shape graphs for different assertion types according to a preset optimization order to obtain a preliminary shape graph of the program, wherein the construction methods for the different assertion types include shape graph construction methods corresponding to the refined assertion types;

[0012] Based on the initially constructed shape graph, correction and optimization are performed to obtain an accurate shape graph.

[0013] As a further optimization of the above solution, the refinement of different types of mutable data structure assertions includes:

[0014] Traverse the syntax tree and obtain all program assertions;

[0015] Transform the assertion into disjunctive normal form, split the assertion of each disjunctive branch into conjunctive subformulas, and classify each subformula into shape assertion, data assertion, and symbol assertion;

[0016] The shape assertions are further divided into shape built-in predicates, table and ring length assertions, pointer distance assertions, pointer equal to null assertions, pointer not equal to null assertions, pointer equality assertions, pointer inequality assertions, and dangling pointer assertions;

[0017] The data assertions are further divided into general pointers, data domain pointers, quantized data domain pointers, predicate pointers, and predicate data domain pointers according to pointer paths.

[0018] As a further optimization of the above solution, the method of simplifying the assertion description for the refined assertion types includes:

[0019] For the case where a pointer takes a pointer field multiple times in a row in a data assertion, it is recorded as a folded pointer field. By adding p->(r:n) to describe that the pointer p takes a pointer field r for n consecutive times, and n is not less than 0, the assertion description method of the folded pointer field is used in the assertion of the distance between two pointers and the data assertion, and the path will not form a loop.

[0020] As a further optimization of the above solution, the method for simplifying the assertion description for the refined assertion types further includes:

[0021] For the table and ring length assertions in the shape assertions, the table and ring lengths are described by adding a new built-in shape predicate \length. \length(p, r) represents the number of nodes that p passes through when accessing along the r pointer domain back to itself or accessing an empty node. If p is an empty node, \length(p, r) is equal to 0.

[0022] As a further optimization of the above solution, the method for simplifying the assertion description for the refined assertion types further includes:

[0023] For dangling pointer assertions, a new built-in shape predicate \dangling is added to describe dangling pointers.

[0024] As a further optimization of the above solution, the shape graph construction method corresponding to the refined assertion types includes: for pointer equality assertions, the shape graph is constructed by merging nodes on both sides of the assertion equation.

[0025] As a further optimization of the above solution, the shape graph construction method of the pointer equality assertion includes the following steps:

[0026] Set the nodes that are not yet constructed among the nodes pointed to by the outgoing edges of the nodes as unknown nodes;

[0027] According to the node types on both sides of the equation, the two nodes are divided into subject nodes and object nodes. The type priorities from low to high are: dangling node, empty node, predicate node, structure node, condensed node. The node with the highest priority is the subject node.

[0028] If the subject node and the object node on both sides of the equation are the same node, then the merge is directly determined to be successful;

[0029] If the object node is a dangling node, transfer the incoming edge of the object node to the subject node and delete the object node;

[0030] If both the subject and object nodes are empty nodes, the merge is directly determined to be successful;

[0031] If both the subject and object nodes are structural nodes, the incoming edge of the object node is transferred to the subject node, and then all the corresponding outgoing edges are recursively merged. If one outgoing edge fails to merge, the current node fails to merge. After the merger succeeds, delete the object node.

[0032] If the subject node is a condensation node, and the object node is a structure node, and the outgoing edge of the structure node corresponding to the condensation node points to a dangling node with in-degree 1, this outgoing edge will not be recursively merged, and the object node will be deleted after the merger is successful;

[0033] If the object node is a predicate node, and the subject node is a structural node and all outgoing edges of the structural node point to dangling nodes with in-degree 1, replace the dangling nodes pointed to by all outgoing edges of the subject node with predicate nodes, and delete the object node;

[0034] If the above situation does not occur, the merger will be directly determined to have failed.

[0035] As a further optimization of the above solution, the shape graph construction method corresponding to the refined assertion type further includes: the shape graph construction method for the pointer distance assertion includes the following steps:

[0036] For pointers p and q, the distance from p to q along the next domain is n, then find the corresponding non-dangling nodes of the two pointers p and q on the shape graph, calculate the expression e of the distance from p to q along the next domain, and concatenate e==n to the symbolic assertion of the current subgraph. If p cannot access q along the next domain, delete the current subgraph. If no non-dangling node is found, construct q according to the overall description.

[0037] As a further optimization of the above scheme, the shape graph construction method corresponding to the refined assertion type also includes a shape graph construction method for user-defined predicates in data assertions, which is to extract the basic shape built-in predicates therein, and construct a shape graph based on the extracted basic shape built-in predicates, and the shape extraction method is:

[0038] Obtaining the dependency relationship between custom predicate parameters, wherein the dependency relationship refers to that, according to the predicate definition description, a predicate pointer parameter is equal to another predicate pointer parameter after at least one pointer domain access;

[0039] Determine whether each parameter is the header or root of the corresponding shape. If so, determine the basic shape built-in predicate of the custom predicate. Otherwise, proceed to the next step.

[0040] Take the pointer parameter as the table segment header or tree segment header, obtain each pointer parameter q that depends on the pointer parameter p according to the dependency relationship, and use the theorem prover to obtain the pointer parameter q at the table segment tail or tree segment tail corresponding to the pointer parameter p, and obtain the basic shape of the custom predicate built-in predicate.

[0041] As a further optimization of the above solution, the method for obtaining the dependency relationship between predicate parameters is:

[0042] Direct references to parameters and predicates are treated as directed edges of length 0, and pointer field references are treated as directed edges of length 1;

[0043] According to the graph theory problem solving method, it is solved whether the node corresponding to the parameter has a path with a length greater than 0 to reach other nodes.

[0044] As a further optimization of the above solution, the process of constructing shape graphs for different assertion types according to a preset optimization order to obtain a preliminary shape graph of the program includes:

[0045] (111) Generate nodes and pointers to mutable data structures based on all normalized assertions, including:

[0046] For the pointer path that does not contain a folding domain, construct all the nodes on the path;

[0047] Added assertion that the pointer folding domain folding times is not less than 0;

[0048] Check whether the current assertion is contradictory. If it is contradictory, stop constructing the shape graph;

[0049] Construct shapes based on basic shape built-in predicates;

[0050] According to each basic shape built-in predicate extracted by the custom predicate, the current shape graph is copied into two copies, one for trying to construct the shape graph and the other for not being used to construct the shape graph, and the subgraph that fails to be constructed is deleted;

[0051] (112) Restore the missing pointer pointing relationship, including:

[0052] Construct a shape graph based on pointer equality assertions;

[0053] (113) Delete or modify the shape subgraph that does not conform to the assertion description, including:

[0054] Construct a shape graph based on pointer distance assertions;

[0055] Check the condensed nodes on the shape graph. If the condensed nodes form a ring, add an assertion that the total length of the ring is greater than 0. If the condensed nodes form a chain and end with an empty node, add an assertion that the total length of the chain is greater than 0.

[0056] Construct a shape based on the pointer equals null assertion;

[0057] Check if the current shape graph complies with the shape according to each basic shape built-in predicate extracted by the custom predicate;

[0058] Construct a shape based on the pointer not equal to null assertion;

[0059] Construct shapes based on pointer inequality assertions;

[0060] According to the table and ring length assertion, calculate the corresponding length on the shape graph, and replace the \length predicate in the current subgraph assertion with the corresponding length expression;

[0061] Check shape based on dangling pointer assertions, removing subgraphs of dangling nodes that are not explicitly declared;

[0062] Check whether the current assertion is contradictory and remove the contradictory subgraph.

[0063] As a further optimization of the above solution, the shape graph based on the preliminary construction is corrected and optimized to obtain a precise shape graph, including de-looping the pointer path and eliminating pointer aliases.

[0064] As a further optimization of the above solution, in the process of removing the pointer path ring, the pointer path ring removal of the user-defined predicate is performed by directly deleting the pointer relationship that describes the ring.

[0065] As a further optimization of the above scheme, the method used for de-looping the pointer path and eliminating pointer aliases for non-user-defined predicates is to construct a spanning tree based on the shape graph, replace the pointer path in the data assertion with the path of the node corresponding to the pointer path on the spanning tree, and use the principle that the spanning tree has no loops and the path to any node on the spanning tree is unique to achieve de-looping and alias elimination of the pointer path.

[0066] As a further optimization of the above solution, the method of using the spanning tree to achieve pointer path de-looping and alias elimination is:

[0067] Construct a spanning tree based on the shape graph;

[0068] According to the longest pointer path prefix without constraint variables in the data assertion, find the unique corresponding node on the spanning tree;

[0069] Replace the pointer path A in the data assertion with the unique path B of the unique corresponding node on the spanning tree;

[0070] Save the bidirectional binding between nodes and pointer paths in data assertions, and dynamically maintain the spanning tree.

[0071] As a further optimization of the above scheme, the method of correcting and optimizing the shape graph based on the preliminary construction to obtain the accurate shape graph further includes: judging whether the predicates asserted before and after the assignment statement are expanded, and the judging method includes:

[0072] Get the scope described by the predicate;

[0073] Determine whether the modification of pointer fields or data fields by assignment statements affects the predicate description;

[0074] If so, perform predicate expansion.

[0075] As a further optimization of the above solution, the scope of obtaining the predicate description specifically includes:

[0076] Obtain the domain of the iterated pointer parameter in the predicate and the domain names and types of all domain references that appear, wherein the domain of the iterated pointer parameter is a domain that the parameter may directly access in the predicate according to the predicate definition description, and the domain names and types of the domain references correspond to each other;

[0077] Starting from the pointer argument on the shape graph, take a reference to the iterative domain corresponding to the argument and then recursively take all domain references that appear in the predicate;

[0078] Get all visited nodes, edges, and data as the scope described by the predicate.

[0079] As a further optimization of the above solution, the method for obtaining the domain of the iterated pointer parameter in the predicate is:

[0080] Direct references to parameters and predicates are treated as virtual directed edges, and pointer field references and data field references are treated as real directed edges;

[0081] The domain of all parameter iterations is obtained by using the solution method in graph theory to solve the types of real edges that can be reached from the nodes corresponding to the parameters.

[0082] As a further optimization of the above solution, the result of taking a reference to the iterative domain corresponding to the actual parameter and then recursively taking all domain references appearing in the predicate includes:

[0083] Determine whether the predicate contains the shape of the table segment or tree segment;

[0084] If it is not included, directly take a reference to the iterative domain corresponding to the actual parameter and then recursively take all domain references that appear in the predicate, otherwise proceed to the next step;

[0085] If the predicate contains the shape of a table segment or a tree segment, when the actual parameter corresponds to the head of the segment and the recursive reference reaches the node pointed to by the actual parameter corresponding to the end of the segment, the recursion to the end of the segment will no longer continue, and the iteration domain of the segment will be supplemented.

[0086] As a further optimization of the above solution, the method of supplementing the segment iteration domain is:

[0087] Construct a simplified shape graph based on the shape description in the predicate, record the predicate reference in the predicate definition to the node corresponding to the actual parameter, and record the position of the formal parameter corresponding to the node;

[0088] For the self-referencing nodes on all nodes in the predicate definition, count all domain references that pass through each parameter domain reference once;

[0089] After obtaining all the domain references of each parameter's domain reference, search for a domain reference on all branches of the current predicate for each parameter, and then recursively search for all domain references. When recursively searching for all domain references of a self-referencing node, it includes recursive searching through predicate references.

[0090] Check if there are other parameters that directly point to the found nodes, and all parameters that directly point to these nodes supplement all domain references to the iterated domain.

[0091] As a further optimization of the above solution, the statistical method for all domain references that pass through each parameter once is as follows:

[0092] An outgoing edge that passes through a self-reference is recorded as a domain reference. The shape description part pointed to by the outgoing edge recursively obtains all domain references, and all the recursively obtained domain references are recorded under all domain references corresponding to the domain reference of the outgoing edge.

[0093] For other predicate references on the self-referenced node, obtain the iterated domains and all domain references under other predicates according to the predicate formal parameters corresponding to the node, and add them to all domain references of the corresponding formal parameter domain reference.

[0094] The present invention further provides an electronic device, characterized in that the electronic device comprises:

[0095] A memory for storing executable instructions;

[0096] The processor is used to implement the shape graph generation method for mutable data structure program verification when running the executable instructions stored in the memory.

[0097] The shape graph generation method for mutable data structure program verification of the present invention has the following beneficial effects:

[0098] 1. The present invention expands the existing implementation technology of shape graph logic and adds more grammatical support for shape assertions that describe shape graphs, including pointer folding domains, assertion description of the distance between two pointers, built-in predicates for describing tables and ring lengths, pointer equality / inequality assertions, dangling pointer assertions, and clearly defines operational semantics for newly added assertion types.

[0099] 2. The present invention improves the shape graph construction method by optimizing the construction order of different assertion types, thereby simplifying the shape graph construction.

[0100] 3. The present invention solves the negative impact of the introduction of built-in shape predicates by extracting basic shape built-in predicates from user-defined predicates and constructing a shape graph based on the extraction results. The extraction method uses the dependency between predicate parameters to quickly check the predicate shape.

[0101] 4. In the case where the pointer path in the data assertion of the shape graph contains a loop, the present invention constructs a spanning tree of the shape graph, replaces the path with the path corresponding to the node on the spanning tree, and performs de-looping, so that the mutable data structure type can be translated into an algebraic data type.

[0102] 5. The present invention utilizes a shape graph to generate a tree, performs bidirectional binding between pointer paths and nodes in assertions, and dynamically maintains the generated tree, thereby optimizing the pointer alias elimination process and reducing the number of aliases that need to be modified during the calculation of pointer operation statements.

[0103] 6. The present invention realizes lazy expansion of predicates by judging the scope of predicate descriptions before and after assignment statements. The method adopted for judging the scope of predicate descriptions ensures, on the one hand, that the scope of the acquired predicate descriptions must include the scope of the entire real description of the predicates, thereby ensuring that the program verification results are reliable. On the other hand, the scope of the acquired predicate descriptions must be included in the scope of recursive search based only on the domains appearing in the predicates, thereby reducing the false alarm rate of the program verification results. BRIEF DESCRIPTION OF THE DRAWINGS

[0104] Figure 1 A flow chart of a method for constructing shape graphs for different assertion types according to a preset optimization order to obtain a preliminary shape graph in the present invention;

[0105] Figure 2 It is a diagram of a shape graph construction method for a case of pointer equality assertion in the present invention;

[0106] Figure 3 It is a diagram of a shape graph construction method for another case of pointer equality assertion in the present invention;

[0107] Figure 4 This is a diagram of a method for obtaining dependency relations between predicate parameters in the present invention, taking a specific data as an example;

[0108] Figure 5 It is a diagram of a method for obtaining the domain of iterations of all parameters in the present invention taking a specific data as an example;

[0109] Figure 6-Figure 10 Taking a specific data as an example, the process diagram starts from the pointer actual parameter, takes a reference to the iterative domain corresponding to the actual parameter, and then recursively takes all domain references that appear in the predicate;

[0110] Figure 11-Figure 14 Taking another specific data as an example, a process diagram is shown on the shape diagram starting from the pointer actual parameter, taking a reference to the iterative domain corresponding to the actual parameter, and then recursively taking all domain references that appear in the predicate. DETAILED DESCRIPTION

[0111] In order to make the purpose, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present invention. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present invention.

[0112] Before further describing the embodiments of the present invention in detail, a program verification process involved in the embodiments of the present invention is briefly described.

[0113] 1. The process of program verification for a C language file

[0114] Safe C language verification is a process of generating a syntax tree and generating verification conditions based on a C source file (including some header files contained in the C source file). For a C program source file, the verification condition generator scans constant definitions, type definitions, variable declarations, function declarations, and function definitions in sequence, and then performs the following processing:

[0115] (11) For external variable (and constant) declarations and static external variable (and constant) declarations, assertions of the corresponding variables are generated according to their initial values ​​as part of the assertion when the operating system calls the main function. It should be noted that the main function is the last function to be verified.

[0116] (12) For a function declaration, when processing its function protocol, add its function protocol to the protocol table of the function. A function may have multiple declarations. Since each function declaration can have a function protocol, a function may have multiple function protocols, and each function protocol needs to be verified separately.

[0117] (13) For a function definition, when processing its function protocol, its function protocol is added to the protocol table of the function, and then the calculation of generating verification conditions is performed for each function protocol on the function protocol table.

[0118] 2. The process of program verification for a function

[0119] The overall process of calculating the verification conditions for a "function definition" is as follows (if the function has multiple protocols, each protocol needs to go through the same process below):

[0120] (21) At the function entry, the verification condition generator needs to generate function entry assertions based on the function protocol.

[0121] (22) The function body is then evaluated using compound statement calculation rules to obtain the assertion at the function exit. A series of verification conditions are also generated during the calculation of the function body statements.

[0122] (23) Generate the function exit verification condition based on the function exit assertion and function protocol obtained by calculation. The compound statement calculation rules and the generation of function exit verification conditions will be introduced in detail below. The following describes the basic process of generating the function entry assertion based on the function protocol at the function entry:

[0123] (211) Obtain the assertion R in the requires clause in the function protocol according to the interface provided by the front-end module;

[0124] (212) Normalize the R assertion. The result of normalization is R1||R2||...||R n ;

[0125] (213) Determine whether the function being verified is a heap pointer operation function according to the interface provided by the front-end module. If so, for each R i (1≤i≤n) Generate the corresponding shape graph G i (1≤i≤n), and delete R i All heap pointer assertions in . If the function being verified is not a heap pointer operation function, no processing is required in this step. Suppose that after this step, the assertion becomes: (R1&&G1)||(R2&&G2)||...||(R n &&G n );

[0126] (214) For each R i Generate the ternary attributes of the stack pointer and static area pointer (including memory status), and delete the assertions related to the stack pointer and static area pointer in R and change them to Qi. If there is no stack pointer operation, the result of this step is assertion \true (stack pointer assertion is equivalent to \true).

[0127] After the above steps, the assertion form at the function entry is:

[0128] (P1∧G1∧Q1)∨(P2∧G2∧Q2)∨...∨(P n ∧G n ∧Q n );

[0129] The embodiment of the present application mainly improves the shape analysis method described in the above step (213) to achieve accurate and simplified construction of the shape graph, thereby improving the accuracy and speed of program verification when the shape graph is used in the program verification process.

[0130] Specifically, the shape graph generation method for mutable data structure program verification provided by the embodiment of the present application includes the following steps:

[0131] Refine different types of mutable data structure assertions, and simplify the assertion description method for the refined assertion types;

[0132] Constructing shape graphs for different assertion types according to a preset optimization order to obtain a preliminary shape graph of the program, wherein the construction methods for the different assertion types include shape graph construction methods corresponding to the refined assertion types;

[0133] Based on the initially constructed shape graph, correction and optimization are performed to obtain an accurate shape graph.

[0134] The embodiment of the present application refines the assertion types and adopts newly added built-in shape predicates to describe the corresponding assertions, so that the description of complex shape graphs is more standardized and concise. On this basis, different corresponding shape graph construction methods are adopted for the refined assertion types to provide more stringent constraints, so that the shape system can better detect errors in assertions; and the construction order is improved based on different assertion types to simplify the construction process, so as to avoid too many unnecessary subgraphs generated in each step of the shape graph construction process, which will cause cumbersomeness in the subsequent construction process.

[0135] Specifically, the process of refining assertions for different types of mutable data structures includes:

[0136] Traverse the syntax tree and obtain all program assertions;

[0137] Transform the assertion into disjunctive normal form, split the assertion of each disjunctive branch into conjunctive subformulas, and classify each subformula into shape assertion, data assertion, and symbol assertion;

[0138] The shape assertions are further divided into shape built-in predicates, table and ring length assertions, pointer distance assertions, pointer equal to null assertions, pointer not equal to null assertions, pointer equality assertions, pointer inequality assertions, and dangling pointer assertions;

[0139] The data assertions are further divided into general pointers, data domain pointers, quantized data domain pointers, predicate pointers, and predicate data domain pointers according to pointer paths.

[0140] For the above two pointer distance assertions and data assertions, in which the pointer takes the pointer domain multiple times in a row, the concept of folded pointer domain is added. p->(r:n) is used to describe that the pointer p takes the pointer domain r for n consecutive times, and n is not less than 0. This simplifies the pointer path description method, and the path will not form a loop. For example, q==p->(next:n) means that p is taken n times in a row along the next domain, that is, the distance between the two pointers p and q is n.

[0141] For the table and loop length assertions in the above shape assertions, the table and loop lengths are described by adding a built-in shape predicate \length. \length(p, r) indicates the number of nodes that p passes through when it accesses back to itself or accesses an empty node along the r pointer domain. If p is an empty node, \length(p, r) is equal to 0. For the description of table and loop length assertions, for example, \length(p, next) = n, it means that the number of nodes that p passes through when it accesses back to itself or accesses an empty node along the r pointer domain is n. Of course, \length(p, r) is not limited to appearing in equation assertions. In the process of shape graph construction, the method for handling table and loop length assertions is to delete the corresponding subgraph if the length of the corresponding table or loop does not meet the assertion.

[0142] For the above dangling pointer assertion, a new built-in shape predicate \dangling is added to describe the dangling pointer. \dangling(p->next) means that p->next is a dangling pointer. During the shape graph construction process, the subgraph containing dangling nodes that are not explicitly declared with \dangling needs to be deleted.

[0143] For the above pointer equality assertion, the shape graph is constructed by merging the nodes on both sides of the assertion equation, which specifically includes the following steps:

[0144] Set the nodes that are not yet constructed among the nodes pointed to by the outgoing edges of the nodes as unknown nodes;

[0145] According to the node types on both sides of the equation, the two nodes are divided into subject nodes and object nodes. The type priorities from low to high are: dangling node, empty node, predicate node, structure node, condensed node. The node with the highest priority is the subject node.

[0146] If the subject node and the object node on both sides of the equation are the same node, then the merge is directly determined to be successful;

[0147] If the object node is a dangling node, transfer the incoming edge of the object node to the subject node and delete the object node;

[0148] If both the subject and object nodes are empty nodes, the merge is directly determined to be successful;

[0149] If both the subject and object nodes are structural nodes, the incoming edge of the object node is transferred to the subject node, and then all the corresponding outgoing edges are recursively merged. If one outgoing edge fails to merge, the current node fails to merge. After the merger succeeds, delete the object node.

[0150] If the subject node is a condensation node, and the object node is a structure node, and the outgoing edge of the structure node corresponding to the condensation node points to a dangling node with in-degree 1, this outgoing edge will not be recursively merged, and the object node will be deleted after the merger is successful;

[0151] If the object node is a predicate node, and the subject node is a structural node and all outgoing edges of the structural node point to dangling nodes with in-degree 1, replace the dangling nodes pointed to by all outgoing edges of the subject node with predicate nodes, and delete the object node;

[0152] If the above situation does not occur, the merger will be directly determined to have failed.

[0153] See also Figure 2 and Figure 3 , the merging process of pointer equality assertions is explained, where circle 1 is the subject, circle 2 is the object, white nodes are structure nodes, gray nodes are condensed nodes, and D refers to dangling nodes.

[0154] The shape graph construction method for the above pointer distance assertion includes the following steps:

[0155] For pointers p and q, the distance from p to q along the next domain is n, then find the corresponding non-dangling nodes of the two pointers p and q on the shape graph, calculate the expression e of the distance from p to q along the next domain, and concatenate e==n to the symbolic assertion of the current subgraph. If p cannot access q along the next domain, delete the current subgraph. If no non-dangling node is found, construct q according to the overall description.

[0156] The shape graph construction method for the user-defined predicate in the data assertion is to extract the basic shape built-in predicates therein, and construct the shape graph based on the extracted basic shape built-in predicates. The shape extraction method is:

[0157] (a1) Obtain the dependency relationship between custom predicate parameters. The dependency relationship refers to the description of a predicate definition that a predicate pointer parameter is equal to another predicate pointer parameter after at least one pointer domain access. The solution to the dependency relationship can be converted into a graph theory problem solving method, specifically, the direct reference between the parameter and the predicate is regarded as a directed edge of length 0, and the pointer domain reference is regarded as a directed edge of length 1; the problem of solving all dependency relationships becomes solving whether the node corresponding to the parameter has a path with a length greater than 0 to reach other nodes. This is a graph theory problem and can be solved by solving the strongly connected component and then depth-first search.

[0158] Taking the definition of seg(Node*p, Node*q)=p==q!=\null||p!=q&&seg(p->r,q) as an example, the judgment process of the dependency relationship between predicate parameters is explained. Figure 4 , the length of the virtual edge in the graph is 0, the length of the real edge is 1, the direct references of the parameters and predicates are regarded as directed edges of length 0, and the pointer domain references are regarded as directed edges of length 1. The graph theory problem solving method is used to solve whether the node corresponding to the parameter has a path with a length greater than 0 to reach other nodes. p has a path of length 1 to access the node pointed to by q, but q does not have a path of length 1 to access the node pointed to by q, so q depends on p, and p does not depend on q.

[0159] (b1) After obtaining the dependency relationship, determine whether each parameter is the header or root of the corresponding shape. If so, determine the basic shape built-in predicate of the custom predicate. Otherwise, proceed to the next step.

[0160] (c1) Take the pointer parameter as the table segment header or the tree segment header, obtain each pointer parameter q that depends on the pointer parameter p according to the dependency relationship, and use the theorem prover to obtain the pointer parameter q at the table segment tail or the tree segment tail corresponding to the pointer parameter p, and obtain the basic shape of the custom predicate built-in predicate.

[0161] To verify whether the parameter ai of a ring-free predicate predicate(a1, a2, ..., ai, ..., an) has shape shape(ai), we can use the theorem prover to prove \forall Type1 a1, Type2 a2, ..., Typen an.(predicate(a1, a2, ..., ai, ..., an) ==> shape(ai)). The same is true for shape with multiple parameters. For example, to verify whether the parameters p and q of the predicate seg(Node*p, Node*q) have shape tree segment \tree_seg_r(p, q), we can use Z3 to prove \forall Node*p, Node*q.(seg(p, q) ==> \tree_seg_r(p, q)). The concrete definition of \tree_seg_r translated into Z3 is constructed based on the abstract definition of the built-in predicates and the user's shape declaration for the domain of type Node.

[0162] Due to the limitation of shape annotation, the shape of a parameter in the predicate only considers the shape that may correspond to the shape annotation of its type (for example, if the shape annotation of a parameter type is a binary tree type, then the case where it expresses the shape of a single linked list in the predicate is not considered). Therefore, if the type annotation of a parameter is a basic shape, then only three shapes are considered: the head of the table (the root of the tree), the head of a table segment (tree segment), or the tail.

[0163] See also Figure 1 , the specific steps of constructing the preliminary shape graph according to the preset optimization sequence in the embodiment of the present application include:

[0164] (111) Generate nodes and pointers to mutable data structures based on all normalized assertions, including:

[0165] For the pointer path that does not contain a folding domain, construct all the nodes on the path;

[0166] Added assertion that the pointer folding domain folding times is not less than 0;

[0167] Check whether the current assertion is contradictory. If it is contradictory, stop constructing the shape graph;

[0168] Construct shapes based on basic shape built-in predicates;

[0169] According to each basic shape built-in predicate extracted by the custom predicate, the current shape graph is copied into two copies, one for trying to construct the shape graph and the other for not being used to construct the shape graph, and the subgraph that fails to be constructed is deleted;

[0170] (112) Restore the missing pointer pointing relationship, including:

[0171] Construct a shape graph based on pointer equality assertions;

[0172] (113) Delete or modify the shape subgraph that does not conform to the assertion description, including:

[0173] Construct a shape graph based on pointer distance assertions;

[0174] Check the condensed nodes on the shape graph. If the condensed nodes form a ring, add an assertion that the total length of the ring is greater than 0. If the condensed nodes form a chain and end with an empty node, add an assertion that the total length of the chain is greater than 0.

[0175] Construct a shape based on the pointer equals null assertion;

[0176] Check if the current shape graph complies with the shape according to each basic shape built-in predicate extracted by the custom predicate;

[0177] Construct a shape based on the pointer not equal to null assertion;

[0178] Construct shapes based on pointer inequality assertions;

[0179] According to the table and ring length assertion, calculate the corresponding length on the shape graph, and replace the \length predicate in the current subgraph assertion with the corresponding length expression;

[0180] Check shape based on dangling pointer assertions, removing subgraphs of dangling nodes that are not explicitly declared;

[0181] Check whether the current assertion is contradictory and remove the contradictory subgraph.

[0182] So far, the preliminary construction of the shape graph is completed. On this basis, the shape graph is corrected and optimized to obtain a precise shape graph, including removing the pointer path loop and eliminating the pointer alias. The method is as follows:

[0183] (a2) For the pointer path de-looping of the user-defined predicate, the pointer relationship describing the loop is directly deleted; for example, dlist_seg(Node*p, Node*q)=p==q!=\null||p!=q&&p->r->l==p&&dlist_seg(p->r,q), after removing the assertion of the pointer relationship describing the loop, it becomes dlist_seg(Node*p, Node*q)=p==q!=\null||p!=q&&dlist_seg(p->r,q).

[0184] (b2) For pointer path delooping and pointer alias elimination of non-user-defined predicates, the method adopted is to construct a spanning tree based on the shape graph, replace the pointer path in the data assertion with the path of the node corresponding to the pointer path on the spanning tree, and use the principle that the spanning tree has no loops and the path to any node on the spanning tree is unique to achieve pointer path delooping and alias elimination.

[0185] Step (b2) is specifically:

[0186] Construct a spanning tree based on the shape graph;

[0187] According to the longest pointer path prefix without constraint variables in the data assertion, find the unique corresponding node on the spanning tree (it may be necessary to discuss separately to split the shape graph so that the path corresponds to a unique node on all subgraphs). An example is given to illustrate the longest pointer path, such as \forall int i:[0..n].p->l->(r:i)->data==0, the longest pointer path prefix without constraint variables is p->l;

[0188] Replace the pointer path A in the data assertion with the unique path B of the unique corresponding node on the spanning tree;

[0189] Save the bidirectional binding between nodes and pointer paths in data assertions, and dynamically maintain the spanning tree.

[0190] Based on the above dynamic spanning tree, the pointer path de-looping and alias pointer elimination are realized at the same time. Specifically, for the program statements involving alias pointers, during the calculation process, various program statement operations that cause shape changes, after decomposition, only the edges are deleted, and the connecting edges will cause the spanning tree to change. The problem becomes a simple spanning tree dynamic maintenance problem, and the pointer paths corresponding to the nodes affected by the spanning tree change can be replaced. In addition, in the selection of the algorithm for constructing the spanning tree, the algorithm for constructing the shortest path tree or the minimum spanning tree can be used, and the edge weight calculation method can be freely set according to experience.

[0191] Based on the above dynamic generation tree, it is ensured that no matter what kind of pointer operation is performed, the pointer path in the assertion remains concise and easy to read, avoiding the tedious process of traversing the pointer paths of all data assertions and checking whether the pointer path needs to be modified every time the pointer is modified.

[0192] In the embodiment of the present application, the shape graph constructed initially is modified and optimized to obtain an accurate shape graph, and the method further includes: implementing lazy expansion of the predicates asserted before and after the assignment statement, and first determining whether to expand, and the determination method includes:

[0193] Get the scope described by the predicate;

[0194] Determine whether the modification of pointer fields or data fields by assignment statements affects the predicate description;

[0195] If so, perform predicate expansion.

[0196] Furthermore, the scope of the acquisition predicate description specifically includes:

[0197] (a3) obtaining the domain of the iterated pointer parameter in the predicate and the domain names and types of all domain references that appear, wherein the domain of the iterated pointer parameter is a domain that may be directly accessed by the parameter in the predicate according to the predicate definition description, and the domain names and types of the domain references correspond to each other;

[0198] (b3) Starting from the pointer argument on the shape graph, take a reference to the iterative domain corresponding to the argument and then recursively take all domain references that appear in the predicate;

[0199] (c3) Get all visited nodes, edges, and data as the scope described by the predicate.

[0200] Based on the method of obtaining the range of the predicate description in steps (a3), (b3), and (c3), firstly, the range of the predicate description obtained by this method must include the range of the entire real description of the predicate, thereby ensuring that the program verification result is reliable ("reliable" means that the verification result is "the verified program is correct", then the verified program must be correct). Secondly, the range of the predicate description obtained by this method must be included in the range of simply searching recursively based on the domain appearing in the predicate, thereby reducing the false positive rate of the program verification result ("false positive" means that the verification result is "the verified program may be wrong", but the verified program is correct.)

[0201] Furthermore, in the above step (a3), the method for obtaining the domain of the iterative pointer parameter in the predicate can be converted into a graph theory problem. Specifically, the direct references of the parameters and the predicate are regarded as virtual directed edges, and the pointer domain references and the data domain references are regarded as real directed edges. Then, the problem of solving the iterative domain of all parameters becomes the problem of solving the types of real edges that can be reached from the nodes corresponding to the parameters. This is a graph theory problem and can be solved by solving the strongly connected components and then depth-first search.

[0202] Take the definition of seg(Node*p, Node*q)=p==q!=\null&&q->data==0||p!=q&&seg(p->r,q) as an example, see Figure 5 , the process of obtaining the domain of all parameter iterations. It can be seen that the domain of p iteration is data and r, and the domain of q iteration is data.

[0203] In the above step (b3), when the result of taking a reference to the iterative domain corresponding to the actual parameter and then recursively taking all domain references appearing in the predicate includes:

[0204] (b31) determine whether the predicate contains the shape of the table segment or the tree segment;

[0205] (b32) If it is not included, directly take the result of a reference to the iterative domain corresponding to the actual parameter and then recursively take all domain references that appear in the predicate, otherwise go to (b33);

[0206] (b33) If the predicate contains the shape of a table segment or a tree segment, when the actual parameter corresponds to the segment head and the recursive reference reaches the node pointed to by the actual parameter corresponding to the segment tail, the segment tail is no longer recursively referenced, and the segment is supplemented with the iteration domain. The supplementation method is:

[0207] (b331) construct a simplified shape graph based on the shape description in the predicate, record the predicate reference in the predicate definition to the node corresponding to the actual parameter, and record the position of the formal parameter corresponding to the node;

[0208] (b332) For all self-referencing nodes on all nodes in the predicate definition, count all domain references that pass through each parameter domain reference once. The counting method is:

[0209] An outgoing edge that passes through a self-reference is recorded as a domain reference. The shape description part pointed to by the outgoing edge recursively obtains all domain references, and all the recursively obtained domain references are recorded under all domain references corresponding to the domain reference of the outgoing edge.

[0210] For other predicate references on the self-referenced node, obtain the iterated domains and all domain references under other predicates according to the predicate formal parameters corresponding to the node, and add them to all domain references of the domain reference of the corresponding formal parameter once;

[0211] (b333) After obtaining all the domain references of each parameter's domain reference, search for a domain reference on all branches of the current predicate for each parameter, and then recursively search for all domain references. When recursively searching for all domain references of a self-referencing node, it includes recursively searching through predicate references.

[0212] (b334) Check if there are other parameters that directly point to the found nodes. All parameters that directly point to these nodes will have all their fields referenced to the iterated fields.

[0213] See also Figure 6-14 , defined with two predicates:

[0214] seg_l(Node*p, Node*q)=p==q! =\null&&tree(q->r)||p! =q&&tree(p->l)&&tree(p->r)&&seg_l(p->l,q)

[0215] and

[0216] seg_r(Node*p, Node*q)=p==q! =\null&&tree(q->l)||p! =q&&tree(p->l)&&tree(p->r->l)&&seg_r(p->r,q)

[0217] Take the above step (b3) as an example:

[0218] First, take seg_l as an example:

[0219] See also Figure 6 First, obtain the domain of the iterated pointer parameter in the predicate, and obtain the iteration domain of p of seg_l(Node*p, Node*q) as l and r, and the iteration domain of q as r.

[0220] See also Figure 7 , for other predicate references on the self-referenced node, according to the predicate formal parameters corresponding to the node, obtain the iterated domains and all domain references under other predicates, add them to all domain references of the first domain reference of the corresponding formal parameter, and obtain the first domain reference l and r of p of seg_l(Node*p, Node*q), all domain references are l and r, q has none.

[0221] After obtaining all the domain references of each parameter's domain reference, search for each parameter's domain reference on all branches of the current predicate and then recursively search using all domain references (when encountering a self-reference node, the search will also recursively search using the predicate reference). Check if the found nodes are directly pointed to by other parameters, and all the parameters that directly point to these nodes will add all the domain references to the iterated domains.

[0222] See also Figure 8 First, recursively search for all domain references of seg_l domain reference l, and find the node labels. Fig. 9 , so the q of seg_l needs to be supplemented with the iteration domain l;

[0223] See also Fig.10 , and then recursively search all domain references of r in the domain reference of seg_l. There is no iterative domain that needs to be supplemented.

[0224] Take seg_r as an example:

[0225] See also Fig.11 First, obtain the domain of the iterated pointer parameter in the predicate, and obtain seg_r(Node*p, Node*q). The iteration domain of p is l and r, and the iteration domain of q is l.

[0226] See also Fig.12 , the outgoing edge that passes through the self-reference is recorded as a primary domain reference, the shape description part pointed to by the outgoing edge recursively obtains all domain references, and all the domain references recursively obtained are recorded under all the domain references corresponding to the primary domain reference of the outgoing edge, and all the domain references of the primary domain reference l of p of seg_r(Node*p, Node*q) are obtained as l and r, and q has none.

[0227] See also Fig.13, recursively search for all domain references of seg_r domain reference l, and the node labels found are shown in Fig.14 , so there is no iteration domain that needs to be supplemented.

[0228] The embodiment of the present invention also provides a shape graph generation device for program verification of a mutable data structure, comprising:

[0229] Assertion type refinement unit, used to refine different types of mutable data structure assertions and simplify the assertion description method for the refined assertion types;

[0230] A shape graph preliminary construction unit, used to construct shape graphs for different assertion types according to a preset optimization order to obtain a preliminary shape graph of the program, wherein the construction methods for the different assertion types include shape graph construction methods corresponding to the refined assertion types;

[0231] The shape graph optimization unit is used to perform correction and optimization based on the initially constructed shape graph to obtain an accurate shape graph.

[0232] An embodiment of the present invention further provides an electronic device, the electronic device comprising:

[0233] A memory for storing executable instructions;

[0234] The processor is used to implement the shape graph generation method for mutable data structure program verification when running the executable instructions stored in the memory.

[0235] The memory may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function, etc., wherein the operating system includes various system programs, such as a framework layer, a core library layer, a driver layer, etc., for implementing various basic services and processing hardware-based tasks. The application program may include various applications; the data storage area may store data created during use, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0236] The embodiment of the present invention also provides a computer-readable storage medium, which stores executable instructions, and when the executable instructions are executed by the processor, the shape diagram generation method for program verification of mutable data structures is implemented. It should be understood that the functional modules or units in the embodiment of the present invention can be integrated together to form an independent part, or each module can exist separately, or two or more modules can be integrated to form an independent part. If the function is implemented in the form of a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-0nlyMemory), random access memory (RAM, RandomAccessMemory), disk or optical disk and other media that can store program codes.

[0237] The present invention is not limited to the above-mentioned specific implementation modes. Various changes made by ordinary technicians in this field based on the above-mentioned concepts without creative work are all within the protection scope of the present invention.

Claims

1. A shape graph generation method for program verification of mutable data structures, characterized in that: The steps include: Refine different types of mutable data structure assertions and simplify the assertion description method for the refined assertion types; Constructing shape graphs for different assertion types according to a preset optimization order to obtain a preliminary shape graph of the program, wherein the construction methods for the different assertion types include shape graph construction methods corresponding to the refined assertion types; Based on the shape diagram initially constructed, correction and optimization are performed to obtain a precise shape diagram; The refining of different types of mutable data structure assertions includes: traversing the syntax tree to obtain all program assertions; The assertion is normalized into a disjunctive normal form, and the assertion of each disjunctive branch is split into conjunctive subformulas, each of which is classified into shape assertions, data assertions, and symbolic assertions; the shape assertions are further divided into shape built-in predicates, table and ring length assertions, pointer distance assertions, pointer equal to null assertions, pointer not equal to null assertions, pointer equality assertions, pointer inequality assertions, and dangling pointer assertions; the data assertions are further divided into general pointers, data domain pointers, quantized data domain pointers, predicate pointers, and predicate data domain pointers according to pointer paths; The shape graph construction method corresponding to the refined assertion type includes: for a pointer equality assertion, a shape graph is constructed by merging nodes on both sides of the assertion equation; the shape graph construction method for the pointer equality assertion includes the following steps: Set the nodes that are not yet constructed among the nodes pointed to by the outgoing edges of the nodes as unknown nodes; According to the node types on both sides of the equation, the two nodes are divided into subject nodes and object nodes. The type priorities from low to high are: dangling node, empty node, predicate node, structure node, condensed node. The node with the highest priority is the subject node. If the subject node and the object node on both sides of the equation are the same node, then the merge is directly determined to be successful; If the object node is a dangling node, the incoming edge of the object node is transferred to the subject node and the object node is deleted; If both the subject node and the object node are empty nodes, the merge is directly determined to be successful; If both the subject node and the object node are structural nodes, the incoming edge of the object node is transferred to the subject node, and then all the corresponding outgoing edges are recursively merged. If one outgoing edge fails to merge, the current node merge fails. After the merge is successful, the object node is deleted. If the subject node is a condensation node, and the object node is a structure node, and the outgoing edge of the structure node corresponding to the condensation node points to a dangling node with in-degree 1, this outgoing edge will not be recursively merged, and the object node will be deleted after the merger is successful; If the object node is a predicate node, and the subject node is a structural node and all outgoing edges of the structural node point to dangling nodes with in-degree 1, replace the dangling nodes pointed to by all outgoing edges of the subject node with predicate nodes, and delete the object node; If the above situation does not occur, the merger will be directly determined to have failed.

2. The shape graph generation method for volatile data structure program verification according to claim 1, characterized in that: The shape graph construction method corresponding to the refined assertion type also includes: the shape graph construction method for the pointer distance assertion includes the following steps: For pointers p and q, the distance from p to q along the next domain is n, then find the corresponding non-dangling nodes of the two pointers p and q on the shape graph, calculate the expression e of the distance from p to q along the next domain, and concatenate e == n to the symbolic assertion of the current subgraph. If p cannot access q along the next domain, delete the current subgraph. If no non-dangling node is found, construct q according to the overall description.

3. The shape graph generation method for volatile data structure program verification according to claim 1, characterized in that: The shape graph construction method corresponding to the refined assertion type also includes a shape graph construction method for user-defined predicates in data assertions, which is to extract basic shape built-in predicates and construct a shape graph based on the extracted basic shape built-in predicates, wherein the extraction method of the basic shape built-in predicates is: Obtaining the dependency relationship between custom predicate parameters, wherein the dependency relationship refers to that, according to the predicate definition description, a predicate pointer parameter is equal to another predicate pointer parameter after at least one pointer domain access; Determine whether each parameter is the header or root of the corresponding shape. If so, determine the basic shape built-in predicate of the custom predicate. Otherwise, proceed to the next step. Take the pointer parameter as the table segment header or tree segment header, obtain the pointer parameter q of each dependent pointer parameter p according to the dependency relationship, and use the theorem prover to obtain the pointer parameter q of the table segment tail or tree segment tail corresponding to the pointer parameter p, and obtain the basic shape of the custom predicate built-in predicate; The method to obtain the dependencies between predicate parameters is: Direct references to parameters and predicates are treated as directed edges of length 0, and pointer field references are treated as directed edges of length 1; According to the graph theory problem solving method, it is solved whether the node corresponding to the parameter has a path with a length greater than 0 to reach other nodes.

4. The shape graph generation method for program verification of a mutable data structure according to claim 1, characterized in that: The process of constructing a shape graph for different assertion types according to a preset optimization order to obtain a preliminary shape graph of the program includes: (71) Generate nodes and pointers to mutable data structures based on all normalized assertions, including: For the pointer path that does not contain a folding domain, construct all the nodes on the path; Added assertion that the pointer folding domain folding times is not less than 0; Check whether the current assertion is contradictory. If it is contradictory, stop constructing the shape graph; Construct shapes based on basic shape built-in predicates; According to each basic shape built-in predicate extracted by the custom predicate, the current shape graph is copied into two copies, one for trying to construct the shape graph and the other for not being used to construct the shape graph, and the subgraph that fails to be constructed is deleted; (72) Restore missing pointer relationships, including: Construct a shape graph based on pointer equality assertions; (73) Delete or modify shape subgraphs that do not conform to the assertion description, including: Construct a shape graph based on pointer distance assertions; Check the condensed nodes on the shape graph. If the condensed nodes form a ring, add an assertion that the total length of the ring is greater than 0. If the condensed nodes form a chain and end with an empty node, add an assertion that the total length of the chain is greater than 0. Construct shape based on pointer equal to null assertion; Check if the current shape graph complies with the shape according to each basic shape built-in predicate extracted by the custom predicate; Construct a shape based on the pointer not equal to null assertion; Construct shapes based on pointer inequality assertions; According to the table and ring length assertion, calculate the corresponding length on the shape graph, and replace the \length predicate in the current subgraph assertion with the corresponding length expression; Check shape based on dangling pointer assertions, removing subgraphs of dangling nodes that are not explicitly declared; Check whether the current assertion is contradictory and remove the contradictory subgraph.

5. The shape graph generation method for program verification of a mutable data structure according to claim 1, characterized in that: For pointer path delooping and pointer alias elimination of non-user-defined predicates, the method adopted is to construct a spanning tree based on the shape graph, replace the pointer path in the data assertion with the path of the node corresponding to the pointer path on the spanning tree, and use the principle that the spanning tree has no loops and the path to any node on the spanning tree is unique to achieve pointer path delooping and alias elimination.

6. The shape graph generation method for volatile data structure program verification according to claim 5, characterized in that: The method for implementing pointer path de-looping and alias elimination by utilizing a spanning tree is as follows: Construct a spanning tree based on the shape graph; According to the longest pointer path prefix without constraint variables in the data assertion, find the unique corresponding node on the spanning tree; Replace the pointer path A in the data assertion with the unique path B of the unique corresponding node on the spanning tree; Save the bidirectional binding between nodes and pointer paths in data assertions, and dynamically maintain the spanning tree.

7. The shape graph generation method for program verification of a mutable data structure according to claim 1, characterized in that: The method of performing correction and optimization based on the initially constructed shape graph to obtain an accurate shape graph further includes: judging whether the predicates asserted before and after the assignment statement are expanded, and the judging method includes: Get the scope described by the predicate; Determine whether the modification of pointer fields or data fields by assignment statements affects the predicate description; If so, perform predicate expansion.

8. The shape graph generation method for program verification of a mutable data structure according to claim 7, characterized in that: The scope of the acquisition predicate description specifically includes: Obtain the domain of the iterated pointer parameter in the predicate and the domain names and types of all domain references that appear, wherein the domain of the iterated pointer parameter is a domain that the parameter may directly access in the predicate according to the predicate definition description, and the domain names and types of the domain references correspond to each other; Starting from the actual parameter of the pointer on the shape graph, take a reference to the iterative domain corresponding to the actual parameter and then recursively take all domain references that appear in the predicate; Get all visited nodes, edges, and data as the scope described by the predicate.

9. The shape graph generation method for program verification of a mutable data structure according to claim 8, characterized in that: The method for obtaining the domain of the pointer parameter iterated in the predicate is: Direct references to parameters and predicates are treated as virtual directed edges, and pointer field references and data field references are treated as real directed edges; The domain of all parameter iterations is obtained by using the solution method in graph theory to solve the types of real edges that can be reached from the nodes corresponding to the parameters.

10. The shape graph generation method for program verification of a mutable data structure according to claim 8, characterized in that: The result of taking a reference to the iterative domain corresponding to the actual parameter and then recursively taking all domain references appearing in the predicate includes: Determine whether the predicate contains the shape of the table segment or tree segment; If it is not included, directly take a reference to the iterative domain corresponding to the actual parameter and then recursively take all domain references that appear in the predicate, otherwise proceed to the next step; If the predicate contains the shape of a table segment or a tree segment, when the actual parameter corresponds to the head of the segment and the recursive reference reaches the node pointed to by the actual parameter corresponding to the end of the segment, the recursion to the end of the segment will no longer continue, and the iteration domain of the segment will be supplemented.

11. The shape graph generation method for program verification of a mutable data structure according to claim 10, characterized in that: The method for iteratively supplementing a segment is: Construct a simplified shape graph based on the shape description in the predicate, record the predicate reference in the predicate definition to the node corresponding to the actual parameter, and record the position of the formal parameter corresponding to the node; For the self-referencing nodes on all nodes in the predicate definition, count all domain references that pass through each parameter domain reference once; After obtaining all the domain references of each parameter's domain reference, search for a domain reference on all branches of the current predicate for each parameter, and then recursively search for all domain references. When recursively searching for all domain references of a self-referencing node, it includes recursive searching through predicate references. Check if there are other parameters that directly point to the found nodes, and all parameters that directly point to these nodes supplement all domain references to the iterated domain.

12. The shape graph generation method for volatile data structure program verification according to claim 11, characterized in that: The counting method for all domain references that pass through each parameter once is: An outgoing edge that passes through a self-reference is recorded as a domain reference. The shape description part pointed to by the outgoing edge recursively obtains all domain references, and all the recursively obtained domain references are recorded under all domain references corresponding to the domain reference of the outgoing edge. For other predicate references on the self-referenced node, obtain the iterated domains and all domain references under other predicates according to the predicate formal parameters corresponding to the node, and add them to all domain references of the corresponding formal parameter domain reference.

13. An electronic device, characterized in that: The electronic device comprises: A memory for storing executable instructions; A processor is used to implement the shape graph generation method for mutable data structure program verification as described in any one of claims 1 to 12 when running the executable instructions stored in the memory.