[LLVMbugs] [Bug 7999] New: Warning about stack returns doesn't account for reference type members

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Aug 26 09:42:11 PDT 2010


http://llvm.org/bugs/show_bug.cgi?id=7999

           Summary: Warning about stack returns doesn't account for
                    reference type members
           Product: clang
           Version: unspecified
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: chandlerc at gmail.com
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


This shows up in Boost, here is the reduced test case:

template <typename T> struct S {
  S(T& t) : value(t) {}

  T& value;
};

struct X {};

X& f(S<X> s) { return s.value; }

void test(X& x) { (void)f(x); }

And the patch to fix:

--- a/trunk/tools/clang/lib/Sema/SemaChecking.cpp
+++ b/trunk/tools/clang/lib/Sema/SemaChecking.cpp
@@ -2028,10 +2028,15 @@ do {
     MemberExpr *M = cast<MemberExpr>(E);

     // Check for indirect access.  We only want direct field accesses.
-    if (!M->isArrow())
-      return EvalVal(M->getBase());
-    else
+    if (M->isArrow())
+      return NULL;
+
+    // Check whether the member type is itself a reference, in which case
we're
+    // not going to refer to the member, but to what the member refers to.
+    if (M->getMemberDecl()->getType()->isReferenceType())
       return NULL;
+
+    return EvalVal(M->getBase());
   }

   // Everything else: we simply don't reason about them.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list