r260867 - Sema: prevent assertion on stack return checking

Saleem Abdulrasool via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 14 17:51:24 PST 2016


Author: compnerd
Date: Sun Feb 14 19:51:24 2016
New Revision: 260867

URL: http://llvm.org/viewvc/llvm-project?rev=260867&view=rev
Log:
Sema: prevent assertion on stack return checking

In the case that the array indexing itself is within a type dependent context,
bail out of the evaluation.  We would previously try to symbolically evaluate
the expression which would then try to evaluate a non-address expression as an
address, triggering an assertion in Asserts builds.

We only need to consider the array subscript expression itself as in the case
that the base itself being type dependent is handled appropriately in EvalAddr.

Resolves PR26599.

Added:
    cfe/trunk/test/SemaCXX/return-stack-addr-2.cpp
Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=260867&r1=260866&r2=260867&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Sun Feb 14 19:51:24 2016
@@ -6144,8 +6144,10 @@ static const Expr *EvalVal(const Expr *E
       // Array subscripts are potential references to data on the stack.  We
       // retrieve the DeclRefExpr* for the array variable if it indeed
       // has local storage.
-      return EvalAddr(cast<ArraySubscriptExpr>(E)->getBase(), refVars,
-                      ParentDecl);
+      const auto *ASE = cast<ArraySubscriptExpr>(E);
+      if (ASE->isTypeDependent())
+        return nullptr;
+      return EvalAddr(ASE->getBase(), refVars, ParentDecl);
     }
 
     case Stmt::OMPArraySectionExprClass: {

Added: cfe/trunk/test/SemaCXX/return-stack-addr-2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/return-stack-addr-2.cpp?rev=260867&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/return-stack-addr-2.cpp (added)
+++ cfe/trunk/test/SemaCXX/return-stack-addr-2.cpp Sun Feb 14 19:51:24 2016
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -std=c++11 %s
+// expected-no-diagnostics
+
+namespace PR26599 {
+template <typename>
+struct S;
+
+struct I {};
+
+template <typename T>
+void *&non_pointer() {
+  void *&r = S<T>()[I{}];
+  return r;
+}
+
+template <typename T>
+void *&pointer() {
+  void *&r = S<T>()[nullptr];
+  return r;
+}
+}
+




More information about the cfe-commits mailing list