[cfe-commits] r125070 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/SemaObjCXX/properties.mm

Douglas Gregor dgregor at apple.com
Mon Feb 7 18:14:35 PST 2011


Author: dgregor
Date: Mon Feb  7 20:14:35 2011
New Revision: 125070

URL: http://llvm.org/viewvc/llvm-project?rev=125070&view=rev
Log:
Sema::MaybeBindToTemporary() shouldn't treat any expression returning
a glvalue as a temporary. Previously, we were enumerating all of the
cases that coul return glvalues and might be called with
Sema::MaybeBindToTemporary(), but that was gross and we missed the
Objective-C property reference case.

Added:
    cfe/trunk/test/SemaObjCXX/properties.mm
Modified:
    cfe/trunk/lib/Sema/SemaExprCXX.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=125070&r1=125069&r2=125070&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon Feb  7 20:14:35 2011
@@ -3370,17 +3370,9 @@
   if (!RT)
     return Owned(E);
 
-  // If this is the result of a call or an Objective-C message send expression,
-  // our source might actually be a reference, in which case we shouldn't bind.
-  if (CallExpr *CE = dyn_cast<CallExpr>(E)) {
-    if (CE->getCallReturnType()->isReferenceType())
-      return Owned(E);
-  } else if (ObjCMessageExpr *ME = dyn_cast<ObjCMessageExpr>(E)) {
-    if (const ObjCMethodDecl *MD = ME->getMethodDecl()) {
-      if (MD->getResultType()->isReferenceType())
-        return Owned(E);
-    }
-  }
+  // If the result is a glvalue, we shouldn't bind it.
+  if (E->Classify(Context).isGLValue())
+    return Owned(E);
 
   // That should be enough to guarantee that this type is complete.
   // If it has a trivial destructor, we can avoid the extra copy.

Added: cfe/trunk/test/SemaObjCXX/properties.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/properties.mm?rev=125070&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/properties.mm (added)
+++ cfe/trunk/test/SemaObjCXX/properties.mm Mon Feb  7 20:14:35 2011
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct X { 
+  void f() const;
+  ~X();
+};
+
+ at interface A {
+  X x_;
+}
+
+- (const X&)x;
+- (void)setx:(const X&)other;
+ at end
+
+ at implementation A
+
+- (const X&)x { return x_; }
+- (void)setx:(const X&)other { x_ = other; }
+- (void)method {
+  self.x.f();
+} 
+ at end
+





More information about the cfe-commits mailing list