diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-06-17 02:43:46 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-06-17 02:43:46 +0000 |
commit | 5549976193e34417d4474a5f4a514268ef6666c7 (patch) | |
tree | 0b998acf163c517c2513c9fc556e08553acf8ef7 /lib/Analysis/CFRefCount.cpp | |
parent | 94cbb3e8942baeacf2265c0b80674ed810817f56 (diff) |
This patch is motivated by numerous strict-aliasing warnings when compiling
clang as a Release build.
The big change is that all AST nodes (subclasses of Stmt) whose children are
Expr* store their children as Stmt* or arrays of Stmt*. This is to remove
strict-aliasing warnings when using StmtIterator. None of the interfaces of any
of the classes have changed (except those with arg_iterators, see below), as the
accessor methods introduce the needed casts (via cast<>). While this extra
casting may seem cumbersome, it actually adds some important sanity checks
throughout the codebase, as clients using StmtIterator can potentially overwrite
children that are expected to be Expr* with Stmt* (that aren't Expr*). The casts
provide extra sanity checks that are operational in debug builds to catch
invariant violations such as these.
For classes that have arg_iterators (e.g., CallExpr), the definition of
arg_iterator has been replaced. Instead of it being Expr**, it is an actual
class (called ExprIterator) that wraps a Stmt**, and provides the necessary
operators for iteration. The nice thing about this class is that it also uses
cast<> to type-checking, which introduces extra sanity checks throughout the
codebase that are useful for debugging.
A few of the CodeGen functions that use arg_iterator (especially from
OverloadExpr) have been modified to take begin and end iterators instead of a
base Expr** and the number of arguments. This matches more with the abstraction
of iteration. This still needs to be cleaned up a little bit, as clients expect
that ExprIterator is a RandomAccessIterator (which we may or may not wish to
allow for efficiency of representation).
This is a fairly large patch. It passes the tests (except CodeGen/bitfield.c,
which was already broken) on both a Debug and Release build, but it should
obviously be reviewed.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52378 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/CFRefCount.cpp')
-rw-r--r-- | lib/Analysis/CFRefCount.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index 24971edcdd..7207c133ad 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -194,10 +194,10 @@ public: return Receiver; } - typedef ArgEffects::const_iterator arg_iterator; + typedef ArgEffects::const_iterator ExprIterator; - arg_iterator begin_args() const { return Args->begin(); } - arg_iterator end_args() const { return Args->end(); } + ExprIterator begin_args() const { return Args->begin(); } + ExprIterator end_args() const { return Args->end(); } static void Profile(llvm::FoldingSetNodeID& ID, ArgEffects* A, RetEffect RetEff, ArgEffect DefaultEff, @@ -998,7 +998,7 @@ public: Expr* Ex, Expr* Receiver, RetainSummary* Summ, - Expr** arg_beg, Expr** arg_end, + ExprIterator arg_beg, ExprIterator arg_end, ExplodedNode<ValueState>* Pred); virtual void EvalCall(ExplodedNodeSet<ValueState>& Dst, @@ -1129,7 +1129,7 @@ void CFRefCount::EvalSummary(ExplodedNodeSet<ValueState>& Dst, Expr* Ex, Expr* Receiver, RetainSummary* Summ, - Expr** arg_beg, Expr** arg_end, + ExprIterator arg_beg, ExprIterator arg_end, ExplodedNode<ValueState>* Pred) { @@ -1146,7 +1146,7 @@ void CFRefCount::EvalSummary(ExplodedNodeSet<ValueState>& Dst, Expr* ErrorExpr = NULL; SymbolID ErrorSym = 0; - for (Expr **I = arg_beg, **E = arg_end; I != E; ++I, ++idx) { + for (ExprIterator I = arg_beg; I != arg_end; ++I, ++idx) { RVal V = StateMgr.GetRVal(St, *I); @@ -1235,9 +1235,9 @@ void CFRefCount::EvalSummary(ExplodedNodeSet<ValueState>& Dst, case RetEffect::Alias: { unsigned idx = RE.getValue(); - assert ((arg_end - arg_beg) >= 0); + assert (arg_end >= arg_beg); assert (idx < (unsigned) (arg_end - arg_beg)); - RVal V = StateMgr.GetRVal(St, arg_beg[idx]); + RVal V = StateMgr.GetRVal(St, *(arg_beg+idx)); St = StateMgr.SetRVal(St, Ex, V, Eng.getCFG().isBlkExpr(Ex), false); break; } |