[cfe-commits] r46389 - in /cfe/trunk: CodeGen/CGExprConstant.cpp clang.xcodeproj/project.pbxproj
Anders Carlsson
andersca at mac.com
Fri Jan 25 20:30:24 PST 2008
Author: andersca
Date: Fri Jan 25 22:30:23 2008
New Revision: 46389
URL: http://llvm.org/viewvc/llvm-project?rev=46389&view=rev
Log:
Tweaks to EmitLValue in CGExprConstant. Patch by Eli Friedman.
Modified:
cfe/trunk/CodeGen/CGExprConstant.cpp
cfe/trunk/clang.xcodeproj/project.pbxproj
Modified: cfe/trunk/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprConstant.cpp?rev=46389&r1=46388&r2=46389&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/CodeGen/CGExprConstant.cpp Fri Jan 25 22:30:23 2008
@@ -22,7 +22,8 @@
using namespace CodeGen;
namespace {
-class VISIBILITY_HIDDEN ConstExprEmitter : public StmtVisitor<ConstExprEmitter, llvm::Constant*> {
+class VISIBILITY_HIDDEN ConstExprEmitter :
+ public StmtVisitor<ConstExprEmitter, llvm::Constant*> {
CodeGenModule &CGM;
public:
ConstExprEmitter(CodeGenModule &cgm)
@@ -285,7 +286,7 @@
// The source value may be an integer, or a pointer.
if (isa<llvm::PointerType>(Src->getType()))
return llvm::ConstantExpr::getBitCast(Src, DstTy);
- assert(SrcType->isIntegerType() && "Not ptr->ptr or int->ptr conversion?");
+ assert(SrcType->isIntegerType() &&"Not ptr->ptr or int->ptr conversion?");
return llvm::ConstantExpr::getIntToPtr(Src, DstTy);
}
@@ -353,8 +354,8 @@
CGM.getContext().getTypeSize(RetType, SourceLocation()));
return llvm::ConstantInt::get(llvm::APInt(ResultWidth, Val));
}
-
- llvm::Constant *EmitLValue(const Expr *E) {
+
+ llvm::Constant *EmitLValue(Expr *E) {
switch (E->getStmtClass()) {
default: {
CGM.WarnUnsupported(E, "constant l-value expression");
@@ -367,15 +368,15 @@
case Expr::CompoundLiteralExprClass: {
// Note that due to the nature of compound literals, this is guaranteed
// to be the only use of the variable, so we just generate it here.
- const CompoundLiteralExpr *CLE = cast<CompoundLiteralExpr>(E);
- llvm::Constant* C = CGM.EmitGlobalInit(CLE->getInitializer());
- C =new llvm::GlobalVariable(C->getType(), E->getType().isConstQualified(),
+ CompoundLiteralExpr *CLE = cast<CompoundLiteralExpr>(E);
+ llvm::Constant* C = Visit(CLE->getInitializer());
+ C = new llvm::GlobalVariable(C->getType(), E->getType().isConstQualified(),
llvm::GlobalValue::InternalLinkage,
C, ".compoundliteral", &CGM.getModule());
return C;
- }
+ }
case Expr::DeclRefExprClass: {
- const ValueDecl *Decl = cast<DeclRefExpr>(E)->getDecl();
+ ValueDecl *Decl = cast<DeclRefExpr>(E)->getDecl();
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(Decl))
return CGM.GetAddrOfFunctionDecl(FD, false);
if (const FileVarDecl* FVD = dyn_cast<FileVarDecl>(Decl))
@@ -386,9 +387,13 @@
return 0;
}
case Expr::MemberExprClass: {
- const MemberExpr* ME = cast<MemberExpr>(E);
+ MemberExpr* ME = cast<MemberExpr>(E);
unsigned FieldNumber = CGM.getTypes().getLLVMFieldNo(ME->getMemberDecl());
- llvm::Constant *Base = EmitLValue(ME->getBase());
+ llvm::Constant *Base;
+ if (ME->isArrow())
+ Base = Visit(ME->getBase());
+ else
+ Base = EmitLValue(ME->getBase());
llvm::Constant *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
llvm::Constant *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty,
FieldNumber);
@@ -396,46 +401,46 @@
return llvm::ConstantExpr::getGetElementPtr(Base, Ops, 2);
}
case Expr::ArraySubscriptExprClass: {
- const ArraySubscriptExpr* ASExpr = cast<ArraySubscriptExpr>(E);
- llvm::Constant *Base = EmitLValue(ASExpr->getBase());
- llvm::Constant *Index = EmitLValue(ASExpr->getIdx());
+ ArraySubscriptExpr* ASExpr = cast<ArraySubscriptExpr>(E);
+ llvm::Constant *Base = Visit(ASExpr->getBase());
+ llvm::Constant *Index = Visit(ASExpr->getIdx());
assert(!ASExpr->getBase()->getType()->isVectorType() &&
"Taking the address of a vector component is illegal!");
return llvm::ConstantExpr::getGetElementPtr(Base, &Index, 1);
}
case Expr::StringLiteralClass: {
- const StringLiteral *String = cast<StringLiteral>(E);
+ StringLiteral *String = cast<StringLiteral>(E);
assert(!String->isWide() && "Cannot codegen wide strings yet");
- const char *StrData = String->getStrData();
- unsigned Len = String->getByteLength();
+ const char *StrData = String->getStrData();
+ unsigned Len = String->getByteLength();
- return CGM.GetAddrOfConstantString(std::string(StrData, StrData + Len));
- }
- case Expr::UnaryOperatorClass: {
- const UnaryOperator *Exp = cast<UnaryOperator>(E);
- switch (Exp->getOpcode()) {
- default: assert(0 && "Unsupported unary operator.");
- case UnaryOperator::Extension:
- // Extension is just a wrapper for expressions
- return EmitLValue(Exp->getSubExpr());
- case UnaryOperator::Real:
- case UnaryOperator::Imag: {
- // The address of __real or __imag is just a GEP off the address
- // of the internal expression
- llvm::Constant* C = EmitLValue(Exp->getSubExpr());
- llvm::Constant *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
- llvm::Constant *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty,
- Exp->getOpcode() == UnaryOperator::Imag);
- llvm::Value *Ops[] = {Zero, Idx};
- return llvm::ConstantExpr::getGetElementPtr(C, Ops, 2);
+ return CGM.GetAddrOfConstantString(std::string(StrData, StrData + Len));
}
- case UnaryOperator::Deref:
- // The address of a deref is just the value of the expression
- return Visit(Exp->getSubExpr());
+ case Expr::UnaryOperatorClass: {
+ UnaryOperator *Exp = cast<UnaryOperator>(E);
+ switch (Exp->getOpcode()) {
+ default: assert(0 && "Unsupported unary operator.");
+ case UnaryOperator::Extension:
+ // Extension is just a wrapper for expressions
+ return EmitLValue(Exp->getSubExpr());
+ case UnaryOperator::Real:
+ case UnaryOperator::Imag: {
+ // The address of __real or __imag is just a GEP off the address
+ // of the internal expression
+ llvm::Constant* C = EmitLValue(Exp->getSubExpr());
+ llvm::Constant *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
+ llvm::Constant *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty,
+ Exp->getOpcode() == UnaryOperator::Imag);
+ llvm::Value *Ops[] = {Zero, Idx};
+ return llvm::ConstantExpr::getGetElementPtr(C, Ops, 2);
+ }
+ case UnaryOperator::Deref:
+ // The address of a deref is just the value of the expression
+ return Visit(Exp->getSubExpr());
+ }
}
+ }
}
- }
-}
};
Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=46389&r1=46388&r2=46389&view=diff
==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Fri Jan 25 22:30:23 2008
@@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
03F50AC60D416EAA00B9CF60 /* Targets.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 03F50AC50D416EAA00B9CF60 /* Targets.cpp */; };
1A30A9E90B93A4C800201A91 /* ExprCXX.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1A30A9E80B93A4C800201A91 /* ExprCXX.h */; };
+ 1A376A2D0D4AED9B002A1C52 /* CGExprConstant.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A376A2C0D4AED9B002A1C52 /* CGExprConstant.cpp */; };
1A7342480C7B57D500122F56 /* CGObjC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A7342470C7B57D500122F56 /* CGObjC.cpp */; };
1A869A700BA2164C008DA07A /* LiteralSupport.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1A869A6E0BA2164C008DA07A /* LiteralSupport.h */; };
1A869AA80BA21ABA008DA07A /* LiteralSupport.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A869AA70BA21ABA008DA07A /* LiteralSupport.cpp */; };
@@ -221,6 +222,7 @@
/* Begin PBXFileReference section */
03F50AC50D416EAA00B9CF60 /* Targets.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Targets.cpp; sourceTree = "<group>"; };
1A30A9E80B93A4C800201A91 /* ExprCXX.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ExprCXX.h; path = clang/AST/ExprCXX.h; sourceTree = "<group>"; };
+ 1A376A2C0D4AED9B002A1C52 /* CGExprConstant.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CGExprConstant.cpp; path = CodeGen/CGExprConstant.cpp; sourceTree = "<group>"; };
1A68BC110D0CADDD001A28C8 /* PPCBuiltins.def */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = PPCBuiltins.def; path = clang/AST/PPCBuiltins.def; sourceTree = "<group>"; };
1A68BC120D0CADDD001A28C8 /* TargetBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TargetBuiltins.h; path = clang/AST/TargetBuiltins.h; sourceTree = "<group>"; };
1A68BC130D0CADDD001A28C8 /* X86Builtins.def */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = X86Builtins.def; path = clang/AST/X86Builtins.def; sourceTree = "<group>"; };
@@ -580,6 +582,7 @@
DE4772FB0C10EAEC002239E8 /* CGExpr.cpp */,
DEF2EFF20C6CDD74000C4259 /* CGExprAgg.cpp */,
DE224FF70C7AA98800D370A5 /* CGExprComplex.cpp */,
+ 1A376A2C0D4AED9B002A1C52 /* CGExprConstant.cpp */,
DE22526F0C7E82D000D370A5 /* CGExprScalar.cpp */,
1A7342470C7B57D500122F56 /* CGObjC.cpp */,
DE4772F90C10EAE5002239E8 /* CGStmt.cpp */,
@@ -901,6 +904,7 @@
35BB2D7F0D19954000944DB5 /* ASTConsumer.cpp in Sources */,
DE47999C0D2EBE1A00706D2D /* SemaExprObjC.cpp in Sources */,
03F50AC60D416EAA00B9CF60 /* Targets.cpp in Sources */,
+ 1A376A2D0D4AED9B002A1C52 /* CGExprConstant.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
More information about the cfe-commits
mailing list