]> granicus.if.org Git - clang/commitdiff
Fix PR10204 in a better way.
authorJohn McCall <rjmccall@apple.com>
Mon, 27 Jun 2011 21:24:11 +0000 (21:24 +0000)
committerJohn McCall <rjmccall@apple.com>
Mon, 27 Jun 2011 21:24:11 +0000 (21:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133943 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExpr.cpp
lib/Sema/SemaExprCXX.cpp

index 5bdb016738bfdc8e8bd7b71971f5dab480216095..a3f8301578fdd4c350484d721d26463225237202 100644 (file)
@@ -791,9 +791,7 @@ RValue CodeGenFunction::EmitLoadOfLValue(LValue LV) {
     return RValue::get(EmitARCLoadWeak(LV.getAddress()));
 
   if (LV.isSimple()) {
-    // Functions are l-values that don't require loading.
-    if (LV.getType()->isFunctionType())
-      return RValue::get(LV.getAddress());
+    assert(!LV.getType()->isFunctionType());
 
     // Everything needs a load.
     return RValue::get(EmitLoadOfScalar(LV));
index f8da76bf848e6e36c31faf71dd5815dba3b3f561..c6443e988bc4a7cd9e75e7b3ab6c377fc7e1625d 100644 (file)
@@ -4461,7 +4461,16 @@ ExprResult Sema::IgnoredValueConversions(Expr *E) {
   //   [Except in specific positions,] an lvalue that does not have
   //   array type is converted to the value stored in the
   //   designated object (and is no longer an lvalue).
-  if (E->isRValue()) return Owned(E);
+  if (E->isRValue()) {
+    // In C, function designators (i.e. expressions of function type)
+    // are r-values, but we still want to do function-to-pointer decay
+    // on them.  This is both technically correct and convenient for
+    // some clients.
+    if (!getLangOptions().CPlusPlus && E->getType()->isFunctionType())
+      return DefaultFunctionArrayConversion(E);
+
+    return Owned(E);
+  }
 
   // We always want to do this on ObjC property references.
   if (E->getObjectKind() == OK_ObjCProperty) {