Import Clang r73984.

This commit is contained in:
Ed Schouten 2009-06-23 19:32:16 +00:00
parent d6aff018d4
commit f698f7e719
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/vendor/clang/dist/; revision=194755
svn path=/vendor/clang/clang-r73984/; revision=194757; tag=vendor/clang/clang-r73984
14 changed files with 120 additions and 1915 deletions

File diff suppressed because it is too large Load Diff

View File

@ -530,21 +530,6 @@ class GRStateManager {
private:
// Methods that query & manipulate the Environment.
SVal GetSVal(const GRState* St, const Stmt* Ex) {
return St->getEnvironment().GetSVal(Ex, ValueMgr);
}
SVal GetSValAsScalarOrLoc(const GRState* state, const Stmt *S) {
if (const Expr *Ex = dyn_cast<Expr>(S)) {
QualType T = Ex->getType();
if (Loc::IsLocType(T) || T->isIntegerType())
return GetSVal(state, S);
}
return UnknownVal();
}
SVal GetBlkExprSVal(const GRState* St, const Stmt* Ex) {
return St->getEnvironment().GetBlkExprSVal(Ex, ValueMgr);
}
@ -589,21 +574,11 @@ class GRStateManager {
// Methods that manipulate the GDM.
const GRState* addGDM(const GRState* St, void* Key, void* Data);
// Methods that query or create regions.
bool hasStackStorage(const MemRegion* R) {
return getRegionManager().hasStackStorage(R);
}
// Methods that query & manipulate the Store.
void iterBindings(const GRState* state, StoreManager::BindingsHandler& F) {
StoreMgr->iterBindings(state->getStore(), F);
}
SVal GetSVal(const GRState* state, Loc LV, QualType T = QualType()) {
return StoreMgr->Retrieve(state, LV, T);
}
SVal GetSVal(const GRState* state, const MemRegion* R) {
return StoreMgr->Retrieve(state, loc::MemRegionVal(R));
@ -781,19 +756,25 @@ inline const llvm::APSInt *GRState::getSymVal(SymbolRef sym) const {
}
inline SVal GRState::getSVal(const Stmt* Ex) const {
return Mgr->GetSVal(this, Ex);
return getEnvironment().GetSVal(Ex, Mgr->ValueMgr);
}
inline SVal GRState::getBlkExprSVal(const Stmt* Ex) const {
return Mgr->GetBlkExprSVal(this, Ex);
}
inline SVal GRState::getSValAsScalarOrLoc(const Stmt *Ex) const {
return Mgr->GetSValAsScalarOrLoc(this, Ex);
inline SVal GRState::getSValAsScalarOrLoc(const Stmt *S) const {
if (const Expr *Ex = dyn_cast<Expr>(S)) {
QualType T = Ex->getType();
if (Loc::IsLocType(T) || T->isIntegerType())
return getSVal(S);
}
return UnknownVal();
}
inline SVal GRState::getSVal(Loc LV, QualType T) const {
return Mgr->GetSVal(this, LV, T);
return Mgr->StoreMgr->Retrieve(this, LV, T);
}
inline SVal GRState::getSVal(const MemRegion* R) const {

View File

@ -33,7 +33,7 @@ namespace llvm { class raw_ostream; }
namespace clang {
class MemRegionManager;
class MemSpaceRegion;
/// MemRegion - The root abstract class for all memory regions.
class MemRegion : public llvm::FoldingSetNode {
@ -68,6 +68,14 @@ class MemRegion : public llvm::FoldingSetNode {
virtual MemRegionManager* getMemRegionManager() const = 0;
std::string getString() const;
const MemSpaceRegion *getMemorySpace() const;
bool hasStackStorage() const;
bool hasHeapStorage() const;
bool hasHeapOrStackStorage() const;
virtual void print(llvm::raw_ostream& os) const;
@ -668,10 +676,6 @@ class MemRegionManager {
assert(R);
return R == globals;
}
bool hasStackStorage(const MemRegion* R);
bool hasHeapStorage(const MemRegion* R);
private:
MemSpaceRegion* LazyAllocate(MemSpaceRegion*& region);

View File

@ -380,7 +380,7 @@ class VISIBILITY_HIDDEN NotableSymbolHandler
return true;
// Check if the previous state has this binding.
SVal X = VMgr.GetSVal(PrevSt, loc::MemRegionVal(R));
SVal X = PrevSt->getSVal(loc::MemRegionVal(R));
if (X == V) // Same binding?
return true;

View File

@ -3141,7 +3141,7 @@ void CFRefCount::EvalBind(GRStmtNodeBuilderRef& B, SVal location, SVal val) {
escapes = true;
else {
const MemRegion* R = cast<loc::MemRegionVal>(location).getRegion();
escapes = !B.getStateManager().hasStackStorage(R);
escapes = !R->hasStackStorage();
if (!escapes) {
// To test (3), generate a new state with the binding removed. If it is

View File

@ -31,6 +31,7 @@ add_clang_library(clangAnalysis
SVals.cpp
SymbolManager.cpp
UninitializedValues.cpp
ValueManager.cpp
)
add_dependencies(clangAnalysis ClangDiagnosticAnalysis)

View File

@ -2764,7 +2764,7 @@ void GRExprEngine::VisitReturnStmt(ReturnStmt* S, NodeTy* Pred, NodeSet& Dst) {
// Determine if the value is on the stack.
const MemRegion* R = cast<loc::MemRegionVal>(&X)->getRegion();
if (R && getStateManager().hasStackStorage(R)) {
if (R && R->hasStackStorage()) {
// Create a special node representing the error.
if (NodeTy* N = Builder->generateNode(S, GetState(*I), *I)) {
N->markAsSink();

View File

@ -282,7 +282,7 @@ bool GRState::scanReachableSymbols(SVal val, SymbolVisitor& visitor) const {
bool GRStateManager::isEqual(const GRState* state, Expr* Ex,
const llvm::APSInt& Y) {
SVal V = GetSVal(state, Ex);
SVal V = state->getSVal(Ex);
if (loc::ConcreteInt* X = dyn_cast<loc::ConcreteInt>(&V))
return X->getValue() == Y;

View File

@ -313,46 +313,41 @@ AllocaRegion* MemRegionManager::getAllocaRegion(const Expr* E, unsigned cnt) {
return getRegion<AllocaRegion>(E, cnt);
}
bool MemRegionManager::hasStackStorage(const MemRegion* R) {
// Only subregions can have stack storage.
const SubRegion* SR = dyn_cast<SubRegion>(R);
if (!SR)
return false;
MemSpaceRegion* S = getStackRegion();
const MemSpaceRegion *MemRegion::getMemorySpace() const {
const MemRegion *R = this;
const SubRegion* SR = dyn_cast<SubRegion>(this);
while (SR) {
R = SR->getSuperRegion();
if (R == S)
return true;
SR = dyn_cast<SubRegion>(R);
}
return false;
}
bool MemRegionManager::hasHeapStorage(const MemRegion* R) {
// Only subregions can have stack storage.
const SubRegion* SR = dyn_cast<SubRegion>(R);
if (!SR)
return false;
MemSpaceRegion* H = getHeapRegion();
while (SR) {
R = SR->getSuperRegion();
if (R == H)
return true;
SR = dyn_cast<SubRegion>(R);
}
return dyn_cast<MemSpaceRegion>(R);
}
bool MemRegion::hasStackStorage() const {
if (const MemSpaceRegion *MS = getMemorySpace())
return MS == getMemRegionManager()->getStackRegion();
return false;
}
bool MemRegion::hasHeapStorage() const {
if (const MemSpaceRegion *MS = getMemorySpace())
return MS == getMemRegionManager()->getHeapRegion();
return false;
}
bool MemRegion::hasHeapOrStackStorage() const {
if (const MemSpaceRegion *MS = getMemorySpace()) {
MemRegionManager *Mgr = getMemRegionManager();
return MS == Mgr->getHeapRegion() || MS == Mgr->getStackRegion();
}
return false;
}
//===----------------------------------------------------------------------===//
// View handling.
//===----------------------------------------------------------------------===//

View File

@ -939,7 +939,7 @@ SVal RegionStoreManager::Retrieve(const GRState *state, Loc L, QualType T) {
}
}
if (MRMgr.hasStackStorage(R) || MRMgr.hasHeapStorage(R)) {
if (R->hasHeapOrStackStorage()) {
// All stack variables are considered to have undefined values
// upon creation. All heap allocated blocks are considered to
// have undefined values as well unless they are explicitly bound

View File

@ -18,4 +18,4 @@ add_clang_library(clangDriver
Types.cpp
)
add_dependencies(clangSema ClangDiagnosticDriver)
add_dependencies(clangDriver ClangDiagnosticDriver)

View File

@ -36,4 +36,4 @@ add_clang_library(clangFrontend
Warnings.cpp
)
add_dependencies(clangSema ClangDiagnosticFrontend)
add_dependencies(clangFrontend ClangDiagnosticFrontend)

View File

@ -0,0 +1,36 @@
// RUN: clang-cc -fsyntax-only -verify %s
// C++ [basic.def.odr]p2:
// An expression is potentially evaluated unless it [...] is the
// operand of the typeid operator and the expression does not
// designate an lvalue of polymorphic class type.
// FIXME: This should really include <typeinfo>, but we don't have that yet.
namespace std {
class type_info;
}
struct Poly {
virtual ~Poly();
};
struct NonPoly { };
template<typename T, typename Result = T>
struct X {
Result f(T t) { return t + t; } // expected-error{{invalid operands}}
void g(T t) {
(void)typeid(f(t)); // expected-note{{here}}
}
};
void test(X<Poly> xp, X<Poly, Poly&> xpr, X<NonPoly> xnp, X<NonPoly, NonPoly&> xnpr) {
// These are okay (although GCC and EDG get them wrong).
xp.g(Poly());
xnp.g(NonPoly());
xnpr.g(NonPoly());
// Triggers an error (as it should);
xpr.g(Poly());
}

View File

@ -0,0 +1,32 @@
// RUN: clang-cc -fsyntax-only -verify %s
// XFAIL
// Note: we fail this test because we perform template instantiation
// at the end of the translation unit, so argument-dependent lookup
// finds functions that occur after the point of instantiation. Note
// that GCC fails this test; EDG passes the test in strict mode, but
// not in relaxed mode.
namespace N {
struct A { };
struct B : public A { };
int& f0(A&);
}
template<typename T, typename Result>
struct X0 {
void test_f0(T t) {
Result r = f0(t);
};
};
void test_f0() {
X0<N::A, int&> xA;
xA.test_f0(N::A());
X0<N::B, int&> xB;
xB.test_f0(N::B());
}
namespace N {
char& f0(B&);
}