Commit Graph

15361 Commits

Author SHA1 Message Date
Mandeep Singh Grang 2147b1af95 [COFF, ARM64] Add _ReadStatusReg and_WriteStatusReg intrinsics
Reviewers: rnk, compnerd, mstorsjo, efriedma, TomTan, haripul, javed.absar

Reviewed By: efriedma

Subscribers: dmajor, kristof.beyls, chrib, cfe-commits

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

llvm-svn: 344765
2018-10-18 23:35:35 +00:00
David Bolvansky 3b6ae57654 [Diagnostics] Check for integer overflow in array size expressions
Summary: Fixes PR27439

Reviewers: rsmith, Rakete1111

Reviewed By: rsmith

Subscribers: Rakete1111, cfe-commits

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

llvm-svn: 344759
2018-10-18 20:49:06 +00:00
Leonard Chan 99bda375a1 [Fixed Point Arithmetic] FixedPointCast
This patch is a part of https://reviews.llvm.org/D48456 in an attempt to
split them up. This contains the code for casting between fixed point types
and other fixed point types.

The method for converting between fixed point types is based off the convert()
method in APFixedPoint.

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

llvm-svn: 344530
2018-10-15 16:07:02 +00:00
Eric Liu b87c6eba2e [CodeComplete] Make sure keyword 'template' is added even when code pattern is disabled.
Reviewers: sammccall, hokein

Subscribers: arphaman, cfe-commits

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

llvm-svn: 344509
2018-10-15 12:37:23 +00:00
Aaron Ballman 20ea72476c Improve -Wshadow warnings with enumerators.
Addresses PR24718 by checking for enumerators that shadow other enumerators. Catches issues like:

enum E1{e1};
void f(void) {
  enum E2{e1};
}

llvm-svn: 344259
2018-10-11 16:40:18 +00:00
Patrick Lyster 3fe9e396f4 Add support for 'dynamic_allocators' clause on 'requires' directive. Differential Revision: https://reviews.llvm.org/D53079
llvm-svn: 344249
2018-10-11 14:41:10 +00:00
Andrew Savonichev 16f1699dda [Sema][OpenCL] Improve diagnostics for not viable overloadable function candidates
Summary:
Allowed extension name (that ought to be disabled) printing in the note message.

This diagnostic was proposed here: https://reviews.llvm.org/D51341

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia

Subscribers: cfe-commits, asavonic, bader

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

llvm-svn: 344246
2018-10-11 13:35:34 +00:00
Erik Pilkington d1a184fc6a [Sema] Fix a multiple definition bug with friends and templates
The problem was that MergeFunctionDecl sometimes needs the injected template
arguments of a FunctionTemplateDecl, but is called before adding the new
template to the redecl chain. This leads to multiple common pointers in the same
redecl chain, each with their own identical instantiation. Fix this by merging
the the common state before inserting the new template into the redecl chain.

rdar://44810129

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

llvm-svn: 344157
2018-10-10 17:17:51 +00:00
Anastasia Stulova 5325f83470 [OpenCL] Fixed address space cast in C style cast of C++ parsing
C style cast in OpenCL C++ was ignoring the address space
conversions from OpenCL C and as a result accepting incorrect
code to compile. This commit adds special function for checking 
correctness of address spaces that is shared between C and C++
casts.
 

llvm-svn: 344148
2018-10-10 16:05:22 +00:00
Louis Dionne e6e817534a [clang] Properly apply attributes on explicit instantiations of static data members
Summary: https://llvm.org/PR39118

Reviewers: aaron.ballman, rnk

Subscribers: dexonsmith, cfe-commits

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

llvm-svn: 344146
2018-10-10 15:32:29 +00:00
Jonas Devlieghere fc51490baf Lift VFS from clang to llvm (NFC)
This patch moves the virtual file system form clang to llvm so it can be
used by more projects.

Concretely the patch:
 - Moves VirtualFileSystem.{h|cpp} from clang/Basic to llvm/Support.
 - Moves the corresponding unit test from clang to llvm.
 - Moves the vfs namespace from clang::vfs to llvm::vfs.
 - Formats the lines affected by this change, mostly this is the result of
   the added llvm namespace.

RFC on the mailing list:
http://lists.llvm.org/pipermail/llvm-dev/2018-October/126657.html

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

llvm-svn: 344140
2018-10-10 13:27:25 +00:00
Sam McCall aeb4b3e632 [CodeComplete] Fix crash when completing params function declarations.
Summary:
In a decl like `int AA(BB cc)` where BB isn't defined, we end up trying to
parse `BB cc` as an expression (vexing parse) and end up triggering the
parser's "recovery-in-function" completion with no actual function
scope.

This patch avoids the assumption that such a scope exists in this context.

Reviewers: kadircet

Subscribers: cfe-commits

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

llvm-svn: 344133
2018-10-10 10:51:48 +00:00
Richard Smith e54d9525ad PR39231: fix null dereference when diagnosing deduction failure due to
conflicting values for a non-type pack.

llvm-svn: 344070
2018-10-09 18:49:22 +00:00
Yaxun Liu a461174cfd [CUDA][HIP] Fix ShouldDeleteSpecialMember for inherited constructors
ShouldDeleteSpecialMember is called upon inherited constructors.
It calls inferCUDATargetForImplicitSpecialMember.

Normally the special member enum passed to ShouldDeleteSpecialMember
matches the constructor. However this is not true when inherited
constructor is passed, where DefaultConstructor is passed to treat
the inherited constructor as DefaultConstructor. However
inferCUDATargetForImplicitSpecialMember expects the special
member enum argument to match the constructor, which results
in assertion when this expection is not satisfied.

This patch checks whether the constructor is inherited. If true it will
get the real special member enum for the constructor and pass it
to inferCUDATargetForImplicitSpecialMember.

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

llvm-svn: 344057
2018-10-09 15:53:14 +00:00
Brian Gesiak 0b56830011 [coro]Pass rvalue reference for named local variable to return_value
Summary:
Addressing https://bugs.llvm.org/show_bug.cgi?id=37265.

Implements [class.copy]/33 of coroutines TS.

When the criteria for elision of a copy/move operation are met, but not
for an exception-declaration, and the object to be copied is designated by an
lvalue, or when the expression in a return or co_return statement is a
(possibly parenthesized) id-expression that names an object with automatic
storage duration declared in the body or parameter-declaration-clause of the
innermost enclosing function or lambda-expression, overload resolution to select
the constructor for the copy or the return_value overload to call is first
performed as if the object were designated by an rvalue.

Patch by Tanoy Sinha!

Reviewers: modocache, GorNishanov

Reviewed By: modocache, GorNishanov

Subscribers: cfe-commits

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

llvm-svn: 343949
2018-10-08 03:08:39 +00:00
James Y Knight 49bf370a8b Emit CK_NoOp casts in C mode, not just C++.
Previously, it had been using CK_BitCast even for casts that only
change const/restrict/volatile. Now it will use CK_Noop where
appropriate.

This is an alternate solution to r336746.

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

llvm-svn: 343892
2018-10-05 21:53:51 +00:00
Simon Pilgrim 3c19674fac Fix llvm-clang-x86_64-expensive-checks-win build by setting bigobj flag.
llvm-svn: 343846
2018-10-05 12:33:57 +00:00
Mandeep Singh Grang ecc82ef0c2 [COFF, ARM64] Add __getReg intrinsic
Reviewers: rnk, mstorsjo, compnerd, TomTan, haripul, javed.absar, efriedma

Reviewed By: efriedma

Subscribers: peter.smith, efriedma, kristof.beyls, chrib, cfe-commits

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

llvm-svn: 343824
2018-10-04 22:32:42 +00:00
Louis Dionne d269579a97 [clang] Add the exclude_from_explicit_instantiation attribute
Summary:
This attribute allows excluding a member of a class template from being part
of an explicit template instantiation of that class template. This also makes
sure that code using such a member will not take for granted that an external
instantiation exists in another translation unit. The attribute was discussed
on cfe-dev at [1] and is primarily motivated by the removal of always_inline
in libc++ to control what's part of the ABI (see links in [1]).

[1]: http://lists.llvm.org/pipermail/cfe-dev/2018-August/059024.html

rdar://problem/43428125

Reviewers: rsmith

Subscribers: dexonsmith, cfe-commits

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

llvm-svn: 343790
2018-10-04 15:49:42 +00:00
Nick Desaulniers 150ca5309e [SEMA] split ExtWarn dupl-decl-spec's into Extension and ExtWarn
Summary:
For types deduced from typedef's and typeof's, don't warn for duplicate
declaration specifiers in C90 unless -pedantic.

Create a third diagnostic type for duplicate declaration specifiers.
Previously, we had an ExtWarn and a Warning. This change adds a third,
Extension, which only warns when -pedantic is set, staying silent
otherwise.

Fixes PR32985.

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: srhines, cfe-commits

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

llvm-svn: 343740
2018-10-03 23:09:29 +00:00
Patrick Lyster 6bdf63bd32 [OPENMP] Add reverse_offload clause to requires directive
llvm-svn: 343711
2018-10-03 20:07:58 +00:00
Yaxun Liu 9767089d00 [HIP] Support early finalization of device code for -fno-gpu-rdc
This patch renames -f{no-}cuda-rdc to -f{no-}gpu-rdc and keeps the original
options as aliases. When -fgpu-rdc is off,
clang will assume the device code in each translation unit does not call
external functions except those in the device library, therefore it is possible
to compile the device code in each translation unit to self-contained kernels
and embed them in the host object, so that the host object behaves like
usual host object which can be linked by lld.

The benefits of this feature is: 1. allow users to create static libraries which
can be linked by host linker; 2. amortized device code linking time.

This patch modifies HIP action builder to insert actions for linking device
code and generating HIP fatbin, and pass HIP fatbin to host backend action.
It extracts code for constructing command for generating HIP fatbin as
a function so that it can be reused by early finalization. It also modifies
codegen of HIP host constructor functions to embed the device fatbin
when it is available.

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

llvm-svn: 343611
2018-10-02 17:48:54 +00:00
Eric Liu b91e08197c [CodeComplete] Re-fix accessibilty of protected members from base class.
Summary:
The initial fix (r337453) had bug and was partially reverted (r338255).
This simplies the original fix by explicitly passing the naming class to the
completion consumer.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

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

llvm-svn: 343575
2018-10-02 10:29:00 +00:00
Kadir Cetinkaya ae45d0a4fd [clang] Implement Override Suggestions in Sema.
Summary:
In clangd we had a new type of completion suggestions for cpp
class/struct/unions that will show override signatures for virtual methods in
base classes. This patch implements it in sema because it is hard to deduce more
info about completion token outside of Sema and handle itchy cases.

See the patch D50898 for more info on the functionality.

In addition to above patch this one also converts the suggestion into a
CK_Pattern with whole insertion text as the name of the suggestion and factors
out CodeCompletionString generation for declerations so that it can be re-used
by others.

Reviewers: ioeric, ilya-biryukov

Reviewed By: ioeric

Subscribers: cfe-commits

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

llvm-svn: 343568
2018-10-02 09:42:31 +00:00
David Bolvansky cf7d2256d6 Added warning for unary minus used with unsigned type
Summary:
Inspired by MSVC, which found some occurrences of this expression on our code base.

Fixes PR38950

Reviewers: rsmith, craig.topper, spatel, RKSimon, aaron.ballman, thakis

Reviewed By: rsmith

Subscribers: joerg, Quuxplusone, lebedev.ri, craig.topper, RKSimon, cfe-commits

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

llvm-svn: 343560
2018-10-02 06:02:30 +00:00
Akira Hatanaka 8e57b07f66 Distinguish `__block` variables that are captured by escaping blocks
from those that aren't.

This patch changes the way __block variables that aren't captured by
escaping blocks are handled:

- Since non-escaping blocks on the stack never get copied to the heap
  (see https://reviews.llvm.org/D49303), Sema shouldn't error out when
  the type of a non-escaping __block variable doesn't have an accessible
  copy constructor.

- IRGen doesn't have to use the specialized byref structure (see
  https://clang.llvm.org/docs/Block-ABI-Apple.html#id8) for a
  non-escaping __block variable anymore. Instead IRGen can emit the
  variable as a normal variable and copy the reference to the block
  literal. Byref copy/dispose helpers aren't needed either.

This reapplies r343518 after fixing a use-after-free bug in function
Sema::ActOnBlockStmtExpr where the BlockScopeInfo was dereferenced after
it was popped and deleted.

rdar://problem/39352313

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

llvm-svn: 343542
2018-10-01 21:51:28 +00:00
Akira Hatanaka 3197484701 Revert r343518.
Bots are still failing.

http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/24420
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/12958

llvm-svn: 343531
2018-10-01 20:29:34 +00:00
Akira Hatanaka 2bf09ccfd5 Distinguish `__block` variables that are captured by escaping blocks
from those that aren't.

This patch changes the way __block variables that aren't captured by
escaping blocks are handled:

- Since non-escaping blocks on the stack never get copied to the heap
  (see https://reviews.llvm.org/D49303), Sema shouldn't error out when
  the type of a non-escaping __block variable doesn't have an accessible
  copy constructor.

- IRGen doesn't have to use the specialized byref structure (see
  https://clang.llvm.org/docs/Block-ABI-Apple.html#id8) for a
  non-escaping __block variable anymore. Instead IRGen can emit the
  variable as a normal variable and copy the reference to the block
  literal. Byref copy/dispose helpers aren't needed either.

This reapplies r341754, which was reverted in r341757 because it broke a
couple of bots. r341754 was calling markEscapingByrefs after the call to
PopFunctionScopeInfo, which caused the popped function scope to be
cleared out when the following code was compiled, for example:

$ cat test.m
struct A {
  id data[10];
};

void foo() {
  __block A v;
  ^{ (void)v; };
}

This commit calls markEscapingByrefs before calling PopFunctionScopeInfo
to prevent that from happening.

rdar://problem/39352313

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

llvm-svn: 343518
2018-10-01 18:50:14 +00:00
Patrick Lyster 4a370b9f63 Add support for unified_shared_memory clause on requires directive
llvm-svn: 343472
2018-10-01 13:47:43 +00:00
Sam McCall 3e4f5eb33c [CodeComplete] #include completion treats -I as non-system (require header-like extension).
llvm-svn: 343457
2018-10-01 11:56:42 +00:00
Fangrui Song 1d38c13f6e Use the container form llvm::sort(C, ...)
There are a few leftovers of rC343147 that are not (\w+)\.begin but in
the form of ([-[:alnum:]>.]+)\.begin or spanning two lines. Change them
to use the container form in this commit. The 12 occurrences have been
inspected manually for safety.

llvm-svn: 343425
2018-09-30 21:41:11 +00:00
Alexey Bataev bc52967835 [OPENMP]Fix PR39084: Check datasharing attributes of reduction variables only.
According to OpenMP, the reduction item must be shared in parent region.
But the item can be an array section or array subscript. In this case,
we should not check for the datasharing of the base declaration.

llvm-svn: 343356
2018-09-28 19:33:14 +00:00
Richard Smith 8baa50013c [cxx2a] P0614R1: Support init-statements in range-based for loops.
We don't yet support this for the case where a range-based for loop is
implicitly rewritten to an ObjC for..in statement.

llvm-svn: 343350
2018-09-28 18:44:09 +00:00
Richard Smith cff420120f Handle dependent class template names in class template argument
deduction for new-expressions.

llvm-svn: 343293
2018-09-28 03:18:53 +00:00
Richard Smith 9b2c5e7c44 [cxx2a] P0641R2: (Some) type mismatches on defaulted functions only
render the function deleted instead of rendering the program ill-formed.

This change also adds an enabled-by-default warning for the case where
an explicitly-defaulted special member function of a non-template class
is implicitly deleted by the type checking rules. (This fires either due
to this language change or due to pre-C++20 reasons for the member being
implicitly deleted). I've tested this on a large codebase and found only
bugs (where the program means something that's clearly different from
what the programmer intended), so this is enabled by default, but we
should revisit this if there are problems with this being enabled by
default.

llvm-svn: 343285
2018-09-28 01:16:43 +00:00
Richard Smith 864949bda1 [cxx2a] P0624R2: Lambdas with no capture-default are
default-constructible and assignable.

llvm-svn: 343279
2018-09-27 22:47:04 +00:00
Patrick Lyster e653b63d83 Test commit. NFC
llvm-svn: 343258
2018-09-27 19:30:32 +00:00
Martin Storsjo 0b339e4d80 [Sema] Handle __va_start for Windows/ARM64 in the same way as for ARM
This fixes PR39090.

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

llvm-svn: 343184
2018-09-27 08:24:15 +00:00
Fangrui Song 55fab260ca llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)
Summary: The convenience wrapper in STLExtras is available since rL342102.

Reviewers: rsmith, #clang, dblaikie

Reviewed By: rsmith, #clang

Subscribers: mgrang, arphaman, kadircet, cfe-commits

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

llvm-svn: 343147
2018-09-26 22:16:28 +00:00
Richard Smith 79c88c3105 P1008R1 Classes with user-declared constructors are never aggregates in
C++20.

llvm-svn: 343131
2018-09-26 19:00:16 +00:00
Richard Smith 12938cf899 P0859R0: List-initialization is potentially-constant-evaluated and
triggers instantiation of constexpr functions.

We mostly implemented this since Clang 6, but missed the template
instantiation case.

We do not implement the '&cast-expression' special case. It appears to
be a mistake / oversight. I've mailed CWG to see if we can remove it.

llvm-svn: 343064
2018-09-26 04:36:55 +00:00
Kelvin Li 1408f91a25 [OPENMP] Add support for OMP5 requires directive + unified_address clause
Add support for OMP5.0 requires directive and unified_address clause.
Patches to follow will include support for additional clauses.

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

llvm-svn: 343063
2018-09-26 04:28:39 +00:00
Erik Pilkington b794aec290 [Sema] Use a more civilized hash map to implement -Wduplicate-enum.
DenseMap<long, SOMETHING> used LONG_MAX as a tombstone, so it asserts
when you try to insert it!

rdar://44774672

llvm-svn: 343042
2018-09-25 22:53:06 +00:00
Richard Smith 5c9b3b7576 P0969R0: allow structured binding of accessible members, not only public members.
llvm-svn: 343036
2018-09-25 22:12:44 +00:00
Sven van Haastregt 0ea28c0e47 [OpenCL] Allow zero assignment and comparisons between queue_t type variables
This change allows for zero assignment and comparison of queue_t
type variables, and extends null_queue.cl to test this.

Patch by Alistair Davies.

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

llvm-svn: 342968
2018-09-25 12:59:34 +00:00
Richard Smith 236ffdeeb2 P0962R1: only use the member form of 'begin' and 'end' in a range-based
for loop if both members exist.

This resolves a DR whereby an errant 'begin' or 'end' member in a base
class could result in a derived class not being usable as a range with
non-member 'begin' and 'end'.

llvm-svn: 342925
2018-09-24 23:17:44 +00:00
Anastasia Stulova ae2e86fb2f Revert "We allow implicit function declarations as an extension in all C dialects. Remove OpenCL special case."
Discussed on cfe-commits (Week-of-Mon-20180820), this change leads to
the generation of invalid IR for OpenCL without giving an error.
Therefore, the conclusion was to revert.

llvm-svn: 342885
2018-09-24 14:21:56 +00:00
Sven van Haastregt 7b39a085d9 Fix Wundef NDEBUG warning; NFC
Check for definedness of the NDEBUG macro rather than its value,
to be consistent with other uses.

llvm-svn: 342876
2018-09-24 12:12:03 +00:00
Richard Trieu 8d3fa39a0d Update smart pointer detection for thread safety analysis.
Objects are determined to be smart pointers if they have both a star and arrow
operator.  Some implementations of smart pointers have these overloaded
operators in a base class, while the check only searched the derived class.
This fix will also look for the operators in the base class.

llvm-svn: 342794
2018-09-22 01:50:52 +00:00
Artem Belevich 78929efb4d [CUDA] Ignore uncallable functions when we check for usual deallocators.
Previously clang considered function variants from both sides of
compilation and that resulted in picking up wrong deallocation function.

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

llvm-svn: 342749
2018-09-21 17:29:33 +00:00
Alexey Bataev f898d1de4a [OPENMP] Disable emission of the class with vptr if they are not used in
target constructs.

Prevent compilation of the classes with the virtual tables when
compiling for the device.

llvm-svn: 342741
2018-09-21 14:55:26 +00:00
Bruno Ricci 366ba73018 [AST] Various optimizations + refactoring in DeclarationName(Table)
Introduce the following optimizations in DeclarationName(Table):

 1. Store common kinds inline in DeclarationName instead of
    DeclarationNameExtra. Currently the kind of C++ constructor, destructor,
    conversion function and overloaded operator names is stored in
    DeclarationNameExtra. Instead store it inline in DeclarationName.
    To do this align IdentifierInfo, CXXSpecialName, DeclarationNameExtra
    and CXXOperatorIdName to 8 bytes so that we can use the lower 3 bits of
    DeclarationName::Ptr. This is already the case on 64 bits archs anyway.
    This also allow us to remove DeclarationNameExtra from CXXSpecialName
    and CXXOperatorIdName, which shave off a pointer from CXXSpecialName. 

 2. Synchronize the enumerations DeclarationName::NameKind,
    DeclarationName::StoredNameKind and Selector::IdentifierInfoFlag.
    This makes DeclarationName::getNameKind much more efficient since we can
    replace the switch table by a single comparison and an addition.

 3. Put the overloaded operator names inline in DeclarationNameTable to remove
    an indirection. This increase the size of DeclarationNameTable a little
    bit but this is not important since it is only used in ASTContext, and
    never copied nor moved from. This also get rid of the last dynamic
    allocation in DeclarationNameTable.

Altogether these optimizations cut the run time of parsing all of Boost by
about 0.8%. While we are at it, do the following NFC modifications:

 1. Put the internal classes CXXSpecialName, CXXDeductionGuideNameExtra,
    CXXOperatorIdName, CXXLiteralOperatorIdName and DeclarationNameExtra
    in a namespace detail since these classes are only meant to be used by
    DeclarationName and DeclarationNameTable. Make this more explicit by making
    the members of these classes private and friending DeclarationName(Table).

 2. Make DeclarationName::getFETokenInfo a non-template since every users are
    using it to get a void *. It was supposed to be used with a type to avoid
    a subsequent static_cast.

 3. Change the internal functions DeclarationName::getAs* to castAs* since when
    we use them we already know the correct kind. This has no external impact
    since all of these are private.

Reviewed By: erichkeane, rjmccall

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

llvm-svn: 342729
2018-09-21 12:53:22 +00:00
Erik Pilkington f452337787 [Sema] Retain __restrict qualifiers when substituting a reference type.
Fixes rdar://43760099

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

llvm-svn: 342672
2018-09-20 18:12:24 +00:00
Alexey Bataev e82445f5a9 [OPENMP] Add support for mapping memory pointed by member pointer.
Added support for map(s, s.ptr[0:1]) kind of mapping.

llvm-svn: 342648
2018-09-20 13:54:02 +00:00
Sven van Haastregt 1076cc2ffa [OpenCL] Diagnose redundant address space conversion
Add a warning if a parameter with a named address space is passed
to a to_addr builtin.

For example:

  int i;
  to_private(&i); // generate warning as conversion from private to private is redundant.

Patch by Alistair Davies.

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

llvm-svn: 342638
2018-09-20 10:07:27 +00:00
QingShan Zhang accb65b994 [PowerPC] [Clang] Add vector int128 pack/unpack builtins
unsigned long long builtin_unpack_vector_int128 (vector int128_t, int);
vector int128_t builtin_pack_vector_int128 (unsigned long long, unsigned long long);

Builtins should behave the same way as in GCC.

Patch By: wuzish (Zixuan Wu)
Differential Revision: https://reviews.llvm.org/D52074

llvm-svn: 342614
2018-09-20 05:04:57 +00:00
Aaron Puchert 7ba1ab71ec Thread Safety Analysis: warnings for attributes without arguments
Summary:
When thread safety annotations are used without capability arguments,
they are assumed to apply to `this` instead. So we warn when either
`this` doesn't exist, or the class is not a capability type.

This is based on earlier work by Josh Gao that was committed in r310403,
but reverted in r310698 because it didn't properly work in template
classes. See also D36237.

The solution is not to go via the QualType of `this`, which is then a
template type, hence the attributes are not known because it could be
specialized. Instead we look directly at the class in which we are
contained.

Additionally I grouped two of the warnings together. There are two
issues here: the existence of `this`, which requires us to be a
non-static member function, and the appropriate annotation on the class
we are contained in. So we don't distinguish between not being in a
class and being static, because in both cases we don't have `this`.

Fixes PR38399.

Reviewers: aaron.ballman, delesley, jmgao, rtrieu

Reviewed By: delesley

Subscribers: cfe-commits

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

llvm-svn: 342605
2018-09-20 00:39:27 +00:00
Eric Liu 88de9f6579 [Sema] Do not load macros from preamble when LoadExternal is false.
Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: cfe-commits

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

llvm-svn: 342528
2018-09-19 09:34:55 +00:00
Sam McCall 3d8051abb8 [CodeComplete] Add completions for filenames in #include directives.
Summary:
The dir component ("somedir" in #include <somedir/fo...>) is considered fixed.
We append "foo" to each directory on the include path, and then list its files.

Completions are of the forms:
 #include <somedir/fo^
                   foo.h>
                   fox/

The filter is set to the filename part ("fo"), so fuzzy matching can be
applied to the filename only.

No fancy scoring/priorities are set, and no information is added to
CodeCompleteResult to make smart scoring possible. Could be in future.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

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

llvm-svn: 342449
2018-09-18 08:40:41 +00:00
Andrew Savonichev 83ace12e86 [OpenCL] Allow blocks to capture arrays in OpenCL
Summary: Patch by Egor Churaev

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia

Subscribers: asavonic, bader, cfe-commits

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

llvm-svn: 342370
2018-09-17 11:19:42 +00:00
Andrew Savonichev 1a5623489b Merge two attribute diagnostics into one
Summary:
Merged the recently added `err_attribute_argument_negative` diagnostic
with existing `err_attribute_requires_positive_integer` diagnostic:
the former allows only strictly positive integer, while the latter
also allows zero.

Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 342367
2018-09-17 10:39:46 +00:00
Richard Smith ac9f7fb9a1 [modules] Don't bother creating a global module fragment when building a
header module.

llvm-svn: 342307
2018-09-15 01:59:39 +00:00
Richard Smith d6509cf21d [modules] Frontend support for building a header module from a list of
headaer files.

llvm-svn: 342304
2018-09-15 01:21:15 +00:00
Louis Dionne 3c011e1e3c [clang] Make sure attributes on member classes are applied properly
Summary:
Attributes on member classes of class templates and member class templates
of class templates are not currently instantiated. This was discovered by
Richard Smith here:

  http://lists.llvm.org/pipermail/cfe-dev/2018-September/059291.html

This commit makes sure that attributes are instantiated properly. This
commit does not fix the broken behavior for member partial and explicit
specializations of class templates.

PR38913

Reviewers: rsmith

Subscribers: dexonsmith, cfe-commits

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

llvm-svn: 342238
2018-09-14 14:07:16 +00:00
Vedant Kumar 35d303adbf [Sema] Remove location from implicit capture init expr
A lambda's closure is initialized when the lambda is declared. For
implicit captures, the initialization code emitted from EmitLambdaExpr
references source locations *within the lambda body* in the function
containing the lambda. This results in a poor debugging experience: we
step to the line containing the lambda, then into lambda, out again,
over and over, until every capture's field is initialized.

To improve stepping behavior, assign the starting location of the lambda
to expressions which initialize an implicit capture within it.

rdar://39807527

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

llvm-svn: 342194
2018-09-13 23:28:25 +00:00
Alexey Bataev e6aa4694de [OPENMP] Fix PR38903: Crash on instantiation of the non-dependent
declare reduction.

If the declare reduction construct with the non-dependent type is
defined in the template construct, the compiler might crash on the
template instantition. Reworked the whole instantiation scheme for the
declare reduction constructs to fix this problem correctly.

llvm-svn: 342151
2018-09-13 16:54:05 +00:00
Richard Smith 56dd0d2cfd Remove dead code made unnecessary by r342018.
llvm-svn: 342098
2018-09-12 23:37:58 +00:00
Richard Smith 13897ebb00 Track definition merging on the canonical declaration even when local
submodule visibility is disabled.

Attempting to pick a specific declaration to make visible when the
module containing the merged declaration becomes visible is error-prone,
as we don't yet know which declaration we'll choose to be the definition
when we are informed of the merging.

This reinstates r342019, reverted in r342020. The regression previously
observed after this commit was fixed in r342096.

llvm-svn: 342097
2018-09-12 23:37:00 +00:00
Alexey Bataev 43b90b73e6 [OPENMP] Fix PR38902: support ADL for declare reduction constructs.
Added support for argument-dependent lookup when trying to find the
required declare reduction decl.

llvm-svn: 342062
2018-09-12 16:31:59 +00:00
Richard Smith 4034461abd Revert r342019, "Track definition merging on the canonical declaration
even when [...]"

Further testing has revealed that this causes build breaks during
explicit module compilations.

llvm-svn: 342020
2018-09-12 02:28:14 +00:00
Richard Smith e731d9acff Track definition merging on the canonical declaration even when local
submodule visibility is disabled.

Attempting to pick a specific declaration to make visible when the
module containing the merged declaration becomes visible is error-prone,
as we don't yet know which declaration we'll choose to be the definition
when we are informed of the merging.

llvm-svn: 342019
2018-09-12 02:13:48 +00:00
Richard Smith c457766c6d Consistently create a new declaration when merging a pre-existing but
hidden definition with a would-be-parsed redefinition.

This permits a bunch of cleanups. In particular, we no longer need to
take merged definitions into account when checking declaration
visibility, only when checking definition visibility, which makes
certain visibility checks take linear instead of quadratic time.

We could also now remove the UPD_DECL_EXPORTED update record and track
on each declaration whether it was demoted from a definition (as we
already do for variables), but I'm not doing that in this patch to keep
the changes here simpler.

llvm-svn: 342018
2018-09-12 02:13:47 +00:00
Kadir Cetinkaya 84774c3ae3 [CodeCompletion] Enable signature help when initializing class/struct/union members.
Summary:
Factors out member decleration gathering and uses it in parsing to call signature
help. Doesn't support signature help for base class constructors, the code was too
coupled with diagnostic handling, but still can be factored out but just needs
more afford.

Reviewers: sammccall, ilya-biryukov, ioeric

Reviewed By: ilya-biryukov

Subscribers: cfe-commits

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

llvm-svn: 341949
2018-09-11 15:02:18 +00:00
Alexey Bataev 30a7821760 [OPENMP] Simplified checks for declarations in declare target regions.
Sema analysis should not mark functions as an implicit declare target,
it may break codegen. Simplified semantic analysis and removed extra
code for implicit declare target functions.

llvm-svn: 341939
2018-09-11 13:59:10 +00:00
Erik Pilkington 4257857bf8 [Sema][ObjC] Infer availability of +new from availability of -init.
When defined in NSObject, +new will call -init. If -init has been marked
unavailable, diagnose uses of +new.

rdar://18335828

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

llvm-svn: 341874
2018-09-10 22:20:09 +00:00
JF Bastien e77b48b078 Implement -Watomic-implicit-seq-cst
Summary:
_Atomic and __sync_* operations are implicitly sequentially-consistent. Some
codebases want to force explicit usage of memory order instead. This warning
allows them to know where implicit sequentially-consistent memory order is used.
The warning isn't on by default because _Atomic was purposefully designed to
have seq_cst as the default: the idea was that it's the right thing to use most
of the time. This warning allows developers who disagree to enforce explicit
usage instead.

A follow-up patch will take care of C++'s std::atomic. It'll be different enough
from this patch that I think it should be separate: for C++ the atomic
operations all have a memory order parameter (or two), but it's defaulted. I
believe this warning should trigger when the default is used, but not when
seq_cst is used explicitly (or implicitly as the failure order for cmpxchg).

<rdar://problem/28172966>

Reviewers: rjmccall

Subscribers: dexonsmith, cfe-commits

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

llvm-svn: 341860
2018-09-10 20:42:56 +00:00
Richard Smith 8eeb16f5d1 Enhance -Wc++14-compat for class template argument deduction to list the
deduced type (if known).

llvm-svn: 341858
2018-09-10 20:31:03 +00:00
Erich Keane 659c871a1b Prevent cpu-specific/cpu-dispatch from giong on a lambda.
It is non-sensical to use cpu-specific/cpu-dispatch multiversioning
on a lambda, so prevent it when trying to add the attribute.

llvm-svn: 341833
2018-09-10 14:31:56 +00:00
Kadir Cetinkaya a32d253f10 [clang] Make sure codecompletion is called for calls even when inside a token.
Summary:
Currently CodeCompleteCall only gets called after a comma or parantheses. This
patch makes sure it is called even at the cases like:
```foo(1^);```

Reviewers: ilya-biryukov, ioeric, hokein

Reviewed By: ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

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

llvm-svn: 341824
2018-09-10 13:46:28 +00:00
Richard Smith 4576a77b80 PR33222: Require the declared return type not the actual return type to
match when checking for redeclaration of a function template.

This properly handles differences in deduced return types, particularly
when performing redeclaration checks for a friend function template.

llvm-svn: 341778
2018-09-10 06:35:32 +00:00
Richard Smith 4ced5d751b Part of PR33222: defer enforcing return type mismatch for dependent
friend function declarations of class templates.

llvm-svn: 341775
2018-09-10 05:32:13 +00:00
Kelvin Li bc38e63718 [OpenMP] Add support for nested 'declare target' directives
Add the capability to nest multiple declare target directives 
- including header files within a declare target region.

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

Patch by Patrick Lyster

llvm-svn: 341766
2018-09-10 02:07:09 +00:00
Fangrui Song aadc93c887 [Sema] Make typo correction slightly more efficient
edit_distance returns UpperBound+1 if the distance will exceed UpperBound. We can subtract 1 from UpperBound and change >= to > in the if condition. The threshold does not change but edit_distance will have more opportunity to bail out earlier.

llvm-svn: 341763
2018-09-09 17:20:03 +00:00
Akira Hatanaka 9bd2452708 Revert r341754.
The commit broke a couple of bots:

http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/12347
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/7310

llvm-svn: 341757
2018-09-09 05:22:49 +00:00
Akira Hatanaka 2e00b98027 Distinguish `__block` variables that are captured by escaping blocks
from those that aren't.

This patch changes the way __block variables that aren't captured by
escaping blocks are handled:

- Since non-escaping blocks on the stack never get copied to the heap
  (see https://reviews.llvm.org/D49303), Sema shouldn't error out when
  the type of a non-escaping __block variable doesn't have an accessible
  copy constructor.

- IRGen doesn't have to use the specialized byref structure (see
  https://clang.llvm.org/docs/Block-ABI-Apple.html#id8) for a
  non-escaping __block variable anymore. Instead IRGen can emit the
  variable as a normal variable and copy the reference to the block
  literal. Byref copy/dispose helpers aren't needed either.

rdar://problem/39352313

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

llvm-svn: 341754
2018-09-08 20:03:00 +00:00
Ilya Biryukov 832c4afe00 [CodeComplete] Clearly distinguish signature help and code completion.
Summary:
Code completion in clang is actually a mix of two features:
- Code completion is a familiar feature. Results are exposed via the
  CodeCompleteConsumer::ProcessCodeCompleteResults callback.
- Signature help figures out if the current expression is an argument of
  some function call and shows corresponding signatures if so.
  Results are exposed via CodeCompleteConsumer::ProcessOverloadCandidates.

This patch refactors the implementation to untangle those two from each
other and makes some naming tweaks to avoid confusion when reading the
code.

The refactoring is required for signature help fixes, see D51038.

The only intended behavior change is the order of callbacks.
ProcessOverloadCandidates is now called before ProcessCodeCompleteResults.

Reviewers: sammccall, kadircet

Reviewed By: sammccall

Subscribers: cfe-commits

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

llvm-svn: 341660
2018-09-07 14:04:39 +00:00
Akira Hatanaka 2ccb31977c [Sema] Check that the destructor for each element of class type is
accessible from the context where aggregate initialization occurs.

rdar://problem/38168772

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

llvm-svn: 341629
2018-09-07 02:38:01 +00:00
Stephen Kelly 96160587f9 Remove deprecated API
Reviewers: teemperor!

Subscribers: cfe-commits

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

llvm-svn: 341573
2018-09-06 18:26:30 +00:00
Alexey Bataev d2c1dd5902 [OPENMP] Fix PR38823: Do not emit vtable if it is not used in target
context.

If the explicit template instantiation definition defined outside of the
target context, its vtable should not be marked as used. This is true
for other situations where the compiler want to emit vtables
unconditionally.

llvm-svn: 341570
2018-09-06 17:56:28 +00:00
Erik Pilkington f85e391063 [Sema] Clean up some __builtin_*_chk diagnostics
Namely, print the likely macro name when it's used, and include the actual
computed sizes in the diagnostic message, which are sometimes not obvious.

rdar://43909200

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

llvm-svn: 341566
2018-09-06 17:19:33 +00:00
Simon Pilgrim 58310ec11f Remove unnecessary semicolon to silence -Wpedantic warning. NFCI.
llvm-svn: 341556
2018-09-06 15:16:17 +00:00
Andrew Savonichev 05a15afe6f [OpenCL] Relax diagnostics on OpenCL access qualifiers
Summary:
Emit warning for multiple access qualifiers if they do not conflict.

Patch by Alexey Bader

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia

Subscribers: asavonic, bader, cfe-commits

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

llvm-svn: 341553
2018-09-06 15:10:26 +00:00
Andrew Savonichev d353e6d748 [OpenCL] Disallow negative attribute arguments
Summary:
Negative arguments in kernel attributes are silently bitcast'ed to
unsigned, for example:

    __attribute__((reqd_work_group_size(1, -1, 1)))
    __kernel void k() {}

is a complete equivalent of:

    __attribute__((reqd_work_group_size(1, 4294967294, 1)))
    __kernel void k() {}

This is likely an error, so the patch forbids negative arguments in
several OpenCL attributes. Users who really want 4294967294 can still
use it as an unsigned representation.

Reviewers: Anastasia, yaxunl, bader

Reviewed By: Anastasia, yaxunl, bader

Subscribers: bader, cfe-commits

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

llvm-svn: 341539
2018-09-06 11:54:09 +00:00
Richard Smith 5159bbad8b PR38627: Fix handling of exception specification adjustment for
destructors.

We previously tried to patch up the exception specification after
completing the class, which went wrong when the exception specification
was needed within the class body (in particular, by a friend
redeclaration of the destructor in a nested class). We now mark the
destructor as having a not-yet-computed exception specification
immediately after creating it.

This requires delaying various checks against the exception
specification (where we'd previously have just got the wrong exception
specification, and now find we have an exception specification that we
can't compute yet) when those checks fire while the class is being
defined.

This also exposed an issue that we were missing a CodeSynthesisContext
for computation of exception specifications (otherwise we'd fail to make
the module containing the definition of the class visible when computing
its members' exception specs). Adding that incidentally also gives us a
diagnostic quality improvement.

This has also exposed an pre-existing problem: making the exception
specification evaluation context a non-SFINAE context (as it should be)
results in a bootstrap failure; PR38850 filed for this.

llvm-svn: 341499
2018-09-05 22:30:37 +00:00
John McCall 7fa8af0abe Forbid address spaces on compound literals in local scope.
Patch by Bevin Hansson!

llvm-svn: 341491
2018-09-05 19:22:40 +00:00
Erik Pilkington 3e4e3b17c1 [Sema] Don't warn about omitting unavailable enum constants in a switch
rdar://42717026

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

llvm-svn: 341490
2018-09-05 19:13:27 +00:00
John McCall 52a503d4f3 Add -Wobjc-property-assign-on-object-type.
This is a warning about using 'assign' instead of 'unsafe_unretained'
in Objective-C property declarations.  It's off by default because there
isn't consensus in the Objective-C steering group that this is the right
thing to do, but we're nonetheless okay with adding it because there's a
substantial pool of Objective-C programmers who will appreciate the warning.

Patch by Alfred Zien!

llvm-svn: 341489
2018-09-05 19:02:00 +00:00
Eric Liu d485df17d5 [Sema] Store MacroInfo in CodeCompletionResult for macro results.
Summary:
This provides information about the macro definition. For example, it
can be used to compute macro USRs.

Reviewers: sammccall

Subscribers: cfe-commits

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

llvm-svn: 341476
2018-09-05 14:59:17 +00:00
Simon Pilgrim 275288d696 Fix -Wdocumentation warning. NFCI.
llvm-svn: 341460
2018-09-05 10:44:03 +00:00
Alexey Sotkin 73ae7cb4f1 [OpenCL] Traverse vector types for ocl extensions support
Summary:
Given the following kernel:
__kernel void foo() {
  double d;
  double4 dd;
}

and cl_khr_fp64 is disabled, the compilation would fail due to
the presence of 'double d', but when removed, it passes.

The expectation is that extended vector types of unsupported types
will also be unsupported.

The patch adds the check for this scenario.

Patch by: Ofir Cohen

Reviewers: bader, Anastasia, AlexeySotkin, yaxunl

Reviewed By: Anastasia

Subscribers: cfe-commits

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

llvm-svn: 341309
2018-09-03 11:43:22 +00:00
Craig Topper 2aa8efc820 [X86] Add kshift intrinsics to match gcc and icc.
This adds the following intrinsics:
_kshiftli_mask8
_kshiftli_mask16
_kshiftli_mask32
_kshiftli_mask64
_kshiftri_mask8
_kshiftri_mask16
_kshiftri_mask32
_kshiftri_mask64

llvm-svn: 341234
2018-08-31 18:22:52 +00:00
Richard Smith 218538ebe9 Add missing -Wc++11-compat / -Wc++14-compat warnings for:
* generic lambdas
 * return type deduction
 * class template argument deduction

llvm-svn: 341098
2018-08-30 19:16:35 +00:00
Jan Korous ba3334a25f [Sema][NFC] Trivial cleanup in ActOnCallExpr
Use logical or operator instead of a bool variable and if/else.

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

llvm-svn: 341074
2018-08-30 14:46:48 +00:00
Ilya Biryukov 2fab235316 [CodeComplete] Report location of opening parens for signature help
Summary: Used in clangd.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ioeric, kadircet, cfe-commits

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

llvm-svn: 341063
2018-08-30 13:08:03 +00:00
Leonard Chan fdadd998ee [Sema/Attribute] Make types declared with address_space an AttributedType
Currently an address_space is stored in a qualifier. This makes any type
declared with an address_space attribute in the form
`__attribute__((address_space(1))) int 1;` be wrapped in an AttributedType.

This is for a later patch where if `address_space` is declared in a macro,
any diagnostics that would normally print the address space will instead dump
the macro name. This will require saving any macro information in the
AttributedType.

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

llvm-svn: 340765
2018-08-27 17:57:29 +00:00
Erik Pilkington 63e7ab18e5 Address Aaron Ballman's post-commit review comments from r340306, NFC
llvm-svn: 340311
2018-08-21 17:50:10 +00:00
Erik Pilkington 5a559e64a9 Add a new flag and attributes to control static destructor registration
This commit adds the flag -fno-c++-static-destructors and the attributes
[[clang::no_destroy]] and [[clang::always_destroy]]. no_destroy specifies that a
specific static or thread duration variable shouldn't have it's destructor
registered, and is the default in -fno-c++-static-destructors mode.
always_destroy is the opposite, and is the default in -fc++-static-destructors
mode.

A variable whose destructor is disabled (either because of
-fno-c++-static-destructors or [[clang::no_destroy]]) doesn't count as a use of
the destructor, so we don't do any access checking or mark it referenced. We
also don't emit -Wexit-time-destructors for these variables.

rdar://21734598

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

llvm-svn: 340306
2018-08-21 17:24:06 +00:00
Louis Dionne 751381db5a [clang][NFC] Fix typo in the name of a note
Summary:
r306722 introduced a new note called note_silence_unligned_allocation_unavailable
where I believe what was meant is note_silence_aligned_allocation_unavailable.

Reviewers: ahatanak

Subscribers: dexonsmith, cfe-commits

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

llvm-svn: 340288
2018-08-21 15:54:24 +00:00
Mikael Holmen 0b739fd837 Removed unused variable [NFC]
The compiler warned:
../tools/clang/lib/Sema/SemaType.cpp:6788:31: error: unused variable 'AT' [-Werror,-Wunused-variable]
    if (const AttributedType *AT = S.getCallingConvAttributedType(type)) {
                              ^
1 error generated.

llvm-svn: 340251
2018-08-21 07:22:45 +00:00
Richard Smith e43e2b3667 Model type attributes as regular Attrs.
Specifically, AttributedType now tracks a regular attr::Kind rather than
having its own parallel Kind enumeration, and AttributedTypeLoc now
holds an Attr* instead of holding an ad-hoc collection of Attr fields.

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

This reinstates r339623, reverted in r339638, with a fix to not fail
template instantiation if we instantiate a QualType with no associated
type source information and we encounter an AttributedType.

llvm-svn: 340215
2018-08-20 21:47:29 +00:00
Alex Lorenz b111da14ad [ObjC] Error out when using forward-declared protocol in a @protocol
expression

Clang emits invalid protocol metadata when a @protocol expression is used with a
forward-declared protocol. The protocol metadata is missing protocol conformance
list of the protocol since we don't have access to the definition of it in the
compiled translation unit. The linker then might end up picking the invalid
metadata when linking which will lead to incorrect runtime protocol conformance
checks.

This commit makes sure that Clang fails to compile code that uses a @protocol
expression with a forward-declared protocol. This ensures that Clang does not
emit invalid protocol metadata. I added an extra assert in CodeGen to ensure
that this kind of issue won't happen in other places.

rdar://32787811

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

llvm-svn: 340102
2018-08-17 22:18:08 +00:00
Reid Kleckner 4c33d197fa Don't warn on returning the address of a label from a statement expression
Summary:
There isn't anything inherently wrong with returning a label from a
statement expression. In practice, the Linux kernel uses this pattern to
materialize PCs.

Fixes PR38569

Reviewers: niravd, rsmith, nickdesaulniers

Subscribers: cfe-commits

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

llvm-svn: 340101
2018-08-17 22:11:31 +00:00
Alexey Bataev 97b722121e [OPENMP] Fix processing of declare target construct.
The attribute marked as inheritable since OpenMP 5.0 supports it +
additional fixes to support new functionality.

llvm-svn: 339704
2018-08-14 18:31:20 +00:00
Kevin P. Neal 2c0bc8b7a3 We have in place support for parsing #pragma FENV_ACCESS, but that
information is then discarded with a warning to the user that we don't 
support it.

This patch gets us one step closer by getting the info down into the 
AST in most cases.

Reviewed by:	rsmith
Differential Revision:	https://reviews.llvm.org/D49865

llvm-svn: 339693
2018-08-14 17:06:56 +00:00
Reid Kleckner 11f9f8acde Revert r339623 "Model type attributes as regular Attrs."
This breaks compiling atlwin.h in Chromium. I'm sure the code is invalid
in some way, but we put a lot of work into accepting it, and I'm sure
rejecting it was not an intended consequence of this refactoring. :)

llvm-svn: 339638
2018-08-14 01:55:37 +00:00
Richard Smith f79178635a Model type attributes as regular Attrs.
Specifically, AttributedType now tracks a regular attr::Kind rather than
having its own parallel Kind enumeration, and AttributedTypeLoc now
holds an Attr* instead of holding an ad-hoc collection of Attr fields.

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

llvm-svn: 339623
2018-08-13 22:07:09 +00:00
Alexey Bataev f138fda5ed [OPENMP] Fix emission of the loop doacross constructs.
The number of loops associated with the OpenMP loop constructs should
not be considered as the number loops to collapse.

llvm-svn: 339603
2018-08-13 19:04:24 +00:00
Erich Keane 0fb16483ac Enforce instantiation of template multiversion functions
Multiversioned member functions inside of a template type were 
not properly being emitted.  The solution to this is to simply 
ensure that their bodies are correctly evaluated/assigned during
template instantiation.

llvm-svn: 339597
2018-08-13 18:33:20 +00:00
Nick Desaulniers 1aaf524ea1 [SEMA] add more -Wfloat-conversion to compound assigment analysis
Summary: Fixes Bug: https://bugs.llvm.org/show_bug.cgi?id=27061

Reviewers: aaron.ballman, acoomans

Reviewed By: aaron.ballman, acoomans

Subscribers: acoomans, cfe-commits, srhines, pirama

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

llvm-svn: 339581
2018-08-13 16:38:07 +00:00
Alexey Bataev 23647171ea Revert "[OPENMP] Fix emission of the loop doacross constructs."
This reverts commit r339568 because of the problems with the buildbots.

llvm-svn: 339574
2018-08-13 14:42:18 +00:00
Martin Bohme 4e1293b5e1 Summary:Add clang::reinitializes attribute
Summary:
This is for use by clang-tidy's bugprone-use-after-move check -- see
corresponding clang-tidy patch at https://reviews.llvm.org/D49910.

Reviewers: aaron.ballman, rsmith

Reviewed By: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 339569
2018-08-13 14:11:03 +00:00
Alexey Bataev 0ce6360e0e [OPENMP] Fix emission of the loop doacross constructs.
The number of loops associated with the OpenMP loop constructs should
not be considered as the number loops to collapse.

llvm-svn: 339568
2018-08-13 14:05:43 +00:00
Akira Hatanaka 9978da3615 [CodeGen] Merge equivalent block copy/helper functions.
Clang generates copy and dispose helper functions for each block literal
on the stack. Often these functions are equivalent for different blocks.
This commit makes changes to merge equivalent copy and dispose helper
functions and reduce code size.

To enable merging equivalent copy/dispose functions, the captured object
infomation is encoded into the helper function name. This allows IRGen
to check whether an equivalent helper function has already been emitted
and reuse the function instead of generating a new helper function
whenever a block is defined. In addition, the helper functions are
marked as linkonce_odr to enable merging helper functions that have the
same name across translation units and marked as unnamed_addr to enable
the linker's deduplication pass to merge functions that have different
names but the same content.

rdar://problem/42640608

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

llvm-svn: 339438
2018-08-10 15:09:24 +00:00
Stephen Kelly 40922db37c Mark up deprecated methods as such
Reviewers: teemperor!

Subscribers: cfe-commits

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

llvm-svn: 339403
2018-08-09 22:45:38 +00:00
Stephen Kelly a93380db84 Remove obsolete set call
Summary:
Case case of the switch statement here makes the same call, but it is
already done at the start of the function.

Reviewers: rsmith, dblaikie

Subscribers: cfe-commits

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

llvm-svn: 339402
2018-08-09 22:44:03 +00:00
Stephen Kelly 1c301dcbc4 Port getLocEnd -> getEndLoc
Reviewers: teemperor!

Subscribers: cfe-commits

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

llvm-svn: 339386
2018-08-09 21:09:38 +00:00
Stephen Kelly f2ceec4811 Port getLocStart -> getBeginLoc
Reviewers: teemperor!

Subscribers: jholewinski, whisperity, jfb, cfe-commits

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

llvm-svn: 339385
2018-08-09 21:08:08 +00:00
Stephen Kelly a6e4358f07 Port getStartLoc -> getBeginLoc
Reviewers: teemperor!

Subscribers: cfe-commits

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

llvm-svn: 339384
2018-08-09 21:05:56 +00:00
Erich Keane 03406c50fa [NFC] Convert ParsedAttr to use llvm::TrailingObjects
ParsedAttr is using a hand-rolled trailing-objects
implementation that gets cleaned up quite a bit by
just using llvm::TrailingObjects. This is a large
TrailingObjects list, but most things are length '0'.

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

llvm-svn: 339380
2018-08-09 20:25:12 +00:00
Erik Pilkington be168a9d34 [Sema] P0961R1: Relaxing the structured bindings customization point finding rules
Differential revision: https://reviews.llvm.org/D50418

llvm-svn: 339375
2018-08-09 20:11:13 +00:00
Stephen Kelly 02a67baf1e Add getEndLoc API to replace getLocEnd
Subscribers: cfe-commits

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

llvm-svn: 339374
2018-08-09 20:05:47 +00:00
Stephen Kelly 724e9e52a4 Add getBeginLoc API to replace getLocStart
Subscribers: cfe-commits

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

llvm-svn: 339372
2018-08-09 20:05:03 +00:00
Erich Keane 44bacdfcaf Implement diagnostic stream operator for ParsedAttr.
As a part of attempting to clean up the way attributes are 
printed, this patch adds an operator << to the diagnostics/
partialdiagnostics so that ParsedAttr can be sent directly.

This patch also rewrites a large amount* of the times when
ParsedAttr was printed using its IdentifierInfo object instead
of being printed itself.  
*"a large amount" == "All I could find".

llvm-svn: 339344
2018-08-09 13:21:32 +00:00
Richard Smith 2e34bbd8e8 PR38286: Don't crash when attempting to define a constructor for an
incomplete class template.

llvm-svn: 339210
2018-08-08 00:42:42 +00:00
Erik Pilkington 9f9462acf6 [Sema] Ensure an auto non-type template parameter is dependent
The dependent auto was getting stripped away while rebuilding the template
parameter type, so substitute it in.

rdar://41852459

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

llvm-svn: 339198
2018-08-07 22:59:02 +00:00
Richard Smith 96cb356911 Clean up and simplify RequireCompleteType.
No functional change intended, except that we will now produce more
"declared here" notes.

llvm-svn: 339187
2018-08-07 21:35:41 +00:00
Leonard Chan 7add582032 [Sema] Fix for crash on conditional operation with address_space pointer
Compiling the following causes clang to crash

```
char *cmp(__attribute__((address_space(1))) char *x, __attribute__((address_space(2))) char *y) {
  return x < y ? x : y;
}
```

with the message: "wrong cast for pointers in different address
spaces(must be an address space cast)!"

This is because during IR emission, the source and dest type for a
bitcast should not have differing address spaces.

This fix prints an error since the code shouldn't compile in the first place.

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

llvm-svn: 339167
2018-08-07 19:43:53 +00:00
Alexey Bataev bf8fe71b91 [OPENMP] Mark variables captured in declare target region as implicitly
declare target.

According to OpenMP 5.0, variables captured in lambdas in declare target
regions must be considered as implicitly declare target.

llvm-svn: 339152
2018-08-07 16:14:36 +00:00
Leonard Chan a677942d8a [Fixed Point Arithmetic] Fixed Point Constant
This patch proposes an abstract type that represents fixed point numbers, similar to APInt or APSInt that was discussed in https://reviews.llvm.org/D48456#inline-425585. This type holds a value, scale, and saturation and is meant to perform intermediate calculations on constant fixed point values.

Currently this class is used as a way for handling the conversions between fixed point numbers with different sizes and radixes. For example, if I'm casting from a signed _Accum to a saturated unsigned short _Accum, I will need to check the value of the signed _Accum to see if it fits into the short _Accum which involves getting and comparing against the max/min values of the short _Accum. The FixedPointNumber class currently handles the radix shifting and extension when converting to a signed _Accum.

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

llvm-svn: 339028
2018-08-06 16:42:37 +00:00
George Burgess IV b65955e9eb Use Optional instead of unique_ptr; NFC
Looks like the only reason we use a unique_ptr here is so that we can
conditionally construct a LogicalErrorHandler. It's a small type, and
Optional can do the same thing with 100% fewer heap allocations.

llvm-svn: 338962
2018-08-05 01:37:07 +00:00
Volodymyr Sapsai e5015abf18 [Preprocessor] Allow libc++ to detect when aligned allocation is unavailable.
Libc++ needs to know when aligned allocation is supported by clang, but is
otherwise unavailable at link time. Otherwise, libc++ will incorrectly end up
generating calls to `__builtin_operator_new`/`__builtin_operator_delete` with
alignment arguments.

This patch implements the following changes:

* The `__cpp_aligned_new` feature test macro to no longer be defined when
  aligned allocation is otherwise enabled but unavailable.

* The Darwin driver no longer passes `-faligned-alloc-unavailable` when the
  user manually specifies `-faligned-allocation` or `-fno-aligned-allocation`.

* Instead of a warning Clang now generates a hard error when an aligned
  allocation or deallocation function is referenced but unavailable.

Patch by Eric Fiselier.

Reviewers: rsmith, vsapsai, erik.pilkington, ahatanak, dexonsmith

Reviewed By: rsmith

Subscribers: Quuxplusone, cfe-commits

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

llvm-svn: 338934
2018-08-03 23:12:37 +00:00
Eli Friedman 7499610e1b Diagnose invalid cv-qualifiers for friend decls.
Differential Revision: https://reviews.llvm.org/D45712

llvm-svn: 338931
2018-08-03 22:09:44 +00:00
Yaxun Liu 4b06ffe3e4 Sema: Fix explicit address space cast involving void pointers
Explicit cast of a void pointer to a pointer type in different address space is
incorrectly classified as bitcast, which causes invalid bitcast in codegen.

The patch fixes that by checking the address space of the source and destination
type and set the correct cast kind.

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

llvm-svn: 338805
2018-08-03 03:18:56 +00:00
Nicolas Lesser e19e5a69b3 Fold two cast plus a cast in a loop into a variable.
This avoids to recast `Record` multiple times.

llvm-svn: 338801
2018-08-03 01:24:52 +00:00
Michael Kruse dc5ce72afa Append new attributes to the end of an AttributeList.
Recommit of r335084 after revert in r335516.

... instead of prepending it at the beginning (the original behavior
since implemented in r122535 2010-12-23). This builds up an
AttributeList in the the order in which the attributes appear in the
source.

The reverse order caused nodes for attributes in the AST (e.g. LoopHint)
to be in the reverse order, and therefore printed in the wrong order in
-ast-dump. Some TODO comments mention this. The order was explicitly
reversed for enable_if attribute overload resolution and name mangling,
which is not necessary anymore with this patch.

The change unfortunately has some secondary effect, especially on
diagnostic output. In the simplest cases, the CHECK lines or expected
diagnostic were changed to the the new output. If the kind of
error/warning changed, the attributes' order was changed instead.

This unfortunately causes some 'previous occurrence here' hints to be
textually after the main marker. This typically happens when attributes
are merged, but are incompatible to each other. Interchanging the role
of the the main and note SourceLocation will also cause the case where
two different declaration's attributes (in contrast to multiple
attributes of the same declaration) are merged to be reverse. There is
no easy fix because sometimes previous attributes are merged into a new
declaration's attribute list, sometimes new attributes are added to a
previous declaration's attribute list. Since 'previous occurrence here'
pointing to locations after the main marker is not rare, I left the
markers as-is; it is only relevant when the attributes are declared in
the same declaration anyway.

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

llvm-svn: 338800
2018-08-03 01:21:16 +00:00
Martin Storsjo d03fa9903f Work around more GCC miscompiles exposed by r338464.
This is the same fix as in r338478, for another occurrance of the
same pattern from r338464.

See gcc.gnu.org/PR86769 for details of the bug.

llvm-svn: 338749
2018-08-02 18:12:08 +00:00
JF Bastien b4b1f59869 __c11_atomic_load's _Atomic can be const
Summary:
C++11 onwards specs the non-member functions atomic_load and atomic_load_explicit as taking the atomic<T> by const (potentially volatile) pointer. C11, in its infinite wisdom, decided to drop the const, and C17 will fix this with DR459 (the current draft forgot to fix B.16, but that’s not the normative part).

clang’s lib/Headers/stdatomic.h implements these as #define to the __c11_* equivalent, which are builtins with custom typecheck. Fix the typecheck.

D47613 takes care of the libc++ side.

Discussion: http://lists.llvm.org/pipermail/cfe-dev/2018-May/058129.html

<rdar://problem/27426936>

Reviewers: rsmith

Subscribers: cfe-commits

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

llvm-svn: 338743
2018-08-02 17:35:46 +00:00
Matt Arsenault c65f966d76 Try to make builtin address space declarations not useless
The way address space declarations for builtins currently work
is nearly useless. The code assumes the address spaces used for
builtins is a confusingly named "target address space" from user
code using __attribute__((address_space(N))) that matches
the builtin declaration. There's no way to use this to declare
a builtin that returns a language specific address space.
The terminology used is highly cofusing since it has nothing
to do with the the address space selected by the target to use
for a language address space.

This feature is essentially unused as-is. AMDGPU and NVPTX
are the only in-tree targets attempting to use this. The AMDGPU
builtins certainly do not behave as intended (i.e. all of the
builtins returning pointers can never compile because the numbered
address space never matches the expected named address space).

The NVPTX builtins are missing tests for some, and the others
seem to rely on an implicit addrspacecast.

Change the used address space for builtins based on a target
hook to allow using a language address space for a builtin.
This allows the same builtin declaration to be used for multiple
languages with similarly purposed address spaces (e.g. the same
AMDGPU builtin can be used in OpenCL and CUDA even though the
constant address spaces are arbitarily different).

This breaks the possibility of using arbitrary numbered
address spaces alongside the named address spaces for builtins.
If this is an issue we probably need to introduce another builtin
declaration character to distinguish language address spaces from
so-called "target address spaces".

llvm-svn: 338707
2018-08-02 12:14:28 +00:00
Erich Keane 9b18eca352 [AST][4/4] Move the bit-fields from ObjCMethodDecl and ObjCContainerDecl into DeclContext
This patch follows https://reviews.llvm.org/D49729,
https://reviews.llvm.org/D49732 and
https://reviews.llvm.org/D49733.

Move the bits from ObjCMethodDecl and ObjCContainerDecl
into DeclContext.

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

Patch By: bricci

llvm-svn: 338641
2018-08-01 21:31:08 +00:00
David Green c8e3924b3b [UnrollAndJam] Add unroll_and_jam pragma handling
This adds support for the unroll_and_jam pragma, to go with the recently
added unroll and jam pass. The name of the pragma is the same as is used
in the Intel compiler, and most of the code works the same as for unroll.

#pragma clang loop unroll_and_jam has been separated into a different
patch. This part adds #pragma unroll_and_jam with an optional count, and
#pragma no_unroll_and_jam to disable the transform.

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

llvm-svn: 338566
2018-08-01 14:36:12 +00:00