[PATCH] Fix for PR20110: Don't assume that the subexpression of a bit cast has pointer type if the bit cast has pointer type

Richard Trieu rtrieu at google.com
Tue Jul 1 21:48:09 PDT 2014


Closed by commit rL212160 (authored by @rtrieu).

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D4280

Files:
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/SemaCXX/PR20110.cpp

Index: cfe/trunk/test/SemaCXX/PR20110.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/PR20110.cpp
+++ cfe/trunk/test/SemaCXX/PR20110.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// expected-no-diagnostics
+
+// FIXME: These templates should trigger errors in C++11 mode.
+
+template <char const *p>
+class A {
+  char const *get_p() { return *p; }
+};
+template <int p>
+class B {
+  char const *get_p() { return p; }
+};
+
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -4613,7 +4613,6 @@
   case Stmt::CXXReinterpretCastExprClass: {
     Expr* SubExpr = cast<CastExpr>(E)->getSubExpr();
     switch (cast<CastExpr>(E)->getCastKind()) {
-    case CK_BitCast:
     case CK_LValueToRValue:
     case CK_NoOp:
     case CK_BaseToDerived:
@@ -4628,6 +4627,14 @@
     case CK_ArrayToPointerDecay:
       return EvalVal(SubExpr, refVars, ParentDecl);
 
+    case CK_BitCast:
+      if (SubExpr->getType()->isAnyPointerType() ||
+          SubExpr->getType()->isBlockPointerType() ||
+          SubExpr->getType()->isObjCQualifiedIdType())
+        return EvalAddr(SubExpr, refVars, ParentDecl);
+      else
+        return nullptr;
+
     default:
       return nullptr;
     }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4280.11018.patch
Type: text/x-patch
Size: 1449 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140702/d19e0570/attachment.bin>


More information about the cfe-commits mailing list