teak-llvm/clang/test/Frontend/source-col-map.c
Logan Chien d3d385d624 Frontend: Fix SourceColumnMap assertion failure on non-ascii characters.
If there are some non-ascii character in the input source code, the
column index might be smallar than the byte index.  This will result
in two possible assertion failures.  This CL fixes the computation of
the column index and byte index.

1. The assertion in startOfNextColumn() and startOfPreviousColumn()
   should not be raised when the byte index is greater than the column
   index since the non-ascii characters may use more than one bytes to
   store a character in a column.

2. The length of the caret line should be equal to the number of columns
   of source line, instead of the length of the source line.  Otherwise,
   the assertion in selectInterestingSourceRegion will be raised because
   the removed columns plus the kept columns are not greater than the max
   column, which means that we should not remove any column at all.

llvm-svn: 225442
2015-01-08 13:19:07 +00:00

38 lines
1.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// RUN: not %clang_cc1 %s -fsyntax-only -fmessage-length 75 -o /dev/null 2>&1 | FileCheck %s -strict-whitespace
// Test case for the text diagnostics source column conversion crash.
// This test case tries to check the error diagnostic message printer, which is
// responsible to create the code snippet shorter than the message-length (in
// number of columns.)
//
// The error diagnostic message printer should be able to handle the non-ascii
// characters without any segmentation fault or assertion failure. If your
// changes to clang frontend crashes this case, it is likely that you are mixing
// column index with byte index which are two totally different concepts.
// NOTE: This file is encoded in UTF-8 and intentionally contains some
// non-ASCII characters.
__attribute__((format(printf, 1, 2)))
extern int printf(const char *fmt, ...);
void test1(Unknown* b); // αααα αααα αααα αααα αααα αααα αααα αααα αααα αααα αααα
// CHECK: unknown type name 'Unknown'
// CHECK-NEXT: void test1(Unknown* b); // αααα αααα αααα αααα αααα αααα αααα ααα...
// CHECK-NEXT: {{^ \^$}}
void test2(Unknown* b); // αααα αααα αααα αααα αααα αααα αααα αααα αααα
// CHECK: unknown type name 'Unknown'
// CHECK-NEXT: void test2(Unknown* b); // αααα αααα αααα αααα αααα αααα αααα αααα αααα
// CHECK-NEXT: {{^ \^$}}
void test3() {
/* αααα αααα αααα αααα αααα αααα αααα αααα αααα αααα */ printf("%d", "s");
}
// CHECK: format specifies type 'int' but the argument has type 'char *'
// CHECK-NEXT: ...αααα αααα αααα αααα αααα αααα αααα αααα αααα */ printf("%d", "s");
// CHECK-NEXT: {{^ ~~ \^~~$}}
// CHECK-NEXT: {{^ %s$}}