Semantic Equivalence Detection via Control Flow Graph Analysis

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Conventional methods for detecting semantic equivalence between program source codes are inefficient, as they often rely on textual comparisons or exhaustive compilation and execution, failing to identify specific modified portions and requiring extensive computational resources.

Innovation Solution

The method generates structural representations, such as control flow graphs (CFGs), to compare source codes syntactically and semantically, focusing analysis on non-syntactically equivalent sections to reduce computational complexity and identify semantically different code fragments.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Ease of manufacture

If conventional textual comparison methods are used to detect semantic equivalence, then the detection process is simple to implement, but the accuracy and efficiency of identifying semantically different code fragments deteriorates

Engineering Contradiction:
Improveimplementation simplicityVSAvoiddetection accuracy
Core Design Contradiction:
Ease of manufactureVSMeasurement precision

Solution Approach 1:

The patent introduces control flow graphs (CFGs) as an intermediary representation between source code and semantic equivalence detection. The CFG serves as a mediator that captures the semantic structure and execution flow of code, enabling accurate comparison while avoiding direct textual comparison limitations. This intermediary structure allows the system to detect semantic equivalence by comparing CFG properties rather than raw text, resolving the contradiction between implementation simplicity and detection accuracy.

Inventive Principle:
Principle #24Intermediary (Mediator)

Solution Approach 2:

The patent transforms source code into a different parameter representation (control flow graphs with nodes and edges representing program structure and flow). By changing the representation parameters from textual form to graphical structure form, the system enables more accurate semantic comparison. This parameter transformation allows detection of semantic equivalence that textual comparison cannot capture, while the CFG comparison algorithms provide a systematic approach that maintains implementation feasibility.

Inventive Principle:
Principle #35Parameter changes

2Measurement precision

If exhaustive compilation and execution methods are used to detect semantic equivalence, then the detection accuracy is improved, but the computational complexity and resource consumption worsens

Engineering Contradiction:
Improvedetection accuracyVSAvoidcomputational complexity
Core Design Contradiction:
Measurement precisionVSDevice complexity

Solution Approach 1:

The patent segments the source code into basic blocks and represents them as nodes in control flow graphs. This segmentation divides the complex task of comparing entire programs into smaller, manageable units (individual CFG nodes and edges). By comparing CFG structures segment by segment rather than executing entire programs exhaustively, the system achieves accurate semantic equivalence detection with reduced computational complexity. The segmentation allows focused analysis on specific code portions that differ syntactically.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The patent performs preliminary transformation of source code into control flow graphs before conducting semantic equivalence detection. This preliminary action creates a structured representation that captures semantic information without requiring full compilation and execution. By preparing the CFG representation in advance, the system enables efficient comparison operations that avoid the high computational cost of exhaustive execution while maintaining detection accuracy.

Inventive Principle:
Principle #10Preliminary action

3Measurement precision

If comprehensive semantic analysis of entire code fragments is performed, then the detection accuracy is improved, but the analysis time and computational resources worsens

Engineering Contradiction:
Improvedetection accuracyVSAvoidanalysis time
Core Design Contradiction:
Measurement precisionVSLoss of time

Solution Approach 1:

The patent extracts and compares only the control flow graph structures that are necessary for semantic equivalence detection, rather than analyzing entire code fragments comprehensively. By taking out the essential semantic information in the form of CFG nodes and edges, the system achieves accurate detection without the overhead of complete semantic analysis. This extraction approach focuses computational resources on the critical structural elements that determine semantic equivalence.

Inventive Principle:
Principle #2Taking out (Extraction)

Solution Approach 2:

The patent performs partial semantic analysis by comparing control flow graph structures rather than conducting exhaustive semantic analysis of all code aspects. This partial action approach analyzes only the structural and flow-related semantic properties captured in CFGs, which are sufficient for detecting semantic equivalence in many cases. By performing partial rather than complete analysis, the system reduces analysis time while maintaining adequate detection accuracy for practical purposes.

Inventive Principle:
Principle #16Partial or excessive action

Data Source

PatentUS11449317B2Detection of semantic equivalence of program source codes
Publication Date: 2022.09.20 RED HAT INC
  • US11449317B2 patent drawing
  • US11449317B2 patent drawing
  • US11449317B2 patent drawing

AI summary

Implementations of the disclosure provide systems and methods for identifying, in view of a first control flow graph associated with a first code fragment and a second control flow graph associated with a second code fragment, a first set of sections of the first code fragment and a second set of sections of the second code fragment, such that each section of the first set of sections has a corresponding section of the second set of sections. A first section of the first set of sections is identified, where the first section is not syntactically equivalent to a corresponding second section of the second set of sections. Responsive to determining that the first section is not syntactically equivalent to the corresponding second section, it is found that the first code fragment is not semantically equivalent to the second code fragment.