Skip to content

Commit 2c2bf75

Browse files
committed
LLVMTypeAnalyzer: Ignore unknown pre-loop type
1 parent 26b2f6d commit 2c2bf75

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/engine/internal/llvm/llvmtypeanalyzer.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ bool LLVMTypeAnalyzer::variableTypeChangesInLoop(LLVMVariablePtr *varPtr, LLVMIn
5656
if (!varPtr || !loopBody)
5757
return false;
5858

59-
if (preLoopType == Compiler::StaticType::Unknown)
60-
return true;
61-
6259
// Find loop end
6360
LLVMInstruction *ins = loopBody->next;
6461
int loopLevel = 0;
@@ -180,5 +177,9 @@ bool LLVMTypeAnalyzer::typesMatch(LLVMInstruction *ins, Compiler::StaticType exp
180177
/*if (argIns && (argIns->type == LLVMInstruction::Type::ReadVariable || argIns->type == LLVMInstruction::Type::GetListItem))
181178
return isVarOrListTypeSafe(argIns.get(), expectedType, log, c);*/
182179

183-
return (writeValueType(ins) == expectedType);
180+
if (expectedType == Compiler::StaticType::Unknown) {
181+
// Equal unknown types are not considered a match
182+
return false;
183+
} else
184+
return (writeValueType(ins) == expectedType);
184185
}

test/llvm/type_analyzer/variabletypechangesinloop_test.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ TEST(LLVMTypeAnalyzer_VariableTypeChangesInLoop, EmptyLoopUnknownType)
6565
auto end = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::EndLoop, nullptr, false);
6666
list.addInstruction(end);
6767

68-
// Always returns true for unknown type
69-
ASSERT_TRUE(analyzer.variableTypeChangesInLoop(&varPtr, start.get(), Compiler::StaticType::Unknown));
68+
ASSERT_FALSE(analyzer.variableTypeChangesInLoop(&varPtr, start.get(), Compiler::StaticType::Unknown));
7069
}
7170

7271
TEST(LLVMTypeAnalyzer_VariableTypeChangesInLoop, NoWriteOperations)
@@ -232,7 +231,6 @@ TEST(LLVMTypeAnalyzer_VariableTypeChangesInLoop, SingleWriteFromUnknownType)
232231
auto end = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::EndLoop, nullptr, false);
233232
list.addInstruction(end);
234233

235-
// Always returns true for unknown type
236234
ASSERT_TRUE(analyzer.variableTypeChangesInLoop(&varPtr, start.get(), Compiler::StaticType::Number));
237235
}
238236

@@ -256,7 +254,6 @@ TEST(LLVMTypeAnalyzer_VariableTypeChangesInLoop, SingleWriteToUnknownType)
256254
auto end = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::EndLoop, nullptr, false);
257255
list.addInstruction(end);
258256

259-
// Always returns true for unknown type
260257
ASSERT_TRUE(analyzer.variableTypeChangesInLoop(&varPtr, start.get(), Compiler::StaticType::Unknown));
261258
}
262259

@@ -280,7 +277,6 @@ TEST(LLVMTypeAnalyzer_VariableTypeChangesInLoop, SingleWriteUnknownToUnknownType
280277
auto end = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::EndLoop, nullptr, false);
281278
list.addInstruction(end);
282279

283-
// Always returns true for unknown type
284280
ASSERT_TRUE(analyzer.variableTypeChangesInLoop(&varPtr, start.get(), Compiler::StaticType::Unknown));
285281
}
286282

0 commit comments

Comments
 (0)