Fix an extremely subtle bug with pointer comparisons: they have to be

unsigned because it's possible (at least in theory) to have
have both positive and negative pointers pointing to the same object.

llvm-svn: 51681
This commit is contained in:
Eli Friedman 2008-05-29 15:09:15 +00:00
parent 9e064a2180
commit 3c28524632
2 changed files with 7 additions and 4 deletions

View File

@ -917,12 +917,12 @@ Value *ScalarExprEmitter::EmitCompare(const BinaryOperator *E,unsigned UICmpOpc,
if (LHS->getType()->isFloatingPoint()) {
Result = Builder.CreateFCmp((llvm::FCmpInst::Predicate)FCmpOpc,
LHS, RHS, "cmp");
} else if (LHSTy->isUnsignedIntegerType()) {
Result = Builder.CreateICmp((llvm::ICmpInst::Predicate)UICmpOpc,
} else if (LHSTy->isSignedIntegerType()) {
Result = Builder.CreateICmp((llvm::ICmpInst::Predicate)SICmpOpc,
LHS, RHS, "cmp");
} else {
// Signed integers and pointers.
Result = Builder.CreateICmp((llvm::ICmpInst::Predicate)SICmpOpc,
// Unsigned integers and pointers.
Result = Builder.CreateICmp((llvm::ICmpInst::Predicate)UICmpOpc,
LHS, RHS, "cmp");
}
} else {

View File

@ -0,0 +1,3 @@
// RUN: clang -emit-llvm %s -o - | grep "icmp ult"
int a(char* a, char* b) {return a<b;}