Skip to content

Commit 059bfd6

Browse files
committed
Compiler: Do not allow null input return values
1 parent 3f79e00 commit 059bfd6

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/engine/compiler.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,22 @@ CompilerValue *Compiler::addInput(Input *input)
259259
impl->block = input->valueBlock();
260260

261261
if (impl->block) {
262-
if (impl->block->compileFunction())
262+
if (impl->block->compileFunction()) {
263263
ret = impl->block->compile(this);
264-
else {
264+
265+
if (!ret) {
266+
std::cout << "warning: the compile function of '" << impl->block->opcode() << "' returns null" << std::endl;
267+
ret = addConstValue(Value());
268+
}
269+
} else {
265270
std::cout << "warning: unsupported reporter block: " << impl->block->opcode() << std::endl;
266271
impl->unsupportedBlocks.insert(impl->block->opcode());
267272
ret = addConstValue(Value());
268273
}
269274
} else
270275
ret = addConstValue(input->primaryValue()->value());
271276

277+
assert(ret);
272278
impl->block = previousBlock;
273279
return ret;
274280
}
@@ -280,16 +286,28 @@ CompilerValue *Compiler::addInput(Input *input)
280286
impl->block = input->valueBlock();
281287

282288
if (impl->block) {
283-
if (impl->block->compileFunction())
289+
if (impl->block->compileFunction()) {
284290
ret = impl->block->compile(this);
285-
else {
291+
292+
if (!ret) {
293+
std::cout << "warning: the compile function of '" << impl->block->opcode() << "' returns null" << std::endl;
294+
ret = addConstValue(Value());
295+
}
296+
} else {
286297
std::cout << "warning: unsupported reporter block: " << impl->block->opcode() << std::endl;
287298
impl->unsupportedBlocks.insert(impl->block->opcode());
288299
ret = addConstValue(Value());
289300
}
290-
} else
301+
} else {
291302
ret = input->primaryValue()->compile(this);
292303

304+
if (!ret) {
305+
std::cout << "warning: input '" << input->name() << "' compiles to null" << std::endl;
306+
ret = addConstValue(Value());
307+
}
308+
}
309+
310+
assert(ret);
293311
impl->block = previousBlock;
294312
return ret;
295313
}

test/compiler/compiler_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,8 @@ TEST_F(CompilerTest, UnsupportedBlocks)
17751775
block4->setParent(block3.get());
17761776
block3->setNext(block4.get());
17771777

1778-
EXPECT_CALL(*m_builder, addConstValue).WillRepeatedly(Return(nullptr));
1778+
CompilerConstant constValue(Compiler::StaticType::Number, 5);
1779+
EXPECT_CALL(*m_builder, addConstValue).WillRepeatedly(Return(&constValue));
17791780
compile(m_compiler.get(), block1.get());
17801781

17811782
// Hat predicates

0 commit comments

Comments
 (0)