[clang] [clang][analyzer] Support strlen with offset to string literal in CStringChecker (PR #159795)
Balazs Benics via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 2 04:29:29 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/159795 at github.com>
================
@@ -979,6 +981,22 @@ SVal CStringChecker::getCStringLengthForRegion(CheckerContext &C,
return strLength;
}
+const StringLiteral *
+CStringChecker::getStringLiteralFromRegion(const MemRegion *MR) {
+ switch (MR->getKind()) {
+ case MemRegion::StringRegionKind:
+ return cast<StringRegion>(MR)->getStringLiteral();
+ case MemRegion::NonParamVarRegionKind:
+ if (const VarDecl *Decl = cast<NonParamVarRegion>(MR)->getDecl();
+ Decl->getType().isConstQualified() && Decl->hasGlobalStorage())
+ return dyn_cast_or_null<StringLiteral>(Decl->getInit());
+ return nullptr;
+ default:
+ return nullptr;
----------------
steakhal wrote:
Either this default case or the subsequent return is dead code.
https://github.com/llvm/llvm-project/pull/159795
More information about the cfe-commits
mailing list