sampsyo / quala

custom type systems for Clang
MIT License
96 stars 7 forks source link

Annotation Infection for Pointee #10

Closed EmmetZC closed 8 years ago

EmmetZC commented 8 years ago

Hi, sampsyo.

I want to implement an annotation which does not ensure Pointer Invariance and allows un-annotated pointers to be infected by annotated pointer, as the code shows below:

ANNO int *p = malloc(sizeof(int));     // *p (p's Pointee) is annotated
int *a;     // *a is declared un-annotated
a = p;     // allowed, a is infected and *a is annotated from now on

To achieve this, I need to change the PointeeType of the LHS of BinAssginExpr a = p in function void VisitBinAssign(BinaryOperator *E), which I don't know how.

So, do you have any ideas about how to modify the PointeeType of an Expr?

Emmet

sampsyo commented 8 years ago

To modify the pointee type of a pointer type in Clang, I believe you need to reconstruct the type "from scratch." This can be a little tricky, but getPointerType is probably the place to start: http://clang.llvm.org/doxygen/classclang_1_1ASTContext.html#a3574cad49cba0fc48ab7b4c953e7e31e

EmmetZC commented 8 years ago

Got it. I was hoping there might be an easier way besides "unwrapping the type and then wrapping it again". XD Anyway, thanks a lot for giving me the hint, getPointType(), which does help!