Commit Graph

11064 Commits

Author SHA1 Message Date
Volodymyr Sapsai 636ed47428 [CodeGen] Add support for IncompleteArrayType in Obj-C ivars.
Fixes an assertion failure when ivar is a struct containing incomplete
array. Also completes support for direct flexible array members.

rdar://problem/21054495

Reviewers: rjmccall, theraven

Reviewed By: rjmccall

Subscribers: cfe-commits

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

llvm-svn: 316723
2017-10-27 00:56:23 +00:00
Vedant Kumar 9c6b6826ce [CGBlocks] Improve line info in backtraces containing *_helper_block
Instead of only setting a non-zero debug location on the return
instruction in *_helper_block functions, set a proper location on all
instructions within these functions. Pick the start location of the
block literal expr for maximum clarity.

The debugger does not step into *_helper_block functions during normal
single-stepping because we mark their parameters as artificial. This is
what we want (the functions are implicitly generated and uninteresting
to most users). The stepping behavior is unchanged by this patch.

rdar://32907581

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

llvm-svn: 316704
2017-10-26 21:27:24 +00:00
Adrian Prantl 356347b58d Simplify codegen and debug info generation for block context parameters.
The exisiting code goes out of its way to put block parameters into an
alloca only at -O0, and then describes the funciton argument with a
dbg.declare, which is undocumented in the LLVM-CFE contract and does
not actually behave as intended after LLVM r642022.

This patch just generates the alloca unconditionally, the mem2reg pass
will eliminate it at -O1 and up anyway and points the dbg.declare to
the alloca as intended (which mem2reg will then correctly rewrite into
a dbg.value).

This reapplies r316684 with some dead code removed.

rdar://problem/35043980

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

llvm-svn: 316689
2017-10-26 20:08:52 +00:00
Adrian Prantl e78a62207a Revert "Simplify codegen and debug info generation for block context parameters."
This reverts commit r316684 while investigating buildbot breakage.

llvm-svn: 316686
2017-10-26 18:32:16 +00:00
Adrian Prantl 1c45b09add Simplify codegen and debug info generation for block context parameters.
The exisiting code goes out of its way to put block parameters into an
alloca only at -O0, and then describes the funciton argument with a
dbg.declare, which is undocumented in the LLVM-CFE contract and does
not actually behave as intended after LLVM r642022.

This patch just generates the alloca unconditionally, the mem2reg pass
will eliminate it at -O1 and up anyway and points the dbg.declare to
the alloca as intended (which mem2reg will then correctly rewrite into
a dbg.value).

rdar://problem/35043980

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

llvm-svn: 316684
2017-10-26 18:16:05 +00:00
Saleem Abdulrasool 2a5015b11b CodeGen: fix PPC Darwin variadics
Darwin uses char * for the variadic list type (va_list).  We use the PPC
SVR4 ABI for PPC, which uses a structure type for the va_list.  When
constructing the GEP, we would fail due to the incorrect handling for
the va_list.  Correct this to use the right type.

llvm-svn: 316599
2017-10-25 17:56:50 +00:00
Saleem Abdulrasool ad75c7d194 CodeGen: fix a case of incorrect checks for ivars
Ensure that we check the ivar containing decl for the DLL storage
attribute rather than the ivar itself as the dll storage is associated
to the interface decl not the ivar decl.

llvm-svn: 316545
2017-10-25 03:58:15 +00:00
Alexey Bataev 1b48c5e56b [OPENMP] Fix PR35013: Fix passing VLAs captures to outlined functions.
Fixed passing of VLAs and variably-modified types to outlined functions.
Synchronized passing with the types codegen.

llvm-svn: 316488
2017-10-24 19:52:31 +00:00
Yaxun Liu e45b3d5dad CodeGen: Fix missing debug loc due to alloca
Builder save/restores insertion pointer when emitting addr space cast
for alloca, but does not save/restore debug loc, which causes verifier
failure for certain call instructions.

This patch fixes that.

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

llvm-svn: 316484
2017-10-24 19:14:43 +00:00
Jonas Hahnfeld 4525c82428 [OpenMP] Avoid VLAs for some reductions on array sections
In some cases the compiler can deduce the length of an array section
as constants. With this information, VLAs can be avoided in place of
a constant sized array or even a scalar value if the length is 1.
Example:
int a[4], b[2];
pragma omp parallel reduction(+: a[1:2], b[1:1])
{ }

For chained array sections, this optimization is restricted to cases
where all array sections except the last have a constant length 1.
This trivially guarantees that there are no holes in the memory region
that needs to be privatized.
Example:
int c[3][4];
pragma omp parallel reduction(+: c[1:1][1:2])
{ }

This relands commit r316229 that I reverted in r316235 because it
failed on some bots. During investigation I found that this was because
Clang and GCC evaluate the two arguments to emplace_back() in
ReductionCodeGen::emitSharedLValue() in a different order, hence
leading to a different order of generated instructions in the final
LLVM IR. Fix this by passing in the arguments from temporary variables
that are evaluated in a defined order.

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

llvm-svn: 316362
2017-10-23 19:01:35 +00:00
Yaxun Liu bd3823618d CodeGen: Fix invalid bitcast in partial initialization of automatic arrary variable
Differential Revision: https://reviews.llvm.org/D39184

llvm-svn: 316353
2017-10-23 17:49:26 +00:00
Jonas Hahnfeld c95a6985bd Revert "[OpenMP] Avoid VLAs for some reductions on array sections"
This breaks at least two buildbots:
http://lab.llvm.org:8011/builders/clang-cmake-x86_64-avx2-linux/builds/1175
http://lab.llvm.org:8011/builders/clang-atom-d525-fedora-rel/builds/10478

This reverts commit r316229 during local investigation.

llvm-svn: 316235
2017-10-20 20:16:17 +00:00
Jonas Hahnfeld b6229be460 [OpenMP] Avoid VLAs for some reductions on array sections
In some cases the compiler can deduce the length of an array section
as constants. With this information, VLAs can be avoided in place of
a constant sized array or even a scalar value if the length is 1.
Example:
int a[4], b[2];
pragma omp parallel reduction(+: a[1:2], b[1:1])
{ }

For chained array sections, this optimization is restricted to cases
where all array sections except the last have a constant length 1.
This trivially guarantees that there are no holes in the memory region
that needs to be privatized.
Example:
int c[3][4];
pragma omp parallel reduction(+: c[1:1][1:2])
{ }

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

llvm-svn: 316229
2017-10-20 19:40:40 +00:00
Ivan A. Kosarev f761d0e514 [CodeGen] Fix generation of TBAA info for array-to-pointer conversions
Resolves:
Fatal error: Offset not zero at the point of scalar access.
http://llvm.org/PR34992

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

llvm-svn: 316211
2017-10-20 12:35:17 +00:00
Guozhi Wei 769095bd07 [CGExprScalar] Add missing types in function GetIntrinsic
In function GetIntrinsic, not all types are covered. Types double and long long are missed, type long is wrongly treated same as int, it should be same as long long. These problems cause compiler crashes when compiling code in PR31161. This patch fixed the problem.

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

llvm-svn: 316179
2017-10-19 20:11:23 +00:00
Yaxun Liu f2127d1728 [AMDGPU] Fix bug in enqueued block codegen due to an extra line
llvm-svn: 316165
2017-10-19 15:56:13 +00:00
Alexey Bataev 7ba57afd6e [OPENMP] Fix capturing of boolean variables in debug mode.
If the variables is boolean and we generating inner function with real
types, the codegen may crash because of not loading boolean value from
memory.

llvm-svn: 316011
2017-10-17 16:47:34 +00:00
Yaxun Liu 8ab5ab066a CodeGen: Fix invalid bitcasts for atomic builtins
Currently clang assumes the temporary variables emitted during
codegen of atomic builtins have address space 0, which
is not true for target triple amdgcn---amdgiz and causes invalid
bitcasts.

This patch fixes that.

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

llvm-svn: 316000
2017-10-17 14:19:29 +00:00
Ivan A. Kosarev 17db3a10f5 [CodeGen] Refine generation of TBAA info for bit-field lvalues
The main change is that now we generate TBAA info before
constructing the resulting lvalue instead of constructing lvalue
with some default TBAA info and fixing it as necessary
afterwards. We also keep the TBAA info close to lvalue base info,
which is supposed to simplify their future merging.

This patch should not bring in any functional changes.

This is part of D38126 reworked to be a separate patch to
simplify review.

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

llvm-svn: 315989
2017-10-17 11:20:19 +00:00
Ivan A. Kosarev d17f12a35d [CodeGen] Pass TBAA info along with lvalue base info everywhere
This patch addresses the rest of the cases where we pass lvalue
base info, but do not provide corresponding TBAA info.

This patch should not bring in any functional changes.

This is part of D38126 reworked to be a separate patch to make
reviewing easier.

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

llvm-svn: 315986
2017-10-17 10:17:43 +00:00
Ivan A. Kosarev ed141bab63 [CodeGen] EmitPointerWithAlignment() to generate TBAA info along with LValue base info
Differential Revision: https://reviews.llvm.org/D38796

llvm-svn: 315984
2017-10-17 09:12:13 +00:00
Vedant Kumar 341bf42991 [Coverage] Discard deferred region in closing if-else
A trailing deferred region isn't necessary in a function that ends with
this pattern:

  ...
  else {
    ...
    return;
  }

Special-case this pattern so that the closing curly brace of the
function isn't marked as uncovered. This issue came up in PR34962.

llvm-svn: 315982
2017-10-17 07:47:39 +00:00
Vedant Kumar e5f06a81a8 [Coverage] Explicitly mark the l.h.s of && and || (fixes PR33465)
This makes it possible to view sub-line region counts for the l.h.s of
&& and || expressions in coverage reports.

It also fixes PR33465, which shows an example of incorrect coverage
output for an assignment statement containing '||'.

llvm-svn: 315979
2017-10-17 06:51:54 +00:00
Wei Mi 9b3d627280 [Bitfield] Add an option to access bitfield in a fine-grained manner.
Currently all the consecutive bitfields are wrapped as a large integer unless there is unamed zero sized bitfield in between. The patch provides an alternative manner which makes the bitfield to be accessed as separate memory location if it has legal integer width and is naturally aligned. Such separate bitfield may split the original consecutive bitfields into subgroups of consecutive bitfields, and each subgroup will be wrapped as an integer. Now This is all controlled by an option -ffine-grained-bitfield-accesses. The alternative of bitfield access manner can improve the access efficiency of those bitfields with legal width and being aligned, but may reduce the chance of load/store combining of other bitfields, so it depends on how the bitfields are defined and actually accessed to choose when to use the option. For now the option is off by default.

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

llvm-svn: 315915
2017-10-16 16:50:27 +00:00
Alexander Richardson 6d989436d0 Convert clang::LangAS to a strongly typed enum
Summary:
Convert clang::LangAS to a strongly typed enum

Currently both clang AST address spaces and target specific address spaces
are represented as unsigned which can lead to subtle errors if the wrong
type is passed. It is especially confusing in the CodeGen files as it is
not possible to see what kind of address space should be passed to a
function without looking at the implementation.
I originally made this change for our LLVM fork for the CHERI architecture
where we make extensive use of address spaces to differentiate between
capabilities and pointers. When merging the upstream changes I usually
run into some test failures or runtime crashes because the wrong kind of
address space is passed to a function. By converting the LangAS enum to a
C++11 we can catch these errors at compile time. Additionally, it is now
obvious from the function signature which kind of address space it expects.

I found the following errors while writing this patch:

- ItaniumRecordLayoutBuilder::LayoutField was passing a clang AST address
  space to  TargetInfo::getPointer{Width,Align}()
- TypePrinter::printAttributedAfter() prints the numeric value of the
  clang AST address space instead of the target address space.
  However, this code is not used so I kept the current behaviour
- initializeForBlockHeader() in CGBlocks.cpp was passing
  LangAS::opencl_generic to TargetInfo::getPointer{Width,Align}()
- CodeGenFunction::EmitBlockLiteral() was passing a AST address space to
  TargetInfo::getPointerWidth()
- CGOpenMPRuntimeNVPTX::translateParameter() passed a target address space
  to Qualifiers::addAddressSpace()
- CGOpenMPRuntimeNVPTX::getParameterAddress() was using
  llvm::Type::getPointerTo() with a AST address space
- clang_getAddressSpace() returns either a LangAS or a target address
  space. As this is exposed to C I have kept the current behaviour and
  added a comment stating that it is probably not correct.

Other than this the patch should not cause any functional changes.

Reviewers: yaxunl, pcc, bader

Reviewed By: yaxunl, bader

Subscribers: jlebar, jholewinski, nhaehnle, Anastasia, cfe-commits

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

llvm-svn: 315871
2017-10-15 18:48:14 +00:00
Yaxun Liu 98f0c43f85 Fix build failure on android due to missing std::to_string()
llvm-svn: 315805
2017-10-14 12:51:52 +00:00
Yaxun Liu c2a87a05f1 [OpenCL] Emit enqueued block as kernel
In OpenCL the kernel function and non-kernel function has different calling conventions.
For certain targets they have different argument ABIs. Also kernels have special function
attributes and metadata for runtime to launch them.

The blocks passed to enqueue_kernel is supposed to be executed as kernels. As such,
the block invoke function should be emitted as kernel with proper calling convention and
argument ABI.

This patch emits enqueued block as kernel. If a block is both called directly and passed
to enqueue_kernel, separate functions will be generated.

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

llvm-svn: 315804
2017-10-14 12:23:50 +00:00
Vedant Kumar aa4ea5fb45 [ubsan] Don't emit function signatures for non-static member functions
The function sanitizer only checks indirect calls through function
pointers. This excludes all non-static member functions (constructor
calls, calls through thunks, etc. all use a separate code path). Don't
emit function signatures for functions that won't be checked.

Apart from cutting down on code size, this should fix a regression on
Linux caused by r313096. For context, see the mailing list discussion:

r313096 - [ubsan] Function Sanitizer: Don't require writable text segments

Testing: check-clang, check-ubsan

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

llvm-svn: 315786
2017-10-14 01:23:30 +00:00
Ivan A. Kosarev ce601eedf6 Revert "[CodeGen] EmitPointerWithAlignment() to generate TBAA info along with LValue base info", r315731.
With this change we fail on the clang-x86_64-linux-selfhost-modules builder.

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

llvm-svn: 315739
2017-10-13 19:55:01 +00:00
Ivan A. Kosarev 0e528202b8 [CodeGen] EmitPointerWithAlignment() to generate TBAA info along with LValue base info
Differential Revision: https://reviews.llvm.org/D38796

llvm-svn: 315731
2017-10-13 18:40:18 +00:00
Ivan A. Kosarev cbee219700 [CodeGen] emitOMPArraySectionBase() to generate TBAA info along with LValue base info
Differential Revision: https://reviews.llvm.org/D38795

llvm-svn: 315715
2017-10-13 17:34:18 +00:00
Ivan A. Kosarev 78f486d136 [CodeGen] getNaturalTypeAlignment() to generate TBAA info along with LValue base info
This patch should not bring in any functional changes.

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

llvm-svn: 315708
2017-10-13 16:58:30 +00:00
Reid Kleckner 65fa869c23 [SEH] Use the SEH personality on frontend-outlined funclets
This allows __try inside __finally to work.

Fixes PR34939

llvm-svn: 315707
2017-10-13 16:55:14 +00:00
Ivan A. Kosarev 1590fd3aa8 [CodeGen] EmitLoadOfReference() to generate TBAA info along with LValue base info
This patch should not bring in any functional changes.

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

llvm-svn: 315705
2017-10-13 16:50:50 +00:00
Ivan A. Kosarev 9029564e8c [CodeGen] EmitLoadOfPointer() to generate TBAA info along with LValue base info
This patch should not bring in any functional changes.

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

llvm-svn: 315704
2017-10-13 16:47:22 +00:00
Ivan A. Kosarev 229a6d8d17 [CodeGen] EmitCXXMemberDataPointerAddress() to generate TBAA info along with LValue base info
This patch should not bring in any functional changes.

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

llvm-svn: 315702
2017-10-13 16:38:32 +00:00
Haojian Wu 5b5c81f683 Fix an unused-variable warning.
llvm-svn: 315689
2017-10-13 15:37:53 +00:00
Yaxun Liu b7318e02c1 [OpenCL] Add LangAS::opencl_private to represent private address space in AST
Currently Clang uses default address space (0) to represent private address space for OpenCL
in AST. There are two issues with this:

Multiple address spaces including private address space cannot be diagnosed.
There is no mangling for default address space. For example, if private int* is emitted as
i32 addrspace(5)* in IR. It is supposed to be mangled as PUAS5i but it is mangled as
Pi instead.

This patch attempts to represent OpenCL private address space explicitly in AST. It adds
a new enum LangAS::opencl_private and adds it to the variable types which are implicitly
private:

automatic variables without address space qualifier

function parameter

pointee type without address space qualifier (OpenCL 1.2 and below)

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

llvm-svn: 315668
2017-10-13 03:37:48 +00:00
Richard Smith 5b34958b46 Support for destroying operator delete, per C++2a proposal P0722.
This feature is not (yet) approved by the C++ committee, so this is liable to
be reverted or significantly modified based on committee feedback.

No functionality change intended for existing code (a new type must be defined
in namespace std to take advantage of this feature).

llvm-svn: 315662
2017-10-13 01:55:36 +00:00
Reid Kleckner 3da37e05f7 [MS] Don't bail on replacing dllimport vbase dtors with base dtors
Fix PR32990 by effectively reverting r283063 and solving it a different
way.

We want to limit the hack to not replace equivalent available_externally
dtors specifically to libc++, which uses always_inline. It seems certain
versions of libc++ do not provide all the symbols that an explicit
template instantiation is expected to provide.

If we get to the code that forms a real alias, only *then* check if this
is available_externally, and do that by asking a better question, which
is "is this a declaration for the linker?", because *that's* what means
we can't form an alias to it.

As a follow-on simplification, remove the InEveryTU parameter. Its last
use guarded this code for forming aliases, but we should never form
aliases to declarations, regardless of what we know about every TU.

llvm-svn: 315656
2017-10-13 00:53:02 +00:00
Adam Nemet 7b1faaacbe Handle/assert on DK_Remark
We don't generate remarks during inline assembly parsing so no need to handle
these for now.

llvm-svn: 315643
2017-10-12 23:56:54 +00:00
Artem Belevich 91cc00bde6 [CUDA] Added __hmma_m16n16k16_* builtins to support mma instructions on sm_70
Differential Revision: https://reviews.llvm.org/D38742

llvm-svn: 315624
2017-10-12 21:32:19 +00:00
Alexey Bataev a7b19157ba [OPENMP] Fix PR34927: Emit initializer for reduction array with declare
reduction.

If the reduction is an array or an array section and reduction operation
is declare reduction without initializer, it may lead to crash.

llvm-svn: 315611
2017-10-12 20:03:39 +00:00
Alexey Bataev 7b0f1f09a9 [OPENMP] Fix PR34926: Fix handling of the array sections passed as
function params.

Codegen could crash if the array section base expression is the
function parameter.

llvm-svn: 315586
2017-10-12 15:18:41 +00:00
Alexey Bataev 311a928359 [OPENMP] Fix PR34925: Fix getting thread_id lvalue for inlined regions
in C.

If we try to get the lvalue for thread_id variables in inlined regions,
we did not use the correct version of function. Fixed this bug by adding
overrided version of the function getThreadIDVariableLValue for inlined
regions.

llvm-svn: 315578
2017-10-12 13:51:32 +00:00
Ivan A. Kosarev f5f204679b [CodeGen] Generate TBAA info along with LValue base info
This patch enables explicit generation of TBAA information in all
cases where LValue base info is propagated or constructed in
non-trivial ways. Eventually, we will consider each of these
cases to make sure the TBAA information is correct and not too
conservative. For now, we just fall back to generating TBAA info
from the access type.

This patch should not bring in any functional changes.

This is part of D38126 reworked to be a separate patch to
simplify review.

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

llvm-svn: 315575
2017-10-12 11:29:46 +00:00
Zachary Turner 41a9ee98f9 Revert "[ADT] Make Twine's copy constructor private."
This reverts commit 4e4ee1c507e2707bb3c208e1e1b6551c3015cbf5.

This is failing due to some code that isn't built on MSVC
so I didn't catch.  Not immediately obvious how to fix this
at first glance, so I'm reverting for now.

llvm-svn: 315536
2017-10-11 23:54:34 +00:00
Zachary Turner 337462b365 [ADT] Make Twine's copy constructor private.
There's a lot of misuse of Twine scattered around LLVM.  This
ranges in severity from benign (returning a Twine from a function
by value that is just a string literal) to pretty sketchy (storing
a Twine by value in a class).  While there are some uses for
copying Twines, most of the very compelling ones are confined
to the Twine class implementation itself, and other uses are
either dubious or easily worked around.

This patch makes Twine's copy constructor private, and fixes up
all callsites.

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

llvm-svn: 315530
2017-10-11 23:33:06 +00:00
Craig Topper 8c8e83a15f [X86] Add support for 'amdfam17h' to __builtin_cpu_is to match gcc.
The compiler-rt implementation already supported it, it just wasn't exposed.

llvm-svn: 315517
2017-10-11 21:42:02 +00:00
Alexey Bataev 3a03a7f636 [OPENMP] Remove extra if, NFC.
llvm-svn: 315467
2017-10-11 15:56:38 +00:00