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
Build fails with strict-aliasing violations #6245
Comments
The Gentoo ticket links back to some issues here which involved adding -fno-strict-aliasing to the mingw builds to, essentially, "fix problems". From back in the gcc 4.9 days. Compiler diagnostics have come a long way since 2016, so solving this issue may mean you can get rid of that flag for mingw as well... |
Thanks for raising this! Unfortunately this won't be a simple fix. Concerning the casting of the PyrObjects... supercollider/lang/LangSource/PyrKernel.h Line 120 in 28a0b12
PyrMethodRaw takes up two slots, raw1 and raw2 in PyrBlock. I'm pretty sure slicing an object like this is undefined behaviour. I can think of two solutions, either heap allocate PyrMethodRaw, or split it into two classes. Since PyrMethodRaw preserves the tag variable of both slots it spans, attempting to place its data into the union's memory, splitting would be relatively straightforward and have the least performance impact - particularly since the data is just a series of packed shorts and chars that fit into a double word. This (excellent) summary of strict aliasing also suggest the only way to make punnable pointers in c++ is with placement new (or construct_at presumably), which supercollider does not do. https://gist.github.com/shafik/848ae25ee209f698763cffee272a58f8 |
I can't seem to find where the strict aliasing is violated for the calc_slope macro. |
Found it. float arr[10];
decltype(arr[0]); // this is a float&, not a float therefore the cast in (float&)(unit->....) This one is a pretty big bug actually! Some code demonstrating the error. #include <iostream>
#include <cstdint>
#include <string>
template<typename ToType, typename FromValue>
[[nodiscard]] inline constexpr ToType numeric_value_cast_to_type_of(ToType, FromValue value) noexcept {
using TargetT = std::remove_cv_t<std::remove_reference_t<ToType>>;
static_assert(std::is_arithmetic_v<FromValue>);
static_assert(std::is_arithmetic_v<TargetT>);
return static_cast<TargetT>(value);
}
int main() {
double a = 0.1;
float as[4] = {0.0, 0.0, 0.0, 0.0};
float staticcast = numeric_value_cast_to_type_of(as[0], a);
float ccast = (decltype(as[0])) a;
std::cout << "staticcast " << staticcast << " ccast " << ccast << '\n';
// staticcast 0.1 ccast -1.58819e-23
return 0;
} |
I tried to build with the following *FLAGS to optimize the build:
-flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing
The -Werror=* flags are important to detect cases where the compiler can try to optimize based on assuming UB cannot happen, and miscompile code that has UB in it. strict-aliasing issues are always bad but LTO can make them even worse.
I got this error:
Downstream report: https://bugs.gentoo.org/927071
Full build log: build.log
Note the downstream report is reported against 3.13.0 but my local reproducer is against git develop.
The text was updated successfully, but these errors were encountered: