Skip to content

Commit

Permalink
tests: catch O3 compiler bug if present
Browse files Browse the repository at this point in the history
- force O3
- allow modern compilers instead of C++11
- improve gitignores
  • Loading branch information
dch committed Nov 22, 2024
1 parent 8d619fd commit 9b55512
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ priv
*~
*.swp
compile_commands.json
/.rebar/
4 changes: 2 additions & 2 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{erl_opts, [debug_info, warn_unused_vars, warn_shadow_vars, warn_unused_import]}.
{port_sources, ["c_src/*.cc",
{port_sources, ["c_src/*.cc",
"c_src/snappy/*.cc"]}.
{port_env, [
{"CXXFLAGS", "$CXXFLAGS -DNDEBUG -std=c++11"},
{"CXXFLAGS", "$CXXFLAGS -DNDEBUG -O3"},
{"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin)",
"LDFLAGS", "$LDFLAGS -lstdc++"}
]}.
Expand Down
11 changes: 11 additions & 0 deletions test/snappy_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,14 @@ decompression() ->
?assertEqual({ok, BigData}, snappy:decompress(Compressed3)),
ok.

can_compress_and_decompress_binary_that_triggers_corruption_with_o3_test() ->
% triggers a corruption when compiled with -O3, but not with -O0,
% on OTP25, 26, 27 at least *and* clang18, but not clang16. GCC to be tested.
% See https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=282217 for background.
Doc =[<<"00000000-7fffffff">>],
{ok, C} = snappy:compress(erlang:term_to_binary(Doc)),
true = snappy:is_valid(C),
{ok, U} = snappy:decompress(C),
New = erlang:binary_to_term(U),
?assertEqual(Doc, New),
ok.

0 comments on commit 9b55512

Please sign in to comment.