[cfe-commits] r51681 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGen/pointer-cmp-type.c
Eli Friedman
eli.friedman at gmail.com
Thu May 29 08:09:15 PDT 2008
Author: efriedma
Date: Thu May 29 10:09:15 2008
New Revision: 51681
URL: http://llvm.org/viewvc/llvm-project?rev=51681&view=rev
Log:
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.
Added:
cfe/trunk/test/CodeGen/pointer-cmp-type.c
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=51681&r1=51680&r2=51681&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Thu May 29 10:09:15 2008
@@ -917,12 +917,12 @@
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 {
Added: cfe/trunk/test/CodeGen/pointer-cmp-type.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/pointer-cmp-type.c?rev=51681&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/pointer-cmp-type.c (added)
+++ cfe/trunk/test/CodeGen/pointer-cmp-type.c Thu May 29 10:09:15 2008
@@ -0,0 +1,3 @@
+// RUN: clang -emit-llvm %s -o - | grep "icmp ult"
+
+int a(char* a, char* b) {return a<b;}
More information about the cfe-commits
mailing list