Skip to content

Commit

Permalink
Fix build / sanitizer warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
MikePopoloski committed Jun 9, 2024
1 parent 780c284 commit 73b79be
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CMAKE_CXX_COMPILER": "clang++-18",
"CMAKE_CXX_FLAGS": "-fsanitize=undefined,address -fno-sanitize-recover=undefined -fno-omit-frame-pointer -fno-common -Wno-deprecated-declarations",
"CMAKE_CXX_FLAGS": "-DSLANG_ASSERT_ENABLED -fsanitize=undefined,address -fno-sanitize-recover=undefined -fno-omit-frame-pointer -fno-common -Wno-deprecated-declarations",
"CMAKE_EXE_LINKER_FLAGS": "-fsanitize=undefined,address -fno-sanitize-recover=undefined",
"CMAKE_SHARED_LINKER_FLAGS": "-fsanitize=undefined,address -fno-sanitize-recover=undefined",
"SLANG_CLANG_TIDY": "clang-tidy-18"
Expand Down
4 changes: 2 additions & 2 deletions include/slang/ast/Compilation.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,10 @@ class SLANG_EXPORT Compilation : public BumpAllocator {
/// @{

/// Registers a system subroutine handler, which can be accessed by compiled code.
void addSystemSubroutine(std::shared_ptr<SystemSubroutine> subroutine);
void addSystemSubroutine(const std::shared_ptr<SystemSubroutine>& subroutine);

/// Registers a type-based system method handler, which can be accessed by compiled code.
void addSystemMethod(SymbolKind typeKind, std::shared_ptr<SystemSubroutine> method);
void addSystemMethod(SymbolKind typeKind, const std::shared_ptr<SystemSubroutine>& method);

/// Gets a system subroutine with the given name, or nullptr if there is no such subroutine
/// registered.
Expand Down
9 changes: 5 additions & 4 deletions source/ast/Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1016,12 +1016,13 @@ void Compilation::addGateType(const PrimitiveSymbol& prim) {
gateMap.emplace(prim.name, &prim);
}

void Compilation::addSystemSubroutine(std::shared_ptr<SystemSubroutine> subroutine) {
subroutineMap.emplace(subroutine->name, std::move(subroutine));
void Compilation::addSystemSubroutine(const std::shared_ptr<SystemSubroutine>& subroutine) {
subroutineMap.emplace(subroutine->name, subroutine);
}

void Compilation::addSystemMethod(SymbolKind typeKind, std::shared_ptr<SystemSubroutine> method) {
methodMap.emplace(std::make_tuple(std::string_view(method->name), typeKind), std::move(method));
void Compilation::addSystemMethod(SymbolKind typeKind,
const std::shared_ptr<SystemSubroutine>& method) {
methodMap.emplace(std::make_tuple(std::string_view(method->name), typeKind), method);
}

const SystemSubroutine* Compilation::getSystemSubroutine(std::string_view name) const {
Expand Down
14 changes: 3 additions & 11 deletions source/ast/expressions/AssertionExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,10 +615,8 @@ std::optional<SequenceRange> SimpleAssertionExpr::computeSequenceLengthImpl() co

if (expr.kind == ExpressionKind::AssertionInstance) {
if (auto& aie = expr.as<AssertionInstanceExpression>(); aie.type->isSequenceType()) {
if (auto aieSeqLength = aie.body.computeSequenceLength();
aieSeqLength.has_value() && (res < aieSeqLength.value())) {
return aieSeqLength.value();
}
if (auto aieSeqLength = aie.body.computeSequenceLength(); res < aieSeqLength)
return aieSeqLength;
}
}
return res;
Expand Down Expand Up @@ -1178,14 +1176,8 @@ std::optional<SequenceRange> BinaryAssertionExpr::computeSequenceLengthImpl() co
const auto rightLenVal = rightLen.value();
return (rightLenVal < leftLenVal) ? leftLenVal : rightLenVal;
}
else if (leftLen.has_value()) {
return leftLen.value();
}
else if (rightLen.has_value()) {
return rightLen.value();
}

return std::nullopt;
return leftLen.has_value() ? leftLen : rightLen;
}

void BinaryAssertionExpr::serializeTo(ASTSerializer& serializer) const {
Expand Down
6 changes: 6 additions & 0 deletions tests/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ if(CMAKE_SYSTEM_NAME MATCHES "Windows")
target_sources(unittests PRIVATE ${PROJECT_SOURCE_DIR}/scripts/win32.manifest)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# Suppress annoying false positive Wstringop-overflow warnings
target_compile_options(unittests PUBLIC "-Wno-stringop-overflow")
target_link_options(unittests PUBLIC "-Wno-stringop-overflow")
endif()

# Copy the data directory for running tests from the build folder.
add_custom_command(
TARGET unittests
Expand Down

0 comments on commit 73b79be

Please sign in to comment.