Skip to content

aditya-singh2005/Dead-Code-Analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔍 Dead Code Analyzer (C++)

A high-performance static analysis tool designed to identify redundant code in C/C++ source files. It leverages regex-based pattern matching and basic control flow analysis to detect potential optimizations.

✨ Features

  • Unused Variables: Detects variables that are declared but never used on reachable lines.
  • Unused Functions: Identifies functions that are never called (excluding main).
  • Unreachable Code: Detects code located after return, break, or continue statements within the same scope.
  • Smart Parsing: Handles single-line comments and string literals to avoid false positives.

🚀 Getting Started

Prerequisites

  • GCC/G++ Compiler

Compilation

Build the analyzer using the following command:

g++ main.cpp analyzer.cpp utils.cpp -o analyzer

Usage

Run the analyzer against any C/C++ source file:

./analyzer sample.c

📊 Sample Output

==== Dead Code Analysis Report ====

Unused Variables:
  - b
  - c

Unused Functions:
  - unusedFunction
  - add

Unreachable Code:
  Line 13: b = b + 1; // unreachable

🧠 Concepts

  • Static Program Analysis: Analyzing code without executing it.
  • Dead Code Elimination (DCE): A compiler optimization that removes code which does not affect the program results.
  • Scope-Aware Reachability: Utilizing brace depth tracking to determine control flow boundaries.

Created as a demonstration of compiler-inspired static analysis techniques.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors