diff options
| author | Zhongxing Xu <xuzhongxing@gmail.com> | 2009-06-19 06:00:32 +0000 |
|---|---|---|
| committer | Zhongxing Xu <xuzhongxing@gmail.com> | 2009-06-19 06:00:32 +0000 |
| commit | 54fb536b5c191317a4544e26964189a67a09cdcf (patch) | |
| tree | 07a9297354fa14f4fcd3bf810873e6ed2a7c0fe1 /clang | |
| parent | 77585a24ac481c5773d96f561840b04e81b22161 (diff) | |
| download | bcm5719-llvm-54fb536b5c191317a4544e26964189a67a09cdcf.tar.gz bcm5719-llvm-54fb536b5c191317a4544e26964189a67a09cdcf.zip | |
A further step of r73690: associate the cast-to type with the created symbol,
because the type of the symbol is used to create the default range. We need the
sign to be consistent.
llvm-svn: 73756
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/Analysis/PathSensitive/SymbolManager.h | 17 | ||||
| -rw-r--r-- | clang/lib/Analysis/SVals.cpp | 4 | ||||
| -rw-r--r-- | clang/lib/Analysis/SymbolManager.cpp | 9 | ||||
| -rw-r--r-- | clang/test/Analysis/casts.c | 2 |
4 files changed, 22 insertions, 10 deletions
diff --git a/clang/include/clang/Analysis/PathSensitive/SymbolManager.h b/clang/include/clang/Analysis/PathSensitive/SymbolManager.h index d424526d4eb..d074e30333d 100644 --- a/clang/include/clang/Analysis/PathSensitive/SymbolManager.h +++ b/clang/include/clang/Analysis/PathSensitive/SymbolManager.h @@ -83,19 +83,25 @@ typedef const SymbolData* SymbolRef; class SymbolRegionValue : public SymbolData { const MemRegion *R; + // We may cast the region to another type, so the expected type of the symbol + // may be different from the region's original type. + QualType T; + public: - SymbolRegionValue(SymbolID sym, const MemRegion *r) - : SymbolData(RegionValueKind, sym), R(r) {} + SymbolRegionValue(SymbolID sym, const MemRegion *r, QualType t = QualType()) + : SymbolData(RegionValueKind, sym), R(r), T(t) {} const MemRegion* getRegion() const { return R; } - static void Profile(llvm::FoldingSetNodeID& profile, const MemRegion* R) { + static void Profile(llvm::FoldingSetNodeID& profile, const MemRegion* R, + QualType T) { profile.AddInteger((unsigned) RegionValueKind); profile.AddPointer(R); + T.Profile(profile); } virtual void Profile(llvm::FoldingSetNodeID& profile) { - Profile(profile, R); + Profile(profile, R, T); } QualType getType(ASTContext&) const; @@ -240,7 +246,8 @@ public: static bool canSymbolicate(QualType T); /// Make a unique symbol for MemRegion R according to its kind. - const SymbolRegionValue* getRegionValueSymbol(const MemRegion* R); + const SymbolRegionValue* getRegionValueSymbol(const MemRegion* R, + QualType T = QualType()); const SymbolConjured* getConjuredSymbol(const Stmt* E, QualType T, unsigned VisitCount, const void* SymbolTag = 0); diff --git a/clang/lib/Analysis/SVals.cpp b/clang/lib/Analysis/SVals.cpp index 37f9ac7cad9..77c3c8f7722 100644 --- a/clang/lib/Analysis/SVals.cpp +++ b/clang/lib/Analysis/SVals.cpp @@ -323,10 +323,10 @@ NonLoc NonLoc::MakeCompoundVal(QualType T, llvm::ImmutableList<SVal> Vals, } SVal ValueManager::getRegionValueSymbolVal(const MemRegion* R, QualType T) { - SymbolRef sym = SymMgr.getRegionValueSymbol(R); + SymbolRef sym = SymMgr.getRegionValueSymbol(R, T); if (const TypedRegion* TR = dyn_cast<TypedRegion>(R)) { - if (!T.getTypePtr()) + if (T.isNull()) T = TR->getValueType(SymMgr.getContext()); // If T is of function pointer type, create a CodeTextRegion wrapping a diff --git a/clang/lib/Analysis/SymbolManager.cpp b/clang/lib/Analysis/SymbolManager.cpp index 5c885cd6e15..4e38a3492c7 100644 --- a/clang/lib/Analysis/SymbolManager.cpp +++ b/clang/lib/Analysis/SymbolManager.cpp @@ -92,14 +92,14 @@ std::ostream& std::operator<<(std::ostream& os, const SymExpr *SE) { } const SymbolRegionValue* -SymbolManager::getRegionValueSymbol(const MemRegion* R) { +SymbolManager::getRegionValueSymbol(const MemRegion* R, QualType T) { llvm::FoldingSetNodeID profile; - SymbolRegionValue::Profile(profile, R); + SymbolRegionValue::Profile(profile, R, T); void* InsertPos; SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos); if (!SD) { SD = (SymExpr*) BPAlloc.Allocate<SymbolRegionValue>(); - new (SD) SymbolRegionValue(SymbolCounter, R); + new (SD) SymbolRegionValue(SymbolCounter, R, T); DataSet.InsertNode(SD, InsertPos); ++SymbolCounter; } @@ -166,6 +166,9 @@ QualType SymbolConjured::getType(ASTContext&) const { } QualType SymbolRegionValue::getType(ASTContext& C) const { + if (!T.isNull()) + return T; + if (const TypedRegion* TR = dyn_cast<TypedRegion>(R)) return TR->getValueType(C); diff --git a/clang/test/Analysis/casts.c b/clang/test/Analysis/casts.c index d47184fb5f5..5e4222bc84b 100644 --- a/clang/test/Analysis/casts.c +++ b/clang/test/Analysis/casts.c @@ -25,6 +25,8 @@ int f1(struct s **pval) { pval = &(t->value); tbool = (int *)pval; // Should record the cast-to type here. char c = (unsigned char) *tbool; // Should use cast-to type to create symbol. + if (*tbool == -1) + 3; } void f2(const char *str) { |

