Commit Graph

8011 Commits

Author SHA1 Message Date
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
Adrian Prantl d951ca5439 Revert "[Driver] Enable to use C++20 standalne by -fcxx-modules"
This reverts commit a544710cd4.

See discussion in D120540.

This breaks C++ Clang modules on Darwin and also more than a dozen
tests in the LLDB testsuite.  I think we need to be more careful to
separate out the enabling of Clang C++ modules and C++20
modules. Either by having -fmodules-ts control the HaveModules flag,
or by adding a way to explicitly turn them off.
2022-06-01 12:11:57 -07:00
Haojian Wu 94552f0216 [pseudo] Build inc files when cxx.bnf changes.
Add the cxx.bnf file as a dependency of custom gen commands, so that the
inc files can be rebuilt when cxx.bnf changes.
2022-06-01 13:48:09 +02:00
Endre Fülöp e290fcef11 [clang-tidy] Extend cert-oop57-cpp to check non-zero memset values
Clang Tidy check cert-oop57-cpp now checks for arbitrary-valued
arguments in memset expressions containing non-trivially
default-constructible instances. Previously it only checked literal 0 values.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D126186
2022-06-01 08:23:23 +02:00
Endre Fülöp 1c459a20ea Revert "[clang-tidy] Extend cert-oop57-cpp to check non-zero memset values"
Revert to fix a ReleaseNote issue.

This reverts commit d33f199910.
2022-06-01 08:21:16 +02:00
Endre Fülöp d33f199910 [clang-tidy] Extend cert-oop57-cpp to check non-zero memset values
Clang Tidy check cert-oop57-cpp now checks for arbitrary-valued
arguments in memset expressions containing non-trivially
default-constructible instances. Previously it only checked literal 0 values.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D126186
2022-06-01 08:15:03 +02:00
Yuki Okushi 5c14940394
[clangd] Remove a test with a duplicate of FileCacheTests
FIXME says it should be removed so followed it.

Differential Revision: https://reviews.llvm.org/D126608
2022-06-01 08:15:54 +09:00
Sam McCall 218393f44e Revert "[clangd] Fix hover crashing on integral or enumeral casts"
This reverts commit ce5ebf0b91.

Fails on bots e.g. https://buildkite-cloud.s3.amazonaws.com/logs-by-pipeline/f8ab115f-a384-49e8-a048-0f71ab03c5d0/0181020b-0737-40e5-a05a-ab198347d8ad/0181020b-ecbe-4ac6-ad23-e04c17217893.log?response-content-disposition=inline&response-content-type=text%2Fplain&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIAQPCP3C7LT7IGTS76%2F20220531%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220531T202904Z&X-Amz-Expires=600&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEDwaCXVzLWVhc3QtMSJGMEQCIEfw6ocELTUWa2mj4reHKLe5OdUmQqVJpPsdZS2wNDhhAiB7qx6Q17HVVY%2BkJZ5hwTQ6b1MkOG4czysfciD9GghJmCrSBAg1EAAaDDAzMjM3OTcwNTMwMyIMgdUfJT4A6wcP2hl2Kq8EefYtGIt0yaiOSfuq05UzI6WcBY9yOOyYCs3%2FJJDvK3jkpiYQhjA1kgVluePIb3P4yOTXs8lv9U6p8HU555Vzvrv1Wg%2FGvx7U398lH8zg%2BqkvEwnpGuRf0pTInPJftg2bgm%2F7l%2BCM6PtW4mRlzjeQ0IoA3AeENqVM35RYtQdh%2BcAZIfV4l7uAySVgwY1yFu0XznuGAVVryZyYcA2cjKkkNE%2F9n2QTo80%2FbZBvoh1bxJqXRbs5WrSnWlIEj3RPX61ir7lDpRNL5tyVlqsv%2BvV01aS%2F9JbM4cNDXZ%2BDwOR1Q%2By1ajJOomuK9Bqm%2Fq8%2B9%2Byo1t8rFSN7I4X%2BGGuicXFQQnIJAkW3zSQlx9SWrf2uDg7cbXL4MukD9cQB5aN8yX85a%2BRcbb5l4%2BOC%2B8UFKMeemUZyEl5PyyJSBnAnzqvKviJPev9Thj9rZeHGEJD9vOkVM%2FG2tOlC7HUxXAE4kuLlAdeKdIOtHz%2Bx8FzRn%2Bgl6EB2nB4kSVLvfgrsrlHS0L0J1zWbN%2F6prqzum%2FEVIhT7Y5fyZRqtygAX2n7iBjQEM3vpF2GTneUI1FlDeQvGPLADFdq7bXSUOt577YOTw1mW1JzqmZljrJeIM40HdMYnuIg3%2FwW8oK6RKGADdW7URPw%2FoFeGKfrnN%2BuDwJKvrRGCpReseGse2sdYIe28rgGHpc5xsp3pzipQDLfW3hTNtM%2FNNuPJjUWZoBRTMr2eMuk2zs2c6jNvnuBTbgXjcdjCbjCX2dmUBjqqAUalggvk2TGoJzTuqAT%2Fj1kz0vnHdmsHY3B9aR2kY501gISXQMKj7l03E7OfFsu4oPzEgmnyQFKcAolRDI%2F7NRmG8HwtP40iTCjflOHIxkJ1%2FnVNqkeyIznUu6zOr589zIjNqFCm74jOfWjj2%2FO8WU4pc%2FRqeBuGzzpQkAIGGxCwsmd3WG8Z8pyMoJomij7c4LO6ep4O0OUESxbXHcIfzUfR6ajPsKFKS9lb&X-Amz-SignedHeaders=host&X-Amz-Signature=96a132be6f99b5cd5cf29f3226115e480508079047bc8639d69c672f1fe9f0c1
2022-05-31 22:30:20 +02:00
Georg Kotheimer ce5ebf0b91 [clangd] Fix hover crashing on integral or enumeral casts
When pretty printing the value of an expression, we cannot infer from
the type of the expression the type of the constant that the expression
evaluates to, as the expression might contain a type cast.
2022-05-31 22:05:23 +02:00
Sam McCall 9d991da60d [pseudo] Respect LLVM_USE_HOST_TOOLS
This is the intended way to request that build-time tools be built in a
distinct configuration.

This is set implicitly by LLVM_OPTIMIZED_TABLEGEN, which may be
surprising, but if undesired this should be fixed elsewhere.

Should fix crbug.com/1330304
2022-05-31 20:47:57 +02:00
David Goldman c797952d4f [clangd] Minor fixes to ExtractVariableTests missed in D124486 2022-05-31 11:34:35 -04:00
David Goldman ae67984ca6 [clangd] ExtractVariable support for C and Objective-C
- Use the expression's type for non-C++ as the variable type. This works
  well, but might not preserve the typedefs due to type
  canonicalization.

- Improve support for Objective-C property references which are
  represented using `ObjCPropertyRefExpr` and `BuiltinType::PseudoObject`.

Differential Revision: https://reviews.llvm.org/D124486
2022-05-31 11:14:51 -04:00
Haojian Wu a5ddd4a238 [pseudo] Remove an unnecessary nullable check diagnostic in the bnf
grammar, NFC.

This diagnostic has been handled in eliminateOptional.
2022-05-30 09:04:47 +02:00
Chuanqi Xu a544710cd4 [Driver] Enable to use C++20 standalne by -fcxx-modules
This patch allows user to use C++20 module by -fcxx-modules. Previously,
we could only use it under -std=c++20. Given that user could use C++20
coroutine standalonel by -fcoroutines-ts. It makes sense to offer an
option to use C++20 modules without enabling C++20.

Reviewed By: iains, MaskRay

Differential Revision: https://reviews.llvm.org/D120540
2022-05-30 14:19:56 +08:00
Sockke 3f3a235aa2 [clang-apply-replacements] Added an option to ignore insert conflict.
If two different texts are inserted at the same offset, clang-apply-replacements prints the conflict error and discards all fixes. This patch adds support for adjusting conflict offset and keeps running to continually fix them.

https://godbolt.org/z/P938EGoxj doesn't have any fixes when I run run-clang-tidy.py to generate a YAML file with clang-tidy and fix them with clang-apply-replacements. The YAML file has two different header texts insertions at the same offset, unlike clang-tidy with '-fix', clang-apply-replacements does not adjust for this conflict.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D123924
2022-05-30 13:02:25 +08:00
Sockke c98b3a8cd9 Fix `performance-unnecessary-value-param` for template specialization
The checker missed a check for parameter type of primary template of specialization template and this could cause build breakages.

Reviewed By: aaron.ballman, flx

Differential Revision: https://reviews.llvm.org/D116593
2022-05-30 09:55:53 +08:00
Shoaib Meenai 4baae166ce [pseudo] Fix pseudo-gen usage when cross-compiling
Use the LLVM build system's cross-compilation support for the tool, so
that the build works for both host and cross-compilation scenarios.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D126397
2022-05-25 11:08:21 -07:00
Nico Weber 788463e72a [pseudo-gen] Add -o flag, make --grammar required
Virtually all LLVM tools accept a `-o` flag, so add one. This will make it
possible to possibly add a --write-if-changed flag later. It also makes it
so that the file isn't partially written if the tool oesn't run successfully.

Marking --grammar as `Required` allows removing some manual
verification code for it.

Differential Revision: https://reviews.llvm.org/D126373
2022-05-25 09:11:42 -04:00
Nathan James 09ef6da8dc
[clang-tidy] Update docs for SimplifyDeMorganRelaxed
Forgot to add this to f3c1d28176
2022-05-25 13:12:20 +01:00
Nathan James f3c1d28176
[clang-tidy] Extend SimplifyBooleanExpr demorgan support.
Adds an option SimplifyDemorganRelaxed which, when enabled, will transform negated conjunctions or disjunctions when neither operand is a negation.
Default value is `false`.

Reviewed By: LegalizeAdulthood

Differential Revision: https://reviews.llvm.org/D126162
2022-05-25 13:09:00 +01:00
Haojian Wu f1df6515e3 [pseudo] Add missing dependency, fix shared library build. 2022-05-25 12:38:23 +02:00
Haojian Wu cd2292ef82 [pseudo] A basic implementation of compiling cxx grammar at build time.
The main idea is to compile the cxx grammar at build time, and construct
the core pieces (Grammar, LRTable) of the pseudoparse based on the compiled
data sources.

This is a tiny implementation, which is good for start:

- defines how the public API should look like;
- integrates the cxx grammar compilation workflow with the cmake system.
- onlynonterminal symbols of the C++ grammar are compiled, anything
  else are still doing the real compilation work at runtime, we can opt-in more
  bits in the future;
- splits the monolithic clangPsuedo library for better layering;

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D125667
2022-05-25 11:26:06 +02:00
Salman Javed 9ff4f2dfea [clang-tidy] Fix #55134 (regression introduced by 5da7c04)
5da7c04 introduced a regression in the NOLINT macro checking loop, replacing the
call to `getImmediateExpansionRange().getBegin()` with
`getImmediateMacroCallerLoc()`, which has similar but subtly different
behaviour.

The consequence is that NOLINTs cannot suppress diagnostics when they are
attached to a token that came from a macro **argument**, rather than elsewhere
in the macro expansion.

Revert to pre-patch behaviour and add test cases to cover this issue.

Differential Revision: https://reviews.llvm.org/D126138
2022-05-25 11:30:58 +12:00
Nathan Ridge 175833ed6f [clangd] Handle '--' in QueryDriverDatabase
Fixes https://github.com/clangd/clangd/issues/1100,
a regression from D116721.

Differential Revision: https://reviews.llvm.org/D126274
2022-05-24 13:10:41 -04:00
Sam McCall 0360b9f159 [pseudo] (trivial) bracket-matching
Error-tolerant bracket matching enables our error-tolerant parsing strategies.
The implementation here is *not* yet error tolerant: this patch sets up the APIs
and plumbing, and describes the planned approach.

Differential Revision: https://reviews.llvm.org/D125911
2022-05-24 15:13:36 +02:00
usama hameed 63ecb7dcc8 bugfix in InfiniteLoopCheck to not print warnings for unevaluated loops
Added a separate check for unevaluated statements. Updated InfiniteLoopCheck to use new check

Differential Revision: https://reviews.llvm.org/D126246
2022-05-23 20:18:49 -07:00