]> granicus.if.org Git - clang/commitdiff
Ignore typedefs in pointer arithmetic codegen.
authorSeo Sanghyeon <sanxiyn@gmail.com>
Mon, 3 Dec 2007 06:23:43 +0000 (06:23 +0000)
committerSeo Sanghyeon <sanxiyn@gmail.com>
Mon, 3 Dec 2007 06:23:43 +0000 (06:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44529 91177308-0d34-0410-b5e6-96231b3b80d8

CodeGen/CGExprScalar.cpp
test/CodeGen/pointer-arithmetic.c [new file with mode: 0644]

index ab61aac59903f5374286d1881241d55128131bf4..7639d82f6bdf0d9a71644cbe2464eea63e5fdb39 100644 (file)
@@ -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/test/CodeGen/pointer-arithmetic.c b/test/CodeGen/pointer-arithmetic.c
new file mode 100644 (file)
index 0000000..6c644c6
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: clang -emit-llvm %s
+
+typedef int Int;
+
+int test1(int *a, Int *b) { return a - b; }