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/CodeGen/CodeGenFunction.h | |
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/CodeGen/CodeGenFunction.h')
-rw-r--r-- | lib/CodeGen/CodeGenFunction.h | 57 |
1 files changed, 11 insertions, 46 deletions
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index 313d2d1829..6712d2f05f 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -18,6 +18,9 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/IRBuilder.h" +#include "clang/AST/Expr.h" +#include "clang/AST/ExprObjC.h" + #include <vector> namespace llvm { @@ -31,50 +34,7 @@ namespace clang { class ObjCMethodDecl; class TargetInfo; class FunctionTypeProto; - - class Stmt; - class CompoundStmt; - class LabelStmt; - class GotoStmt; - class IfStmt; - class WhileStmt; - class DoStmt; - class ForStmt; - class ReturnStmt; - class DeclStmt; - class CaseStmt; - class DefaultStmt; - class SwitchStmt; - class AsmStmt; - - class Expr; - class DeclRefExpr; - class StringLiteral; - class IntegerLiteral; - class FloatingLiteral; - class CharacterLiteral; - class TypesCompatibleExpr; - - class ImplicitCastExpr; - class CastExpr; - class CallExpr; - class UnaryOperator; - class BinaryOperator; - class CompoundAssignOperator; - class ArraySubscriptExpr; - class ExtVectorElementExpr; - class ConditionalOperator; - class ChooseExpr; - class PreDefinedExpr; - class ObjCStringLiteral; - class ObjCIvarRefExpr; - class MemberExpr; - class CompoundLiteralExpr; - - class VarDecl; - class EnumConstantDecl; - class ParmVarDecl; - class FieldDecl; + namespace CodeGen { class CodeGenModule; class CodeGenTypes; @@ -468,9 +428,14 @@ public: //===--------------------------------------------------------------------===// RValue EmitCallExpr(const CallExpr *E); - RValue EmitCallExpr(Expr *FnExpr, Expr *const *Args, unsigned NumArgs); + + RValue EmitCallExpr(Expr *FnExpr, CallExpr::const_arg_iterator ArgBeg, + CallExpr::const_arg_iterator ArgEnd); + RValue EmitCallExpr(llvm::Value *Callee, QualType FnType, - Expr *const *Args, unsigned NumArgs); + CallExpr::const_arg_iterator ArgBeg, + CallExpr::const_arg_iterator ArgEnd); + RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E); llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E); |