mirror of https://github.com/microsoft/clang.git
Remove offset size check in nullptr arithmetic handling
Differential Revision: https://reviews.llvm.org/D37042 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@313784 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
f6e021e7e9
commit
93bd7cd32d
|
@ -1837,17 +1837,14 @@ bool BinaryOperator::isNullPointerArithmeticExtension(ASTContext &Ctx,
|
||||||
|
|
||||||
// Check that we have one pointer and one integer operand.
|
// Check that we have one pointer and one integer operand.
|
||||||
Expr *PExp;
|
Expr *PExp;
|
||||||
Expr *IExp;
|
|
||||||
if (LHS->getType()->isPointerType()) {
|
if (LHS->getType()->isPointerType()) {
|
||||||
if (!RHS->getType()->isIntegerType())
|
if (!RHS->getType()->isIntegerType())
|
||||||
return false;
|
return false;
|
||||||
PExp = LHS;
|
PExp = LHS;
|
||||||
IExp = RHS;
|
|
||||||
} else if (RHS->getType()->isPointerType()) {
|
} else if (RHS->getType()->isPointerType()) {
|
||||||
if (!LHS->getType()->isIntegerType())
|
if (!LHS->getType()->isIntegerType())
|
||||||
return false;
|
return false;
|
||||||
PExp = RHS;
|
PExp = RHS;
|
||||||
IExp = LHS;
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1862,10 +1859,6 @@ bool BinaryOperator::isNullPointerArithmeticExtension(ASTContext &Ctx,
|
||||||
if (!PTy || !PTy->getPointeeType()->isCharType())
|
if (!PTy || !PTy->getPointeeType()->isCharType())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check that the integer type is pointer-sized.
|
|
||||||
if (Ctx.getTypeSize(IExp->getType()) != Ctx.getTypeSize(PExp->getType()))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
InitListExpr::InitListExpr(const ASTContext &C, SourceLocation lbraceloc,
|
InitListExpr::InitListExpr(const ASTContext &C, SourceLocation lbraceloc,
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
// RUN: %clang_cc1 -S %s -emit-llvm -o - | FileCheck %s
|
// 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 <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
@ -32,3 +34,14 @@ int8_t* test3(intptr_t n) {
|
||||||
// CHECK-LABEL: test3
|
// CHECK-LABEL: test3
|
||||||
// CHECK: getelementptr
|
// CHECK: getelementptr
|
||||||
// CHECK-NOT: inttoptr
|
// 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
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wextra -std=c11
|
// 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 <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wextra -std=c++11
|
// 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 <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue