Commit Graph

48855 Commits

Author SHA1 Message Date
Richard Smith aa6ce34141 Fix tracking of whether a destructor would be deleted.
I've been unable to find any cases whose behavior is actually changed by this,
but only because an implicitly deleted destructor also results in it being
impossible to have a trivial (non-deleted) copy constructor, which the place
where this really matters (choosing whether to pass a class in registers)
happens to also check.

llvm-svn: 313948
2017-09-22 01:04:22 +00:00
Akira Hatanaka 98a49337be Add support for attribute 'noescape'.
The attribute informs the compiler that the annotated pointer parameter
of a function cannot escape and enables IRGen to attach attribute
'nocapture' to parameters that are annotated with the attribute. That is
the only optimization that currently takes advantage of 'noescape', but
there are other optimizations that will be added later that improves
IRGen for ObjC blocks.

This recommits r313722, which was reverted in r313725 because clang
couldn't build compiler-rt. It failed to build because there were
function declarations that were missing 'noescape'. That has been fixed
in r313929.

rdar://problem/19886775

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

llvm-svn: 313945
2017-09-22 00:41:05 +00:00
George Karpenkov 504e236003 [Analyzer] Log when auto-synthesized body is used.
Differential Revision: https://reviews.llvm.org/D37910

llvm-svn: 313944
2017-09-22 00:37:12 +00:00
Richard Smith dfc4bff19b Extend -ast-dump for CXXRecordDecl to dump the flags from the DefinitionData.
llvm-svn: 313943
2017-09-22 00:11:15 +00:00
Erich Keane 69dbbb0bca Suppress Wsign-conversion for enums with matching underlying type
As reported here: https://bugs.llvm.org/show_bug.cgi?id=34692

A non-defined enum with a backing type was always defaulting to
being treated as a signed type. IN the case where it IS defined,
the signed-ness of the actual items is used.

This patch uses the underlying type's signed-ness in the non-defined
case to test signed-comparision.

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

llvm-svn: 313907
2017-09-21 19:58:55 +00:00
Volodymyr Sapsai 4fbaa62b60 [Sema] Prevent InstantiateClass from checking unrelated exception specs.
Sema::InstantiateClass should check only exception specs added during
class instantiation and ignore already present delayed specs. This fixes
a case where we instantiate a class before parsing member initializers,
check exceptions for a different class and fail to find a member
initializer. Which is required for comparing exception specs for
explicitly-defaulted and implicit default constructor. With the fix we
are still checking exception specs but only after member initializers
are present.

Removing errors in crash-unparsed-exception.cpp is acceptable according
to discussion in PR24000 because other compilers accept code in
crash-unparsed-exception.cpp as valid.

rdar://problem/34167492

Reviewers: davide, rsmith

Reviewed By: rsmith

Subscribers: dim, cfe-commits

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

llvm-svn: 313906
2017-09-21 19:54:12 +00:00
Artem Belevich b542f1f3df [CUDA] Fixed order of words in the names of shfl builtins.
Differential Revision: https://reviews.llvm.org/D38147

llvm-svn: 313899
2017-09-21 18:46:39 +00:00
Artem Belevich 42960b4188 [NVPTX] Implemented bar.warp.sync, barrier.sync, and vote{.sync} instructions/intrinsics/builtins.
Differential Revision: https://reviews.llvm.org/D38148

llvm-svn: 313898
2017-09-21 18:44:49 +00:00
Volodymyr Sapsai ddf524c031 [Sema] Fix using old initializer during switch statement transformation.
It fixes a crash in CodeGen when we are trying to generate code for
initializer expression created before template instantiation, like

    CallExpr '<dependent type>'
    |-UnresolvedLookupExpr '<overloaded function type>' lvalue (ADL) = 'parse'
    `-DeclRefExpr 'Buffer<N>' lvalue ParmVar 'buffer' 'Buffer<N>'

rdar://problem/33888545

Reviewers: rsmith, ahatanak

Reviewed By: ahatanak

Subscribers: aemerson, kristof.beyls, cfe-commits

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

llvm-svn: 313896
2017-09-21 17:58:27 +00:00
Volodymyr Sapsai 8c9fde598b [fixup][Sema] Allow in C to define tags inside enumerations.
Fix for too aggressive error err_type_defined_in_enum introduced in
r313386. Defining tags inside enumerations is prohibited in C++ but
allowed in C.

Reviewers: aaron.ballman, rnk, doug.gregor

Reviewed By: rnk

Subscribers: alberto_magni, cfe-commits

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

llvm-svn: 313894
2017-09-21 17:41:30 +00:00
Alexey Bataev 0dce2ea758 [OPENMP] Use canonical declarations for redeclarations checks.
If the captured variable has some redeclarations we may run into the
situation where the redeclaration is used instead of the canonical
declaration and we may consider this variable as one not captured
before.

llvm-svn: 313880
2017-09-21 14:06:59 +00:00
Gabor Horvath 5536a01ad2 [analyzer] Fix an assertion fail in VirtualCallChecker
Differential Revision: https://reviews.llvm.org/D37978

llvm-svn: 313866
2017-09-21 08:18:59 +00:00
Vitaly Buka 17def21749 Revert "Give external linkage and mangling to lambdas inside inline variables and variable templates."
To fix: runtime error: load of value 15, which is not a valid value for type 'clang::LVComputationKind'

This reverts commit r313827.

llvm-svn: 313856
2017-09-21 02:51:56 +00:00
Matt Morehouse 4881a23ca8 [MSan] Disable sanitization for __sanitizer_dtor_callback.
Summary:
Eliminate unnecessary instrumentation at __sanitizer_dtor_callback
call sites.  Fixes https://github.com/google/sanitizers/issues/861.

Reviewers: eugenis, kcc

Reviewed By: eugenis

Subscribers: vitalybuka, llvm-commits, cfe-commits, hiraditya

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

llvm-svn: 313831
2017-09-20 22:53:08 +00:00
Erich Keane bb8636477d [MS Compat]Allow __interfaces to have properties.
__interface types are allowed in MSVC to have "property" data members
(marked with declspec property). This patch alters Sema to allow property
data members.

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

llvm-svn: 313828
2017-09-20 22:28:24 +00:00
Richard Smith fb130c6084 Give external linkage and mangling to lambdas inside inline variables and variable templates.
This implements the proposed approach in https://github.com/itanium-cxx-abi/cxx-abi/issues/33

llvm-svn: 313827
2017-09-20 22:17:55 +00:00
Artem Belevich 4654dc89be [NVPTX] Implemented shfl.sync instruction and supporting intrinsics/builtins.
Differential Revision: https://reviews.llvm.org/D38090

llvm-svn: 313820
2017-09-20 21:23:07 +00:00
Alexey Bataev e85de8fcf9 [OPENMP] Support for re-declarations when checking captured variables.
Need to check for variables re-declarations when checking that the
variable was already captured in the captured region.

llvm-svn: 313805
2017-09-20 20:11:31 +00:00
Cameron Desrochers 531aec2e90 Fixed unused variable warning introduced in r313796 causing build failure
llvm-svn: 313802
2017-09-20 19:37:37 +00:00
Cameron Desrochers 84fd064ef9 [PCH] Fixed preamble breaking with BOM presence (and particularly, fluctuating BOM presence)
This patch fixes broken preamble-skipping when the preamble region includes a byte order mark (BOM). Previously, parsing would fail if preamble PCH generation was enabled and a BOM was present.

This also fixes preamble invalidation when a BOM appears or disappears. This may seem to be an obscure edge case, but it happens regularly with IDEs that pass buffer overrides that never (or always) have a BOM, yet the underlying file from the initial parse that generated a PCH might (or might not) have a BOM.

I've included a test case for these scenarios.

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

llvm-svn: 313796
2017-09-20 19:03:37 +00:00
Andrew Kaylor b9be53634c Remove offset size check in nullptr arithmetic handling
Differential Revision: https://reviews.llvm.org/D37042

llvm-svn: 313784
2017-09-20 18:06:44 +00:00
Roman Lebedev 30d2608637 Replace r313747, don't always warn on enums, rework testcases.
As Aaron Ballman has pointed out, that is not really correct.
So the key problem there is the invalidity of the testcase.

Revert r313747, and rework testcase in such a way, so these
details (platform-specific default enum sigdness) are
accounted for.

Also, add a C++-specific testcase.

llvm-svn: 313756
2017-09-20 13:50:01 +00:00
Roman Lebedev b513ebfc0f [Sema] CheckTautologicalComparisonWithZero(): always complain about enums
Hopefully fixes test-clang-msc-x64-on-i686-linux-RA build.

The underlying problem is that the enum is signed there.
Yet still, it is invalid for it to contain negative values,
so the comparison is always tautological in this case.

No differential, but related to https://reviews.llvm.org/D37629

llvm-svn: 313747
2017-09-20 10:15:27 +00:00
Roman Lebedev b0f0a1ea03 [Sema] Move some stuff into -Wtautological-unsigned-enum-zero-compare
Recommit. Original commit was reverted because buildbots broke.
The error was only reproducible in the build with assertions.
The problem was that the diagnostic expected true/false as
bool, while it was provided as string "true"/"false".

Summary:
As requested by Sam McCall:
> Enums (not new I guess). Typical case: if (enum < 0 || enum > MAX)
> The warning strongly suggests that the enum < 0 check has no effect
> (for enums with nonnegative ranges).
> Clang doesn't seem to optimize such checks out though, and they seem
> likely to catch bugs in some cases. Yes, only if there's UB elsewhere,
> but I assume not optimizing out these checks indicates a deliberate
> decision to stay somewhat compatible with a technically-incorrect
> mental model.
> If this is the case, should we move these to a
> -Wtautological-compare-enum subcategory?

Reviewers: rjmccall, rsmith, aaron.ballman, sammccall, bkramer, djasper

Reviewed By: aaron.ballman

Subscribers: jroelofs, cfe-commits

Tags: #clang

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

llvm-svn: 313745
2017-09-20 09:54:47 +00:00
Manuel Klimek 89628f6414 clang-format clang-format.
llvm-svn: 313744
2017-09-20 09:51:03 +00:00
Manuel Klimek e411aa85ac Fix clang-format's detection of structured bindings.
Correctly determine when [ is part of a structured binding instead of a
lambda.

To be able to reuse the implementation already available, this patch also:
- sets the Previous link of FormatTokens in the UnwrappedLineParser
- moves the isCppStructuredBinding function into FormatToken

Before:
  auto const const &&[x, y] { A *i };

After:
  auto const const && [x, y]{A * i};

Fixing formatting of the type of the structured binding is still missing.

llvm-svn: 313742
2017-09-20 09:29:37 +00:00
Richard Smith 405e2dbf37 Implement C++ [basic.link]p8.
If a function or variable has a type with no linkage (and is not extern "C"),
any use of it requires a definition within the same translation unit; the idea
is that it is not possible to define the entity elsewhere, so any such use is
necessarily an error.

There is an exception, though: some types formally have no linkage but
nonetheless can be referenced from other translation units (for example, this
happens to anonymous structures defined within inline functions). For entities
with those types, we suppress the diagnostic except under -pedantic.

llvm-svn: 313729
2017-09-20 07:22:00 +00:00
Akira Hatanaka 30c93dba5b Revert "Add support for attribute 'noescape'."
This reverts commit r313722.

It looks like compiler-rt/lib/tsan/rtl/tsan_libdispatch_mac.cc cannot be
compiled because some of the functions declared in the file do not match
the ones in the SDK headers (which are annotated with 'noescape').

llvm-svn: 313725
2017-09-20 06:55:43 +00:00
Akira Hatanaka e974479fa5 Add support for attribute 'noescape'.
The attribute informs the compiler that the annotated pointer parameter
of a function cannot escape and enables IRGen to attach attribute
'nocapture' to parameters that are annotated with the attribute. That is
the only optimization that currently takes advantage of 'noescape', but
there are other optimizations that will be added later that improves
IRGen for ObjC blocks.

rdar://problem/19886775

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

llvm-svn: 313722
2017-09-20 06:32:45 +00:00
Akira Hatanaka 1b9418e163 Revert "Add support for attribute 'noescape'."
This reverts r313717.

I closed the wrong phabricator review.

llvm-svn: 313721
2017-09-20 06:27:39 +00:00
Akira Hatanaka fc587e6a57 Add support for attribute 'noescape'.
The attribute informs the compiler that the annotated pointer parameter
of a function cannot escape and enables IRGen to attach attribute
'nocapture' to parameters that are annotated with the attribute. That is
the only optimization that currently takes advantage of 'noescape', but
there are other optimizations that will be added later that improves
IRGen for ObjC blocks.

rdar://problem/19886775

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

llvm-svn: 313720
2017-09-20 06:22:51 +00:00
Akira Hatanaka 7d85b8f6f6 [Sema][ObjC] Warn about mismatches in attributes between overriding and
overridden methods when compiling for non-ARC.

Previously, clang would error out when compiling for ARC, but didn't
print any diagnostics when compiling for non-ARC.

This was pointed out in the patch review for attribute noescape:

https://reviews.llvm.org/D32210

llvm-svn: 313717
2017-09-20 05:39:18 +00:00
Adam Nemet 3ac802a1f6 Add override for ClangDiagnosticHandler::isAnyRemarkEnabled()
This is used by the new closure-based variant of
OptimizationRemarkEmitter::emit().

llvm-svn: 313693
2017-09-19 23:00:59 +00:00
Roman Lebedev 918eaf9585 Revert "[Sema] Move some stuff into -Wtautological-unsigned-enum-zero-compare"
This reverts commit r313677.

Buildbots fail with assertion failure
Failing Tests (7):
    Clang :: Analysis/null-deref-ps.c
    Clang :: CodeGen/enum.c
    Clang :: Sema/compare.c
    Clang :: Sema/outof-range-constant-compare.c
    Clang :: Sema/tautological-unsigned-enum-zero-compare.c
    Clang :: Sema/tautological-unsigned-zero-compare.c
    Clang :: SemaCXX/compare.cpp

llvm-svn: 313683
2017-09-19 21:40:41 +00:00
Roman Lebedev c9c9748d99 [Sema] Move some stuff into -Wtautological-unsigned-enum-zero-compare
Summary:
As requested by Sam McCall:
> Enums (not new I guess). Typical case: if (enum < 0 || enum > MAX)
> The warning strongly suggests that the enum < 0 check has no effect
> (for enums with nonnegative ranges).
> Clang doesn't seem to optimize such checks out though, and they seem
> likely to catch bugs in some cases. Yes, only if there's UB elsewhere,
> but I assume not optimizing out these checks indicates a deliberate
> decision to stay somewhat compatible with a technically-incorrect
> mental model.
> If this is the case, should we move these to a
> -Wtautological-compare-enum subcategory?

Reviewers: rjmccall, rsmith, aaron.ballman, sammccall, bkramer, djasper

Reviewed By: aaron.ballman

Subscribers: jroelofs, cfe-commits

Tags: #clang

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

llvm-svn: 313677
2017-09-19 21:11:35 +00:00
Rachel Craik 1cf49e4d12 [OpenMP] fix seg-faults printing diagnostics with invalid ordered(n) values
When the value specified for n in ordered(n) is larger than the number of loops a segmentation fault can occur in one of two ways when attempting to print out a diagnostic for an associated depend(sink : vec):
1) The iteration vector vec contains less than n items
2) The iteration vector vec contains a variable that is not a loop control variable
This patch addresses both of these issues.

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

llvm-svn: 313675
2017-09-19 21:04:23 +00:00
Andrew Kaylor 3d0a540857 Teach clang to tolerate the 'p = nullptr + n' idiom used by glibc
Differential Revision: https://reviews.llvm.org/D37042

llvm-svn: 313666
2017-09-19 20:26:40 +00:00
Adam Nemet 5d2eb16c9f Fix ClangDiagnosticHandler::is*RemarkEnabled members
Apparently these weren't really working. I added test coverage and fixed the
typo in the name and the parameter.

llvm-svn: 313653
2017-09-19 17:59:40 +00:00
Bjorn Pettersson 9cf0e12a80 [Sema] Disallow assigning record lvalues with nested const-qualified fields.
Summary:
According to C99 6.3.2.1p1, structs and unions with nested
const-qualified fields (that is, const-qualified fields
declared at some recursive level of the aggregate) are not
modifiable lvalues. However, Clang permits assignments of
these lvalues.

With this patch, we both prohibit the assignment of records
with const-qualified fields and emit a best-effort diagnostic.
This fixes https://bugs.llvm.org/show_bug.cgi?id=31796 .

Committing on behalf of bevinh (Bevin Hansson).

Reviewers: rtrieu, rsmith, bjope

Reviewed By: bjope

Subscribers: Ka-Ka, rogfer01, bjope, fhahn, cfe-commits

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

llvm-svn: 313628
2017-09-19 13:10:30 +00:00
Jina Nahias 3ad702a1ed Lowering Mask Set1 intrinsics to LLVM IR
This patch, together with a matching llvm patch (https://reviews.llvm.org/D37669), implements the lowering of X86 mask set1 intrinsics to IR.

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

llvm-svn: 313624
2017-09-19 11:00:27 +00:00
Manuel Klimek 9f0a4e5041 Fix formatting of lambda introducers with initializers.
Most of the work was already done when we introduced a look-behind based
lambda introducer detection.

This patch finishes the transition by completely relying on the simple
lambda introducer detection and simply recursing into normal
brace-parsing code to parse until the end of the introducer.

This fixes initializers in lambdas, including nested lambdas.

Before:
  auto a = [b = [c = 42]{}]{};
  auto b = [c = &i + 23]{};

After:
  auto a = [b = [c = 42] {}] {};
  auto b = [c = &i + 23] {};

llvm-svn: 313622
2017-09-19 09:59:30 +00:00
Vedant Kumar ef8e05ff07 [Coverage] Remove deferred region for trailing return, fixes PR34611
As a special case, throw away deferred regions for trailing returns.
This allows the closing curly brace to have a count, and is less
distracting.

llvm-svn: 313603
2017-09-19 00:29:46 +00:00
Vedant Kumar a1c4deb792 [Coverage] Use a new API to label gap areas
This will make it possible for llvm-cov to pick better line execution
counts, and is part of the fix for llvm.org/PR34612.

llvm-svn: 313598
2017-09-18 23:37:30 +00:00
Erich Keane 0ac9524c99 [Sema] Fix a pair of crashes when generating exception specifiers with an
error'ed field for a template class' default ctor.

The two examples in the test would both cause a compiler assert when attempting
to calculate the exception specifier for the default constructor for the
template classes. The problem was that dependents of this function expect that
Field->getInClassInitializer (including canThrow) is not nullptr. However, if
the template's initializer has an error, exactly that situation happens.

This patch simply sets the field to be invalid.

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

llvm-svn: 313569
2017-09-18 21:28:55 +00:00
Vitaly Buka 55a27d3c14 Another attempt to fix warning discovered by r313487. [-Wunused-lambda-capture]
llvm-svn: 313521
2017-09-18 08:26:01 +00:00
NAKAMURA Takumi 7f10a34d88 Revert rL313511, "Fix a warning discovered by rL313487. [-Wunused-lambda-capture]"
It was incompatible to msc.

llvm-svn: 313513
2017-09-18 05:52:57 +00:00
NAKAMURA Takumi 0004057985 Fix a warning discovered by rL313487. [-Wunused-lambda-capture]
llvm-svn: 313511
2017-09-18 04:55:33 +00:00
NAKAMURA Takumi a5b348be9d Reformat.
llvm-svn: 313510
2017-09-18 04:55:31 +00:00
Craig Topper a98e1e214d [X86] Move even more of our CPU to feature mapping switch to use fallthroughs
This arranges more of the Intel and AMD CPUs into fallthrough positions based on their features. We may be able to merge this new AMD set with the BTVER or BDVER sets but I didn't look that closely.

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

llvm-svn: 313497
2017-09-17 19:05:46 +00:00
Faisal Vali f60ebcda68 Fix the second half of PR34266: Don't implicitly capture '*this' if the members are found in a class unrelated to the enclosing class.
https://bugs.llvm.org/show_bug.cgi?id=34266

For e.g.
  struct A {
     void f(int);
     static void f(char);
  };
  struct B {
    auto foo() {
      return [&] (auto a) {
         A::f(a); // this should not cause a capture of '*this'
      };
    }
  };

The patch does the following:
1) It moves the check to attempt an implicit capture of '*this' by reference into the more logical location of when the call is actually built within ActOnCallExpr (as opposed to when the unresolved-member-lookup node is created).
  - Reminder: A capture of '*this' by value has to always be an explicit capture.

2) It additionally checks whether the naming class of the UnresolvedMemberExpr ('A' in the example above) is related to the enclosing class ('B' above).

P.S. If you have access to ISO-C++'s CWG reflector, see this thread for some potentially related discussion: http://lists.isocpp.org/core/2017/08/2851.php

llvm-svn: 313487
2017-09-17 15:37:51 +00:00