# US 12,008,364 B1 · Inconsistency-based bug detection

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 12,008,364 B1
- Document ID: US12008364B1
- Status: Granted
- Kind: B1
- Application number: 17/357,616
- Filed: 2021-06-24
- Granted: 2024-06-11
- Earliest claimed: 2021-06-24
- Assignees: Amazon Technologies, Inc.
- Applicants: Amazon Technologies, Inc.
- Inventors: Hangqi Zhao; Qiang Zhou; Sengamedu Hanumantha Rao Srinivasan
- Web page: https://patentgrep.com/patent/US12008364B1

## CPC

- G06F 8/75: Structural analysis for program understanding
- G06F 8/10: Requirements analysis; Specification techniques
- G06F 40/30: Semantic analysis
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A system identifies a pattern in source code. The pattern is identified based, at least in part, on correlation between units of code, or on the derivation of a rule from a recurring sequence in the source code. The system identifies a portion of the source code that at least partially matches the pattern, and determines that this portion includes at least one deviation from the pattern. The system then generates an error message to describe the deviation.

## Claims

### Claim 1

A computer-implemented method, comprising:
generating a plurality of code units corresponding to a plurality of portions of source code by at least one of a lexical analyzer and a semantic analyzer;
identifying one or more patterns in source code, wherein patterns of two code units are identified based, at least in part, on correlation between two units of code, and patterns of two or more code units are identified based, at least in part, on a rule derived from a recurring sequence in the source code;
determining that a portion of source code matches a part of a pattern and also contains at least one deviation from the pattern; and
generating a message to indicate the portion of the source code contains an error based on the deviation.

### Claim 2 (depends on 1)

The method of claim 1, wherein the correlation between the two units of code comprises a first unit of code followed by a second unit of code, the first and second units of code obtained from a compiler stage.

### Claim 3 (depends on 1)

The method of claim 1, further comprising:
identifying the patterns of two code units based, at least in part, on a bigram comprising a first component corresponding to a first one of the two units of code and a second component corresponding to a second one of the two units of code; and
determining that the portion of source code includes a first code unit that corresponds to the first component, but does not include a second code unit that corresponds to the second component.

### Claim 4 (depends on 1)

The method of claim 1, wherein the unit of code comprises a token.

### Claim 5 (depends on 1)

The method of claim 1, wherein the unit of code comprises a semantic element of a programming language.

### Claim 6 (depends on 1)

The method of claim 1, further comprising:
determining a frequency distribution of a plurality of sequences in the source code; and
deriving the rule based, at least in part, on the frequency distribution.

### Claim 7 (depends on 1)

The method of claim 1, further comprising:
estimating a likelihood that the portion of source code includes an error based, at least in part, on a degree to which the portion of source code deviates from the pattern.

### Claim 8 (depends on 1)

The method of claim 1, wherein the pattern indicates an expected sequence of units of code, the units of code obtained from output of a compiler stage.

### Claim 9 (depends on 1)

The method of claim 1, wherein the message comprises information indicating a location in the source code estimated to contain an error.

### Claim 10

A system, comprising:
one or more processors; and
memory storing instructions that, in response to execution by the one or more processors, cause the system to at least:
generate a plurality of code units corresponding to a plurality of portions of source code by at least one of a lexical analyzer and a semantic analyzer;
identify one or more patterns in source code, wherein patterns of two code units are identified based at least in part on recurrence of a bigram in the source code, and patterns of two or more code units are identified based at least in part on a rule derived from a recurring sequence in the source code;
determine that a portion of the source code at least partially matches a pattern, and that the portion of the source code comprises a deviation from the pattern; and
generate, based at least in part on the deviation, an error message indicating the portion of the source code contains an error.

### Claim 11 (depends on 10)

The system of claim 10, wherein the bigram comprises a first unit of code and a second unit of code, wherein the first unit of code is sequential with the second unit of code.

### Claim 12 (depends on 10)

The system of claim 10, wherein the patterns of two code units indicate that a first unit of code should be followed, in the source code, by a second unit of code, wherein the first and second units of code are components of the bigram.

### Claim 13 (depends on 10)

The system of claim 10, wherein the rule is derived by at least determining a frequency distribution of a plurality of sequences of code units obtained from a compiler stage.

### Claim 14

A non-transitory computer-readable storage medium comprising executable instructions that, as a result of being executed by one or more processors of a computer system, cause the computer system to:
generate a plurality of code units corresponding to a plurality of portions of source code by at least one of a lexical analyzer and a semantic analyzer;
identify one or more patterns in source code, wherein patterns of two code units are identified based, at least in part, on recurrence of a bigram in the source code of the two code units, and patterns of two or more code units are identified based, at least in part, on a rule obtained from a sequence in the source code determined to be recurring;
identify a portion of source code matches at least part of a pattern but comprises at least one deviation from the pattern;
and generate, based at least in part on the at least one deviation, a message to indicate that the portion of the source code contains an error.

### Claim 15 (depends on 14)

The non-transitory computer-readable storage medium of claim 14, wherein the executable instructions further comprise executable instructions that, as a result of being executed by the one or more processors, cause the computer system to:
identify the patterns of the two code units by determining that the bigram recurs with a frequency that is above a threshold amount.

### Claim 16 (depends on 14)

The non-transitory computer-readable storage medium of claim 14, wherein the executable instructions further comprise further executable instructions that, as a result of being executed by the one or more processors, cause the computer system to:
store a bigram comprising an ordered sequence of the two units of code.

### Claim 17 (depends on 14)

The non-transitory computer-readable storage medium of claim 14, wherein the two code units and elements of the sequence each comprise output from a compiler stage.

### Claim 18 (depends on 14)

The non-transitory computer-readable storage medium of claim 14, wherein the executable instructions further comprise executable instructions that, as a result of being executed by the one or more processors, cause the computer system to:
determine a frequency distribution of one or more sequences, the one or more sequences comprising the sequence; and
derive a rule based on the frequency distribution.

### Claim 19 (depends on 14)

The non-transitory computer-readable storage medium of claim 14, wherein the executable instructions further comprise executable instructions that, as a result of being executed by the one or more processors, cause the computer system to:
identify the patterns of two or more code units based at least in part on a frequency with which the sequence occurs in the source code.

### Claim 20 (depends on 14)

The non-transitory computer-readable storage medium of claim 14, wherein the executable instructions further comprise executable instructions that, as a result of being executed by the one or more processors, cause the computer system to:
generate the message to comprise a description of the one or more patterns.
