[cfe-commits] r64295 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGen/exprs.c
Chris Lattner
sabre at nondot.org
Tue Feb 10 23:21:43 PST 2009
Author: lattner
Date: Wed Feb 11 01:21:43 2009
New Revision: 64295
URL: http://llvm.org/viewvc/llvm-project?rev=64295&view=rev
Log:
finish off codegen support for sub of pointer to functions,
finishing off rdar://6520707
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/test/CodeGen/exprs.c
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=64295&r1=64294&r2=64295&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Wed Feb 11 01:21:43 2009
@@ -965,8 +965,9 @@
uint64_t ElementSize;
- // Handle GCC extension for pointer arithmetic on void* types.
- if (LHSElementType->isVoidType()) {
+ // Handle GCC extension for pointer arithmetic on void* and function pointer
+ // types.
+ if (LHSElementType->isVoidType() || LHSElementType->isFunctionType()) {
ElementSize = 1;
} else {
ElementSize = CGF.getContext().getTypeSize(LHSElementType) / 8;
@@ -977,6 +978,10 @@
RHS = Builder.CreatePtrToInt(RHS, ResultType, "sub.ptr.rhs.cast");
Value *BytesBetween = Builder.CreateSub(LHS, RHS, "sub.ptr.sub");
+ // Optimize out the shift for element size of 1.
+ if (ElementSize == 1)
+ return BytesBetween;
+
// HACK: LLVM doesn't have an divide instruction that 'knows' there is no
// remainder. As such, we handle common power-of-two cases here to generate
// better code. See PR2247.
Modified: cfe/trunk/test/CodeGen/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/exprs.c?rev=64295&r1=64294&r2=64295&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/exprs.c (original)
+++ cfe/trunk/test/CodeGen/exprs.c Wed Feb 11 01:21:43 2009
@@ -52,3 +52,10 @@
if (*t)
return;
}
+
+// rdar://6520707
+void f0(void (*fp)(void), void (*fp2)(void)) {
+ int x = fp - fp2;
+}
+
+
More information about the cfe-commits
mailing list