[cfe-dev] libIndex and diagnostic location's bogus column/offset

David Mirabito david.mirabito at gmail.com
Fri Jan 6 12:12:00 PST 2012


Hi All,

I have a little syntax highlighting app, built against libIndex and so
far it works great. However I've come against some troubles when
extending it to display diagnostic info.

In my test setup I basically follow these steps with main.c reading as:
--
#include <stdio.h>
int main (void)
{
    return 0;
}
--

 * clang_createIndex(1, 1)
 * clang_parseTranslationUnit(index, cPath,
                                        NULL, 0,
                                        NULL, 0,

clang_defaultEditingTranslationUnitOptions() |
detailedPreprocessingRecord);
 * manually delete the 2 characters: "0;" to force errors to obtain
some diagnostics
 * inform libIndex of the change via clang_reparseTranslationUnit(tu,
1, &unsaved, clang_defaultReparseOptions(tu));
 * clang_tokenize / clang_annotateTokens and processing the resulting
list works perfectly
 * clang_getNumDiagnostics(tu) ; clang_getNumDiagnostics(tu) ;
clang_formatDiagnostic(diag, ~0); produces the following 3 diagnostic
strings:

 /Users/davidm/test/main.c:5:1: error: expected expression [3, Parse Issue]
 /Users/davidm/test/main.c:5:8142: error: expected '}' [3, Parse Issue]
 /Users/davidm/test/main.c:3:1: note: to match this '{'

(note if I include the trailing newline the 2nd diagnostic is reported
at location 6:8140)
(and if I have 4 blank trailing lines after that the location is 9:8137)

 * clang_getDiagnosticLocation ; clang_getExpansionLocation also
return bogus column and offset values

It seems that no matter what the contents of the file (longer main,
additional definitions, etc) if the error is removing the "0;"
characters, the offset is always 8190 (0x1ffe). Is there some
significance to that value?

Or is my use of the library API incorrect?

If necessary I can perhaps distill down to a reproducible test case.

Lastly, the version of llvm/clang I checked-out when building the lib
and header is "clang version 3.1 (trunk 145025)". Perhaps over the
weekend I'll have time to update, but in the meantime I'm wondering if
this sounds familiar to anyone.

Cheers, and thanks!
David M



More information about the cfe-dev mailing list