Commit Graph

68685 Commits

Author SHA1 Message Date
Yaxun Liu 6d96f16347 CodeGen: Cast alloca to expected address space
Alloca always returns a pointer in alloca address space, which may
be different from the type defined by the language. For example,
in C++ the auto variables are in the default address space. Therefore
cast alloca to the expected address space when necessary.

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

llvm-svn: 303370
2017-05-18 18:51:09 +00:00
Alex Lorenz 6796c0b97f [index] Avoid one more crash caused by infinite recursion that happens when
looking up a dependent name in a record that derives from itself

rdar://32273000

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

llvm-svn: 303366
2017-05-18 18:06:07 +00:00
Krzysztof Parzyszek 8f248234fa [CodeGen] Propagate LValueBaseInfo instead of AlignmentSource
The functions creating LValues propagated information about alignment
source. Extend the propagated data to also include information about
possible unrestricted aliasing. A new class LValueBaseInfo will
contain both AlignmentSource and MayAlias info.

This patch should not introduce any functional changes.

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

llvm-svn: 303358
2017-05-18 17:07:11 +00:00
Krasimir Georgiev 9f5608a862 [clang-format] Fix MatchingOpeningBlockLineIndex computation
Summary:
Computed line index must be relative to the current 'parent' node, and
thus use CurrentLines instead of Lines.

Without this, a child line's MatchingOpeningBlockLineIndex is out of
range of the parent's list of line, which can cause crash or unexpected
behavior if this field is used in childs.

Contributed by @Typz!

Reviewers: krasimir, djasper

Reviewed By: krasimir

Subscribers: cfe-commits, klimek

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

llvm-svn: 303353
2017-05-18 15:16:24 +00:00
Alex Lorenz e1e566d4df [index] Record references to class receivers used in property references
rdar://32250025

llvm-svn: 303343
2017-05-18 10:43:11 +00:00
Krasimir Georgiev 994b6c9b8e [clang-format] Make NoLineBreakFormatter respect MustBreakBefore
Summary:
This patch makes NoLineBreakFormatter to insert a break before tokens where
MustBreakBefore is true.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 303332
2017-05-18 08:07:52 +00:00
Krasimir Georgiev ba6b315ea9 clang-format: fix prefix for doxygen comments after member
Summary:
Doxygen supports putting documentation blocks after member, by adding
an additional < marker in the comment block. This patch makes sure
this marker is used in lines which are introduced by breaking the
comment.

  int foo; ///< Some very long comment.

becomes:

  int foo; ///< Some very long
           ///< comment.

Contributed by @Typz!

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: djasper, klimek, cfe-commits

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

llvm-svn: 303330
2017-05-18 07:36:21 +00:00
Alexander Kornienko fd3e39846d Fix an assertion failure in FormatASTNodeDiagnosticArgument.
Summary:
The test being added in this patch used to cause an assertion failure:

/build/./bin/clang -cc1 -internal-isystem /build/lib/clang/5.0.0/include -nostdsysteminc -verify -fsyntax-only -std=c++11 -Wshadow-all /src/tools/clang/test/SemaCXX/warn-shadow.cpp
--
Exit Code: 134

Command Output (stderr):
--
clang: /src/tools/clang/lib/AST/ASTDiagnostic.cpp:424: void clang::FormatASTNodeDiagnosticArgument(DiagnosticsEngine::ArgumentKind, intptr_t, llvm::StringRef, llvm::StringRef, ArrayRef<DiagnosticsEngine::ArgumentValue>, SmallVectorImpl<char> &, void *, ArrayRef<intptr_t>): Assertion `isa<NamedDecl>(DC) && "Expected a NamedDecl"' failed.
#0 0x0000000001c7a1b4 PrintStackTraceSignalHandler(void*) (/build/./bin/clang+0x1c7a1b4)
#1 0x0000000001c7a4e6 SignalHandler(int) (/build/./bin/clang+0x1c7a4e6)
#2 0x00007f30880078d0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0xf8d0)
#3 0x00007f3087054067 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x35067)
#4 0x00007f3087055448 abort (/lib/x86_64-linux-gnu/libc.so.6+0x36448)
#5 0x00007f308704d266 (/lib/x86_64-linux-gnu/libc.so.6+0x2e266)
#6 0x00007f308704d312 (/lib/x86_64-linux-gnu/libc.so.6+0x2e312)
#7 0x00000000035b7f22 clang::FormatASTNodeDiagnosticArgument(clang::DiagnosticsEngine::ArgumentKind, long, llvm::StringRef, llvm::StringRef, llvm::ArrayRef<std::pair<clang::DiagnosticsEngine::ArgumentKind, long> >, llvm::SmallVectorImpl<char>&, void*, llvm::ArrayRef<long>) (/build/
./bin/clang+0x35b7f22)
#8 0x0000000001ddbae4 clang::Diagnostic::FormatDiagnostic(char const*, char const*, llvm::SmallVectorImpl<char>&) const (/build/./bin/clang+0x1ddbae4)
#9 0x0000000001ddb323 clang::Diagnostic::FormatDiagnostic(char const*, char const*, llvm::SmallVectorImpl<char>&) const (/build/./bin/clang+0x1ddb323)
#10 0x00000000022878a4 clang::TextDiagnosticBuffer::HandleDiagnostic(clang::DiagnosticsEngine::Level, clang::Diagnostic const&) (/build/./bin/clang+0x22878a4)
#11 0x0000000001ddf387 clang::DiagnosticIDs::ProcessDiag(clang::DiagnosticsEngine&) const (/build/./bin/clang+0x1ddf387)
#12 0x0000000001dd9dea clang::DiagnosticsEngine::EmitCurrentDiagnostic(bool) (/build/./bin/clang+0x1dd9dea)
#13 0x0000000002cad00c clang::Sema::EmitCurrentDiagnostic(unsigned int) (/build/./bin/clang+0x2cad00c)
#14 0x0000000002d91cd2 clang::Sema::CheckShadow(clang::NamedDecl*, clang::NamedDecl*, clang::LookupResult const&) (/build/./bin/clang+0x2d91cd2)

Stack dump:
0.      Program arguments: /build/./bin/clang -cc1 -internal-isystem /build/lib/clang/5.0.0/include -nostdsysteminc -verify -fsyntax-only -std=c++11 -Wshadow-all /src/tools/clang/test/SemaCXX/warn-shadow.cpp
1.      /src/tools/clang/test/SemaCXX/warn-shadow.cpp:214:23: current parser token ';'
2.      /src/tools/clang/test/SemaCXX/warn-shadow.cpp:213:26: parsing function body 'handleLinkageSpec'
3.      /src/tools/clang/test/SemaCXX/warn-shadow.cpp:213:26: in compound statement ('{}')
/build/tools/clang/test/SemaCXX/Output/warn-shadow.cpp.script: line 1: 15595 Aborted                 (core dumped) /build/./bin/clang -cc1 -internal-isystem /build/lib/clang/5.0.0/include -nostdsysteminc -verify -fsyntax-only -std=c++11 -Wshadow-all /src/tools/clang/test/SemaCXX/warn-shadow.cpp

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: krytarowski, cfe-commits

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

llvm-svn: 303325
2017-05-18 03:02:15 +00:00
Richard Smith 54f0440c1f [modules] Switch from inferring owning modules based on source location to
inferring based on the current module at the point of creation.

This should result in no functional change except when building a preprocessed
module (or more generally when using #pragma clang module begin/end to switch
module in the middle of a file), in which case it allows us to correctly track
the owning module for declarations. We can't map from FileID to module in the
preprocessed module case, since all modules would have the same FileID.

There are still a couple of remaining places that try to infer a module from a
source location; I'll clean those up in follow-up changes.

llvm-svn: 303322
2017-05-18 02:29:20 +00:00
Craig Topper 704b4fbbf6 [Statistics] Use the new Statistic::updateMax to atomically calculate a maximum value statistic.
llvm-svn: 303320
2017-05-18 01:11:52 +00:00
Nick Lewycky 9add1594d2 The constant expression evaluator should examine function arguments for non-constexpr function calls unless the EvalInfo says to stop.
llvm-svn: 303317
2017-05-17 23:56:54 +00:00
Hans Wennborg 6dc120a41d clang-cl: Fix path-based MSVC version detection
The code wasn't taking the architecture-specific subdirectory into
account.

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

llvm-svn: 303267
2017-05-17 15:27:44 +00:00
Krasimir Georgiev 1f64bf6c69 [Frontend] Remove unused TemporaryFiles
Summary:
OnDiskData.TemporaryFiles is filled only by ASTUnit::addTemporaryFile, which is
dead. Also these files are used nowhere in the frontend nor in libclang.

Reviewers: bkramer, ilya-biryukov

Reviewed By: bkramer, ilya-biryukov

Subscribers: cfe-commits

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

llvm-svn: 303265
2017-05-17 14:51:44 +00:00
Vassil Vassilev da7c45468f Constify.
llvm-svn: 303250
2017-05-17 12:09:11 +00:00
Alex Lorenz d47546612d [Lexer] Ensure that the token is not an annotation token when
retrieving the identifer info for an Objective-C keyword

This commit fixes an assertion that's triggered in getIdentifier when the token
is an annotation token.

rdar://32225463

llvm-svn: 303246
2017-05-17 11:08:36 +00:00
Richard Trieu ce81b194a0 [ODRHash] Support NestedNameSpecifier
llvm-svn: 303233
2017-05-17 03:23:35 +00:00
Richard Trieu 58bb7bd18a [ODRHash] Support more types in the ODR checker.
Added support for TagType, TypeWithKeyword, and all children types.

llvm-svn: 303231
2017-05-17 02:29:02 +00:00
Ekaterina Romanova bfc1e3a84e (1) Fixed mismatch in intrinsics names in declarations and in doxygen comments.
(2) Removed uncessary anymore \c commands, since the same effect will be achived by <c> ... </c> sequence. 

I got an OK from Eric Christopher to commit doxygen comments without prior code
review upstream.

llvm-svn: 303228
2017-05-17 01:46:11 +00:00
Richard Smith 26342f915b [modules] When creating a declaration, cache its owning module immediately
rather than waiting until it's queried.

Currently this is only applied to local submodule visibility mode, as we don't
yet allocate storage for the owning module in non-local-visibility modules
compilations.


This reinstates r302965, reverted in r303037, with a fix for the reported
crash, which occurred when reparenting a local declaration to be a child of
a hidden imported declaration (specifically during template instantiation).

llvm-svn: 303224
2017-05-17 00:24:14 +00:00
Adrian Prantl 6fc8875739 Fix scope of namespaced DISubprograms when the function definition is out-of-line.
This fixes a regression introduced in r302915.

Using the lexical decl context is not necessary here for what r302915
wast trying to achieve. Not canonicalizing the NamespaceDecl in
getOrCreateNamespace is suficient.

rdar://problem/29339538

llvm-svn: 303222
2017-05-16 23:46:10 +00:00
Alex Lorenz d2b8aaa05a [index] Avoid another crash that happens when looking up a dependent name
in a record that has a base without a definition

rdar://32224197

llvm-svn: 303192
2017-05-16 17:33:17 +00:00
Alex Lorenz 6f91112051 [Sema] Avoid duplicate -Wunguarded-availability warnings in nested functions
rdar://31862310

llvm-svn: 303170
2017-05-16 13:58:53 +00:00
Peter Szecsi 32134db1a1 [StaticAnalyzer] Move inline counter increaser to inlineCall function
Even though the shouldInlineCall function returns true, it can happen that the
function is not going to be inlined (as it can be seen at line 913 and below).
Moved the bumpNumTimesInlined(D) (the counter increaser) call to the inlineCall
function where it logically belongs.

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

llvm-svn: 303158
2017-05-16 11:54:00 +00:00
Alex Lorenz de69ff9b7c Fix PR 10758: Infinite recursion when dealing with copy-initialization
This commit fixes a bug that's tracked by PR 10758 and duplicates like PR 30343.
The bug causes clang to crash with a stack overflow while recursing infinitely
trying to perform copy-initialization on a type without a copy constructor but
with a constructor that accepts another type that can be constructed using the
original type.

The commit fixes this bug by detecting the recursive behavior and failing
correctly with an appropriate error message. It also tries to provide a
meaningful diagnostic note about the constructor which leads to this behavior.

rdar://28483944

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

llvm-svn: 303156
2017-05-16 10:23:58 +00:00
Vitaly Buka dcac9f51d8 [Sema] Use CK_NoOp instead CK_Invalid in tryGCCVectorConvertAndSplat
This fix UBSAN bots after r302935. Storing non-defined values in enum is
undefined behavior.

Other places, where "if (ScalarCast != CK_Invalid)" is used, never get to the
"if" with CK_Invalid. tryGCCVectorConvertAndSplat can get to the "if" with
CK_Invalid and it looks like expected case. So we have to use something other
than CK_Invalid, e.g. CK_NoOp.

llvm-svn: 303121
2017-05-15 22:04:03 +00:00
Evgeniy Stepanov 5c3e07f78d [asan] One more test for -fsanitize-address-globals-dead-stripping.
llvm-svn: 303114
2017-05-15 20:43:48 +00:00
Martin Probst bd49e321d3 clang-format: [JS] for async loops.
Summary:
JavaScript supports asynchronous loop iteration in async functions:

    for async (const x of y) ...

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 303106
2017-05-15 19:33:20 +00:00
Alexey Bataev 2c84541a21 [OPENMP] Check DSA for variables captured by value.
Currently clang checks for default data sharing attributes only for
variables captured in OpenMP regions by reference. Patch adds checks for
variables captured by value.

llvm-svn: 303077
2017-05-15 16:26:15 +00:00
Yaxun Liu 4f33b3d396 [OpenCL] Emit function-scope variable in constant address space as static variable
Differential Revision: https://reviews.llvm.org/D32977

llvm-svn: 303072
2017-05-15 14:47:47 +00:00
Alex Lorenz 048c8a9e7f [index] References to fields from template instantiations should refer to
fields in base templates

rdar://32197158

llvm-svn: 303068
2017-05-15 14:26:22 +00:00
Martin Probst 2c1cdae2df JavaScript allows parameter lists to include trailing commas:
myFunction(param1, param2,);

For symmetry with other parenthesized lists ([...], {...}), clang-format should
wrap parenthesized lists one-per-line if they contain a trailing comma:

    myFunction(
        param1,
        param2,
    );

This is particularly useful in function declarations or calls with many
arguments, e.g. commonly in constructors.

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

llvm-svn: 303049
2017-05-15 11:15:29 +00:00
Alex Lorenz 4ab5193735 [index] Visit and store information about namespace alias declarations
rdar://32195226

llvm-svn: 303048
2017-05-15 10:56:31 +00:00
Alex Lorenz 57c4f648d1 [index] Store correct location for namespace nested name qualifiers
rdar://32195200

llvm-svn: 303046
2017-05-15 10:41:04 +00:00
Alex Lorenz 09653330bc [index] Avoid a crash that happens when looking up a dependent name
in a record that has no definition

rdar://32194921

llvm-svn: 303045
2017-05-15 10:20:39 +00:00
Martin Probst 82b3d906bc clang-format: [JS] fix non-null assertion operator recognition.
Summary:
`getIdentifierInfo()` includes all keywords, whereas non-null assertion
operators should only be recognized after non-keywords or pseudo keywords.
Ideally this should list all tokens that clang-format recognizes as a keyword,
but that are pseudo or no keywords in JS. For the time being, just recognize
the specific bits users ran into (`namespace` in this case).

Reviewers: djasper

Subscribers: klimek

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

llvm-svn: 303038
2017-05-15 08:15:53 +00:00
Daniel Jasper 89f9ad8636 Revert r302965 - [modules] When creating a declaration, cache its owning
module immediately

Also revert dependent r302969. This is leading to crashes.
Will provide more details reproduction instructions to Richard.

llvm-svn: 303037
2017-05-15 07:51:10 +00:00
Ekaterina Romanova 1d4a0f270c [DOXYGEN] Minor improvements in doxygen comments.
Separated very long brief sections into two sections. 

I got an OK from Eric Christopher to commit doxygen comments without prior code
review upstream.

llvm-svn: 303031
2017-05-15 03:25:04 +00:00
Faisal Vali 718b7457e8 Silence buildbots by tweaking an IR codegen test to be less specific w register names.
llvm-svn: 303030
2017-05-15 02:56:02 +00:00
Faisal Vali c3dbd7f270 [NFC] Remove some comments (IR aid) from a test file erroneous committed in r303026
llvm-svn: 303027
2017-05-15 01:54:02 +00:00
Faisal Vali 1ca2d9679b Fix PR32933: crash on lambda capture of VLA
https://bugs.llvm.org/show_bug.cgi?id=32933

Turns out clang wasn't really handling vla's (*) in C++11's for-range entirely correctly. 

For e.g. This would lead to generation of buggy IR:

  void foo(int b) {
    int vla[b];
    b = -1;  // This store would affect the '__end = vla + b'
    for (int &c : vla) 
      c = 0;
  }

Additionally, code-gen would get confused when VLA's were reference-captured by lambdas, and then used in a for-range, which would result in an attempt to generate IR for '__end = vla + b' within the lambda's body - without any capture of 'b' - hence the assertion.

This patch modifies clang, so that for VLA's it translates the end pointer approximately into:
  __end = __begin + sizeof(vla)/sizeof(vla->getElementType())

As opposed to the __end = __begin + b;

I considered passing a magic value into codegen - or having codegen special case the '__end' variable when it referred to a variably-modified type, but I decided against that approach, because it smelled like I would be increasing a complicated form of coupling, that I think would be even harder to maintain than the above approach (which can easily be optimized (-O1) to refer to the run-time bound that was calculated upon array's creation or copied into the lambda's closure object).


(*) why oh why gcc would you enable this by default?! ;)

llvm-svn: 303026
2017-05-15 01:49:19 +00:00
Sean Callanan 9092d4795d [ASTImporter] Improve handling of incomplete types
ASTImporter has some bugs when it's importing types 
that themselves come from an ExternalASTSource. This 
is exposed particularly in the behavior when 
comparing complete TagDecls with forward 
declarations. This patch does several things:

- Adds a test case making sure that conflicting 
  forward-declarations are resolved correctly;
- Extends the clang-import-test harness to test 
  two-level importing, so that we make sure we 
  complete types when necessary; and
- Fixes a few bugs I found this way. Failure to 
  complete types was one; however, I also discovered 
  that complete RecordDecls aren't properly added to 
  the redecls chain for existing forward 
  declarations.

llvm-svn: 302975
2017-05-13 00:46:33 +00:00
Richard Smith 3533397a3a Add LangOptions method to query whether we are tracking the owning module for a local declaration.
In preparation for expanding this behavior to cover additional cases.

llvm-svn: 302969
2017-05-13 00:00:16 +00:00
Richard Smith 3f6dd7a86c Remove unused tracking of owning module for MacroInfo objects.
llvm-svn: 302966
2017-05-12 23:40:52 +00:00
Richard Smith fc8c57cc5b [modules] When creating a declaration, cache its owning module immediately
rather than waiting until it's queried.

Currently this is only applied to local submodule visibility mode, as we don't
yet allocate storage for the owning module in non-local-visibility modules
compilations.

llvm-svn: 302965
2017-05-12 23:27:00 +00:00
Richard Smith 483d74c7ee Revert r302932, as it appears to be breaking stage2 for some of our modules-enabled buildbots.
llvm-svn: 302947
2017-05-12 20:42:54 +00:00
Simon Dardis e94124804e [Sema] Silence buildbot failures introduced by r302935
Attempt to silence buildbot failures by pinning the test to a given
triple rather than the host's triple.

llvm-svn: 302941
2017-05-12 19:55:32 +00:00
Teresa Johnson 517729fb20 Remove ignore-empty-index-file option
Summary:
Clang changes to remove this option and replace with a parameter
always set in the context of a ThinLTO distributed backend.

Depends on D33133.

Reviewers: pcc

Subscribers: mehdi_amini, eraman, cfe-commits

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

llvm-svn: 302940
2017-05-12 19:32:17 +00:00
Simon Dardis 7cd5876e60 [Sema] Support implicit scalar to vector conversions
This patch teaches clang to perform implicit scalar to vector conversions
when one of the operands of a binary vector expression is a scalar which
can be converted to the element type of the vector without truncation
following GCC's implementation.

If the (constant) scalar is can be casted safely, it is implicitly casted to the
vector elements type and splatted to produce a vector of the same type.

Contributions from: Petar Jovanovic

Reviewers: bruno, vkalintiris

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

llvm-svn: 302935
2017-05-12 19:11:06 +00:00
Richard Smith d58e2d951e [modules] Simplify module macro handling in non-local-submodule-visibility mode.
When reaching the end of a module, we used to convert its macros to
ModuleMacros but also leave them in the MacroDirective chain for the
identifier. This meant that every lookup of such a macro would find two
(identical) definitions. It also made it difficult to determine the correct
owner for a macro when reaching the end of a module: the most recent
MacroDirective in the chain could be from an #included submodule rather than
the current module.

Simplify this: whenever we convert a MacroDirective to a ModuleMacro when
leaving a module, clear out the MacroDirective chain for that identifier, and
just rely on the ModuleMacro to provide the macro definition information.

(We don't want to do this for local submodule visibility mode, because in that
mode we maintain a distinct MacroDirective chain for each submodule, and we
need to keep around the prior MacroDirective in case we re-enter the submodule
-- for instance, if its header is #included more than once in a module build,
we need the include guard directive to stick around. But the problem doesn't
arise in this case for the same reason: each submodule has its own
MacroDirective chain, so the macros don't leak out of submodules in the first
place.)

llvm-svn: 302932
2017-05-12 18:56:03 +00:00
Alex Lorenz d43f75b54a [index] Index template specialization arguments for function templats
Also ensure that class template specialization arguments are covered

rdar://31812032

llvm-svn: 302918
2017-05-12 16:32:26 +00:00