Commit Graph

32367 Commits

Author SHA1 Message Date
Michael Zuckerman 35731a0b84 [Clang] Adding missing feature to goldmont
Change-Id: I6c22478d16b8e02ce60dae2f8c80d43bc5ab3a9c
llvm-svn: 314104
2017-09-25 13:49:32 +00:00
Jina Nahias 123c599a0f fixing a bug in mask[z]_set1 intrinsic
Differential Revision: https://reviews.llvm.org/D38231

Change-Id: I80bbff9cbe93e4be54d8a761ef9723edf3f57c57
llvm-svn: 314102
2017-09-25 13:38:08 +00:00
Richard Smith 263a0a33cc Don't warn about runtime behavior problems in variable initializers that we
know are going to be constant-evaluated.

Any relevant diagnostics should be produced by constant expression evaluation.

llvm-svn: 314067
2017-09-23 18:27:11 +00:00
Akira Hatanaka 34b5dbca0a Promote storage-only __fp16 vector operands to float vectors.
This commit fixes a bug in the handling of storage-only __fp16 vectors
where clang didn't promote __fp16 vector operands to float vectors.

Conceptually, it performs the following transformation on the AST in
CreateBuiltinBinOp and CreateBuiltinUnaryOp:

(Before)
  typedef __fp16 half4 __attribute__ ((vector_size (8)));
  typedef float float4 __attribute__ ((vector_size (16)));
  half4 hv0, hv1, hv2, hv3;

  hv0 = hv1 + hv2 + hv3;

(After)
  float4 t0 = (float4)hv1 + (float4)hv2;
  float4 t1 = t0 + (float4)hv3;
  hv0 = (half4)t1;

Note that this commit fixes the bug for targets that set
HalfArgsAndReturns to true (ARM and ARM64). Targets using intrinsics
such as llvm.convert.to.fp16 to handle __fp16 are still broken.

rdar://problem/20625184

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

llvm-svn: 314056
2017-09-23 05:02:02 +00:00
Richard Smith cdb06f2150 Correctly compute linkage for members of internal linkage classes.
We used to give such members no linkage instead of giving them the linkage of
the class.

llvm-svn: 314054
2017-09-23 04:02:17 +00:00
Richard Smith df963a38a9 DR1113: anonymous namespaces formally give their contents internal linkage.
This doesn't affect our code generation in any material way -- we already give
such declarations internal linkage from a codegen perspective -- but it has
some subtle effects on code validity.

We suppress the 'L' (internal linkage) marker for mangled names in anonymous
namespaces, because it is redundant (the information is already carried by the
namespace); this deviates from GCC's behavior if a variable or function in an
anonymous namespace is redundantly declared 'static' (where GCC does include
the 'L'), but GCC's behavior is incoherent because such a declaration can be
validly declared with or without the 'static'.

We still deviate from the standard in one regard here: extern "C" declarations
in anonymous namespaces are still granted external linkage. Changing those does
not appear to have been an intentional consequence of the standard change in
DR1113.

llvm-svn: 314037
2017-09-22 22:21:44 +00:00
Vedant Kumar 5fc4942888 [test] Enable clang-func-mapping as a test dep with the analyzer
clang-func-mapping should not be a test dependency when the static
analyzer isn't being built.

llvm-svn: 314036
2017-09-22 22:17:10 +00:00
Akira Hatanaka ba0367a708 [CodeGen][ObjC] Build the global block structure before emitting the
body of global block invoke functions.

This commit fixes an infinite loop in IRGen that occurs when compiling
the following code:

void FUNC2() {
  static void (^const block1)(int) = ^(int a){
    if (a--)
      block1(a);
  };
}

This is how IRGen gets stuck in the infinite loop:

1. GenerateBlockFunction is called to emit the body of "block1".

2. GetAddrOfGlobalBlock is called to get the address of "block1". The
   function calls getAddrOfGlobalBlockIfEmitted to check whether the
   global block has been emitted. If it hasn't been emitted, it then
   tries to emit the body of the block function by calling
   GenerateBlockFunction, which goes back to step 1.

This commit prevents the inifinite loop by building the global block in
GenerateBlockFunction before emitting the body of the block function.

rdar://problem/34541684

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

llvm-svn: 314029
2017-09-22 21:32:06 +00:00
Ilya Biryukov 4e7a6fef81 Set completion priority of destructors and operators to CCP_Unlikely.
Summary:
It will move destructors and operators to the end of completion list.
Destructors and operators are currently very high on the completion
list, as they have the same priority as member functions. However,
they are clearly not something users usually choose in completion
lists.

Reviewers: arphaman, erikjv, bkramer, krasimir

Reviewed By: arphaman

Subscribers: eraman, klimek, cfe-commits

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

llvm-svn: 314019
2017-09-22 19:07:37 +00:00
Vedant Kumar 148fd4416b [lit.cfg] Avoid concatenating which(clang-func-mapping) if it's missing
This un-breaks a lit workflow where you run lit tests from a test
sub-directory within clang without first building clang-func-mapping.

llvm-svn: 314013
2017-09-22 18:42:28 +00:00
Alexander Shaposhnikov 1788a9b71c [clang] Fix printf fixit for objc specific types
For the triple thumbv7-apple-ios8.0.0 ssize_t is long and size_t is unsigned long,
while NSInteger is int and NSUinteger is unsigned int. Following 
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html
Clang catches it and insert a cast to long, for example
 printf("%zd", getNSInteger())
will be replaced with 
 printf("%zd", (long)getNSInteger())
but since the underlying type of ssize_t is long the specifier "%zd" is not getting replaced.
This diff changes this behavior to enable replacing the specifier "%zd" with the correct one.

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

Test plan: make check-all

llvm-svn: 314011
2017-09-22 18:36:06 +00:00
Vedant Kumar 0acf3434e7 [Coverage] Add an option to emit limited coverage info
Add an option to emit limited coverage info for unused decls. It's just a
cl::opt for now to allow us to experiment quickly.

When building llc, this results in an 84% size reduction in the llvm_covmap
section, and a similar size reduction in the llvm_prf_names section. In
practice I expect the size reduction to be roughly quadratic with the size of
the program.

The downside is that coverage for headers will no longer be complete. This will
make the line/function/region coverage metrics incorrect, since they will be
artificially high. One mitigation would be to somehow disable those metrics
when using limited-coverage=true.

This is related to: llvm.org/PR34533 (make SourceBasedCodeCoverage scale)

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

llvm-svn: 314002
2017-09-22 18:23:04 +00:00
Dave Lee 1a532c9e1d [index] Generate class & metaclass manglings for objc
Summary:
ObjC classes have two associated symbols, one for the class and one for the
metaclass.

This change overloads `CodegenNameGenerator::getAllManglings` to produce both
class and metaclass symbols.

While this function is called by `clang_Cursor_getCXXManglings`, it's only
called for CXXRecordDecl and CXXMethodDecl, and so libclang's behavior is
unchanged.

Reviewers: arphaman, abdulras, alexshap, compnerd

Reviewed By: compnerd

Subscribers: compnerd

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

llvm-svn: 313997
2017-09-22 16:58:57 +00:00
Alexey Bataev b7f18c3297 [OPENMP] Handle re-declaration of captured variables in CodeGen.
If the captured variable has re-declaration we may end up with the
situation where the captured variable is the re-declaration while the
referenced variable is the canonical declaration (or vice versa). In
this case we may generate wrong code. Patch fixes this situation.

llvm-svn: 313995
2017-09-22 16:56:13 +00:00
Wei Mi b086289787 [Atomic][X8664] set max atomic inline width according to the target
This is to fix PR31620. MaxAtomicInlineWidth is set to 128 for x86_64. However
for target without cx16 support, 128 atomic operation will generate __sync_*
libcalls. The patch set MaxAtomicInlineWidth to 64 if the target doesn't support
cx16.

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

llvm-svn: 313992
2017-09-22 16:30:00 +00:00
Gabor Horvath e350b0a196 Add Cross Translation Unit support library
This patch introduces a class that can help to build tools that require cross
translation unit facilities. This class allows function definitions to be loaded
from external AST files based on an index. In order to use this functionality an
index is required. The index format is a flat text file but it might be
replaced with a different solution in the near future. USRs are used as names to
look up the functions definitions. This class also does caching to avoid
redundant loading of AST files.

Right now only function defnitions can be loaded using this API because this is
what the in progress cross translation unit feature of the Static Analyzer
requires. In to future this might be extended to classes, types etc.

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

llvm-svn: 313975
2017-09-22 11:11:01 +00:00
Gabor Horvath 61e7adef42 [analyzer] Add new delete with non-virtual destructor check
Patch by: Reka Nikolett Kovacs

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

llvm-svn: 313973
2017-09-22 10:16:33 +00:00
Richard Smith 7ff8304db7 Closure types have no name (and can't have a typedef name for linkage
purposes), so they never formally have linkage.

llvm-svn: 313957
2017-09-22 04:33:20 +00:00
Richard Smith c95d2c5dda 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

This reinstates r313827, reverted in r313856, with a fix for the 'out-of-bounds
enumeration value' ubsan error in that change.

llvm-svn: 313955
2017-09-22 04:25:05 +00:00
Saleem Abdulrasool 83e2838d03 Driver: remove support for libstdc++ from CrossWindows
This code path is entirely untested and not really maintained.  The
expected use here is with libc++ only.

llvm-svn: 313954
2017-09-22 04:01:12 +00:00
Akira Hatanaka 6c2dbc69a7 Add test cases that weren't committed in r313945.
llvm-svn: 313952
2017-09-22 01:54:36 +00:00
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
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
Zachary Turner 0aa02c08a7 Resubmit "[lit] Refactor out some more common lit configuration code."
There were two issues, one Python 3 specific related to Unicode,
and another which is that the tool substitution for lld no longer
rejected matches where a / preceded the tool name.

llvm-svn: 313928
2017-09-21 22:16:40 +00:00
Zachary Turner 5f2fd9b783 Revert "[lit] Refactor out some more common lit configuration code."
This is breaking several bots.  I have enough information to
investigate, so I'm reverting to green until I get it figured
out.

llvm-svn: 313922
2017-09-21 21:45:45 +00:00
Zachary Turner 0d36b657b9 [lit] Refactor out some more common lit configuration code.
debuginfo-tests has need to reuse a lot of common configuration
from clang and lld, and in general it seems like all of the
projects which are tightly coupled (e.g. lld, clang, llvm, lldb,
etc) can benefit from knowing about one other.  For example,
lldb needs to know various things about how to run clang in its
test suite.  Since there's a lot of common substitutions and
operations that need to be shared among projects, sinking this
up into LLVM makes sense.

In addition, this patch introduces a function add_tool_substitution
which handles all the dirty intricacies of matching tool names
which was previously copied around the various config files.  This
is now a simple straightforward interface which is hard to mess
up.

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

llvm-svn: 313919
2017-09-21 21:27:31 +00:00
Erich Keane 05eac27677 Add testcase I forgot to add in R313907.
llvm-svn: 313909
2017-09-21 20:14:08 +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 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
Zachary Turner bbe23ae675 [lit] Rename lld and clang lit configs to end in .py
This follows in line with a previous patch of renaming LLVM's.

Working on these files is difficult in certain operating systems
and/or environments that don't like handling python code with a
non .py file extension.

llvm-svn: 313892
2017-09-21 17:38:13 +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
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
Serge Pavlov 3b7d381169 Put target deduced from executable name at the start of argument list
When clang is called as 'target-clang', put deduced target option at
the start of argument list so that option '--target=' specified in command
line could override it.

This change fixes PR34671.

llvm-svn: 313760
2017-09-20 15:22:27 +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 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
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
Andrew Kaylor 21a2aa7203 Fix 32-bit buildbots by removing tests that are dependent on pointer-size comparisons.
The recently behavior in the code that these tests were meant to be checking will be ammended as soon as a suitable change can be properly reviewed.

llvm-svn: 313684
2017-09-19 21:43:01 +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
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
Zachary Turner d4401d354a [lit] Update clang and lld to use new config helpers.
NFC intended here, this only updates clang and lld's lit configs
to use some helper functionality in the lit.llvm submodule.

llvm-svn: 313579
2017-09-18 22:26:48 +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
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
Heejin Ahn b29a17ba21 [WebAssembly] Restore __builtin_wasm_rethrow builtin
Summary:
Restore the `__builtin_wasm_rethrow` builtin deleted in D37931. On second
thought, it appears it can be used to implement `__cxa_rethrow`.

Reviewers: dschuff, sunfish

Reviewed By: dschuff

Subscribers: jfb, sbc100, jgravelle-google

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

llvm-svn: 313430
2017-09-16 01:07:43 +00:00
Craig Topper 8cd7b0cd2c [X86] Use native shuffle vector for the perm2f128 intrinsics
This patch replaces the perm2f128 intrinsics with native shuffle vectors.

This uses a pretty simple approach to allocate source 0 to the lower half input and source 1 to the upper half input. Then its just a matter of filling in the indices to use either the lower or upper half of that specific source. This can result in the same source being used by both operands. InstCombine or SelectionDAGBuilder should be able to clean that up.

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

llvm-svn: 313418
2017-09-15 23:00:59 +00:00
Zachary Turner ce92db13ea Resubmit "[lit] Force site configs to run before source-tree configs"
This is a resubmission of r313270.  It broke standalone builds of
compiler-rt because we were not correctly generating the llvm-lit
script in the standalone build directory.

The fixes incorporated here attempt to find llvm/utils/llvm-lit
from the source tree returned by llvm-config.  If present, it
will generate llvm-lit into the output directory.  Regardless,
the user can specify -DLLVM_EXTERNAL_LIT to point to a specific
lit.py on their file system.  This supports the use case of
someone installing lit via a package manager.  If it cannot find
a source tree, and -DLLVM_EXTERNAL_LIT is either unspecified or
invalid, then we print a warning that tests will not be able
to run.

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

llvm-svn: 313407
2017-09-15 22:10:46 +00:00
Heejin Ahn fa9e1fba8c Remove __builtin_wasm_rethrow builtin
Summary:
Remove `__builtin_wasm_rethrow` builtin. I thought it was required to implement
`__cxa_rethrow` function in libcxxabi, but it turned out it will be using
`__builtin_wasm_throw` instead.

Reviewers: dschuff, jgravelle-google

Reviewed By: jgravelle-google

Subscribers: jfb, sbc100, jgravelle-google

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

llvm-svn: 313402
2017-09-15 22:01:22 +00:00
Craig Topper 04370d3a82 [X86] Disable _mm512_maskz_set1_epi64 intrinsic on 32-bit targets to prevent a backend isel failure.
The __builtin_ia32_pbroadcastq512_mem_mask we were previously trying to use in 32-bit mode is not implemented in the x86 backend and causes isel to fail in release builds. In debug builds it fails even earlier during legalization with an llvm_unreachable.

While there add the missing test case for this intrinsic for this for 64-bit mode.

This fixes PR34631. D37668 should be able to recover this for 32-bit mode soon. But I wanted to fix the crash ahead of that.

llvm-svn: 313392
2017-09-15 20:27:59 +00:00
Volodymyr Sapsai 8b0bbc6fe0 [Sema] Error out early for tags defined inside an enumeration.
This fixes PR28903 by avoiding access check for inner enum constant. We
are performing access check because one enum constant references another
and because enum is defined in CXXRecordDecl. But access check doesn't
work because FindDeclaringClass doesn't expect more than one EnumDecl
and because inner enum has access AS_none due to not being an immediate
child of a record.

The change detects an enum is defined in wrong place and allows to skip
parsing its body. Access check is skipped together with body parsing.
There was no crash in C, added test case to cover the new error.

rdar://problem/28530809

Reviewers: rnk, doug.gregor, rsmith

Reviewed By: doug.gregor

Subscribers: cfe-commits

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

llvm-svn: 313386
2017-09-15 19:51:42 +00:00
George Karpenkov e28adb4fb2 [Analyzer] Check function name size before indexing.
https://reviews.llvm.org/D37908

llvm-svn: 313385
2017-09-15 19:51:26 +00:00
Erich Keane 58bd603109 Fix the __interface inheritence rules to work better with IUnknown and IDispatch
__interface objects in MSVC are permitted to inherit from __interface types, 
and interface-like types.

Additionally, there are two default interface-like types 
(IUnknown and IDispatch) that all interface-like
types must inherit from.

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

llvm-svn: 313364
2017-09-15 16:03:35 +00:00
Zachary Turner 83dcb68468 Revert "[lit] Force site configs to run before source-tree configs"
This patch is still breaking several multi-stage compiler-rt bots.
I already know what the fix is, but I want to get the bots green
for now and then try re-applying in the morning.

llvm-svn: 313335
2017-09-15 02:56:40 +00:00
Volodymyr Sapsai 4c33079dc3 [Sema] Correct typos in LHS, RHS before building a binop expression.
Specifically, typo correction should be done before dispatching between
different kinds of binary operations like pseudo-object assignment,
overloaded binary operation, etc.

Without this change we hit an assertion

    Assertion failed: (!LHSExpr->hasPlaceholderType(BuiltinType::PseudoObject)), function CheckAssignmentOperands

when in Objective-C we reference a property without `self` and there are
2 equally good typo correction candidates: ivar and a class name. In
this case LHS expression in `BuildBinOp` is

    CXXDependentScopeMemberExpr
    `-TypoExpr

and instead of handling Obj-C property assignment as pseudo-object
assignment, we call `CreateBuiltinBinOp` which corrects typo to

    ObjCPropertyRefExpr '<pseudo-object type>'

but cannot handle pseudo-objects and asserts about it (indirectly,
through `CheckAssignmentOperands`).

rdar://problem/33102722

Reviewers: rsmith, ahatanak, majnemer

Reviewed By: ahatanak

Subscribers: cfe-commits

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

llvm-svn: 313323
2017-09-15 00:08:37 +00:00
Douglas Gregor f0b11de279 [Module map] Introduce a private module re-export directive.
Introduce a new "export_as" directive for top-level modules, which
indicates that the current module is a "private" module whose symbols
will eventually be exported through the named "public" module. This is
in support of a common pattern in the Darwin ecosystem where a single
public framework is constructed of several private frameworks, with
(currently) header duplication and some support from the linker.

Addresses rdar://problem/34438420.

llvm-svn: 313316
2017-09-14 23:38:44 +00:00
Douglas Gregor 672281a511 Diagnostic specific failed condition in a static_assert.
When a static_assert fails, dig out a specific condition to diagnose,
using the same logic that we use to find the enable_if condition to
diagnose.

llvm-svn: 313315
2017-09-14 23:38:42 +00:00
Matt Morehouse bb26f86e6f [MSan] Add flag to disable use-after-dtor.
Summary: Flag is -fno-sanitize-use-after-dtor.

Reviewers: vitalybuka, eugenis, kcc

Reviewed By: vitalybuka, eugenis

Subscribers: cfe-commits

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

llvm-svn: 313314
2017-09-14 23:14:37 +00:00
Sam Clegg 49581583e2 [WebAssembly] Fix wasm-toolchain.c tests
Summary: This test should have been updated in r313299

Subscribers: jfb, dschuff, jgravelle-google, aheejin

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

llvm-svn: 313307
2017-09-14 22:36:44 +00:00
Piotr Padlewski 45761a6950 Enable __declspec(selectany) on any platform
Summary:
This feature was disabled probably by mistake in rL300562
This fixes bug https://bugs.llvm.org/show_bug.cgi?id=33285

Reviewers: davide, rnk

Subscribers: cfe-commits

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

llvm-svn: 313278
2017-09-14 17:33:08 +00:00
Zachary Turner a0e55b6403 [lit] Force site configs to be run before source-tree configs
This patch simplifies LLVM's lit infrastructure by enforcing an ordering
that a site config is always run before a source-tree config.

A significant amount of the complexity from lit config files arises from
the fact that inside of a source-tree config file, we don't yet know if
the site config has been run.  However it is *always* required to run
a site config first, because it passes various variables down through
CMake that the main config depends on.  As a result, every config
file has to do a bunch of magic to try to reverse-engineer the location
of the site config file if they detect (heuristically) that the site
config file has not yet been run.

This patch solves the problem by emitting a mapping from source tree
config file to binary tree site config file in llvm-lit.py. Then, during
discovery when we find a config file, we check to see if we have a
target mapping for it, and if so we use that instead.

This mechanism is generic enough that it does not affect external users
of lit. They will just not have a config mapping defined, and everything
will work as normal.

On the other hand, for us it allows us to make many simplifications:

* We are guaranteed that a site config will be executed first
* Inside of a main config, we no longer have to assume that attributes
  might not be present and use getattr everywhere.
* We no longer have to pass parameters such as --param llvm_site_config=<path>
  on the command line.
* It is future-proof, meaning you don't have to edit llvm-lit.in to add
  support for new projects.
* All of the duplicated logic of trying various fallback mechanisms of
  finding a site config from the main config are now gone.

One potentially noteworthy thing that was required to implement this
change is that whereas the ninja check targets previously used the first
method to spawn lit, they now use the second. In particular, you can no
longer run lit.py against the source tree while specifying the various
`foo_site_config=<path>` parameters.  Instead, you need to run
llvm-lit.py.

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

llvm-svn: 313270
2017-09-14 16:47:58 +00:00
Alex Lorenz 18633071a3 Fix Refactor/tool-test-support.c test on Windows by avoiding
the STDERR redirect

llvm-svn: 313266
2017-09-14 15:10:39 +00:00
Alex Lorenz 3d712c46e6 [refactor] Use CommonOptionsParser in clang-refactor
This commit ensures that CommonOptionsParser works with subcommands. This allows
clang-refactor to use the CommonOptionsParser.

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

llvm-svn: 313260
2017-09-14 13:16:14 +00:00
Alex Lorenz b54ef6a2a4 [refactor] add clang-refactor tool with initial testing support and
local-rename action

This commit introduces the clang-refactor tool alongside the local-rename action
which uses the existing renaming engine used by clang-rename. The tool
doesn't actually perform the source transformations yet, it just provides
testing support. This commit also moves only one test from clang-rename over to
test/Refactor. I will continue to move the other tests throughout
development of clang-refactor.

The following options are supported by clang-refactor:

-v: use verbose output
-selection: The source range that corresponds to the portion of the source
 that's selected (currently only special command test:<file> is supported).

Please note that a follow-up commit will migrate clang-refactor to
libTooling's common option parser, so clang-refactor will be able to use
the common interface with compilation database and options like -p, -extra-arg,
etc.

The testing support provided by clang-refactor is described below:

When -selection=test:<file> is given, clang-refactor will parse the selection
commands from that file. The selection commands are grouped and the specified
refactoring action invoked by the tool. Each command in a group is expected to
produce an identical result. The precise syntax for the selection commands is
described in a comment in TestSupport.h.

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

llvm-svn: 313244
2017-09-14 10:06:52 +00:00
Peter Collingbourne cb1c5fc93f Use -- to prevent the driver from confusing paths with flags, should fix Mac bot.
llvm-svn: 313201
2017-09-13 21:49:17 +00:00
Adrian McCarthy d91bf3998f Mark static member functions as static in CodeViewDebug
Summary:
To improve CodeView quality for static member functions, we need to make the
static explicit.  In addition to a small change in LLVM's CodeViewDebug to
return the appropriate MethodKind, this requires a small change in Clang to
note the staticness in the debug info metadata.

Subscribers: aprantl, hiraditya

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

llvm-svn: 313192
2017-09-13 20:53:55 +00:00
Alexey Bataev 36f2c4df12 [OPENMP] Fix types for the target specific parameters in debug mode.
Used incorrect types for target specific parameters in debug mode,
should use original pointers rather than the pointee types.

llvm-svn: 313186
2017-09-13 20:20:59 +00:00
Yaxun Liu 1f33d8eb19 Add more tests for OpenCL atomic builtin functions
Add tests for different address spaces and insert some blank lines to make them more readable.

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

llvm-svn: 313172
2017-09-13 18:56:25 +00:00
Yaxun Liu e37793545e [AMDGPU] Change addr space of clk_event_t, queue_t and reserve_id_t to global
Differential Revision: https://reviews.llvm.org/D37703

llvm-svn: 313171
2017-09-13 18:50:42 +00:00
Peter Collingbourne a2fa8e4c46 Driver: Make -fwhole-program-vtables a core option so it can be used from clang-cl.
Also add some missing driver tests for the regular clang driver.

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

llvm-svn: 313169
2017-09-13 18:36:07 +00:00
Sjoerd Meijer c05609ca36 This adds the _Float16 preprocessor macro definitions.
Differential Revision: https://reviews.llvm.org/D34695

llvm-svn: 313152
2017-09-13 15:23:19 +00:00
Alexey Bataev ed94bd9223 [OPENMP] Allow all classes as mappable types.
According to upcoming OpenMP 5.0 all classes/structs are now considered
as mappable, even polymorphic and with static members.

llvm-svn: 313141
2017-09-13 11:12:35 +00:00
Uriel Korach 3fba3c3b0c [X86] [PATCH] [intrinsics] Lowering X86 ABS intrinsics to IR. (clang)
This patch, together with a matching llvm patch (https://reviews.llvm.org/D37693), implements the lowering of X86 ABS intrinsics to IR.

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

llvm-svn: 313133
2017-09-13 09:02:02 +00:00
Martell Malone 9127e849e4 Revert "[Driver] MinGW: Remove custom linker detection"
This reverts rL313102 because it still fails some build bot tests.

On many linux bots it fails with the following error.
error: invalid linker name in argument '-fuse-ld=lld'
and on some windows bots also because there is no ld.lld.exe
lld-link.exe: warning: ignoring unknown argument: -fuse-ld=lld

llvm-svn: 313104
2017-09-13 00:57:50 +00:00
Martell Malone 9a9d4c4c4c [Driver] MinGW: Remove custom linker detection
In rL289668 the ability to specify the default linker at compile time
was added but because the MinGW driver used custom detection we could
not take advantage of this new CMAKE flag CLANG_DEFAULT_LINKER.

This is a re-apply of rL313082 which was reverted in rL313088
due to failing buildbot tests.

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

llvm-svn: 313102
2017-09-13 00:46:54 +00:00
Vedant Kumar d8ab8c2528 [ubsan] Enable -fsanitize=function on Darwin
https://reviews.llvm.org/D37598

llvm-svn: 313099
2017-09-13 00:04:36 +00:00
Vedant Kumar 8e2baf96f0 Tighten up a test case. NFC.
llvm-svn: 313098
2017-09-13 00:04:36 +00:00
Vedant Kumar bb5d485cd3 [ubsan] Function Sanitizer: Don't require writable text segments
This change will make it possible to use -fsanitize=function on Darwin and
possibly on other platforms. It fixes an issue with the way RTTI is stored into
function prologue data.

On Darwin, addresses stored in prologue data can't require run-time fixups and
must be PC-relative. Run-time fixups are undesirable because they necessitate
writable text segments, which can lead to security issues. And absolute
addresses are undesirable because they break PIE mode.

The fix is to create a private global which points to the RTTI, and then to
encode a PC-relative reference to the global into prologue data.

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

llvm-svn: 313096
2017-09-13 00:04:35 +00:00
Martell Malone 079e746814 Revert "[Driver] MinGW: Remove custom linker detection"
This reverts rL313082

llvm-svn: 313088
2017-09-12 22:58:12 +00:00
Vedant Kumar df50259f98 [Driver] Disable uwtable by default in -ffreestanding mode
We make the same decision when compiling the kernel or kexts -- we
should do this in -ffreestanding mode as well to avoid size regressions
in a potentially large set of firmware projects.

It's still possible to get uwtable information in -ffreestanding mode by
compiling with -funwind-tables (I expect this to be a rare case: I
certainly haven't seen any projects like that).

Context: -munwind-tables was enabled by default for some arm targets in
r310006.

Testing: check-clang

rdar://problem/33934446

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

llvm-svn: 313087
2017-09-12 22:51:53 +00:00
Martell Malone 760ad5ce03 [Driver] MinGW: Remove custom linker detection
In rL289668 the ability to specify the default linker at compile time
was added but because the MinGW driver used custom detection we could
not take advantage of this new CMAKE flag CLANG_DEFAULT_LINKER.

llvm-svn: 313082
2017-09-12 22:14:18 +00:00