[cfe-commits] r45530 - in /cfe/trunk: CodeGen/CGExprScalar.cpp CodeGen/CodeGenModule.h clang.xcodeproj/project.pbxproj test/CodeGen/exprs.c
Chris Lattner
sabre at nondot.org
Wed Jan 2 22:36:54 PST 2008
Author: lattner
Date: Thu Jan 3 00:36:51 2008
New Revision: 45530
URL: http://llvm.org/viewvc/llvm-project?rev=45530&view=rev
Log:
Fix a crash reported by Seo Sanghyeon.
Modified:
cfe/trunk/CodeGen/CGExprScalar.cpp
cfe/trunk/CodeGen/CodeGenModule.h
cfe/trunk/clang.xcodeproj/project.pbxproj
cfe/trunk/test/CodeGen/exprs.c
Modified: cfe/trunk/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprScalar.cpp?rev=45530&r1=45529&r2=45530&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/CodeGen/CGExprScalar.cpp Thu Jan 3 00:36:51 2008
@@ -713,10 +713,30 @@
return Builder.CreateAdd(Ops.LHS, Ops.RHS, "add");
// FIXME: What about a pointer to a VLA?
- if (isa<llvm::PointerType>(Ops.LHS->getType())) // pointer + int
- return Builder.CreateGEP(Ops.LHS, Ops.RHS, "add.ptr");
- // int + pointer
- return Builder.CreateGEP(Ops.RHS, Ops.LHS, "add.ptr");
+ Value *Ptr, *Idx;
+ Expr *IdxExp;
+ if (isa<llvm::PointerType>(Ops.LHS->getType())) { // pointer + int
+ Ptr = Ops.LHS;
+ Idx = Ops.RHS;
+ IdxExp = Ops.E->getRHS();
+ } else { // int + pointer
+ Ptr = Ops.RHS;
+ Idx = Ops.LHS;
+ IdxExp = Ops.E->getLHS();
+ }
+
+ unsigned Width = cast<llvm::IntegerType>(Idx->getType())->getBitWidth();
+ if (Width < CGF.LLVMPointerWidth) {
+ // Zero or sign extend the pointer value based on whether the index is
+ // signed or not.
+ const llvm::Type *IdxType = llvm::IntegerType::get(CGF.LLVMPointerWidth);
+ if (IdxExp->getType().getCanonicalType()->isSignedIntegerType())
+ Idx = Builder.CreateSExt(Idx, IdxType, "idx.ext");
+ else
+ Idx = Builder.CreateZExt(Idx, IdxType, "idx.ext");
+ }
+
+ return Builder.CreateGEP(Ptr, Idx, "add.ptr");
}
Value *ScalarExprEmitter::EmitSub(const BinOpInfo &Ops) {
Modified: cfe/trunk/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenModule.h?rev=45530&r1=45529&r2=45530&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/CodeGen/CodeGenModule.h Thu Jan 3 00:36:51 2008
@@ -67,6 +67,7 @@
llvm::Module &getModule() const { return TheModule; }
CodeGenTypes &getTypes() { return Types; }
Diagnostic &getDiags() const { return Diags; }
+ const llvm::TargetData &getTargetData() const { return TheTargetData; }
llvm::Constant *GetAddrOfFunctionDecl(const FunctionDecl *D,
bool isDefinition);
Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=45530&r1=45529&r2=45530&view=diff
==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Thu Jan 3 00:36:51 2008
@@ -796,6 +796,7 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
+ compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = "";
Modified: cfe/trunk/test/CodeGen/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/exprs.c?rev=45530&r1=45529&r2=45530&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/exprs.c (original)
+++ cfe/trunk/test/CodeGen/exprs.c Thu Jan 3 00:36:51 2008
@@ -6,3 +6,11 @@
int x=sizeof(zxcv);
int y=__alignof__(zxcv);
+
+void *test(int *i) {
+ short a = 1;
+ i += a;
+ i + a;
+ a + i;
+}
+
More information about the cfe-commits
mailing list