[cfe-commits] r131957 - in /cfe/trunk: lib/Sema/SemaCXXCast.cpp test/SemaCXX/reinterpret-cast.cpp

Chandler Carruth chandlerc at gmail.com
Tue May 24 00:43:20 PDT 2011


Author: chandlerc
Date: Tue May 24 02:43:19 2011
New Revision: 131957

URL: http://llvm.org/viewvc/llvm-project?rev=131957&view=rev
Log:
Fix a bug in -Wundefined-reinterpret-cast where we failed to look
through sugared types when testing for TagTypes. This was the actual
cause of the only false positive in Clang+LLVM.

Next evaluation will be over a much larger selection of code including
large amounts of open source code.

Modified:
    cfe/trunk/lib/Sema/SemaCXXCast.cpp
    cfe/trunk/test/SemaCXX/reinterpret-cast.cpp

Modified: cfe/trunk/lib/Sema/SemaCXXCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXCast.cpp?rev=131957&r1=131956&r2=131957&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Tue May 24 02:43:19 2011
@@ -1330,7 +1330,7 @@
     return;
   }
   // or one of the types is a tag type.
-  if (isa<TagType>(SrcTy) || isa<TagType>(DestTy)) {
+  if (SrcTy->getAs<TagType>() || DestTy->getAs<TagType>()) {
     return;
   }
 

Modified: cfe/trunk/test/SemaCXX/reinterpret-cast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/reinterpret-cast.cpp?rev=131957&r1=131956&r2=131957&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/reinterpret-cast.cpp (original)
+++ cfe/trunk/test/SemaCXX/reinterpret-cast.cpp Tue May 24 02:43:19 2011
@@ -119,9 +119,13 @@
 
 void dereference_reinterpret_cast() {
   struct A {};
+  typedef A A2;
   class B {};
+  typedef B B2;
   A a;
   B b;
+  A2 a2;
+  B2 b2;
   long l;
   double d;
   float f;
@@ -142,6 +146,10 @@
   (void)*reinterpret_cast<A*>(&b);
   (void)reinterpret_cast<B&>(a);
   (void)*reinterpret_cast<B*>(&a);
+  (void)reinterpret_cast<A2&>(b2);
+  (void)*reinterpret_cast<A2*>(&b2);
+  (void)reinterpret_cast<B2&>(a2);
+  (void)*reinterpret_cast<B2*>(&a2);
 
   // Casting to itself is allowed
   (void)reinterpret_cast<A&>(a);





More information about the cfe-commits mailing list