[PATCH] CodeGen: Properly null-check typeid expressions
Richard Smith
richard at metafoo.co.uk
Tue Jul 15 16:39:16 PDT 2014
================
Comment at: lib/CodeGen/CGExprCXX.cpp:1622
@@ +1621,3 @@
+ if (const auto *CE = dyn_cast<CastExpr>(E)) {
+ if (!CE->getSubExpr()->isGLValue())
+ return false;
----------------
Maybe add a test for the xvalue case; something like `typeid((T&&)*(T*)nullptr)` ?
================
Comment at: lib/CodeGen/CGExprCXX.cpp:1636
@@ +1635,3 @@
+ if (const auto *BCO = dyn_cast<BinaryConditionalOperator>(E))
+ if (const auto *OVE = dyn_cast<OpaqueValueExpr>(BCO->getTrueExpr()))
+ return isGLValueFromPointerDeref(OVE->getSourceExpr()) ||
----------------
How could this not be the case? Also, you have no test coverage for binary conditionals.
================
Comment at: lib/CodeGen/CGExprCXX.cpp:1660
@@ -1625,8 +1659,3 @@
// a pointer and the pointer is a null pointer value, the typeid expression
// throws the std::bad_typeid exception.
QualType SrcRecordTy = E->getType();
----------------
Maybe extend this to say that it's not clear what this means, but we use the most generous interpretation.
http://reviews.llvm.org/D4416
More information about the cfe-commits
mailing list