GCC Code Coverage Report


Directory: src/
File: src/analysis/analysis-unreachable.cpp
Date: 2025-10-15 09:43:47
Exec Total Coverage
Lines: 20 26 76.9%
Functions: 3 4 75.0%
Branches: 9 10 90.0%

Line Branch Exec Source
1 #include <gyoji-analysis.hpp>
2 #include <stdio.h>
3
4 using namespace Gyoji::mir;
5 using namespace Gyoji::context;
6 using namespace Gyoji::analysis;
7
8 30 AnalysisPassUnreachable::AnalysisPassUnreachable(CompilerContext & _compiler_context)
9 60 : AnalysisPass(_compiler_context, "unreachable analysis")
10 30 {}
11 AnalysisPassUnreachable::~AnalysisPassUnreachable()
12 {}
13
14 void
15 30 AnalysisPassUnreachable::check(const MIR & mir) const
16 {
17
2/2
✓ Branch 7 taken 266 times.
✓ Branch 8 taken 30 times.
296 for (const auto & function : mir.get_functions().get_functions()) {
18 266 check(*function);
19 }
20 30 }
21
22 266 void AnalysisPassUnreachable::check(const Function & function) const
23 {
24 266 const auto & blocks = function.get_blocks();
25
2/2
✓ Branch 5 taken 362 times.
✓ Branch 6 taken 266 times.
628 for (const auto & block_it : blocks) {
26 362 const BasicBlock & block = *block_it.second;
27 362 const std::vector<Gyoji::owned<Operation>> & operations = block.get_operations();
28
29 362 bool terminated = false;
30
2/2
✓ Branch 5 taken 3994 times.
✓ Branch 6 taken 362 times.
4356 for (const auto & operation_it : operations) {
31 3994 const Operation & operation = *operation_it;
32 // We found an operation after we found a terminator.
33
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3994 times.
3994 if (terminated) {
34 get_compiler_context()
35 .get_errors()
36 .add_simple_error(operation.get_source_ref(),
37 "Unreachable Statement",
38 "Unreachable statement"
39 );
40 break;
41 }
42 // We found a terminating operation.
43
2/2
✓ Branch 1 taken 362 times.
✓ Branch 2 taken 3632 times.
3994 if (operation.is_terminating()) {
44 362 terminated = true;
45 362 continue;
46 }
47 }
48 }
49 266 }
50