From 29f90e804d12daaaba89b1830de27af0e69e5af4 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Thu, 12 Jul 2012 08:20:49 +0000 Subject: [PATCH] PR13312: Don't crash when printing a fixit that ends in a unicode character. llvm-svn: 160112 --- clang/lib/Frontend/TextDiagnostic.cpp | 7 ++++++- clang/test/FixIt/fixit-unicode.c | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 clang/test/FixIt/fixit-unicode.c diff --git a/clang/lib/Frontend/TextDiagnostic.cpp b/clang/lib/Frontend/TextDiagnostic.cpp index ae1396672b77..306306d3acef 100644 --- a/clang/lib/Frontend/TextDiagnostic.cpp +++ b/clang/lib/Frontend/TextDiagnostic.cpp @@ -1160,8 +1160,13 @@ std::string TextDiagnostic::buildFixItInsertionLine( unsigned LastColumnModified = HintColNo + I->CodeToInsert.size(); - if (LastColumnModified <= static_cast(map.bytes())) + if (LastColumnModified <= static_cast(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/clang/test/FixIt/fixit-unicode.c b/clang/test/FixIt/fixit-unicode.c new file mode 100644 index 000000000000..04d582e856f4 --- /dev/null +++ b/clang/test/FixIt/fixit-unicode.c @@ -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: {{^ ;$}} +}