Skip to content

[-Wunsafe-buffer-usage] Fix AST matcher of UUCAddAssignGadget #79392

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
Contributor

We are not interested in nonpointers being added to.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:analysis labels Jan 25, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 25, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-analysis

Author: None (jkorous-apple)

Changes

We are not interested in nonpointers being added to.


Full diff: https://github.com/llvm/llvm-project/pull/79392.diff

1 Files Affected:

  • (modified) clang/lib/Analysis/UnsafeBufferUsage.cpp (+6-1)
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 7df706beb22662c..fd7a76d511862ec 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1081,11 +1081,16 @@ class UUCAddAssignGadget : public FixableGadget {
   }
 
   static Matcher matcher() {
+// clang-format off
     return stmt(isInUnspecifiedUntypedContext(expr(ignoringImpCasts(
         binaryOperator(hasOperatorName("+="),
-                       hasLHS(declRefExpr(toSupportedVariable())),
+                       hasLHS(
+                        declRefExpr(
+                          hasPointerType(),
+                          toSupportedVariable())),
                        hasRHS(expr().bind(OffsetTag)))
             .bind(UUCAddAssignTag)))));
+// clang-format on
   }
 
   virtual std::optional<FixItList> getFixits(const Strategy &S) const override;

Copy link

github-actions bot commented Jan 25, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

We are not interested in nonpointers being added to.
@jkorous-apple jkorous-apple force-pushed the cxx-safe-buffers/fix-nonptr-assign-to-matcher branch from afda86d to dcc2b0c Compare January 25, 2024 00:32
@jkorous-apple
Copy link
Contributor Author

Buildkite failed for unrelated reason - this change really doesn't introduce virus in filecheck on Windows.

# executed command: 'c:\ws\src\build\build-clang-windows\bin\filecheck.exe' -check-prefix=CHECK-CC1 'C:\ws\src\clang\test\CodeCompletion\using.cpp'
--
  | # .---command stderr------------
  | # \| Could not create process (c:\ws\src\build\build-clang-windows\bin\filecheck.exe) due to [WinError 225] Operation did not complete successfully because the file contains a virus or potentially unwanted software

Copy link
Contributor

@ziqingluo-90 ziqingluo-90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, It's great to catch and fix this bug!

@jkorous-apple jkorous-apple merged commit e5cebec into llvm:main Jan 30, 2024
@jkorous-apple jkorous-apple deleted the cxx-safe-buffers/fix-nonptr-assign-to-matcher branch February 1, 2024 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:analysis clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants