Commit Graph

8136 Commits

Author SHA1 Message Date
Sam McCall a0f4c10ae2 [pseudo] Add error-recovery framework & brace-based recovery
The idea is:
 - a parse failure is detected when all heads die when trying to shift
   the next token
 - we can recover by choosing a nonterminal we're partway through parsing,
   and determining where it ends through nonlocal means (e.g. matching brackets)
 - we can find candidates by walking up the stack from the (ex-)heads
 - the token range is defined using heuristics attached to grammar rules
 - the unparsed region is represented in the forest by an Opaque node

This patch has the core GLR functionality.
It does not allow recovery heuristics to be attached as extensions to
the grammar, but rather infers a brace-based heuristic.

Expected followups:
 - make recovery heuristics grammar extensions (depends on D127448)
 - add recover to our grammar for bracketed constructs and sequence nodes
 - change the structure of our augmented `_ := start` rules to eliminate
   some special-cases in glrParse.
 - (if I can work out how): avoid some spurious recovery cases described
   in comments
 - grammar changes to eliminate the hard distinction between init-list
   and designated-init-list shown in the recovery-init-list.cpp testcase

Differential Revision: https://reviews.llvm.org/D128486
2022-06-28 21:08:43 +02:00
Sam McCall 3f028c02ba [pseudo] Grammar::parseBNF returns Grammar not unique_ptr. NFC 2022-06-28 16:34:21 +02:00
Sam McCall 241557fb06 [pseudo] Move cxx grammar into the cxx/ directory. NFC 2022-06-28 16:02:10 +02:00
Sam McCall aacefc817d [pseudo] Simplify/loosen the grammar around lambda captures.
Treat captures as a uniform list, rather than default-captures being special
snowflakes that may only appear at the start.

This accepts a larger set of (incorrect) code, and simplifies error-handling
by making this fit into the usual homogeneous-list pattern.

Differential Revision: https://reviews.llvm.org/D128708
2022-06-28 15:56:12 +02:00
Sam McCall 8cf28585a4 [pseudo] Allow mixed designated/undesignated init lists.
This isn't allowed by the standard grammar but is allowed in C, and clang/GCC
permit it as an extension.
It avoids the need to determine which type of list we have in error-recovery.

While here, also support array index designators `{ [4]=1 }` which are
also legal in C, and common extensions in C++.

Differential Revision: https://reviews.llvm.org/D128687
2022-06-28 15:45:41 +02:00
Sam McCall 85eaecbe8e [pseudo] Check follow-sets instead of tying reduce actions to lookahead tokens.
Previously, the action table stores a reduce action for each lookahead
token it should allow. These tokens are the followSet(action.rule.target).

In practice, the follow sets are large, so we spend a bunch of time binary
searching around all these essentially-duplicates to check whether our lookahead
token is there.
However the number of reduces for a given state is very small, so we're
much better off linear scanning over them and performing a fast check for each.

D128318 was an attempt at this, storing a bitmap for each reduce.
However it's even more compact just to use the follow sets directly, as
there are fewer nonterminals than (state, rule) pairs. It's also faster.

This specialized approach means unbundling Reduce from other actions in
LRTable, so it's no longer useful to support it in Action. I suspect
Action will soon go away, as we store each kind of action separately.

This improves glrParse speed by 42% (3.30 -> 4.69 MB/s).
It also reduces LR table size by 59% (343 -> 142kB).

Differential Revision: https://reviews.llvm.org/D128472
2022-06-28 00:36:16 +02:00
Aaron Ballman 9878e17624 Silence an "illegal conversion" diagnostic
MSVC was issuing "illegal conversion; more than one user-defined
conversion has been implicitly applied" as a warning on this code.
Explicitly calling .str() causes a StringRef to be materialized so
that a second user-defined conversion is not required.
2022-06-27 12:04:01 -04:00
Kazu Hirata 94460f5136 Don't use Optional::hasValue (NFC)
This patch replaces x.hasValue() with x where x is contextually
convertible to bool.
2022-06-26 19:54:41 -07:00
Joachim Priesner b2cb7e81f8 [clang-tidy] cppcoreguidelines-virtual-class-destructor: Fix crash when "virtual" keyword is expanded from a macro
Check llvm::Optional before dereferencing it.

Compute VirtualEndLoc differently to avoid an assertion failure
in clang::SourceManager::getFileIDLoaded:

Assertion `0 && "Invalid SLocOffset or bad function choice"' failed
2022-06-25 15:50:13 -06:00
Kazu Hirata 3b7c3a654c Revert "Don't use Optional::hasValue (NFC)"
This reverts commit aa8feeefd3.
2022-06-25 11:56:50 -07:00
Kazu Hirata aa8feeefd3 Don't use Optional::hasValue (NFC) 2022-06-25 11:55:57 -07:00
Kazu Hirata b8df4093e4 [clang, clang-tools-extra] Don't use Optional::{hasValue,getValue} (NFC) 2022-06-25 11:55:33 -07:00
Richard 5e97788a3e [clang-tidy] Update release notes (NFC)
- Sort changes to existing checks by check name
- Correct check link
2022-06-24 10:48:47 -06:00
Haojian Wu 9081d3d809 [clang-tidy] Make the cert/uppercase-literal-suffix-integer fully hermetic.
after the test-reorg commit (89a1d03e2b), the
cert/uppercase test starts to fail in our internal environment -- it accesses
a header file from "../readability", which is not friendly to a hermetic test environment.

This change makes the test fully hermetic, and does some cleanup on the
uppercase header (I think it is better to move it the share
Inputs/Header directory, and rename it)

Differential Revision: https://reviews.llvm.org/D128511
2022-06-24 14:18:02 +02:00
Nathan James fbf611ed2a
[clang-tidy] Extend spelling for CheckOptions
The current way to specify CheckOptions is pretty verbose and unintuitive.
Given that the options are a dictionary it makes much more sense to treat them as such in the config files.
Example:
```
CheckOptions: {SomeCheck.Option: true, SomeCheck.OtherOption: 'ignore'}
# Or
CheckOptions:
  SomeCheck.Option: true
  SomeCheck.OtherOption: 'ignore'
```

This change will still handle the old syntax with no issue, ensuring we don't screw up users current config files.

The only observable differences are support for the new syntax and `-dump=config` will emit using the new syntax.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D128337
2022-06-23 19:59:31 +01:00
Sam McCall 768216cac0 [pseudo] Handle no-reductions-available on the fastpath. NFC
This is a ~2% speedup.
2022-06-23 20:34:11 +02:00
Nathan James 5ca68d5845
[clang-tidy] Add `-verify-config` command line argument
Adds a `-verify-config` command line argument, that when specified will verify the Checks and CheckOptions fields in the config files:
 - A warning will be raised for any check that doesn't correspond to a registered check, a suggestion will also be emitted for close misses.
 - A warning will be raised for any check glob(containing *) that doesn't match any registered check.
 - A warning will be raised for any CheckOption that isn't read by any registered check, a suggestion will also be emitted for close misses.

This can be useful if debuging why a certain check isn't enabled, or the options are being handled as you expect them to be.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D127446
2022-06-23 19:23:09 +01:00
Sam McCall 466eae6aa3 [pseudo] Store last node popped in the queue, not its parent(s). NFC
We have to walk up to the last node to find the start token, but no need
to go even one node further.

This is one node fewer to store, but more importantly if the last node
happens to have multiple parents we avoid storing the sequence multiple times.

This saves ~5% on glrParse.
Based on a comment by hokein@ on https://reviews.llvm.org/D128307
2022-06-23 20:10:20 +02:00
Sam McCall 7aff663b2a [pseudo] Store reduction sequences by pointer in heaps, instead of by value.
Copying sequences around as the heap resized is significantly expensive.

This speeds up glrParse by ~35% (2.4 => 3.25 MB/s)

Differential Revision: https://reviews.llvm.org/D128307
2022-06-23 19:41:11 +02:00
Sam McCall 3e610f2cdc [pseudo] Turn glrReduce into a class, reuse storage across calls.
This is a ~5% speedup, we no longer have to allocate the priority queues and
other collections for each reduction step where we use them.

It's also IMO easier to understand the structure of a class with methods vs a
function with nested lambdas.

Differential Revision: https://reviews.llvm.org/D128301
2022-06-23 19:27:47 +02:00
Sam McCall f9710d1908 [pseudo] Add a fast-path to GLR reduce when both pop and push are trivial
In general we split a reduce into pop/push, so concurrently-available reductions
can run in the correct order. The data structures for this are expensive.

When only one reduction is possible at a time, we need not do this: we can pop
and immediately push instead.
Strictly this is correct whenever we yield one concurrent PushSpec.

This patch recognizes a trivial but common subset of these cases:
 - there must be no pending pushes and only one head available to pop
 - the head must have only one reduction rule
 - the reduction path must be a straight line (no multiple parents)

On my machine this speeds up by 2.12 -> 2.30 MB/s = 8%

Differential Revision: https://reviews.llvm.org/D128299
2022-06-23 18:21:59 +02:00
Sam McCall b70ee9d984 Reland "[pseudo] Track heads as GSS nodes, rather than as "pending actions"."
This reverts commit 2c80b53198.

Fixes LRTable::buildForTest to create states that are referenced but
have no actions.
2022-06-23 18:21:44 +02:00
Sam McCall 2c80b53198 Revert "[pseudo] Track heads as GSS nodes, rather than as "pending actions"."
This reverts commit e3ec054dfd.

Tests fail in asserts mode: https://lab.llvm.org/buildbot/#/builders/109/builds/41217
2022-06-23 18:16:38 +02:00
Sam McCall e3ec054dfd [pseudo] Track heads as GSS nodes, rather than as "pending actions".
IMO this model is simpler to understand (borrowed from the LR0 patch D127357).
It also makes error recovery easier to implement, as we have a simple list of
head nodes lying around to recover from when needed.
(It's not quite as nice as LR0 in this respect though).

It's slightly slower (2.24 -> 2.12 MB/S on my machine = 5%) but nothing close
to as bad as LR0.
However
 - I think we'd have to eat a litle performance loss otherwise to implement
   error recovery.
 - this frees up some complexity budget for optimizations like fastpath push/pop
   (this + fastpath is already faster than head)
 - I haven't changed the data structure here and it's now pretty dumb, we can
   make it faster

Differential Revision: https://reviews.llvm.org/D128297
2022-06-23 17:26:42 +02:00
Sam McCall 6b187fdf3b [pseudo] Add xfail tests for a simple-declaration/function-definition ambiguity
I expect to eliminate this ambiguity at the grammar level by use of guards,
because it interferes with brace-based error recvoery.

Differential Revision: https://reviews.llvm.org/D127400
2022-06-23 15:52:22 +02:00
Aaron Ballman e36535f99c Fix sphinx build for clang-tools-extra
I think it doesn't like the non-ASCII characters in the block, so using
a text block to disable syntax highlighting.

This should fix:
https://lab.llvm.org/buildbot/#/builders/115/builds/29888
2022-06-23 07:22:00 -04:00
Nathan James 165d69337a
[clang-tidy][docs] Fix a couple of missed cases from 6e566bc552
A few of the checks had documentation URLs that weren't updated in the aforementioned commit.
2022-06-22 21:37:16 +01:00
Nathan James b1cc59fd3a
[clang-tidy][docs] Reorganise release notes 2022-06-22 21:21:24 +01:00
Richard 89a1d03e2b [clang-tidy] Organize test files into subdirectories by module (NFC)
Eliminate clutter by reorganizing the Lit test files for clang-tidy:
- Move checkers/<module>-* to checkers/<module>/*.
- Move module specific inputs from Inputs to <module>/Inputs.  Remove
  any module prefix from the file or subdirectory name as they are no
  longer needed.
- Introduce a Lit substitution %clang_tidy_headers for the system
  headers in checkers/Inputs/Headers and use this throughout.  This
  avoids referencing system headers through a relative path to the
  parent directory and makes it clear that these fake system headers are
  shared among all modules.
- Update add_new_check.py to follow the above conventions when creating
  the boiler plate test files for a new check.
- Update Contributing.rst to describe per-module Inputs directory and
  fix link to test source code.

Differential Revision: https://reviews.llvm.org/D128072
2022-06-22 12:13:34 -06:00
Richard b967a97550 [clang-tidy] Fix documentation (NFC)
The documentation files were reorganized into subdirectories, but a new
check was added concurrently and wasn't rebased correctly before
submitting.  Sort the new clang-tidy checks by check name and fix the
indentation of bugprone-unchecked-optional-access.
2022-06-22 10:49:00 -06:00
Nico Weber 721875db2b Reland "[gn build] (manually) port b94db7ed7e (Confusables.inc)"
b94db7ed7e relanded in c3574ef739.

This relands commit 180bae08a0, rebased across the new version of
commit c3574ef739, and rebased across 10f7255d32.
2022-06-22 10:38:14 -04:00
serge-sans-paille c3574ef739 [clang-tidy] Confusable identifiers detection
Detect identifiers that are confusable using a variant of Unicode definition

        http://www.unicode.org/reports/tr39/#Confusable_Detection

and have conflicting scopes.

This a recommit (with portability and feature fixes) of b94db7ed7e

Differential Revision: https://reviews.llvm.org/D112916
2022-06-22 16:17:20 +02:00
Aaron Ballman bb297024fa Don't treat invalid parameters as being unused
The misc-unused-parameters check would trigger false positive warnings
about the parameter being unused when the parameter declaration was
invalid. No longer issue the warning in that case on the assumption
that most parameters are used in practice, so the extra diagnostic is
most likely a false positive.

Fixes #56152
2022-06-22 08:56:38 -04:00
Balazs Benics ae76b2f455 [clang-tidy][docs] Fix wrong sphinx link after d9afb8c3e8
There was a copy-paste mistake at the embedded link:
  `clang-tidy/checks/cppcoreguidelines-virtual-class-destructor`
  ->
  `clang-tidy/checks/cppcoreguidelines/virtual-class-destructor`

Sphinx error:
/home/zbebnal/git/llvm-project/clang-tools-extra/docs/ReleaseNotes.rst:168:unknown document: clang-tidy/checks/cppcoreguidelines-virtual-class-destructor

Build bot: https://lab.llvm.org/buildbot#builders/115/builds/29805

Differential Revision: https://reviews.llvm.org/D126891
2022-06-21 11:42:09 +02:00
Balazs Benics d9afb8c3e8 [clang-tidy] cppcoreguidelines-virtual-class-destructor should ignore final classes
The `cppcoreguidelines-virtual-class-destructor` supposed to enforce
http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c35-a-base-class-destructor-should-be-either-public-and-virtual-or-protected-and-non-virtual

Quote:
> A **base** class destructor should be either public and virtual, or
> protected and non-virtual
[emphasis mine]

However, this check still rules the following case:

  class MostDerived final : public Base {
  public:
    MostDerived() = default;
    ~MostDerived() = default;
    void func() final;
  };

Even though `MostDerived` class is marked `final`, thus it should not be
considered as a **base** class. Consequently, the rule is satisfied, yet
the check still flags this code.

In this patch, I'm proposing to ignore `final` classes since they cannot
be //base// classes.

Reviewed By: whisperity

Differential Revision:  https://reviews.llvm.org/D126891
2022-06-21 11:02:18 +02:00
Kazu Hirata ed8fceaa09 Don't use Optional::getValue (NFC) 2022-06-20 23:35:53 -07:00
Kazu Hirata 0916d96d12 Don't use Optional::hasValue (NFC) 2022-06-20 20:17:57 -07:00
Kazu Hirata 064a08cd95 Don't use Optional::hasValue (NFC) 2022-06-20 20:05:16 -07:00
Kazu Hirata 5413bf1bac Don't use Optional::hasValue (NFC) 2022-06-20 11:33:56 -07:00
Kadir Cetinkaya 1c92e06ded
[clangd] Handle initializers that contain =
Differential Revision: https://reviews.llvm.org/D128197
2022-06-20 16:42:54 +02:00
Joachim Priesner 541a50e207
[clang-tidy] bugprone-argument-comment: Ignore calls to user-defined literals
Without this change, code such as "f(/*param=*/1_op)" will check the
comment twice, once for the parameter of f (correct) and once for
the parameter of operator""_op (likely incorrect). The change removes
only the second check.

Reviewed By: njames93, LegalizeAdulthood

Differential Revision: https://reviews.llvm.org/D125885
2022-06-20 13:30:30 +01:00
Kazu Hirata 30c675878c Use value_or instead of getValueOr (NFC) 2022-06-19 10:34:41 -07:00
Kazu Hirata 5dd171dcb5 [clang-tools-extra] Use value_or instead of getValueOr (NFC) 2022-06-19 00:13:38 -07:00
Javier Alvarez 5ea341d7c4 [clang] Fix trivially copyable for copy constructor and copy assignment operator
From [class.copy.ctor]:

```
A non-template constructor for class X is a copy constructor if its first
parameter is of type X&, const X&, volatile X& or const volatile X&, and
either there are no other parameters or else all other parameters have
default arguments (9.3.4.7).

A copy/move constructor for class X is trivial if it is not user-provided and if:
- class X has no virtual functions (11.7.3) and no virtual base classes (11.7.2), and
- the constructor selected to copy/move each direct base class subobject is trivial, and
- or each non-static data member of X that is of class type (or array thereof),
  the constructor selected to copy/move that member is trivial;

otherwise the copy/move constructor is non-trivial.
```

So `T(T&) = default`; should be trivial assuming that the previous
provisions are met.

This works in GCC, but not in Clang at the moment:
https://godbolt.org/z/fTGe71b6P

Reviewed By: royjacobson

Differential Revision: https://reviews.llvm.org/D127593
2022-06-17 10:35:01 +03:00
Richard 6e566bc552 [clang-tidy] Organize check doc files into subdirectories (NFC)
- Rename doc files to subdirs by module
- Update release notes and check list to use subdirs
- Update add_new_check.py to handle doc subdirs

Differential Revision: https://reviews.llvm.org/D126495
2022-06-16 16:06:20 -06:00
Tobias Ribizel e984e1cd61
[clangd] Don't add inlay hints on std::move/forward
This removes parameter inlay hints from a few builtin functions like std::move/std::forward

Reviewed By: nridge

Differential Revision: https://reviews.llvm.org/D127859
2022-06-16 12:24:16 +02:00
David Goldman bc1f24332a [clangd] Improve ObjC protocol suggestions from the index
When querying the index during an ObjC protocol name lookup for code
completion, we should only suggest ObjC protocols.

Differential Revision: https://reviews.llvm.org/D127125
2022-06-15 15:02:37 -04:00
Kadir Cetinkaya 0473530281
[clangd][NFC] Use the existing ASTContext from scope 2022-06-15 16:10:49 +02:00
Kadir Cetinkaya 7212977fbb
[clangd] Always desugar type aliases in hover
The alias itself is already included in the definition section of the
hover (it's printed as spelled in source code). So it doesn't provide any value
when we print the aliases as-is.
Fixes https://github.com/clangd/clangd/issues/1134.

Differential Revision: https://reviews.llvm.org/D127832
2022-06-15 16:10:49 +02:00
Furkan Usta 462def25ec
[clang] Use correct visibility parameters when following a Using declaration
Fixes https://github.com/clangd/clangd/issues/1137

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D127629
2022-06-15 15:52:59 +02:00
Kadir Cetinkaya a67beef3ac
[clangd] Enable AKA type printing by default
This has been tested on a large set of c++ developers for a long while,
without any crashes or complaints.

Differential Revision: https://reviews.llvm.org/D127833
2022-06-15 10:43:17 +02:00
Kadir Cetinkaya 3ecfeb4c2f
[clangd] Wire up compilation for style blocks
Differential Revision: https://reviews.llvm.org/D127749
2022-06-15 08:15:32 +02:00
Balazs Benics 9da697e1bc Reland "[analyzer] Deprecate the unused 'analyzer-opt-analyze-nested-blocks' cc1 flag"
It was previously reverted by 8406839d19.

---

This flag was introduced by
6818991d71
    commit 6818991d71
    Author: Ted Kremenek <kremenek@apple.com>
    Date:   Mon Dec 7 22:06:12 2009 +0000

  Add clang-cc option '-analyzer-opt-analyze-nested-blocks' to treat
  block literals as an entry point for analyzer checks.

The last reference was removed by this commit:
5c32dfc5fb

    commit 5c32dfc5fb
    Author: Anna Zaks <ganna@apple.com>
    Date:   Fri Dec 21 01:19:15 2012 +0000

  [analyzer] Add blocks and ObjC messages to the call graph.
  This paves the road for constructing a better function dependency graph.
  If we analyze a function before the functions it calls and inlines,
  there is more opportunity for optimization.
  Note, we add call edges to the called methods that correspond to
  function definitions (declarations with bodies).

Consequently, we should remove this dead flag.
However, this arises a couple of burning questions.
 - Should the `cc1` frontend still accept this flag - to keep
   tools/users passing this flag directly to `cc1` (which is unsupported,
   unadvertised) working.
 - If we should remain backward compatible, how long?
 - How can we get rid of deprecated and obsolete flags at some point?

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D126067
2022-06-14 10:22:37 +02:00
Dmitri Gribenko 11f75e0a2d [clang-tidy][docs] Remove an unintentional paragraph break 2022-06-11 21:03:43 +02:00
Dmitri Gribenko 65299c9c65 [clang-tidy][docs] Use std::optional instead of absl::optional in examples
The standard type is vastly more popular than the Abseil polyfill, so it
makes more sense to use it in documentation, even though the checker
actually understands both (and that fact is documented already).
2022-06-11 21:03:43 +02:00
Nico Weber 8406839d19 Revert "[analyzer] Deprecate `-analyzer-store region` flag"
This reverts commit d50d9946d1.
Broke check-clang, see comments on https://reviews.llvm.org/D126067

Also revert dependent change "[analyzer] Deprecate the unused 'analyzer-opt-analyze-nested-blocks' cc1 flag"
This reverts commit 07b4a6d046.

Also revert "[analyzer] Fix buildbots after introducing a new frontend warning"
This reverts commit 90374df15d.
(See https://reviews.llvm.org/rG90374df15ddc58d823ca42326a76f58e748f20eb)
2022-06-10 08:50:13 -04:00
Shivam Gupta 8311604669 [NFC] update clang-tools-extra README.txt 2022-06-10 16:59:57 +05:30
Balazs Benics 4c38953f32 [clang-tidy] Remove reference to CSA AnalysisStoreOpt field
D126215 removed the `AnalysisStoreOpt` field, so `clang-tidy` should not
refer to it.
http://45.33.8.238/linux/78232/step_4.txt

  ../../clang-tools-extra/clang-tidy/ClangTidy.cpp:444:22: error: no
member named 'AnalysisStoreOpt' in 'clang::AnalyzerOptions'
      AnalyzerOptions->AnalysisStoreOpt = RegionStoreModel;
      ~~~~~~~~~~~~~~~~~^
  ../../clang-tools-extra/clang-tidy/ClangTidy.cpp:444:41: error: use of
undeclared identifier 'RegionStoreModel'
      AnalyzerOptions->AnalysisStoreOpt = RegionStoreModel;

This one liner patch should resolve the build failure.

Differential Revision: https://reviews.llvm.org/D126215
2022-06-10 13:21:28 +02:00
Balazs Benics 07b4a6d046 [analyzer] Deprecate the unused 'analyzer-opt-analyze-nested-blocks' cc1 flag
This flag was introduced by
6818991d71
    commit 6818991d71
    Author: Ted Kremenek <kremenek@apple.com>
    Date:   Mon Dec 7 22:06:12 2009 +0000

  Add clang-cc option '-analyzer-opt-analyze-nested-blocks' to treat
  block literals as an entry point for analyzer checks.

The last reference was removed by this commit:
5c32dfc5fb

    commit 5c32dfc5fb
    Author: Anna Zaks <ganna@apple.com>
    Date:   Fri Dec 21 01:19:15 2012 +0000

  [analyzer] Add blocks and ObjC messages to the call graph.
  This paves the road for constructing a better function dependency graph.
  If we analyze a function before the functions it calls and inlines,
  there is more opportunity for optimization.
  Note, we add call edges to the called methods that correspond to
  function definitions (declarations with bodies).

Consequently, we should remove this dead flag.
However, this arises a couple of burning questions.
 - Should the `cc1` frontend still accept this flag - to keep
   tools/users passing this flag directly to `cc1` (which is unsupported,
   unadvertised) working.
 - If we should remain backward compatible, how long?
 - How can we get rid of deprecated and obsolete flags at some point?

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D126067
2022-06-10 13:09:37 +02:00
Nathan James b831786292
[clang-tidy][NFC] Tweak identifier-naming options reading/writiing 2022-06-10 07:07:21 +01:00
Haojian Wu 70d35fe125 [pseudo] Fix the broken build of ClangPseudoBenchmark, after c70aeaa. 2022-06-09 23:03:54 +02:00
Haojian Wu c70aeaad2b [pseudo] Move grammar-related headers to a separate dir, NFC.
We did that for .cpp, but forgot the headers.

Differential Revision: https://reviews.llvm.org/D127388
2022-06-09 14:58:05 +02:00
Christian Kandeler bf830623b0 [pseudo] Fix unit test build
Analogous to 632545e8ce.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D127397
2022-06-09 14:42:47 +02:00
Sam McCall 18f0b7092d [pseudo] Don't clang-format test inputs. NFC 2022-06-09 14:18:30 +02:00
Haojian Wu 9ce232fba9 [pseudo] Fix the missing-field-initializers warning from f1ac00c9b0, NFC 2022-06-09 14:10:36 +02:00
Paul Pluzhnikov afbe3aed49 [clangd] Minor refactor of CanonicalIncludes::addSystemHeadersMapping.
Before commit b3a991df3c SystemHeaderMap used to be a vector.

Commit b3a991df3c changed it into a map, but neglected to remove
duplicate keys (e.g. "bits/typesizes.h", "include/stdint.h", etc.).

To prevent confusion, remove all duplicates, build HeaderMapping
one pair at a time and assert() that no duplicates are found.

Change by Paul Pluzhnikov (ppluzhnikov)!

Reviewed By: ilya-biryukov

Differential Revision: https://reviews.llvm.org/D125742
2022-06-09 12:18:39 +02:00
Haojian Wu f1ac00c9b0 [pseudo] Add grammar annotations support.
Add annotation handling ([key=value]) in the BNF grammar parser, which
will be used in the conditional reduction, and error recovery.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D126536
2022-06-09 12:06:22 +02:00
Haojian Wu 74e4d5f256 [pseudo] Simplify the glrReduce implementation.
glrReduce maintains two priority queues (one for bases, and the other
for Sequence), these queues are in parallel with each other, corresponding to a
single family. They can be folded into one.

This patch removes the bases priority queue, which improves the glrParse by
10%.

ASTReader.cpp: 2.03M/s (before) vs 2.26M/s (after)

Differential Revision: https://reviews.llvm.org/D127283
2022-06-09 11:28:52 +02:00
Haojian Wu 7a05942dd0 [pseudo] Remove the explicit Accept actions.
As pointed out in the previous review section, having a dedicated accept
action doesn't seem to be necessary. This patch implements the the same behavior
without accept acction, which will save some code complexity.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D125677
2022-06-09 11:19:07 +02:00
Haojian Wu 075449da80 [pseudo] Fix a sign-compare warning in debug build, NFC. 2022-06-09 11:18:03 +02:00
Christian Kandeler d352017184 [include-cleaner] Fix build error in unit test
Reviewed By: nridge

Differential Revision: https://reviews.llvm.org/D127217
2022-06-09 03:38:13 -04:00
Sam McCall 94b2ca18c1 [pseudo] GC GSS nodes, reuse them with a freelist
Most GSS nodes have short effective lifetimes, keeping them around until the
end of the parse is wasteful. Mark and sweep them every 20 tokens.

When parsing clangd/AST.cpp, this reduces the GSS memory from 1MB to 20kB.
We pay ~5% performance for this according to the glrParse benchmark.
(Parsing more tokens between GCs doesn't seem to improve this further).

Compared to the refcounting approach in https://reviews.llvm.org/D126337, this
is simpler (at least the complexity is better isolated) and has >2x less
overhead. It doesn't provide death handlers (for error-handling) but we have
an alternative solution in mind.

Differential Revision: https://reviews.llvm.org/D126723
2022-06-08 23:39:59 +02:00
Sam McCall bbc58c5e9b [pseudo] Restore accidentally removed debug print 2022-06-08 23:39:34 +02:00
Sam McCall 93bcff8aa8 [pseudo] Invert rows/columns of LRTable storage for speedup. NFC
There are more states than symbols.
This means first partioning the action list by state leaves us with a smaller
range to binary search over. This improves find() a lot and glrParse() by 7%.
The tradeoff is storing more smaller ranges increases the size of the offsets
array, overall grammar memory is +1% (337->340KB).

Before:
glrParse    188795975 ns    188778003 ns           77 bytes_per_second=1.98068M/s
After:
glrParse    175936203 ns    175916873 ns           81 bytes_per_second=2.12548M/s

Differential Revision: https://reviews.llvm.org/D127006
2022-06-08 23:35:14 +02:00
Nathan Lanza dd2f290918 Add llvm's Support lib to the psuedoCXX library
This is failing to find `EnableABIBreakingCheck` at link time. Add
Support to provide it here.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D127269
2022-06-08 17:12:02 -04:00
Andrew Browne c7689fd552 [Clang] Fix memory leak due to TemplateArgumentListInfo used in AST node.
It looks like the leak is rooted at the allocation here:
1a155ee7de/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (L3857)

The VarTemplateSpecializationDecl is allocated using placement new which uses the AST structure for ownership: 1a155ee7de/clang/lib/AST/DeclBase.cpp (L99)

The problem is the TemplateArgumentListInfo inside 1a155ee7de/clang/include/clang/AST/DeclTemplate.h (L2721)
This object contains a vector which does not use placement new: 1a155ee7de/clang/include/clang/AST/TemplateBase.h (L564)

Apparently ASTTemplateArgumentListInfo should be used instead 1a155ee7de/clang/include/clang/AST/TemplateBase.h (L575)

https://reviews.llvm.org/D125802#3551305

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D126944
2022-06-08 09:58:25 -07:00
Martin Boehme f4baf63155 [clang-tidy] Fix syntax error in release notes.
Introduced by
1b664460fa

Sorry for the breakage.
2022-06-07 13:04:56 +02:00
Martin Boehme 1b664460fa [clang-tidy] `bugprone-use-after-move`: Don't warn on self-moves.
Reviewed By: sammccall, njames93

Differential Revision: https://reviews.llvm.org/D126853
2022-06-07 12:53:03 +02:00
Haojian Wu 28eeea1e27 [pseudo]Pull out the operator< test, NFC
Fix the review comment in https://reviews.llvm.org/D125479.
2022-06-07 11:00:08 +02:00
Haojian Wu cf88150c48 [pseudo] Fix the incorrect parameters-and-qualifiers rule.
The parenthese body should be parameter-declaration-clause, rather
than parameter-declaration-list.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D125479
2022-06-07 10:47:07 +02:00
Haojian Wu ecd7ff53b5 [pseudo] Fix the type-parameter rule.
The IDENTIFIER should be optional.

Differential Revision: https://reviews.llvm.org/D126998
2022-06-07 10:36:45 +02:00
Haojian Wu 90dab0473e [pseudo] Handle the language predefined identifier __func__
The clang lexer lexes it as a dedicated token kind (rather than
identifier), we extend the grammar to handle it.

Differential Revision: https://reviews.llvm.org/D126996
2022-06-07 10:34:37 +02:00
Haojian Wu 58b33bc8c4 [pseudo] Fix noptr-abstract-declarator rule.
The const-expression in the [] can be empty.

Differential Revision: https://reviews.llvm.org/D126992
2022-06-07 10:22:23 +02:00
Haojian Wu 0a6a17a4f9 [pseudo] Fix the member-specification grammar rule.
The grammar rule is not right, doesn't match the standard one.

Differential Revision: https://reviews.llvm.org/D126991
2022-06-07 10:18:18 +02:00
Qingyuan Zheng c119a17e7f [AST] Fix clang RecursiveASTVisitor for definition of XXXTemplateSpecializationDecl
Fixes https://github.com/clangd/clangd/issues/1132
where clangd's semantic highlighting is missing for symbols of a template
specialization definition. It turns out the visitor didn't traverse the
base classes of Class/Var##TemplateSpecializationDecl, i.e.
CXXRecordDecl/VarDecl. This patch adds them back as what is done in
DEF_TRAVERSE_TMPL_PART_SPEC_DECL.

Reviewed By: rsmith

Differential Revision: https://reviews.llvm.org/D126757
2022-06-06 02:35:34 -04:00
Fangrui Song d86a206f06 Remove unneeded cl::ZeroOrMore for cl::opt/cl::list options 2022-06-05 00:31:44 -07:00
Fangrui Song 47ec8b5574 [pseudo] Fix leaks after D126731
Array Operator new Cookies help lsan find allocations, while std::array
can't.
2022-06-03 18:43:16 -07:00
Sam McCall 830d158d2b [pseudo] Add CLANG_PSEUDO_GEN cmake cache variable to avoid nested CMake invocation
Similar to LLVM_TABLEGEN, CLANG_TABLEGEN variables

Differential Revision: https://reviews.llvm.org/D126717
2022-06-03 20:48:55 +02:00
Sam McCall a43fef05d4 [pseudo] rename pseudo-gen -> clang-pseudo-gen. NFC
This name is not namespaced. Requested in D126717

Differential Revision: https://reviews.llvm.org/D126725
2022-06-03 20:45:48 +02:00
Sam McCall dc63ad8878 [pseudo] Eliminate dependencies from clang-pseudo-gen. NFC
ClangBasic dependency eliminated by replacing our usage of
tok::getPunctuatorSpelling etc with direct use of the *.def file.

Implicit dependencies on clang-tablegen-targets removed as we manage to avoid
any transitive tablegen deps.

After these changes, `ninja clean; ninja pseudo-gen` runs 169 actions only
(basically Support and Demangle).

Differential Revision: https://reviews.llvm.org/D126731
2022-06-03 20:42:38 +02:00
Nico Weber 371e6f8b7f Revert "[clang-tidy] Confusable identifiers detection"
This reverts commit b94db7ed7e.
See comments on https://reviews.llvm.org/D112916:
- breaks `check-clangd`, and makes clang-tidy crash on simple inputs
- likely does the wrong thing in cross builds

Also revert follow-up "[gn build] (manually) port b94db7ed7e (Confusables.inc)"
This reverts commit 180bae08a0.
2022-06-03 09:30:01 -04:00
Nico Weber 88052fd241 check_clang_tidy.py: Update run line to python3
`python` no longer exists on several systems, and the script
runs under python3 when run as part of lit.
2022-06-03 09:28:09 -04:00
Nico Weber 180bae08a0 [gn build] (manually) port b94db7ed7e (Confusables.inc) 2022-06-03 07:49:28 -04:00
CHIANG, YU-HSUN (Tommy Chiang, oToToT) 8df2b1a866 [pp-trace] Print HashLoc in InclusionDirective callback
The HashLoc in InclusionDirective callback is an unused parameter.
Since pp-trace is also used as a test of Clang’s PPCallbacks interface,
add it to the output of pp-trace could avoid some unintended change on
it.

This shuold resolves PR52673

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D125373
2022-06-03 19:29:59 +08:00
serge-sans-paille b94db7ed7e [clang-tidy] Confusable identifiers detection
Detect identifiers that are confusable according to Unicode definition

        http://www.unicode.org/reports/tr39/#Confusable_Detection

and have conflicting scopes.

Differential Revision: https://reviews.llvm.org/D112916
2022-06-03 12:18:36 +02:00
Martin Boehme b50542f21e [clang-tidy] Add missing close quote in release notes.
Sorry for the breakage.
2022-06-03 10:33:57 +02:00
Martin Boehme 8b90b25390 [clang-tidy] `bugprone-use-after-move`: Fix handling of moves in lambda captures
Previously, we were treating a move in the lambda capture as if it happened
within the body of the lambda, not within the function that defines the lambda.

This fixes the same bug as https://reviews.llvm.org/D119165 (which it appears
may have been abandoned by the author?) but does so more simply.

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D126780
2022-06-03 09:34:09 +02:00
Nicolas van Kempen 987f9cb6b9 [clang-tidy] Add proper emplace checks to modernize-use-emplace
modernize-use-emplace only recommends going from a push_back to an
emplace_back, but does not provide a recommendation when emplace_back is
improperly used. This adds the functionality of warning the user when
an unecessary temporary is created while calling emplace_back or other "emplacy"
functions from the STL containers.

Reviewed By: kuhar, ivanmurashko

Differential Revision: https://reviews.llvm.org/D101471
2022-06-03 00:14:57 +01:00
Mikael Holmen 35f0890c4e [clang-tidy] Remove extra ";" in ModernizeModuleTest.cpp
Without this fix we get

../../clang-tools-extra/unittests/clang-tidy/ModernizeModuleTest.cpp:270:2: error: extra ';' outside of a function is incompatible with C++98 [-Werror,-Wc++98-compat-extra-semi]
};
 ^
1 error generated.

when compiling with -Werror.
2022-06-02 12:50:00 +02:00
Richard b418ef5cb9 [clang-tidy] Reject invalid enum initializers in C files
C requires that enum values fit into an int.  Scan the macro tokens
present in an initializing expression and reject macros that contain
tokens that have suffixes making them larger than int.

C forbids the comma operator in enum initializing expressions, so
optionally reject comma operator.

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

Fixes #55467
2022-06-01 22:25:39 -06:00