[PATCH] CodeGen: Properly null-check typeid expressions

David Majnemer david.majnemer at gmail.com
Fri Jul 18 13:03:01 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;
----------------
Richard Smith wrote:
> Maybe add a test for the xvalue case; something like `typeid((T&&)*(T*)nullptr)` ?
Done.

================
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()) ||
----------------
Richard Smith wrote:
> How could this not be the case? Also, you have no test coverage for binary conditionals.
A test has been added, this code has been merged with the `ConditionalOperator` case above.

================
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();
----------------
Richard Smith wrote:
> Maybe extend this to say that it's not clear what this means, but we use the most generous interpretation.
Done.

http://reviews.llvm.org/D4416






More information about the cfe-commits mailing list