add a test and a couple minor bug fixes for the implicit-signed-integer-truncation sanitizer. This is PR#40566

llvm-svn: 352926
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 2e719bc428d27345da7cdcfa634c03ec69f31474
diff --git a/include/locale b/include/locale
index f16d4ba..c3c05eb 100644
--- a/include/locale
+++ b/include/locale
@@ -546,7 +546,7 @@
         __exp = 'P';
     else if ((__x & 0x5F) == __exp)
     {
-        __exp |= 0x80;
+        __exp |= (char) 0x80;
         if (__in_units)
         {
             __in_units = false;
diff --git a/include/sstream b/include/sstream
index 71204e0..14c9197 100644
--- a/include/sstream
+++ b/include/sstream
@@ -558,7 +558,7 @@
             char_type* __p = const_cast<char_type*>(__str_.data());
             this->setg(__p, __p + __ninp, __hm_);
         }
-        return this->sputc(__c);
+        return this->sputc(traits_type::to_char_type(__c));
     }
     return traits_type::not_eof(__c);
 }
diff --git a/test/std/input.output/string.streams/stringstream.members/str.pass.cpp b/test/std/input.output/string.streams/stringstream.members/str.pass.cpp
index b8fa28d..392a168 100644
--- a/test/std/input.output/string.streams/stringstream.members/str.pass.cpp
+++ b/test/std/input.output/string.streams/stringstream.members/str.pass.cpp
@@ -58,4 +58,9 @@
         ss << i << ' ' << 321;
         assert(ss.str() == L"89 3219 ");
     }
+    {
+        std::stringstream ss;
+        ss.write("\xd1", 1);
+        assert(ss.str().length() == 1);
+    }
 }