[clang] [clang][analyzer] Add C standard streams to the internal memory space (PR #147766)
Balazs Benics via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 10 06:23:40 PDT 2025
=?utf-8?q?Balázs_Kéri?= <balazs.keri at ericsson.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/147766 at github.com>
================
@@ -1054,10 +1054,26 @@ const VarRegion *MemRegionManager::getVarRegion(const VarDecl *D,
assert(!Ty.isNull());
if (Ty.isConstQualified()) {
sReg = getGlobalsRegion(MemRegion::GlobalImmutableSpaceRegionKind);
- } else if (Ctx.getSourceManager().isInSystemHeader(D->getLocation())) {
- sReg = getGlobalsRegion(MemRegion::GlobalSystemSpaceRegionKind);
} else {
- sReg = getGlobalsRegion(MemRegion::GlobalInternalSpaceRegionKind);
+ StringRef N = D->getNameAsString();
+ QualType FILETy = D->getASTContext().getFILEType();
+ if (!FILETy.isNull())
+ FILETy = FILETy.getCanonicalType();
+ Ty = Ty.getCanonicalType();
+ bool IsStdStreamVar = Ty->isPointerType() &&
+ Ty->getPointeeType() == FILETy &&
+ (N == "stdin" || N == "stdout" || N == "stderr");
----------------
steakhal wrote:
All this work is basically done to set the `IsStdStreamVar`.
This seems pretty complicated and not strictly necessary for `getVarRegion` itself.
This prompts me if we should hoist this into a helper function that we can call here. WDYT?
https://github.com/llvm/llvm-project/pull/147766
More information about the cfe-commits
mailing list