Skip to content

Commit

Permalink
tests: catch O3 compiler bug if present
Browse files Browse the repository at this point in the history
- requires setting `-O3` in env vars if required
- improve gitignores
  • Loading branch information
dch committed Nov 25, 2024
1 parent 8d619fd commit 3a9584e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
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/
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{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"},
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 3a9584e

Please sign in to comment.