Commit Graph

46840 Commits

Author SHA1 Message Date
Richard Smith c27b3d7623 Canonicalize implicit deduction guide parameter types when forming a deduction
guide from a constructor.

The purpose of this change is to avoid triggering instantiation of the class
when substituting back into the deduction guide if it uses a typedef member.
We will still instantiate the class if the constructor (explicitly or
implicitly, directly or indirectly) uses the current instantiation in a way
that we can't canonicalize out, but that seems unavoidable.

llvm-svn: 295016
2017-02-14 01:49:59 +00:00
Richard Smith cbe079321e [c++1z] Add some more tests for class template argument deduction, add
feature-test macro, and mark feature as done on status page.

llvm-svn: 295011
2017-02-14 00:55:25 +00:00
David Majnemer dc169759ca [MS ABI] Correctly mangling vbase destructors
They are a little bit of a special case in the mangling. They are always
mangled without taking into account their virtual-ness of the
destructor. They are also mangled to return void, unlike the actual
destructor.

This fixes PR31931.

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

llvm-svn: 295010
2017-02-14 00:54:11 +00:00
Richard Smith 3291877656 [c++1z] Synthesize implicit deduction guides from constructors on demand. Rank
such guides below explicit ones, and ensure that references to the class's
template parameters are not treated as forwarding references.

We make a few tweaks to the wording in the current standard:
1) The constructor parameter list is copied faithfully to the deduction guide,
   without losing default arguments or a varargs ellipsis (which the standard
   wording loses by omission).
2) If the class template declares no constructors, we add a T() -> T<...> guide
   (which will only ever work if T has default arguments for all non-pack
   template parameters).
3) If the class template declares nothing that looks like a copy or move
   constructor, we add a T(T<...>) -> T<...> guide.
#2 and #3 follow from the "pretend we had a class type with these constructors"
philosophy for deduction guides.

llvm-svn: 295007
2017-02-14 00:25:28 +00:00
Nick Lewycky 0752762180 When the new expr's array size is an ICE, emit it as a constant expression.
This bypasses integer sanitization checks which are redundant on the expression since it's been checked by Sema. Fixes a clang codegen assertion on "void test() { new int[0+1]{0}; }" when building with -fsanitize=signed-integer-overflow.

llvm-svn: 295006
2017-02-13 23:49:55 +00:00
Alex Lorenz 46eed9d625 [CodeCompletion] Code complete the '__auto_type' keyword
rdar://29219185

llvm-svn: 295003
2017-02-13 23:35:59 +00:00
Alex Lorenz 8f4d399c99 [CodeCompletion] Code complete the missing C++11 keywords
This commit adds context sensitive code completion support for the C++11
keywords that currently don't have completion results.

The following keywords are supported by this patch:

alignas
constexpr
static_assert
noexcept (as a function/method qualifier)
thread_local

The following special identifiers are also supported:

final (as a method qualifier or class qualifier)
override

rdar://29219185

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

llvm-svn: 295001
2017-02-13 23:19:40 +00:00
Reid Kleckner 9de921470d [CodeGen] Treat auto-generated __dso_handle symbol as HiddenVisibility
Fixes https://bugs.llvm.org/show_bug.cgi?id=31932

Based on a patch by Roland McGrath

Reviewed By: phosek

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

llvm-svn: 294978
2017-02-13 18:49:21 +00:00
Benjamin Kramer 8484a326fb [ASTUnit] Clear out diagnostic state after creating the preamble.
If the preamble had diagnostic state this would leave behind invalid
state in the DiagnosticsEngine and crash later. The test case runs into
an assertion in DiagnosticsEngine::setSourceManager.

llvm-svn: 294963
2017-02-13 16:16:43 +00:00
Davide Italiano 945de43dbe [PM] Add support for instrumented PGO in the new pass manager (clang-side)
Differential Revision:  https://reviews.llvm.org/D29309

llvm-svn: 294961
2017-02-13 16:07:05 +00:00
Gor Nishanov bbe1c07387 [coroutines] NFC: Refactor Sema::CoroutineBodyStmt construction.
Summary:
Sema::CheckCompletedCoroutineBody was growing unwieldy with building all of the substatements. Also, constructors for CoroutineBodyStmt had way too many parameters.

Instead,  CoroutineBodyStmt now defines CtorArgs structure with all of the required construction parameters.
CheckCompleteCoroutineBody delegates construction of individual substatements to short functions one per each substatement.

Also, added a drive-by fix of initializing CoroutinePromise to nullptr in ScopeInfo.h.
And addressed the FIXME that wanted to tail allocate extra room at the end of the CoroutineBodyStmt to hold parameter move expressions. (The comment was longer that the code that implemented tail allocation).

Reviewers: rsmith, EricWF

Subscribers: mehdi_amini, cfe-commits

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

llvm-svn: 294933
2017-02-13 05:05:02 +00:00
Aaron Ballman e826cbf4f3 Revert r294910 and recommit r294861 and r294862 with a target triple to hopefully appease the bots.
llvm-svn: 294911
2017-02-12 19:24:47 +00:00
Renato Golin 510f37cc7d Revert "Attributes on K&R C functions should not cause incompatible..."
...function type with a redeclaration having the same attribute. Fixing this
introduced a secondary problem where we were assuming that K&R functions
could not be attributed types when reporting old-style function definitions
that are not preceded by a prototype."

Also Revert "Hopefully fixes a compile error introduced by r294861."

This reverts commit r294862, r294861, as they bork the ARM builds and
haven't fix it back.

Also, please, short commit titles, long commit decsriptions...

llvm-svn: 294910
2017-02-12 19:08:02 +00:00
David Blaikie ac4345c303 ASTReader: Refactor common code for writing function definitions, to match the writing code
llvm-svn: 294904
2017-02-12 18:45:31 +00:00
Davide Italiano 4efbbce4d1 [Driver] Use stem() and not filename().
On Windows the filename might have an extension, namely
`.exe`, so the search will fail. Sorry, I don't have a
good way to test this as it seems to fail only in some
weird configurations. r284430 has the same modification
for Fuchsia.

llvm-svn: 294879
2017-02-11 23:44:37 +00:00
Saleem Abdulrasool 40db4772bd CodeGen: use # as the comment leader for ARC marker
Use # as the comment leader for AArch64 auto-release elision marker.
This is to keep it in sync with the value used in swift.  When building
libdispatch for Linux AArch64, the auto-release elision marker was
emitted.  However, ELF uses # as the comment leader while MachO accepts
both ; and #.  Use the common marker for it instead.

llvm-svn: 294877
2017-02-11 23:03:13 +00:00
Saleem Abdulrasool c30cec26ed CodeGen: annotate ObjC ARC functions with ABI constraints
Certain ARC runtime functions have an ABI contract of being forwarding.
Annotate the functions with the appropriate `returned` attribute on the
arguments.  This hoists some of the runtime ABI contract information
into the frontend rather than the backend transformations.

The test adjustments are to mark the returned function parameter as
such.  The minor change to the IR output is due to the fact that the
returned reference of the object causes it to extend the lifetime of the
object by returning an autoreleased return value.  The result is that
the explicit objc_autorelease call is no longer formed, as autorelease
elision is now possible on the return.

llvm-svn: 294872
2017-02-11 21:34:18 +00:00
Dylan McKay 315edb0216 [AVR] Fix __AVR_xxx macro definitions; authored by Peter Wu
Summary:
The -mmcu option for GCC sets macros like __AVR_ATmega328P__ (with the trailing
underscores), be sure to include these underscores for Clangs -mcpu option.

See "AVR Built-in Macros" in https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html

Reviewers: jroelofs, dylanmckay

Reviewed By: jroelofs, dylanmckay

Subscribers: efriedma, cfe-commits

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

llvm-svn: 294869
2017-02-11 21:06:07 +00:00
Aaron Ballman 3dcb85b01f Attributes on K&R C functions should not cause incompatible function type with a redeclaration having the same attribute. Fixing this introduced a secondary problem where we were assuming that K&R functions could not be attributed types when reporting old-style function definitions that are not preceded by a prototype.
This patch fixes PR31020.

llvm-svn: 294861
2017-02-11 17:49:53 +00:00
Saleem Abdulrasool 5b1f0edf2d docs: update docs for objc_storeStrong behaviour
objc_storeStrong does not return a value.

llvm-svn: 294855
2017-02-11 17:24:09 +00:00
Saleem Abdulrasool e60561c073 CodeGen: rename variables to adhere to naming convention
Adjust style before making more intrusive changes.  NFC.

llvm-svn: 294854
2017-02-11 17:24:07 +00:00
Saleem Abdulrasool b893ed26ec Sema: simplify conditional execution (NFC)
The conditional cast is unnecessary since we know that it will always
succeed.  NFC.

llvm-svn: 294853
2017-02-11 17:24:04 +00:00
Benjamin Kramer 357c9e1a4b Make helpers static. NFC.
llvm-svn: 294838
2017-02-11 12:21:17 +00:00
George Burgess IV f9013bf8f0 Don't let EvaluationModes dictate whether an invalid base is OK
What we want to actually control this behavior is something more local
than an EvalutationMode. Please see the linked revision for more
discussion on why/etc.

This fixes PR31843.

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

llvm-svn: 294800
2017-02-10 22:52:29 +00:00
Richard Smith bfbff07e73 [c++1z] Diagnose attempts to use variables with deduced class template
specialization types from within their own initializers.

llvm-svn: 294796
2017-02-10 22:35:37 +00:00
Richard Smith d69f4f5b05 [c++1z] Require an initializer for deduced class template specialization types.
It's actually meaningful and useful to allow such variables to have no
initializer, but we are strictly following the standard here until the C++
committee reaches consensus on allowing this.

llvm-svn: 294785
2017-02-10 21:40:29 +00:00
Tim Shen 918ed871df [XRay] Implement powerpc64le xray.
Summary:
powerpc64 big-endian is not supported, but I believe that most logic can
be shared, except for xray_powerpc64.cc.

Also add a function InvalidateInstructionCache to xray_util.h, which is
copied from llvm/Support/Memory.cpp. I'm not sure if I need to add a unittest,
and I don't know how.

Reviewers: dberris, echristo, iteratee, kbarton, hfinkel

Subscribers: mehdi_amini, nemanjai, mgorny, llvm-commits

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

llvm-svn: 294781
2017-02-10 21:03:24 +00:00
Richard Smith 278890f85b [c++1z] Enforce restriction that deduction guide is declared in the same scope as its template.
llvm-svn: 294778
2017-02-10 20:39:58 +00:00
Richard Smith 3817e4a40c [c++1z] Disallow deduction guides with deduced types that don't syntactically match the template being deduced.
llvm-svn: 294773
2017-02-10 19:49:50 +00:00
Nico Weber 2108880660 clang-format: don't break code using __has_include, PR31908
llvm-svn: 294772
2017-02-10 19:36:52 +00:00
Simon Pilgrim 463cb8ac30 Wdocumentation fixes
llvm-svn: 294740
2017-02-10 12:14:01 +00:00
Eric Christopher f6ee1f3d69 Temporarily revert "For X86-64 linux and PPC64 linux align int128 to 16 bytes."
until we can get better TargetMachine::isCompatibleDataLayout to compare - otherwise
we can't code generate existing bitcode without a string equality data layout.

This reverts commit r294703.

llvm-svn: 294708
2017-02-10 04:35:21 +00:00
Eric Christopher 4855ba8f24 For X86-64 linux and PPC64 linux align int128 to 16 bytes.
For other platforms we should find out what they need and likely
make the same change, however, a smaller additional change is easier
for platforms we know have it specified in the ABI.

clang support for r294702

llvm-svn: 294703
2017-02-10 03:32:34 +00:00
Richard Smith a2c581f42f [c++1z] In class template argument deduction, all declarators must deduce the same type (just like with auto deduction).
llvm-svn: 294700
2017-02-10 03:27:13 +00:00
Hubert Tong 5a8ec4e287 [Concepts] Class template associated constraints
Summary:
This adds associated constraints as a property of class templates.
An error is produced if redeclarations are not similarly constrained.

Reviewers: rsmith, faisalv, aaron.ballman

Reviewed By: rsmith

Subscribers: cfe-commits, nwilson

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

llvm-svn: 294697
2017-02-10 02:46:19 +00:00
Richard Smith afe4aa8b2c [c++1z] P0512R0: support for 'explicit' specifier on deduction-guides.
llvm-svn: 294693
2017-02-10 02:19:05 +00:00
Richard Smith 78e3d70135 Sink IsExplicitSpecified flag from CXXConstructorDecl and CXXConversionDecl
into FunctionDecl. Makes CXXConversionDecl 8 bytes smaller. No functionality
change intended.

llvm-svn: 294684
2017-02-10 01:32:04 +00:00
Eric Christopher cdbfd0edb5 Update C style comments to C++ style.
llvm-svn: 294680
2017-02-10 00:20:26 +00:00
David Blaikie 8677e04240 Fix the -Werror build by removing an unused default in a fully covered switch
llvm-svn: 294676
2017-02-10 00:06:38 +00:00
George Burgess IV fc9705679e Add support for armv7ve flag in clang (PR31358).
This is a followup change to add v7ve support to clang for gcc
compatibility. Please see r294661.

Patch by Manoj Gupta.

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

llvm-svn: 294662
2017-02-09 23:30:10 +00:00
Richard Smith 19a311a483 Disallow explicit instantiation and explicit specialization for deduction guides.
llvm-svn: 294641
2017-02-09 22:47:51 +00:00
Richard Smith 3af700977b Diagnose attempts to explicitly instantiate a template at class scope. Previously Clang would simply ignore the 'template' keyword in this case.
llvm-svn: 294639
2017-02-09 22:14:25 +00:00
Amjad Aboud 546bc1103b [DebugInfo] Added support to Clang FE for generating debug info for preprocessor macros.
Added "-fdebug-macro" flag (and "-fno-debug-macro" flag) to enable (and to disable) emitting macro debug info.
Added CC1 "-debug-info-macro" flag that enables emitting macro debug info.

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

llvm-svn: 294637
2017-02-09 22:07:24 +00:00
Davide Italiano 05f25fa950 [CodeGen] Remove unneeded `private`. NFCI.
llvm-svn: 294623
2017-02-09 21:19:51 +00:00
Richard Smith f445f196ae Rename IsExplicitSpecialization -> IsMemberSpecialization when we're talking
about member specializations to avoid ambiguous and confusing terminology.

llvm-svn: 294622
2017-02-09 21:04:43 +00:00
Richard Smith 60437620db [c++1z] P0091R3: Basic support for deducing class template arguments via deduction-guides.
llvm-svn: 294613
2017-02-09 19:17:44 +00:00
Reid Kleckner 04f9f91da6 [MS] Implement the __fastfail intrinsic as a builtin
__fastfail terminates the process immediately with a special system
call. It does not run any process shutdown code or exception recovery
logic.

Fixes PR31854

llvm-svn: 294606
2017-02-09 18:31:06 +00:00
Marcos Pividori 147f62fc0b [windows] [asan] Add wholearchive flag when including asan_cxx lib.
We need -wholearchive for asan_cxx, the same than for asan.
Clang Driver will add asan_cxx at the beginning of the arg list that we pass to
the linker. To ensure that all the static libraries are linked to asan_cxx, we
force the linker to include the object files in asan_cxx.

This fixes some linker errors when compiling with address sanitizer for MT and
passing the static library libFuzzer.

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

llvm-svn: 294604
2017-02-09 18:22:35 +00:00
Krasimir Georgiev b8b987f508 [clang-format] Fix typo in comment.
llvm-svn: 294570
2017-02-09 09:02:13 +00:00
Craig Topper 4574226c3f [X86] Clzero flag addition and inclusion under znver1
1. Adds the command line flag for clzero.
2. Includes the clzero flag under znver1.
3. Defines the macro for clzero.
4. Adds a new file which has the intrinsic definition for clzero instruction.

Patch by Ganesh Gopalasubramanian with some additional tests from me.

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

llvm-svn: 294559
2017-02-09 06:10:14 +00:00
David Blaikie ee12322372 Initialize builtins during modular codegen
llvm-svn: 294512
2017-02-08 20:51:11 +00:00
Richard Smith ef2cd8f8c3 More fixes for places where 'decltype(auto)' is permitted in the C++ grammar but makes no sense.
llvm-svn: 294509
2017-02-08 20:39:08 +00:00
Richard Smith 3f846bd9fe Don't crash on 'decltype(auto)::'. Rather than treating it as a meaningless
nested-name-specifier (as the standard appears to require), treat it as the
type specifier 'decltype(auto)' followed by a nested-name-specifier starting
with '::'.

llvm-svn: 294506
2017-02-08 19:58:48 +00:00
Reid Kleckner a858981c1d [MS] Fix C++ destructor thunk line info for a declaration
Sometimes the MS ABI needs to emit thunks for declarations that don't
have bodies. Destructor thunks make calls to inlinable functions, so
they need line info or LLVM will complain.

Fixes PR31893

llvm-svn: 294465
2017-02-08 16:09:32 +00:00
Krasimir Georgiev 2091a3a0b9 [clang-format] Move OriginalPrefix from base to subclass.
Summary:
OriginalPrefix is only needed for line comment sections. Moved from the base class to the child class.
No functional changes.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 294457
2017-02-08 14:45:19 +00:00
Krasimir Georgiev f62f958a58 [clang-format] Break before a sequence of line comments aligned with the next line.
Summary:
Make the comment alignment respect sections of line comments originally alinged
with the next token. Until now the decision how to break a continuous sequence
of line comments into sections was taken without reference to the next token.

source:
```
class A {
public: // comment about public
  // comment about a
  int a;
}
```

format before:
```
class A {
public: // comment about public
        // comment about a
  int a;
}
```

format after:
```
class A {
public: // comment about public
  // comment about a
  int a;
}
```

Reviewers: djasper, klimek

Reviewed By: klimek

Subscribers: cfe-commits, klimek

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

llvm-svn: 294435
2017-02-08 10:30:44 +00:00
Craig Topper d2bf7b03e5 [X86] Add -mprefetchwt1/-mno-prefetchwt1 command line options and __PREFETCHWT1__ define to match gcc.
llvm-svn: 294424
2017-02-08 08:23:40 +00:00
Craig Topper 204ecffdb4 [X86] Add -msgx/-mno-sgx command line options and __SGX__ define to match gcc.
llvm-svn: 294423
2017-02-08 08:23:17 +00:00
Craig Topper b16cb82c93 [X86] Add -mmpx/-mno-mpx command line options and __MPX__ define to match gcc.
llvm-svn: 294419
2017-02-08 07:56:42 +00:00
Craig Topper 8c708cf6bc [X86] Add -mclwb/-mno-clwb command line arguments and __CLWB__ define to match gcc.
In the future, we should also add a clwb intrinsic to the backend, a frontend builtin, and an instrinsic header file.

llvm-svn: 294416
2017-02-08 07:36:58 +00:00
Craig Topper 32c959dab3 [X86] Remove 'umip' feature flag.
This feature flag indicates that the processor has support for removing certain instructions from user mode software. But the feature flag by itself doesn't indicate if the support is enabled in the OS. The affected instructions aren't even instructions the compiler would emit. So I don't think think this feature flag should be in the compiler.

llvm-svn: 294414
2017-02-08 07:13:22 +00:00
Craig Topper 78b4787593 [X86] Add -mclflushopt/-mno-clflushopt command line support and __CLFLUSHOPT__ define to match gcc.
llvm-svn: 294411
2017-02-08 06:48:58 +00:00
Craig Topper 7d494ef610 Use LLVM_FALLTHROUGH instead of FALLTHROUGH comments.
llvm-svn: 294404
2017-02-08 05:44:30 +00:00
Craig Topper c31d9e4a01 [X86] Remove PCOMMIT feature support since Intel has deprecated this instruction with no plans to release products with it.
Intel's documentation for the deprecation https://software.intel.com/en-us/blogs/2016/09/12/deprecate-pcommit-instruction

llvm-svn: 294403
2017-02-08 05:44:28 +00:00
Dylan McKay e8232d73f5 [AVR] Add support for the 'interrupt' and 'naked' attributes
Summary:
This teaches clang how to parse and lower the 'interrupt' and 'naked'
attributes.

This allows interrupt signal handlers to be written.

Reviewers: aaron.ballman

Subscribers: malcolm.parsons, cfe-commits

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

llvm-svn: 294402
2017-02-08 05:09:26 +00:00
Saleem Abdulrasool a6ae060db4 Sema: add warning for c++ member variable shadowing
Add a warning for shadowed variables across records.  Referencing a
shadow'ed variable may not give the desired variable.  Add an optional
warning for the shadowing.

Patch by James Sun!

llvm-svn: 294401
2017-02-08 03:30:13 +00:00
Richard Smith c88aa3f3a6 Diagnose an attempt to give a deduction-guide a function body.
llvm-svn: 294397
2017-02-08 01:27:29 +00:00
Richard Smith 8f8697f3e1 Fix constructor declarator detection for the case when the name is followed by
an attribute-specifier-seq. (Also fixes the same problem for deduction-guides.)

llvm-svn: 294396
2017-02-08 01:16:55 +00:00
Richard Smith f283fdcd50 P0091R3: Improved syntactic checking of deduction-guides.
llvm-svn: 294395
2017-02-08 00:35:25 +00:00
Bruno Cardoso Lopes 15300655ab [ASTReader] Improve ReadASTBlock error message when module not available
Point to the PCM file that could not be found.

rdar://problem/30381981

llvm-svn: 294362
2017-02-07 21:55:02 +00:00
Bruno Cardoso Lopes 17da34d2bd [PCH] Fix a regression when PCH is used with -fmodules
Following up on r291465 after a regression in r276159. When we use
-fmodule-name=X while building a PCH, modular headers in X will be
textually included and the compiler knows that we are not building
module X, so don't serialize such headers in the PCH as being part of a
module, because at this point they are not.

This was causing subtle bugs and malformed AST crashes, for instance,
when using the PCH in subsequent compiler invocation with -fmodules, the
HFI for a modular header would map to the PCH, which would force a
module load of and unexistent module ID.

rdar://problem/30171164

llvm-svn: 294361
2017-02-07 21:54:57 +00:00
Vassil Vassilev a2c2d94dcb Enable -dump-deserialized-decls and -error-on-deserialized-decl for modules.
llvm-svn: 294359
2017-02-07 21:49:41 +00:00
Daniel Jasper 697a8ec6cd clang-format: Fix bad variable declaration detection.
Before:
  LooooooooooooooooongType
  variable(nullptr, [](A *a) {});

After:
  LooooooooooooooooongType
      variable(nullptr, [](A *a) {});

llvm-svn: 294358
2017-02-07 21:38:16 +00:00
Saleem Abdulrasool 5602709b98 Revert "Basic: match GCC behaviour for SuS macro"
This reverts commit SVN r294148.  Seems that it was mistaken, and GCC
does still define `__unix` and `unix` when in GNU mode.

llvm-svn: 294332
2017-02-07 19:00:06 +00:00
Martin Probst 8e3eba0373 clang-format: [JS] correcly format object literal methods.
Summary:
In JavaScript, object literals can contain methods:

   var x = {
     a() { return 1; },
   };

Previously, clang-format always parsed nested {} inside a braced list as
further braced lists. Special case this logic for JavaScript to try
parsing as a braced list, but fall back to parsing as a child block.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 294315
2017-02-07 16:33:13 +00:00
Anastasia Stulova 32f0a4330a [OpenCL] Accept logical NOT for pointer types in CL1.1
Fix for bug 30217 - incorrect error given for logical
NOT operation with a pointer type: corrected sema check
and improved related tests.

Review: D29038
llvm-svn: 294313
2017-02-07 16:09:41 +00:00
Martin Probst 16282993b7 clang-format: [JS] exclaim preceding regex literals.
Summary:
Regex detection would incorrectly classify a trailing `!` operator
(nullability cast) followed by a `/` as the start of a regular
expression literal. This fixes code such as:

    var foo = x()! / 10;

Which would previously parse a regexp all the way to the end of the
source file (or next `/`).

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 294304
2017-02-07 14:08:03 +00:00
Martin Probst 1027fb8a06 clang-format: [JS] handle parenthesized class expressions.
Summary:
In JavaScript, classes are expressions, so they can appear e.g. in
argument lists.

    var C = foo(class {
      bar() {
        return 1;
      }
    };

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 294302
2017-02-07 14:05:30 +00:00
Dylan McKay ecb6e7b83c Revert "Revert "[AVR] Allow specifying the CPU on the command line""
This reverts commit 7ac30e0f839fdab6d723ce2ef6a5b7a4cf03d150.

llvm-svn: 294282
2017-02-07 06:04:18 +00:00
Peter Collingbourne 8e6a25feca Driver: Do not link safestack with --whole-archive.
This allows it to be used with the other sanitizers.

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

llvm-svn: 294274
2017-02-07 03:21:57 +00:00
Richard Smith 3584515018 P0091R3: Implement basic parsing support for C++17 deduction-guides.
We model deduction-guides as functions with a new kind of name that identifies
the template whose deduction they guide; the bulk of this patch is adding the
new name kind. This gives us a clean way to attach an extensible list of guides
to a class template in a way that doesn't require any special handling in AST
files etc (and we're going to need these functions we come to performing
deduction).

llvm-svn: 294266
2017-02-07 01:37:30 +00:00
Ulrich Weigand 82a86cb155 [SystemZ] Provide predefined __ARCH__ and __VX__ macros
GCC 7 will predefine two new macros on s390x:

- __ARCH__ indicates the ISA architecture level
- __VX__ indicates that the vector facility is available

This adds those macros to clang as well to ensure continued
compatibility with GCC.

llvm-svn: 294197
2017-02-06 17:04:22 +00:00
Diana Picus 37a2d6d699 Revert "[AVR] Allow specifying the CPU on the command line"
This reverts commit r294177. It seems to have broken some buildbots.

llvm-svn: 294180
2017-02-06 11:35:42 +00:00
Daniel Jasper 2db1b4a177 clang-format: Fix bug with conflicting BreakBeforeBinaryOperations and AlignAfterOpenBracket
Fix for the formatting options combination of
BreakBeforeBinaryOperators: All, AlignAfterOpenBracket: AlwaysBreak not
handling long templates correctly. This patch allows a break after an
opening left parenthesis, TemplateOpener, or bracket when both options
are enabled.

Patch by Daphne Pfister, thank you!

Fixes llvm.org/PR30304.

llvm-svn: 294179
2017-02-06 10:55:49 +00:00
Dylan McKay 8464c9b579 [AVR] Allow specifying the CPU on the command line
Summary:
This tells clang about all of the different AVR microcontrollers.

It also adds code to define the correct preprocessor macros for each
device.

Reviewers: jroelofs, asl

Reviewed By: asl

Subscribers: asl, cfe-commits

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

llvm-svn: 294177
2017-02-06 09:07:56 +00:00
Dylan McKay d31534cd3a [AVR] Add support for the full set of inline asm constraints
Summary:
Previously the method would simply return false, causing every single
inline assembly constraint to trigger a compile error.

This adds inline assembly constraint support for the AVR target.

This patch is derived from the code in
AVRISelLowering::getConstraintType.

More details can be found on the AVR-GCC reference wiki
http://www.nongnu.org/avr-libc/user-manual/inline_asm.html

Reviewers: jroelofs, asl

Reviewed By: asl

Subscribers: asl, ahatanak, saaadhu, cfe-commits

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

llvm-svn: 294176
2017-02-06 09:01:59 +00:00
Saleem Abdulrasool c5cddc9fa8 Basic: match GCC behaviour for SuS macro
GCC does not generate `__unix` nor `unix` macros.  The latter already
intrudes into the user's namespace and should be avoided.  Use the
canonical spelling of `__unix__` across all the targets.

llvm-svn: 294148
2017-02-05 22:18:15 +00:00
Coby Tayree c0fb36f442 [X86][MS]Adjacent comments within multi-line inline assembly statement
Allowing adjacent comments within MS inline assembly multi-line statement

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

llvm-svn: 294120
2017-02-05 10:23:06 +00:00
Richard Smith 33c33c3e86 PR31846: Don't replace 'auto' type with a template parameter type in a generic lambda
until after we've checked whether 'auto' is valid in the current language mode.

llvm-svn: 294078
2017-02-04 01:28:01 +00:00
Matthias Braun 9e838bd142 Driver: Do not warn about unused -pthread when linking on darwin
While there is nothing to do at link time to get pthreads support on
darwin, specifying the argument is fine and we should not warn about
unused arguments.

llvm-svn: 294065
2017-02-03 23:09:31 +00:00
Daniel Jasper c06f6da34e clang-format: [JS] Fix bugs in parsing and aligning template strings.
llvm-svn: 294009
2017-02-03 14:32:38 +00:00
Alex Lorenz 776b417634 [Sema][ObjC++] Typo correction should handle ivars and properties
After r260016 and r260017 disabled typo correction for ivars and properties
clang didn't report errors about unresolved identifier in the base of ivar and
property ref expressions. This meant that clang invoked CodeGen on invalid AST
which then caused a crash.

This commit re-enables typo correction for ivars and properites, and fixes the
PR25113 & PR26486 (that were originally fixed in r260017 and r260016) in a
different manner by transforming the Objective-C ivar reference expression with
'IsFreeIvar' preserved.

rdar://30310772

llvm-svn: 294008
2017-02-03 14:22:33 +00:00
Krasimir Georgiev d105b72df6 [clang-format] Re-align broken comment lines where appropriate.
Summary:
The comment aligner was skipping over newly broken comment lines. This patch fixes that.

source:
```
int ab; // line
int a; // long long
```

format with column limit 15 before:
```
int ab; // line
int a;  // long
       // long
```

format with column limit 15 after:
```
int ab; // line
int a;  // long
        // long
```

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 293997
2017-02-03 10:18:25 +00:00
Daniel Jasper da910e0a8b clang-format: [Proto] Also supports implicit string literal concatenation
llvm-svn: 293995
2017-02-03 08:29:02 +00:00
Reid Kleckner bf18355d5c Revert "[Driver] Updated for Visual Studio 2017"
This reverts commit r293923. It causes test failures on Linux that need
time to debug.

llvm-svn: 293924
2017-02-02 19:36:22 +00:00
Reid Kleckner 723fabfcdf [Driver] Updated for Visual Studio 2017
Summary:
The patch updates the MSVC ToolChain for the changes made in Visual
Studio 2017[1].

Other notable changes:
  - Path handling code has been centralised to make potential future
    changes less painful.
  - A compiler error is emitted if the driver is unable to locate a
    usable MSVC toolchain. (Previously it'd fail with a cryptic error
    such as "link.exe is not executable")
  - Support for the new Setup Config Server API[2] has been added,
    albeit block commented out with a preprocessor conditional. This can
    probably be re-evaluated when the API is officially released (it's
    currently at the RC stage), but it's left in to make it easy for
    anyone familiar with the API to give it a go with Clang.

Patch by Hamza Sood.

[1] https://blogs.msdn.microsoft.com/vcblog/2016/10/07/compiler-tools-layout-in-visual-studio-15/
[2] https://blogs.msdn.microsoft.com/heaths/2016/09/15/changes-to-visual-studio-15-setup/

Reviewers: ruiu, hans, rnk

Reviewed By: rnk

Subscribers: awson, RKSimon, amccarth, cfe-commits

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

llvm-svn: 293923
2017-02-02 19:29:46 +00:00
Warren Ristow 8d17b40500 Prevent ICE in dllexport class with _Atomic data member
Guard against a null pointer dereference that caused Clang to crash
when processing a class containing an _Atomic qualified data member,
and that is tagged with 'dllexport'.

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

llvm-svn: 293911
2017-02-02 17:53:34 +00:00
Argyrios Kyrtzidis 5b7a09aca4 [index] Provide a more general index::generateUSRForMacro() that doesn't depend on having a PreprocessingRecord.
llvm-svn: 293904
2017-02-02 16:13:10 +00:00
Krasimir Georgiev 00c5c72d0e [clang-format] Don't reflow across comment pragmas.
Summary:
The comment reflower wasn't taking comment pragmas as reflow stoppers. This patch fixes that.

source:
```
// long long long long
// IWYU pragma:
```
format with column limit  = 20 before:
```
// long long long
// long IWYU pragma:
```
format with column limit  = 20 after:
```
// long long long
// long
// IWYU pragma:
```

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 293898
2017-02-02 15:32:19 +00:00
Krasimir Georgiev b6ccd38dee [clang-format] Fix breaking of comment sections in unwrapped lines containing newlines.
Summary:
The breaking of line comment sections was misaligning the case where the first comment line is on an unwrapped line containing newlines. In this case, the breaking column must be based on the source column of the last token that is preceded by a newline, not on the first token of the unwrapped line.

source:
```
enum A {
  a, // line 1
  // line 2
};
```
format before:
```
enum A {
  a, // line 1
     // line 2
};
```
format after:
```
enum A {
  a, // line 1
  // line 2
};
```

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 293891
2017-02-02 14:36:50 +00:00
Krasimir Georgiev 28912c09b2 [clang-format] Don't reflow lines starting with TODO, FIXME or XXX.
Summary: These lines commonly carry a special meaning.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 293878
2017-02-02 10:52:08 +00:00
Daniel Jasper c3aa05c01b clang-format: Do not use two-argument/operand special case with no alignment
Without alignment, there is no clean separation between the arguments, even if
there are only two.

Before:
  aaaaaaaaaaaaaa(
      aaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
          aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

After:
  aaaaaaaaaaaaaa(aaaaaaaaaaaa,
                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
                     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

llvm-svn: 293875
2017-02-02 08:30:21 +00:00
Gabor Horvath 3b008536f3 [analyzer] Fix an assertion fail in CStringSyntaxChecker.
Differential Revision: https://reviews.llvm.org/D29384

llvm-svn: 293874
2017-02-02 08:20:54 +00:00
George Burgess IV 5731707668 Fix typo. NFC
llvm-svn: 293871
2017-02-02 07:53:55 +00:00
Saleem Abdulrasool 8de4e87305 CodeGen: add a LLVM_FALLTHROUGH to a fallthrough (NFC)
Drive by cleanup noticed while investigating an IR verifier assertion.

llvm-svn: 293867
2017-02-02 05:45:43 +00:00
Duncan P. N. Exon Smith 1116d6915c Modules: Simplify CompilerInstance constructor, NFC
Initialize fields directly in header.  Note that the ModuleManager field is an
IntrusiveRefCntPtr, so there's no need for explicit initialization.

llvm-svn: 293863
2017-02-02 05:09:51 +00:00
Daniel Jasper b127039c77 clang-format: Fix incorrect line breaks after forced operator wraps.
Before:
  bool x = aaaaa //
           ||
           bbbbb
           //
           || cccc;

After:
  bool x = aaaaa //
           || bbbbb
           //
           || cccc;

llvm-svn: 293839
2017-02-01 23:27:37 +00:00
Dehao Chen 5a3f890e06 Change debug-info-for-profiling from a TargetOption to a function attribute.
Summary: cfe change for https://reviews.llvm.org/D29203

Reviewers: echristo, dblaikie

Reviewed By: dblaikie

Subscribers: mehdi_amini, cfe-commits

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

llvm-svn: 293834
2017-02-01 22:45:21 +00:00
Richard Smith 3411fbff0b Repoint 'missing typename' diagnostic to the location where 'typename' should be added.
llvm-svn: 293817
2017-02-01 21:41:18 +00:00
Richard Smith 62559bd7ce Fix hole in our enforcement of rule requiring 'typename' prior to a dependent
name. If the dependent name happened to end in a template-id (X<T>::Y<U>), we
would fail to notice that the 'typename' keyword is missing when resolving it
to a type.

It turns out that GCC has a similar bug. If this shows up in much real code, we
can easily downgrade this to an ExtWarn.

llvm-svn: 293815
2017-02-01 21:36:38 +00:00
Akira Hatanaka 034c6337e5 [Sema][ObjC] Don't pass a DeclRefExpr that doesn't reference a VarDecl
to WeakObjectProfileTy's constructor.

This fixes an assertion failure in WeakObjectProfileTy's constructor.

rdar://problem/30112633

llvm-svn: 293808
2017-02-01 20:22:26 +00:00
Hans Wennborg 9d17df8b46 Drop 'dllimport' when redeclaring inline function template without the attribute (PR31695)
For non-template dllimport functions, MSVC allows providing an inline
definition without spelling out the attribute again. In the example below, f
remains a dllimport function.

  __declspec(dllimport) int f();
  inline int f() { return 42; }

  int useit() {
    return f();
  }

However, for a function template, not putting dllimport on the redeclaration
causes it to be dropped. In the example below, f is not dllimport.

  template <typename> __declspec(dllimport) int f();
  template <typename> inline int f() { return 42; }

  int useit() {
    return f<int>();
  }

This patch makes Clang match MSVC for the second example.

MSVC does not warn about the attribute being dropped in the example above, but
I think we should. (MSVC does warn if the inline keyword isn't used.)

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

llvm-svn: 293800
2017-02-01 18:52:53 +00:00
Alex Lorenz 86d3232daf [CodeGen][ObjC] Avoid asserting on block pointer types in
isPointerZeroInitializable

rdar://30111891

llvm-svn: 293787
2017-02-01 17:37:28 +00:00
Krasimir Georgiev 13dbaa09e5 [clang-format] Fix regression about not aligning trailing comments in case they were previously aligned, but at different indent.
Summary:
Comment reflower was adding untouchable tokens in case two consecutive comment lines are aligned in the source code. This disallows the whitespace manager to re-indent them later.

source:
```
int i = f(abc, // line 1
          d, // line 2
	     // line 3
	  b);
```
Since line 2 and line 3 are aligned, the reflower was marking line 3 as untouchable; however the three comment lines need to be re-aligned.
output before:
```
int i = f(abc, // line 1
          d,   // line 2
	     // line 3
	  b);
```
output after:
```
int i = f(abc, // line 1
          d,   // line 2
	       // line 3
	  b);
```

Reviewers: djasper

Reviewed By: djasper

Subscribers: sammccall, cfe-commits, klimek

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

llvm-svn: 293755
2017-02-01 10:10:04 +00:00
Daniel Jasper 21f7dea5f5 clang-format: Don't force-wrap multiline RHSs for 2-operand experssions.
This rows back on r288120, r291801 and r292110. I apologize in advance
for the churn. All of those revisions where meant to make the wrapping
of RHS expressions more consistent. However, now that they are
consistent, we seem to be a bit too eager.

The reasoning here is that I think it is generally correct that we want
to line-wrap before multiline RHS expressions (or multiline arguments to
a function call). However, if there are only two of such operands or
arguments, there is always a clear vertical separation between them and
the additional line break seems much less desirable.

Somewhat good examples are expressions like:

  EXPECT_EQ(2, someLongExpression(
                   orCall));

llvm-svn: 293752
2017-02-01 09:23:39 +00:00
Ekaterina Romanova ae7b82eaf8 Doxygen comments for prfchwintrin.h
Added doxygen comments to prfchwintrin.h's intrinsics. 

Note: The doxygen comments are automatically generated based on Sony's intrinsic
s document.

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

llvm-svn: 293745
2017-02-01 07:37:40 +00:00
Richard Smith 776e9c35b5 Remove apparently-unnecessary copy of constructor lookup result.
Contrary to the comment, DeclContext intends to guarantee that the lookup
results for a particular name will be stable across non-AST-mutating
operations, so a copy here should not be necessary. Further, if a copy *is*
necessary, the other four instances of this pattern within this file would also
be wrong, and we have no evidence of any problems with them; if this change
unearths problems, we should fix all the instances of this pattern.

llvm-svn: 293740
2017-02-01 03:28:59 +00:00
Hans Wennborg 27dcc6c0e2 clang-cl: Evaluate arguments left-to-right in constructor call with initializer list (PR31831)
clang-cl would evaluate the arguments right-to-left (see PR), and for
non-Windows targets I suppose we only got it because we were already
emitting left-to-right in CodeGenFunction::EmitCallArgs.

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

llvm-svn: 293732
2017-02-01 02:21:07 +00:00
David Blaikie 4d92301075 Fix modules codegen to be compatible with modules-ts
The Module::WithCodegen flag was only being set when the module was
parsed from a ModuleMap. Instead set it late, in the ASTWriter to match
the layer where the MODULAR_CODEGEN_DECLs list is determined (the
WithCodegen flag essentially means "are this module's decls in
MODULAR_CODEGEN_DECLs").

When simultaneous emission of AST file and modular object is implemented
this may need to change - the Module::WithCodegen flag will need to be
set earlier, and ideally the MODULAR_CODEGEN_DECLs gathering will
consult this flag (that's not possible right now since Decls destined
for an AST File don't have a Module - only if they're /read/ from a
Module is that true - I expect that would need to change as well).

llvm-svn: 293692
2017-01-31 21:28:19 +00:00
Akira Hatanaka 59e3b43abc [Sema] Transform a templated name before looking it up in
FindInstantiatedDecl or passing it to RebuildMemberExpr.

This fixes PR30361.

rdar://problem/17341274

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

llvm-svn: 293678
2017-01-31 19:53:32 +00:00
Reid Kleckner 0b009e8269 Extend -Wcast-calling-convention to warn on declarations as well as definitions
My original warning was very conservative and I never revisited the
heuristics that were used.

This would have caught http://crbug.com/687251 at compile time.

llvm-svn: 293677
2017-01-31 19:37:45 +00:00
Nico Weber 9e2bc306ba Keep Chromium ObjC column limit at 80 for consistency with C++
https://reviews.llvm.org/D29337
Patch from Dan Beam <dbeam@chromium.org>!

llvm-svn: 293675
2017-01-31 18:42:05 +00:00
Marcos Pividori 7eeaf90193 [windows] [asan] Add wholearchive flag when including static lib asan.
In Windows, when the sanitizer is implemented as a static library, we use
auxiliary static library dll_thunk that will be linked to the dlls that have
instrumentation, so they can refer to the runtime in the main executable.
It uses interception to get a pointer the function in the main executable and
override its function with that pointer.
Because of that, we need to ensure that the main executable exports all the
sanitizers' interface, otherwise the initialization in dll_thunk will fail.

In this commit we add the flag -wholearchive to clang driver to ensure that
the linker does not omit any object files from asan library.

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

llvm-svn: 293668
2017-01-31 18:31:38 +00:00
Nirav Dave 0c86ccf4b4 [X86] Teach Clang about -mfentry flag
Replace mcount calls with calls to fentry.

Reviewers: hfinkel, craig.topper

Subscribers: llvm-commits

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

llvm-svn: 293649
2017-01-31 17:00:35 +00:00
Krasimir Georgiev b796cebf3f [clang-format] Fix regression about adding leading whitespace to the content of line comments
Summary:
The reflower didn't measure precisely the line column of a line in the middle of
a line comment section that has a prefix that needs to be adapted.

source:
```
/// a
//b
```

format before:
```
/// a
 //b
```

format after:
```
/// a
// b
```

Reviewers: djasper

Reviewed By: djasper

Subscribers: sammccall, cfe-commits, klimek

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

llvm-svn: 293641
2017-01-31 15:40:15 +00:00
Daniel Jasper 3f11941d8a clang-format: [JS] Indent expressions in ${} relative to their surrounding
This only affects expressions inside ${} scopes of template strings.
Here, we want to indent relative to the surrounding template string and
not the surrounding expression. Otherwise, this can create quite a mess.

Before:
  var f = `
    aaaaaaaaaaaaaaaaaa: ${someFunction(
      aaaaa +  //
      bbbb)}`;

After:
  var f = `
    aaaaaaaaaaaaaaaaaa: ${someFunction(
                              aaaaa +  //
                              bbbb)}`;

llvm-svn: 293636
2017-01-31 14:39:33 +00:00
Krasimir Georgiev af1b9622d4 [clang-format] Fix reflow in block comment lines with leading whitespace.
Summary:
The reflower was not taking into account the additional  leading whitespace in block comment lines.

source:
```
{
/*
 * long long long long
 *   long
 * long long long long
 */
}
```

format (with column limit 20) before:
```
{
  /*
   * long long long
   * long long long long
   * long long
   */
}
```
format after:
```
{
  /*
   * long long long
   * long long long
   * long long long
   */
}
```

Reviewers: djasper, klimek

Reviewed By: djasper

Subscribers: cfe-commits, sammccall, klimek

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

llvm-svn: 293633
2017-01-31 14:31:44 +00:00
Krasimir Georgiev 753625b62e [clang-format] Fix regression merging comments across newlines.
Summary:
This fixes a regression that causes example:
```
enum A {
  a, // line a

  // line b
  b
};
```
to be formatted as follows:
```
enum A {
  a, // line a
     // line b
  b
};
```

Reviewers: djasper, klimek

Reviewed By: klimek

Subscribers: cfe-commits, sammccall, djasper, klimek

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

llvm-svn: 293624
2017-01-31 13:32:38 +00:00
Daniel Jasper 24de6fbfdb clang-format: [JS] Properly set scopes inside template strings.
Before:
  var f = `aaaaaaaaaaaaa:${aaaaaaa
              .aaaaa} aaaaaaaa
           aaaaaaaaaaaaa:${aaaaaaa.aaaaa} aaaaaaaa`;

After:
  var f = `aaaaaaaaaaaaa:${aaaaaaa.aaaaa} aaaaaaaa
           aaaaaaaaaaaaa:${aaaaaaa.aaaaa} aaaaaaaa`;

llvm-svn: 293622
2017-01-31 13:03:07 +00:00
Daniel Jasper f201929010 clang-format: [JS] Fix incorrect line break in template strings.
Before:
  var f = `aaaa ${a ? 'a' : 'b'
                            }`;

After:
  var f = `aaaa ${a ? 'a' : 'b'}`;

llvm-svn: 293618
2017-01-31 12:07:35 +00:00
Krasimir Georgiev 8f62cf74ef [clang-format] Don't reflow comment lines starting with '@'.
Summary:
This patch stops reflowing comment lines starting with '@', since they commonly
have a special meaning.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 293617
2017-01-31 11:38:02 +00:00
Daniel Jasper 7d42f3f746 [clang-format] Refactor WhitespaceManager and friends
The main motivation behind this is to cleanup the WhitespaceManager and
make it more extensible for future alignment etc. features.
Specifically, WhitespaceManager has started to copy more and more code
that is already present in FormatToken. Instead, I think it makes more
sense to actually store a reference to each FormatToken for each change.

This has as a consequence led to a change in the calculation of indent
levels. Now, we actually compute them for each Token ahead of time,
which should be more efficient as it removes an unsigned value for the
ParenState, which is used during the combinatorial exploration of the
solution space.

No functional changes intended.

Review: https://reviews.llvm.org/D29300
llvm-svn: 293616
2017-01-31 11:25:01 +00:00
Sam McCall 61e29aafa7 Revert r293585 "Add better ODR checking for modules."
We're seeing what we believe are false positives. (It's hard to tell with the
available diagnostics, and I'm not sure how to reduce them yet).
I'll send Richard reproduction details offline.

djasper/chandlerc suggested this should be a warning for now, to make rolling it
out feasible.

llvm-svn: 293611
2017-01-31 08:24:40 +00:00
Maxim Ostapenko c5d0ed5f3a [lsan] Enable LSan for x86 Linux
This is a missed part of https://reviews.llvm.org/D28609.
Enable LSan for x86 Linux in clang driver.

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

llvm-svn: 293609
2017-01-31 07:00:23 +00:00
Sam McCall 93590e09d5 In VirtualCallChecker, handle indirect calls
Summary:
In VirtualCallChecker, handle indirect calls.

getDirectCallee() can be nullptr, and dyn_cast(nullptr) is UB

Reviewers: bkramer

Subscribers: cfe-commits

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

llvm-svn: 293604
2017-01-31 05:23:20 +00:00
Matt Arsenault a274b209f5 AMDGPU: Add builtin for fmed3 intrinsic
llvm-svn: 293600
2017-01-31 03:42:07 +00:00
Akira Hatanaka bc332648e8 Handle ObjCEncodeExpr in extractStringLiteralCharacter.
This fixes an assertion failure that occurs later in the function when
an ObjCEncodeExpr is cast to StringLiteral.

rdar://problem/30111207

llvm-svn: 293596
2017-01-31 02:31:39 +00:00
Richard Smith d6cc198d53 Improve fix for PR28739
Don't try to map an APSInt addend to an int64_t in pointer arithmetic before
bounds-checking it. This gives more consistent behavior (outside C++11, we
consistently use 2s complement semantics for both pointer and integer overflow
in constant expressions) and fixes some cases where in C++11 we would fail to
properly check for out-of-bounds pointer arithmetic (if the 2s complement
64-bit overflow landed us back in-bounds).

In passing, also fix some cases where we'd perform possibly-overflowing
arithmetic on CharUnits (which have a signed underlying type) during constant
expression evaluation.

llvm-svn: 293595
2017-01-31 02:23:02 +00:00
Richard Trieu fa3d93a148 Add better ODR checking for modules.
When objects are imported for modules, there is a chance that a name collision
will cause an ODR violation.  Previously, only a small number of such
violations were detected.  This patch provides a stronger check based on
AST nodes.

The information needed to uniquely identify an object is taked from the AST and
put into a one-dimensional byte stream.  This stream is then hashed to give
a value to represent the object, which is stored with the other object data
in the module.

When modules are loaded, and Decl's are merged, the hash values of the two
Decl's are compared.  Only Decl's with matched hash values will be merged.
Mismatch hashes will generate a module error, and if possible, point to the
first difference between the two objects.

The transform from AST to byte stream is a modified depth first algorithm.
Due to references between some AST nodes, a pure depth first algorithm could
generate loops.  For Stmt nodes, a straight depth first processing occurs.
For Type and Decl nodes, they are replaced with an index number and only on
first visit will these nodes be processed.  As an optimization, boolean
values are saved and stored together in reverse order at the end of the
byte stream to lower the ammount of data that needs to be hashed.

Compile time impact was measured at 1.5-2.0% during module building, and
negligible during builds without module building.

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

llvm-svn: 293585
2017-01-31 01:44:15 +00:00
Vedant Kumar d3a601b06b Re-apply "[ubsan] Sanity-check shift amounts before truncation"
This re-applies r293343 (reverts commit r293475) with a fix for an
assertion failure caused by a missing integer cast. I tested this patch
by using the built compiler to compile X86FastISel.cpp.o with ubsan.

Original commit message:

Ubsan does not report UB shifts in some cases where the shift exponent
needs to be truncated to match the type of the shift base. We perform a
range check on the truncated shift amount, leading to false negatives.

Fix the issue (PR27271) by performing the range check on the original
shift amount.

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

llvm-svn: 293572
2017-01-30 23:38:54 +00:00
Richard Smith 642a2365fb PR28739: Check that integer values fit into 64 bits before extracting them as 64 bit values for pointer arithmetic.
This fixes various ways to tickle an assertion in constant expression
evaluation when using __int128. Longer term, we need to figure out what should
happen here: either any kind of overflow in offset calculation should result in
a non-constant value or we should truncate to 64 bits. In C++11 onwards, we're
effectively already checking for overflow because we strictly enforce array
bounds checks, but even there some forms of overflow can slip past undetected.

llvm-svn: 293568
2017-01-30 23:30:26 +00:00
Krasimir Georgiev e518e0bfe9 [clang-format] Fix regression that breaks comments without a comment prefix
Summary:
Consider formatting the following code fragment with column limit 20:
```
{
  // line 1
  // line 2\
  // long long long line
}
```
Before this fix the output is:
```
{
  // line 1
  // line 2\
  // long long
  long line
}
```
This patch fixes a regression that breaks the last comment line without
adding the '//' prefix.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 293548
2017-01-30 21:00:01 +00:00
Richard Smith ee57984c11 Towards P0091R3: parsing support for class template argument deduction in typename-specifiers.
This reinstates r293455, reverted in r293455, with a fix for cv-qualifier
handling on dependent typename-specifiers.

llvm-svn: 293544
2017-01-30 20:39:26 +00:00
Krasimir Georgiev 8432161f1d [clang-format] Separate line comment sections after a right brace from comment sections in the scope.
Summary:
The following two comment lines form a single comment section:
```
if (1) { // line 1
   // line 2
}
```
This is because the break of a comment section was based on the original column
of the first token of the previous line (in this case, the 'if').
This patch splits these two comment lines into different sections by taking into
account the original column of the right brace preceding the first line comment
where applicable.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 293539
2017-01-30 19:18:55 +00:00
Benjamin Kramer 5d4e7c089b [AST] Give TemplateArgumentLoc a constexpr ctor.
This removes the thread-safe static from
clang::TemplateTemplateParmDecl::getDefaultArgument() const::None

llvm-svn: 293523
2017-01-30 18:32:46 +00:00
Benjamin Kramer 2664a866db [IRGen] Make header standalone.
llvm-svn: 293485
2017-01-30 15:39:18 +00:00
Alex Lorenz 94c26be581 Revert "r293343 - [ubsan] Sanity-check shift amounts before truncation
(fixes PR27271)"

After r293343 clang fails to compile itself with -fsanitize=undefined (
http://lab.llvm.org:8080/green/job/clang-stage2-cmake-RgSan_build/).

rdar://30259929

llvm-svn: 293475
2017-01-30 11:37:18 +00:00
Sam McCall 4f53b51fe7 Revert r293455, which breaks v8 with a spurious error. Testcase added.
Summary: Revert r293455, which breaks v8 with a spurious error. Testcase added.

Reviewers: klimek

Subscribers: cfe-commits, rsmith

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

llvm-svn: 293473
2017-01-30 10:44:11 +00:00
Daniel Jasper 51c868e9aa clang-format: [JavaScript] Undo r291974 for JavaScript.
This had significant negative consequences and I don't have a good
solution for it yet.

Before:
  var string =
      [
        'aaaaaa',
        'bbbbbb',
      ]
          .join('+');

After:
  var string = [
    'aaaaaa',
    'bbbbbb',
  ].join('+');

llvm-svn: 293465
2017-01-30 07:08:40 +00:00
Argyrios Kyrtzidis b065ecf4f0 [index] CMake: add missing reference to clangSerialization library.
llvm-svn: 293463
2017-01-30 06:48:27 +00:00
David Blaikie b11c87324e Reapply "DebugInfo: Omit class definitions even in the presence of available_externally vtables"
Accounts for a case that caused an assertion failure by attempting to
query for the vtable linkage of a non-dynamic type.t

This reverts commit r292801.

llvm-svn: 293462
2017-01-30 06:36:08 +00:00
Argyrios Kyrtzidis a38cb204a3 [c-index-test] Provide capability to index module file imports and dump their input files.
This ensures the capability to index a module file using an existing ASTReader from a compiler instance or ASTUnit.

llvm-svn: 293461
2017-01-30 06:05:58 +00:00
David Blaikie 9ffe5a3525 Prototype of modules codegen
First pass at generating weak definitions of inline functions from module files
(& skipping (-O0) or emitting available_externally (optimizations)
definitions where those modules are used).

External functions defined in modules are emitted into the modular
object file as well (this may turn an existing ODR violation (if that
module were imported into multiple translations) into valid/linkable
code).

Internal symbols (static functions, for example) are not correctly
supported yet. The symbol will be produced, internal, in the modular
object - unreferenceable from the users.

Reviewers: rsmith

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

llvm-svn: 293456
2017-01-30 05:00:26 +00:00
Richard Smith c95726ea39 Towards P0091R3: parsing support for class template argument deduction in typename-specifiers.
llvm-svn: 293455
2017-01-30 04:38:28 +00:00
Arpith Chacko Jacob cdda3daa7f [OpenMP][NVPTX][CUDA] Adding support for printf for an NVPTX OpenMP device.
Support for CUDA printf is exploited to support printf for
an NVPTX OpenMP device.

To reflect the support of both programming models, the file
CGCUDABuiltin.cpp has been renamed to CGGPUBuiltin.cpp, and
the call EmitCUDADevicePrintfCallExpr has been renamed to
EmitGPUDevicePrintfCallExpr.

Reviewers: jlebar
Differential Revision: https://reviews.llvm.org/D17890

llvm-svn: 293444
2017-01-29 20:49:31 +00:00
Marcos Pividori b130469bc9 [windows] [asan] Add linker flag when including "asan_dynamic_runtime_thunk".
I modify clang driver for windows to include:
"-wholearchive:asan_dynamic_runtime_thunk", so all object files in the
static library: asan_dynamic_runtime_thunk are considered by the linker.
This is necessary, because some object files only include linker pragmas,
and doesn't resolve any symbol. If we don't include that flag, the
linker will ignore them, and won't read the linker pragmas.

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

llvm-svn: 293420
2017-01-29 06:03:05 +00:00
Duncan P. N. Exon Smith 688b69adf8 Modules: Fix a minor performance bug from r293393
Oops... r293393 started calling ReadSignature in
ModuleManager::addModule even when there was no ExpectedSignature.

Whether or not this would have a measurable performance impact (I
spotted this by inspection, and ReadSignature should be fairly fast), we
might as well get what we can.  Add an extra check against
ExpectedSignature to avoid the hit.

llvm-svn: 293415
2017-01-29 04:42:21 +00:00
Duncan P. N. Exon Smith 56c0e28827 Modules: Simplify the ModuleFile constructor; likely NFC
Zero-initialize ModuleFile members directly in the class definition, and
move the (now uninteresting) constructor into the class definition.

There were a few members that weren't being initialized at all.  I
zero-initialized them for consistency, but it's likely that they were
somehow initialized before their first use; i.e., there's likely no
functionality change here.

llvm-svn: 293404
2017-01-29 00:39:09 +00:00
Duncan P. N. Exon Smith 26308a68c8 Modules: Return early in ModuleManager::addModule; NFC
Invert the main branch in ModuleManager::addModule to return early and
reduce indentation, and clean up a bunch of logic as a result.  I split
out a function called updateModuleImports to avoid triggering code
duplication.

llvm-svn: 293400
2017-01-28 23:22:40 +00:00
Duncan P. N. Exon Smith 073ec35024 Modules: Clean up ModuleFile::Imports in ModuleManager::removeModules
I don't have a testcase for this (and I'm not sure if it's an observable
bug), but it seems obviously wrong that ModuleManager::removeModules is
failing to clean up deleted modules from ModuleFile::Imports.  See the
code in ModuleManager::addModule that inserts into ModuleFile::Imports;
we need the inverse operation.

llvm-svn: 293399
2017-01-28 23:12:13 +00:00
Duncan P. N. Exon Smith 8e6bc1979d Modules: Enforce that ModuleManager::removeModules deletes the tail
ModuleManager::removeModules always deletes a tail of the
ModuleManager::Chain.  Change the API to enforce that so that we can
simplify the code inside.

There's no real functionality change, although there's a slight
performance hack to loop to the First deleted module instead of the
final module in the chain (skipping the about-to-be-deleted tail).

Also document something suspicious: we fail to clean deleted modules out
of ModuleFile::Imports.

llvm-svn: 293398
2017-01-28 23:02:12 +00:00
Duncan P. N. Exon Smith a897f7cd40 Modules: Clarify ownership of ModuleFile instances in ModuleManager, NFC
Use std::unique_ptr to clarify the ownership of the ModuleFile instances in
ModuleManager.

llvm-svn: 293395
2017-01-28 22:24:01 +00:00
Duncan P. N. Exon Smith 96a06e0ec0 Modules: Return ModuleFile& from ModuleManager::begin, etc.; NFC
Hide the pointer indirection in ModuleManager::begin, ModuleManager::end,
ModuleManager::rbegin, and ModuleManager::rend.  Besides tidying up the call
sites, this is preparation for making ownership of ModuleFile explicit.

llvm-svn: 293394
2017-01-28 22:15:22 +00:00
Duncan P. N. Exon Smith 14afc8e7b8 Modules: Separate out a checkSignature helper, almost NFC
The main point is to move the delete-the-new-module logic into the same block
that creates it, so I can simplify the memory management in a follow-up, but I
think it's clearer to use use a checkSignature helper here anyway.

There is a minor functionality change: we now scan ahead to pull the signature
out of the control block *only* if this is a new ModuleFile.  For old ones,
ASTReader::ReadControlBlock will have already read the signature.

llvm-svn: 293393
2017-01-28 21:34:28 +00:00
Sylvestre Ledru fccc52aa66 Remove unused 'using' declaration. Found by clang-tidy: misc-unused-using-decls NFC
llvm-svn: 293381
2017-01-28 13:41:50 +00:00
Sylvestre Ledru d8650cde5d Pass a char instead of a string to the find function. clang-tidy: performance-faster-string-find
llvm-svn: 293379
2017-01-28 13:36:34 +00:00
Mehdi Amini 655f794964 Fix typo introduced in r292960 that may affect -flto -save-temps (saving the optimized bitcode)
llvm-svn: 293370
2017-01-28 06:07:17 +00:00
Richard Smith 152bcd2d0d Switch the template specialization kind for a non-defining declaration of a
non-template function instantiated from a friend declaration in a class
template from TSK_ImplicitInstantiation to TSK_Undeclared.

It doesn't make sense for a non-template function to be flagged as being
instantiated from a template; that property really belongs to the entity
as a whole and not an individual declaration of it. There's some history
here:

 * r137934 started marking these functions as instantiations in order to
   work around an issue where we might instantiate a class template while
   we're still parsing its member definitions, and would otherwise fail
   to instantiate the friend definition

 * r177003 fixed the same issue but for friend templates, but did so by
   making the friends claim to be definitions even before we'd parsed
   their actual bodies; this made the r137934 change redundant

 * r293558 worked around a problem caused by the marking of a non-template
   function as a template instantiation in r137934

This change reverts the code changes from r293358 and r137934 and retains
all the tests.

llvm-svn: 293367
2017-01-28 02:56:07 +00:00
George Burgess IV ce6284b179 Change how we handle diagnose_if attributes.
This patch changes how we handle argument-dependent `diagnose_if`
attributes. In particular, we now check them in the same place that we
check for things like passing NULL to Nonnull args, etc. This is
basically better in every way than how we were handling them before. :)

This fixes PR31638, PR31639, and PR31640.

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

llvm-svn: 293360
2017-01-28 02:19:40 +00:00
Richard Smith cfa5dc4a1d -Wunused-func-template: do not warn on non-template function declarations that
were nonetheless instantiated (particularly, non-template friends declared
within class templates).

llvm-svn: 293358
2017-01-28 01:50:33 +00:00
Richard Smith b256d30004 Support '#pragma clang __debug dump' within C++ classes.
llvm-svn: 293355
2017-01-28 01:20:57 +00:00
Richard Smith b55f75826a Convert sequence of 'if's on the same value to a switch. No functionality change intended.
llvm-svn: 293354
2017-01-28 01:12:10 +00:00
Richard Smith fc6fca1cab When converting a template argument representing &array to an expression for a
pointer typed template parameter, form &array rather than an array-to-pointer
decay on array.

llvm-svn: 293350
2017-01-28 00:38:35 +00:00
David Blaikie eb21001111 Fix linkage of static locals in available_externally functions to be DiscardableODR/linkonce_odr
As Mehdi put it, entities should either be
available_externally+weak_odr, or linkonce_odr+linkonce_odr. While some
functions are emitted a_e/weak, their local variables were emitted
a_e/linkonce_odr.

While it might be nice to emit them a_e/weak, the Itanium ABI (& best
guess at MSVC's behavior as well) requires the local to be
linkonce/linkonce.

Reviewers: rsmith, mehdi_amini

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

llvm-svn: 293344
2017-01-27 23:11:10 +00:00
Vedant Kumar 3db9974b2d [ubsan] Sanity-check shift amounts before truncation (fixes PR27271)
Ubsan does not report UB shifts in some cases where the shift exponent
needs to be truncated to match the type of the shift base. We perform a
range check on the truncated shift amount, leading to false negatives.

Fix the issue (PR27271) by performing the range check on the original
shift amount.

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

llvm-svn: 293343
2017-01-27 23:02:44 +00:00
Richard Smith 78aacbe2f9 PR31783: Don't request the alignment of an invalid declaration.
Fixes an assertion failure on PS4 targets.

llvm-svn: 293333
2017-01-27 21:28:37 +00:00
Tim Northover 3b34a9b5d9 ARM-Darwin: re-enable -momit-leaf-frame-pointer.
In r279546 I disabled all frame pointer elimination at the front-end on
ARM-Darwin (and warned about it) because before that the backend had been
silently ignoring these options. It turns out we didn't ignore
-momit-leaf-frame-pointer though, just the more general -fomit-frame-pointer.

So this re-enables passing that down to CodeGen so that everything really does
continue working as before (with better diagnostics).

llvm-svn: 293311
2017-01-27 17:53:42 +00:00
Hans Wennborg 091f1b6ef3 clang-cl: Warn about /U flags that look like filenames (PR31662)
Both on Mac and Windows, it's common to have a 'Users' directory in the
root of the filesystem, so one might specify a filename as
'/Users/me/myfile.c'. clang-cl (as well as MSVC's cl.exe) will interpret
that as invoking the '/U' option, which is probably not what the user
wanted. Add a warning about this.

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

llvm-svn: 293305
2017-01-27 17:09:41 +00:00
Anastasia Stulova af0a7bbbe2 [OpenCL] Add missing address spaces in IR generation of blocks
Modify ObjC blocks impl wrt address spaces as follows:

- keep default private address space for blocks generated
as local variables (with captures);

- add global address space for global block literals (no captures);

- make the block invoke function and enqueue_kernel prototype with
the generic AS block pointer parameter to accommodate both 
private and global AS cases from above;

- add block handling into default AS because it's implemented as
a special pointer type (BlockPointer) in the frontend and therefore
it is used as a pointer everywhere. This is also needed to accommodate
both private and global AS blocks for the two cases above.

- removes ObjC RT specific symbols (NSConcreteStackBlock and
NSConcreteGlobalBlock) in the OpenCL mode.

Review: https://reviews.llvm.org/D28814
llvm-svn: 293286
2017-01-27 15:11:34 +00:00
Simon Dardis 9e962add70 [mips] Add support for static model on N64
The patch teaches the Clang driver how to handle the N64 static
relocation model properly. It enforces the correct target feature
(+noabicalls) when -fno-pic is used. This is required as non-pic
N64 code as the abi extension to call PIC code (CPIC) is unsupported.

Make PIC the default for mips64 and mips64el, this affects both N32
& N64 ABIs, to better match GCC.

As part of this effort, clean up the assembler invocation command
builder, so the correct flags are used.

This and r293279 in LLVM resolves PR/23485.

Thanks to Brooks Davis for reporting the issue!

Reviewers: slthakur, seanbruno

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

llvm-svn: 293285
2017-01-27 15:05:25 +00:00
Artem Dergachev 12caf8e1e6 [analyzer] Consider function call arguments while building CallGraph.
Function call can appear in the arguments of another function call, eg.:

  foo(bar());

This patch adds support for such cases.

Patch by Ivan Sidorenko!

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

llvm-svn: 293280
2017-01-27 12:14:56 +00:00
Martin Probst fa37b18f94 clang-format: [JS] do not format MPEG transport streams.
Summary:
The MPEG transport stream file format also uses ".ts" as its file extension.
This change detects its specific framing format (0x47 every 189 bytes) and
simply ignores MPEG TS files.

Reviewers: djasper, sammccall

Subscribers: klimek, cfe-commits

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

llvm-svn: 293270
2017-01-27 09:09:11 +00:00
Richard Smith c5b2e00d06 [docs] Add help text and refine grouping for various options.
Also accept -G= (and -msmall-data-threshold=) as an alias for -G on MIPS as well as Hexagon.

llvm-svn: 293254
2017-01-27 02:08:37 +00:00
Peter Collingbourne b884716f6a Re-apply r292662, "IRGen: Start using the WriteThinLTOBitcode pass."
The internal build issue has been resolved.

llvm-svn: 293231
2017-01-26 23:51:50 +00:00
Richard Smith c0ca4c2c95 [modules] When reading / writing a typedef that is a name for linkage for
another declaration, ensure we actually serialize / deserialize that
declaration.

Before this patch, if another copy of the typedef were merged with the parsed
version, we would emit type information referring to the merged version and
consequently emit nothing about the parsed anonymous struct. This resulted in
us losing information, particularly the visible merged module set for the
parsed definition. Force that information to be emitted and to be loaded when
the typedef is used.

llvm-svn: 293219
2017-01-26 22:39:55 +00:00
Peter Collingbourne f5d1712189 IRGen: When loading the main module in the distributed ThinLTO backend, look for the module containing the summary.
Differential Revision: https://reviews.llvm.org/D29067

llvm-svn: 293209
2017-01-26 21:09:48 +00:00
Richard Smith 600b5261c4 PR0091R3: Implement parsing support for using templates as types.
This change adds a new type node, DeducedTemplateSpecializationType, to
represent a type template name that has been used as a type. This is modeled
around AutoType, and shares a common base class for representing a deduced
placeholder type.

We allow deduced class template types in a few more places than the standard
does: in conditions and for-range-declarators, and in new-type-ids. This is
consistent with GCC and with discussion on the core reflector. This patch
does not yet support deduced class template types being named in typename
specifiers.

llvm-svn: 293207
2017-01-26 20:40:47 +00:00
Akira Hatanaka 5d55a6c69d [Sema][ObjC] Make sure -Wblock-capture-autoreleasing issues a warning
even in the presence of nullability qualifiers.

This commit fixes bugs in r285031 where -Wblock-capture-autoreleasing
wouldn't issue warnings when the function parameters were annotated
with nullability qualifiers. Specifically, look through the sugar and
see if there is an AttributedType of kind attr_objc_ownership to
determine whether __autoreleasing was explicitly specified or implicitly
added by the compiler.

rdar://problem/30193488

llvm-svn: 293194
2017-01-26 18:13:06 +00:00
Stanislav Mekhanoshin 61da067393 Use TargetMachine adjustPassManager hook
Differential Revision: https://reviews.llvm.org/D28340

llvm-svn: 293190
2017-01-26 16:49:21 +00:00
Arpith Chacko Jacob cca61a3a74 [OpenMP] Codegen support for 'target teams' on the NVPTX device.
This is a simple patch to teach OpenMP codegen to emit the construct
in Generic mode.

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D29143

llvm-svn: 293183
2017-01-26 15:43:27 +00:00
Adam Nemet 7b796f825b Support MIR opt-remarks with -fsave-optimization-record
The handler that deals with IR passed/missed/analysis remarks is extended to
also handle the corresponding MIR remarks.

The more thorough testing in done via llc (rL293113, rL293121).  Here we just
make sure that the functionality is accessible through clang.

llvm-svn: 293146
2017-01-26 04:07:11 +00:00
Argyrios Kyrtzidis aee15fb204 [index] When indexing an ObjC method declaration use its base name for the location.
Instead of using the location of the beginning '-'/'+'.
This is consistent with location used for function decls and ObjC method calls where we use the base name as the location as well.

llvm-svn: 293134
2017-01-26 02:11:50 +00:00
Richard Smith d230de27f8 Remove and replace DiagStatePoint tracking and lookup data structure.
Rather than storing a single flat list of SourceLocations where the diagnostic
state changes (in source order), we now store a separate list for each FileID
in which there is a diagnostic state transition. (State for other files is
built and cached lazily, on demand.) This has two consequences:

1) We can now sensibly support modules, and properly track the diagnostic state
for modular headers (this matters when, for instance, triggering instantiation
of a template defined within a module triggers diagnostics).

2) It's much faster than the old approach, since we can now just do a binary
search on the offsets within the FileID rather than needing to call
isBeforeInTranslationUnit to determine source order (which is surprisingly
slow). For some pathological (but real world) files, this reduces total
compilation time by more than 10%.

For now, the diagnostic state points for modules are loaded eagerly. It seems
feasible to defer this until diagnostic state information for one of the
module's files is needed, but that's not part of this patch.

llvm-svn: 293123
2017-01-26 01:01:01 +00:00
Akira Hatanaka fdcd18b4c9 [CodeGen] Suppress emission of lifetime markers if a label has been seen
in the current lexical scope.

clang currently emits the lifetime.start marker of a variable when the
variable comes into scope even though a variable's lifetime starts at
the entry of the block with which it is associated, according to the C
standard. This normally doesn't cause any problems, but in the rare case
where a goto jumps backwards past the variable declaration to an earlier
point in the block (see the test case added to lifetime2.c), it can
cause mis-compilation.

To prevent such mis-compiles, this commit conservatively disables
emitting lifetime variables when a label has been seen in the current
block.

This problem was discussed on cfe-dev here: 
http://lists.llvm.org/pipermail/cfe-dev/2016-July/050066.html

rdar://problem/30153946

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

llvm-svn: 293106
2017-01-25 22:55:13 +00:00
Justin Lebar b080b630b1 [CodeGen] [CUDA] Add the ability set default attrs on functions in linked modules.
Summary:
Now when you ask clang to link in a bitcode module, you can tell it to
set attributes on that module's functions to match what we would have
set if we'd emitted those functions ourselves.

This is particularly important for fast-math attributes in CUDA
compilations.

Each CUDA compilation links in libdevice, a bitcode library provided by
nvidia as part of the CUDA distribution.  Without this patch, if we have
a user-function F that is compiled with -ffast-math that calls a
function G from libdevice, F will have the unsafe-fp-math=true (etc.)
attributes, but G will have no attributes.

Since F calls G, the inliner will merge G's attributes into F's.  It
considers the lack of an unsafe-fp-math=true attribute on G to be
tantamount to unsafe-fp-math=false, so it "merges" these by setting
unsafe-fp-math=false on F.

This then continues up the call graph, until every function that
(transitively) calls something in libdevice gets unsafe-fp-math=false
set, thus disabling fastmath in almost all CUDA code.

Reviewers: echristo

Subscribers: hfinkel, llvm-commits, mehdi_amini

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

llvm-svn: 293097
2017-01-25 21:29:48 +00:00
Arpith Chacko Jacob 2cd6eeabfd [OpenMP] Support for the proc_bind-clause on 'target parallel' on the NVPTX device.
This patch adds support for the proc_bind clause on the Spmd construct
'target parallel' on the NVPTX device.  Since the parallel region is created
upon kernel launch, this clause can be safely ignored on the NVPTX device at
codegen time for level 0 parallelism.

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D29128

llvm-svn: 293069
2017-01-25 16:55:10 +00:00
Krasimir Georgiev 91834227a3 [clang-format] Implement comment reflowing.
Summary:
This presents a version of the comment reflowing with less mutable state inside
the comment breakable token subclasses. The state has been pushed into the
driving breakProtrudingToken method. For this, the API of BreakableToken is enriched
by the methods getSplitBefore and getLineLengthAfterSplitBefore.

Reviewers: klimek

Reviewed By: klimek

Subscribers: djasper, klimek, mgorny, cfe-commits, ioeric

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

llvm-svn: 293055
2017-01-25 13:58:58 +00:00
Anastasia Stulova d1f390ef99 [OpenCL] Diagnose write_only image3d when extension is disabled
Prior to OpenCL 2.0, image3d_t can only be used with the write_only
access qualifier when the cl_khr_3d_image_writes extension is enabled,
see e.g. OpenCL 1.1 s6.8b.

Require the extension for write_only image3d_t types and guard uses of
write_only image3d_t in the OpenCL header.

Patch by Sven van Haastregt!

Review: https://reviews.llvm.org/D28860
llvm-svn: 293050
2017-01-25 12:18:50 +00:00
Arpith Chacko Jacob 7ecc0b7f3d [OpenMP] Support for thread_limit-clause on the 'target teams' directive.
The thread_limit-clause on the combined directive applies to the
'teams' region of this construct. We modify the ThreadLimitClause
class to capture the clause expression within the 'target' region.

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D29087

llvm-svn: 293049
2017-01-25 11:44:35 +00:00
Arpith Chacko Jacob bc126344e1 [OpenMP] Support for num_teams-clause on the 'target teams' directive.
The num_teams-clause on the combined directive applies to the
'teams' region of this construct. We modify the NumTeamsClause
class to capture the clause expression within the 'target' region.

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D29085

llvm-svn: 293048
2017-01-25 11:28:18 +00:00