aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/test/warnings_SUITE.erl
AgeCommit message (Collapse)Author
2018-09-21Update copyright yearHenrik Nord
2018-07-06Call test_lib:recompile/1 from init_per_suite/1Björn Gustavsson
Call test_lib:recompile/1 from init_per_suite/1 instead of from all/0. That makes it easy to find the log from the compilation in the log file for the init_per_suite/1 test case.
2017-06-14Update copyright yearHans Nilsson
2017-06-07Fix unsafe bit syntax matching optimizationBjörn Gustavsson
As part of sys_core_fold, variables involved in bit syntax matching would be annotated when it would be safe for a later pass to do the delayed sub-binary creation optimization. An implicit assumption regarding the annotation was that the code must not be further optimized. That assumption was broken in 05130e48555891, which introduced a fixpoint iteration (applying the optimizations until there were no more changes). That means that a variable could be annotated as safe for reusing the match context in one iteration, but a later iteration could rewrite the code in a way that would make the optimization unsafe. One way to fix this would be to clear all reuse_for_context annotations before each iteration. But that would be wasteful. Instead I chose to fix the problem by moving out the annotation code to a separate pass (sys_core_bsm) that is run later after all major optimizations of Core Erlang has been done.
2016-11-28Merge branch 'egil/compiler/maps-warn-repeated-keys/OTP-14058'Björn-Egil Dahlberg
* egil/compiler/maps-warn-repeated-keys/OTP-14058: compiler: Test repeated map key warnings compiler: Warn for repeated identical map keys
2016-11-23compiler: Test repeated map key warningsBjörn-Egil Dahlberg
2016-11-23Merge branch 'maint'Björn Gustavsson
* maint: Update primary bootstrap document {yield/nb_yield}() limitation Suppress warnings from v3_kernel when inlining is turned on
2016-11-18Suppress warnings from v3_kernel when inlining is turned onBjörn Gustavsson
v3_kernel may produce unwanted and confusing warnings for code that has been inlined with the new inliner (cerl_inline). Consider this code: -compile(inline). compute1(X) -> add(X, 0). compute2(X, Y) -> add(X, Y). add(1, 0) -> 1; add(1, Y) -> %% "this clause cannot match..." 1 + Y; add(X, Y) -> X + Y. v3_kernel warns because add/2 has been inlined into compute1/1 and only the first clause in add/2 will match. But the other clauses are needed when add/2 is inlined into compute2/2, so the user cannot do anything to eliminate the warning (short of manually inlining add/2, defeating the purpose of the 'inline' option). The warning would be reasonable if compute2/2 didn't exist, but it would be too complicated for the compiler to figure whether a warning make sense or not. Therefore, suppress all warnings generated by v3_kernel if cerl_inline has been run. ERL-301
2016-10-28sys_core_fold: Eliminate complaint from core_lintBjörn Gustavsson
2016-03-15update copyright-yearHenrik Nord
2016-02-26Merge branch 'bjorn/compiler/modernize-tests'Björn Gustavsson
* bjorn/compiler/modernize-tests: Remove ?line macros Replace use of lists:keysearch/3 with lists:keyfind/3 Eliminate use of doc and suite clauses Replace ?t with test_server Replace use of test_server:format/2 with io:format/2 Eliminate use of test_server:fail/0,1 Eliminate use of ?config() macro Modernize use of timetraps Eliminate useless helper functions
2016-02-25Remove ?line macrosBjörn Gustavsson
2016-02-25Replace use of test_server:format/2 with io:format/2Björn Gustavsson
There is no practial difference.
2016-02-25Eliminate use of test_server:fail/0,1Björn Gustavsson
2016-02-25Eliminate use of ?config() macroBjörn Gustavsson
?config is ugly and not recommended. Use proplists:get_value/2 instead.
2016-02-25Modernize use of timetrapsBjörn Gustavsson
Either rely on the default 30 minutes timetrap, or set the timeout using the supported methods in common_test.
2016-02-25Produce warnings for binary patterns that will never matchBjörn Gustavsson
Binary matching can be confusing. For example: 1> <<-1>> = <<-1>>. ** exception error: no match of right hand side value <<"ÿ">> 2> When constructing binaries, the value will be masked to fit in the binary segment. But no such masking happens when matching binaries. One solution that we considered was to do the same masking when matching. We have rejected that solution for several reasons: * Masking in construction is highly controversial and by some people considered a bad design decision. * While masking of unsigned numbers can be understood, masking of signed numbers it not easy to understand. * Then there is the question of backward compatibility. Adding masking to matching would mean that clauses that did not match earlier would start to match. That means that code that has never been tested will be executed. Code that has not been tested will usually not work. Therefore, we have decided to warn for binary patterns that cannot possibly match. While we are it, we will also warn for the following example where size for a binary segment is invalid: bad_size(Bin) -> BadSize = bad_size, <<42:BadSize>> = Bin. That example would crash the HiPE compiler because the BEAM compiler would generate a bs_get_integer2 instruction with an invalid size field. We can avoid that crash if sys_core_fold not only warns for bad binary pattern, but also removes the clauses that will not match. Reported-by: http://bugs.erlang.org/browse/ERL-44 Reported-by: Kostis Sagonas
2016-02-17Eliminate use of test_server.hrl and test_server_line.hrlBjörn Gustavsson
As a first step to removing the test_server application as as its own separate application, change the inclusion of test_server.hrl to an inclusion of ct.hrl and remove the inclusion of test_server_line.hrl.
2015-06-18Change license text to APLv2Bruce Yinhe
2015-06-04Merge branch 'bjorn/compiler/spurious-warning'Björn Gustavsson
* bjorn/compiler/spurious-warning: sys_core_fold: Eliminate warnings for unused terms in effect context sys_core_fold: Eliminate warnings for unused terms
2015-05-22sys_core_fold: Eliminate warnings for unused terms in effect contextBjörn Gustavsson
The optimization introduced in 0a0d39d351fc could cause spurious warnings of the type: "a term is constructed, but never used". That would happen for constructs in effect context. To avoid those warnings, we will need to apply warning suppression also in effect context.
2015-05-21compiler: Add tests for beam_bsm get_map_elementsBjörn-Egil Dahlberg
2015-05-13sys_core_fold: Eliminate warnings for unused termsBjörn Gustavsson
The optimization introduced in 0a0d39d351fc would cause spurious warnings of the type: "a term is constructed, but never used". To avoid the warning, we must mark not only tuples and lists as compiler_generated, but also each element. We must also propagate compiler_generated annotations in lets. For example, if we have: let <X -| ['compiler_generated']> = 42 in X + 1 we must propagate the compiler_generated annotation to the literal when do constant propagation: 42 -| ['compiler_generated'] + 1
2015-04-29sys_core_fold: Suppress warnings betterBjörn Gustavsson
86fbd6d76d strengthened type optimization in lets. As a result of the stronger optimizations, special care had to be taken to suppress false warnings. It turns out that false warnings can still slip through. Slapping on a 'compiler_generated' annotation at the top-level of a complex term such as #c_tuple{} may not suppress all warnings. We will need to go deeper into the term to eliminate all warnings.
2015-04-15Raise more descriptive error messages for failed map operationsBjörn Gustavsson
According to EEP-43 for maps, a 'badmap' exception should be generated when an attempt is made to update non-map term such as: <<>>#{a=>42} That was not implemented in the OTP 17. José Valim suggested that we should take the opportunity to improve the errors coming from map operations: http://erlang.org/pipermail/erlang-questions/2015-February/083588.html This commit implement better errors from map operations similar to his suggestion. When a map update operation (Map#{...}) or a BIF that expects a map is given a non-map term, the exception will be: {badmap,Term} This kind of exception is similar to the {badfun,Term} exception from operations that expect a fun. When a map operation requires a key that is not present in a map, the following exception will be raised: {badkey,Key} José Valim suggested that the exception should be {badkey,Key,Map}. We decided not to do that because the map could potentially be huge and cause problems if the error propagated through links to other processes. For BIFs, it could be argued that the exceptions could be simply 'badmap' and 'badkey', because the bad map and bad key can be found in the argument list for the BIF in the stack backtrace. However, for the map update operation (Map#{...}), the bad map or bad key will not be included in the stack backtrace, so that information must be included in the exception reason itself. For consistency, the BIFs should raise the same exceptions as update operation. If more than one key is missing, it is undefined which of keys that will be reported in the {badkey,Key} exception.
2015-03-09sys_core_fold: Strengthen type optimization in letsBjörn Gustavsson
Make sure that we take extract all possible type information when optimizing a 'let' construct. Since the stronger optimization may generate false warnings, we also need to take special care to suppress false warnings.
2015-03-09v3_core: Add is_map tests before map instructionsBjörn Gustavsson
If we have a sequence of put_map_* instructions operating on the same map, it will be more efficient if we can have one is_map/2 instruction before put_map_* instructions, so that each put_map_* does not need to test whether the argument is a map.
2015-02-03sys_core_fold: Optimize let statements more aggressivelyBjörn Gustavsson
I originally decided that in 'value' context, rewriting a let statement where the variables were not in the body to a sequence was not worth it, because the variables would be unused in only one let in a thousand lets (roughly). I have reconsidered. The main reason is that if we do the rewrite, core_lib:is_var_used/2 will be used much more frequently, which will help us to find bugs in it sooner. Another reason is that the way letify/2 is currently implemented with its own calls to core_lib:is_var_used/2 is only safe as long as all the bindings are independent of each other. We could make letify/2 smarter, but if we introduce this new optimization there is no need. Measuring compilation speed, I have not seen any significant slowdown. It seems that although core_lib:is_var_used/2 is called much more frequently, most calls will be fast because is_var_used/2 will quickly find a use of the variable. Also add a test case to cover a line opt_guard_try/1 that was no longer covered.
2015-02-03Suppress warnings for expressions that are assigned to '_'Björn Gustavsson
In c34ad2d5, the compiler learned to silence some warnings for expressions that were explicitly assigned to the '_' variable, as in this example: _ = list_to_integer(S), ok That commit intentionally only made it possible to silence warnings for BIFs that could cause an exception. Warnings would still be produced for: _ = date(), ok because date/0 can never fail and thus making the call completely useless. The reasoning was that such warnings can always be eliminated by eliminating the offending code. While that is true, there is the question about rules and their consistency. It is surprising that '_' can be used to silence some warnings, but has no effect on other warnings. Therefore, we will teach the compiler to silence warnings for the following constructs: * Calls to safe BIFs such as date/0 * Expressions that will cause an exception such as 'X/0' * Terms that are built but not used, such as '{x,X}'
2015-01-26warnings_SUITE: Eliminate compiler warning for a shadowed variableBjörn Gustavsson
2014-08-26compiler: Update Map testsBjörn-Egil Dahlberg
2014-06-16Fix handling of latin1 characters in false ifdef branchesBjörn Gustavsson
The fallback to latin-1 encoding would not work if the invalid UTF-8 characters occurred in a skipped branch in an -ifdef/-ifndef.
2014-03-25compiler: Throw 'nomatch' on matching with bad binary keysBjörn-Egil Dahlberg
Even if a binary key is written as a literal the compiler may choose to make an expression. Emit a warning in those cases and saying the case will not match. This is a limitation in current implementation.
2014-03-25compiler: Strengthen Maps warnings testsBjörn-Egil Dahlberg
Increases coverage.
2014-03-18Don't fail compilation for modules that contain invalid UTF-8Björn Gustavsson
The default encoding for Erlang modules is now UTF-8, and the compilation would fail if a module contained byte sequences that are not valid UTF-8 sequences. In a large project with say many hundreds of Erlang modules with names of developers such as "Björn" or "Håkan" encoded in latin-1, that could mean that many hundreds of files would need to be modified just to get started testing OTP 17. As a temporary measure to ease the transition, automatically fall back to the latin-1 encoding with a warning for any module that contains invalid byte sequences and for which no encoding has been specified. The intention is to remove this workaround in OTP 18 or 19.
2014-03-10Properly handle redundant boolean clauses in sys_core_foldAnthony Ramine
Boolean case expressions with redundant clauses could make the compiler crash: case X == 0 of false -> no; false -> no; true -> yes end. Reported-by: Ulf Norell
2014-03-04Support maps in cerl_clauses:match/2Anthony Ramine
Without this, sys_core_fold could crash on non-matching clauses using maps patterns. Reported-by: Ulf Norell
2014-01-30Issue a warning when a named fun is constructed but not usedBjörn Gustavsson
2014-01-16Generalize optimizations of case statementsBjörn Gustavsson
Case expressions such as: case {Expr1,Expr} of {V1,V2} -> ... end are already optimized to not actually build the tuple. Generalize the optimization to avoid building any kind of composite term, such as: case {ok,[A,B]} of {ok,[X,Y]} -> ... end We don't expect programmers to write such code directly, but inlining can produce such code. We need to be careful about the warnings we produce. If the case expression is a literal, it is expected that no warnings should be produced for clauses that don't match. We must make sure that we continue to suppress those warnings.
2013-06-07Silence a misleading warning with some comprehensionsAnthony Ramine
When compiling comprehensions with generators which are foldable to 'true', a misleading warning is emitted by sys_core_fold because a clause resulting from the compilation of the comprehension to Core Erlang is not marked as generated by the compiler. An example of such a comprehension is [ true || true ].
2013-01-25Update copyright yearsBjörn-Egil Dahlberg
2012-10-23compiler: Run testcases in parallelBjörn Gustavsson
Run testcases in parallel will make the test suite run slightly faster. Another reason for this change is that we want more testing of parallel testcase support in common_test.
2011-04-12compiler tests: Reinstate ?MODULE macro in calls to test_lib:recompile/1Björn Gustavsson
In 3d0f4a3085f11389e5b22d10f96f0cbf08c9337f (an update to conform with common_test), in all test_lib:recompile(?MODULE) calls, ?MODULE was changed to the actual name of the module. That would cause test_lib:recompile/1 to compile the module with the incorrect compiler options in cloned modules such as record_no_opt_SUITE, causing worse coverage.
2011-03-25sys_core_fold: Eliminate incorrect warningBjörn Gustavsson
The compiler (sys_core_fold) tries to avoid constructing tuples in case expressions. The following code: c(A, B) -> case {A,B} of {ok,X} -> X; {_,_} -> error end. will be rewritten so that no tuple is built. If a clause requires a tuple to be built as in this code: c(A, B) -> case {A,B} of {ok,X} -> X; V -> V %The tuple will be built here end. the tuple will be built in the clause(s) in which it is needed. If the value returned from the case is not used as in this code: c(A, B) -> case {A,B} of V -> V %Warning: a term is constructed, but never used end, ok. there will be an incorrect warning. Basically, what happens is that the code is reduced to: c(A, B) -> {A,B}, %Warning: a term is constructed, but never used ok. and the optimizer sees that the {A,B} tuple can't possibly be used. Eliminate the warning by adding a 'compiler_generated' annotation to the tuple. Reported-by: Kostis Sagonas
2011-03-11Update copyright yearsBjörn-Egil Dahlberg
2011-02-17Rename Suite Callback to Common Test HookLukas Larsson
2011-02-17Fix formatting for compilerLukas Larsson
2011-02-17Add init_per_suite and end_per_suiteLukas Larsson
2011-02-17Add ts_install_scb to suite/0Lukas Larsson
2011-02-17Update compiler tests to conform with common_test standardLukas Larsson