This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG95ce9fbc235a: [clang] Do not crash on pointer wchar_t 
pointer assignment. (authored by adamcz).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91625/new/

https://reviews.llvm.org/D91625

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/wchar_t.cpp


Index: clang/test/SemaCXX/wchar_t.cpp
===================================================================
--- clang/test/SemaCXX/wchar_t.cpp
+++ clang/test/SemaCXX/wchar_t.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-// RUN: %clang_cc1 -fsyntax-only -Wno-signed-unsigned-wchar 
-verify=allow-signed %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-signed-unsigned-wchar 
-verify=allow-signed -DSKIP_ERROR_TESTS %s
 // allow-signed-no-diagnostics
 wchar_t x;
 
@@ -32,3 +32,10 @@
 // rdar://8040728
 wchar_t in[] = L"\x434" "\x434";  // No warning
 
+#ifndef SKIP_ERROR_TESTS
+// Verify that we do not crash when assigning wchar_t* to another pointer type.
+void assignment(wchar_t *x) {
+  char *y;
+  y = x; // expected-error {{incompatible pointer types assigning to 'char *' 
from 'wchar_t *'}}
+}
+#endif
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -10007,6 +10007,11 @@
     return UnsignedLongLongTy;
   case BuiltinType::Int128:
     return UnsignedInt128Ty;
+  // wchar_t is special. It is either signed or not, but when it's signed,
+  // there's no matching "unsigned wchar_t". Therefore we return the unsigned
+  // version of it's underlying type instead.
+  case BuiltinType::WChar_S:
+    return getUnsignedWCharType();
 
   case BuiltinType::ShortAccum:
     return UnsignedShortAccumTy;


Index: clang/test/SemaCXX/wchar_t.cpp
===================================================================
--- clang/test/SemaCXX/wchar_t.cpp
+++ clang/test/SemaCXX/wchar_t.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-// RUN: %clang_cc1 -fsyntax-only -Wno-signed-unsigned-wchar -verify=allow-signed %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-signed-unsigned-wchar -verify=allow-signed -DSKIP_ERROR_TESTS %s
 // allow-signed-no-diagnostics
 wchar_t x;
 
@@ -32,3 +32,10 @@
 // rdar://8040728
 wchar_t in[] = L"\x434" "\x434";  // No warning
 
+#ifndef SKIP_ERROR_TESTS
+// Verify that we do not crash when assigning wchar_t* to another pointer type.
+void assignment(wchar_t *x) {
+  char *y;
+  y = x; // expected-error {{incompatible pointer types assigning to 'char *' from 'wchar_t *'}}
+}
+#endif
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -10007,6 +10007,11 @@
     return UnsignedLongLongTy;
   case BuiltinType::Int128:
     return UnsignedInt128Ty;
+  // wchar_t is special. It is either signed or not, but when it's signed,
+  // there's no matching "unsigned wchar_t". Therefore we return the unsigned
+  // version of it's underlying type instead.
+  case BuiltinType::WChar_S:
+    return getUnsignedWCharType();
 
   case BuiltinType::ShortAccum:
     return UnsignedShortAccumTy;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to