summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/numerics/rand
Commit message (Collapse)AuthorAgeFilesLines
* [libc++] Fix potential OOB in poisson_distributionLouis Dionne2019-11-072-1/+74
| | | | | See details in the original Chromium bug report: https://bugs.chromium.org/p/chromium/issues/detail?id=994957
* [libc++] Fix broken <random> testLouis Dionne2019-08-221-16/+23
| | | | | | | | | | | | In r369429, I hoisted a floating point computation to a variable in order to remove a warning. However, it turns out this doesn't play well with floating point arithmetic. This commit reverts r369429 and instead casts the result of the floating point computation to remove the warning. Whether hoisting the computaiton to a variable should give the same result can be investigated independently. llvm-svn: 369693
* [libc++] Avoid implicit conversion warning in a <random> testLouis Dionne2019-08-201-23/+16
| | | | | | | | | | By stashing the computation of `E::max() - E::min()` in a variable, we avoid the warning introduced in r367497. Note that we use `auto` to avoid having to deduce the type of the computation, which is not a problem since Clang provides `auto` as an extension even in C++03 (and we disable warnings related to using C++11 extensions in the test suite). llvm-svn: 369429
* Add include for 'test_macros.h' to all the tests that were missing them. ↵Marshall Clow2019-05-31463-0/+925
| | | | | | Thanks to Zoe for the (big, but simple) patch. NFC intended. llvm-svn: 362252
* [libc++] Remove unnecessary <iostream> #includes in testsLouis Dionne2019-03-284-8/+0
| | | | | | | Some tests #include <iostream> but they don't use anything from the header. Those are probably artifacts of when the tests were developped. llvm-svn: 357181
* Support tests in freestandingJF Bastien2019-02-04495-495/+1485
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Freestanding is *weird*. The standard allows it to differ in a bunch of odd manners from regular C++, and the committee would like to improve that situation. I'd like to make libc++ behave better with what freestanding should be, so that it can be a tool we use in improving the standard. To do that we need to try stuff out, both with "freestanding the language mode" and "freestanding the library subset". Let's start with the super basic: run the libc++ tests in freestanding, using clang as the compiler, and see what works. The easiest hack to do this: In utils/libcxx/test/config.py add: self.cxx.compile_flags += ['-ffreestanding'] Run the tests and they all fail. Why? Because in freestanding `main` isn't special. This "not special" property has two effects: main doesn't get mangled, and main isn't allowed to omit its `return` statement. The first means main gets mangled and the linker can't create a valid executable for us to test. The second means we spew out warnings (ew) and the compiler doesn't insert the `return` we omitted, and main just falls of the end and does whatever undefined behavior (if you're luck, ud2 leading to non-zero return code). Let's start my work with the basics. This patch changes all libc++ tests to declare `main` as `int main(int, char**` so it mangles consistently (enabling us to declare another `extern "C"` main for freestanding which calls the mangled one), and adds `return 0;` to all places where it was missing. This touches 6124 files, and I apologize. The former was done with The Magic Of Sed. The later was done with a (not quite correct but decent) clang tool: https://gist.github.com/jfbastien/793819ff360baa845483dde81170feed This works for most tests, though I did have to adjust a few places when e.g. the test runs with `-x c`, macros are used for main (such as for the filesystem tests), etc. Once this is in we can create a freestanding bot which will prevent further regressions. After that, we can start the real work of supporting C++ freestanding fairly well in libc++. <rdar://problem/47754795> Reviewers: ldionne, mclow.lists, EricWF Subscribers: christof, jkorous, dexonsmith, arphaman, miyuki, libcxx-commits Differential Revision: https://reviews.llvm.org/D57624 llvm-svn: 353086
* Update more file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-19495-1980/+1485
| | | | | | | | | | | | | | | | | | to reflect the new license. These used slightly different spellings that defeated my regular expressions. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351648
* Fix FP comparisons when SSE isn't availableEric Fiselier2018-12-171-13/+15
| | | | llvm-svn: 349387
* [libc++] Use correct rand.eng.mers all-zeroes seed sequence fallbackHubert Tong2018-08-161-0/+81
| | | | | | | | | | | | | | | | | | | | | | | Summary: When a seed sequence would lead to having no non-zero significant bits in the initial state of a `mersenne_twister_engine`, the fallback is to flip the most significant bit of the first value that appears in the textual representation of the initial state. rand.eng.mers describes this as setting the value to be 2 to the power of one less than w; the previous value encoded in the implementation, namely one less than "2 to the power of w", is replaced by the correct value in this patch. Reviewers: mclow.lists, EricWF, jasonliu Reviewed By: mclow.lists Subscribers: mclow.lists, jasonliu, EricWF, christof, ldionne, cfe-commits Differential Revision: https://reviews.llvm.org/D50736 llvm-svn: 339969
* [libcxx] [test] Remove unused local typedef in ↵Billy Robert O'Neal III2018-05-171-1/+0
| | | | | | test/std/numerics/rand/rand.eng/rand.eng.lcong/default.pass.cpp llvm-svn: 332571
* Add void casts to suppress nodiscard on linear_congruential_engine.Billy Robert O'Neal III2018-05-172-3/+3
| | | | llvm-svn: 332567
* [libcxx] [test] Use TEST_COMPILER_C1XX.Stephan T. Lavavej2018-04-121-4/+4
| | | | | | Also TEST_COMPILER_CLANG in one place. (More could be changed.) llvm-svn: 329977
* Include <system_error> since we use it. Thanks to Andrey Maksimov for the catch.Marshall Clow2018-03-071-0/+1
| | | | llvm-svn: 326958
* Tolerate even more [[nodiscard]] in the STL. Reviewed as ↵Billy Robert O'Neal III2017-11-1519-54/+58
| | | | | | https://reviews.llvm.org/D39080 llvm-svn: 318277
* [libcxx] [test] Rename _Tp to T. NFCI.Stephan T. Lavavej2017-08-115-10/+10
| | | | | | | This improves readability and (theoretically) improves portability, as _Ugly names are reserved. llvm-svn: 310758
* [libcxx] [test] Fix Clang -Wunused-local-typedef warnings.Stephan T. Lavavej2017-07-195-21/+0
| | | | | | Fix D34536. llvm-svn: 308534
* Document XFAIL's with the relevent bug numberEric Fiselier2017-05-052-0/+4
| | | | llvm-svn: 302213
* Add markup for libc++ dylib availabilityMehdi Amini2017-05-042-0/+12
| | | | | | | | | | | | | | | Libc++ is used as a system library on macOS and iOS (amongst others). In order for users to be able to compile a binary that is intended to be deployed to an older version of the platform, clang provides the availability attribute <https://clang.llvm.org/docs/AttributeReference.html#availability>_ that can be placed on declarations to describe the lifecycle of a symbol in the library. See docs/DesignDocs/AvailabilityMarkup.rst for more information. Differential Revision: https://reviews.llvm.org/D31739 llvm-svn: 302172
* Cleanup _LIBCPP_HAS_NO_<c++11-feature> macros in the numeric tests and headersEric Fiselier2017-04-1916-20/+32
| | | | llvm-svn: 300632
* [libcxx] [test] Fix Clang -Wunused-local-typedef, part 2/3.Stephan T. Lavavej2017-02-056-16/+0
| | | | | | | | These typedefs were completely unused. Fixes D29136. llvm-svn: 294155
* Fix unused parameters and variablesEric Fiselier2016-12-233-7/+9
| | | | llvm-svn: 290459
* Enable the -Wsign-compare warning to better support MSVCEric Fiselier2016-12-1120-131/+135
| | | | llvm-svn: 289363
* [libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible ↵Stephan T. Lavavej2016-12-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | loss of data", part 7/7. test/std/input.output/iostream.format/input.streams/istream.unformatted/get.pass.cpp Add static_cast<char> because basic_istream::get() returns int_type (N4606 27.7.2.3 [istream.unformatted]/4). test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/minus1.pass.cpp Add static_cast<char> because toupper() returns int (C11 7.4.2.2/1). test/std/iterators/stream.iterators/ostream.iterator/ostream.iterator.ops/assign_t.pass.cpp This test is intentionally writing doubles to ostream_iterator<int>. It's silencing -Wliteral-conversion for Clang, so I'm adding C4244 silencing for MSVC. test/std/language.support/support.limits/limits/numeric.limits.members/infinity.pass.cpp Given `extern float zero;`, the expression `1./zero` has type double, which emits a truncation warning when being passed to test<float>() taking float. The fix is to say `1.f/zero` which has type float. test/std/numerics/complex.number/cmplx.over/arg.pass.cpp test/std/numerics/complex.number/cmplx.over/norm.pass.cpp These tests were constructing std::complex<double>(x, 0), emitting truncation warnings when x is long long. Saying static_cast<double>(x) avoids this. test/std/numerics/rand/rand.eng/rand.eng.lcong/seed_result_type.pass.cpp This was using `int s` to construct and seed a linear_congruential_engine<T, stuff>, where T is unsigned short/unsigned int/unsigned long/unsigned long long. That emits a truncation warning in the unsigned short case. Because the range [0, 20) is tiny and we aren't doing anything else with the index, we can just iterate with `T s`. test/std/re/re.traits/value.pass.cpp regex_traits<wchar_t>::value()'s first parameter is wchar_t (N4606 28.7 [re.traits]/13). This loop is using int to iterate through ['g', 0xFFFF), emitting a truncation warning from int to wchar_t (which is 16-bit for some of us). Because the bound is exclusive, we can just iterate with wchar_t. test/std/strings/basic.string/string.cons/size_char_alloc.pass.cpp This test is a little strange. It's trying to verify that basic_string's (InIt, InIt) range constructor isn't confused by "N copies of C" when N and C have the same integral type. To do this, it was testing (100, 65), but that eventually emits truncation warnings from int to char. There's a simple way to avoid this - passing (static_cast<char>(100), static_cast<char>(65)) also exercises the disambiguation. (And 100 is representable even when char has a signed range.) test/std/strings/string.view/string.view.hash/string_view.pass.cpp Add static_cast<char_type> because `'0' + i` has type int. test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp What's more horrible than nested bind()? pow() overloads! This operator()(T a, T b) was assuming that std::pow(a, b) can be returned as T. (In this case, T is int.) However, N4606 26.9.1 [cmath.syn]/2 says that pow(int, int) returns double, so this was truncating double to int. Adding static_cast<T> silences this. test/std/utilities/function.objects/unord.hash/integral.pass.cpp This was iterating `for (int i = 0; i <= 5; ++i)` and constructing `T t(i);` but that's truncating when T is short. (And super truncating when T is bool.) Adding static_cast<T> silences this. test/std/utilities/utility/exchange/exchange.pass.cpp First, this was exchanging 67.2 into an int, but that's inherently truncating. Changing this to static_cast<short>(67) avoids the truncation while preserving the "what if T and U are different" test coverage. Second, this was exchanging {} with the explicit type float into an int, and that's also inherently truncating. Specifying short is just as good. test/std/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp Add static_cast<short>. Note that this affects template argument deduction for make_pair(), better fulfilling the test's intent. For example, this was saying `typedef std::pair<int, short> P1; P1 p1 = std::make_pair(3, 4);` but that was asking make_pair() to return pair<int, int>, which was then being converted to pair<int, short>. (pair's converting constructors are tested elsewhere.) Now, std::make_pair(3, static_cast<short>(4)) actually returns pair<int, short>. (There's still a conversion from pair<nullptr_t, short> to pair<unique_ptr<int>, short>.) Fixes D27544. llvm-svn: 289111
* [libcxx] [test] D27020: Fix MSVC warning C4245 "conversion from 'X' to 'Y', ↵Stephan T. Lavavej2016-11-234-4/+4
| | | | | | | | | | signed/unsigned mismatch", part 7/12. When initializing unsigned integers to their maximum values, change "const T M(~0);" to "const T M(static_cast<T>(-1));". ~0 and -1 are equivalent, but I consider the -1 form to be significantly clearer (and more consistent with other tests). llvm-svn: 287827
* [libcxx] [test] D27018: Fix MSVC warning C4018 "signed/unsigned mismatch", ↵Stephan T. Lavavej2016-11-232-2/+2
| | | | | | | | | | | | | | | | | | | part 5/12. Various changes: test/std/algorithms/alg.sorting/alg.binary.search/binary.search/binary_search.pass.cpp Change M from unsigned to int. It's compared against "int x", and we binary_search() for it within a vector<int>. test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/eval.pass.cpp test/std/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.f/eval_param.pass.cpp Add static_cast<unsigned> when comparing int to unsigned. test/std/strings/basic.string/string.cons/size_char_alloc.pass.cpp Change unsigned indices to int when we're being given int as a bound. llvm-svn: 287825
* [libcxx] [test] D27013: Fix MSVC warning C4018 "signed/unsigned mismatch", ↵Stephan T. Lavavej2016-11-2315-46/+61
| | | | | | | | | | part 1/12. Change loop indices from int to std::size_t. Also, include <cstddef> when it wasn't already being included. llvm-svn: 287820
* [libcxx] [test] D26812: In random tests, use real static_asserts and silence ↵Stephan T. Lavavej2016-11-186-20/+84
| | | | | | | | | | | | | a warning. In C++11 mode and newer, use real static_asserts. In C++03 mode, min() and max() aren't constexpr, so use plain asserts. One test triggers MSVC's warning C4310 "cast truncates constant value". The code is valid, and yet the warning is valid, so I'm silencing it through push-disable-pop. llvm-svn: 287391
* [libcxx] [test] D26314: Fix MSVC warning C4189 "local variable is ↵Stephan T. Lavavej2016-11-142-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | initialized but not referenced". test/std/depr/depr.c.headers/inttypes_h.pass.cpp test/std/input.output/file.streams/c.files/cinttypes.pass.cpp test/std/input.output/iostream.forward/iosfwd.pass.cpp Add test() to avoid a bunch of void-casts, although we still need a few. test/std/input.output/iostream.format/quoted.manip/quoted.pass.cpp skippingws was unused (it's unclear to me whether this was mistakenly copy-pasted from round_trip() below). test/std/localization/locale.categories/category.collate/locale.collate/types.pass.cpp test/std/localization/locale.categories/category.ctype/facet.ctype.special/types.pass.cpp test/std/localization/locale.categories/category.ctype/locale.codecvt/types_char.pass.cpp test/std/localization/locale.categories/category.ctype/locale.codecvt/types_wchar_t.pass.cpp test/std/localization/locale.categories/category.ctype/locale.ctype/types.pass.cpp test/std/localization/locale.categories/facet.numpunct/locale.numpunct/types.pass.cpp test/std/localization/locales/locale.global.templates/use_facet.pass.cpp When retrieving facets, the references are unused. test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_long.pass.cpp test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_unsigned_long.pass.cpp "std::ios_base::iostate err = ios.goodbit;" was completely unused here. test/std/localization/locale.categories/category.time/locale.time.get/time_base.pass.cpp test/std/numerics/c.math/ctgmath.pass.cpp test/std/numerics/rand/rand.device/entropy.pass.cpp test/std/numerics/rand/rand.device/eval.pass.cpp test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/eof.pass.cpp test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/eof.pass.cpp test/std/thread/futures/futures.promise/dtor.pass.cpp test/std/thread/futures/futures.task/futures.task.members/dtor.pass.cpp test/std/thread/thread.condition/thread.condition.condvar/wait_for_pred.pass.cpp These variables are verifying types but are otherwise unused. test/std/strings/basic.string/string.capacity/reserve.pass.cpp old_cap was unused (it's unclear to me whether it was intended to be used). test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char/eq.pass.cpp test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/eq.pass.cpp test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/lt.pass.cpp test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/eq.pass.cpp test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/lt.pass.cpp test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/eq.pass.cpp test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/lt.pass.cpp These tests contained unused characters. llvm-svn: 286847
* Protect tests that expect an exception for an unknown std::random_deviceRoger Ferrer Ibanez2016-11-012-2/+4
| | | | | | | | Skip these tests under libcpp-no-exceptions. Differential Revision: https://reviews.llvm.org/D26141 llvm-svn: 285677
* Remove usages of _LIBCPP_CONSTEXPR under test/stdEric Fiselier2016-10-124-12/+20
| | | | llvm-svn: 284002
* Fix portability issues in <random> tests. Patch from STL@microsoft.comEric Fiselier2016-07-241-1/+3
| | | | llvm-svn: 276585
* Add array bounds assertions to satisfy MSVC's /analyze flag. Patch from ↵Eric Fiselier2016-06-261-0/+3
| | | | | | STL@microsoft.com llvm-svn: 273820
* Move remaining _LIBCPP_VERSION tests into test/libcxxEric Fiselier2016-06-221-20/+0
| | | | llvm-svn: 273367
* Avoid huge main() functions and huge arrays. Patch from STL@microsoft.comEric Fiselier2016-06-229-2455/+2686
| | | | llvm-svn: 273354
* Improve portability of random_device tests. Patch from STL@microsoft.comEric Fiselier2016-06-152-2/+6
| | | | llvm-svn: 272746
* Rename variables to prevent shadowing. Patch from STL@microsoft.comEric Fiselier2016-06-1432-372/+372
| | | | llvm-svn: 272619
* Guard use of <unistd.h> in test.Eric Fiselier2016-05-031-17/+22
| | | | llvm-svn: 268346
* Initialize local doubles to NaN. Patch from STL@microsoft.comEric Fiselier2016-05-022-28/+30
| | | | llvm-svn: 268285
* Void cast runtime-unused variables. Patch from STL@microsoft.comEric Fiselier2016-05-021-1/+1
| | | | llvm-svn: 268284
* Fix some non-standard parts of our test suite. Reported by STLEric Fiselier2016-04-222-0/+2
| | | | llvm-svn: 267131
* Add missing include of <algorithm>Marshall Clow2016-04-222-0/+2
| | | | llvm-svn: 267119
* Add a bunch of missing includes in the test suite to make it more portable. ↵Marshall Clow2016-01-121-0/+1
| | | | | | Fixes bugs #26120 and #26121. Thanks to Jonathan Wakely for the reports and the patches. llvm-svn: 257474
* Make it possible to build a no-exceptions variant of libcxx.Asiri Rathnayake2015-11-102-0/+2
| | | | | | | | | | | | Fixes a small omission in libcxx that prevents libcxx being built when -DLIBCXX_ENABLE_EXCEPTIONS=0 is specified. This patch adds XFAILS to all those tests that are currently failing on the new -fno-exceptions library variant. Follow-up patches will update the tests (progressively) to cope with the new library variant. Change-Id: I4b801bd8d8e4fe7193df9e55f39f1f393a8ba81a llvm-svn: 252598
* Add support for arc4random() to random_device.Ed Schouten2015-03-101-6/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | Nuxi CloudABI (https://github.com/NuxiNL/cloudlibc) does not allow processes to access the global filesystem namespace. This breaks random_device, as it attempts to use /dev/{u,}random. This change adds support for arc4random(), which is present on CloudABI. In my opinion it would also make sense to use arc4random() on other operating systems, such as *BSD and Mac OS X, but I'd rather leave that to the maintainers of the respective platforms. Switching to arc4random() does change the ABI. This change also attempts to make some cleanups to the code. It adds a single #define for every random interface, instead of testing against operating systems explicitly. As discussed, also validate the token argument to be equal to "/dev/urandom" on all systems that only provide pseudo-random numbers. This should cause little to no breakage, as "/dev/urandom" is also the default argument value. Reviewed by: jfb Differential Revision: http://reviews.llvm.org/D8134 llvm-svn: 231764
* Move test into test/std subdirectory.Eric Fiselier2014-12-20495-0/+25941
llvm-svn: 224658
OpenPOWER on IntegriCloud