platform/upstream/llvm.git
5 years ago[SelectionDAG] Add scalarization of ABS node (PR41149)
Simon Pilgrim [Thu, 21 Mar 2019 11:18:54 +0000 (11:18 +0000)]
[SelectionDAG] Add scalarization of ABS node (PR41149)

Patch by: @ikulagin (Ivan Kulagin)

Differential Revision: https://reviews.llvm.org/D59577

llvm-svn: 356656

5 years agoFix two more issues with r356652
Pavel Labath [Thu, 21 Mar 2019 10:21:55 +0000 (10:21 +0000)]
Fix two more issues with r356652

The first problem was a use-after-free in the tests (detected by asan
bots). The temporary array created for the "create" call is guaranteed
to live only until the end of the statement. The fix there is to store
the test data in a local variable to ensure it has the right lifetime

The second issue is broken BUILD_SHARED_LIBS build, which I fix by
adding the appropriate BinaryFormat dependency to the Object unit tests.

llvm-svn: 356655

5 years ago[RISCV][NFC] Remove old CHECK lines from linker-relaxation.s test
Alex Bradbury [Thu, 21 Mar 2019 09:53:19 +0000 (09:53 +0000)]
[RISCV][NFC] Remove old CHECK lines from linker-relaxation.s test

The RELOC: check lines are no longer used.

llvm-svn: 356654

5 years agoAttempt to fix modules build for r356652
Pavel Labath [Thu, 21 Mar 2019 09:44:07 +0000 (09:44 +0000)]
Attempt to fix modules build for r356652

The commit added a new .def file. This adds it to the list of textual
headers.

llvm-svn: 356653

5 years ago[Object] Add basic minidump support
Pavel Labath [Thu, 21 Mar 2019 09:18:59 +0000 (09:18 +0000)]
[Object] Add basic minidump support

Summary:
This patch adds basic support for reading minidump files. It contains
the definitions of various important minidump data structures (header,
stream directory), and of one minidump stream (SystemInfo). The ability
to read other streams will be added in follow-up patches. However, all
streams can be read even now as raw data, which means lldb's minidump
support (where this code is taken from) can be immediately rebased on
top of this patch as soon as it lands.

As we don't have any support for generating minidump files (yet), this
tests the code via unit tests with some small handcrafted binaries in
the form of c char arrays.

Reviewers: Bigcheese, jhenderson, zturner

Subscribers: srhines, dschuff, mgorny, fedor.sergeev, lemo, clayborg, JDevlieghere, aprantl, lldb-commits, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D59291

llvm-svn: 356652

5 years ago[BasicAA] Use DenseMap::try_emplace after D59151. NFC
Fangrui Song [Thu, 21 Mar 2019 08:47:40 +0000 (08:47 +0000)]
[BasicAA] Use DenseMap::try_emplace after D59151. NFC

llvm-svn: 356651

5 years agoReland r356547 after fixing the YAML module missing issue.
Zinovy Nis [Thu, 21 Mar 2019 08:32:07 +0000 (08:32 +0000)]
Reland r356547 after fixing the YAML module missing issue.

[clang-tidy] Parallelize clang-tidy-diff.py

This patch has 2 rationales:

- large patches lead to long command lines and often cause max command line length restrictions imposed by OS;
- clang-tidy runs on modified files are independent and can be done in parallel, the same as done for run-clang-tidy.

Differential Revision: https://reviews.llvm.org/D5766

llvm-svn: 356649

5 years agoSilence warning about unused variable in builds without asserts [NFC]
Mikael Holmen [Thu, 21 Mar 2019 07:54:44 +0000 (07:54 +0000)]
Silence warning about unused variable in builds without asserts [NFC]

llvm-svn: 356648

5 years agoUse list comprehension instead of map/filter to prepare Python2/3 compat
Serge Guelton [Thu, 21 Mar 2019 07:19:09 +0000 (07:19 +0000)]
Use list comprehension instead of map/filter to prepare Python2/3 compat

Differential Revision: https://reviews.llvm.org/D59579

llvm-svn: 356647

5 years ago[ScalarizeMaskedMemIntrinsics] Reverse some if conditions to reduce indentations...
Craig Topper [Thu, 21 Mar 2019 05:54:37 +0000 (05:54 +0000)]
[ScalarizeMaskedMemIntrinsics] Reverse some if conditions to reduce indentations to remove curly braces.

Pre-commit for D59180

llvm-svn: 356646

5 years ago[InstCombine] Add test case for PR41164. NFC
Craig Topper [Thu, 21 Mar 2019 05:33:10 +0000 (05:33 +0000)]
[InstCombine] Add test case for PR41164. NFC

llvm-svn: 356645

5 years ago[BasicAA] Reduce no of map seaches [NFCI].
Alina Sbirlea [Thu, 21 Mar 2019 05:02:05 +0000 (05:02 +0000)]
[BasicAA] Reduce no of map seaches [NFCI].

Summary:
This is a refactoring patch.
- Reduce the number of map searches by reusing the iterator.
- Add asserts to check that the entry is in the cache, as this is something BasicAA relies on to avoid infinite recursion.

Reviewers: chandlerc, aschwaighofer

Subscribers: sanjoy, jlebar, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D59151

llvm-svn: 356644

5 years ago[Reproducers] Properly handle QEnvironment packets
Jonas Devlieghere [Thu, 21 Mar 2019 04:08:31 +0000 (04:08 +0000)]
[Reproducers] Properly handle QEnvironment packets

On Linux, a QEnvironment packet is sent for every environment variable.
This breaks replay when the number of environment variables is different
then during capture. The solution is to always reply with OK.

llvm-svn: 356643

5 years ago[instcombine] Add some todos, and arrange code for readibility
Philip Reames [Thu, 21 Mar 2019 03:23:40 +0000 (03:23 +0000)]
[instcombine] Add some todos, and arrange code for readibility

llvm-svn: 356642

5 years ago[MSSA] Delete move ctor; remove dynamic never-moved verification
George Burgess IV [Thu, 21 Mar 2019 03:11:34 +0000 (03:11 +0000)]
[MSSA] Delete move ctor; remove dynamic never-moved verification

Code archaeology in D59315 revealed that MSSA should never be moved.
Rather than trying to check dynamically that this hasn't happened in the
verify() functions of Walkers, it's likely best to just delete its move
constructor.

Since all these verify() functions did is check that MSSA hasn't moved,
this allows us to remove these verify functions.

I can readd the verification checks if someone's super concerned about
us trying to `memcpy` MemorySSA or something somewhere, but I imagine we
have other problems if we're trying anything like that...

llvm-svn: 356641

5 years agoAdd dylib-has-no-filesystem when filesystem is disabled
Eric Fiselier [Thu, 21 Mar 2019 02:13:30 +0000 (02:13 +0000)]
Add dylib-has-no-filesystem when filesystem is disabled

llvm-svn: 356640

5 years agoMark debug death tests as unsupported on Windows
Eric Fiselier [Thu, 21 Mar 2019 02:07:55 +0000 (02:07 +0000)]
Mark debug death tests as unsupported on Windows

llvm-svn: 356639

5 years ago[Reproducers] Log inconsistencies during replay (NFC)
Jonas Devlieghere [Thu, 21 Mar 2019 01:57:33 +0000 (01:57 +0000)]
[Reproducers] Log inconsistencies during replay (NFC)

Make debugging of the GDB remote packet aspect of reproducers easier by
logging both requests and replies. This enables some sanity checking
during replay.

llvm-svn: 356638

5 years agoRemove type visibility specifiers from new chrono types.
Eric Fiselier [Thu, 21 Mar 2019 01:48:15 +0000 (01:48 +0000)]
Remove type visibility specifiers from new chrono types.

_LIBCPP_TYPE_VIS is only really needed on types with a vtable.
And on Windows it doesn't work with types that have only inline methods.

This patch removes the unneeded attributes.

llvm-svn: 356637

5 years agocreduce-clang-crash.py: preprocess file + reduce commandline
George Burgess IV [Thu, 21 Mar 2019 01:01:53 +0000 (01:01 +0000)]
creduce-clang-crash.py: preprocess file + reduce commandline

This CL causes our creduce-clang-crash.py util to:

- try to preprocess the file before reducing
- try to remove some command line arguments
- now require a llvm bin directory, since the generated crash script
  doesn't have an absolute path for clang

It also marks it as executable, since I forgot to do that in the last
commit. :)

Patch by Amy Huang!

Differential Revision: https://reviews.llvm.org/D59440

llvm-svn: 356636

5 years ago[libcxx] [test] Revert r356632 add (void) casts to operator new calls, to suppress...
Billy Robert O'Neal III [Thu, 21 Mar 2019 00:24:43 +0000 (00:24 +0000)]
[libcxx] [test] Revert r356632 add (void) casts to operator new calls, to suppress warnings generated by [[nodiscard]]."

llvm-svn: 356635

5 years ago[CFG] [analyzer] pr41142: C++17: Skip transparent InitListExprs in constructors.
Artem Dergachev [Thu, 21 Mar 2019 00:15:07 +0000 (00:15 +0000)]
[CFG] [analyzer] pr41142: C++17: Skip transparent InitListExprs in constructors.

When searching for construction contexts, i.e. figuring out which statements
define the object that is constructed by each construct-expression, ignore
transparent init-list expressions because they don't add anything to the
context. This allows the Static Analyzer to model construction, destruction,
materialization, lifetime extension correctly in more cases. Also fixes
a crash caused by incorrectly evaluating initial values of variables
initialized with such expressions.

Differential Revision: https://reviews.llvm.org/D59573

llvm-svn: 356634

5 years agoAllow disabling of filesystem library.
Eric Fiselier [Thu, 21 Mar 2019 00:04:31 +0000 (00:04 +0000)]
Allow disabling of filesystem library.

Summary: Filesystem doesn't work on Windows, so we need a mechanism to turn it off for the time being.

Reviewers: ldionne, serge-sans-paille, EricWF

Reviewed By: EricWF

Subscribers: mstorsjo, mgorny, christof, jdoerfert, libcxx-commits

Differential Revision: https://reviews.llvm.org/D59619

llvm-svn: 356633

5 years ago[libcxx] [test] Add (void) casts to operator new calls, to suppress warnings generate...
Billy Robert O'Neal III [Wed, 20 Mar 2019 23:58:46 +0000 (23:58 +0000)]
[libcxx] [test] Add (void) casts to operator new calls, to suppress warnings generated by [[nodiscard]].

This allows these tests to pass when compiled by MSVC++.

llvm-svn: 356632

5 years ago[X86] Add CMPXCHG8B feature flag. Set it for all CPUs except i386/i486 including...
Craig Topper [Wed, 20 Mar 2019 23:35:49 +0000 (23:35 +0000)]
[X86] Add CMPXCHG8B feature flag. Set it for all CPUs except i386/i486 including 'generic'. Disable use of CMPXCHG8B when this flag isn't set.

CMPXCHG8B was introduced on i586/pentium generation.

If its not enabled, limit the atomic width to 32 bits so the AtomicExpandPass will expand to lib calls. Unclear if we should be using a different limit for other configs. The default is 1024 and experimentation shows that using an i256 atomic will cause a crash in SelectionDAG.

Differential Revision: https://reviews.llvm.org/D59576

llvm-svn: 356631

5 years agoRevert "Reland r356547 after fixing the tests for Linux."
Douglas Yung [Wed, 20 Mar 2019 23:21:43 +0000 (23:21 +0000)]
Revert "Reland r356547 after fixing the tests for Linux."

This reverts commit 538fb72226cf6dff95af83f7777e12b8dbd061ea (r356565).

This is still breaking a build bot:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/45557

llvm-svn: 356630

5 years agoFix Mach-O bind and rebase validation errors in libObject
Michael Trent [Wed, 20 Mar 2019 23:21:16 +0000 (23:21 +0000)]
Fix Mach-O bind and rebase validation errors in libObject

Summary:
llvm-objdump (via libObject) validates DYLD_INFO rebase and bind
entries against the basic structure found in the Mach-O file before
evaluating the contents of those entries. Certain malformed Mach-Os can
defeat the validation check and force llvm-objdump (libObject) to crash.

The previous logic verified a rebase or bind started in a valid Mach-O
section, but did not verify that the section wholely contained the
fixup. It also generally allows rebases or binds to start immediately
after a valid section even if that range is not itself part of a valid
section. Finally, bind and rebase opcodes that indicate more than one
fixup (apply N times...) are not completely validated: only the first
and final fixups are checked.

The previous logic also rejected certain binaries as false positives.
Some bind and rebase opcodes can modify the state machine such that the
next bind or rebase will fail. libObject will reject these opcodes as
invalid in order to be helpful and print an error message associated
with the instruction that caused the problem, even though the binary is
not actually illegal until it consumes the invalid state in the state
machine. In other words, libObject may reject a Mach-O binary that
Apple's dynamic linker may consider legal. The original version of
macho-rebase-add-addr-uleb-too-big is an example of such a binary.

I have replaced the existing checkSegAndOffset and checkCountAndSkip
functions with a single function, checkSegAndOffsets, which validates
all of the fixups realized by a DYLD_INFO opcode. checkSegAndOffsets
verifies that a Mach-O section fully contains each fixup. Every fixup
realized by an opcode is validated, and some (but not all!)
inconsistencies in the state machine are allowed until a fixup is
realized. This means that libObject may fail on an opcode that realizes
a fixup, not on the opcode that introduced the arithmetic error.

Existing test cases have been modified to reflect the changes in error
messages returned by libObject. What's more, the test case for
macho-rebase-add-addr-uleb-too-big has been modified so that it actually
triggers the error condition; the new code in libObject considers the
original test binary "legal".

rdar://47797757

Reviewers: lhames, pete, ab

Reviewed By: pete

Subscribers: rupprecht, jdoerfert, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D59574

llvm-svn: 356629

5 years agoRemove extra white spaces
Jennifer Yu [Wed, 20 Mar 2019 23:05:18 +0000 (23:05 +0000)]
Remove extra white spaces

llvm-svn: 356628

5 years ago[clang-tidy] Disable google-runtime-int in Objective-C++ 🔓
Stephane Moore [Wed, 20 Mar 2019 23:05:00 +0000 (23:05 +0000)]
[clang-tidy] Disable google-runtime-int in Objective-C++ ðŸ”“

Summary:
In contrast to Google C++, Objective-C often uses built-in integer types
other than `int`. In fact, the Objective-C runtime itself defines the
types NSInteger¹ and NSUInteger² which are variant types depending on
the target architecture. The Objective-C style guide indicates that
usage of system types with variant sizes is appropriate when handling
values provided by system interfaces³. Objective-C++ is commonly the
result of conversion from Objective-C to Objective-C++ for the purpose
of integrating C++ functionality. The opposite of Objective-C++ being
used to expose Objective-C functionality to C++ is less common,
potentially because Objective-C has a signficantly more uneven presence
on different platforms compared to C++. This generally predisposes
Objective-C++ to commonly being more Objective-C than C++. Forcing
Objective-C++ developers to perform conversions between variant system types
and fixed size integer types depending on target architecture when
Objective-C++ commonly uses variant system types from Objective-C is
likely to lead to more bugs and overhead than benefit. For that reason,
this change proposes to disable google-runtime-int in Objective-C++.

[1] https://developer.apple.com/documentation/objectivec/nsinteger?language=objc
[2] https://developer.apple.com/documentation/objectivec/nsuinteger?language=objc
[3] "Types long, NSInteger, NSUInteger, and CGFloat vary in size between
32- and 64-bit builds. Use of these types is appropriate when handling
values exposed by system interfaces, but they should be avoided for most
other computations."
https://github.com/google/styleguide/blob/gh-pages/objcguide.md#types-with-inconsistent-sizes

Subscribers: xazax.hun, jdoerfert, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59336

llvm-svn: 356627

5 years agoChange the logging on ptrace(PT_KILL) in MachProcess::Kill to log
Jason Molenda [Wed, 20 Mar 2019 22:59:16 +0000 (22:59 +0000)]
Change the logging on ptrace(PT_KILL) in MachProcess::Kill to log
if LOG_PROCESS is enabled or if there was an error making that call.

<rdar://problem/49036508>

llvm-svn: 356626

5 years agoUpdate DWARF files.
Jason Molenda [Wed, 20 Mar 2019 22:57:33 +0000 (22:57 +0000)]
Update DWARF files.

llvm-svn: 356625

5 years agolibc++/win: Make once_flag have the same size as a pointer.
Nico Weber [Wed, 20 Mar 2019 22:55:03 +0000 (22:55 +0000)]
libc++/win: Make once_flag have the same size as a pointer.

`unsigned long` is 32-bit on 32-bit systems and 64-bit on 64-bit systems
on LP64 systems -- which most Unix systems are, but Windows isn't.
Windows is LLP64, which means unsigned long is 32-bit even on 64-bit
systems.

pplwin.h contains

    static_assert(alignof(void *) == alignof(::std::once_flag), ...)

which fails due to this problem.

Instead of unsigned long, use uintptr_t, which consistently is 32-bit
on 32-bit systems and 64-bit on 64-bit systems.

No functional change except on 64-bit Windows.

Differential Revision: https://reviews.llvm.org/D59607

llvm-svn: 356624

5 years agoRevert "[clangd] Print arguments in template specializations"
Jordan Rupprecht [Wed, 20 Mar 2019 22:51:56 +0000 (22:51 +0000)]
Revert "[clangd] Print arguments in template specializations"

This reverts commit 44a63f6a150dec72dea43730d2a89d292e58bd6f. It segfaults on an internal test case (will follow up off thread).

llvm-svn: 356623

5 years ago[WebAssembly][NFC] Fix formatting error from rL356610
Thomas Lively [Wed, 20 Mar 2019 22:34:34 +0000 (22:34 +0000)]
[WebAssembly][NFC] Fix formatting error from rL356610

llvm-svn: 356622

5 years ago[AMDGPU] Do not generate spurious PAL metadata
Tim Renouf [Wed, 20 Mar 2019 22:02:09 +0000 (22:02 +0000)]
[AMDGPU] Do not generate spurious PAL metadata

My previous fix rL356591 "[AMDGPU] Added MsgPack format PAL metadata"
accidentally caused a spurious PAL metadata .note record to be emitted
for any AMDGPU output. That caused failures in the lld test
amdgpu-relocs.s. Fixed.

Differential Revision: https://reviews.llvm.org/D59613

Change-Id: Ie04a2aaae890dcd490f22c89edf9913a77ce070e
llvm-svn: 356621

5 years ago[InstCombine] Add additional sub nsw inference tests; NFC
Nikita Popov [Wed, 20 Mar 2019 21:42:17 +0000 (21:42 +0000)]
[InstCombine] Add additional sub nsw inference tests; NFC

nsw can be determined based on known bits here, but currently
isn't.

llvm-svn: 356620

5 years agoAllow machine dce to remove uses in the same instruction
Stanislav Mekhanoshin [Wed, 20 Mar 2019 21:42:05 +0000 (21:42 +0000)]
Allow machine dce to remove uses in the same instruction

Machine DCE cannot remove a dead definition if there are non-dbg uses.
A use however can be in the same instruction:

  dead %0 = INST %0

Such instructions sometimes created by Detect dead lanes pass.

Allow this instruction to be deleted despite the use if the only use
belongs to the same instruction.

Differential Revision: https://reviews.llvm.org/D59565

llvm-svn: 356619

5 years ago[X86] Call lowerShuffleAsBitMask for 512-bit vectors in lowerShuffleAsBlend.
Craig Topper [Wed, 20 Mar 2019 21:30:20 +0000 (21:30 +0000)]
[X86] Call lowerShuffleAsBitMask for 512-bit vectors in lowerShuffleAsBlend.

This patch enables the use of lowerShuffleAsBitMask for 512-bit blends before
falling back to move immedate, GPR to k-register, and masked op.

I had to make some changes to support v8i64 when i64 is not a legal type. And to
support floating point types.

This trades a load for the move immediate and GPR move which is higher latency.
But its probably better for register pressure not having to hop through other
register classes. The load+and should play better with LICM and
rematerialization I think.

Differential Revision: https://reviews.llvm.org/D59479

llvm-svn: 356618

5 years ago[AMDGPU] Fix dependency on `BinaryFormat`
Michael Liao [Wed, 20 Mar 2019 21:22:27 +0000 (21:22 +0000)]
[AMDGPU] Fix dependency on `BinaryFormat`

Summary: - The linking is broken when this library is built as shared one.

Subscribers: arsenm, kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D59610

llvm-svn: 356617

5 years ago[libc++] Mark <filesystem> as unavailable on Apple platforms using pragmas
Louis Dionne [Wed, 20 Mar 2019 21:18:14 +0000 (21:18 +0000)]
[libc++] Mark <filesystem> as unavailable on Apple platforms using pragmas

Summary:
Also add the corresponding XFAILs to tests that require filesystem.
The approach taken to mark <filesystem> as unavailable in this patch
is to mark all the header as unavailable using #pragma clang attribute.
Marking each declaration using the attribute is more intrusive and
does not provide a lot of value right now because pretty much everything
in <filesystem> requires dylib support, often transitively.

This is an alternative to https://reviews.llvm.org/D59093.
A similar (but partial) patch was already applied in r356558.

Reviewers: mclow.lists, EricWF, serge-sans-paille

Subscribers: christof, jkorous, dexonsmith, libcxx-commits

Differential Revision: https://reviews.llvm.org/D59224

llvm-svn: 356616

5 years ago[clang-format][NFC] fix release notes build issue
Paul Hoad [Wed, 20 Mar 2019 21:02:12 +0000 (21:02 +0000)]
[clang-format][NFC] fix release notes build issue

build issue from r356613

llvm-svn: 356615

5 years ago[clang][OpenMP] Fix build when using libgomp
Jordan Rupprecht [Wed, 20 Mar 2019 21:01:56 +0000 (21:01 +0000)]
[clang][OpenMP] Fix build when using libgomp

Summary: rL356570 introduced a test which only passes with the default openmp library, libomp, and fails with other openmp libraries, such as libgomp. Explicitly choose libomp.

Reviewers: lebedev.ri

Subscribers: guansong, jdoerfert, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59609

llvm-svn: 356614

5 years ago[clang-format] BeforeHash added to IndentPPDirectives
Paul Hoad [Wed, 20 Mar 2019 20:49:43 +0000 (20:49 +0000)]
[clang-format] BeforeHash added to IndentPPDirectives

Summary:
The option BeforeHash added to IndentPPDirectives.
Fixes Bug 36019. https://bugs.llvm.org/show_bug.cgi?id=36019

Reviewers: djasper, klimek, krasimir, sammccall, mprobst, Nicola, MyDeveloperDay

Reviewed By: klimek, MyDeveloperDay

Subscribers: kadircet, MyDeveloperDay, mnussbaum, geleji, ufna, cfe-commits

Patch by to-mix.

Differential Revision: https://reviews.llvm.org/D52150

llvm-svn: 356613

5 years agoIntroduce DWARFContext.
Zachary Turner [Wed, 20 Mar 2019 20:49:25 +0000 (20:49 +0000)]
Introduce DWARFContext.

LLVM's DWARF parsing library has a class called DWARFContext which holds
all of the various DWARF data sections and lots of other information.
LLDB's on the other hand stores all of this directly in SymbolFileDWARF
/ SymbolFileDWARFDwo and passes this interface around through the
parsing library. Obviously this is incompatible with a world where the
low level interface does not depend on the high level interface, so we
need to move towards a model similar to LLVM's - i.e. all of the context
needed for low level parsing should be in a single class, and that class
gets passed around.

This patch is a small incremental step towards achieving this. The
interface and internals deviate from LLVM's for technical reasons, but
the high level idea is the same. The goal is, eventually, to remove all
occurrences of SymbolFileDWARF from the low level parsing code.

For now I've chosen a very simple section - the .debug_aranges section
to move into DWARFContext while leaving everything else unchanged. In
the short term this is a bit confusing because now the information you
need might come from either of 2 different locations. But it's a huge
refactor to do this all at once and runs a much higher risk of breaking
things. So I think it would be wise to do this in very small pieces.

TL;DR - No functional change

Differential Revision: https://reviews.llvm.org/D59562

llvm-svn: 356612

5 years agoAMDGPU: Don't look for constant in insert/extract_vector_elt regbankselect
Matt Arsenault [Wed, 20 Mar 2019 20:41:34 +0000 (20:41 +0000)]
AMDGPU: Don't look for constant in insert/extract_vector_elt regbankselect

The constantness shouldn't change the register bank choice. We also
don't need to restrict this to only indexing VGPRs, since it's
possible to index SGPRs (but SelectionDAG made using this
difficult). Allow directly indexing SGPRs when appropriate.

llvm-svn: 356611

5 years ago[WebAssembly] Target features section
Thomas Lively [Wed, 20 Mar 2019 20:26:45 +0000 (20:26 +0000)]
[WebAssembly] Target features section

Summary:
Implements a new target features section in assembly and object files
that records what features are used, required, and disallowed in
WebAssembly objects. The linker uses this information to ensure that
all objects participating in a link are feature-compatible and records
the set of used features in the output binary for use by optimizers
and other tools later in the toolchain.

The "atomics" feature is always required or disallowed to prevent
linking code with stripped atomics into multithreaded binaries. Other
features are marked used if they are enabled globally or on any
function in a module.

Future CLs will add linker flags for ignoring feature compatibility
checks and for specifying the set of allowed features, implement using
the presence of the "atomics" feature to control the type of memory
and segments in the linked binary, and add front-end flags for
relaxing the linkage policy for atomics.

Reviewers: aheejin, sbc100, dschuff

Subscribers: jgravelle-google, hiraditya, sunfish, mgrang, jfb, jdoerfert, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D59173

llvm-svn: 356610

5 years ago[X86] Add __crc32b/__crc32w/__crc32d/__crc32q intrinsics to match gcc and icc.
Craig Topper [Wed, 20 Mar 2019 20:25:28 +0000 (20:25 +0000)]
[X86] Add __crc32b/__crc32w/__crc32d/__crc32q intrinsics to match gcc and icc.

gcc has these intrinsics in ia32intrin.h as well. And icc implements them
though they aren't documented in the Intel Intrinsics Guide.

Differential Revision: https://reviews.llvm.org/D59533

llvm-svn: 356609

5 years ago[AMDGPU] Fix clamp bit DAG operand
Michael Liao [Wed, 20 Mar 2019 20:18:56 +0000 (20:18 +0000)]
[AMDGPU] Fix clamp bit DAG operand

Summary:
- Should use `targetconstant` instead of `constant` operand for clamp
  bit, which is expected as an immediate operand. Under certain
  conditions, such as a common `i1 false` constant is used in other
  place and selected before the instruction with clamp bit, register
  operand may be added instead of immediate one. Use `targetcosntant` to
  enforce that.

Subscribers: arsenm, kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D59608

llvm-svn: 356608

5 years ago[OPENMP]Improve detection of omp_allocator_handle_t type and predefined
Alexey Bataev [Wed, 20 Mar 2019 20:14:22 +0000 (20:14 +0000)]
[OPENMP]Improve detection of omp_allocator_handle_t type and predefined
allocators.

It is better to deduce omp_allocator_handle_t type from the predefined
allocators, because omp.h header might not define it explicitly. Plus,
it allows to identify the predefined allocators correctly when trying to
build the allcoator for the global variables.

llvm-svn: 356607

5 years ago[ARC] Add ARCOptAddrMode pass to generate postincrement loads/stores.
Pete Couperus [Wed, 20 Mar 2019 20:06:21 +0000 (20:06 +0000)]
[ARC] Add ARCOptAddrMode pass to generate postincrement loads/stores.

Build on newly introduced ARC postincrement loads/stores from r356200.

Patch By Denis Antrushin! <denis@synopsys.com>

Differential Revision: https://reviews.llvm.org/D59409

llvm-svn: 356606

5 years agoFix implicit ios -> watchOS availability version mapping for
Alex Lorenz [Wed, 20 Mar 2019 20:02:00 +0000 (20:02 +0000)]
Fix implicit ios -> watchOS availability version mapping for
versions that have the major number only

rdar://48018651

llvm-svn: 356605

5 years ago[AArch64] Fix formatting (NFC)
Evandro Menezes [Wed, 20 Mar 2019 19:57:59 +0000 (19:57 +0000)]
[AArch64] Fix formatting (NFC)

Indent macro instances properly.

llvm-svn: 356604

5 years agoAMDHSA: Fix COMPUTE_PGM_RSRC2.USER_SGPR calculation when parsing ISA assembly
Konstantin Zhuravlyov [Wed, 20 Mar 2019 19:44:47 +0000 (19:44 +0000)]
AMDHSA: Fix COMPUTE_PGM_RSRC2.USER_SGPR calculation when parsing ISA assembly

It must match https://llvm.org/docs/AMDGPUUsage.html#initial-kernel-execution-state

Differential Revision: https://reviews.llvm.org/D59570

llvm-svn: 356603

5 years agoMark <charconv> tests as unsupported for C++11 and C++14 if you're not testing libc...
Marshall Clow [Wed, 20 Mar 2019 19:43:22 +0000 (19:43 +0000)]
Mark <charconv> tests as unsupported for C++11 and C++14 if you're not testing libc++. Thanks to Louis for the suggestion.

llvm-svn: 356602

5 years ago[ARM] Eliminate redundant "mov rN, sp" instructions in Thumb1.
Eli Friedman [Wed, 20 Mar 2019 19:40:45 +0000 (19:40 +0000)]
[ARM] Eliminate redundant "mov rN, sp" instructions in Thumb1.

This takes sequences like "mov r4, sp; str r0, [r4]", and optimizes them
to something like "str r0, [sp]".

For regular stack variables, this optimization was already implemented:
we lower loads and stores using frame indexes, which are expanded later.
However, when constructing a call frame for a call with more than four
arguments, the existing optimization doesn't apply.  We need to use
stores which are actually relative to the current value of sp, and don't
have an associated frame index.

This patch adds a special case to handle that construct.  At the DAG
level, this is an ISD::STORE where the address is a CopyFromReg from SP
(plus a small constant offset).

This applies only to Thumb1: in Thumb2 or ARM mode, a regular store
instruction can access SP directly, so the COPY gets eliminated by
existing code.

The change to ARMDAGToDAGISel::SelectThumbAddrModeSP is a related
cleanup: we shouldn't pretend that it can select anything other than
frame indexes.

Differential Revision: https://reviews.llvm.org/D59568

llvm-svn: 356601

5 years agoAdd a __has_extension check for '#pragma clang attribute' as an external-declaration
Erik Pilkington [Wed, 20 Mar 2019 19:26:37 +0000 (19:26 +0000)]
Add a __has_extension check for '#pragma clang attribute' as an external-declaration

This was added in r356075.

llvm-svn: 356600

5 years ago[Sema] Deduplicate some availability checking logic
Erik Pilkington [Wed, 20 Mar 2019 19:26:33 +0000 (19:26 +0000)]
[Sema] Deduplicate some availability checking logic

Before this commit, we emit unavailable errors for calls to functions during
overload resolution, and for references to all other declarations in
DiagnoseUseOfDecl. The early checks during overload resolution aren't as good as
the DiagnoseAvailabilityOfDecl based checks, as they error on the code from
PR40991. This commit fixes this by removing the early checking.

llvm.org/PR40991
rdar://48564179

Differential revision: https://reviews.llvm.org/D59394

llvm-svn: 356599

5 years agoRecommit "Support attribute used in member funcs of class templates"
Rafael Auler [Wed, 20 Mar 2019 19:22:24 +0000 (19:22 +0000)]
Recommit "Support attribute used in member funcs of class templates"

This diff previously exposed a bug in LLVM's IRLinker, breaking
buildbots that tried to self-host LLVM with monolithic LTO.
The bug is now in LLVM by D59552

Original commit message:
As PR17480 describes, clang does not support the used attribute
for member functions of class templates. This means that if the member
function is not used, its definition is never instantiated. This patch
changes clang to emit the definition if it has the used attribute.

Test Plan: Added a testcase

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D56928

llvm-svn: 356598

5 years ago[Linker] Fix crash handling appending linkage
Rafael Auler [Wed, 20 Mar 2019 19:20:07 +0000 (19:20 +0000)]
[Linker] Fix crash handling appending linkage

Summary:
When linking two llvm.used arrays, if the resulting merged
array ends up with duplicated elements (with the same name) but with
different types, the IRLinker was crashing. This was supposed to be
legal, as the IRLinker bitcasts elements to match types in these
situations.

This bug was exposed by D56928 in clang to support attribute used
in member functions of class templates. Crash happened when self-hosting
with LTO. Since LLVM depends on attribute used to generate code
for the dump() method, ubiquitous in the code base, many input bc
had a definition of this method referenced in their llvm.used array.
Some of these classes got optimized, changing the type of the first
parameter (this) in the dump method, leading to a scenario with a
pool of valid definitions but some with a different type, triggering
this bug.

This is a memory bug: ValueMapper depends on (calls) the materializer
provided by IRLinker, and this materializer was freely calling RAUW
methods whenever a global definition was updated in the temporary merged
output file. However, replaceAllUsesWith may or may not destroy
constants that use this global. If the linked definition has a type
mismatch regarding the new def and the old def, the materializer would
bitcast the old type to the new type and the elements of the llvm.used
array, which already uses bitcast to i8*, would end up with elements
cascading two bitcasts. RAUW would then indirectly call the
constantfolder to update the constant to the new ref, which would,
instead of updating the constant, destroy it to be able to create
a new constant that folds the two bitcasts into one. The problem is that
ValueMapper works with pointers to the same constants that may be
getting destroyed by RAUW. Obviously, RAUW can update references in the
Module to do not use the old destroyed constant, but it can't update
ValueMapper's internal pointers to these constants, which are now
invalid.

The approach here is to move the task of RAUWing old definitions
outside of the materializer.

Test Plan:
Added LIT test case, tested clang self-hosting with D56928 and
verified it works

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D59552

llvm-svn: 356597

5 years ago[NFC] Fix brace indentation.
Alina Sbirlea [Wed, 20 Mar 2019 19:18:55 +0000 (19:18 +0000)]
[NFC] Fix brace indentation.

llvm-svn: 356596

5 years ago[libc++] Use the compiler that CMake found when running lit for back-deployment tests
Louis Dionne [Wed, 20 Mar 2019 19:12:27 +0000 (19:12 +0000)]
[libc++] Use the compiler that CMake found when running lit for back-deployment tests

llvm-svn: 356595

5 years agoResubmit r356511 "[TailCallElim] Add tailcall elimination pass to LTO pipelines"
Robert Lougher [Wed, 20 Mar 2019 19:08:18 +0000 (19:08 +0000)]
Resubmit r356511 "[TailCallElim] Add tailcall elimination pass to LTO pipelines"

Failing LLD tests have been fixed in r356593.

llvm-svn: 356594

5 years ago[TailCallElim] Update tests for LTO pipeline change
Robert Lougher [Wed, 20 Mar 2019 19:05:05 +0000 (19:05 +0000)]
[TailCallElim] Update tests for LTO pipeline change

D58391 changed the LTO pipelines to add the tailcall elimination pass.
This caused three LLD tests to fail.

Differential Revision: https://reviews.llvm.org/D59604

llvm-svn: 356593

5 years agoRemove the unused return value in ASTImporter::Imported [NFC]
Raphael Isemann [Wed, 20 Mar 2019 19:00:25 +0000 (19:00 +0000)]
Remove the unused return value in ASTImporter::Imported [NFC]

Summary:
`ASTImporter::Imported` currently returns a Decl, but that return value is not used by the ASTImporter (or anywhere else)
nor is it documented.

Reviewers: balazske, martong, a.sidorin, shafik

Reviewed By: balazske, martong

Subscribers: rnkovacs, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59595

llvm-svn: 356592

5 years ago[AMDGPU] Added MsgPack format PAL metadata
Tim Renouf [Wed, 20 Mar 2019 18:47:21 +0000 (18:47 +0000)]
[AMDGPU] Added MsgPack format PAL metadata

Summary:
PAL metadata now supports both the old linear reg=val pairs format and
the new MsgPack format.

The MsgPack format uses YAML as its textual representation. On output to
YAML, a mnemonic name is provided for some hardware registers.

Differential Revision: https://reviews.llvm.org/D57028

Change-Id: I2bbaabaaca4b3574f7e03b80fbef7c7a69d06a94
llvm-svn: 356591

5 years agoSimplify operands of masked stores and scatters based on demanded elements
Philip Reames [Wed, 20 Mar 2019 18:44:58 +0000 (18:44 +0000)]
Simplify operands of masked stores and scatters based on demanded elements

If we know we're not storing a lane, we don't need to compute the lane. This could be improved by using the undef element result to further prune the mask, but I want to separate that into its own change since it's relatively likely to expose other problems.

Differential Revision: https://reviews.llvm.org/D57247

llvm-svn: 356590

5 years ago[clang-tidy] Fix redundant check breaking the test on many platforms.
Zinovy Nis [Wed, 20 Mar 2019 18:37:04 +0000 (18:37 +0000)]
[clang-tidy] Fix redundant check breaking the test on many platforms.

Differential Revision: https://reviews.llvm.org/D57662

llvm-svn: 356589

5 years ago[LICM & MemorySSA] Don't sink/hoist stores in the presence of ordered loads.
Alina Sbirlea [Wed, 20 Mar 2019 18:33:37 +0000 (18:33 +0000)]
[LICM & MemorySSA] Don't sink/hoist stores in the presence of ordered loads.

Summary:
Before this patch, if any Use existed in the loop, with a defining
access in the loop, we conservatively decide to not move the store.
What this approach was missing, is that ordered loads are not Uses, they're Defs
in MemorySSA. So, even when the clobbering walker does not find that
volatile load to interfere, we still cannot hoist a store past a
volatile load.
Resolves PR41140.

Reviewers: george.burgess.iv

Subscribers: sanjoy, jlebar, Prazek, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D59564

llvm-svn: 356588

5 years ago[libc++][CMake] Clean up some of the libc++ re-exporting logic
Louis Dionne [Wed, 20 Mar 2019 18:16:24 +0000 (18:16 +0000)]
[libc++][CMake] Clean up some of the libc++ re-exporting logic

Summary:
This change allows specifying the version of libc++abi's ABI to re-export
when configuring CMake. It also clearly identifies which ABI version of
libc++abi each export file contains.

Finally, it removes hardcoded knowledge about the 10.9 SDK for MacOS,
since that knowledge is not relevant anymore. Indeed, libc++ can't be
built with the toolchain that came with the 10.9 SDK anyway because
the version of Clang it includes is too old (for example if you want
to build a working libc++.dylib, you need bugfixes to visibility
attributes that are only in recent Clangs).

Reviewers: dexonsmith, EricWF

Subscribers: mgorny, christof, jkorous, arphaman, libcxx-commits

Differential Revision: https://reviews.llvm.org/D59489

llvm-svn: 356587

5 years ago[ValueTracking] Compute range for abs without nsw
Nikita Popov [Wed, 20 Mar 2019 18:16:02 +0000 (18:16 +0000)]
[ValueTracking] Compute range for abs without nsw

This is a small followup to D59511. The code that was moved into
computeConstantRange() there is a bit overly conversative: If the
abs is not nsw, it does not compute any range. However, abs without
nsw still has a well-defined contiguous unsigned range from 0 to
SIGNED_MIN. This is a lot less useful than the usual 0 to SIGNED_MAX
range, but if we're already here we might as well specify it...

Differential Revision: https://reviews.llvm.org/D59563

llvm-svn: 356586

5 years agoMake to_chars/from_chars work back to C++11. This means that we can use them to imple...
Marshall Clow [Wed, 20 Mar 2019 18:13:23 +0000 (18:13 +0000)]
Make to_chars/from_chars work back to C++11. This means that we can use them to implement to_string as well. Reviewed as https://reviews.llvm.org/D59598.

llvm-svn: 356585

5 years ago[InstCombine] Fold add nuw + uadd.with.overflow
Nikita Popov [Wed, 20 Mar 2019 18:00:27 +0000 (18:00 +0000)]
[InstCombine] Fold add nuw + uadd.with.overflow

Fold add nuw and uadd.with.overflow with constants if the
addition does not overflow.

Part of https://bugs.llvm.org/show_bug.cgi?id=38146.

Patch by Dan Robertson.

Differential Revision: https://reviews.llvm.org/D59471

llvm-svn: 356584

5 years ago[Remarks] Fix mismatched delete due to missing virtual destructor
Jordan Rupprecht [Wed, 20 Mar 2019 17:44:24 +0000 (17:44 +0000)]
[Remarks] Fix mismatched delete due to missing virtual destructor

This fixes an asan failure introduced in r356519.

llvm-svn: 356583

5 years ago[AMDGPU] Factored PAL metadata handling out into its own class
Tim Renouf [Wed, 20 Mar 2019 17:42:00 +0000 (17:42 +0000)]
[AMDGPU] Factored PAL metadata handling out into its own class

Summary:
This commit introduces a new AMDGPUPALMetadata class that:
* is inside the AMDGPU target;
* keeps an in-memory representation of PAL metadata;
* provides a method to read the frontend-supplied metadata from LLVM IR;
* provides methods for the asm printer to set metadata items;
* provides methods to write the metadata as a binary blob to put in a
  .note record or as an asm directive;
* provides a method to read the metadata as a binary blob from a .note
  record.

Because llvm-readobj cannot call directly into a target, I had to remove
llvm-readobj's ability to dump PAL metadata, pending a resolution to
https://reviews.llvm.org/D52821

Differential Revision: https://reviews.llvm.org/D57027

Change-Id: I756dc830894fcb6850324cdcfa87c0120eb2cf64
llvm-svn: 356582

5 years agoMake __cpu_model a hidden symbol, to match libgcc.
Sterling Augustine [Wed, 20 Mar 2019 17:37:23 +0000 (17:37 +0000)]
Make __cpu_model a hidden symbol, to match libgcc.
Also hide __cpu_inicator_init and __cpu_features2
for similar reasons.

Summary: Make __cpu_model a hidden symbol, to match libgcc.

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D59561

llvm-svn: 356581

5 years ago[X86] Remove getCPUKindCanonicalName which is unused.
Craig Topper [Wed, 20 Mar 2019 17:26:51 +0000 (17:26 +0000)]
[X86] Remove getCPUKindCanonicalName which is unused.

Differential Revision: https://reviews.llvm.org/D59578

llvm-svn: 356580

5 years agoRemove HAVE_REALPATH from config.h
Nico Weber [Wed, 20 Mar 2019 17:26:11 +0000 (17:26 +0000)]
Remove HAVE_REALPATH from config.h

Its last use was removed in r352916.
No behavior change.

Differential Revision: https://reviews.llvm.org/D59601

llvm-svn: 356579

5 years ago[NFC][ASTMatchers] Alphabetically sort REGISTER_MATCHER() macros in RegistryMaps...
Roman Lebedev [Wed, 20 Mar 2019 17:15:47 +0000 (17:15 +0000)]
[NFC][ASTMatchers] Alphabetically sort REGISTER_MATCHER() macros in RegistryMaps::RegistryMaps()

As noted in https://reviews.llvm.org/D59453#inline-526253

llvm-svn: 356578

5 years ago[AST] Disable ast-dump-openmp-parallel-master-XFAIL.c test
Roman Lebedev [Wed, 20 Mar 2019 17:14:49 +0000 (17:14 +0000)]
[AST] Disable ast-dump-openmp-parallel-master-XFAIL.c test

Fails on MSVC buildbot (but not locally).
Not important as it is 'testing' something that isn't supported yet anyway:
https://bugs.llvm.org/show_bug.cgi?id=41022

llvm-svn: 356577

5 years ago[AMDGPU][MC] Corrected checks for DS offset0 range
Dmitry Preobrazhensky [Wed, 20 Mar 2019 17:13:58 +0000 (17:13 +0000)]
[AMDGPU][MC] Corrected checks for DS offset0 range

See bug 40889: https://bugs.llvm.org/show_bug.cgi?id=40889

Reviewers: artem.tamazov, arsenm

Differential Revision: https://reviews.llvm.org/D59313

llvm-svn: 356576

5 years ago[clang-format] structured binding in range for detected as Objective C
Paul Hoad [Wed, 20 Mar 2019 17:10:23 +0000 (17:10 +0000)]
[clang-format] structured binding in range for detected as Objective C

Summary:
Sometime after 6.0.0 and the current trunk 9.0.0 the following code would be considered as objective C and not C++

Reported by: https://twitter.com/mattgodbolt/status/1096188576503644160

$ clang-format.exe test.h
Configuration file(s) do(es) not support Objective-C: C:\clang\build\.clang-format

--- test.h --
```

std::vector<std::pair<std::string,std::string>> C;

void foo()
{
   for (auto && [A,B] : C)
   {
       std::string D = A + B;
   }
}
```
The following code fixes this issue of incorrect detection

Reviewers: djasper, klimek, JonasToth, reuk

Reviewed By: klimek

Subscribers: cfe-commits

Tags: #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D59546

llvm-svn: 356575

5 years ago[NFC] Fix a couple of typos in libc++'s __config
Louis Dionne [Wed, 20 Mar 2019 17:05:52 +0000 (17:05 +0000)]
[NFC] Fix a couple of typos in libc++'s __config

llvm-svn: 356574

5 years agoFix UUID decoding from minidump files
Greg Clayton [Wed, 20 Mar 2019 16:50:17 +0000 (16:50 +0000)]
Fix UUID decoding from minidump files

This patch fixes:

UUIDs now don't include the age field from a PDB70 when the age is zero. Prior to this they would incorrectly contain the zero age which stopped us from being able to match up the UUID with real files.
UUIDs for Apple targets get the first 32 bit value and next two 16 bit values swapped. Breakpad incorrectly swaps these values when it creates darwin minidump files, so this must be undone so we can match up symbol files with the minidump modules.
UUIDs that are all zeroes are treated as invalid UUIDs. Breakpad will always save out a UUID, even if one wasn't available. This caused all files that have UUID values of zero to be uniqued to the first module that had a zero UUID. We now don't fill in the UUID if it is all zeroes.
Added tests for PDB70 and ELF build ID based CvRecords.

Differential Revision: https://reviews.llvm.org/D59433

llvm-svn: 356573

5 years ago[CGP] fix formatting; NFC
Sanjay Patel [Wed, 20 Mar 2019 16:47:53 +0000 (16:47 +0000)]
[CGP] fix formatting; NFC

llvm-svn: 356572

5 years ago[OpenCL] Generate 'unroll.enable' metadata for __attribute__((opencl_unroll_hint))
Andrew Savonichev [Wed, 20 Mar 2019 16:43:07 +0000 (16:43 +0000)]
[OpenCL] Generate 'unroll.enable' metadata for  __attribute__((opencl_unroll_hint))

Summary:
[OpenCL] Generate 'unroll.enable' metadata for  __attribute__((opencl_unroll_hint))

For both !{!"llvm.loop.unroll.enable"} and !{!"llvm.loop.unroll.full"} the unroller
will try to fully unroll a loop unless the trip count is not known at compile time.
In that case for '.full' metadata no unrolling will be processed, while for '.enable'
the loop will be partially unrolled with a heuristically chosen unroll factor.

See: docs/LanguageExtensions.rst

From https://www.khronos.org/registry/OpenCL/sdk/2.0/docs/man/xhtml/attributes-loopUnroll.html

    __attribute__((opencl_unroll_hint))
    for (int i=0; i<2; i++)
    {
        ...
    }

In the example above, the compiler will determine how much to unroll the loop.

Before the patch for  __attribute__((opencl_unroll_hint)) was generated metadata
!{!"llvm.loop.unroll.full"}, which limits ability of loop unroller to decide, how
much to unroll the loop.

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia

Subscribers: zzheng, dmgreen, jdoerfert, cfe-commits, asavonic, AlexeySotkin

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59493

llvm-svn: 356571

5 years ago[clang][OpeMP] Model OpenMP structured-block in AST (PR40563)
Roman Lebedev [Wed, 20 Mar 2019 16:32:36 +0000 (16:32 +0000)]
[clang][OpeMP] Model OpenMP structured-block in AST (PR40563)

Summary:
https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5.0.pdf, page 3:
```
structured block

For C/C++, an executable statement, possibly compound, with a single entry at the
top and a single exit at the bottom, or an OpenMP construct.

COMMENT: See Section 2.1 on page 38 for restrictions on structured
blocks.
```
```
2.1 Directive Format

Some executable directives include a structured block. A structured block:
• may contain infinite loops where the point of exit is never reached;
• may halt due to an IEEE exception;
• may contain calls to exit(), _Exit(), quick_exit(), abort() or functions with a
_Noreturn specifier (in C) or a noreturn attribute (in C/C++);
• may be an expression statement, iteration statement, selection statement, or try block, provided
that the corresponding compound statement obtained by enclosing it in { and } would be a
structured block; and

Restrictions
Restrictions to structured blocks are as follows:
• Entry to a structured block must not be the result of a branch.
• The point of exit cannot be a branch out of the structured block.
C / C++
• The point of entry to a structured block must not be a call to setjmp().
• longjmp() and throw() must not violate the entry/exit criteria.
```

Of particular note here is the fact that OpenMP structured blocks are as-if `noexcept`,
in the same sense as with the normal `noexcept` functions in C++.
I.e. if throw happens, and it attempts to travel out of the `noexcept` function
(here: out of the current structured-block), then the program terminates.

Now, one of course can say that since it is explicitly prohibited by the Specification,
then any and all programs that violate this Specification contain undefined behavior,
and are unspecified, and thus no one should care about them. Just don't write broken code /s

But i'm not sure this is a reasonable approach.
I have personally had oss-fuzz issues of this origin - exception thrown inside
of an OpenMP structured-block that is not caught, thus causing program termination.
This issue isn't all that hard to catch, it's not any particularly different from
diagnosing the same situation with the normal `noexcept` function.

Now, clang static analyzer does not presently model exceptions.
But clang-tidy has a simplisic [[ https://clang.llvm.org/extra/clang-tidy/checks/bugprone-exception-escape.html | bugprone-exception-escape ]] check,
and it is even refactored as a `ExceptionAnalyzer` class for reuse.
So it would be trivial to use that analyzer to check for
exceptions escaping out of OpenMP structured blocks. (D59466)

All that sounds too great to be true. Indeed, there is a caveat.
Presently, it's practically impossible to do. To check a OpenMP structured block
you need to somehow 'get' the OpenMP structured block, and you can't because
it's simply not modelled in AST. `CapturedStmt`/`CapturedDecl` is not it's representation.

Now, it is of course possible to write e.g. some AST matcher that would e.g.
match every OpenMP executable directive, and then return the whatever `Stmt` is
the structured block of said executable directive, if any.
But i said //practically//. This isn't practical for the following reasons:
1. This **will** bitrot. That matcher will need to be kept up-to-date,
   and refreshed with every new OpenMP spec version.
2. Every single piece of code that would want that knowledge would need to
   have such matcher. Well, okay, if it is an AST matcher, it could be shared.
   But then you still have `RecursiveASTVisitor` and friends.
   `2 > 1`, so now you have code duplication.

So it would be reasonable (and is fully within clang AST spirit) to not
force every single consumer to do that work, but instead store that knowledge
in the correct, and appropriate place - AST, class structure.

Now, there is another hoop we need to get through.
It isn't fully obvious //how// to model this.
The best solution would of course be to simply add a `OMPStructuredBlock` transparent
node. It would be optimal, it would give us two properties:
* Given this `OMPExecutableDirective`, what's it OpenMP structured block?
* It is trivial to  check whether the `Stmt*` is a OpenMP structured block (`isa<OMPStructuredBlock>(ptr)`)

But OpenMP structured block isn't **necessarily** the first, direct child of `OMP*Directive`.
(even ignoring the clang's `CapturedStmt`/`CapturedDecl` that were inserted inbetween).
So i'm not sure whether or not we could re-create AST statements after they were already created?
There would be other costs to a new AST node: https://bugs.llvm.org/show_bug.cgi?id=40563#c12
```
1. You will need to break the representation of loops. The body should be replaced by the "structured block" entity.
2. You will need to support serialization/deserialization.
3. You will need to support template instantiation.
4. You will need to support codegen and take this new construct to account in each OpenMP directive.
```

Instead, there **is** an functionally-equivalent, alternative solution, consisting of two parts.

Part 1:
* Add a member function `isStandaloneDirective()` to the `OMPExecutableDirective` class,
  that will tell whether this directive is stand-alone or not, as per the spec.
  We need it because we can't just check for the existance of associated statements,
  see code comment.
* Add a member function `getStructuredBlock()` to the OMPExecutableDirective` class itself,
  that assert that this is not a stand-alone directive, and either return the correct loop body
  if this is a loop-like directive, or the captured statement.
This way, given an `OMPExecutableDirective`, we can get it's structured block.
Also, since the knowledge is ingrained into the clang OpenMP implementation,
it will not cause any duplication, and //hopefully// won't bitrot.

Great we achieved 1 of 2 properties of `OMPStructuredBlock` approach.

Thus, there is a second part needed:
* How can we check whether a given `Stmt*` is `OMPStructuredBlock`?
Well, we can't really, in general. I can see this workaround:
```
class FunctionASTVisitor : public RecursiveASTVisitor<FunctionASTVisitor> {
  using Base = RecursiveASTVisitor<FunctionASTVisitor>;
public:
  bool VisitOMPExecDir(OMPExecDir *D) {
    OmpStructuredStmts.emplace_back(D.getStructuredStmt());
  }
  bool VisitSOMETHINGELSE(???) {
    if(InOmpStructuredStmt)
      HI!
  }
  bool TraverseStmt(Stmt *Node) {
    if (!Node)
      return Base::TraverseStmt(Node);
    if (OmpStructuredStmts.back() == Node)
      ++InOmpStructuredStmt;
    Base::TraverseStmt(Node);
    if (OmpStructuredStmts.back() == Node) {
      OmpStructuredStmts.pop_back();
      --InOmpStructuredStmt;
    }
    return true;
  }
  std::vector<Stmt*> OmpStructuredStmts;
  int InOmpStructuredStmt = 0;
};
```
But i really don't see using it in practice.
It's just too intrusive; and again, requires knowledge duplication.

.. but no. The solution lies right on the ground.
Why don't we simply store this `i'm a openmp structured block` in the bitfield of the `Stmt` itself?
This does not appear to have any impact on the memory footprint of the clang AST,
since it's just a single extra bit in the bitfield. At least the static assertions don't fail.
Thus, indeed, we can achieve both of the properties without a new AST node.

We can cheaply set that bit right in sema, at the end of `Sema::ActOnOpenMPExecutableDirective()`,
by just calling the `getStructuredBlock()` that we just added.
Test coverage that demonstrates all this has been added.

This isn't as great with serialization though. Most of it does not use abbrevs,
so we do end up paying the full price (4 bytes?) instead of a single bit.
That price, of course, can be reclaimed by using abbrevs.
In fact, i suspect that //might// not just reclaim these bytes, but pack these PCH significantly.

I'm not seeing a third solution. If there is one, it would be interesting to hear about it.
("just don't write code that would require `isa<OMPStructuredBlock>(ptr)`" is not a solution.)

Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=40563 | PR40563 ]].

Reviewers: ABataev, rjmccall, hfinkel, rsmith, riccibruno, gribozavr

Reviewed By: ABataev, gribozavr

Subscribers: mgorny, aaron.ballman, steveire, guansong, jfb, jdoerfert, cfe-commits

Tags: #clang, #openmp

Differential Revision: https://reviews.llvm.org/D59214

llvm-svn: 356570

5 years ago[NFC][clang][astdump] Some baseline tests for OpenMP
Roman Lebedev [Wed, 20 Mar 2019 16:31:47 +0000 (16:31 +0000)]
[NFC][clang][astdump] Some baseline tests for OpenMP

Summary:
Split off from D59214.
Not a fully exhaustive test coverage, but better than what there currently is.

Differential Revision: https://reviews.llvm.org/D59306

llvm-svn: 356569

5 years agoFix sanitizer failures for 356550.
Clement Courbet [Wed, 20 Mar 2019 16:14:59 +0000 (16:14 +0000)]
Fix sanitizer failures for 356550.

Mark bcmp as having optimized codegen, so that asan can detect it and
mark users as nobuiltin.

llvm-svn: 356568

5 years agogn build: Add build files for some clang-tools-extra
Nico Weber [Wed, 20 Mar 2019 16:14:16 +0000 (16:14 +0000)]
gn build: Add build files for some clang-tools-extra

Adds clang-change-namespace, clang-move, clang-query,
clang-reorder-fields.

Differential Revision: https://reviews.llvm.org/D59554

llvm-svn: 356567

5 years ago[CGP] convert chain of 'if' to 'switch'; NFC
Sanjay Patel [Wed, 20 Mar 2019 15:53:06 +0000 (15:53 +0000)]
[CGP] convert chain of 'if' to 'switch'; NFC

This should be extended, but CGP does some strange things,
so I'm intentionally not changing the potential order of
any transforms yet.

llvm-svn: 356566

5 years agoReland r356547 after fixing the tests for Linux.
Zinovy Nis [Wed, 20 Mar 2019 15:50:26 +0000 (15:50 +0000)]
Reland r356547 after fixing the tests for Linux.

[clang-tidy] Parallelize clang-tidy-diff.py

This patch has 2 rationales:

- large patches lead to long command lines and often cause max command line length restrictions imposed by OS;
- clang-tidy runs on modified files are independent and can be done in parallel, the same as done for run-clang-tidy.

Differential Revision: https://reviews.llvm.org/D57662

llvm-svn: 356565

5 years ago[ASTImporter] Remove obsolete function ImportTemplateParameterList.
Balazs Keri [Wed, 20 Mar 2019 15:42:42 +0000 (15:42 +0000)]
[ASTImporter] Remove obsolete function ImportTemplateParameterList.

Summary:
The ASTNodeImporter::ImportTemplateParameterList is replaced by a
template specialization of 'import' that already exists and does
(almost) the same thing.

Reviewers: martong, a.sidorin, shafik, a_sidorin

Reviewed By: martong

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59134

llvm-svn: 356564

5 years agogn build: Merge r356508
Nico Weber [Wed, 20 Mar 2019 15:41:25 +0000 (15:41 +0000)]
gn build: Merge r356508

llvm-svn: 356563

5 years ago[libc++] Do not force going through xcrun to find Clang in the macOS CI scripts
Louis Dionne [Wed, 20 Mar 2019 15:40:56 +0000 (15:40 +0000)]
[libc++] Do not force going through xcrun to find Clang in the macOS CI scripts

It should be possible to run those CI scripts with different compilers
by simply exporting a different CXX environment variable.

llvm-svn: 356562

5 years ago[AMDGPU][MC][GFX9] Added support of operands shared_base, shared_limit, private_base...
Dmitry Preobrazhensky [Wed, 20 Mar 2019 15:40:52 +0000 (15:40 +0000)]
[AMDGPU][MC][GFX9] Added support of operands shared_base, shared_limit, private_base, private_limit, pops_exiting_wave_id

See bug 39297: https://bugs.llvm.org/show_bug.cgi?id=39297

Reviewers: artem.tamazov, arsenm, rampitec

Differential Revision: https://reviews.llvm.org/D59290

llvm-svn: 356561

5 years agogn build: Merge r356519
Nico Weber [Wed, 20 Mar 2019 15:36:11 +0000 (15:36 +0000)]
gn build: Merge r356519

llvm-svn: 356560

5 years ago[CGP][x86] add tests for usubo regression (PR41129); NFC
Sanjay Patel [Wed, 20 Mar 2019 15:02:35 +0000 (15:02 +0000)]
[CGP][x86] add tests for usubo regression (PR41129); NFC

llvm-svn: 356559

5 years ago[libc++] Mark <filesystem> tests as failing when the dylib doesn't support filesystem
Louis Dionne [Wed, 20 Mar 2019 14:34:00 +0000 (14:34 +0000)]
[libc++] Mark <filesystem> tests as failing when the dylib doesn't support filesystem

This fixes CI for back-deployment testers on platforms that don't have
<filesystem> support in the dylib.

This is effectively half of https://reviews.llvm.org/D59224. The other
half requires fixes in Clang.

llvm-svn: 356558

5 years agoFollow up of rL356555
Sjoerd Meijer [Wed, 20 Mar 2019 14:33:39 +0000 (14:33 +0000)]
Follow up of rL356555

Pacify buildbot that complained about a member function not marked with
override.

llvm-svn: 356557

5 years ago[scudo][standalone] Add error reports
Kostya Kortchinsky [Wed, 20 Mar 2019 14:31:23 +0000 (14:31 +0000)]
[scudo][standalone] Add error reports

Summary:
This change adds fatal error messages for various error conditions that
will be added later in the code.
This also addresses a `TODO` now that we have `reportCheckFailed` (which
lead me to notice a few variables that were not cased properly so I
changed that as well).

Reviewers: morehouse, hctim, vitalybuka

Reviewed By: morehouse, hctim, vitalybuka

Subscribers: mgorny, delcypher, jfb, jdoerfert, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

Differential Revision: https://reviews.llvm.org/D59551

llvm-svn: 356556