[cfe-commits] r60280 - in /cfe/trunk/lib/Analysis: GRExprEngine.cpp RegionStore.cpp
Zhongxing Xu
xuzhongxing at gmail.com
Sat Nov 29 21:49:49 PST 2008
Author: zhongxingxu
Date: Sat Nov 29 23:49:49 2008
New Revision: 60280
URL: http://llvm.org/viewvc/llvm-project?rev=60280&view=rev
Log:
Add support for initializing array with string literal.
This fixes PR3127
http://llvm.org/bugs/show_bug.cgi?id=3127
Modified:
cfe/trunk/lib/Analysis/GRExprEngine.cpp
cfe/trunk/lib/Analysis/RegionStore.cpp
Modified: cfe/trunk/lib/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngine.cpp?rev=60280&r1=60279&r2=60280&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Sat Nov 29 23:49:49 2008
@@ -405,6 +405,10 @@
break;
}
+
+ case Stmt::StringLiteralClass:
+ VisitLValue(cast<StringLiteral>(S), Pred, Dst);
+ break;
case Stmt::UnaryOperatorClass:
VisitUnaryOperator(cast<UnaryOperator>(S), Pred, Dst, false);
Modified: cfe/trunk/lib/Analysis/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/RegionStore.cpp?rev=60280&r1=60279&r2=60280&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
+++ cfe/trunk/lib/Analysis/RegionStore.cpp Sat Nov 29 23:49:49 2008
@@ -637,17 +637,42 @@
ConstantArrayType* CAT = cast<ConstantArrayType>(T.getTypePtr());
- llvm::APInt Size = CAT->getSize();
+ llvm::APSInt Size(CAT->getSize(), false);
+
+ llvm::APSInt i = getBasicVals().getZeroWithPtrWidth(false);
+
+ // Check if the init expr is a StringLiteral.
+ if (isa<loc::MemRegionVal>(Init)) {
+ const MemRegion* InitR = cast<loc::MemRegionVal>(Init).getRegion();
+ const StringLiteral* S = cast<StringRegion>(InitR)->getStringLiteral();
+ const char* str = S->getStrData();
+ unsigned len = S->getByteLength();
+ unsigned j = 0;
+
+ for (; i < Size; ++i, ++j) {
+ SVal Idx = NonLoc::MakeVal(getBasicVals(), i);
+ ElementRegion* ER = MRMgr.getElementRegion(Idx, R);
+
+ // Copy bytes from the string literal into the target array. Trailing
+ // bytes in the array that are not covered by the string literal are
+ // initialized to zero.
+ SVal V = (j < len)
+ ? NonLoc::MakeVal(getBasicVals(), str[j], sizeof(char)*8, true)
+ : NonLoc::MakeVal(getBasicVals(), 0, sizeof(char)*8, true);
+
+ store = Bind(store, loc::MemRegionVal(ER), V);
+ }
+
+ return store;
+ }
- llvm::APInt i = llvm::APInt::getNullValue(Size.getBitWidth());
nonloc::CompoundVal& CV = cast<nonloc::CompoundVal>(Init);
nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end();
- for (; i != Size; ++i) {
- nonloc::ConcreteInt Idx(getBasicVals().getValue(llvm::APSInt(i, false)));
-
+ for (; i < Size; ++i) {
+ SVal Idx = NonLoc::MakeVal(getBasicVals(), i);
ElementRegion* ER = MRMgr.getElementRegion(Idx, R);
store = Bind(store, loc::MemRegionVal(ER), (VI!=VE) ? *VI : UndefinedVal());
More information about the cfe-commits
mailing list