[clang] a157d83 - [clang] Environment::createValueUnlessSelfReferential - use castAs<> instead of getAs<> to avoid dereference of nullptr
Simon Pilgrim via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 9 03:40:56 PST 2022
Author: Simon Pilgrim
Date: 2022-03-09T11:40:37Z
New Revision: a157d839c52077001f234ce5c8b0cbc05fbb429c
URL: https://github.com/llvm/llvm-project/commit/a157d839c52077001f234ce5c8b0cbc05fbb429c
DIFF: https://github.com/llvm/llvm-project/commit/a157d839c52077001f234ce5c8b0cbc05fbb429c.diff
LOG: [clang] Environment::createValueUnlessSelfReferential - use castAs<> instead of getAs<> to avoid dereference of nullptr
The pointer is always dereferenced, so assert the cast is correct instead of returning nullptr
Added:
Modified:
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
Removed:
################################################################################
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index ec945bac09863..23e905fc5138c 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -439,7 +439,7 @@ Value *Environment::createValueUnlessSelfReferential(
if (Type->isReferenceType()) {
CreatedValuesCount++;
- QualType PointeeType = Type->getAs<ReferenceType>()->getPointeeType();
+ QualType PointeeType = Type->castAs<ReferenceType>()->getPointeeType();
auto &PointeeLoc = createStorageLocation(PointeeType);
if (!Visited.contains(PointeeType.getCanonicalType())) {
@@ -457,7 +457,7 @@ Value *Environment::createValueUnlessSelfReferential(
if (Type->isPointerType()) {
CreatedValuesCount++;
- QualType PointeeType = Type->getAs<PointerType>()->getPointeeType();
+ QualType PointeeType = Type->castAs<PointerType>()->getPointeeType();
auto &PointeeLoc = createStorageLocation(PointeeType);
if (!Visited.contains(PointeeType.getCanonicalType())) {
More information about the cfe-commits
mailing list