Skip to content

[-Wunsafe-buffer-usage] cherry-picks #7779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

jkorous-apple
Copy link

No description provided.

t-rasmud and others added 23 commits November 10, 2023 13:05
…xed at an earlier stage

`FixableGadget`s are not always associated with variables that are unsafe
(warned). For example, they could be associated with variables whose
unsafe operations are suppressed or that are not used in any unsafe
operation. Such `FixableGadget`s will not be fixed. Removing these
`FixableGadget` as early as possible helps improve the performance
and stability of the analysis.

Reviewed by: NoQ (Artem Dergachev), t-rasmud (Rashmi Mudduluru)

Differential revision: https://reviews.llvm.org/D155524

(cherry picked from commit cfcf76c)
…n a value" warning. NFC.

(cherry picked from commit 4cd7d8e)
Fix the linting problems which causes `clang/utils/ci/run-buildbot check-format` to return 1.

Also make a correction for the email address of the author of
0fd4175:

  The correct email address is "[email protected]", not "[email protected]".

Reviewed by: ziqingluo-90 (Ziqing Luo)

Differential revision: https://reviews.llvm.org/D155814

(cherry picked from commit 82b94a9)
- Factor out the code that will be shared by both parameter and local variable fix-its
- Add a check to ensure that a TypeLoc::isNull is false before using the TypeLoc
- Remove the special check for whether a fixing variable involves unnamed types. This check is unnecessary now.
- Move tests for cv-qualified parameters and unnamed types out of the "...-unsupported.cpp" test file.

Reviewed by: NoQ (Artem Dergachev)

Differential revision: https://reviews.llvm.org/D156188

(cherry picked from commit 41279e8)
Slightly refactor and optimize the code in preparation for
implementing grouping parameters for a single fix-it.

Reviewed by: NoQ (Artem Dergachev), t-rasmud (Rashmi Mudduluru)

Differential revision: https://reviews.llvm.org/D156474

(cherry picked from commit 8437847)
…he code"

This reverts commit 8437847.
There is a build failure caused by this commit.

(cherry picked from commit ac9a76d)
…g/include clang/docs" fail

(cherry picked from commit 630ba7d)
…the code"

This reverts commit ac9a76d.

Previously an abstract class has no pure virtual function.  It causes build error on some bots.

(cherry picked from commit 472a510)
… generated

Refactor the getFixIts function for better readability.

Reviewed by: NoQ (Artem Dergachev), t-rasmud (Rashmi Mudduluru)

Differential revision: https://reviews.llvm.org/D156762

(cherry picked from commit acc8a33)
This breaks the clang check-format on CI.

+ grep -rnI '[[:blank:]]$' clang/lib clang/include clang/docs
clang/lib/Analysis/UnsafeBufferUsage.cpp:2277:#endif

(cherry picked from commit 69a8636)
…rameter fix-its share common code

Refactor the code for local variable fix-its so that it reuses the
code for parameter fix-its, which is in general better. For example,
cv-qualifiers are supported.

Reviewed by: NoQ (Artem Dergachev), t-rasmud (Rashmi Mudduluru)

Differential revision: https://reviews.llvm.org/D156189

(cherry picked from commit 3a67b91)
…e declarations with unsupported specifiers

We have to give up on fixing a variable declaration if it has
specifiers that are not supported yet.  We could support these
specifiers incrementally using the same approach as how we deal with
cv-qualifiers. If a fixing variable declaration has a storage
specifier, instead of trying to find out the source location of the
specifier or to avoid touching it, we add the keyword to a
canonicalized place in the fix-it text that replaces the whole
declaration.

Reviewed by: NoQ (Artem Dergachev), jkorous (Jan Korous)

Differential revision: https://reviews.llvm.org/D156192

(cherry picked from commit b58e528)
For a function `F` whose parameters need to be fixed, we group fix-its
of F's parameters together so that either all of the parameters get
fixed or none of them gets fixed.

Reviewed by: NoQ (Artem Dergachev), t-rasmud (Rashmi Mudduluru), jkorous (Jan Korous)

Differential revision: https://reviews.llvm.org/D153059

(cherry picked from commit 33f6161)
…parameter

- Use Strategy to determine whether to fix a parameter
- Fix the `Strategy` construction so that only variables on the graph
are assigned the `std::span` strategy

Reviewed by: t-rasmud (Rashmi Mudduluru), NoQ (Artem Dergachev)

Differential revision: https://reviews.llvm.org/D157441

(cherry picked from commit 700baeb)
… with auto

Reviewed By: tahonermann

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

(cherry picked from commit 06c9cc7)
…e header files

Extract included parts in the following tests to separate header files:
- SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span-overload.cpp
- SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span.cpp

Removed the included part in the following tests as it is not useful:
- SemaCXX/warn-unsafe-buffer-usage-warning-unevaluated-context.cpp

(cherry picked from commit de8b2f0)
… for analysis

- For a better understand of what the unsupported cases are, we add
  more information to the debug note---a string of ancestor AST nodes
  of the unclaimed DRE. For example, an unclaimed DRE p in an
  expression `*(p++)` will result in a string starting with
  `DRE ==> UnaryOperator(++) ==> Paren ==> UnaryOperator(*)`.

- To find out the most common patterns of those unsupported use cases,
  we add a simple script to build a prefix tree over those strings and
  count each prefix. The script reads input line by line, assumes a
  line is a list of words separated by `==>`s, and builds a prefix tree
  over those lists.

Reviewed by: t-rasmud (Rashmi Mudduluru), NoQ (Artem Dergachev)

Differential revision: https://reviews.llvm.org/D158561

(cherry picked from commit a432358)
@jkorous-apple
Copy link
Author

@swift-ci please test

@jkorous-apple jkorous-apple merged commit ddf2cc9 into swiftlang:stable/20230725 Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants