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:
parent
9e064a2180
commit
3c28524632
|
@ -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 {
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
// RUN: clang -emit-llvm %s -o - | grep "icmp ult"
|
||||
|
||||
int a(char* a, char* b) {return a<b;}
|
Loading…
Reference in New Issue