Commit Graph

48855 Commits

Author SHA1 Message Date
Bob Haarman c6c9b8fa1f [codeview] omit debug locations for nested exprs unless column info enabled
Summary:
Microsoft Visual Studio expects debug locations to correspond to
statements. We used to emit locations for expressions nested inside statements.
This would confuse the debugger, causing it to stop multiple times on the
same line and breaking the "step into specific" feature. This change inhibits
the emission of debug locations for nested expressions when emitting CodeView
debug information, unless column information is enabled.

Fixes PR34312.

Reviewers: rnk, zturner

Reviewed By: rnk

Subscribers: majnemer, echristo, aprantl, cfe-commits

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

llvm-svn: 312965
2017-09-11 22:11:57 +00:00
Vedant Kumar f56f77f5c8 [Driver] Support ubsan-minimal on Darwin
Make it possible to use the minimal ubsan runtime on Darwin.

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

llvm-svn: 312958
2017-09-11 21:37:06 +00:00
Vedant Kumar 3919a501f3 [Lexer] Report more precise skipped regions (PR34166)
This patch teaches the preprocessor to report more precise source ranges for
code that is skipped due to conditional directives.

The new behavior includes the '#' from the opening directive and the full text
of the line containing the closing directive in the skipped area. This matches
up clang's behavior (we don't IRGen the code between the closing "endif" and
the end of a line).

This also affects the code coverage implementation. See llvm.org/PR34166 (this
also happens to be rdar://problem/23224058).

The old behavior (report the end of the skipped range as the end
location of the 'endif' token) is preserved for indexing clients.

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

llvm-svn: 312947
2017-09-11 20:47:42 +00:00
Miklos Vajna bf0d49c437 clang-rename: let -force handle multiple renames
Summary:
The use case is that renaming multiple symbols in a large enough codebase is
much faster if all of these can be done with a single invocation, but
there will be multiple translation units where one or more symbols are
not found.

Old behavior was to exit with an error (default) or exit without
reporting an error (-force). New behavior is that -force results in a
best-effort rename: rename symbols which are found and just ignore the
rest.

The existing help for -force sort of already implies this behavior.

Reviewers: cfe-commits, klimek, arphaman

Reviewed By: klimek

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

llvm-svn: 312942
2017-09-11 20:18:38 +00:00
Saleem Abdulrasool 015bded23f Driver: default to `-fno-use-cxatexit` on Windows
This primarily impacts the Windows MSVC and Windows itanium
environments.  Windows MSVC does not use `__cxa_atexit` and Itanium
follows suit.  Simplify the logic for the default value calculation and
blanket the Windows environments to default to off for use of
`__cxa_atexit`.

llvm-svn: 312941
2017-09-11 20:18:09 +00:00
Martin Probst 103a7b5bbb clang-format: [JS] wrap and indent `goog.setTestOnly` calls.
Summary:
While `goog.setTestOnly` usually appears in the imports section of a file, it is
not actually an import, and also usually doesn't take long parameters (nor
namespaces as a parameter, it's a description/message that should be wrapped).

This fixes a regression where a `goog.setTestOnly` call nested in a function was
not wrapped.

Reviewers: djasper

Subscribers: klimek

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

llvm-svn: 312918
2017-09-11 15:22:52 +00:00
Cameron Desrochers b5b48db12e [PCH] Allow VFS to be used for tests that generate PCH files
When using a virtual file-system (VFS) and a preamble file (PCH) is generated,
it is generated on-disk in the real file-system instead of in the VFS (which
makes sense, since the VFS is read-only). However, when subsequently reading
the generated PCH, the frontend passes through the VFS it has been given --
resulting in an error and a failed parse (since the VFS doesn't contain the
PCH; the real filesystem does).

This patch fixes that by detecting when a VFS is being used for a parse that
needs to work with a PCH file, and creating an overlay VFS that includes the
PCH file from the real file-system.

This allows tests to be written which make use of both PCH files and a VFS.

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

llvm-svn: 312917
2017-09-11 15:03:23 +00:00
Krasimir Georgiev 3b0b50bac5 [clang-format] Fixed one-line if statement
Summary:
**Short overview:**

Fixed bug: https://bugs.llvm.org/show_bug.cgi?id=34001
Clang-format bug resulting in a strange behavior of control statements short blocks. Different flags combinations do not guarantee expected result. Turned on option AllowShortBlocksOnASingleLine does not work as intended.

**Description of the problem:**

Cpp source file UnwrappedLineFormatter does not handle AllowShortBlocksOnASingleLine flag as it should. Putting a single-line control statement without any braces, clang-format works as expected (depending on AllowShortIfStatementOnASingleLine or AllowShortLoopsOnASingleLine value). Putting a single-line control statement in braces, we can observe strange and incorrect behavior.
Our short block is intercepted by tryFitMultipleLinesInOne function. The function returns a number of lines to be merged. Unfortunately, our control statement block is not covered properly. There are several if-return statements, but none of them handles our block. A block is identified by the line first token and by left and right braces. A function block works as expected, there is such an if-return statement doing proper job. A control statement block, from the other hand, falls into strange conditional construct, which depends on BraceWrapping.AfterFunction flag (with condition that the line’s last token is left brace, what is possible in our case) or goes even further. That should definitely not happen.

**Description of the patch:**

By adding three different if statements, we guarantee that our short control statement block, however it looks like (different brace wrapping flags may be turned on), is handled properly and does not fall into wrong conditional construct. Depending on appropriate options we return either 0 (when something disturbs our merging attempt) or let another function (tryMergeSimpleBlock) take the responsibility of returned result (number of merged lines). Nevertheless, one more correction is required in mentioned tryMergeSimpleBlock function. The function, previously, returned either 0 or 2. The problem was that this did not handle the case when our block had the left brace in a separate line, not the header one. After change, after adding condition, we return the result compatible with block’s structure. In case of left brace in the header’s line we do everything as before the patch. In case of left brace in a separate line we do the job similar to the one we do in case of a “non-header left brace” function short block. To be precise, we try to merge the block ignoring the header line. Then, if success, we increment our returned result.

**After fix:**

**CONFIG:**
```
AllowShortBlocksOnASingleLine: true
AllowShortIfStatementsOnASingleLine: true
BreakBeforeBraces: Custom
BraceWrapping: {
AfterClass: true, AfterControlStatement: true, AfterEnum: true, AfterFunction: true, AfterNamespace: false, AfterStruct: true, AfterUnion: true, BeforeCatch: true, BeforeElse: true
}
```
**BEFORE:**
```
if (statement) doSomething();
if (statement) { doSomething(); }
if (statement) {
    doSomething();
}
if (statement)
{
    doSomething();
}
if (statement)
    doSomething();
if (statement) {
    doSomething1();
    doSomething2();
}
```
**AFTER:**
```
if (statement) doSomething();
if (statement) { doSomething(); }
if (statement) { doSomething(); }
if (statement) { doSomething(); }
if (statement) doSomething();
if (statement)
{
  doSomething1();
  doSomething2();
}
```

Contributed by @PriMee!

Reviewers: krasimir, djasper

Reviewed By: krasimir

Subscribers: cfe-commits, klimek

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

llvm-svn: 312904
2017-09-11 10:12:16 +00:00
Daniel Jasper 7af729b3d2 Revert r312830: "Reinstall the patch "Use EmitPointerWithAlignment to get alignment information of the pointer used in atomic expr"."
This triggers llvm.org/PR31620 in several of our internal builds. I'll
forward reproduction instructions to the original author.

llvm-svn: 312897
2017-09-11 07:35:01 +00:00
Dave Lee e6d362cea8 Add objcImplementationDecl matcher
Summary:
Add the `objcImplementationDecl` matcher. See related: D30854

Tested with:

```
./tools/clang/unittests/ASTMatchers/ASTMatchersTests
```

Reviewers: aaron.ballman, compnerd, alexshap

Reviewed By: aaron.ballman

Subscribers: klimek, cfe-commits

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

llvm-svn: 312889
2017-09-10 21:00:15 +00:00
Coby Tayree 18f9218689 [clang][SemaStmtAsm] small refactoring, NFC.
llvm-svn: 312882
2017-09-10 12:39:21 +00:00
Nuno Lopes 9211ceef2d clang fix for LLVM API change: isKnownNonNull -> isKnownNonZero
Differential Revision: https://reviews.llvm.org/D37628

llvm-svn: 312870
2017-09-09 18:25:36 +00:00
MinSeong Kim 7c2556a895 [Basic] Update CMakeLists.txt to handle repo
Summary:
The find_first_existing_file and find_first_existing_vc_file macros in
lib/Basic/CMakeLists.txt are removed. The macros are also defined in
{LLVM}/cmake/modules/AddLLVM.cmake for the same purpose. This change
serves the following 2 objectives:

    1. To remove the redundant code in clang to use the same
       macros in llvm,
    2. The macros in AddLLVM.cmake can also handle repo for
       displaying correct version information.

Reviewers: jordan_rose, cfe-commits, modocache, hintonda

Reviewed By: hintonda

Subscribers: mgorny

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

llvm-svn: 312865
2017-09-09 14:18:53 +00:00
Richard Smith 6d9bc278ef Fix ownership of the MemoryBuffer in a FrontendInputFile.
This fixes a possible crash on certain kinds of corrupted AST file, but
checking in an AST file corrupted in just the right way will be a maintenance
nightmare because the format changes frequently.

llvm-svn: 312851
2017-09-09 01:14:04 +00:00
Richard Trieu 285c93666b Catch more cases with -Wenum-compare
Treat typedef enum as named enums instead of anonymous enums.  Anonymous enums
are ignored by the warning, so previously, typedef enums were ignored as well.

llvm-svn: 312842
2017-09-09 00:25:05 +00:00
Saleem Abdulrasool 94bb1a06fb CodeGen: correct arguments for NSFastEnumeration
When performing a NSFastEnumeration, the compiler synthesizes a call to
`countByEnumeratingWithState:objects:count:` where the `count` parameter
is of type `NSUInteger` and the return type is a `NSUInteger`.  We would
previously always use a `UnsignedLongTy` for the `NSUInteger` type.  On
32-bit targets, `long` is 32-bits which is the same as `unsigned int`.
Most 64-bit targets are LP64, where `long` is 64-bits.  However, on
LLP64 targets, such as Windows, `long` is 32-bits.  Introduce new
`getNSUIntegerType` and `getNSIntegerType` helpers to allow us to
determine the correct type for the `NSUInteger` type.  Wire those
through into the generation of the message dispatch to the selector.

llvm-svn: 312835
2017-09-08 23:41:17 +00:00
Wei Mi 015a484fe2 Reinstall the patch "Use EmitPointerWithAlignment to get alignment information of the pointer used in atomic expr".
This is to fix PR34347. EmitAtomicExpr now only uses alignment information from
Type, instead of Decl, so when the declaration of an atomic variable is marked
to have the alignment equal as its size, EmitAtomicExpr doesn't know about it and
will generate libcall instead of atomic op. The patch uses EmitPointerWithAlignment
to get the precise alignment information.

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

llvm-svn: 312830
2017-09-08 21:58:18 +00:00
Vedant Kumar 747b0e2905 [Coverage] Precise region termination with deferred regions (reapply)
The current coverage implementation doesn't handle region termination
very precisely. Take for example an `if' statement with a `return':

  void f() {
    if (true) {
      return; // The `if' body's region is terminated here.
    }
    // This line gets the same coverage as the `if' condition.
  }

If the function `f' is called, the line containing the comment will be
marked as having executed once, which is not correct.

The solution here is to create a deferred region after terminating a
region. The deferred region is completed once the start location of the
next statement is known, and is then pushed onto the region stack.
In the cases where it's not possible to complete a deferred region, it
can safely be dropped.

Testing: lit test updates, a stage2 coverage-enabled build of clang

This is a reapplication but there are no changes from the original commit.
With D36813, the segment builder in llvm will be able to handle deferred
regions correctly.

llvm-svn: 312818
2017-09-08 18:44:56 +00:00
Wei Mi c8c7cfc2bd Revert rL312801 since it generated some calls from libatomic and broke some tests.
llvm-svn: 312805
2017-09-08 18:10:13 +00:00
Wei Mi 3420ae489c Use EmitPointerWithAlignment to get alignment information of the pointer used in atomic expr.
This is to fix PR34347. EmitAtomicExpr now only uses alignment information from
Type, instead of Decl, so when the declaration of an atomic variable is marked
to have the alignment equal as its size, EmitAtomicExpr doesn't know about it and
will generate libcall instead of atomic op. The patch uses EmitPointerWithAlignment
to get the precise alignment information.

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

llvm-svn: 312801
2017-09-08 17:07:32 +00:00
Sjoerd Meijer cc623ad071 Recommit "Add _Float16 as a C/C++ source language type"
This is a recommit of r312781; in some build configurations
variable names are omitted, so changed the new regression
test accordingly.

llvm-svn: 312794
2017-09-08 15:15:00 +00:00
Krasimir Georgiev 46dfb7a39d Updated two annotations for Store.h and CodeGenFunction.h.
Summary:
1.Updated annotations for include/clang/StaticAnalyzer/Core/PathSensitive/Store.h, which belong to the old version of clang.
2.Delete annotations for CodeGenFunction::getEvaluationKind() in clang/lib/CodeGen/CodeGenFunction.h, which belong to the old version of clang.

Reviewers: bkramer, krasimir, klimek

Reviewed By: bkramer

Subscribers: MTC

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

Contributed by @MTC!

llvm-svn: 312790
2017-09-08 13:44:51 +00:00
Ilya Biryukov cbea95dd95 Fixed a crash in code completion.
Summary: The crash occured when FunctionDecl was parsed with an initializer.

Reviewers: bkramer, klimek, francisco.lopes

Reviewed By: bkramer

Subscribers: cfe-commits

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

llvm-svn: 312788
2017-09-08 13:36:38 +00:00
Erik Verbruggen 7ec9107fdc Don't show deleted function (constructor) candidates for code completion
In case of copy constructor is implicitly deleted it's still shown.
PR34402 describes a way to reproduce that.

Patch by Ivan Donchevskii!

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

llvm-svn: 312785
2017-09-08 10:23:08 +00:00
Sjoerd Meijer 9aeedde7ff Revert "Add _Float16 as a C/C++ source language type"
The clang-with-lto-ubuntu bot didn't like the new regression
test, revert while I investigate the issue.

llvm-svn: 312784
2017-09-08 10:20:52 +00:00
Sjoerd Meijer ab36f33db8 Add _Float16 as a C/C++ source language type
This adds _Float16 as a source language type, which is a 16-bit floating point
type defined in C11 extension ISO/IEC TS 18661-3.

In follow up patches documentation and more tests will be added.

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

llvm-svn: 312781
2017-09-08 09:42:32 +00:00
Erik Verbruggen 51ee12a9fb Fix templated type alias completion when using global completion cache
When we have enabled cache for global completions we did not have
diagnostics for Bar and could not complete Ba as in provided code
example.

template <typename T>
struct Foo { T member; };

template<typename T> using Bar = Foo<T>;

int main() {
   Ba
}

(This is the fixed version of r 311442, which was reverted in r311445.)

Patch by Ivan Donchevskii!

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

llvm-svn: 312780
2017-09-08 09:31:13 +00:00
Roman Lebedev 6aa34aadd1 [Sema] -Wtautological-compare: handle comparison of unsigned with 0S.
Summary:
This is a first half(?) of a fix for the following bug:
https://bugs.llvm.org/show_bug.cgi?id=34147 (gcc -Wtype-limits)

GCC's -Wtype-limits does warn on comparison of unsigned value
with signed zero (as in, with 0), but clang only warns if the
zero is unsigned (i.e. 0U).

Also, be careful not to double-warn, or falsely warn on
comparison of signed/fp variable and signed 0.

Yes, all these testcases are needed.

Testing: $ ninja check-clang-sema check-clang-semacxx
Also, no new warnings for clang stage-2 build.

Reviewers: rjmccall, rsmith, aaron.ballman

Reviewed By: rjmccall

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 312750
2017-09-07 22:14:25 +00:00
Jonathan Roelofs 6fbb9e017d Fix validation of the -mthread-model flag in the Clang driver
The ToolChain class validates the -mthread-model flag in the constructor which
doesn't work correctly since the thread model methods are virtual methods. The
check is moved into Clang::ConstructJob() when constructing the internal
command line.

https://reviews.llvm.org/D37496

Patch by: Ian Tessier!

llvm-svn: 312748
2017-09-07 22:01:25 +00:00
Richard Smith b8c419085f Add IDNS_Tag to C++ declarations that conflict with tag declarations.
Fixes some accepts-invalids with tags and other declarations declared in the
same scope.

llvm-svn: 312743
2017-09-07 20:22:00 +00:00
Jan Vesely 31ecb4bf60 [OpenCL] Add half load and store builtins
This enables load/stores of half type, without half being a legal type.

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

llvm-svn: 312742
2017-09-07 19:39:10 +00:00
Justin Lebar 78137ec868 [CUDA] When compilation fails, print the compilation mode.
Summary:
That is, instead of "1 error generated", we now say "1 error generated
when compiling for sm_35".

This (partially) solves a usability foogtun wherein e.g. users call a
function that's only defined on sm_60 when compiling for sm_35, and they
get an unhelpful error message.

Reviewers: tra

Subscribers: sanjoy, cfe-commits

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

llvm-svn: 312736
2017-09-07 18:37:16 +00:00
Artem Belevich 8af4e23d1e [CUDA] Added rudimentary support for CUDA-9 and sm_70.
For now CUDA-9 is not included in the list of CUDA versions clang
searches for, so the path to CUDA-9 must be explicitly passed
via --cuda-path=.

On LLVM side NVPTX added sm_70 GPU type which bumps required
PTX version to 6.0, but otherwise is equivalent to sm_62 at the moment.

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

llvm-svn: 312734
2017-09-07 18:14:32 +00:00
Anastasia Stulova 257132a019 [OpenCL] Handle taking an address of block captures.
Block captures can have different physical locations
in memory segments depending on the use case (as a function
call or as a kernel enqueue) and in different vendor
implementations.

Therefore it's unclear how to add address space to capture
addresses uniformly. Currently it has been decided to disallow
taking addresses of captured variables until further
clarifications in the spec.

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

llvm-svn: 312728
2017-09-07 17:00:33 +00:00
Marek Kurdej ceeb8b91e7 [clang-format] Add support for C++17 structured bindings.
Summary:
Before:
```
    auto[a, b] = f();
```

After:
```
    auto [a, b] = f();
```
or, if SpacesInSquareBrackets is true:
```
    auto [ a, b ] = f();
```

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 312723
2017-09-07 14:28:32 +00:00
Richard Smith 1363e8f6ed P0702R1: in class template argument deduction from a list of one element, if
that element's type is (or is derived from) a specialization of the deduced
template, skip the std::initializer_list special case.

llvm-svn: 312703
2017-09-07 07:22:36 +00:00
Simon Atanasyan cfad9d5f0f [mips] Replace Triple::Environment check by the isGNUEnvironment() call. NFC
llvm-svn: 312701
2017-09-07 06:05:06 +00:00
Richard Smith 48b35d9a14 Fix off-by-one error in block mangling.
This restores the ABI prior to r214699.

llvm-svn: 312700
2017-09-07 05:41:24 +00:00
Richard Smith cd4a7a461f [modules ts] Ensure that module linkage variables are always emitted and always have their name mangled.
llvm-svn: 312684
2017-09-07 00:55:55 +00:00
Justin Lebar 3310888aec [CUDA] Add device overloads for non-placement new/delete.
Summary:
Tests have to live in the test-suite, and so will come in a separate
patch.

Fixes PR34360.

Reviewers: tra

Subscribers: llvm-commits, sanjoy

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

llvm-svn: 312681
2017-09-07 00:37:20 +00:00
George Karpenkov 50657f6bd6 [CSA] [NFC] Move AnalysisContext.h to AnalysisDeclContext.h
The implementation is in AnalysisDeclContext.cpp and the class is called
AnalysisDeclContext.

Making those match up has numerous benefits, including:

 - Easier jump from header to/from implementation.
 - Easily identify filename from class.

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

llvm-svn: 312671
2017-09-06 21:45:03 +00:00
George Karpenkov 7b9cf1c4c3 [NFC] [CSA] Move AnyFunctionCall::getRuntimeDefinition implementation to cpp.
Differential Revision: https://reviews.llvm.org/D37499

llvm-svn: 312670
2017-09-06 21:45:01 +00:00
Richard Smith a465362d77 [modules ts] Emit global variables in a module interface unit as part of that unit, not in importers.
llvm-svn: 312665
2017-09-06 20:01:14 +00:00
Jonathan Roelofs b780c8ac75 Fix ARM bare metal driver to support atomics
The new bare metal support only supports the single thread model. This causes
the builtin atomic functions (e.g.: __atomic_fetch_add) to not generate
thread-safe assembly for these operations, which breaks our firmware. We target
bare metal, and need to atomically modify variables in our interrupt routines,
and task threads.

Internally, the -mthread-model flag determines whether to lower or expand
atomic operations (see D4984).

This change removes the overridden thread model methods, and instead relies on
the base ToolChain class to validate the thread model (which already includes
logic to validate single thread model support). If the single thread model is
required, the -mthread-model flag will have to be provided.

As a workaround "-mthread-model posix" could be provided, but it only works due
to a bug in the validation of the -mthread-model flag (separate patch coming to
fix this).

https://reviews.llvm.org/D37493

Patch by: Ian Tessier!

llvm-svn: 312651
2017-09-06 17:09:25 +00:00
Alexey Bataev f43f714213 [OPENMP] Fix for PR33922: New ident_t flags for
__kmpc_for_static_fini().

Added special flags for calls of __kmpc_for_static_fini(), like previous
ly for __kmpc_for_static_init(). Added flag OMP_IDENT_WORK_DISTRIBUTE
for distribute cnstruct, OMP_IDENT_WORK_SECTIONS for sections-based
  constructs and OMP_IDENT_WORK_LOOP for loop-based constructs in
  location flags.

llvm-svn: 312642
2017-09-06 16:17:35 +00:00
Alexey Bataev 070f43aee7 [OPENMP] Fix for PR34445: Reduction initializer segfaults at runtime in
move constructor.

Previously user-defined reduction initializer was considered as an
assignment expression, not as initializer. Fixed this by treating the
initializer expression as an initializer.

llvm-svn: 312638
2017-09-06 14:49:58 +00:00
Johannes Altmanninger 1509da083a [AST] Add TableGen for StmtDataCollectors
Summary:
This adds an option "-gen-clang-data-collectors" to the Clang TableGen
that is used to generate StmtDataCollectors.inc.

Reviewers: arphaman, teemperor!

Subscribers: mgorny, cfe-commits

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

llvm-svn: 312634
2017-09-06 13:20:51 +00:00
Karl-Johan Karlsson 33e205a40f Debug info: Fixed faulty debug locations for attributed statements
Summary:
As the attributed statements are considered simple statements no
stoppoint was generated before emitting attributed do/while/for/range-
statement. This lead to faulty debug locations.

Reviewers: echristo, aaron.ballman, dblaikie

Reviewed By: dblaikie

Subscribers: bjope, aprantl, cfe-commits

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

llvm-svn: 312623
2017-09-06 08:47:18 +00:00
Saleem Abdulrasool 6bf6a9a124 Driver: delete some dead code (NFC)
This code has been `#if 0`'ed out for a very long time.  After speaking
with Duncan, opt to remove it even if it is something which should be
fixed.  If the underlying issue is still valid, this can be restored
with proper explanation and tests.

llvm-svn: 312618
2017-09-06 05:11:19 +00:00
Saleem Abdulrasool c2320add83 Driver: remove unused variable (NFC)
Remove `IsHosted` which is no longer needed in `RenderSSPOptions` after
SVN r312595.  The single use can now be inlined.  NFC

llvm-svn: 312616
2017-09-06 04:56:23 +00:00
Bruno Cardoso Lopes bad2c4a000 Fix indentation mistake from r312595
llvm-svn: 312599
2017-09-06 00:44:10 +00:00
Bruno Cardoso Lopes c1843c2c85 [Darwin] Enable -fstack-protector (back) by default with -ffreestanding
Go back to behavior prior to r289005.

rdar://problem/32987198

llvm-svn: 312595
2017-09-05 23:50:58 +00:00
Richard Smith 056bf77faf Fix memory leak after r312467. The ModuleMap is the owner of the global module object until it's reparented under a real module.
llvm-svn: 312580
2017-09-05 21:46:22 +00:00
Reid Kleckner d53c39ba46 Commit changes missing from r312572
llvm-svn: 312573
2017-09-05 20:38:29 +00:00
Reid Kleckner 30701edf76 [ms] Implement the __annotation intrinsic
llvm-svn: 312572
2017-09-05 20:27:35 +00:00
Gor Nishanov db419a6f7c [coroutines] Make sure auto return type of await_resume is properly handled
Reviewers: rsmith, EricWF

Reviewed By: rsmith

Subscribers: javed.absar, cfe-commits

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

llvm-svn: 312565
2017-09-05 19:31:52 +00:00
Erich Keane e916d54614 [Preprocessor] Correct internal token parsing of newline characters in CRLF
Correct implementation:  Apparently I managed in r311683 to submit the wrong
version of the patch for this, so I'm correcting it now.

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

llvm-svn: 312542
2017-09-05 17:32:36 +00:00
Raphael Isemann bd7c45e7a8 [Bash-autocomplete] Fix crash when invoking --autocomplete without value.
Summary:
Currently clang segfaults when invoked with `clang --autocomplete=`.
This patch adds the necessary boundary checks and some tests for corner cases like this.

Reviewers: yamaguchi

Reviewed By: yamaguchi

Subscribers: cfe-commits

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

llvm-svn: 312533
2017-09-05 12:41:00 +00:00
Simon Pilgrim 108f36d5b9 Removed dead code (PR34467). NFCI.
The for loop already checks that Idx < NumOfArgs.

llvm-svn: 312525
2017-09-05 10:37:13 +00:00
Andrey Kasaurov 6618c39a95 [AMDGPU] Implement infrastructure to set options in AMDGPUToolChain
In current OpenCL implementation some options are set in OpenCL RT/Driver, which causes discrepancy between online and offline paths.
Implement infrastructure to move options from OpenCL RT/Driver to AMDGPUToolChain using overloaded TranslateArgs() method.
Create map for default options values, as Options.td doesn't support default values (in contrast with OPTIONS.def).
Add two driver options: -On and -mNN (like -O3, -m64).
Some minor formatting changes to follow the clang-format style.

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

llvm-svn: 312524
2017-09-05 10:24:38 +00:00
Simon Pilgrim 1ba2bf2162 [X86][AVX512] _mm512_stream_load_si512 should take a void const* argument (PR33977)
Based off the Intel Intrinsics guide, we should expect a void const* argument.

Prevents 'passing 'const void *' to parameter of type 'void *' discards qualifiers' warnings.

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

llvm-svn: 312523
2017-09-05 10:06:41 +00:00
Mehdi Amini 7cb1b304f8 Emit static constexpr member as available_externally definition
By exposing the constant initializer, the optimizer can fold many
of these constructs.

This is a recommit of r311857 that was reverted in r311898 because
an assert was hit when building Chromium.
We have to take into account that the GlobalVariable may be first
created with a different type than the initializer. This can
happen for example when the variable is a struct with tail padding
while the initializer does not have padding. In such case, the
variable needs to be destroyed an replaced with a new one with the
type of the initializer.

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

llvm-svn: 312512
2017-09-05 03:58:35 +00:00
Richard Smith debbaefb76 Always allocate room for a ModuleDecl on the TranslationUnitDecl.
Sometimes we create the ASTContext and thus the TranslationUnitDecl before we know the LangOptions. This should fix the asan buildbot failures after r312467.

llvm-svn: 312506
2017-09-05 00:50:19 +00:00
Daniel Jasper 4df130f941 clang-format: Fix indentation of macros in include guards (after r312125).
Before:
  #ifndef A_H
  #define A_H

  #define A() \
  int i;    \
  int j;

  #endif // A_H

After:
  #ifndef A_H
  #define A_H

  #define A() \
    int i;    \
    int j;

  #endif // A_H

llvm-svn: 312484
2017-09-04 13:33:52 +00:00
Simon Pilgrim f331a6642b Fix MSVC narrowing conversion warning.
llvm-svn: 312479
2017-09-04 10:54:39 +00:00
Raphael Isemann 561f0de6d9 [analyzer] Increase minimum complexity filter of the CloneChecker.
Summary:
So far we used a value of 10 which was useful for testing but produces many false-positives in real programs. The usual suspicious clones we find seem to be at around a complexity value of 70 and for normal clone-reporting everything above 50 seems to be a valid normal clone for users, so let's just go with 50 for now and set this as the new default value.

This patch also explicitly sets the complexity value for the regression tests as they serve more of a regression testing/debugging purpose and shouldn't really be reported by default in real programs. I'll add more tests that reflect actual found bugs that then need to pass with the default setting in the future.

Reviewers: NoQ

Subscribers: cfe-commits, javed.absar, xazax.hun, v.g.vassilev

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

llvm-svn: 312468
2017-09-04 05:56:36 +00:00
Richard Smith dd8b5337e9 Implement Itanium name mangling support for C++ Modules TS.
This follows the scheme agreed with Nathan Sidwell, which can be found here:

  https://gcc.gnu.org/wiki/cxx-modules?action=AttachFile

This will be proposed to the itanium-cxx-abi list once we have some experience
with how well it works; the ABI for this TS should be considered unstable until
it is part of the Itanium C++ ABI.

llvm-svn: 312467
2017-09-04 05:37:53 +00:00
Hal Finkel c9fac9e151 [CodeGen] Treat all vector fields as mayalias
Because it is common to treat vector types as an array of their elements, or
even some other type that's not the element type, and thus index into them, we
can't use struct-path TBAA for these accesses. Even though we already treat all
vector types as equivalent to 'char', we were using field-offset information
for them with TBAA, and this renders undefined the intra-value indexing we
intend to allow. Note that, although 'char' is universally aliasing, with path
TBAA, we can still differentiate between access to s.a and s.b in
  struct { char a, b; } s;. We can't use this capability as-is for vector types.

Fixes PR33967.

llvm-svn: 312447
2017-09-03 17:18:25 +00:00
Yaxun Liu 29a5ee358e [OpenCL] Do not use vararg in emitted functions for enqueue_kernel
Not all targets support vararg (e.g. amdgpu). Instead of using vararg in the emitted functions for enqueue_kernel,
this patch creates a temporary array of size_t, stores the size arguments in the temporary array
and passes it to the emitted functions for enqueue_kernel.

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

llvm-svn: 312441
2017-09-03 13:52:24 +00:00
Raphael Isemann 785e8161ad [analyzer] MinComplexityConstraint now early exits and only does one macro stack lookup
Summary:
This patch contains performance improvements for the `MinComplexityConstraint`. It reduces the constraint time when running on the SQLite codebase by around 43% (from 0.085s down to 0.049s).

The patch is essentially doing two things:

* It introduces a possibility for the complexity value to early exit when reaching the limit we were checking for. This means that once we noticed that the current clone is larger than the limit the user has set, we instantly exit and no longer traverse the tree or do further expensive lookups in the macro stack.

* It also removes half of the macro stack lookups we do so far. Previously we always checked the start and the end location of a Stmt for macros, which was only a middle way between checking all locations of the Stmt and just checking one location. In practice I rarely found cases where it really matters if we check start/end or just the start of a statement as code with lots of macros that somehow just produce half a statement are very rare.

Reviewers: NoQ

Subscribers: cfe-commits, xazax.hun, v.g.vassilev

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

llvm-svn: 312440
2017-09-03 13:45:33 +00:00
Daniel Jasper 7b85a19b9a clang-format: Fix formatting of for loops with multiple increments.
This fixes llvm.org/PR34366.

llvm-svn: 312437
2017-09-03 08:56:24 +00:00
Saleem Abdulrasool 6c3ed7b654 Driver; extract target specific option application (NFC)
Extract the target specific option application.  This is a huge switch
which was inlined into the `ConstructJob` option which adds a large
amount of code to the already large function.  Extract it to simply
reduce the line count.  NFC

llvm-svn: 312436
2017-09-03 04:47:00 +00:00
Saleem Abdulrasool 9934eabaf9 Driver: extract debugging related options (NFC)
Out-of-line the logic for selecting the debug information handling.
This is still split across the new function and partially inline in the
job construction.  This is needed since the split portion attempts to
record the "-cc1" arguments.  This needs to be the very last item to
ensure that all the flags are recorded.  NFC.

llvm-svn: 312435
2017-09-03 04:46:59 +00:00
Saleem Abdulrasool fb302caa36 Driver: move `-mfpmath` into FP Options (NFC)
Move the `-mfpmath` handling with the rest of the floating point
optimization flags.

llvm-svn: 312434
2017-09-03 04:46:57 +00:00
Saleem Abdulrasool 99f4ead12a Driver: extract `-fbuiltin` option handling (NFC)
Extract the handling of the `-fbuiltin` family of flags to the driver.
This centralises the handling of those options, keeping the long
standing `#if 0`'ed block of code.  This requires some additional code
archaeology to determine if we need to enable this functionality.

llvm-svn: 312392
2017-09-01 23:44:01 +00:00
Saleem Abdulrasool e6d219df25 Driver: extract floating point optimization handling (NFC)
Extract the logic for the floating point handling into its own function.
None of this information is needed for calculating the remainder of the
arguments to the frontend.  NFC

llvm-svn: 312385
2017-09-01 22:04:24 +00:00
Erich Keane 9937b134c5 [CodeGen]Refactor CpuSupports/CPUIs Builtin Code Gen to better work with
"target" implementation

A small set of refactors that'll make it easier for me to implement 'target' 
support.

First, extract the CPUSupports functionality into its own function. 
THis has the advantage of not wasting time in this builtin to deal with 
arguments.
Second, pulls both CPUSupports and CPUIs implementation into a member-function, 
so that it can be called from the resolver generation that I'm working on.
Third, creates an overload that takes simply the feature/cpu name (rather than 
extracting it from a callexpr), since that info isn't available later.

Note that despite how the 'diff' looks, the EmitX86CPUSupports function simply 
takes the implementation out of the 'switch'.

llvm-svn: 312355
2017-09-01 19:42:45 +00:00
Saleem Abdulrasool 75557fa024 Driver: extract diagnostics flag handling (NFC)
Extract a function to render the diagnostics options to the clang
frontend.  This continues the simplification of the clang cc1 command
line invocation generation.  NFC

llvm-svn: 312351
2017-09-01 18:57:34 +00:00
Kostya Serebryany a523135f97 [libFuzzer] switch -fsanitize=fuzzer from trace-pc-guard to inline-8bit-counters
llvm-svn: 312346
2017-09-01 18:34:36 +00:00
Saleem Abdulrasool b2d4ebb0c0 Driver: extract ObjC option rendering (NFC)
Extract the ObjC option rendering for the frontend.  This localises the
option translation.  It augments the existing `AddRuntimeObjCOptions`
which handles the runtime/ABI versioning flags only.  This new function
handles the non-runtime selecting flags.  This logic was previously
inlined into the `ConstructJob` function.

Minor change to the flag ordering to group the blocks related flags
together.

llvm-svn: 312344
2017-09-01 17:43:59 +00:00
Benjamin Kramer 0b94bfc709 std::function -> llvm::function_ref. NFC.
llvm-svn: 312336
2017-09-01 16:51:51 +00:00
Saleem Abdulrasool e196e94eca Driver: extract modules flag handling (NFC)
Extract a function to render the options related to modules.  This
reduces the cyclomatic complexity of the `ConstructJob` function.  NFC.

llvm-svn: 312330
2017-09-01 15:25:17 +00:00
Martin Storsjo c6c5af75f2 Reland r312224 - [ItaniumCXXABI] Always use linkonce_odr linkage for RTTI data on MinGW
This fixes cases where dynamic classes produced RTTI data with
external linkage, producing linker errors about duplicate symbols.

This touches code close to what was changed in SVN r244266, but
this change doesn't break the tests added in that revision.

The previous version had missed to update CodeGenCXX/virt-dtor-key.cpp,
which had a behaviour change only when running the testsuite on windows.

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

llvm-svn: 312306
2017-09-01 06:41:55 +00:00
Alexey Bataev 5372fb8cc1 [OPENMP] Fix for PR34398: assert with random access iterator if the
step>1.

If the loop is a loot with random access iterators and the iteration
construct is represented it += n, then the compiler crashed because of
reusing of the same MaterializedTemporaryExpr around N. Patch fixes it
by using the expression as written, without any special kind of
wrappings.

llvm-svn: 312292
2017-08-31 23:06:52 +00:00
Dave Lee cde4528a8e Register linkageSpecDecl matcher
Summary:
This allows `linkageSpecDecl` to be used from `clang-query`.

See also D31869 which similary adds `isStaticStorageClass`.

Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: cfe-commits, klimek

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

llvm-svn: 312283
2017-08-31 21:18:27 +00:00
Oleg Ranevskyy 8052318287 [clang-cl] Explicitly set object format to COFF in CL mode
Summary:
Currently object format is taken from the default target triple. For toolchains with a non-COFF default target this may result in an object format inappropriate for pc-windows and lead to compilation issues. 

For example, the default triple `aarch64-linux-elf` may produce something like `aarch64-pc-windows-msvc19.0.24215-elf` in CL mode. Clang creates `MicrosoftARM64TargetInfo` for such triple with data layout `e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128`. On the other hand, the AArch64 backend in `computeDataLayout` detects a non-COFF target and selects `e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128` as data layout for little endian. Different layouts used by clang and the backend cause an error:
```
error: backend data layout 'e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128'
 does not match expected target description 'e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128'
```
This can be observed on the clang's Driver/cl-pch.c test with AArch64 as a default target.

This patch enforces COFF in CL mode.

Reviewers: hans

Reviewed By: hans

Subscribers: cfe-commits, aemerson, asl, kristof.beyls

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

llvm-svn: 312275
2017-08-31 20:31:30 +00:00
Saleem Abdulrasool 0a322c6c81 Driver: extract ARCMT flag construction (NFC)
Extract the ARC migration tool flag handling into its own function.
This simplifies the flow of the clang frontend command line construction
function.  NFC.

llvm-svn: 312244
2017-08-31 15:35:01 +00:00
Martin Storsjo 7bfb697259 Revert r312224: "[ItaniumCXXABI] Always use linkonce_odr linkage for RTTI data on MinGW"
Breaks on buildbot:
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/4548/steps/test-check-all/logs/stdio

The test in CodeGenCXX/virt-dtor-key.cpp tests using %itanium_abi_triple;
on non-windows platforms, this resolves to the current platform triple
(where there was no behaviour change), while on windows, it resolves to
a mingw triple (where the behaviour was intentionally changed).

llvm-svn: 312229
2017-08-31 09:46:27 +00:00
Martin Storsjo cd7d552e04 [ItaniumCXXABI] Always use linkonce_odr linkage for RTTI data on MinGW
This fixes cases where dynamic classes produced RTTI data with
external linkage, producing linker errors about duplicate symbols.

This touches code close to what was changed in SVN r244266, but
this change doesn't break the tests added in that revision.

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

llvm-svn: 312224
2017-08-31 08:29:59 +00:00
Raphael Isemann 70686a1590 [analyzer] Performance optimizations for the CloneChecker
Summary:
This patch  aims at optimizing the CloneChecker for larger programs. Before this
patch we took around 102 seconds to analyze sqlite3 with a complexity value of
50. After this patch we now take 2.1 seconds to analyze sqlite3.

The biggest performance optimization is that we now put the constraint for group
size before the constraint for the complexity. The group size constraint is much
faster in comparison to the complexity constraint as it only does a simple
integer comparison. The complexity constraint on the other hand actually
traverses each Stmt and even checks the macro stack, so it is obviously not able
to handle larger amounts of incoming clones. The new order filters out all the
single-clone groups that the type II constraint generates in a faster way before
passing the fewer remaining clones to the complexity constraint. This reduced
runtime by around 95%.

The other change is that we also delay the verification part of the type II
clones back in the chain of constraints. This required to split up the
constraint into two parts - a verification and a hash constraint (which is also
making it more similar to the original design of the clone detection algorithm).
The reasoning for this is the same as before: The verification constraint has to
traverse many statements and shouldn't be at the start of the constraint chain.
However, as the type II hashing has to be the first step in our algorithm, we
have no other choice but split this constrain into two different ones. Now our
group size and complexity constrains filter out a chunk of the clones before
they reach the slow verification step, which reduces the runtime by around 8%.

I also kept the full type II constraint around - that now just calls it's two
sub-constraints - in case someone doesn't care about the performance benefits
of doing this.

Reviewers: NoQ

Reviewed By: NoQ

Subscribers: klimek, v.g.vassilev, xazax.hun, cfe-commits

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

llvm-svn: 312222
2017-08-31 07:10:46 +00:00
Boris Kolpackov d30446fd77 [modules] Add ability to specify module name to module file mapping (reapply)
Extend the -fmodule-file option to support the [<name>=]<file> value format.
If the name is omitted, then the old semantics is preserved (the module file
is loaded whether needed or not). If the name is specified, then the mapping
is treated as just another prebuilt module search mechanism, similar to
-fprebuilt-module-path, and the module file is only loaded if actually used
(e.g., via import). With one exception: this mapping also overrides module
file references embedded in other modules (which can be useful if module files
are moved/renamed as often happens during remote compilation).

This override semantics requires some extra work: we now store the module name
in addition to the file name in the serialized AST representation.

Reviewed By: rsmith

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

llvm-svn: 312220
2017-08-31 06:26:43 +00:00
Nico Weber bf2260ca62 Suppress -Wdelete-non-virtual-dtor warnings about classes defined in system headers.
r312167 made it so that we emit Wdelete-non-virtual-dtor from delete statements
that are in system headers (e.g. std::unique_ptr). That works great on Linux
and macOS, but on Windows there are non-final classes that are defined in
system headers that have virtual methods but non-virtual destructors and yet
get deleted through a base class pointer (e.g. ATL::CAccessToken::CRevert). So
paddle back a bit and don't emit the warning if it's about a class defined in a
system header.

https://reviews.llvm.org/D37324

llvm-svn: 312216
2017-08-31 06:17:08 +00:00
Matt Morehouse 034126e507 [SanitizeCoverage] Enable stack-depth coverage for -fsanitize=fuzzer
Summary:
- Don't sanitize __sancov_lowest_stack.
- Don't instrument leaf functions.
- Add CoverageStackDepth to Fuzzer and FuzzerNoLink.
- Only enable on Linux.

Reviewers: vitalybuka, kcc, george.karpenkov

Reviewed By: kcc

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

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

llvm-svn: 312185
2017-08-30 22:49:31 +00:00
Erich Keane bb9c704784 [CodeGen][x86_64] Enable 'force_align_arg_pointer' attribute at x86_64
This attribute is useful in OS development when we jump from 32 to 64 bit
code and expect that 64bit function forces correct stack alignment.

Related discussion: http://lists.llvm.org/pipermail/cfe-dev/2017-June/054358.html

Patch By: anatol.pomozov (anatol.pomozov@gmail.com)

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

llvm-svn: 312173
2017-08-30 21:17:40 +00:00
Nico Weber 955bb84090 Let -Wdelete-non-virtual-dtor fire in system headers too.
Makes the warning useful again in a std::unique_ptr world, PR28460.

Also make the warning not fire in unevaluated contexts, since system libraries
(e.g. libc++) do do that. This would've been a good change before we started
emitting this warning in system headers too, but "normal" code seems to be less
template-heavy, so we didn't notice until now.

https://reviews.llvm.org/D37235

llvm-svn: 312167
2017-08-30 20:25:22 +00:00
Craig Topper 5ece4cfe1e [X86] Implement broadcastf32x2 and broadcasti32x2 intrinsics using __builtin_shufflevector instead builtins
This patch implements the broadcastf32x2/broadcasti32x2 intrinsics using __builtin_shufflevector.

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

llvm-svn: 312135
2017-08-30 16:15:12 +00:00
Alex Lorenz 410ef3838a Recommit r312127: [refactor] AST selection tree should contain syntactic
form of PseudoObjectExpr

The new commit adjusts unittest test code compilation options so that the
Objective-C code in the unittest can be parsed on non-macOS platforms.

Original message:

The AST selection finder now constructs a selection tree that contains only the
syntactic form of PseudoObjectExpr. This form of selection tree is more
meaningful when doing downstream analysis as we're interested in the syntactic
features of the AST and the correct lexical parent relation.

llvm-svn: 312132
2017-08-30 15:28:01 +00:00
Alex Lorenz 02c9994472 Revert r312127 as the ObjC unittest code fails to compile on Linux
llvm-svn: 312131
2017-08-30 15:11:45 +00:00
Alex Lorenz 6852bea7cc [refactor] AST selection tree should contain syntactic form
of PseudoObjectExpr

The AST selection finder now constructs a selection tree that contains only the
syntactic form of PseudoObjectExpr. This form of selection tree is more
meaningful when doing downstream analysis as we're interested in the syntactic
features of the AST and the correct lexical parent relation.

llvm-svn: 312127
2017-08-30 15:00:27 +00:00
Krasimir Georgiev ad47c90767 clang-format: Add preprocessor directive indentation
Summary:
This is an implementation for [bug 17362](https://bugs.llvm.org/attachment.cgi?bugid=17362) which adds support for indenting preprocessor statements inside if/ifdef/endif. This takes previous work from fmauch (https://github.com/fmauch/clang/tree/preprocessor_indent) and makes it into a full feature.
The context of this patch is that I'm a VMware intern, and I implemented this because VMware needs the feature. As such, some decisions were made based on what VMware wants, and I would appreciate suggestions on expanding this if necessary to use-cases other people may want.

This adds a new enum config option, `IndentPPDirectives`. Values are:

* `PPDIS_None` (in config: `None`):
```
    #if FOO
    #if BAR
    #include <foo>
    #endif
    #endif
```
* `PPDIS_AfterHash` (in config: `AfterHash`):
```
    #if FOO
    #  if BAR
    #    include <foo>
    #  endif
    #endif
```
This is meant to work whether spaces or tabs are used for indentation. Preprocessor indentation is independent of indentation for non-preprocessor lines.

Preprocessor indentation also attempts to ignore include guards with the checks:
1. Include guards cover the entire file
2. Include guards don't have `#else`
3. Include guards begin with
```
#ifndef <var>
#define <var>
```

This patch allows `UnwrappedLineParser::PPBranchLevel` to be decremented to -1 (the initial value is -1) so the variable can be used for indent tracking.

Defects:
* This patch does not handle the case where there's code between the `#ifndef` and `#define` but all other conditions hold. This is because when the #define line is parsed, `UnwrappedLineParser::Lines` doesn't hold the previous code line yet, so we can't detect it. This is out of the scope of this patch.

* This patch does not handle cases where legitimate lines may be outside an include guard. Examples are `#pragma once` and `#pragma GCC diagnostic`, or anything else that does not change the meaning of the file if it's included multiple times.

* This does not detect when there is a single non-preprocessor line in front of an include-guard-like structure where other conditions hold because `ScopedLineState` hides the line.

* Preprocessor indentation throws off `TokenAnnotator::setCommentLineLevels` so the indentation of comments immediately before indented preprocessor lines is toggled on each run. Fixing this issue appears to be a major change and too much complexity for this patch.

Contributed by @euhlmann!

Reviewers: djasper, klimek, krasimir

Reviewed By: djasper, krasimir

Subscribers: krasimir, mzeren-vmw, cfe-commits

Tags: #clang

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

llvm-svn: 312125
2017-08-30 14:34:57 +00:00
Saleem Abdulrasool 24aafa5799 Driver: out-of-line static analyzer flag handling (NFC)
Extract the analyzer flag handling into its own function to reduce the
overall complexity of the construction of the clang compiler arguments.
NFC.

llvm-svn: 312124
2017-08-30 14:18:08 +00:00
Alex Lorenz 23654b501c [refactor] Examine the whole range for ObjC @implementation decls
when computing the AST selection

llvm-svn: 312121
2017-08-30 13:24:37 +00:00
Victor Leschuk db68911b07 Revert r312105 [modules] Add ability to specify module name to module file mapping
Looks like it breaks win10 builder.

llvm-svn: 312112
2017-08-30 11:31:56 +00:00
Martin Bohme 542c84b2a1 Revert "Improve constant expression evaluation of arrays of unknown bound."
This reverts commit r311970.

Breaks internal tests.

llvm-svn: 312108
2017-08-30 10:44:46 +00:00
Boris Kolpackov 7a71b4b658 [modules] Add ability to specify module name to module file mapping
Extend the -fmodule-file option to support the [<name>=]<file> value format.
If the name is omitted, then the old semantics is preserved (the module file
is loaded whether needed or not). If the name is specified, then the mapping
is treated as just another prebuilt module search mechanism, similar to
-fprebuilt-module-path, and the module file is only loaded if actually used
(e.g., via import). With one exception: this mapping also overrides module
file references embedded in other modules (which can be useful if module files
are moved/renamed as often happens during remote compilation).

This override semantics requires some extra work: we now store the module name
in addition to the file name in the serialized AST representation.

Reviewed By: rsmith

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

llvm-svn: 312105
2017-08-30 08:45:59 +00:00
Richard Smith b1efc9b410 Give a better error if auto deduction fails due to inconsistent element types in a braced initializer list.
llvm-svn: 312085
2017-08-30 00:44:08 +00:00
Saleem Abdulrasool d5ba54549d Driver: refactor SSP argument handling (NFC)
Out-of-line the SSP argument handling for the sake of readability.  Pass
along some state information to avoid re-computing the command line
flags.

llvm-svn: 312084
2017-08-29 23:59:08 +00:00
Saleem Abdulrasool 68c808f6e3 Driver: refactor OpenCL argument forwarding
Extract the argument forwarding for OpenCL arguments.  Make this more
data driven as we are just repeating the argument name and spelling.
This costs a slight bit more memory due to the string duplication, but
makes it easier to follow.  It should be possible to forward the
internal string representation from the TableGen data to avoid this.
But, this makes the code simpler to follow for now.

llvm-svn: 312083
2017-08-29 23:59:07 +00:00
Saleem Abdulrasool 33d4138235 Driver: reuse existing `D` variable (NFC)
Change the rest of the function to use the `D` variable for the driver
instance.  NFC.

llvm-svn: 312082
2017-08-29 23:59:06 +00:00
Saleem Abdulrasool 374b558603 Driver: hoist a local variable (NFC)
Hoist the `getToolChain().getTriple()` to a variable rather than
re-fetching it every time.  NFC.

llvm-svn: 312081
2017-08-29 23:59:05 +00:00
Richard Smith 1abacfcb23 PR10147: When substituting a template template argument, substitute in the most
recent (non-friend) declaration to pick up the right set of default template
arguments.

llvm-svn: 312049
2017-08-29 22:14:43 +00:00
Evgeniy Stepanov c6daf73c72 Restore clang_rt library name on i686-android.
Summary:
Recent changes canonicalized clang_rt library names to refer to
"i386" on all x86 targets. Android historically uses i686.

This change adds a special case to keep i686 in all clang_rt
libraries when targeting Android.

Reviewers: hans, mgorny, beanz

Subscribers: srhines, cfe-commits, llvm-commits

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

llvm-svn: 312048
2017-08-29 22:12:31 +00:00
Matt Morehouse ba2e61b357 Revert "[SanitizeCoverage] Enable stack-depth coverage for -fsanitize=fuzzer"
This reverts r312026 due to bot breakage.

llvm-svn: 312047
2017-08-29 21:56:56 +00:00
Matt Morehouse 2edac86cdb Re-enable stack depth instrumentation on Windows.
Specified tls_model attribute properly. Should compile on Windows
now.

llvm-svn: 312037
2017-08-29 21:15:33 +00:00
Matt Morehouse c29c2c9b0c Disable stack depth tracking on Windows.
Windows doesn't support the tls_model attribute.

llvm-svn: 312032
2017-08-29 20:44:41 +00:00
Evgeniy Stepanov 6d2b6f0a5f Minimal runtime for UBSan.
Summary:
An implementation of ubsan runtime library suitable for use in production.

Minimal attack surface.
* No stack traces.
* Definitely no C++ demangling.
* No UBSAN_OPTIONS=log_file=/path (very suid-unfriendly). And no UBSAN_OPTIONS in general.
* as simple as possible

Minimal CPU and RAM overhead.
* Source locations unnecessary in the presence of (split) debug info.
* Values and types (as in A+B overflows T) can be reconstructed from register/stack dumps, once you know what type of error you are looking at.
* above two items save 3% binary size.

When UBSan is used with -ftrap-function=abort, sometimes it is hard to reason about failures. This library replaces abort with a slightly more informative message without much extra overhead. Since ubsan interface in not stable, this code must reside in compiler-rt.

Reviewers: pcc, kcc

Subscribers: srhines, mgorny, aprantl, krytarowski, llvm-commits

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

llvm-svn: 312029
2017-08-29 20:03:51 +00:00
Matt Morehouse 2ad8d948b2 [SanitizeCoverage] Enable stack-depth coverage for -fsanitize=fuzzer
Summary:
- Don't sanitize __sancov_lowest_stack.
- Don't instrument leaf functions.
- Add CoverageStackDepth to Fuzzer and FuzzerNoLink.
- Disable stack depth tracking on Mac.

Reviewers: vitalybuka, kcc, george.karpenkov

Reviewed By: kcc

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

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

llvm-svn: 312026
2017-08-29 19:48:12 +00:00
Alexey Bataev 61498fb88f [OPENMP] Capture global variables in all target executable regions.
Capturing of the global variables occurs only in target regions. Patch
fixes it and allows capturing of globals in all target executable
directives.

llvm-svn: 312024
2017-08-29 19:30:57 +00:00
Yuka Takahashi 1a89520d92 [Bash-autocomplete] Refactor autocomplete code into own function
Summary:
We wrote many codes in HandleImediateArgs, so I've refactored it into
handleAutocompletions.

Reviewers: v.g.vassilev, teemperor

Subscribers: cfe-commits

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

llvm-svn: 312018
2017-08-29 17:46:46 +00:00
Reid Kleckner dd6fc83cb4 [ms] Fix vbtable index for covariant overrides of vbase methods
Overriding a method from a virtual base with a covariant return type
consumes a slot from the vftable in the virtual base. This can make it
impossible to implement certain diamond inheritance hierarchies, but we
have to follow along for compatibility in the simple cases.

This patch only affects our vtable dumper and member pointer function
mangling, since all other callers of getMethodVFTableLocation seem to
recompute VBTableIndex instead of using the one in the method location.

Patch by David Majnemer

llvm-svn: 312017
2017-08-29 17:40:04 +00:00
Boris Kolpackov 734d8548ee [modules-ts] Omit submodule semantics for TS modules
If a TS module name has more than one component (e.g., foo.bar) then we
erroneously activated the submodule semantics when encountering a module
declaration in the module implementation unit (e.g., 'module foo.bar;').

Reviewed By: rsmith

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

llvm-svn: 312007
2017-08-29 15:30:18 +00:00
Krasimir Georgiev 86873030ae [clang-format] Refactor likely xml a bit, NFC
llvm-svn: 312000
2017-08-29 13:57:31 +00:00
Krasimir Georgiev a2e7d0dee3 [clang-format] Do not format likely xml
Summary:
This patch detects the leading '<' in likely xml files and stops formatting in
that case. A recent use of a Qt xml file with a .ts extension triggered this:
http://doc.qt.io/qt-4.8/linguist-ts-file-format.html

Reviewers: djasper

Reviewed By: djasper

Subscribers: sammccall, cfe-commits, klimek

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

llvm-svn: 311999
2017-08-29 13:51:38 +00:00
Krasimir Georgiev 81341d7022 [clang-format] Fixed typedef enum brace wrapping
Summary:
Bug: https://bugs.llvm.org/show_bug.cgi?id=34016 - **Typedef enum part**

**Problem:**

Clang format does not allow the flag **BraceWrapping.AfterEnum** control the case when our **enum** is preceded by **typedef** keyword (what is common in C language).

**Patch description:**

Added case to the **"AfterEnum"** flag when our enum does not start a line - is preceded by **typedef** keyword.

**After fix:**

**CONFIG:**
```
BreakBeforeBraces: Custom
BraceWrapping: {
AfterClass: true, AfterControlStatement: true, AfterEnum: true, AfterFunction: true, AfterNamespace: false, AfterStruct: true, AfterUnion: true, BeforeCatch: true, BeforeElse: true
}
```

**BEFORE:**
```
typedef enum
{
    a,
    b,
    c
} SomeEnum;
```

**AFTER:**

```
typedef enum
{
    a,
    b,
    c
} SomeEnum;
```

Contributed by @PriMee!

Reviewers: krasimir, djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 311998
2017-08-29 13:32:30 +00:00
Martin Probst c10d97f924 clang-format: [JS] simplify template string wrapping.
Summary:
Previously, clang-format would try to wrap template string substitutions
by indenting relative to the openening `${`. This helped with
indenting structured strings, such as strings containing HTML, as the
substitutions would be aligned according to the structure of the string.

However it turns out that the overwhelming majority of template string +
substitution usages are for substitutions into non-structured strings,
e.g. URLs or just plain messages. For these situations, clang-format
would often produce very ugly indents, in particular for strings
containing no line breaks:

    return `<a href='http://google3/${file}?l=${row}'>${file}</a>(${
                                                                    row
                                                                  },${
                                                                      col
                                                                    }): `;

This change makes clang-format indent template string substitutions as
if they were string concatenation operations. It wraps +4 on overlong
lines and keeps all operands on the same line:

    return `<a href='http://google3/${file}?l=${row}'>${file}</a>(${
        row},${col}): `;

While this breaks some lexical continuity between the `${` and `row}`
here, the overall effects are still a huge improvement, and users can
still manually break the string using `+` if desired.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 311988
2017-08-29 08:30:07 +00:00
Serge Pavlov 4e769847c2 Use class to pass information about executable name
Information about clang executable name components, such as target and
driver mode, was passes in std::pair. With this change it is passed in
a special structure. It improves readability and makes access to this
information more convenient.

NFC.

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

llvm-svn: 311981
2017-08-29 05:22:26 +00:00
Faisal Vali c3ef532c2d revert r311839 (ongoing cwg discussion)
apologies.

llvm-svn: 311975
2017-08-29 03:04:13 +00:00
Richard Smith 2cd5604823 Improve constant expression evaluation of arrays of unknown bound.
The standard is not clear on how these are supposed to be handled, so we
conservatively treat as non-constant any cases whose value is unknown or whose
evaluation might result in undefined behavior.

llvm-svn: 311970
2017-08-29 01:52:13 +00:00
Yuka Takahashi 24bc6a4c4f Revert "Revert r311552: [Bash-autocompletion] Add support for static analyzer flags"
This reverts commit 7c46b80c022e18d43c1fdafb117b0c409c5a6d1e.

r311552 broke lld buildbot because I've changed OptionInfos type from
ArrayRef to vector. However the bug is fixed, so I'll commit this again.

llvm-svn: 311958
2017-08-29 00:09:31 +00:00
Rui Ueyama 5ad6bdf2fd Remove trailing space.
llvm-svn: 311936
2017-08-28 21:38:14 +00:00
Alexander Shaposhnikov 18d77984fb [analyzer] Fix crash in modeling arithmetic
This diff fixes modeling of arithmetic 
expressions where pointers are treated as integers 
(i.e. via C-style / reinterpret casts).
For now we return UnknownVal unless the operation is a comparison.

Test plan: make check-all

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

llvm-svn: 311935
2017-08-28 21:15:21 +00:00
Michal Gorny 62dc83b9b7 Reland r311836 - [Driver] Use arch type to find compiler-rt libraries (on Linux)
Use llvm::Triple::getArchTypeName() when looking for compiler-rt
libraries, rather than the exact arch string from the triple. This is
more correct as it matches the values used when building compiler-rt
(builtin-config-ix.cmake) which are the subset of the values allowed
in triples.

For example, this fixes an issue when the compiler set for
i686-pc-linux-gnu triple would not find an i386 compiler-rt library,
while this is the exact arch that is detected by compiler-rt. The same
applies to any other i?86 variant allowed by LLVM.

This also makes the special case for MSVC unnecessary, since now i386
will be used reliably for all 32-bit x86 variants.

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

llvm-svn: 311923
2017-08-28 20:29:52 +00:00
Alexey Bataev f32ec1ab31 [OPENMP] Remove unused header files, NFC.
llvm-svn: 311908
2017-08-28 19:26:54 +00:00
Erich Keane 0a539b5859 Change Diagnostic Category size error from runtime to compiletime
Diagnostic Categories are fairly annoying, and are only enforced
by a runtime-debug-only assert. This puts in a touch more work
to get this all done at compile-time with static asserts

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

llvm-svn: 311905
2017-08-28 18:53:17 +00:00
Reid Kleckner ea2683ecb8 Fix inaccurate comment about -fdelayed-template-parsing and MSVC
llvm-svn: 311899
2017-08-28 17:59:24 +00:00
Hans Wennborg edd66ab9dc Revert r311857 "Emit static constexpr member as available_externally definition"
It caused PR759744.

> Emit static constexpr member as available_externally definition
>
> By exposing the constant initializer, the optimizer can fold many
> of these constructs.
>
> Differential Revision: https://reviews.llvm.org/D34992

llvm-svn: 311898
2017-08-28 17:53:00 +00:00
Alex Lorenz 1586fa70a6 [refactor] initial support for refactoring action rules
This patch implements the initial support for refactoring action rules. The
first rule that's supported is a "source change" rule that returns a set of
atomic changes. This patch is based on the ideas presented in my RFC:

http://lists.llvm.org/pipermail/cfe-dev/2017-July/054831.html

The following pieces from the RFC are added by this patch:

- `createRefactoringRule` (known as `apply` in the RFC)
- `requiredSelection` refactoring action rule requirement.
- `selection::SourceSelectionRange` selection constraint.

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

llvm-svn: 311884
2017-08-28 11:12:05 +00:00
Peter Szecsi 0db84863d0 [StaticAnalyzer] LoopUnrolling: Keep track the maximum number of steps for each loop
This way the unrolling can be restricted for loops which will take at most a
given number of steps. It is defined as 128 in this patch and it seems to have
a good number for that purpose.

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

llvm-svn: 311883
2017-08-28 10:50:28 +00:00
Peter Szecsi d0604acd8e [StaticAnalyzer] LoopUnrolling: Excluding loops which splits the state
Added check if the execution of the last step of the given unrolled loop has
generated more branches. If yes, than treat it as a normal (non-unrolled) loop
in the remaining part of the analysis.

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

llvm-svn: 311881
2017-08-28 10:34:50 +00:00
Peter Szecsi d91554bc91 [StaticAnalyzer] LoopUnrolling fixes
1. The LoopUnrolling feature needs the LoopExit included in the CFG so added this
dependency via the config options
2. The LoopExit element can be encountered even if we haven't encountered the 
block of the corresponding LoopStmt. So the asserts were not right.
3. If we are caching out the Node then we get a nullptr from generateNode which
case was not handled.


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

llvm-svn: 311880
2017-08-28 10:21:24 +00:00
Gabor Horvath 857ccd2919 [analyzer][GSoC] Re-implemente current virtual calls checker in a path-sensitive way
Patch by: Xin Wang

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

llvm-svn: 311877
2017-08-28 08:44:43 +00:00
Craig Topper 2c03e53f4e [X86] Add support for __builtin_cpu_init
This adds builtin_cpu_init which will emit a call to cpu_indicator_init in libgcc or compiler-rt.

This is needed to support builtin_cpu_supports/builtin_cpu_is in an ifunc resolver.

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

llvm-svn: 311874
2017-08-28 05:43:23 +00:00
Richard Smith 6b8e3c02ca [c++2a] P0683R1: Permit default member initializers for bit-fields.
This would be trivial, except that our in-memory and serialized representations
for FieldDecls assumed that this can't happen.

llvm-svn: 311867
2017-08-28 00:28:14 +00:00
Johannes Altmanninger 41395022a3 [clang-diff] Treat CXXCtorInitializer as a node
Reviewers: arphaman

Subscribers: cfe-commits, klimek

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

llvm-svn: 311865
2017-08-27 22:52:20 +00:00
Michal Gorny 617e898dca Revert r311836 - [Driver] Use arch type to find compiler-rt libraries (on Linux)
This causes a breakage on the Android build bot. Let's revert it until
we figure out the correct solution there.

llvm-svn: 311861
2017-08-27 20:38:43 +00:00
Mehdi Amini f23847604b Emit static constexpr member as available_externally definition
By exposing the constant initializer, the optimizer can fold many
of these constructs.

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

llvm-svn: 311857
2017-08-27 20:24:09 +00:00
Faisal Vali 55bc389aeb revert changes from r311851.
The right answers here (and how clang needs to be tweaked) require further analysis (ongoing cwg thread).

sorry.

llvm-svn: 311855
2017-08-27 19:00:08 +00:00
Faisal Vali 5f5b29dd22 Don't see through 'using member-declarations' when determining the relation of any potential implicit object expression to the parent class of the member function containing the function call.
Prior to this patch clang would not error here:

  template <class T> struct B;
  
  template <class T> struct A {
    void foo();
    void foo2();
    
    void test1() {
      B<T>::foo();  // OK, foo is declared in A<int> - matches type of 'this'.
      B<T>::foo2(); // This should be an error!  
                    // foo2 is found in B<int>, 'base unrelated' to 'this'.
    }
  };

  template <class T> struct B : A<T> {
    using A<T>::foo2;
  };

llvm-svn: 311851
2017-08-27 16:49:47 +00:00
Vassil Vassilev 3d05c56ef2 D34059: Get the file name for the symbol from the Module, not the SourceManager.
This allows multi-module / incremental compilation environments to have unique
initializer symbols.

Patch by Axel Naumann with minor modifications by me!

llvm-svn: 311844
2017-08-27 11:27:30 +00:00
Vassil Vassilev 4d54e543ab D34444: Teach codegen to work in incremental processing mode.
When isIncrementalProcessingEnabled is on we might want to produce multiple
llvm::Modules. This patch allows the clients to start a new llvm::Module,
allowing CodeGen to continue working after a HandleEndOfTranslationUnit call.

This should give the necessary facilities to write a unittest for D34059.

As discussed in the review this is meant to give us a way to proceed forward
in our efforts to upstream our interpreter-related patches. The design of this
will likely change soon.

llvm-svn: 311843
2017-08-27 10:58:03 +00:00