[clang] [clang][Sema] Fix crash on [[fallthrough]] in stmt-expr initializers (PR #248042)

via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 2 05:48:58 PST 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,c -- clang/lib/Sema/AnalysisBasedWarnings.cpp clang/test/Sema/c2x-fallthrough.c clang/test/SemaCXX/switch-implicit-fallthrough.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index 95a9c7c5a..c85254764 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -1351,14 +1351,14 @@ public:
     return true;
   }
 
-    // Skip local functions, types, and blocks; they are analyzed separately.
-    // Still walk other decls (notably VarDecl initializers) so fallthrough
-    // attributes inside statement expressions used as initializers are seen.
-    bool TraverseDecl(Decl *D) override {
-      if (isa<FunctionDecl>(D) || isa<TypeDecl>(D) || isa<BlockDecl>(D))
-        return true;
-      return DynamicRecursiveASTVisitor::TraverseDecl(D);
-    }
+  // Skip local functions, types, and blocks; they are analyzed separately.
+  // Still walk other decls (notably VarDecl initializers) so fallthrough
+  // attributes inside statement expressions used as initializers are seen.
+  bool TraverseDecl(Decl *D) override {
+    if (isa<FunctionDecl>(D) || isa<TypeDecl>(D) || isa<BlockDecl>(D))
+      return true;
+    return DynamicRecursiveASTVisitor::TraverseDecl(D);
+  }
 
     // We analyze lambda bodies separately. Skip them here.
     bool TraverseLambdaExpr(LambdaExpr *LE) override {

``````````

</details>


https://github.com/llvm/llvm-project/pull/248042


More information about the cfe-commits mailing list