[cfe-commits] r131201 - in /cfe/trunk: lib/Sema/SemaCXXCast.cpp test/SemaCXX/MicrosoftExtensions.cpp

Francois Pichet pichet2000 at gmail.com
Wed May 11 15:13:54 PDT 2011


Author: fpichet
Date: Wed May 11 17:13:54 2011
New Revision: 131201

URL: http://llvm.org/viewvc/llvm-project?rev=131201&view=rev
Log:
In Microsoft mode, allow conversion from pointer to integral type no matter what size the integral type is. Necessary to parse MFC code.

Example:
void f(char *ptr) {
  char var = (char)ptr;
}

Modified:
    cfe/trunk/lib/Sema/SemaCXXCast.cpp
    cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp

Modified: cfe/trunk/lib/Sema/SemaCXXCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXCast.cpp?rev=131201&r1=131200&r2=131201&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Wed May 11 17:13:54 2011
@@ -1514,9 +1514,11 @@
   if (DestType->isIntegralType(Self.Context)) {
     assert(srcIsPtr && "One type must be a pointer");
     // C++ 5.2.10p4: A pointer can be explicitly converted to any integral
-    //   type large enough to hold it.
-    if (Self.Context.getTypeSize(SrcType) >
-        Self.Context.getTypeSize(DestType)) {
+    //   type large enough to hold it; except in Microsoft mode, where the
+    //   integral type size doesn't matter.
+    if ((Self.Context.getTypeSize(SrcType) >
+         Self.Context.getTypeSize(DestType)) &&
+         !Self.getLangOptions().Microsoft) {
       msg = diag::err_bad_reinterpret_cast_small_int;
       return TC_Failed;
     }

Modified: cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp?rev=131201&r1=131200&r2=131201&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp (original)
+++ cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp Wed May 11 17:13:54 2011
@@ -189,3 +189,11 @@
    void *a2 = &function_prototype;
    void *a3 = function_ptr;
 }
+
+
+void pointer_to_integral_type_conv(char* ptr) {
+   char ch = (char)ptr;
+   short sh = (short)ptr;
+   ch = (char)ptr;
+   sh = (short)ptr;
+} 





More information about the cfe-commits mailing list