@@ -107,31 +107,14 @@ Compiler::StaticType LLVMTypeAnalyzer::variableTypeAfterBranch(Variable *var, LL
107107 if (!var || !start)
108108 return previousType;
109109
110- assert (isLoopStart (start) || isIfStart (start) || isElse (start));
111-
112- // Find loop/if statement end or else branch
113- LLVMInstruction *ins = start->next ;
114- int level = 0 ;
110+ LLVMInstruction *end = branchEnd (start);
115111
116- while (ins && !((isLoopEnd (ins) || isIfEnd (ins) || isElse (ins)) && level == 0 )) {
117- if (isLoopStart (ins) || isIfStart (ins))
118- level++;
119- else if (isLoopEnd (ins) || isIfEnd (ins)) {
120- assert (level > 0 );
121- level--;
122- }
123-
124- ins = ins->next ;
125- }
126-
127- if (!ins) {
128- assert (false );
112+ if (!end)
129113 return Compiler::StaticType::Unknown;
130- }
131114
132115 // Process the branch from end
133116 bool write = false ; // only used internally (the compiler doesn't need this)
134- return variableTypeAfterBranchFromEnd (var, ins , previousType, write, visitedInstructions);
117+ return variableTypeAfterBranchFromEnd (var, end , previousType, write, visitedInstructions);
135118}
136119
137120Compiler::StaticType LLVMTypeAnalyzer::variableTypeAfterBranchFromEnd (Variable *var, LLVMInstruction *end, Compiler::StaticType previousType, bool &write, InstructionSet &visitedInstructions) const
@@ -187,6 +170,30 @@ Compiler::StaticType LLVMTypeAnalyzer::variableTypeAfterBranchFromEnd(Variable *
187170 return previousType;
188171}
189172
173+ LLVMInstruction *LLVMTypeAnalyzer::branchEnd (LLVMInstruction *start) const
174+ {
175+ assert (start);
176+ assert (isLoopStart (start) || isIfStart (start) || isElse (start));
177+
178+ // Find loop/if statement end or else branch
179+ LLVMInstruction *ins = start->next ;
180+ int level = 0 ;
181+
182+ while (ins && !((isLoopEnd (ins) || isIfEnd (ins) || isElse (ins)) && level == 0 )) {
183+ if (isLoopStart (ins) || isIfStart (ins))
184+ level++;
185+ else if (isLoopEnd (ins) || isIfEnd (ins)) {
186+ assert (level > 0 );
187+ level--;
188+ }
189+
190+ ins = ins->next ;
191+ }
192+
193+ assert (ins);
194+ return ins;
195+ }
196+
190197LLVMInstruction *LLVMTypeAnalyzer::skipBranch (LLVMInstruction *pos) const
191198{
192199 int level = 0 ;
0 commit comments