summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support
Commit message (Collapse)AuthorAgeFilesLines
...
* Refactor DynamicLibrary so searching for a symbol will have a defined order andFrederich Munch2017-04-245-0/+209
| | | | | | | | | | | | | | | | | | | | | | | | | | | libraries are properly unloaded when llvm_shutdown is called. Summary: This was mostly affecting usage of the JIT, where storing the library handles in a set made iteration unordered/undefined. This lead to disagreement between the JIT and native code as to what the address and implementation of particularly on Windows with stdlib functions: JIT: putenv_s("TEST", "VALUE") // called msvcrt.dll, putenv_s JIT: getenv("TEST") -> "VALUE" // called msvcrt.dll, getenv Native: getenv("TEST") -> NULL // called ucrt.dll, getenv Also fixed is the issue of DynamicLibrary::getPermanentLibrary(0,0) on Windows not giving priority to the process' symbols as it did on Unix. Reviewers: chapuni, v.g.vassilev, lhames Reviewed By: lhames Subscribers: danalbert, srhines, mgorny, vsk, llvm-commits Differential Revision: https://reviews.llvm.org/D30107 llvm-svn: 301236
* Don't test setting sticky bits on files for modern BSDsDimitry Andric2017-04-241-0/+7
| | | | | | | | | | | | | | | | | | | Summary: In rL297945, jhenderson added methods for setting permissions to sys::fs, but some of the unittests that attempt to set sticky bits (01000) on files fail on modern BSDs, such as FreeBSD, NetBSD and OpenBSD. This is because those systems do not allow regular users to set sticky bits on files, only on directories. Fix it by disabling these particular tests on modern BSDs. Reviewers: emaste, brad, jhenderson Reviewed By: jhenderson Subscribers: joerg, krytarowski, llvm-commits Differential Revision: https://reviews.llvm.org/D32120 llvm-svn: 301220
* Revert "Refactor DynamicLibrary so searching for a symbol will have a ↵Frederich Munch2017-04-245-209/+0
| | | | | | | | | | defined order.” The changes are causing the i686-mingw32 build to fail. This reverts commit r301153, and the changes for a separate warning on i686-mingw32 in r301155 and r301156. llvm-svn: 301157
* Refactor DynamicLibrary so searching for a symbol will have a defined order andFrederich Munch2017-04-245-0/+209
| | | | | | | | | | | | | | | | | | | | | | | | | | | libraries are properly unloaded when llvm_shutdown is called. Summary: This was mostly affecting usage of the JIT, where storing the library handles in a set made iteration unordered/undefined. This lead to disagreement between the JIT and native code as to what the address and implementation of particularly on Windows with stdlib functions: JIT: putenv_s("TEST", "VALUE") // called msvcrt.dll, putenv_s JIT: getenv("TEST") -> "VALUE" // called msvcrt.dll, getenv Native: getenv("TEST") -> NULL // called ucrt.dll, getenv Also fixed is the issue of DynamicLibrary::getPermanentLibrary(0,0) on Windows not giving priority to the process' symbols as it did on Unix. Reviewers: chapuni, v.g.vassilev, lhames Reviewed By: lhames Subscribers: danalbert, srhines, mgorny, vsk, llvm-commits Differential Revision: https://reviews.llvm.org/D30107 llvm-svn: 301153
* [BPI] Add multiplication by scalar operators to BranchProbabilitySerguei Katkov2017-04-211-0/+48
| | | | | | | | | | | | | | | This patch just adds two operators to BranchProbability class: (BP * scalar) and (BP *= scalar). Reviewers: junbuml, chandlerc, sanjoy, vsk Reviewed By: chandlerc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32334 llvm-svn: 300945
* [ARM] Rename HW div feature to HW div Thumb. NFCI.Diana Picus2017-04-201-45/+52
| | | | | | | | | | | | | | | | The hardware div feature refers only to Thumb, but because of its name it is tempting to use it to check for hardware division in general, which may cause problems in ARM mode. See https://reviews.llvm.org/D32005. This patch adds "Thumb" to its name, to make its scope clear. One notable place where I haven't made the change is in the feature flag (used with -mattr), which is still hwdiv. Changing it would also require changes in a lot of tests, including clang tests, and it doesn't seem like it's worth the effort. Differential Revision: https://reviews.llvm.org/D32160 llvm-svn: 300827
* [MathExtras] Fix undefined behavior (shift by bit width)Benjamin Kramer2017-04-191-0/+5
| | | | | | While there add some unit tests for uint64_t. Found by ubsan. llvm-svn: 300721
* [Support] Add some helpers to generate bitmasks.Zachary Turner2017-04-191-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | Frequently you you want a bitmask consisting of a specified number of 1s, either at the beginning or end of a word. The naive way to do this is to write template<typename T> T leadingBitMask(unsigned N) { return (T(1) << N) - 1; } but using this function you cannot produce a word with every bit set to 1 (i.e. leadingBitMask<uint8_t>(8)) because left shift is undefined when N is greater than or equal to the number of bits in the word. This patch provides an efficient, branch-free implementation that works for all values of N in [0, CHAR_BIT*sizeof(T)] Differential Revision: https://reviews.llvm.org/D32212 llvm-svn: 300710
* [Support] Add support for unique_ptr<> to Casting.h.Zachary Turner2017-04-121-0/+75
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Often you have a unique_ptr<T> where T supports LLVM's casting methods, and you wish to cast it to a unique_ptr<U>. Prior to this patch, this requires doing hacky things like: unique_ptr<U> Casted; if (isa<U>(Orig.get())) Casted.reset(cast<U>(Orig.release())); This is overly verbose, and it would be nice to just be able to use unique_ptr directly with cast and dyn_cast. To this end, this patch updates cast<> to work directly with unique_ptr<T>, so you can now write: auto Casted = cast<U>(std::move(Orig)); Since it's possible for dyn_cast<> to fail, however, we choose to use a slightly different API here, because it's awkward to write if (auto Casted = dyn_cast<U>(std::move(Orig))) {} when Orig may end up not having been moved at all. So the interface for dyn_cast is if (auto Casted = unique_dyn_cast<U>(Orig)) {} Where the inclusion of `unique` in the name of the cast operator re-affirms that regardless of success of or fail of the casting, exactly one of the input value and the return value will contain a non-null result. Differential Revision: https://reviews.llvm.org/D31890 llvm-svn: 300098
* Implement host CPU detection for AArch64Yi Kong2017-04-041-0/+35
| | | | | | | | | | | | | | | | | | This shares detection logic with ARM(32), since AArch64 capable CPUs may also run in 32-bit system mode. We observe weird /proc/cpuinfo output for MSM8992 and MSM8994, where they report all CPU cores as one single model, depending on which CPU core the kernel is running on. As a workaround, we hardcode the known CPU part name for these SoCs. For big.LITTLE systems, this patch would only return the part name of the first core (usually the little core). Proper support will be added in a follow-up change. Differential Revision: D31675 llvm-svn: 299458
* Align all scalar numbers to LLVM_YAML_IS_FLOW_SEQUENCE_VECTORJonas Hahnfeld2017-04-041-8/+8
| | | | | | | | | Otherwise, yamlize in YAMLTraits.h might be wrongly defined. This makes some AMDGPU tests fail when LLVM_LINK_LLVM_DYLIB is set. Differential Revision: https://reviews.llvm.org/D30508 llvm-svn: 299415
* Make naming in Host.h in line with coding standards.Kristof Beyls2017-03-311-13/+10
| | | | | | | Based on post-commit review comments by Chandler Carruth on https://reviews.llvm.org/D31236. Thanks! llvm-svn: 299211
* Revert "Make naming in Host.h in line with coding standards."Kristof Beyls2017-03-301-10/+13
| | | | | | | | | | | | | | | | | | | This reverts r299062, which caused build failures on Windows. It also reverts the attempts to fix the windows builds in r299064 and r299065. The introduction of namespace llvm::sys::detail makes MSVC, and seemingly also mingw, complain about ambiguity with the existing namespace llvm::detail. E.g.: C:\b\slave\sanitizer-windows\llvm\include\llvm/Support/MathExtras.h(184): error C2872: 'detail': ambiguous symbol C:\b\slave\sanitizer-windows\llvm\include\llvm/Support/PointerLikeTypeTraits.h(31): note: could be 'llvm::detail' C:\b\slave\sanitizer-windows\llvm\include\llvm/Support/Host.h(80): note: or 'llvm::sys::detail' In r299064 and r299065 I tried to fix these ambiguities, based on the errors reported in the log files. It seems however that the build stops early when this kind of error is encountered, and many build-then-fix-iterations on Windows may be needed to fix this. Therefore reverting r299062 for now to get the build working again on Windows. llvm-svn: 299066
* Make naming in Host.h in line with coding standards.Kristof Beyls2017-03-301-13/+10
| | | | | | | Based on post-commit review comments by Chandler Carruth on https://reviews.llvm.org/D31236. Thanks! llvm-svn: 299062
* Refactor getHostCPUName to allow testing on non-native hardware.Kristof Beyls2017-03-301-0/+44
| | | | | | | | | | | | | | | | | | | | | | | | | This refactors getHostCPUName so that for the architectures that get the host cpu info on linux from /proc/cpuinfo, the /proc/cpuinfo parsing logic is present in the build, even if it wasn't built on a linux system for that architecture. Since the code is present in the build, we can then test that code also on other systems, i.e. we don't need to have buildbots setup for all architectures on linux to be able to test this. Instead, developers will test this as part of the regression test run. As an example, a few unit tests are added to test getHostCPUName for ARM running linux. A unit test is preferred over a lit-based test, since the expectation is that in the future, the functionality here will grow over what can be tested with "llc -mcpu=native". This is a preparation step to enable implementing the range of improvements discussed on PR30516, such as adding AArch64 support, support for big.LITTLE systems, reducing code duplication. Differential Revision: https://reviews.llvm.org/D31236 llvm-svn: 299060
* Make the home_directory test a little more resilient.Zachary Turner2017-03-221-10/+21
| | | | | | | | | | | | It's possible (albeit strange) for $HOME to intentionally point somewhere other than the user's home directory as reported by the password database. Our test shouldn't fail in this case. This patch updates the test to pull directly from the password database before unsetting $HOME, rather than comparing the return value of home_directory() to the original value of the environment variable. llvm-svn: 298514
* Make home_directory look in the password database in addition to $HOME.Zachary Turner2017-03-221-0/+20
| | | | | | | | | | | | | This is something of an edge case, but when the $HOME environment variable is not set, we can still look in the password database to get the current user's home directory. Added a test for this by getting the value of $HOME, then unsetting it, then calling home_directory() and verifying that it succeeds and that the value is the same as what we originally read from the environment. llvm-svn: 298513
* Add a function to MD5 a file's contents.Zachary Turner2017-03-202-1/+17
| | | | | | | | | | | | | | | In doing so, clean up the MD5 interface a little. Most existing users only care about the lower 8 bytes of an MD5, but for some users that care about the upper and lower, there wasn't a good interface. Furthermore, consumers of the MD5 checksum were required to handle endianness details on their own, so it seems reasonable to abstract this into a nicer interface that just gives you the right value. Differential Revision: https://reviews.llvm.org/D31105 llvm-svn: 298322
* SmallString doesn't have implicit conversion from const char*.Zachary Turner2017-03-171-2/+2
| | | | llvm-svn: 298019
* Don't rely on an implicit std::tuple constructor.Zachary Turner2017-03-171-4/+9
| | | | | | | Apparently it doesn't have one, so using an initializer list doesn't work correctly. llvm-svn: 298018
* Fix unit test.Zachary Turner2017-03-161-1/+1
| | | | llvm-svn: 298014
* [Support] Support both Windows and Posix paths on both platforms.Zachary Turner2017-03-161-87/+68
| | | | | | | | | | | | | | | | | | Previously which path syntax we supported dependend on what platform we were compiling LLVM on. While this is normally desirable, there are situations where we need to be able to handle a path that we know was generated on a remote host. Remote debugging, for example, or parsing debug info. 99% of the code in LLVM for handling paths was platform agnostic and literally just a few branches were gated behind pre-processor checks, so this changes those sites to use runtime checks instead, and adds a flag to every path API that allows one to override the host native syntax. Differential Revision: https://reviews.llvm.org/D30858 llvm-svn: 298004
* [Support] Add support for getting file system permissions on Windows and ↵James Henderson2017-03-161-0/+171
| | | | | | | | | | | | | | | | | | implement sys::fs::set/getPermissions to work with them This change adds support for functions to set and get file permissions, in a similar manner to the C++17 permissions() function in <filesystem>. The setter uses chmod on Unix systems and SetFileAttributes on Windows, setting the permissions as passed in. The getter simply uses the existing status() function. Prior to this change, status() would always return an unknown value for the permissions on a Windows file, making it impossible to test the new function on Windows. I have therefore added support for this as well. On Linux, prior to this change, the permissions included the file type, which should actually be accessed via a different member of the file_status class. Note that on Windows, only the *_write permission bits have any affect - if any are set, the file is writable, and if not, the file is read-only. This is in common with what MSDN describes for their behaviour of std::filesystem::permissions(), and also what boost::filesystem does. The motivation behind this change is so that we can easily test behaviour on read-only files in LLVM unit tests, but I am sure that others may find it useful in some situations. Reviewers: zturner, amccarth, aaron.ballman Differential Revision: https://reviews.llvm.org/D30736 llvm-svn: 297945
* Support: Add a cache pruning policy parser.Peter Collingbourne2017-03-162-0/+72
| | | | | | | | | The idea is that the policy string fully specifies the policy and is portable between clients. Differential Revision: https://reviews.llvm.org/D31020 llvm-svn: 297927
* [Support][CommandLine] Make it possible to get error messages from ↵Eric Liu2017-03-151-21/+55
| | | | | | | | | | | | | | | | | | | ParseCommandLineOptions when ignoring errors. Summary: Previously, ParseCommandLineOptions returns false and ignores error messages when IgnoreErrors. It would be useful to also return error messages if users decide to check parsing result instead of having the program exit on error. Reviewers: chandlerc, mehdi_amini, rnk Reviewed By: rnk Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D30893 llvm-svn: 297810
* [Support] Make the SystemZ bot happy by using make_error_code.Juergen Ributzka2017-03-141-1/+2
| | | | | | | This should fix the last issue on the SystemZ bot related to the broken symlink test. llvm-svn: 297767
* [Support] Follow-up for "Test directory iterators and recursive directory ↵Juergen Ributzka2017-03-131-1/+1
| | | | | | | | iterators with broken symlinks." Fix the test by sorting the result vector. llvm-svn: 297672
* [Support] Test directory iterators and recursive directory iterators with ↵Juergen Ributzka2017-03-131-0/+78
| | | | | | | | | | | broken symlinks. This commit adds a unit test to the file system tests to verify the behavior of the directory iterator and recursive directory iterator with broken symlinks. This test is Unix only. llvm-svn: 297669
* Bring back r297624.Rafael Espindola2017-03-131-0/+8
| | | | | | The issues was just a missing REQUIRES in the test. llvm-svn: 297661
* Revert "Fix crash when multiple raw_fd_ostreams to stdout are created."Rafael Espindola2017-03-131-8/+0
| | | | | | | This reverts commit r297624. It was failing on the bots. llvm-svn: 297657
* Fix crash when multiple raw_fd_ostreams to stdout are created.Rafael Espindola2017-03-131-0/+8
| | | | | | | | | | | | | | | | | | | | | If raw_fd_ostream is constructed with the path of "-", it claims ownership of the stdout file descriptor. This means that it closes stdout when it is destroyed. If there are multiple users of raw_fd_ostream wrapped around stdout, then a crash can occur because of operations on a closed stream. An example of this would be running something like "clang -S -o - -MD -MF - test.cpp". Alternatively, using outs() (which creates a local version of raw_fd_stream to stdout) anywhere combined with such a stream usage would cause the crash. The fix duplicates the stdout file descriptor when used within raw_fd_ostream, so that only that particular descriptor is closed when the stream is destroyed. Patch by James Henderson! llvm-svn: 297624
* Reverting r297617 because it broke some bots:Aaron Ballman2017-03-131-182/+4
| | | | | | http://bb.pgr.jp/builders/cmake-llvm-x86_64-linux/builds/49970 llvm-svn: 297618
* Add support for getting file system permissions and implement ↵Aaron Ballman2017-03-131-4/+182
| | | | | | | | sys::fs::permissions to set them. Patch by James Henderson. llvm-svn: 297617
* [unittest] Explicitly specify alignment when using BumpPtrAllocator.Jordan Rose2017-03-112-4/+5
| | | | | | | | | | | | | r297310 began inserting red zones around allocations under ASan, which perturbs the alignment of subsequent allocations. Deliberately specify this in two places where it matters. Fixes failures when these tests are run under ASan and UBSan together. Reviewed by Duncan Exon Smith. rdar://problem/30980047 llvm-svn: 297540
* Fix test failure when Home directory cannot be found.Zachary Turner2017-03-101-9/+8
| | | | llvm-svn: 297484
* Add llvm::sys::fs::real_path.Zachary Turner2017-03-101-0/+36
| | | | | | | | | | | | | | | | | | | | | LLVM already has real_path like functionality, but it is cumbersome to use and involves clean up after (e.g. you have to call openFileForRead, then close the resulting FD). Furthermore, on Windows it doesn't work for directories since opening a directory and opening a file require slightly different flags. So I add a simple function `real_path` which works for all paths on all platforms and has a simple to use interface. In doing so, I add the ability to opt in to resolving tilde expressions (e.g. ~/foo), which are normally handled by the shell. Differential Revision: https://reviews.llvm.org/D30668 llvm-svn: 297483
* [Support] Add llvm::sys::fs::remove_directories.Zachary Turner2017-03-081-0/+33
| | | | | | | | | | | | | | | | | | | | | We already have a function create_directories() which can create an entire tree, and remove() which can remove an empty directory, but we do not have remove_directories() which can remove an entire tree. This patch adds such a function. Because removing a directory tree can have dangerous consequences when the tree contains a directory symlink, the patch here updates the existing directory_iterator construct to optionally not follow symlinks (previously it would always follow symlinks). The delete algorithm uses this flag so that for symlinks, only the links are removed, and not the targets. On Windows this is implemented with SHFileOperation, which also does not recurse into symbolic links or junctions. Differential Revision: https://reviews.llvm.org/D30676 llvm-svn: 297314
* [Support] Remove unit test for fs::is_localJonas Hahnfeld2017-03-081-55/+0
| | | | | | | | | rL295768 introduced this test that fails if LLVM is built and tested on an NFS share. Delete the test as discussed on the corresponing commit thread. The only feasible solution would have been to introduce environment variables and to en/disable the test conditionally. llvm-svn: 297260
* [AArch64] Vulcan is now ThunderXT99Joel Jones2017-03-071-3/+4
| | | | | | | | | | | | | | | | | Broadcom Vulcan is now Cavium ThunderX2T99. LLVM Bugzilla: http://bugs.llvm.org/show_bug.cgi?id=32113 Minor fixes for the alignments of loops and functions for ThunderX T81/T83/T88 (better performance). Patch was tested with SpecCPU2006. Patch by Stefan Teleman Differential Revision: https://reviews.llvm.org/D30510 llvm-svn: 297190
* [Support] Move Stream library from MSF -> Support.Zachary Turner2017-03-022-0/+711
| | | | | | | | | | After several smaller patches to get most of the core improvements finished up, this patch is a straight move and header fixup of the source. Differential Revision: https://reviews.llvm.org/D30266 llvm-svn: 296810
* Process tilde in llvm::sys::path::nativeSerge Pavlov2017-03-011-0/+27
| | | | | | | | | | | | | Windows does not treat `~` as a reference to home directory, so the call to `llvm::sys::path::native` on, say, `~/somedir` produces `~\somedir`, which has different meaning than the original path. With this change tilde is expanded on Windows to user profile directory. Such behavior keeps original meaning of the path and is consistent with the algorithm of `llvm::sys::path::home_directory`. Differential Revision: https://reviews.llvm.org/D27527 llvm-svn: 296590
* Workaround MSVC bug when using TrailingObjects from a template.James Y Knight2017-02-281-0/+21
| | | | | | | | | | | | | MSVC appears to be getting confused as to whether OverloadToken is supposed to be public or not. This was discovered by code in Swift, and has been reported to microsoft by hughbe: https://connect.microsoft.com/VisualStudio/feedback/details/3116517 Differential Revision: https://reviews.llvm.org/D29880 llvm-svn: 296497
* [Support][Error] Add a 'cantFail' utility function for known-safe calls toLang Hames2017-02-271-0/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fallible functions. Some fallible functions (those returning Error or Expected<T>) may only fail for a subset of their inputs. For example, a "safe" square root function will succeed for all finite positive inputs: Expected<double> safeSqrt(double d) { if (d < 0 && !isnan(d) && !isinf(d)) return make_error<...>("Cannot sqrt -ve values, nans or infs"); return sqrt(d); } At a safe callsite for such a function, checking the error return value is redundant: if (auto ValOrErr = safeSqrt(42.0)) { // use *ValOrErr. } else llvm_unreachable("safeSqrt should always succeed for +ve values"); The cantFail function wraps this check and extracts the contained value, simplifying control flow: double Result = cantFail(safeSqrt(42.0)); This function should be used with care: it is a programmatic error to wrap a call with cantFail if it can in fact fail. For debug builds this will result in llvm_unreachable being called. For release builds the behavior is undefined. Use of this function is likely to be rare in library code, but more common for tool and unit-test code where inputs and mock functions may be known to be safe. llvm-svn: 296384
* [Support] XFAIL is_local for mipsSimon Dardis2017-02-221-0/+36
| | | | | | | is_local can't pass on some our buildbots as some of our buildbots use network shares for building and testing LLVM. llvm-svn: 295840
* [Support] Add a function to check if a file resides locally.Zachary Turner2017-02-211-0/+22
| | | | | | Differential Revision: https://reviews.llvm.org/D30010 llvm-svn: 295768
* [AArch64] Add Cavium ThunderX supportJoel Jones2017-02-171-0/+24
| | | | | | | | | | | | | | This set of patches adds support for Cavium ThunderX ARM64 processors: * ThunderX * ThunderX T81 * ThunderX T83 * ThunderX T88 Patch by Stefan Teleman Differential Revision: https://reviews.llvm.org/D28891 llvm-svn: 295475
* [Support] Add formatv support for StringLiteralPavel Labath2017-02-141-0/+2
| | | | | | | | | | | | | | | Summary: This is achieved by generalizing the expression selecting the StringRef format_provider. Now, anything that can be converted to a StringRef will use it's formatter. Reviewers: zturner Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D29898 llvm-svn: 295064
* [CMake] Fix pthread handling for out-of-tree buildsEric Fiselier2017-02-101-1/+1
| | | | | | | | | | | | | | | LLVM defines `PTHREAD_LIB` which is used by AddLLVM.cmake and various projects to correctly link the threading library when needed. Unfortunately `PTHREAD_LIB` is defined by LLVM's `config-ix.cmake` file which isn't installed and therefore can't be used when configuring out-of-tree builds. This causes such builds to fail since `pthread` isn't being correctly linked. This patch attempts to fix that problem by renaming and exporting `LLVM_PTHREAD_LIB` as part of`LLVMConfig.cmake`. I renamed `PTHREAD_LIB` because It seemed likely to cause collisions with downstream users of `LLVMConfig.cmake`. llvm-svn: 294690
* [Support] Extend SLEB128 encoding support.Dan Gohman2017-02-101-14/+33
| | | | | | | | Add support for padded SLEB128 values, and support for writing SLEB128 values to buffers rather than to ostreams, similar to the existing ULEB128 support. llvm-svn: 294675
* [ARM] Add support for armv7ve triple in llvm (PR31358).George Burgess IV2017-02-091-17/+21
| | | | | | | | | | | | | | | Gcc supports target armv7ve which is armv7-a with virtualization extensions. This change adds support for this in llvm for gcc compatibility. Also remove redundant FeatureHWDiv, FeatureHWDivARM for a few models as this is specified automatically by FeatureVirtualization. Patch by Manoj Gupta. Differential Revision: https://reviews.llvm.org/D29472 llvm-svn: 294661
OpenPOWER on IntegriCloud