Skip to content

Commit

Permalink
Enable sanitizers in dev builds
Browse files Browse the repository at this point in the history
  • Loading branch information
electroly committed Jan 18, 2024
1 parent 6e707f2 commit 42c4f67
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,10 @@ RANLIB=$(LINUX_TRIPLE)-ranlib
STRIP=$(LINUX_TRIPLE)-strip
else
# ubuntu dev container
CC=ccache gcc -fdiagnostics-color=always
CXX=ccache g++ -fdiagnostics-color=always
CC=ccache gcc
CXX=ccache g++
CXXFLAGS += -fdiagnostics-color=always -fsanitize=undefined -fsanitize=address -fsanitize=shift -fsanitize=shift-exponent -fsanitize=shift-base -fsanitize=integer-divide-by-zero -fsanitize=unreachable -fsanitize=null -fsanitize=return -fsanitize=signed-integer-overflow -fsanitize=bounds -fsanitize=object-size -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fsanitize=bool -fsanitize=enum -fsanitize=vptr -fsanitize=pointer-overflow -fsanitize=builtin -fno-sanitize-recover
LDFLAGS += -static-libasan
endif
endif

Expand Down
1 change: 1 addition & 0 deletions src/buildDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ static void forEachFile(const string& path, const function<void(string)>& func)
}
func(entry->d_name);
}
closedir(dir);
}

static string replace(string haystack, const string& needle, const string& replacement) {
Expand Down
5 changes: 5 additions & 0 deletions src/vm/BasicFormsStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ namespace vm {
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
BasicFormsStorage basicFormsStorage{};

void BasicFormsStorage::clear() {
forms.clear();
controls.clear();
}

} // namespace vm
26 changes: 25 additions & 1 deletion src/vm/BasicFormsStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,30 @@ class IdKeyedStorage {
return it->second;
}

void remove(int64_t id) { _map.erase(id); }
void remove(int64_t id) {
if (isClearing) {
return;
}

delete _map[id];
_map.erase(id);
}

bool isClearing = false;

void clear() {
assert(!isClearing);

// They try to remove themselves from the map in their destructors, so set a
// flag that disables that behavior here. We will erase from the map.
isClearing = true;
for (auto& [id, item] : _map) {
delete item;
}
isClearing = false;

_map.clear();
}

protected:
virtual void throwNotFoundError() = 0;
Expand Down Expand Up @@ -47,6 +70,7 @@ class BasicFormsStorage {
inline int64_t nextId() { return _nextId++; }
IdKeyedFormStorage forms{};
IdKeyedControlStorage controls{};
void clear();

private:
int64_t _nextId = 1;
Expand Down
8 changes: 7 additions & 1 deletion src/vm/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "shared/decimal.h"
#include "shared/Error.h"
#include "shared/Opcode.h"
#include "vm/BasicFormsStorage.h"
#include "vm/CallFrame.h"
#include "vm/castObject.h"
#include "vm/constants.h"
Expand Down Expand Up @@ -122,7 +123,11 @@ class InterpreterPrivate {
}

*procedure = callFrame.procedure;
*instructions = &callFrame.procedure->instructions;
if (callFrame.procedure == nullptr) {
*instructions = nullptr;
} else {
*instructions = &callFrame.procedure->instructions;
}
*instructionIndex = callFrame.instructionIndex;

callStack.pop();
Expand All @@ -139,6 +144,7 @@ Interpreter::Interpreter(Program* program, std::istream* consoleInputStream, std

Interpreter::~Interpreter() {
delete _private;
basicFormsStorage.clear();
}

void Interpreter::init(size_t procedureIndex) {
Expand Down

0 comments on commit 42c4f67

Please sign in to comment.