[cfe-commits] r91932 - in /cfe/trunk: lib/Sema/SemaCXXCast.cpp test/CodeGenCXX/casts.cpp

Douglas Gregor dgregor at apple.com
Tue Dec 22 14:47:22 PST 2009


Author: dgregor
Date: Tue Dec 22 16:47:22 2009
New Revision: 91932

URL: http://llvm.org/viewvc/llvm-project?rev=91932&view=rev
Log:
Make sure that reinterpret_cast gets a CastKind on all successful
paths. Fixes "cannot compile this unexpected cast lvalue yet" error in
llvm/lib/Analysis/IPA/GlobalsModRef.cpp.

Modified:
    cfe/trunk/lib/Sema/SemaCXXCast.cpp
    cfe/trunk/test/CodeGenCXX/casts.cpp

Modified: cfe/trunk/lib/Sema/SemaCXXCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXCast.cpp?rev=91932&r1=91931&r2=91932&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Tue Dec 22 16:47:22 2009
@@ -1053,8 +1053,11 @@
       return TC_NotApplicable;
 
     // If both types have the same size, we can successfully cast.
-    if (Self.Context.getTypeSize(SrcType) == Self.Context.getTypeSize(DestType))
+    if (Self.Context.getTypeSize(SrcType)
+          == Self.Context.getTypeSize(DestType)) {
+      Kind = CastExpr::CK_BitCast;
       return TC_Success;
+    }
     
     if (destIsScalar)
       msg = diag::err_bad_cxx_cast_vector_to_scalar_different_size;
@@ -1083,6 +1086,7 @@
     // to the same type. However, the behavior of compilers is pretty consistent
     // on this point: allow same-type conversion if the involved types are
     // pointers, disallow otherwise.
+    Kind = CastExpr::CK_NoOp;
     return TC_Success;
   }
 

Modified: cfe/trunk/test/CodeGenCXX/casts.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/casts.cpp?rev=91932&r1=91931&r2=91932&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/casts.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/casts.cpp Tue Dec 22 16:47:22 2009
@@ -5,6 +5,8 @@
 struct A {
   void copyFrom(const A &src);
   void addRef(void);
+
+  A& operator=(int);
 };
 
 void A::copyFrom(const A &src) {
@@ -12,3 +14,7 @@
 }
 }
 
+// reinterpret_cast to self
+void test(PR5248::A* a) {
+  reinterpret_cast<PR5248::A&>(*a) = 17;
+}





More information about the cfe-commits mailing list