[PATCH] D115932: [Analyzer] Create and handle SymbolCast for pointer to integral conversion

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 10 13:59:49 PST 2022


NoQ added inline comments.


================
Comment at: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:420
+      auto FromTy = symRHS->getType();
+      auto ToTy = RLocAsInt->getType(this->Context);
+      symRHS = this->getSymbolManager().getCastSymbol(symRHS, FromTy, ToTy);
----------------
ASDenysPetrov wrote:
> Please take into account that `SVal::getType` may return NULL `QualType`. See function's description.
Yup, `SVal::getType()` is relatively speculative. It arguably shouldn't be but as of now it is.

In this case though it'll probably always work correctly. Despite the relevant code making relatively little sense:
```lang=c++
   QualType VisitNonLocLocAsInteger(nonloc::LocAsInteger LI) {
     // Who cares about the pointer type? It's turned into an integer anyway.
     QualType NestedType = Visit(LI.getLoc());

     // Ok, now we suddenly have a failure condition when there's no pointer type
     // even though the pointer type is completely immaterial.
     // It probably never fails in practice though, because there's usually at least some
     // pointer type (void pointer in the worst case, but it's still something).
     if (NestedType.isNull())
       return NestedType;
  
     // See? We can get bit width without pointer type.
     return Context.getIntTypeForBitwidth(LI.getNumBits(),
                                          // Oh I know this one! It's a pointer type. It isn't an integer type at all.
                                          // Whelp I guess "always unsigned" works for us as well as anything else.
                                          // We don't have any information about signedness one way or the other.
                                          NestedType->isSignedIntegerType());
   }
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115932/new/

https://reviews.llvm.org/D115932



More information about the cfe-commits mailing list