]> granicus.if.org Git - clang/commitdiff
PR13312: Don't crash when printing a fixit that ends in a unicode character.
authorBenjamin Kramer <benny.kra@googlemail.com>
Thu, 12 Jul 2012 08:20:49 +0000 (08:20 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Thu, 12 Jul 2012 08:20:49 +0000 (08:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160112 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/TextDiagnostic.cpp
test/FixIt/fixit-unicode.c [new file with mode: 0644]

index ae1396672b77fa99dc974b71a660359e9979e7be..306306d3acef36e31a8b0b2886b40ef3f8dd8270 100644 (file)
@@ -1160,8 +1160,13 @@ std::string TextDiagnostic::buildFixItInsertionLine(
         unsigned LastColumnModified
           = HintColNo + I->CodeToInsert.size();
 
-        if (LastColumnModified <= static_cast<unsigned>(map.bytes()))
+        if (LastColumnModified <= static_cast<unsigned>(map.bytes())) {
+          // If we're right in the middle of a multibyte character skip to
+          // the end of it.
+          while (map.byteToColumn(LastColumnModified) == -1)
+            ++LastColumnModified;
           LastColumnModified = map.byteToColumn(LastColumnModified);
+        }
 
         if (LastColumnModified > FixItInsertionLine.size())
           FixItInsertionLine.resize(LastColumnModified, ' ');
diff --git a/test/FixIt/fixit-unicode.c b/test/FixIt/fixit-unicode.c
new file mode 100644 (file)
index 0000000..04d582e
--- /dev/null
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck -strict-whitespace %s
+// PR13312
+
+struct Foo {
+  int bar;
+};
+
+void test1() {
+  struct Foo foo;
+  (&foo)☃>bar = 42;
+// CHECK: error: expected ';' after expression
+// Make sure we emit the fixit right in front of the snowman.
+// CHECK: {{^        \^$}}
+// CHECK: {{^        ;$}}
+}