summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeo Sanghyeon <sanxiyn@gmail.com>2007-12-03 06:23:43 +0000
committerSeo Sanghyeon <sanxiyn@gmail.com>2007-12-03 06:23:43 +0000
commit3d072bea09eac989a4cb231dca74d9816c93f70b (patch)
treee03819fc02fb926cc54f92c36a0431e3396a15a9
parent9050bd1f687d04742ca54bb2541197c0c905934f (diff)
downloadbcm5719-llvm-3d072bea09eac989a4cb231dca74d9816c93f70b.tar.gz
bcm5719-llvm-3d072bea09eac989a4cb231dca74d9816c93f70b.zip
Ignore typedefs in pointer arithmetic codegen.
llvm-svn: 44529
-rw-r--r--clang/CodeGen/CGExprScalar.cpp8
-rw-r--r--clang/test/CodeGen/pointer-arithmetic.c5
2 files changed, 9 insertions, 4 deletions
diff --git a/clang/CodeGen/CGExprScalar.cpp b/clang/CodeGen/CGExprScalar.cpp
index ab61aac5990..7639d82f6bd 100644
--- a/clang/CodeGen/CGExprScalar.cpp
+++ b/clang/CodeGen/CGExprScalar.cpp
@@ -697,11 +697,11 @@ Value *ScalarExprEmitter::VisitBinSub(const BinaryOperator *E) {
Value *LHS = Visit(E->getLHS());
Value *RHS = Visit(E->getRHS());
- const PointerType *LHSPtrType = E->getLHS()->getType()->getAsPointerType();
- assert(LHSPtrType == E->getRHS()->getType()->getAsPointerType() &&
- "Can't subtract different pointer types");
+ const QualType LHSType = E->getLHS()->getType().getCanonicalType();
+ const QualType RHSType = E->getRHS()->getType().getCanonicalType();
+ assert(LHSType == RHSType && "Can't subtract different pointer types");
- QualType LHSElementType = LHSPtrType->getPointeeType();
+ QualType LHSElementType = cast<PointerType>(LHSType)->getPointeeType();
uint64_t ElementSize = CGF.getContext().getTypeSize(LHSElementType,
SourceLocation()) / 8;
diff --git a/clang/test/CodeGen/pointer-arithmetic.c b/clang/test/CodeGen/pointer-arithmetic.c
new file mode 100644
index 00000000000..6c644c6e06f
--- /dev/null
+++ b/clang/test/CodeGen/pointer-arithmetic.c
@@ -0,0 +1,5 @@
+// RUN: clang -emit-llvm %s
+
+typedef int Int;
+
+int test1(int *a, Int *b) { return a - b; }
OpenPOWER on IntegriCloud