aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/test/core_SUITE_data/non_variable_apply.core
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2017-08-07 07:00:14 +0200
committerBjörn Gustavsson <[email protected]>2017-08-07 07:20:29 +0200
commitf59e70ce61913356a67d58e03d6b68c29e983363 (patch)
tree370a0b69f33dc1db37fb79bc249e7402719cb101 /lib/compiler/test/core_SUITE_data/non_variable_apply.core
parent520310feef0d76c0f99447187f3574408b219ae5 (diff)
downloadotp-f59e70ce61913356a67d58e03d6b68c29e983363.tar.gz
otp-f59e70ce61913356a67d58e03d6b68c29e983363.tar.bz2
otp-f59e70ce61913356a67d58e03d6b68c29e983363.zip
sys_core_fold: Fix unsafe optimization of non-variable apply
The sys_core_fold pass would do an unsafe "optimization" when an apply operation did not have a variable in the function position as in the following example: > cat test1.core module 'test1' ['test1'/2] attributes [] 'i'/1 = fun (_f) -> _f 'test1'/2 = fun (_f, _x) -> apply apply 'i'/1 (_f) (_x) end > erlc test1.core no_file: Warning: invalid function call Reported-by: Mikael Pettersson
Diffstat (limited to 'lib/compiler/test/core_SUITE_data/non_variable_apply.core')
-rw-r--r--lib/compiler/test/core_SUITE_data/non_variable_apply.core80
1 files changed, 80 insertions, 0 deletions
diff --git a/lib/compiler/test/core_SUITE_data/non_variable_apply.core b/lib/compiler/test/core_SUITE_data/non_variable_apply.core
new file mode 100644
index 0000000000..d9322cc455
--- /dev/null
+++ b/lib/compiler/test/core_SUITE_data/non_variable_apply.core
@@ -0,0 +1,80 @@
+module 'non_variable_apply' ['module_info'/0,
+ 'module_info'/1,
+ 'non_variable_apply'/0]
+ attributes []
+
+'non_variable_apply'/0 =
+ %% Line 4
+ fun () ->
+ case <> of
+ <> when 'true' ->
+ let <OkFun> =
+ fun (_@c0) ->
+ %% Line 5
+ case _@c0 of
+ <'ok'> when 'true' ->
+ 'ok'
+ ( <_@c1> when 'true' ->
+ ( primop 'match_fail'
+ ({'function_clause',_@c1})
+ -| [{'function_name',{'-non_variable_apply/0-fun-0-',1}}] )
+ -| ['compiler_generated'] )
+ end
+ in let <F> =
+ fun (_@c5,_@c4) ->
+ %% Line 6
+ case <_@c5,_@c4> of
+ <F,X> when 'true' ->
+ apply apply 'id'/1 (F) (X)
+ ( <_@c7,_@c6> when 'true' ->
+ ( primop 'match_fail'
+ ({'function_clause',_@c7,_@c6})
+ -| [{'function_name',{'-non_variable_apply/0-fun-1-',2}}] )
+ -| ['compiler_generated'] )
+ end
+ in %% Line 9
+ apply F
+ (OkFun, 'ok')
+ ( <> when 'true' ->
+ ( primop 'match_fail'
+ ({'function_clause'})
+ -| [{'function_name',{'non_variable_apply',0}}] )
+ -| ['compiler_generated'] )
+ end
+'id'/1 =
+ %% Line 11
+ fun (_@c0) ->
+ case _@c0 of
+ <I> when 'true' ->
+ I
+ ( <_@c1> when 'true' ->
+ ( primop 'match_fail'
+ ({'function_clause',_@c1})
+ -| [{'function_name',{'id',1}}] )
+ -| ['compiler_generated'] )
+ end
+'module_info'/0 =
+ fun () ->
+ case <> of
+ <> when 'true' ->
+ call 'erlang':'get_module_info'
+ ('non_variable_apply')
+ ( <> when 'true' ->
+ ( primop 'match_fail'
+ ({'function_clause'})
+ -| [{'function_name',{'module_info',0}}] )
+ -| ['compiler_generated'] )
+ end
+'module_info'/1 =
+ fun (_@c0) ->
+ case _@c0 of
+ <X> when 'true' ->
+ call 'erlang':'get_module_info'
+ ('non_variable_apply', X)
+ ( <_@c1> when 'true' ->
+ ( primop 'match_fail'
+ ({'function_clause',_@c1})
+ -| [{'function_name',{'module_info',1}}] )
+ -| ['compiler_generated'] )
+ end
+end