[clang] Environment::createValueUnlessSelfReferential - use castAs<> instead of getAs...
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 9 Mar 2022 10:51:43 +0000 (10:51 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 9 Mar 2022 11:40:37 +0000 (11:40 +0000)
The pointer is always dereferenced, so assert the cast is correct instead of returning nullptr

clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp

index ec945ba..23e905f 100644 (file)
@@ -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())) {