diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index f04a78f609..aab89d392d 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1837,17 +1837,14 @@ bool BinaryOperator::isNullPointerArithmeticExtension(ASTContext &Ctx, // Check that we have one pointer and one integer operand. Expr *PExp; - Expr *IExp; if (LHS->getType()->isPointerType()) { if (!RHS->getType()->isIntegerType()) return false; PExp = LHS; - IExp = RHS; } else if (RHS->getType()->isPointerType()) { if (!LHS->getType()->isIntegerType()) return false; PExp = RHS; - IExp = LHS; } else { return false; } @@ -1862,10 +1859,6 @@ bool BinaryOperator::isNullPointerArithmeticExtension(ASTContext &Ctx, if (!PTy || !PTy->getPointeeType()->isCharType()) return false; - // Check that the integer type is pointer-sized. - if (Ctx.getTypeSize(IExp->getType()) != Ctx.getTypeSize(PExp->getType())) - return false; - return true; } InitListExpr::InitListExpr(const ASTContext &C, SourceLocation lbraceloc, diff --git a/test/CodeGen/nullptr-arithmetic.c b/test/CodeGen/nullptr-arithmetic.c index 0c8ad5e34d..ce9c9765b0 100644 --- a/test/CodeGen/nullptr-arithmetic.c +++ b/test/CodeGen/nullptr-arithmetic.c @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -S %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -S %s -emit-llvm -triple i686-unknown-unknown -o - | FileCheck %s +// RUN: %clang_cc1 -S %s -emit-llvm -triple x86_64-unknown-unknown -o - | FileCheck %s #include @@ -32,3 +34,14 @@ int8_t* test3(intptr_t n) { // CHECK-LABEL: test3 // CHECK: getelementptr // CHECK-NOT: inttoptr + +// This checks the case where the offset isn't pointer-sized. +// The front end will implicitly cast the offset to an integer, so we need to +// make sure that doesn't cause problems on targets where integers and pointers +// are not the same size. +int8_t *test4(int8_t b) { + return NULLPTRI8 + b; +} +// CHECK-LABEL: test4 +// CHECK: inttoptr +// CHECK-NOT: getelementptr diff --git a/test/Sema/pointer-addition.c b/test/Sema/pointer-addition.c index 3e77cbde47..562f05340f 100644 --- a/test/Sema/pointer-addition.c +++ b/test/Sema/pointer-addition.c @@ -1,4 +1,6 @@ // RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wextra -std=c11 +// RUN: %clang_cc1 %s -fsyntax-only -triple i686-unknown-unknown -verify -pedantic -Wextra -std=c11 +// RUN: %clang_cc1 %s -fsyntax-only -triple x86_64-unknown-unknown -verify -pedantic -Wextra -std=c11 #include diff --git a/test/SemaCXX/nullptr-arithmetic.cpp b/test/SemaCXX/nullptr-arithmetic.cpp index 7d11e268f2..9963c8858e 100644 --- a/test/SemaCXX/nullptr-arithmetic.cpp +++ b/test/SemaCXX/nullptr-arithmetic.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wextra -std=c++11 +// RUN: %clang_cc1 %s -fsyntax-only -triple i686-unknown-unknown -verify -pedantic -Wextra -std=c++11 +// RUN: %clang_cc1 %s -fsyntax-only -triple x86_64-unknown-unknown -verify -pedantic -Wextra -std=c++11 #include