r190981 - Fix crash with cast of value-dependent expr.

Eli Friedman eli.friedman at gmail.com
Wed Sep 18 18:12:34 PDT 2013


Author: efriedma
Date: Wed Sep 18 20:12:33 2013
New Revision: 190981

URL: http://llvm.org/viewvc/llvm-project?rev=190981&view=rev
Log:
Fix crash with cast of value-dependent expr.

We don't really need to perform semantic analysis on the dependent expression
anyway, so just call the cast dependent.

<rdar://problem/15012610>

Modified:
    cfe/trunk/lib/Sema/SemaCast.cpp
    cfe/trunk/test/SemaTemplate/dependent-expr.cpp

Modified: cfe/trunk/lib/Sema/SemaCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=190981&r1=190980&r2=190981&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCast.cpp Wed Sep 18 20:12:33 2013
@@ -243,7 +243,9 @@ Sema::BuildCXXNamedCast(SourceLocation O
 
   // If the type is dependent, we won't do the semantic analysis now.
   // FIXME: should we check this in a more fine-grained manner?
-  bool TypeDependent = DestType->isDependentType() || Ex.get()->isTypeDependent();
+  bool TypeDependent = DestType->isDependentType() ||
+                       Ex.get()->isTypeDependent() ||
+                       Ex.get()->isValueDependent();
 
   CastOperation Op(*this, DestType, E);
   Op.OpRange = SourceRange(OpLoc, Parens.getEnd());
@@ -2008,7 +2010,8 @@ void CastOperation::CheckCXXCStyleCast(b
   }
 
   // If the type is dependent, we won't do any other semantic analysis now.
-  if (DestType->isDependentType() || SrcExpr.get()->isTypeDependent()) {
+  if (DestType->isDependentType() || SrcExpr.get()->isTypeDependent() ||
+      SrcExpr.get()->isValueDependent()) {
     assert(Kind == CK_Dependent);
     return;
   }

Modified: cfe/trunk/test/SemaTemplate/dependent-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/dependent-expr.cpp?rev=190981&r1=190980&r2=190981&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/dependent-expr.cpp (original)
+++ cfe/trunk/test/SemaTemplate/dependent-expr.cpp Wed Sep 18 20:12:33 2013
@@ -72,3 +72,10 @@ namespace PR8795 {
     return data[0];
   }
 }
+
+template<typename T> struct CastDependentIntToPointer {
+  static void* f() {
+    T *x;
+    return ((void*)(((unsigned long)(x)|0x1ul)));
+  }
+};





More information about the cfe-commits mailing list