Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not use the exception and RTTI optimizations for C #192

Merged
merged 4 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ language: en, en-GB
allowCompoundWords: true
enableGlobDot: true
words:
- awalsh
- pkgs
- aarch
- aminya
- Amnet
Expand Down
13 changes: 8 additions & 5 deletions src/Optimization.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ endmacro()

# Disable C++ exceptions for the given project.
macro(disable_exceptions _project_name)
target_compile_options(${_project_name} INTERFACE $<$<CXX_COMPILER_ID:MSVC>:/EHs-c- /D_HAS_EXCEPTIONS=0>)
target_compile_options(${_project_name} INTERFACE $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-fno-exceptions
-fno-unwind-tables>)
target_compile_options(${_project_name} INTERFACE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/EHs-c-
/D_HAS_EXCEPTIONS=0>)
target_compile_options(
${_project_name} INTERFACE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>:-fno-exceptions
-fno-unwind-tables>)
endmacro()

# Disable C++ RTTI (Run-Time Type Information) for the given project.
macro(disable_rtti _project_name)
target_compile_options(${_project_name} INTERFACE $<$<CXX_COMPILER_ID:MSVC>:/GR->)
target_compile_options(${_project_name} INTERFACE $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-fno-rtti>)
target_compile_options(${_project_name} INTERFACE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/GR->)
target_compile_options(${_project_name}
INTERFACE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>:-fno-rtti>)
endmacro()
4 changes: 2 additions & 2 deletions tests/emscripten/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
#endif

int main() {
printf("hello, world!\n");
return 0;
printf("hello, world!\n");
return 0;
}
4 changes: 2 additions & 2 deletions tests/install/src/another_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
#include <mylib2/lib.hpp>

int main() {
some_fun2();
return some_fun2();
some_fun2();
return some_fun2();
}
4 changes: 2 additions & 2 deletions tests/minimal/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <fmt/core.h>

int main() {
fmt::print("Hello World!");
return 0;
fmt::print("Hello World!");
return 0;
}
12 changes: 6 additions & 6 deletions tests/myproj/include/mylib/lib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
#include <cstring>

int some_fun() {
fmt::print("Hello from fmt{}", "!");
fmt::print("Hello from fmt{}", "!");

// populate an Eigen vector with the values
auto eigen_vec = Eigen::VectorXd::LinSpaced(10, 0, 1);
// populate an Eigen vector with the values
auto eigen_vec = Eigen::VectorXd::LinSpaced(10, 0, 1);

// print the vector
fmt::print("{}", eigen_vec);
// print the vector
fmt::print("{}", eigen_vec);

return 0;
return 0;
}
18 changes: 9 additions & 9 deletions tests/myproj/libs/mythirdpartylib/include/Foo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
namespace mythirdpartylib {

class MYTHIRDPARTYLIB_EXPORT Foo {
public:
Foo() = default;
public:
Foo() = default;

/*implicit*/ Foo(int a) : m_a(a) {}
/*implicit*/ Foo(int a) : m_a(a) {}

int a() const { return m_a; }
int a() const { return m_a; }

void update(bool b, bool c, bool d);
void bad(std::vector<std::string> &v);
void update(bool b, bool c, bool d);
void bad(std::vector<std::string> &v);

private:
int m_a;
private:
int m_a;
};

}// namespace mythirdpartylib
} // namespace mythirdpartylib
20 changes: 10 additions & 10 deletions tests/myproj/libs/mythirdpartylib/src/Foo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
namespace mythirdpartylib {

void Foo::update(bool b, bool c, bool d) {
int e = b + d;
m_a = e;
int e = b + d;
m_a = e;
}

void Foo::bad(std::vector<std::string> &v) {
std::string val = "hello";
int index = -1;// bad, plus should use gsl::index
for (int i = 0; i < v.size(); ++i) {
if (v[i] == val) {
index = i;
break;
}
std::string val = "hello";
int index = -1; // bad, plus should use gsl::index
for (int i = 0; i < v.size(); ++i) {
if (v[i] == val) {
index = i;
break;
}
}
}

static Foo foo(5);
static Foo bar = 42;

}// namespace mythirdpartylib
} // namespace mythirdpartylib
22 changes: 11 additions & 11 deletions tests/myproj/src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
#include <cstring>

int main() {
fmt::print("Hello from fmt{}", "!");
fmt::print("Hello from fmt{}", "!");

Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3);
fmt::print("{}", eigen_vec);
Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3);
fmt::print("{}", eigen_vec);

#if !defined(__MINGW32__) && !defined(__MSYS__)// TODO fails
Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1);
fmt::print("{}", eigen_vec2);
#if !defined(__MINGW32__) && !defined(__MSYS__) // TODO fails
Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1);
fmt::print("{}", eigen_vec2);
#endif

// trigger address sanitizer
// int *p = nullptr;
// *p = 1;
// trigger address sanitizer
// int *p = nullptr;
// *p = 1;

// trigger compiler warnings, clang-tidy, and cppcheck
int a;
// trigger compiler warnings, clang-tidy, and cppcheck
int a;
}
14 changes: 7 additions & 7 deletions tests/myproj/src/mylib2/lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
#include <cstring>

int some_fun2() {
fmt::print("Hello from fmt{}", "!");
fmt::print("Hello from fmt{}", "!");

Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3);
fmt::print("{}", eigen_vec);
Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3);
fmt::print("{}", eigen_vec);

#if !defined(__MINGW32__) && !defined(__MSYS__)// TODO fails
Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1);
fmt::print("{}", eigen_vec2);
#if !defined(__MINGW32__) && !defined(__MSYS__) // TODO fails
Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1);
fmt::print("{}", eigen_vec2);
#endif

return 0;
return 0;
}
4 changes: 2 additions & 2 deletions tests/rpi3/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdio.h>

int main() {
printf("Hello World\n");
return 0;
printf("Hello World\n");
return 0;
}
4 changes: 2 additions & 2 deletions tests/rpi3/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <iostream>

int main() {
std::cout << "Hello World!";
return 0;
std::cout << "Hello World!";
return 0;
}
4 changes: 2 additions & 2 deletions tests/rpi4-vcpkg/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <fmt/core.h>

int main() {
fmt::print("Hello World!");
return 0;
fmt::print("Hello World!");
return 0;
}
4 changes: 2 additions & 2 deletions tests/rpi4/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <iostream>

int main() {
std::cout << "Hello World!";
return 0;
std::cout << "Hello World!";
return 0;
}