From 3606220f9c8f20fc2d967c40d65a0d631f4c36b2 Mon Sep 17 00:00:00 2001 From: David Majnemer <david.majnemer@gmail.com> Date: Fri, 18 Jul 2014 19:53:25 +0000 Subject: [PATCH] Address Richard's latest feedback. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213404 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprCXX.cpp | 15 +++++++-------- test/CodeGenCXX/typeid-should-throw.cpp | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp index 768fab726b..5c4e1f1266 100644 --- a/lib/CodeGen/CGExprCXX.cpp +++ b/lib/CodeGen/CGExprCXX.cpp @@ -1628,14 +1628,9 @@ static bool isGLValueFromPointerDeref(const Expr *E) { if (BO->getOpcode() == BO_Comma) return isGLValueFromPointerDeref(BO->getRHS()); - if (const auto *CO = dyn_cast<ConditionalOperator>(E)) - return isGLValueFromPointerDeref(CO->getTrueExpr()) || - isGLValueFromPointerDeref(CO->getFalseExpr()); - - if (const auto *BCO = dyn_cast<BinaryConditionalOperator>(E)) - if (const auto *OVE = dyn_cast<OpaqueValueExpr>(BCO->getTrueExpr())) - return isGLValueFromPointerDeref(OVE->getSourceExpr()) || - isGLValueFromPointerDeref(BCO->getFalseExpr()); + if (const auto *ACO = dyn_cast<AbstractConditionalOperator>(E)) + return isGLValueFromPointerDeref(ACO->getTrueExpr()) || + isGLValueFromPointerDeref(ACO->getFalseExpr()); // C++11 [expr.sub]p1: // The expression E1[E2] is identical (by definition) to *((E1)+(E2)) @@ -1658,6 +1653,10 @@ static llvm::Value *EmitTypeidFromVTable(CodeGenFunction &CGF, const Expr *E, // If the glvalue expression is obtained by applying the unary * operator to // a pointer and the pointer is a null pointer value, the typeid expression // throws the std::bad_typeid exception. + // + // However, this paragraph's intent is not clear. We choose a very generous + // interpretation which implores us to consider comma operators, conditional + // operators, parentheses and other such constructs. QualType SrcRecordTy = E->getType(); if (CGF.CGM.getCXXABI().shouldTypeidBeNullChecked( isGLValueFromPointerDeref(E), SrcRecordTy)) { diff --git a/test/CodeGenCXX/typeid-should-throw.cpp b/test/CodeGenCXX/typeid-should-throw.cpp index 08e304b13a..8b3f2ac0bb 100644 --- a/test/CodeGenCXX/typeid-should-throw.cpp +++ b/test/CodeGenCXX/typeid-should-throw.cpp @@ -1,10 +1,11 @@ -// RUN: %clang_cc1 %s -triple %itanium_abi_triple -Wno-unused-value -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 %s -triple %itanium_abi_triple -Wno-unused-value -emit-llvm -o - -std=c++11 | FileCheck %s namespace std { struct type_info; } struct A { virtual ~A(); + operator bool(); }; struct B : A {}; @@ -53,6 +54,15 @@ void f9(A *x) { typeid(0[x]); } // CHECK: icmp eq {{.*}}, null // CHECK-NEXT: br i1 -void f10(A *x) { typeid((const A &)(A)*x); } -// CHECK-LABEL: define void @_Z3f10P1A +void f10(A *x, A *y) { typeid(*y ?: *x); } +// CHECK-LABEL: define void @_Z3f10P1AS0_ +// CHECK: icmp eq {{.*}}, null +// CHECK-NEXT: br i1 + +void f11(A *x) { typeid((const A &)(A)*x); } +// CHECK-LABEL: define void @_Z3f11P1A +// CHECK-NOT: icmp eq {{.*}}, null + +void f12(A *x) { typeid((A &&)*(A *)nullptr); } +// CHECK-LABEL: define void @_Z3f12P1A // CHECK-NOT: icmp eq {{.*}}, null -- 2.40.0