diff --git a/src/clang_tu.cc b/src/clang_tu.cc index 70078c61..8e1b6c43 100644 --- a/src/clang_tu.cc +++ b/src/clang_tu.cc @@ -45,6 +45,16 @@ static Pos Decomposed2LineAndCol(const SourceManager &SM, std::pair I) { int l = SM.getLineNumber(I.first, I.second) - 1, c = SM.getColumnNumber(I.first, I.second) - 1; + bool Invalid = false; + StringRef Buf = SM.getBufferData(I.first, &Invalid); + if (!Invalid) { + StringRef P = Buf.substr(I.second - c, c); + c = 0; + for (size_t i = 0; i < P.size(); ) + if (c++, (uint8_t)P[i++] >= 128) + while (i < P.size() && (uint8_t)P[i] >= 128 && (uint8_t)P[i] < 192) + i++; + } return {(int16_t)std::min(l, INT16_MAX), (int16_t)std::min(c, INT16_MAX)}; }