uninitialized variable

I am writing a checker to check that a variable is given a value before it is accessed. So I created a checkLocation call-back:

void checkLocation(SVal L, bool IsLoad, const Stmt* S, CheckerContext &ChCtx) const {

if (!IsLoad) return; // location value is not being accessed

const MemRegion* MemReg = L.getAsRegion();

if (!MemReg) return; // L is not a memory location

const VarRegion* VarReg = MemReg->getAs();

if (!VarReg) return; // L is not a variable location

SVal VarVal = ChCtx.getState()->getSVal(VarReg);

if (VarVal.isUndef()) {

// Variable value is undefined; report error

EmitReport(S->getSourceRange(), ChCtx, “Variable may not have been assigned a value”);



This works fine for scalar variables like ints, but I’ve discovered that a struct variable will be defined even if it hasn’t been given a value. So my plan is to check the struct fields to see if they’ve been given values.

My question is: are there other cases where VarVal.isUndef() will return false even though the variable has not been given a value?


Structures are represented by compound and "lazy" compound values. These values are considered to be defined values even when their contents are undefined; you can explore their contents to see if all fields of the structures you receive are undefined.