[PATCH] CodeGen: Properly null-check typeid expressions

Richard Smith richard at metafoo.co.uk
Sun Jul 13 16:53:51 PDT 2014


================
Comment at: lib/CodeGen/CGExprCXX.cpp:1618
@@ -1617,1 +1617,3 @@
 
+static bool isGLValueFromPointerDeref(const Expr *E) {
+  E = E->IgnoreParenCasts();
----------------
This doesn't handle

  ((T*)nullptr)[0]

Its semantics are defined in terms of a desugaring to

  *((T*)nullptr + 0)

... so I suppose we should probably handle it here, but it's not entirely clear.

================
Comment at: lib/CodeGen/CGExprCXX.cpp:1619
@@ +1618,3 @@
+static bool isGLValueFromPointerDeref(const Expr *E) {
+  E = E->IgnoreParenCasts();
+
----------------
I think this will insert a null check for

  T *p;
  typeid( (const T&)(T)*p )

... which doesn't seem strictly necessary (though superfluous null checks here seem pretty harmless).

http://reviews.llvm.org/D4416






More information about the cfe-commits mailing list