[cfe-commits] r160112 - in /cfe/trunk: lib/Frontend/TextDiagnostic.cpp test/FixIt/fixit-unicode.c

Benjamin Kramer benny.kra at googlemail.com
Thu Jul 12 01:20:50 PDT 2012


Author: d0k
Date: Thu Jul 12 03:20:49 2012
New Revision: 160112

URL: http://llvm.org/viewvc/llvm-project?rev=160112&view=rev
Log:
PR13312: Don't crash when printing a fixit that ends in a unicode character.

Added:
    cfe/trunk/test/FixIt/fixit-unicode.c
Modified:
    cfe/trunk/lib/Frontend/TextDiagnostic.cpp

Modified: cfe/trunk/lib/Frontend/TextDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnostic.cpp?rev=160112&r1=160111&r2=160112&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnostic.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnostic.cpp Thu Jul 12 03:20:49 2012
@@ -1160,8 +1160,13 @@
         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, ' ');

Added: cfe/trunk/test/FixIt/fixit-unicode.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-unicode.c?rev=160112&view=auto
==============================================================================
--- cfe/trunk/test/FixIt/fixit-unicode.c (added)
+++ cfe/trunk/test/FixIt/fixit-unicode.c Thu Jul 12 03:20:49 2012
@@ -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: {{^        ;$}}
+}





More information about the cfe-commits mailing list