Fix the memory leak on Namespace
This commit is contained in:
parent
782c786baf
commit
cb9914f6eb
|
@ -35,9 +35,9 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
|||
# Let's ensure -std=c++xx instead of -std=g++xx
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_CXX_FLAGS_DEBUG
|
||||
"${CMAKE_CXX_FLAGS_DEBUG} -g -fno-omit-frame-pointer -fsanitize=address")
|
||||
"${CMAKE_CXX_FLAGS_DEBUG} -g -fno-omit-frame-pointer $ENV{ASAN_FLAG} -fno-builtin-strlen -ggdb -fno-inline ")
|
||||
set(CMAKE_LINKER_FLAGS_DEBUG
|
||||
"${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
|
||||
"${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer $ENV{ASAN_FLAG}")
|
||||
|
||||
set(CMAKE_CXX_FLAGS_RELEASE
|
||||
"${CMAKE_CXX_FLAGS_RELEASE} -O3")
|
||||
|
|
8
builder
8
builder
|
@ -6,7 +6,7 @@ command=$1
|
|||
export CC=$(which clang)
|
||||
export CXX=$(which clang++)
|
||||
export LDFLAGS="-fuse-ld=lld"
|
||||
|
||||
export ASAN_FLAG="-fsanitize=address"
|
||||
export ASAN_OPTIONS=check_initialization_order=1
|
||||
export LSAN_OPTIONS=suppressions=`pwd`/.ignore_sanitize
|
||||
ROOT_DIR=`pwd`
|
||||
|
@ -67,8 +67,10 @@ function run() {
|
|||
}
|
||||
|
||||
function memcheck() {
|
||||
export ASAN_FLAG=""
|
||||
build
|
||||
pushed_build
|
||||
ctest -T memcheck
|
||||
valgrind --tool=memcheck --leak-check=yes --trace-children=yes $BUILD_DIR/bin/serenec "$@"
|
||||
popd_build
|
||||
}
|
||||
|
||||
|
@ -135,7 +137,7 @@ case "$command" in
|
|||
popd_build
|
||||
;;
|
||||
"memcheck")
|
||||
memcheck
|
||||
memcheck "${@:2}"
|
||||
;;
|
||||
"tests")
|
||||
clean
|
||||
|
|
|
@ -62,7 +62,6 @@ private:
|
|||
bool initialized = false;
|
||||
std::atomic<uint> fn_counter = 0;
|
||||
exprs::Ast tree;
|
||||
mlir::OpBuilder builder;
|
||||
|
||||
public:
|
||||
mlir::StringRef name;
|
||||
|
@ -81,7 +80,6 @@ public:
|
|||
mlir::LogicalResult setTree(exprs::Ast &);
|
||||
uint nextFnCounter();
|
||||
|
||||
mlir::OpBuilder &getBuilder();
|
||||
mlir::ModuleOp &getModule();
|
||||
SereneContext &getContext();
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@ bool Number::classof(const Expression *e) {
|
|||
int Number::toI64() { return std::stoi(this->value); };
|
||||
|
||||
void Number::generateIR(serene::Namespace &ns) {
|
||||
mlir::OpBuilder &builder = ns.getBuilder();
|
||||
mlir::ModuleOp &module = ns.getModule();
|
||||
mlir::OpBuilder builder(&ns.getContext().mlirContext);
|
||||
mlir::ModuleOp &module = ns.getModule();
|
||||
|
||||
auto op = builder.create<serene::slir::ValueOp>(
|
||||
serene::slir::toMLIRLocation(ns, location.start), toI64());
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include "serene/namespace.h"
|
||||
|
||||
#include "mlir/IR/Builders.h"
|
||||
#include "mlir/IR/BuiltinOps.h"
|
||||
#include "serene/context.h"
|
||||
#include "serene/exprs/expression.h"
|
||||
|
@ -43,9 +44,12 @@ namespace serene {
|
|||
|
||||
Namespace::Namespace(SereneContext &ctx, llvm::StringRef ns_name,
|
||||
llvm::Optional<llvm::StringRef> filename)
|
||||
: ctx(ctx), builder(&ctx.mlirContext), name(ns_name),
|
||||
// TODO: Fix the unknown location by pointing to the `ns` form
|
||||
module(mlir::ModuleOp::create(builder.getUnknownLoc(), ns_name)) {
|
||||
: ctx(ctx), name(ns_name)
|
||||
|
||||
{
|
||||
mlir::OpBuilder builder(&ctx.mlirContext);
|
||||
// TODO: Fix the unknown location by pointing to the `ns` form
|
||||
module = mlir::ModuleOp::create(builder.getUnknownLoc(), ns_name);
|
||||
if (filename.hasValue()) {
|
||||
this->filename.emplace(filename.getValue().str());
|
||||
}
|
||||
|
@ -77,7 +81,6 @@ makeNamespace(SereneContext &ctx, llvm::StringRef name,
|
|||
|
||||
uint Namespace::nextFnCounter() { return fn_counter++; };
|
||||
|
||||
mlir::OpBuilder &Namespace::getBuilder() { return this->builder; };
|
||||
mlir::ModuleOp &Namespace::getModule() { return this->module; };
|
||||
SereneContext &Namespace::getContext() { return this->ctx; };
|
||||
|
||||
|
@ -108,6 +111,6 @@ void Namespace::dumpToIR() {
|
|||
m->dump();
|
||||
};
|
||||
|
||||
Namespace::~Namespace() {}
|
||||
Namespace::~Namespace() { this->module.erase(); }
|
||||
|
||||
} // namespace serene
|
||||
|
|
|
@ -23,13 +23,14 @@
|
|||
*/
|
||||
|
||||
#include "mlir/IR/BuiltinOps.h"
|
||||
#include "serene/context.h"
|
||||
#include "serene/namespace.h"
|
||||
#include "serene/reader/location.h"
|
||||
|
||||
namespace serene::slir {
|
||||
::mlir::Location toMLIRLocation(serene::Namespace &ns,
|
||||
serene::reader::Location &loc) {
|
||||
mlir::OpBuilder &builder = ns.getBuilder();
|
||||
mlir::OpBuilder builder(&ns.getContext().mlirContext);
|
||||
auto file = ns.filename;
|
||||
std::string filename{file.getValueOr("REPL")};
|
||||
|
||||
|
|
Loading…
Reference in New Issue