summaryrefslogtreecommitdiff
path: root/clang/lib/Analysis/AnalysisDeclContext.cpp
diff options
context:
space:
mode:
authorJustin Stitt <justinstitt@google.com>2025-11-11 10:22:40 -0800
committerGitHub <noreply@github.com>2025-11-11 10:22:40 -0800
commitcf6b443c688971161542ef2d93e9fd67ffd21f8c (patch)
treeb0f30d21e24a2d5accae03d5c2daad48bb663664 /clang/lib/Analysis/AnalysisDeclContext.cpp
parent4a81e426f0b08b64973b8f2d561fba32c66a74b1 (diff)
[Clang] Consider reachability for file-scope warnings on initializers (#163885)
Co-authored-by: Nathan Huckleberry <nhuck@google.com>
Diffstat (limited to 'clang/lib/Analysis/AnalysisDeclContext.cpp')
-rw-r--r--clang/lib/Analysis/AnalysisDeclContext.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/clang/lib/Analysis/AnalysisDeclContext.cpp b/clang/lib/Analysis/AnalysisDeclContext.cpp
index 5a52056f3e6a..f188fc6921ed 100644
--- a/clang/lib/Analysis/AnalysisDeclContext.cpp
+++ b/clang/lib/Analysis/AnalysisDeclContext.cpp
@@ -117,6 +117,11 @@ Stmt *AnalysisDeclContext::getBody(bool &IsAutosynthesized) const {
return BD->getBody();
else if (const auto *FunTmpl = dyn_cast_or_null<FunctionTemplateDecl>(D))
return FunTmpl->getTemplatedDecl()->getBody();
+ else if (const auto *VD = dyn_cast_or_null<VarDecl>(D)) {
+ if (VD->isFileVarDecl()) {
+ return const_cast<Stmt *>(dyn_cast_or_null<Stmt>(VD->getInit()));
+ }
+ }
llvm_unreachable("unknown code decl");
}