summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-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