Commit Graph

2226 Commits

Author SHA1 Message Date
Manuel Klimek 06d5af4c9d Revert "Implement new interfaces for code-formatting when applying replacements."
This reverts commit r262232.

llvm-svn: 262234
2016-02-29 16:44:16 +00:00
Manuel Klimek 4823631af4 Implement new interfaces for code-formatting when applying replacements.
Patch by Eric Liu.

llvm-svn: 262232
2016-02-29 16:27:41 +00:00
Daniel Jasper 35ca66debf clang-format: Don't format unrelated nested blocks.
With this change:

  SomeFunction(
      [] {
	int i;
	 return i;  // Format this line.
      },
      [] {
	 return 2;  // Don't "fix" this.
      });

llvm-svn: 262216
2016-02-29 12:26:20 +00:00
Bruno Cardoso Lopes b7eb8db023 Revert "[VFS] Add 'overlay-relative' field to YAML files" and "[VFS] Fix call to getVFSFromYAML in unittests"
This reverts commit r261552 and r261556 because of failing unittests on
windows:

Failing Tests (4):
    Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.CaseInsensitive
    Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.DirectoryIteration
    Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.MappedFiles
    Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.UseExternalName

llvm-svn: 261613
2016-02-23 07:06:12 +00:00
Duncan P. N. Exon Smith b5ce11fcc6 Lex: Return "" when HeaderMap::lookupFilename fails
Change getString() to return Optional<StringRef>, and change
lookupFilename() to return an empty string if either one of the prefix
and suffix can't be found.

This is a more robust follow-up to r261461, but it's still not entirely
satisfactory.  Ideally we'd report that the header map is corrupt;
perhaps something for a follow-up.

llvm-svn: 261596
2016-02-23 00:48:16 +00:00
Duncan P. N. Exon Smith 3a7def09fe Lex: Check for 0 buckets on header map construction
Switch to using `isPowerOf2_32()` to check whether the buckets are a
power of two, and as a side benefit reject loading a header map with no
buckets.  This is a follow-up to r261448.

llvm-svn: 261585
2016-02-22 22:24:22 +00:00
Samuel Benzaquen 922bef4f38 [ASTMatchers] Add matcher hasAnyName.
Summary: Add matcher hasAnyName as an optimization over anyOf(hasName(),...)

Reviewers: alexfh

Subscribers: klimek, cfe-commits

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

llvm-svn: 261574
2016-02-22 21:13:02 +00:00
Bruno Cardoso Lopes 32b6222bc3 [VFS] Fix call to getVFSFromYAML in unittests
Follow up from r261552

llvm-svn: 261556
2016-02-22 19:02:27 +00:00
Daniel Jasper 02cbeb2222 clang-format: [JS] treat forwardDeclare as an import/export statement.
Patch by Martin Probst. Thank you.

llvm-svn: 261528
2016-02-22 15:06:53 +00:00
Duncan P. N. Exon Smith 96a01fa046 Lex: Never overflow the file in HeaderMap::lookupFilename()
If a header map file is corrupt, the strings in the string table may not
be null-terminated.  The logic here previously relied on `MemoryBuffer`
always being null-terminated, but this isn't actually guaranteed by the
class AFAICT.  Moreover, we're seeing a lot of crash traces at calls to
`strlen()` inside of `lookupFilename()`, so something is going wrong
there.

Instead, use `strnlen()` to get the length, and check for corruption.

Also remove code paths that could call `StringRef(nullptr)`.  r261459
made these rather obvious (although they'd been there all along).

llvm-svn: 261461
2016-02-21 00:14:36 +00:00
Duncan P. N. Exon Smith 08fd70fae3 Lex: Add a test for HeaderMap::lookupFileName()
Add a simple test for `HeaderMap::lookupFileName()`.  I'm planning to
add better error checking in a moment, and I'll add more tests like this
then.

llvm-svn: 261455
2016-02-20 22:53:22 +00:00
Duncan P. N. Exon Smith 8d6a31c023 Lex: Check whether the header map buffer has space for the buckets
Check up front whether the header map buffer has space for all of its
declared buckets.

There was already a check in `getBucket()`, but it had UB (comparing
pointers that were outside of objects in the error path) and was
insufficient (only checking for a single byte of the relevant bucket).
I fixed the check, moved it to `checkHeader()`, and left a fixed version
behind as an assertion.

llvm-svn: 261449
2016-02-20 21:24:31 +00:00
Duncan P. N. Exon Smith dfe85305fa Lex: Check buckets on header map construction
If the number of buckets is not a power of two, immediately recognize
the header map as corrupt, rather than waiting for the first lookup.  I
converted the later check to an assert.

llvm-svn: 261448
2016-02-20 21:00:58 +00:00
Duncan P. N. Exon Smith 9ab99eecc3 Lex: Add some unit tests for corrupt header maps
Split the implementation of `HeaderMap` into `HeaderMapImpl` so that we
can write unit tests that don't depend on the `FileManager`, and then
write a few tests that cover the types of corrupt header maps already
detected.

This also moves type and constant definitions from HeaderMap.cpp to
HeaderMapTypes.h so that the test can access them.

llvm-svn: 261446
2016-02-20 20:39:51 +00:00
Richard Trieu cc3949d99a Remove use of builtin comma operator.
Cleanup for upcoming Clang warning -Wcomma.  No functionality change intended.

llvm-svn: 261271
2016-02-18 22:34:54 +00:00
David L. Jones cd58bd6200 Use Backend_EmitMCNull for null codegen unit tests.
Using Backend_EmitLL attemps to create a file with an empty filename.
This is problematic in certain environments: an empty filename may be
illegal, or the default output path may not be writable (in the case
where an empty filename would otherwise have some non-failing
semantics). This patch switches to use Backend_EmitMCNull, which
allows CodeGen to run, but does not attempt to create or write an
output file.

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

llvm-svn: 261252
2016-02-18 20:27:16 +00:00
Serge Pavlov 7a545536f5 File missed from r261222
llvm-svn: 261223
2016-02-18 16:43:24 +00:00
Serge Pavlov 41c1f79dfe Avoid double deletion in Clang driver.
Llvm module object is shared between CodeGenerator and BackendConsumer,
in both classes it is stored as std::unique_ptr, which is not a good
design solution and can cause double deletion error. Usually it does
not occur because in BackendConsumer::HandleTranslationUnit the
ownership of CodeGenerator over the module is taken away. If however
this method is not called, the module is deleted twice and compiler crashes.

As the module owned by BackendConsumer is always the same as CodeGenerator
has, pointer to llvm module can be removed from BackendGenerator.

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

llvm-svn: 261222
2016-02-18 16:42:09 +00:00
Aaron Ballman eb7e5d9074 Add an AST matcher for real floating-point types. e.g., float, double, long double, but not complex.
llvm-svn: 261221
2016-02-18 16:36:01 +00:00
Aaron Ballman cc928c80b4 Missing semicolons are kind of important. Who knew?
llvm-svn: 261009
2016-02-16 21:06:10 +00:00
Aaron Ballman 232e63d00b Add a nullPointerConstant() AST matcher to handle variations of null pointer constants in one matcher.
llvm-svn: 261008
2016-02-16 21:02:23 +00:00
Reid Kleckner 94f127e84a Stop using "template" when printing qualtype names
Summary:
The keyword "template" isn't necessary when
printing a fully-qualified qualtype name, and, in fact,
results in a syntax error if one tries to use it. So stop
printing it.

Reviewers: rsmith, rnk

Subscribers: rnk, klimek, cfe-commits

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

llvm-svn: 261005
2016-02-16 20:34:27 +00:00
Felix Berger cc9df3b9cc Add isAnyPointer() matchers. Register missing matchers.
Summary:
The isAnyPointer() matcher is useful for http://reviews.llvm.org/D15623.

Reviewers: alexfh, klimek

Subscribers: cfe-commits

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

llvm-svn: 260872
2016-02-15 04:00:39 +00:00
Jonas Hahnfeld 91924a6f63 tests: Add explicit -stdlib=libstdc++ to tests that require it
This will be needed for the next commit that allows to switch the default
C++ library which would otherwise make these tests fail.

llvm-svn: 260661
2016-02-12 07:48:28 +00:00
Daniel Jasper b7fda11572 clang-format: [JS] Support for (.. of ..) loops.
Before:
  for (var i of[2, 3]) {}

After:
  for (var i of [2, 3]) {}

llvm-svn: 260518
2016-02-11 13:24:15 +00:00
Daniel Jasper 602a727add clang-format: Make indentation after "<<" more consistent.
Before:
  Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa)
      << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
	  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
  Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa)
      << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
	     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
      << aaa;

After:
  Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa)
      << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
	     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
  Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa)
      << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
	     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
      << aaa;

llvm-svn: 260517
2016-02-11 13:15:14 +00:00
Daniel Jasper 88db760e4b clang-format: Make it more expensive to break template parameters.
In particular, make it more expensive than breaking after the return
type of a function definition/declaration.

Before:
  template <typename T>
  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaa<
      T>::aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaa);

After:
  template <typename T>
  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  aaaaaaaaaaaaaaaaaaaaaaa<T>::aaaaaaaaaaaaa(
      aaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaa);

llvm-svn: 260497
2016-02-11 06:43:01 +00:00
Richard Smith 0dd191a5c4 Add Tooling functionality to get a name for a QualType that can be used to name
that type from the global scope.

Patch by Sterling Augustine, derived (with permission) from code from Cling by
Vassil Vassilev and Philippe Canal.

llvm-svn: 260278
2016-02-09 21:04:04 +00:00
Nico Weber 26911c7733 Make ParentMap work with explicit specializations of function templates.
For an explicit specialization, we first build a FunctionDecl, and then
we call SubstDecl() on it to build a second FunctionDecl, which has the
first FunctionDecl as canonical decl.

The address of an explicit specialization of function template used to be the
canonical decl of the FunctionDecl.  This is different from all the other
DeduceTemplateArguments() calls in SemaOverload, and since the canonical decl
isn't visited by ParentMap while the redecl is, it also made ParentMap assert
when computing the parent of a address-of-explicit-specialization-fun-template.

To fix, remove the getCanonicalDecl() call.  No behavior difference for clang,
but it fixes an assert in ParentMap (which is e.g. used by libTooling).

llvm-svn: 260159
2016-02-08 22:23:09 +00:00
Daniel Jasper 2a9f720129 clang-format: Fix weird alignment when not aligning after brackets.
Before:
  bbbbbbbbbbbb(aaaaaaaaaaaaaaaaaaaaaaaa, //
      ccccccc(aaaaaaaaaaaaaaaaa, //
	           b));

After:
  bbbbbbbbbbbb(aaaaaaaaaaaaaaaaaaaaaaaa, //
      ccccccc(aaaaaaaaaaaaaaaaa, //
     	  b));

This fixes llvm.org/PR24905.

llvm-svn: 260080
2016-02-08 09:52:54 +00:00
Daniel Jasper 9f4c9d418f clang-format: [JS] Don't count shortened object literals as blocks.
Before:
  f({a},
    () => {
      g();  //
    });

After:
  f({a}, () => {
    g();  //
  });

llvm-svn: 260060
2016-02-07 22:17:13 +00:00
Samuel Benzaquen 8e566f3740 [ASTMatchers] Allow hasName() to look through inline namespaces
Summary:
Allow hasName() to look through inline namespaces.
This will fix the interaction between some clang-tidy checks and libc++.

libc++ defines names in an inline namespace named std::<version_#>.
When we try to match a name using hasName("std::xxx") it fails to match and the clang-tidy check does not work.

Reviewers: klimek

Subscribers: klimek, cfe-commits

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

llvm-svn: 259898
2016-02-05 18:29:24 +00:00
Daniel Jasper 0c9772e874 clang-format: Fix corner case in template detection.
Before:
  f(a.operator() < A > ());

After:
  f(a.operator()<A>());

llvm-svn: 259884
2016-02-05 14:17:16 +00:00
Daniel Jasper 45860fac37 clang-format: Fix formatting of ternary expressions with comments.
Before:
  int i = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ?
	      /*bbbbbbbbbbbbbbbbbbbb=*/bbbbbbbbbbbbbbbbbbbbbbbbb :
				       ccccccccccccccccccccccccccc;

After:
  int i = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ?
	      /*bbbbbbbbbbbbbbbbbbbb=*/bbbbbbbbbbbbbbbbbbbbbbbbb :
              ccccccccccccccccccccccccccc;

llvm-svn: 259670
2016-02-03 17:27:10 +00:00
Daniel Jasper 739ae64346 Provide match function to look over an entire TU again.
llvm-svn: 259648
2016-02-03 14:29:55 +00:00
Daniel Jasper 8737930cac clang-format: [JS/TypeScript] Support "enum" as an optional property name, too.
Before:
  enum?: string
  [];

After:
  enum?: string[];

llvm-svn: 259628
2016-02-03 05:33:44 +00:00
Daniel Jasper b618a98582 clang-format: Make AlignAfterOpenBracket also affect angle brackets.
Patch by Matthew Whitehead, thank you.

llvm-svn: 259487
2016-02-02 10:28:11 +00:00
Nico Weber c097337493 Always build a new TypeSourceInfo for function templates with parameters
RecursiveASTVisitor::TraverseFunctionHelper() traverses a function's
ParmVarDecls by going to the function's getTypeSourceInfo if it exists, and
`DEF_TRAVERSE_TYPELOC(FunctionProtoType` then goes to the function's
ParmVarDecls.

For a function template that doesn't have parameters that explicitly depend on
the template parameter, we used to be clever and not build a new
TypeSourceInfo. That meant that when an instantiation of such a template is
visited, its TypeSourceInfo would point to the ParmVarDecls of the template,
not of the instantiation, which then confused clients of RecursiveASTVisitor.

So don't be clever for function templates that have parameters, even if none of
the parameters depend on the type.

Fixes PR26257.
http://reviews.llvm.org/D16478

llvm-svn: 259428
2016-02-01 22:31:51 +00:00
Aaron Ballman 7e7b7b2def Reapply r259210 with a fix for RegistryTest.cpp.
Patch by Richard Thomson.

llvm-svn: 259359
2016-02-01 14:11:47 +00:00
Daniel Jasper d27df3dd3d clang-format: Fix incorrect pointer detection in lambdas in constructor
initializers.

Before:
  Constructor() : member([](A *a, B * b) {}) {}

After:
  Constructor() : member([](A *a, B *b) {}) {}

llvm-svn: 259353
2016-02-01 11:21:07 +00:00
Daniel Jasper e1a7b76338 clang-format: Add option to disable string literal formatting.
llvm-svn: 259352
2016-02-01 11:21:02 +00:00
Daniel Jasper bb37a2f6f3 clang-format: Fix alignment of trailing multiline columns.
llvm-svn: 259351
2016-02-01 11:20:55 +00:00
Daniel Jasper 1ce41112a4 clang-format: [JS] Treat "in" as a proper operator.
llvm-svn: 259350
2016-02-01 11:20:47 +00:00
Hans Wennborg 2b79910d8b Revert r259210 "Extend hasType narrowing matcher for TypedefDecls, add functionProtoType matcher for FunctionProtoType nodes, extend parameterCountIs to FunctionProtoType nodes."
It didn't pass check-clang.

llvm-svn: 259218
2016-01-29 18:24:34 +00:00
Aaron Ballman fb9d0e354d Extend hasType narrowing matcher for TypedefDecls, add functionProtoType matcher for FunctionProtoType nodes, extend parameterCountIs to FunctionProtoType nodes.
Patch by Richard Thomson

llvm-svn: 259210
2016-01-29 17:03:11 +00:00
Benjamin Kramer 987a1d21e7 Add an optional ToolName argument to runToolOnCodeWithArgs/buildASTFromCodeWithArgs.
This can be used as a way to modify argv[0] for a clang tool.

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

llvm-svn: 259187
2016-01-29 11:29:02 +00:00
Nico Weber 7b837f578a Include RecordDecls from anonymous unions in the AST.
For

  void f() {
    union { int i; };
  }

clang used to omit the RecordDecl from the anonymous union from the AST.
That's because the code creating it only called PushOnScopeChains(), which adds
it to the current DeclContext, which here is the function's DeclContext. But
RecursiveASTVisitor doesn't descent into all decls in a FunctionDecl.

Instead, for DeclContexts that contain statements, return the RecordDecl so
that it can be included in the DeclStmt containing the VarDecl for the union.

Interesting bits from the AST before this change:

|-FunctionDecl
| `-CompoundStmt
|   |-DeclStmt
|   | `-VarDecl 0x589cd60 <col:3> col:3 implicit used 'union (anonymous at test.cc:3:3)' callinit

After this change:

-FunctionDecl
| `-CompoundStmt
|   |-DeclStmt
|   | |-CXXRecordDecl 0x4612e48 <col:3, col:18> col:3 union definition
|   | | |-FieldDecl 0x4612f70 <col:11, col:15> col:15 referenced i 'int'
|   | `-VarDecl 0x4613010 <col:3> col:3 implicit used 'union (anonymous at test.cc:3:3)' callinit

This is now closer to how anonymous struct and unions are represented as
members of structs.  It also enabled deleting some one-off code in the
template instantiation code.

Finally, it fixes a crash with ASTMatchers, see the included test case
(this fixes http://crbug.com/580749).

llvm-svn: 259079
2016-01-28 19:25:00 +00:00
Daniel Jasper 15b01116d9 clang-format: [Java] Remove unnecessary line break after complex annotations
Before:
  @Annotation("Some"
      + " text")
  List<Integer>
      list;

After:
  @Annotation("Some"
      + " text")
  List<Integer> list;

llvm-svn: 258981
2016-01-27 20:14:23 +00:00
Chris Bieneman 2bf68c6c1c Remove autoconf support
Summary:
This patch is provided in preparation for removing autoconf on 1/26. The proposal to remove autoconf on 1/26 was discussed on the llvm-dev thread here: http://lists.llvm.org/pipermail/llvm-dev/2016-January/093875.html

    "This is the way [autoconf] ends
    Not with a bang but a whimper."
    -T.S. Eliot

Reviewers: chandlerc, grosbach, bob.wilson, echristo

Subscribers: klimek, cfe-commits

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

llvm-svn: 258862
2016-01-26 21:30:40 +00:00
Eugene Zelenko 1660a5d298 Fix Clang-tidy modernize-use-nullptr warnings; other minor fixes.
Differential revision: http://reviews.llvm.org/D16567

llvm-svn: 258836
2016-01-26 19:01:06 +00:00