Skip to content

Commit

Permalink
MemoryModel: add support for modeling global constant variable updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaokang Fan committed Apr 12, 2017
1 parent 9f3b79b commit 14d9b9f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/MemoryModel/MemModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ class SymbolTableInfo {

static bool isBlackholeSym(const llvm::Value *val);

static bool isConstantObjSym(const llvm::Value *val);
bool isConstantObjSym(const llvm::Value *val);

static inline bool isBlkPtr(NodeID id) {
return (id == BlkPtr);
Expand Down
17 changes: 15 additions & 2 deletions lib/MemoryModel/MemModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ void ObjTypeInfo::init(const Value* val) {
}
else if(isa<GlobalVariable>(val)) {
setFlag(GLOBVAR_OBJ);
if(cast<GlobalVariable>(val)->isConstant())
if(SymbolTableInfo::Symbolnfo()->isConstantObjSym(val))
setFlag(CONST_OBJ);
analyzeGlobalStackObjType(val);
objSize = getObjSize(val);
Expand Down Expand Up @@ -849,8 +849,21 @@ bool SymbolTableInfo::isConstantObjSym(const Value *val) {
if (const GlobalVariable* v = dyn_cast<GlobalVariable>(val)) {
if (cppUtil::isValVtbl(const_cast<GlobalVariable*>(v)))
return false;
else
else if (!v->hasInitializer())
return true;
else {
StInfo *stInfo = getStructInfo(v->getInitializer()->getType());
const std::vector<FieldInfo> &fields = stInfo->getFlattenFieldInfoVec();
for (std::vector<FieldInfo>::const_iterator it = fields.begin(), eit = fields.end(); it != eit; ++it) {
const FieldInfo &field = *it;
const Type *elemTy = field.getFlattenElemTy();
assert(!isa<FunctionType>(elemTy) && "Initializer of a global is a function?");
if (isa<PointerType>(elemTy))
return false;
}

return v->isConstant();
}
}
return false;
}
Expand Down

0 comments on commit 14d9b9f

Please sign in to comment.