r213403 - Address Richard's comments

David Majnemer david.majnemer at gmail.com
Fri Jul 18 12:53:23 PDT 2014


Author: majnemer
Date: Fri Jul 18 14:53:23 2014
New Revision: 213403

URL: http://llvm.org/viewvc/llvm-project?rev=213403&view=rev
Log:
Address Richard's comments

Modified:
    cfe/trunk/lib/CodeGen/CGExprCXX.cpp
    cfe/trunk/test/CodeGenCXX/typeid-should-throw.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=213403&r1=213402&r2=213403&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Fri Jul 18 14:53:23 2014
@@ -1616,14 +1616,13 @@ void CodeGenFunction::EmitCXXDeleteExpr(
 }
 
 static bool isGLValueFromPointerDeref(const Expr *E) {
-  E = E->IgnoreParenCasts();
+  E = E->IgnoreParens();
 
-  if (isa<ArraySubscriptExpr>(E))
-    return true;
-
-  if (const auto *UO = dyn_cast<UnaryOperator>(E))
-    if (UO->getOpcode() == UO_Deref)
-      return true;
+  if (const auto *CE = dyn_cast<CastExpr>(E)) {
+    if (!CE->getSubExpr()->isGLValue())
+      return false;
+    return isGLValueFromPointerDeref(CE->getSubExpr());
+  }
 
   if (const auto *BO = dyn_cast<BinaryOperator>(E))
     if (BO->getOpcode() == BO_Comma)
@@ -1638,6 +1637,15 @@ static bool isGLValueFromPointerDeref(co
       return isGLValueFromPointerDeref(OVE->getSourceExpr()) ||
              isGLValueFromPointerDeref(BCO->getFalseExpr());
 
+  // C++11 [expr.sub]p1:
+  //   The expression E1[E2] is identical (by definition) to *((E1)+(E2))
+  if (isa<ArraySubscriptExpr>(E))
+    return true;
+
+  if (const auto *UO = dyn_cast<UnaryOperator>(E))
+    if (UO->getOpcode() == UO_Deref)
+      return true;
+
   return false;
 }
 

Modified: cfe/trunk/test/CodeGenCXX/typeid-should-throw.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/typeid-should-throw.cpp?rev=213403&r1=213402&r2=213403&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/typeid-should-throw.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/typeid-should-throw.cpp Fri Jul 18 14:53:23 2014
@@ -52,3 +52,7 @@ void f9(A *x) { typeid(0[x]); }
 // CHECK-LABEL: define void @_Z2f9P1A
 // CHECK:       icmp eq {{.*}}, null
 // CHECK-NEXT:  br i1
+
+void f10(A *x) { typeid((const A &)(A)*x); }
+// CHECK-LABEL: define void @_Z3f10P1A
+// CHECK-NOT:   icmp eq {{.*}}, null





More information about the cfe-commits mailing list