From 064889dfe2d2b8abd572ca5622eafb62dcd1214c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 17 Aug 2023 11:53:53 +0200 Subject: [PATCH] Eliminate consistency failure for non-matching binary pattern Fixes #7467 --- lib/compiler/src/beam_validator.erl | 5 ++--- lib/compiler/test/bs_match_SUITE.erl | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/compiler/src/beam_validator.erl b/lib/compiler/src/beam_validator.erl index 217b7a2c979b..555ccc113263 100644 --- a/lib/compiler/src/beam_validator.erl +++ b/lib/compiler/src/beam_validator.erl @@ -1720,9 +1720,8 @@ validate_bs_match([I|Is], Ctx, Unit0, Vst0) -> Vst1 = update_bs_unit(Ctx, Unit, Vst0), Vst = update_type(fun meet/2, Type, Ctx, Vst1), validate_bs_match(Is, Ctx, Unit, Vst); - {ensure_exactly,Stride} -> - Vst = advance_bs_context(Ctx, Stride, Vst0), - validate_bs_match(Is, Ctx, Unit0, Vst); + {ensure_exactly,_Stride} -> + validate_bs_match(Is, Ctx, Unit0, Vst0); {'=:=',nil,Bits,Value} when Bits =< 64, is_integer(Value) -> validate_bs_match(Is, Ctx, Unit0, Vst0); {Type0,Live,{literal,Flags},Size,Unit,Dst} when Type0 =:= binary; diff --git a/lib/compiler/test/bs_match_SUITE.erl b/lib/compiler/test/bs_match_SUITE.erl index dd47641c2d78..b24f1afdd8e5 100644 --- a/lib/compiler/test/bs_match_SUITE.erl +++ b/lib/compiler/test/bs_match_SUITE.erl @@ -2722,6 +2722,8 @@ bs_match(_Config) -> {'EXIT',{{case_clause,_},_}} = catch do_bs_match_gh_6755(id(<<"1000">>)), + {'EXIT',{{badmatch,<<>>},_}} = catch do_bs_match_gh_7467(<<>>), + ok. do_bs_match_1(_, X) -> @@ -2793,6 +2795,9 @@ do_bs_match_gh_6755(B) -> <<"b">> -> b end. +do_bs_match_gh_7467(A) -> + do_bs_match_gh_7467(<<_:1/bits>> = A). + %% GH-6348/OTP-18297: Allow aliases for binaries. -record(ba_foo, {a,b,c}).