29.01.2014 Views

A CIL Tutorial - Department of Computer Science - ETH Zürich

A CIL Tutorial - Department of Computer Science - ETH Zürich

A CIL Tutorial - Department of Computer Science - ETH Zürich

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 7. TYPE QUALIFIERS 57<br />

$ ciltutcc enable-tut7 -o tut7 test/tut7.c<br />

Warning: test/tut7.c:16: color mismatch: int attribute (( blue )) int<br />

attribute (( green ))<br />

Which is what we expected.<br />

7.3 Exercises<br />

1. Modify typecheck result and colorTypesCompat to give more information when types do<br />

not match. For example, instead <strong>of</strong> returning TypesMismatch, colorTypesCompat might return<br />

PtrIntMismatch when t1 is a TPtr and t2 is a TInt (but the colors still match).<br />

2. Corret the rule for function types in colorTypesCompat. Possibly add (a) new constructor(s)<br />

to typecheck result for the case when function types do not match.<br />

3. In combination with the above two exercises. Generalize the type checking code in colorTypesCompat.<br />

Instead <strong>of</strong> checking the color qualiers, however, colorTypesCompat would accept a function<br />

argument for deciding whether the set <strong>of</strong> type attributes on t1 and t2 are compatible.<br />

4. Write the Call case in colorCheckVisitor#vinst. Extract the type <strong>of</strong> the function from<br />

fe. Check the return type <strong>of</strong> the function against the destination <strong>of</strong> the return value (rlvo).<br />

Check the types <strong>of</strong> the actual arguments (args) against the types <strong>of</strong> the formal parameters.<br />

Note that there might be more actuals than formals if it is a variable argument function!<br />

5. The attribute syntax in the warning message above could be cleaned up by inheriting<br />

from Cil's defaultCilPrinterClass and overriding the methods for printing attributes.<br />

7.4 Further Reading<br />

Researchers have added ow-sensitive [3], and insensitive type-qualiers [2], type-qualier inference,<br />

and type-qualier polymorphism [1] to languages such as C and Java [4].<br />

In particular, the CCured [5] tool used ow-insensitive type-qualier inference to determine the<br />

kind <strong>of</strong> fat pointer needed to check the correctness <strong>of</strong> pointer arithmetic in C, among other purposes.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!