Commit Graph

254 Commits

Author SHA1 Message Date
Chandler Carruth 2946cd7010 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351636
2019-01-19 08:50:56 +00:00
Reid Kleckner 229eee49fc [MS] Push outermost class DeclContexts only in -fdelayed-template-parsing
This is more or less a complete rewrite of r347627, and it fixes PR38460
I added a reduced test case to DelayedTemplateParsing.cpp.

llvm-svn: 347713
2018-11-27 21:20:42 +00:00
Reid Kleckner 0ef5843dcc Revert r347627 "[MS] Push fewer DeclContexts for delayed template parsing"
It broke the Windows self-host:
http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/1799/steps/stage%202%20build/logs/stdio

I can build
lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/MachinePostDominators.cpp.obj to
repro.

llvm-svn: 347630
2018-11-27 02:54:17 +00:00
Reid Kleckner 5cec19dc1a [MS] Push fewer DeclContexts for delayed template parsing
Only push the outermost record as a DeclContext when parsing a function
body. See the comments in Sema::getContainingDC about the way the parser
pushes contexts. This is intended to match the behavior the parser
normally displays where it parses all method bodies from all nested
classes at the end of the outermost class, when all nested classes are
complete.

Fixes PR38460.

llvm-svn: 347627
2018-11-27 02:21:51 +00:00
Artem Belevich 2eeb048905 [CUDA] Fixed parsing of optional template-argument-list.
We need to consider all tokens that start with '>' when
we're checking for the end of an empty template argument list.

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

llvm-svn: 342752
2018-09-21 17:46:28 +00:00
Richard Smith f9a5d5f04a Improve diagnostic for missing comma in template parameter list.
Given 'typename T typename U', we would correctly diagnose the missing
comma, but incorrectly disambiguate the first parameter as being a
non-type parameter and complain that the 'T' is not a qualified-id.

See also gcc.gnu.org/PR86998.

llvm-svn: 340074
2018-08-17 19:43:40 +00:00
Fangrui Song 6907ce2f8f Remove trailing space
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h}

llvm-svn: 338291
2018-07-30 19:24:48 +00:00
Erich Keane c480f30580 AttributeList de-listifying:
Basically, "AttributeList" loses all list-like mechanisms, ParsedAttributes is
switched to use a TinyPtrVector (and a ParsedAttributesView is created to
have a non-allocating attributes list). DeclaratorChunk gets the later kind,
Declarator/DeclSpec keep ParsedAttributes.

Iterators are added to the ParsedAttribute types so that for-loops work.

llvm-svn: 336945
2018-07-12 21:09:05 +00:00
Nicolas Lesser b6d5c58718 [C++17] Disallow lambdas in template parameters (PR33696).
Summary: This revision disallows lambdas in template parameters, as reported in PR33696.

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: cfe-commits

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

llvm-svn: 336930
2018-07-12 18:45:41 +00:00
Richard Smith c2dead4d9a Diagnose missing 'template' keywords in contexts where a comma is not a
binary operator.

Factor out the checking for a comma within potential angle brackets and
also call it from contexts where we parse a comma-separated list of
arguments or initializers.

llvm-svn: 335699
2018-06-27 01:32:04 +00:00
Adrian Prantl 9fc8faf9e6 Remove \brief commands from doxygen comments.
This is similar to the LLVM change https://reviews.llvm.org/D46290.

We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done

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

llvm-svn: 331834
2018-05-09 01:00:01 +00:00
Richard Smith b5f8171a1b PR37189 Fix incorrect end source location and spelling for a split '>>' token.
When a '>>' token is split into two '>' tokens (in C++11 onwards), or (as an
extension) when we do the same for other tokens starting with a '>', we can't
just use a location pointing to the first '>' as the location of the split
token, because that would result in our miscomputing the length and spelling
for the token. As a consequence, for example, a refactoring replacing 'A<X>'
with something else would sometimes replace one character too many, and
similarly diagnostics highlighting a template-id source range would highlight
one character too many.

Fix this by creating an expansion range covering the first character of the
'>>' token, whose spelling is '>'. For this to work, we generalize the
expansion range of a macro FileID to be either a token range (the common case)
or a character range (used in this new case).

llvm-svn: 331155
2018-04-30 05:25:48 +00:00
Faisal Vali a534f07f8c Revert rC330794 and some dependent tiny bug fixes
See Richard's humbling feedback here: 
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180423/226482.html
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180423/226486.html

Wish I'd had the patience to solicit the feedback prior to committing :)

Sorry for the noise guys.

Thank you Richard for being the steward that clang deserves!

llvm-svn: 330888
2018-04-26 00:42:40 +00:00
Bjorn Pettersson 3dd22c9898 Fix buildbot problems after rC330794
Avoiding
  error: no matching function for call to 'makeArrayRef'
at
  ../tools/clang/lib/Parse/ParseTemplate.cpp:373:17

By using a local C array as input to makeArrayRef.

Not sure if this is the best solution, but it makes the code
compile again.

llvm-svn: 330802
2018-04-25 09:04:12 +00:00
Faisal Vali 936de9d666 [c++2a] [concepts] Add rudimentary parsing support for template concept declarations
This patch is a tweak of changyu's patch: https://reviews.llvm.org/D40381. It differs in that the recognition of the 'concept' token is moved into the machinery that recognizes declaration-specifiers - this allows us to leverage the attribute handling machinery more seamlessly.

See the test file to get a sense of the basic parsing that this patch supports. 

There is much more work to be done before concepts are usable...

Thanks Changyu!

llvm-svn: 330794
2018-04-25 02:42:26 +00:00
Nico Weber ade321e7dd Revert r329684 (and follow-ups 329693, 329714). See discussion on https://reviews.llvm.org/D43578.
llvm-svn: 329739
2018-04-10 18:53:28 +00:00
Andrew V. Tischenko c88deb100f -ftime-report switch support in Clang.
The current support of the feature produces only 2 lines in report:
 -Some general Code Generation Time;
 -Total time of Backend Consumer actions.
This patch extends Clang time report with new lines related to Preprocessor, Include Filea Search, Parsing, etc.
Differential Revision: https://reviews.llvm.org/D43578

llvm-svn: 329684
2018-04-10 10:34:13 +00:00
Richard Smith 77a9c60aa6 Fix a couple of cases where we would fail to correctly parse deduced class template specialization types.
Specifically, we would not properly parse these types within template arguments
(for non-type template parameters), and in tentative parses. Fixing both of
these essentially requires that we parse deduced template specialization types
as types in all contexts, even in template argument lists -- in particular,
tentative parsing may look ahead and annotate a deduced template specialization
type before we figure out that we're actually supposed to treat the tokens as a
template-name. We deal with this by simply permitting deduced template
specialization types when parsing template arguments, and converting them to
template template arguments.

llvm-svn: 326299
2018-02-28 03:02:23 +00:00
Jan Korous 3a98e51823 [Parser][FixIt] Better diagnostics for "typedef" instead of "typename" typo
rdar://problem/10214588

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

llvm-svn: 324607
2018-02-08 14:37:58 +00:00
Faisal Vali 7db85c5282 [NFC] Modernize enum DeclSpecContext into a scoped enum.
llvm-svn: 321590
2017-12-31 00:06:40 +00:00
Faisal Vali 2ab8c15cf1 [NFC] Modernize enum 'UnqualifiedId::IdKind' into a scoped enum UnqualifiedIdKind.
llvm-svn: 321574
2017-12-30 04:15:27 +00:00
Faisal Vali 421b2d1d8e [NFC] Modernize enum Declarator::TheContext to a type-safe scoped enum.
Note, we don't do any bitwise manipulations when using them.

llvm-svn: 321546
2017-12-29 05:41:00 +00:00
Faisal Vali d9548c350f [NFC] Remove a cast rendered unnecessary by r321409
See https://reviews.llvm.org/rC321409 for additional context.

llvm-svn: 321410
2017-12-23 19:27:07 +00:00
Faisal Vali be29403633 [NFC] Update the template-parameter parsers and analyzers to return NamedDecl (vs Decl)
This patch addresses a FIXME and has the template-parameter processing functions return a more derived common type NamedDecl (as opposed to a type needlessly higher up in the inheritance hierarchy : Decl).  

llvm-svn: 321409
2017-12-23 18:56:34 +00:00
Dimitry Andric e4f5d01033 Fix more inconsistent line endings. NFC.
llvm-svn: 321016
2017-12-18 19:46:56 +00:00
Aaron Ballman c351fba69e Now that C++17 is official (https://www.iso.org/standard/68564.html), start changing the C++1z terminology over to C++17. NFC intended, these are all mechanical changes.
llvm-svn: 319688
2017-12-04 20:27:34 +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
Faisal Vali f241b0dcd6 [NFC] Remove a cstyle cast and replace some uses of Decl with NamedDecl during the processing of TemplateParameterLists.
llvm-svn: 311788
2017-08-25 18:24:20 +00:00
Erik Verbruggen aa603c3bef Revert r311442 (Fix templated type alias completion when using global completion cache)
Failing Tests (2):
    Clang :: CXX/dcl.dcl/dcl.spec/dcl.type/p3-0x.cpp
    Clang :: SemaCXX/alias-template.cpp

llvm-svn: 311445
2017-08-22 10:54:40 +00:00
Erik Verbruggen 1ca8bbb078 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
}

Patch by Ivan Donchevskii!

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

llvm-svn: 311442
2017-08-22 10:25:48 +00:00
Momchil Velikov 57c681f33e Place implictly declared functions at block scope
Such implicitly declared functions behave as if the enclosing block
contained the declaration extern int name() (C90, 6.3.3.2 Function calls),
thus their names should have block scope (C90, 6.1.2.1 Scope of identifiers).

This patch fixes https://bugs.llvm.org/show_bug.cgi?id=33224

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

llvm-svn: 310616
2017-08-10 15:43:06 +00:00
Akira Hatanaka 12ddceecde [Sema] Fix a crash-on-invalid when a template parameter list has a class
definition or non-reference class type.

The crash occurs when there is a template parameter list in a class that
is missing the closing angle bracket followed by a definition of a
struct. For example:

class C0 {
public:
  template<typename T, typename T1 = T // missing closing angle bracket
  struct S0 {};

  C0() : m(new S0<int>) {}
  S0<int> *m;
};

This happens because the parsed struct is added to the scope of the
enclosing class without having its access specifier set, which results
in an assertion failure in SemaAccess.cpp later.

This commit fixes the crash by adding the parsed struct to the enclosing
file scope and marking structs as invalid if they are defined in
template parameter lists.

rdar://problem/31783961
rdar://problem/19570630

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

llvm-svn: 306317
2017-06-26 18:46:12 +00:00
Faisal Vali 43caf6785f [NFC, Refactor] Modernize TemplateIdAnnotation using TrailingObjects
A refactoring of TemplateIdAnnotation that uses TrailingObjects to create a variably-sized object on the heap.

https://reviews.llvm.org/D31414

Thanks to Aaron B for the review!

llvm-svn: 303594
2017-05-23 01:07:12 +00:00
Faisal Vali 56f1de4dcb Fix PR25627: constant expressions being odr-used in template arguments.
This patch ensures that clang processes the expression-nodes that are generated when disambiguating between types and expressions within template arguments as constant-expressions by installing the ConstantEvaluated ExpressionEvaluationContext just before attempting the disambiguation - and then making sure that Context carries through into ParseConstantExpression (by refactoring it out into a function that does not create its own EvaluationContext: ParseConstantExpressionInExprEvalContext) 

Note, prior to this patch, trunk would correctly disambiguate and identify the expression as an expression - and while it would annotate the token with the expression - it would fail to complete the odr-use processing (specifically, failing to trigger Sema::UpdateMarkingForLValueToRValue as is done for all Constant Expressions, which would remove it from being considered odr-used).  By installing the ConstantExpression Evaluation Context prior to disambiguation, and making sure it carries though, we ensure correct processing of the expression-node.

For e.g:
  template<int> struct X { };
  void f() {
    const int N = 10;
    X<N> x; // should be OK.
    [] { return X<N>{}; }; // Should be OK - no capture - but clang errors!
  }

See a related bug: https://bugs.llvm.org//show_bug.cgi?id=25627

In summary (and reiteration), the fix is as follows:

    - Remove the EnteredConstantEvaluatedContext action from ParseTemplateArgumentList (relying on ParseTemplateArgument getting it right)
    - Add the EnteredConstantEvaluatedContext action just prior to undergoing the disambiguating parse, and if the parse succeeds for an expression, carry the context though into a refactored version of ParseConstantExpression that does not create its own ExpressionEvaluationContext.

See https://reviews.llvm.org/D31588 for additional context regarding some of the more fragile and complicated approaches attempted, and Richard's feedback that eventually shaped the simpler and more robust rendition that is being committed.

Thanks Richard!

llvm-svn: 303492
2017-05-20 19:58:04 +00:00
Richard Smith af3b325627 Fix the location of "missing ';'" suggestions after annotation tokens.
We were incorrectly setting PrevTokLocation to the first token in the
annotation token instead of the last when consuming it. To fix this without
adding a complex switch to the hot path through ConsumeToken, we now have a
ConsumeAnnotationToken function for consuming annotation tokens in addition
to the other Consume*Token special case functions.

llvm-svn: 303372
2017-05-18 19:21:48 +00:00
NAKAMURA Takumi ef40cde1da Prune unused \param(s) of clang::Parser::ParseTemplateIdAfterTemplateName() in r302737. [-Wdocumentation]
llvm-svn: 302758
2017-05-11 02:43:47 +00:00
Richard Smith 9a420f9f42 Changes missed from r302732.
llvm-svn: 302737
2017-05-10 21:47:30 +00:00
Faisal Vali d143a0c2de [NFC, Scoped Enum] Convert Sema::ExpressionEvaluationContext into a scoped Enum
- also replace direct equality checks against the ConstantEvaluated enumerator  with isConstantEvaluted(), in anticipation of adding finer granularity to the various ConstantEvaluated contexts and reinstating certain restrictions on where lambda expressions can occur in C++17.

- update the clang tablegen backend that uses these Enumerators, and add the relevant scope where needed.

llvm-svn: 299316
2017-04-01 21:30:49 +00:00
Vassil Vassilev 11ad339127 Publish RAIIObjectsForParser.h for external usage.
Some clients (eg the cling interpreter) need to recover their parser from
errors.

Patch by Axel Naumann (D31190)!

llvm-svn: 298606
2017-03-23 15:11:07 +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
Richard Smith 74f02347ca PR13403 (+duplicates): implement C++ DR1310 (http://wg21.link/cwg1310).
Under this defect resolution, the injected-class-name of a class or class
template cannot be used except in very limited circumstances (when declaring a
constructor, in a nested-name-specifier, in a base-specifier, or in an
elaborated-type-specifier). This is apparently done to make parsing easier, but
it's a pain for us since we don't know whether a template-id using the
injected-class-name is valid at the point when we annotate it (we don't yet
know whether the template-id will become part of an elaborated-type-specifier).

As a tentative resolution to a perceived language defect, mem-initializer-ids
are added to the list of exceptions here (they generally follow the same rules
as base-specifiers).

When the reference to the injected-class-name uses the 'typename' or 'template'
keywords, we permit it to be used to name a type or template as an extension;
other compilers also accept some cases in this area. There are also a couple of
corner cases with dependent template names that we do not yet diagnose, but
which will also get this treatment.

llvm-svn: 292518
2017-01-19 21:00:13 +00:00
Richard Smith 6f1daa4660 [c++1z] P0195R2: Allow multiple using-declarators in a single using-declaration.
llvm-svn: 289905
2016-12-16 00:58:48 +00:00
Mehdi Amini 9670f847b8 [NFC] Header cleanup
Summary: Removed unused headers, replaced some headers with forward class declarations

Patch by: Eugene <claprix@yandex.ru>

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

llvm-svn: 275882
2016-07-18 19:02:11 +00:00
Alexey Bataev 61deb4dadc Revert accidential "[MSVC] Late parsing of in-class defined member functions in template"
This reverts commit 0253605771b8bd9d414aba74fe2742c730d6fd1a.

llvm-svn: 272776
2016-06-15 11:24:54 +00:00
Alexey Bataev 86e786bd17 [MSVC] Late parsing of in-class defined member functions in template
classes.

MSVC actively uses unqualified lookup in dependent bases, lookup at the
instantiation point (non-dependent names may be resolved on things
declared later) etc. and all this stuff is the main cause of
incompatibility between clang and MSVC.

Clang tries to emulate MSVC behavior but it may fail in many cases.
clang could store lexed tokens for member functions definitions within
ClassTemplateDecl for later parsing during template instantiation.

It will allow resolving many possible issues with lookup in dependent
base classes and removing many already existing MSVC-specific
hacks/workarounds from the clang code.

llvm-svn: 272774
2016-06-15 11:19:39 +00:00
Hubert Tong f608c05452 [Concepts] Pass requires-clause to ActOnTemplateParameterList; NFC
Summary:
Prepare to store requires-clause expression for access via
TemplateParameterList.

Reviewers: aaron.ballman, faisalv, rsmith

Subscribers: cfe-commits, nwilson

Differential Revision: http://reviews.llvm.org/D19220

llvm-svn: 268081
2016-04-29 18:05:37 +00:00
Akira Hatanaka 10aced824a [Parser] Clear the TemplateParamScope bit of the current scope's flag
if we are parsing a template specialization.

This commit makes changes to clear the TemplateParamScope bit and set
the TemplateParamParent field of the current scope to null if a template
specialization is being parsed.

Before this commit, Sema::ActOnStartOfLambdaDefinition would check
whether the parent template scope had any decls to determine whether
or not a template specialization was being parsed. This wasn't correct
since it couldn't distinguish between a real template specialization and
a template defintion with an unnamed template parameter (only template
parameters with names are added to the scope's decl list). To fix the
bug, this commit changes the code to check the pointer to the parent
template scope rather than the decl list.

rdar://problem/23440346

Differential Revision: http://reviews.llvm.org/D19175

llvm-svn: 267975
2016-04-29 02:24:14 +00:00
David Blaikie 2eabcc988f Simplify EnterTokenStream API to make it more robust for memory management
While this won't help fix things like the bug that r260219 addressed, it
seems like good tidy up to have anyway.

(it might be nice if "makeArrayRef" always produced a MutableArrayRef &
let it decay to an ArrayRef when needed - then I'd use that for the
MutableArrayRefs in this patch)

If we had std::dynarray I'd use that instead of unique_ptr+size_t,
ideally (but then it'd have to be threaded down through the Preprocessor
all the way - no idea how painful that would be)

llvm-svn: 260246
2016-02-09 18:52:09 +00:00
Bruno Cardoso Lopes fb9b6cd24b [Parser] Perform CachedTokens update dependent on token consumption
In the context where we break one tok::greatergreater into two
tok::greater in order to correctly update the cached tokens; update the
CachedTokens with two tok::greater only if ParseGreaterThanInTemplateList
clients asks to consume the last token. Otherwise we only need to add
one because the second is already added later on, as a not yet cached token.

Differential Revision: http://reviews.llvm.org/D16906

rdar://problem/24488367

llvm-svn: 259910
2016-02-05 19:36:39 +00:00
Bruno Cardoso Lopes 428a5aa9a5 [Parser] Update CachedTokens while parsing ObjectiveC template argument list
Consider the following ObjC++ snippet:

--
@protocol PA;
@protocol PB;

@class NSArray<ObjectType>;
typedef int some_t;

id<PA> FA(NSArray<id<PB>> *h, some_t group);
--

This would hit an assertion in the parser after generating an annotation token
while trying to update the token cache:

Assertion failed: (CachedTokens[CachedLexPos-1].getLastLoc() == Tok.getAnnotationEndLoc() && "The annotation should be until the most recent cached token")
...
7 clang::Preprocessor::AnnotatePreviousCachedTokens(clang::Token const&) + 494
8 clang::Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(bool, bool, clang::CXXScopeSpec&, bool) + 1163
9 clang::Parser::TryAnnotateTypeOrScopeToken(bool, bool) + 361
10 clang::Parser::isCXXDeclarationSpecifier(clang::Parser::TPResult, bool*) + 598
...

The cached preprocessor token in this case is:

greatergreater '>>' Loc=<testcase.mm:7:24>

while the annotation ("NSArray<id<PB>>") ends at "testcase.mm:7:25", hence the
assertion.

Properly update the CachedTokens during template parsing to contain
two greater tokens instead of a greatergreater.

Differential Revision: http://reviews.llvm.org/D15173

rdar://problem/23494277

llvm-svn: 259311
2016-01-31 00:47:51 +00:00