Getting an sval for sizeof(type)?

If we have Type object, can we construct an SVal for the size of that type, i.e., for the value we’d get by evaluating sizeof(type)?


Type size is a compile-time constant. To get it, you may use ASTContext::getTypeSize() or ASTContext::getTypeSizeInChars() methods.

Than, you need to make an SVal. Since this value is a constant, you need to get an SVal of nonloc::ConcreteInt type. With your constant, you may use SValBuilder::makeIntVal() method so your code will look like:

CharUnits TypeSize = Ctx.getTypeSizeInChars(Type);
nonloc::ConcreteInt TypeSize = svalBuilder.makeIntVal(TypeSize.getQuantity(), Ctx.getSizeType());

09.05.2016 21:58, McDowell, Raymond C. via cfe-dev пишет: