Skip to content

Commit

Permalink
Fixed memory bug with unary operators
Browse files Browse the repository at this point in the history
  • Loading branch information
ange-yaghi committed Sep 14, 2020
1 parent 453f54f commit 8450a59
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/version.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef PIRANHA_VERSION_H
#define PIRANHA_VERSION_H

#define PIRANHA_VERSION "v0.0.9a"
#define PIRANHA_VERSION "v0.0.10a"

#endif /* PIRANHA_VERSION_H */
3 changes: 2 additions & 1 deletion src/ir_unary_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "../include/ir_compilation_unit.h"
#include "../include/ir_attribute.h"
#include "../include/ir_attribute_list.h"
#include "../include/ir_value_constant.h"
#include "../include/memory_tracker.h"

piranha::IrUnaryOperator::IrUnaryOperator(Operator op, IrValue *operand) : IrValue(IrValue::UNARY_OPERATION) {
Expand Down Expand Up @@ -80,7 +81,7 @@ void piranha::IrUnaryOperator::_expand(IrContextTree *context) {

// Generate the expansion
IrAttribute *attribute = TRACK(new IrAttribute());
attribute->setValue(m_operand);
attribute->setValue(TRACK(new IrInternalReference(m_operand, context)));

IrAttributeList *attributeList = TRACK(new IrAttributeList());
attributeList->addAttribute(attribute);
Expand Down
22 changes: 22 additions & 0 deletions test/operator_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ TEST(IrOperatorTests, IrOperatorTest6) {
}

TEST(IrOperatorTests, IrOperatorTest7) {
MemoryTracker::get()->reset();

const ErrorList *errList;
Compiler *compiler;
IrCompilationUnit *unit = compileToUnit("operator-tests/operator_test_7.mr", &errList, nullptr, &compiler);
Expand All @@ -295,6 +297,8 @@ TEST(IrOperatorTests, IrOperatorTest7) {
}

TEST(IrOperatorTests, IrOperatorTest8) {
MemoryTracker::get()->reset();

const ErrorList *errList;
LanguageRules *rules;
Compiler *compiler;
Expand All @@ -319,3 +323,21 @@ TEST(IrOperatorTests, IrOperatorTest8) {

EXPECT_EQ(MemoryTracker::get()->countLeaks(), 0);
}

TEST(IrOperatorTests, IrOperatorTest9) {
MemoryTracker::get()->reset();

const ErrorList *errList;
Compiler *compiler;
IrCompilationUnit *unit = compileToUnit("operator-tests/operator_test_9.mr", &errList, nullptr, &compiler);

EXPECT_EQ(errList->getErrorCount(), 0);

NodeProgram program;
unit->build(&program);

program.free();
compiler->free();

EXPECT_EQ(MemoryTracker::get()->countLeaks(), 0);
}
8 changes: 8 additions & 0 deletions test/sdl/operator-tests/operator_test_9.mr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
private import "operators.mr" as operators

node test {
input __in;
output __out: -__in; // InvalidOperandTypes
}

test test1(0.5)
5 changes: 5 additions & 0 deletions test/sdl/operator-tests/operators.mr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public inline node float_add => __piranha__float_add {
alias output __out [float];
}

public inline node float_negate => __piranha__float_negate {
input __in;
alias output __out [float];
}

public inline node string_add => __piranha__string_add {
input __in0;
input __in1;
Expand Down
8 changes: 4 additions & 4 deletions test/test_rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,18 @@ void TestRules::registerBuiltinNodeTypes() {
"__piranha__vector_positive"
);

// NEGATIVE
// NEGATE
registerUnaryOperator(
{ piranha::IrUnaryOperator::Operator::NumericNegate, &piranha::FundamentalType::IntType },
"__piranha__int_negative"
"__piranha__int_negate"
);
registerUnaryOperator(
{ piranha::IrUnaryOperator::Operator::NumericNegate, &piranha::FundamentalType::FloatType },
"__piranha__float_negative"
"__piranha__float_negate"
);
registerUnaryOperator(
{ piranha::IrUnaryOperator::Operator::NumericNegate, &piranha::FundamentalType::VectorType },
"__piranha__vector_negative"
"__piranha__vector_negate"
);

// INVERT
Expand Down

0 comments on commit 8450a59

Please sign in to comment.