[PATCH] CodeGen: Properly null-check typeid expressions

David Majnemer david.majnemer at gmail.com
Mon Jul 14 09:48:03 PDT 2014


================
Comment at: lib/CodeGen/CGExprCXX.cpp:1618
@@ -1617,1 +1617,3 @@
 
+static bool isGLValueFromPointerDeref(const Expr *E) {
+  E = E->IgnoreParenCasts();
----------------
Richard Smith wrote:
> 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.
I've updated `isGLValueFromPointerDeref` to handle this.

================
Comment at: lib/CodeGen/CGExprCXX.cpp:1619
@@ +1618,3 @@
+static bool isGLValueFromPointerDeref(const Expr *E) {
+  E = E->IgnoreParenCasts();
+
----------------
Richard Smith wrote:
> 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).
I can live with inserting an extra null check here.

http://reviews.llvm.org/D4416






More information about the cfe-commits mailing list