Commit Graph

5066 Commits

Author SHA1 Message Date
Nikita Popov ed4e6e0398 [cmake] Remove LLVM_ENABLE_NEW_PASS_MANAGER cmake option
Or rather, error out if it is set to something other than ON. This
removes the ability to enable the legacy pass manager by default,
but does not remove the ability to explicitly enable it through
various flags like -flegacy-pass-manager or -enable-new-pm=0.

I checked, and our test suite definitely doesn't pass with
LLVM_ENABLE_NEW_PASS_MANAGER=OFF anymore.

Differential Revision: https://reviews.llvm.org/D123126
2022-04-06 09:52:21 +02:00
Nathan James b4ad3c3891 Reland "[ASTMatchers] Output currently matching node on crash"
Extend D120185 to also log the node being matched on in case of a crash.
This can help if a matcher is causing a crash or there are not enough interesting nodes bound.

Reviewed By: aaron.ballman

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

This reverts commit 61d67c8eec.

This relands commit 6e33e45b94.

Fixing the build issue on 32bit machines due to not enough free bits in the PointerUnion.
2022-04-05 21:47:16 +01:00
Yitzhak Mandelbaum d002495b94 [clang][dataflow] Support integral casts
Adds support for implicit casts `CK_IntegralCast` and `CK_IntegralToBoolean`.

Differential Revision: https://reviews.llvm.org/D123037
2022-04-05 13:55:32 +00:00
Yitzhak Mandelbaum 506ec85ba8 [clang][dataflow] Add support for clang's `__builtin_expect`.
This patch adds basic modeling of `__builtin_expect`, just to propagate the
(first) argument, making the call transparent.

Driveby: adds tests for proper handling of other builtins.

Differential Revision: https://reviews.llvm.org/D122908
2022-04-04 12:20:43 +00:00
Owen Pan 492cb7bf91 [clang-format] Fix a crash in qualifier alignment
Related to #54513.
2022-04-01 17:30:59 -07:00
Yitzhak Mandelbaum 01db10365e [clang][dataflow] Add support for correlation of boolean (tracked) values
This patch extends the join logic for environments to explicitly handle
boolean values. It creates the disjunction of both source values, guarded by the
respective flow conditions from each input environment. This change allows the
framework to reason about boolean correlations across multiple branches (and
subsequent joins).

Differential Revision: https://reviews.llvm.org/D122838
2022-04-01 17:25:49 +00:00
Yitzhak Mandelbaum ef1e1b3106 [clang][dataflow] Add support for (built-in) (in)equality operators
Adds logical interpretation of built-in equality operators, `==` and `!=`.s

Differential Revision: https://reviews.llvm.org/D122830
2022-04-01 17:13:21 +00:00
Yitzhak Mandelbaum 36d4e84427 [clang][dataflow] Fix handling of base-class fields.
Currently, the framework does not track derived class access to base
fields. This patch adds that support and a corresponding test.

Differential Revision: https://reviews.llvm.org/D122273
2022-04-01 15:01:32 +00:00
Iain Sandoe c7ed65b4bc [C++20][Modules] Limit ModuleInternalLinkage to modules-ts.
At present, we are generating wrong code for C++20 modules entities which
should have internal linkage.  This is because we are assigning
'ModuleInternalLinkage' unconditionally to such entities.  However this mode
is only applicable to the modules-ts.

This change makes the special linkage mode conditional on fmodules-ts and
adds a unit test to verify that we generate the correct linkage.

Currently, static variables and functions in module purview are emitted into
object files as external. On some platforms, lambdas are emitted as global
weak defintions (on Windows this causes a mangler crash).

Differential Revision: https://reviews.llvm.org/D122413
2022-04-01 09:10:30 +01:00
Yitzhak Mandelbaum 7f076004e9 [clang][dataflow] Add support for `value_or` in a comparison.
This patch adds limited modeling of the `value_or` method. Specifically, when
used in a particular idiom in a comparison to implicitly check whether the
optional holds a value.

Differential Revision: https://reviews.llvm.org/D122231
2022-03-31 13:21:39 +00:00
sstwcw f6740fe483 [clang-format] Indent import statements in JavaScript.
[clang-format] Indent import statements in JavaScript.

Take for example this piece of code found at
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import>.

```
for (const link of document.querySelectorAll("nav > a")) {
  link.addEventListener("click", e => {
    e.preventDefault();

    import('/modules/my-module.js')
        .then(module => {
          module.loadPageInto(main);
        })
        .catch(err => {
          main.textContent = err.message;
        });
  });
}
```

Previously the import line would be unindented, looking like this.

```
for (const link of document.querySelectorAll("nav > a")) {
  link.addEventListener("click", e => {
    e.preventDefault();

import('/modules/my-module.js')
        .then(module => {
          module.loadPageInto(main);
        })
        .catch(err => {
          main.textContent = err.message;
        });
  });
}
```

Actually we were going to fix this along with fixing Verilog import
statements.  But the patch got too big.

Reviewed By: MyDeveloperDay, curdeius

Differential Revision: https://reviews.llvm.org/D121906
2022-03-30 23:17:27 +00:00
Nathan James 61d67c8eec Revert "[ASTMatchers] Output currently matching node on crash"
This reverts commit 6e33e45b94.

Fails to build on 32bit machines due to PointerUnion limitations
2022-03-30 18:10:48 +01:00
Nathan James 6e33e45b94
[ASTMatchers] Output currently matching node on crash
Extend D120185 to also log the node being matched on in case of a crash.
This can help if a matcher is causing a crash or there are not enough interesting nodes bound.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D122529
2022-03-30 17:14:00 +01:00
owenca eee536dd31 [clang-format] Don't format qualifiers in PPDirective
Fixes #54513

Differential Revision: https://reviews.llvm.org/D122548
2022-03-28 14:28:14 -07:00
Eric Li a29fd4d4da [libTooling] Fix indentation. NFC. 2022-03-28 18:34:45 +00:00
Balázs Kéri c5d83cdca4 [clang][ASTImporter] Fix a bug when importing CXXDefaultInitExpr.
The "in-class initializer" expression should be set in the field of a
default initialization expression before this expression node is created.
The `CXXDefaultInitExpr` objects are created after the AST is loaded and
at import not present in the "To" AST. And the in-class initializers of
the used fields can be missing too, these must be set at import.

This fixes a github issue #54061.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D120824
2022-03-28 10:55:26 +02:00
Corentin Jabot 3784e8ccfb [Clang] Fix Unevaluated Lambdas
Unlike other types, when lambdas are instanciated,
they are recreated from scratch.
When an unevaluated lambdas appear in the type of a function,
parameter it is instanciated in the wrong declaration context,
as parameters are transformed before the function.

To support lambda in function parameters, we try to
compute whether they are dependant without looking at the
declaration context.

This is a short term stopgap solution to avoid clang
iceing. A better fix might be to inject some kind of
transparent declaration with correctly computed dependency
for function parameters, variable templates, etc.

Fixes https://github.com/llvm/llvm-project/issues/50376
Fixes https://github.com/llvm/llvm-project/issues/51414
Fixes https://github.com/llvm/llvm-project/issues/51416
Fixes https://github.com/llvm/llvm-project/issues/51641
Fixes https://github.com/llvm/llvm-project/issues/54296

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D121532
2022-03-25 19:16:45 +01:00
Nathan James b97f26083b Reland "[ASTMatchers] Output currently processing match and nodes on crash"
This reverts commit cff34ccb60.

This relands commit d89f9e963e
2022-03-25 17:53:58 +00:00
Yitzhak Mandelbaum a184a0d8aa [clang][dataflow] Add support for disabling warnings on smart pointers.
This patch provides the user with the ability to disable all checked of accesses
to optionals that are the pointees of smart pointers. Since smart pointers are
not modeled (yet), the system cannot distinguish safe from unsafe accesses to
optionals through smart pointers. This results in false positives whenever
optionals are used through smart pointers. The patch gives the user the choice
of ignoring all positivess in these cases.

Differential Revision: https://reviews.llvm.org/D122143
2022-03-25 16:44:34 +00:00
Marek Kurdej 311a00c390 [clang-format] Clean up DefinitionBlockSeparatorTest. NFC. 2022-03-25 10:59:46 +01:00
Krasimir Georgiev be5c3ca7fb Revert "[clang-format] Correctly recognize arrays in template parameter list."
This reverts commit 126b37a713.

Regressed some ObjC patterns, see comments on https://reviews.llvm.org/D121584.
2022-03-24 10:14:13 +01:00
Kai Luo b8388fa319 [clang][NFC] Fix warning of integer comparison
```
warning: comparison of integers of different signs: 'const unsigned long' and 'const int' [-Wsign-compare]
```

Fix https://lab.llvm.org/buildbot/#/builders/57/builds/16220.
2022-03-24 14:06:45 +08:00
owenca f74413d163 [clang-format] Fix invalid code generation with comments in lambda
Fixes #51234 and #54496

Differential Revision: https://reviews.llvm.org/D122301
2022-03-23 19:40:24 -07:00
Chuanqi Xu 8474668608 [C++20] [Modules] Make the linkage consistent for template and its
specialization

Before the patch, the compiler would crash for the test due to
inconsistent linkage.

This patch tries to avoid it by make the linkage consistent for template
and its specialization. After the patch, the behavior of compiler would
be partially correct for the case.
The correct one is:

```
export template<class T>
void f() {}

template<>
void f<int>() {}
```

In this case, the linkage for both declaration should be external (the
wording I get by consulting in WG21 is "the linkage for name f should be
external").

And for the case:
```
template<class T>
void f() {}

export template<>
void f<int>() {}
```

Compiler should reject it. This isn't done now. After all, this patch would
stop a crash.

Reviewed By: iains, aaron.ballman, dblaikie

Differential Revision: https://reviews.llvm.org/D120397
2022-03-24 10:24:14 +08:00
Marek Kurdej 4e88cb6825 [clang-format] Handle attributes before case label. Relanded.
Fixes https://github.com/llvm/llvm-project/issues/53110.

Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan

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

Relanding as the original patch provoked an infinite loop in JavaScript/TypeScript.
A reproducer test case was added and the issue fixed.
2022-03-23 16:24:24 +01:00
Krasimir Georgiev eb35e0ecbe [clang-format] don't break up #-style comment sections
Follow-up from 36d13d3f8a; https://reviews.llvm.org/D121451.

Restore the old behavior in situations where we use # as comments and long strings of #'s for comment sections.

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D122230
2022-03-22 15:29:02 +01:00
Stanislav Gatev 2ddd57ae1e [clang][dataflow] Model the behavior of optional and std swap
Differential Revision: https://reviews.llvm.org/D122129

Reviewed-by: ymandel, xazax.hun
2022-03-22 08:35:34 +00:00
Ella Ma 9f90254286 [analyzer][ctu] Fix wrong 'multiple definitions' errors caused by space characters in lookup names when parsing the ctu index file
This error was found when analyzing MySQL with CTU enabled.

When there are space characters in the lookup name, the current
delimiter searching strategy will make the file path wrongly parsed.
And when two lookup names have the same prefix before their first space
characters, a 'multiple definitions' error will be wrongly reported.

e.g. The lookup names for the two lambda exprs in the test case are
`c:@S@G@F@G#@Sa@F@operator int (*)(char)#1` and
`c:@S@G@F@G#@Sa@F@operator bool (*)(char)#1` respectively. And their
prefixes are both `c:@S@G@F@G#@Sa@F@operator` when using the first space
character as the delimiter.

Solving the problem by adding a length for the lookup name, making the
index items in the format of `<USR-Length>:<USR File> <Path>`.

---

In the test case of this patch, we found that it will trigger a "triple
mismatch" warning when using `clang -cc1` to analyze the source file
with CTU using the on-demand-parsing strategy in Darwin systems. And
this problem is also encountered in D75665, which is the patch
introducing the on-demand parsing strategy.
We temporarily bypass this problem by using the loading-ast-file
strategy.

Refer to the [discourse topic](https://discourse.llvm.org/t/60762) for
more details.

Differential Revision: https://reviews.llvm.org/D102669
2022-03-22 10:28:42 +08:00
Nathan James cff34ccb60 Revert "[ASTMatchers] Output currently processing match and nodes on crash"
This reverts commit d89f9e963e.
2022-03-21 22:29:22 +00:00
Jorge Gorbe Moya 5b81158675 Revert "[clang-format] Handle attributes before case label."
This reverts commit 596fa2d900.
2022-03-21 14:39:14 -07:00
Eric Li 9edeceaece [libTooling] Generalize string explanation as templated metadata
Change RewriteRule from holding an `Explanation` to being able to generate
arbitrary metadata. Where TransformerClangTidyCheck was interested in a string
description for the diagnostic, other tools may be interested in richer metadata
at a higher level of abstraction than at the edit level (which is currently
available as ASTEdit::Metadata).

Reviewed By: ymandel

Differential Revision: https://reviews.llvm.org/D120360
2022-03-21 20:39:35 +00:00
Nathan James d89f9e963e
[ASTMatchers] Output currently processing match and nodes on crash
Create a PrettyStackTraceEvent that will dump the current `MatchCallback` id as well as the `BoundNodes` if the 'run' method of a `MatchCallback` results in a crash.
The purpose of this is sometimes clang-tidy checks can crash in the `check` method. And in a large codebase with alot of checks enabled and in a release build, it can be near impossible to figure out which check as well as the source code that caused the crash. Without that information a reproducer is very hard to create.
This is a more generalised version of D118520 which has a nicer integration and should be useful to clients other than clang-tidy.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D120185
2022-03-21 19:13:36 +00:00
Yitzhak Mandelbaum 8351726e6d Revert "[libTooling] Generalize string explanation as templated metadata"
This reverts commit 18440547d3. Causing failures
in some build modes.

e.g. https://lab.llvm.org/buildbot/#/builders/217/builds/1886
2022-03-21 19:06:59 +00:00
Aaron Ballman 403d7d8d70 Ignore FullExpr when traversing cast sub-expressions
Full-expressions are Sema-generated implicit nodes that cover
constant-expressions and expressions-with-cleanup for temporaries.

Ignore those as part of implicit-ignore, and also remove too-aggressive
IgnoreImplicit (which includes nested ImplicitCastExprs, for example)
on unpacked sub-expressions.

Add some unittests to demonstrate that RecursiveASTVisitor sees through
ConstantExpr nodes correctly.

Adjust cxx2a-consteval test to cover diagnostics for nested consteval
expressions that were previously missed.

Fixes bug #53044.
2022-03-21 15:05:53 -04:00
Eric Li 18440547d3 [libTooling] Generalize string explanation as templated metadata
Change RewriteRule from holding an `Explanation` to being able to generate
arbitrary metadata. Where TransformerClangTidyCheck was interested in a string
description for the diagnostic, other tools may be interested in richer metadata
at a higher level of abstraction than at the edit level (which is currently
available as ASTEdit::Metadata).

Reviewed By: ymandel

Differential Revision: https://reviews.llvm.org/D120360
2022-03-21 18:45:39 +00:00
Paul Robinson bb78dd2e1f [RGT] StencilTest: Fix an assertion
ASSERT_THAT_EXPECTED implicitly calls takeError(), and calling
takeError() a second time returns nothing, so the check for the
content of the error text wasn't being executed.
Fixes Issue #48901

Found by the Rotten Green Tests project.
2022-03-18 14:13:41 -07:00
Yitzhak Mandelbaum a36c2dd6d5 [clang][dataflow] Add modeling of Chromium's CHECK functionality
Chromium's implementation of assertions (`CHECK`, `DCHECK`, etc.) are not
annotated with "noreturn", by default. This patch adds a model of the logical
implications of successfully executing one of these assertions.

Differential Revision: https://reviews.llvm.org/D121797
2022-03-18 14:39:23 +00:00
Marek Kurdej c79e18da4f [clang-format] Expect instead of setting the same value in tests. NFC. 2022-03-18 15:01:41 +01:00
Stanislav Gatev b000b7705a [clang][dataflow] Model the behavior of non-standard optional assignment
Model nullopt, value, and conversion assignment operators.

Reviewed-by: xazax.hun

Differential Revision: https://reviews.llvm.org/D121863
2022-03-17 17:11:12 +00:00
Marek Kurdej dc142ea184 [clang-format] Correctly recognize binary operators in template arguments with parenthesized literals.
Fixes https://github.com/llvm/llvm-project/issues/24602.

Before, code like `foo<b & 1>` was formatted correctly but `foo<b & (1)>` wasn't.
This patch fixes this inconsistency.

Reviewed By: HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D121846
2022-03-17 09:36:25 +01:00
Marek Kurdej 34ce42fe4d [clang-format] Reformat. NFC. 2022-03-17 09:27:31 +01:00
Marek Kurdej dbefb7e86f [clang-format] Reformat. NFC. 2022-03-16 21:54:11 +01:00
Owen Pan 7fb2d9f9b5 [clang-format] Fix crashes due to missing l_paren
Fixes #54384.

Differential Revision: https://reviews.llvm.org/D121682
2022-03-16 01:45:20 -07:00
Sam McCall 89cd86bbc5 Reapply [pseudo] Move pseudoparser from clang to clang-tools-extra"
This reverts commit 049f4e4eab.

The problem was a stray dependency in CLANG_TEST_DEPS which caused cmake
to fail if clang-pseudo wasn't built. This is now removed.
2022-03-16 01:10:55 +01:00
Sam McCall 049f4e4eab Revert "[pseudo] Move pseudoparser from clang to clang-tools-extra"
This reverts commit b97856c4cf.

Breaks a bunch of bots:
https://lab.llvm.org/buildbot/#/builders/193/builds/8513
2022-03-16 01:06:24 +01:00
Sam McCall b97856c4cf [pseudo] Move pseudoparser from clang to clang-tools-extra
This should make clearer that:
 - it's not part of clang proper
 - there's no expectation to update it along with clang (beyond green tests)
 - clang should not depend on it

This is intended to be expose a library, so unlike other tools has a split
between include/ and lib/.

The main renames are:
  clang/lib/Tooling/Syntax/Pseudo/*           => clang-tools-extra/pseudo/lib/*
  clang/include/clang/Tooling/Syntax/Pseudo/* => clang-tools-extra/pseudo/include/clang-pseudo/*
  clang/tools/clang/pseudo/*                  => clang-tools-extra/pseudo/tool/*
  clang/test/Syntax/*                         => clang-tools-extra/pseudo/test/*
  clang/unittests/Tooling/Syntax/Pseudo/*     => clang-tools-extra/pseudo/unittests/*
  #include "clang/Tooling/Syntax/Pseudo/*"    => #include "clang-pseudo/*"
  namespace clang::syntax::pseudo             => namespace clang::pseudo
  check-clang                                 => check-clang-pseudo
  clangToolingSyntaxPseudo                    => clangPseudo
The clang-pseudo and ClangPseudoTests binaries are not renamed.

See discussion around:
https://discourse.llvm.org/t/rfc-a-c-pseudo-parser-for-tooling/59217/50

Differential Revision: https://reviews.llvm.org/D121233
2022-03-16 00:14:11 +01:00
Björn Schäpers 1db8112311 [clang-format] Fix crash with ObjC Blocks
Fixes https://github.com/llvm/llvm-project/issues/54367
Fixes https://github.com/llvm/llvm-project/issues/54368

Differential Revision: https://reviews.llvm.org/D121596
2022-03-15 21:41:57 +01:00
Marek Kurdej 3227aa3aa8 [clang-format] Correctly format variable templates.
Fixes https://github.com/llvm/llvm-project/issues/54257.

Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D121456
2022-03-15 13:16:56 +01:00
Marek Kurdej e60defb931 [clang-format] Add regression tests for function ref qualifiers on operator definition. NFC.
Fixes https://github.com/llvm/llvm-project/issues/54374.
2022-03-15 12:58:08 +01:00
Marek Kurdej 126b37a713 [clang-format] Correctly recognize arrays in template parameter list.
Fixes https://github.com/llvm/llvm-project/issues/54245.

Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D121584
2022-03-15 11:33:13 +01:00