[cfe-dev] Getting an sval for sizeof(type)?

Alexey Sidorin via cfe-dev cfe-dev at lists.llvm.org
Mon May 9 14:31:47 PDT 2016


Raymond,

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 пишет:
>
> 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)?
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160510/08569a89/attachment.html>


More information about the cfe-dev mailing list