Skip to content

[NFC] [clang-tidy] Fix potential SA issues.#170289

Merged
zahiraam merged 2 commits into
llvm:mainfrom
zahiraam:FixDereferenceNullPtr
Dec 2, 2025
Merged

[NFC] [clang-tidy] Fix potential SA issues.#170289
zahiraam merged 2 commits into
llvm:mainfrom
zahiraam:FixDereferenceNullPtr

Conversation

@zahiraam

@zahiraam zahiraam commented Dec 2, 2025

Copy link
Copy Markdown
Contributor

This patch addresses issues identified by the static analyzers, which appear to be legitimate problems.

FloatLoopCounterCheck.cpp: "Dereferencing a pointer that might be nullptr FS when calling getInc".
ProBoundsAvoidUncheckedContainerAccessCheck.cpp: "Dereferencing a pointer that might be nullptr Callee when calling getBeginLoc".
ExpandModularHeadersPPCallbacks.cpp: Non-static class member CurrentToken.Flags is not initialized in this constructor nor in any functions that it calls. (line #101).

@github-actions

github-actions Bot commented Dec 2, 2025

Copy link
Copy Markdown

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

@zahiraam zahiraam changed the title [NFC] Fix potential SA issues. [NFC] [clang-tidy] Fix potential SA issues. Dec 2, 2025
@zahiraam zahiraam marked this pull request as ready for review December 2, 2025 13:26
Comment thread clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.cpp Outdated
@zahiraam

zahiraam commented Dec 2, 2025

Copy link
Copy Markdown
Contributor Author

Thanks @vbvictor and @zwuis.

@llvmbot

llvmbot commented Dec 2, 2025

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-clang-tidy

@llvm/pr-subscribers-clang-tools-extra

Author: Zahira Ammarguellat (zahiraam)

Changes

This patch addresses issues identified by the static analyzers, which appear to be legitimate problems.

FloatLoopCounterCheck.cpp: "Dereferencing a pointer that might be nullptr FS when calling getInc".
ProBoundsAvoidUncheckedContainerAccessCheck.cpp: "Dereferencing a pointer that might be nullptr Callee when calling getBeginLoc".
ExpandModularHeadersPPCallbacks.cpp: Non-static class member CurrentToken.Flags is not initialized in this constructor nor in any functions that it calls. (line #101).


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

3 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h (+1-1)
  • (modified) clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.cpp (+1)
  • (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.cpp (+1-1)
diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
index 95216368492ca..d72d021f44838 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
@@ -137,7 +137,7 @@ class ExpandModularHeadersPPCallbacks : public PPCallbacks {
   std::unique_ptr<Preprocessor> PP;
   bool EnteredMainFile = false;
   bool StartedLexing = false;
-  Token CurrentToken;
+  Token CurrentToken = Token();
 };
 
 } // namespace tooling
diff --git a/clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.cpp
index adf2d2b4bcc07..38a0234337756 100644
--- a/clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.cpp
@@ -31,6 +31,7 @@ void FloatLoopCounterCheck::registerMatchers(MatchFinder *Finder) {
 
 void FloatLoopCounterCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *FS = Result.Nodes.getNodeAs<ForStmt>("for");
+  assert(FS && "FS should not be null");
 
   diag(FS->getInc()->getBeginLoc(), "loop induction expression should not have "
                                     "floating-point type")
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.cpp
index 83803a3e81937..67ce8e5cf176c 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.cpp
@@ -177,7 +177,7 @@ void ProBoundsAvoidUncheckedContainerAccessCheck::check(
     }
   } else if (const auto *MCE = dyn_cast<CXXMemberCallExpr>(MatchedExpr)) {
     // Case: a.operator[](i) or a->operator[](i)
-    const auto *Callee = dyn_cast<MemberExpr>(MCE->getCallee());
+    const auto *Callee = cast<MemberExpr>(MCE->getCallee());
 
     if (FixMode == At) {
       // Cases: a.operator[](i) => a.at(i) and a->operator[](i) => a->at(i)

@zahiraam zahiraam merged commit c691020 into llvm:main Dec 2, 2025
11 checks passed
honeygoyal pushed a commit to honeygoyal/llvm-project that referenced this pull request Dec 9, 2025
This patch addresses issues identified by the static analyzers, which
appear to be legitimate problems.

`FloatLoopCounterCheck.cpp`: "Dereferencing a pointer that might be
`nullptr` FS when calling `getInc`".
`ProBoundsAvoidUncheckedContainerAccessCheck.cpp`: "Dereferencing a
pointer that might be `nullptr Callee` when calling `getBeginLoc`".
`ExpandModularHeadersPPCallbacks.cpp`: Non-static class member
`CurrentToken.Flags` is not initialized in this constructor nor in any
functions that it calls. (line llvm#101).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants