summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-06-17 02:43:46 +0000
committerTed Kremenek <kremenek@apple.com>2008-06-17 02:43:46 +0000
commit08e171183ffe2039d5b071f89d3b16a0ca108d8b (patch)
tree91c727c8d7ec6a0d410ef031161a5d6c4fa5d0c8 /clang/lib/CodeGen
parente47ca0940f2b3910fb1a464d8f35a68b04fba2ec (diff)
downloadbcm5719-llvm-08e171183ffe2039d5b071f89d3b16a0ca108d8b.tar.gz
bcm5719-llvm-08e171183ffe2039d5b071f89d3b16a0ca108d8b.zip
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. llvm-svn: 52378
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGBuiltin.cpp2
-rw-r--r--clang/lib/CodeGen/CGExpr.cpp30
-rw-r--r--clang/lib/CodeGen/CGExprAgg.cpp3
-rw-r--r--clang/lib/CodeGen/CGExprComplex.cpp4
-rw-r--r--clang/lib/CodeGen/CGExprScalar.cpp2
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.h57
6 files changed, 35 insertions, 63 deletions
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f8132f417de..cd6b742b625 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -42,7 +42,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
if (getContext().BuiltinInfo.isLibFunction(BuiltinID))
return EmitCallExpr(CGM.getBuiltinLibFunction(BuiltinID),
E->getCallee()->getType(), E->arg_begin(),
- E->getNumArgs());
+ E->arg_end());
// See if we have a target specific intrinsic.
Intrinsic::ID IntrinsicID;
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 05a8972a404..5856531f433 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -650,13 +650,15 @@ RValue CodeGenFunction::EmitCallExpr(const CallExpr *E) {
llvm::Value *Callee = EmitScalarExpr(E->getCallee());
return EmitCallExpr(Callee, E->getCallee()->getType(),
- E->arg_begin(), E->getNumArgs());
+ E->arg_begin(), E->arg_end());
}
-RValue CodeGenFunction::EmitCallExpr(Expr *FnExpr, Expr *const *Args,
- unsigned NumArgs) {
+RValue CodeGenFunction::EmitCallExpr(Expr *FnExpr,
+ CallExpr::const_arg_iterator ArgBeg,
+ CallExpr::const_arg_iterator ArgEnd) {
+
llvm::Value *Callee = EmitScalarExpr(FnExpr);
- return EmitCallExpr(Callee, FnExpr->getType(), Args, NumArgs);
+ return EmitCallExpr(Callee, FnExpr->getType(), ArgBeg, ArgEnd);
}
LValue CodeGenFunction::EmitCallExprLValue(const CallExpr *E) {
@@ -702,7 +704,9 @@ LValue CodeGenFunction::EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E) {
}
RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType FnType,
- Expr *const *ArgExprs, unsigned NumArgs) {
+ CallExpr::const_arg_iterator ArgBeg,
+ CallExpr::const_arg_iterator ArgEnd) {
+
// The callee type will always be a pointer to function type, get the function
// type.
FnType = cast<PointerType>(FnType.getCanonicalType())->getPointeeType();
@@ -718,20 +722,20 @@ RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType FnType,
// FIXME: set the stret attribute on the argument.
}
- for (unsigned i = 0, e = NumArgs; i != e; ++i) {
- QualType ArgTy = ArgExprs[i]->getType();
+ for (CallExpr::const_arg_iterator I = ArgBeg; I != ArgEnd; ++I) {
+ QualType ArgTy = I->getType();
if (!hasAggregateLLVMType(ArgTy)) {
// Scalar argument is passed by-value.
- Args.push_back(EmitScalarExpr(ArgExprs[i]));
+ Args.push_back(EmitScalarExpr(*I));
} else if (ArgTy->isAnyComplexType()) {
// Make a temporary alloca to pass the argument.
llvm::Value *DestMem = CreateTempAlloca(ConvertType(ArgTy));
- EmitComplexExprIntoAddr(ArgExprs[i], DestMem, false);
+ EmitComplexExprIntoAddr(*I, DestMem, false);
Args.push_back(DestMem);
} else {
llvm::Value *DestMem = CreateTempAlloca(ConvertType(ArgTy));
- EmitAggExpr(ArgExprs[i], DestMem, false);
+ EmitAggExpr(*I, DestMem, false);
Args.push_back(DestMem);
}
}
@@ -744,8 +748,10 @@ RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType FnType,
ParamAttrList.push_back(
llvm::ParamAttrsWithIndex::get(1, llvm::ParamAttr::StructRet));
unsigned increment = hasAggregateLLVMType(ResultType) ? 2 : 1;
- for (unsigned i = 0; i < NumArgs; i++) {
- QualType ParamType = ArgExprs[i]->getType();
+
+ unsigned i = 0;
+ for (CallExpr::const_arg_iterator I = ArgBeg; I != ArgEnd; ++I, ++i) {
+ QualType ParamType = I->getType();
unsigned ParamAttrs = 0;
if (ParamType->isRecordType())
ParamAttrs |= llvm::ParamAttr::ByVal;
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 924a5cf46d8..748ddde7b7e 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -206,7 +206,8 @@ void AggExprEmitter::VisitCallExpr(const CallExpr *E)
void AggExprEmitter::VisitOverloadExpr(const OverloadExpr *E)
{
RValue RV = CGF.EmitCallExpr(E->getFn(), E->arg_begin(),
- E->getNumArgs(CGF.getContext()));
+ E->arg_end(CGF.getContext()));
+
assert(RV.isAggregate() && "Return value must be aggregate value!");
// If the result is ignored, don't copy from the value.
diff --git a/clang/lib/CodeGen/CGExprComplex.cpp b/clang/lib/CodeGen/CGExprComplex.cpp
index 8a8e7986770..6bf0d48c1ec 100644
--- a/clang/lib/CodeGen/CGExprComplex.cpp
+++ b/clang/lib/CodeGen/CGExprComplex.cpp
@@ -246,8 +246,8 @@ ComplexPairTy ComplexExprEmitter::VisitCallExpr(const CallExpr *E) {
}
ComplexPairTy ComplexExprEmitter::VisitOverloadExpr(const OverloadExpr *E) {
- return CGF.EmitCallExpr(E->getFn(), E->arg_begin(),
- E->getNumArgs(CGF.getContext())).getComplexVal();
+ return CGF.EmitCallExpr(E->getFn(), E->arg_begin(),
+ E->arg_end(CGF.getContext())).getComplexVal();
}
ComplexPairTy ComplexExprEmitter::VisitStmtExpr(const StmtExpr *E) {
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index ea92828f729..47bbd8827d4 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -1095,7 +1095,7 @@ Value *ScalarExprEmitter::VisitChooseExpr(ChooseExpr *E) {
Value *ScalarExprEmitter::VisitOverloadExpr(OverloadExpr *E) {
return CGF.EmitCallExpr(E->getFn(), E->arg_begin(),
- E->getNumArgs(CGF.getContext())).getScalarVal();
+ E->arg_end(CGF.getContext())).getScalarVal();
}
Value *ScalarExprEmitter::VisitVAArgExpr(VAArgExpr *VE) {
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 313d2d1829a..6712d2f05f1 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/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);
OpenPOWER on IntegriCloud