Skip to content
  • Ted Kremenek's avatar
    This patch is motivated by numerous strict-aliasing warnings when compiling · 08e17118
    Ted Kremenek authored
    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.
    
    llvm-svn: 52378
    08e17118
Loading