Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:24
erlang
0197-beam_call_types-Correct-optimization-of-se...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0197-beam_call_types-Correct-optimization-of-setelement-3.patch of Package erlang
From dfc5d7dfbf3fa0e0333d325e01f064be08b35c68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org> Date: Fri, 25 Mar 2022 08:46:38 +0100 Subject: [PATCH] beam_call_types: Correct optimization of setelement/3 2ea04617d18bc3 introduced a bug in the handling of calls to `setelement/3`. Consider this module: -module(bug). -export([bug/0]). bug() -> set(2, {a,b}), set(3, {a,b}). set(Pos, Tuple) -> setelement(Pos, Tuple, something). The second call to `set/2` will fail because the position is `3` is beyond the end of the tuple. Because of that failed call, the compiler would incorrectly assume that the call to `setelement/3` in `set/2` would always fail, and there would be a very confusing exception: 1> bug:bug(). ** exception error: no true branch found when evaluating an if expression in function bug:set/2 (bug.erl, line 8) This commit fixes the bug. With this bug fix, the exception will look like: 4> bug:bug(). ** exception error: bad argument in function setelement/3 called as setelement(3,{a,b},something) *** argument 1: out of range in call from bug:set/2 (bug.erl, line 9) --- lib/compiler/src/beam_call_types.erl | 13 +++++++++---- lib/compiler/test/beam_type_SUITE.erl | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/compiler/test/beam_type_SUITE.erl b/lib/compiler/test/beam_type_SUITE.erl index fcd2c1c915..ca072a89e5 100644 --- a/lib/compiler/test/beam_type_SUITE.erl +++ b/lib/compiler/test/beam_type_SUITE.erl @@ -396,6 +396,15 @@ tuple(_Config) -> [] = [X || X <- [], #bird{b = b} == {bird,X}], [] = [X || X <- [], 3 == X#bird.a], + Counters0 = id({0,0,0}), %Inexact size. + {1,0,0} = Counters1 = increment_element(1, Counters0), + {1,1,0} = increment_element(2, Counters1), + + Counters10 = {id(0),id(0),id(0)}, %Exact size. + {0,-1,0} = decrement_element(2, Counters10), + {0,0,-1} = decrement_element(3, Counters10), + {'EXIT',{badarg,_}} = catch decrement_element(4, Counters10), + ok. do_tuple() -> @@ -407,6 +416,14 @@ do_literal_tuple_1(X) -> do_tuple() -> {0, _} = {necessary}. +increment_element(Pos, Cs) -> + Ns = element(Pos, Cs), + setelement(Pos, Cs, Ns + 1). + +decrement_element(Pos, Cs) -> + Ns = element(Pos, Cs), + setelement(Pos, Cs, Ns - 1). + -record(x, {a}). record_float(_Config) -> -- 2.34.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor