Skip to content

Commit 74161e9

Browse files
committed
LLVMTypeAnalyzer: Ignore query points that write to the variable
1 parent bd0d45e commit 74161e9

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/engine/internal/llvm/llvmtypeanalyzer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Compiler::StaticType LLVMTypeAnalyzer::variableType(
6666
visitedInstructions.insert(pos);
6767

6868
// Check the last write operation before the instruction
69-
const LLVMInstruction *ins = pos;
69+
const LLVMInstruction *ins = pos->previous;
7070
const LLVMInstruction *write = nullptr;
7171
std::pair<const LLVMInstruction *, int> firstBranch = { nullptr, 0 };
7272
std::pair<const LLVMInstruction *, int> firstElseBranch = { nullptr, 0 };

test/llvm/type_analyzer/listtype_test.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ TEST(LLVMTypeAnalyzer_ListType, NoWriteOperationsUnknownType_Empty)
7979
ASSERT_EQ(analyzer.listType(&list, funcCall.get(), Compiler::StaticType::Unknown, true), Compiler::StaticType::Unknown);
8080
}
8181

82+
TEST(LLVMTypeAnalyzer_ListType, QueryPointIsWrite)
83+
{
84+
LLVMTypeAnalyzer analyzer;
85+
LLVMInstructionList instructionList;
86+
List list("", "");
87+
88+
auto appendList = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::AppendToList, nullptr, false);
89+
LLVMConstantRegister value(Compiler::StaticType::Number, 1.25);
90+
appendList->workList = &list;
91+
appendList->args.push_back({ Compiler::StaticType::Unknown, &value });
92+
instructionList.addInstruction(appendList);
93+
94+
ASSERT_EQ(analyzer.listType(&list, appendList.get(), Compiler::StaticType::String, false), Compiler::StaticType::String);
95+
}
96+
8297
TEST(LLVMTypeAnalyzer_ListType, Loop_SingleWriteSameTypeNumber_Before_NonEmpty)
8398
{
8499
LLVMTypeAnalyzer analyzer;

test/llvm/type_analyzer/variabletype_test.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ TEST(LLVMTypeAnalyzer_VariableType, NoWriteOperationsUnknownType)
5555
ASSERT_EQ(analyzer.variableType(&var, funcCall.get(), Compiler::StaticType::Unknown), Compiler::StaticType::Unknown);
5656
}
5757

58+
TEST(LLVMTypeAnalyzer_VariableType, QueryPointIsWrite)
59+
{
60+
LLVMTypeAnalyzer analyzer;
61+
LLVMInstructionList list;
62+
Variable var("", "");
63+
64+
auto setVar = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::WriteVariable, nullptr, false);
65+
LLVMConstantRegister value(Compiler::StaticType::Number, 1.25);
66+
setVar->workVariable = &var;
67+
setVar->args.push_back({ Compiler::StaticType::Unknown, &value });
68+
list.addInstruction(setVar);
69+
70+
ASSERT_EQ(analyzer.variableType(&var, setVar.get(), Compiler::StaticType::Unknown), Compiler::StaticType::Unknown);
71+
}
72+
5873
TEST(LLVMTypeAnalyzer_VariableType, Loop_SingleWriteSameTypeNumber_Before)
5974
{
6075
LLVMTypeAnalyzer analyzer;

0 commit comments

Comments
 (0)