<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - TextDiagnostic.cpp buildFixItInsertionLine assertion check failure of HintByteOffset"
   href="https://bugs.llvm.org/show_bug.cgi?id=33734">33734</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>TextDiagnostic.cpp buildFixItInsertionLine assertion check failure of HintByteOffset
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>chh@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Clang-tidy performance-unnecessary-value-param checks causes this assertion
failure in TextDiagnostic.cpp,
when a function's definition and declaration are at the same line of different
files,
and the declaration line is longer then the definition line.

If clang-tidy is built without assertion checks, it does not abort,
but the "displayed" suggested fix line is wrong.
The actual applied fix is correct.

The following test case is reduced from one Android source file.
Note that t.h declares f1 at line 5 and f2 at line 6.
t.cc defines f1 at line 3 and f2 at line 6.
Declaration lines of f1 and f2 in t.h are longer than
the header lines of f1 and f2 in t.cc.

$ cat t.h
struct ABC {
  ABC(const ABC&);
  int get(int) const;
};
int f1(        int n,       ABC v); // line 5
int f2(        int n,       ABC v); // line 6

$ cat t.cc
#include "t.h"
// line 2
int f1(int n, ABC v) {
  return v.get(n);
}
int f2(int n, ABC v) {
  return v.get(n);
}


============================================================
## Current output from clang-tidy release build, without
-DLLVM_ENABLE_ASSERTIONS
(clang-tidy did not abort, but suggested fix line for f2 is wrong)

clang_tidy  -checks=*,-anal*,-cppcoreguide*,-llvm*,-hicpp* -header-filter=.*
/tmp/t.cc --
2 warnings generated.
/tmp/t.cc:3:19: warning: the parameter 'v' is copied for each invocation but
only used as a const reference; consider making it a const reference
[performance-unnecessary-value-param]
int f1(int n, ABC v) {
              ~~~ ^
/tmp/t.cc:6:19: warning: the parameter 'v' is copied for each invocation but
only used as a const reference; consider making it a const reference
[performance-unnecessary-value-param]
int f2(int n, ABC v) {
              ~~~ ^
              const & const &


============================================================
## Current output from clang-tidy release build, with
-DLLVM_ENABLE_ASSERTIONS=On
(clang-tidy has assertion error)

.../llvm.307566/build/bin/clang-tidy 
-checks=*,-anal*,-cppcoreguide*,-llvm*,-hicpp* -header-filter=.* /tmp/t.cc --
2 warnings generated.
/tmp/t.cc:3:19: warning: the parameter 'v' is copied for each invocation but
only used as a const reference; consider making it a const reference
[performance-unnecessary-value-param]
int f1(int n, ABC v) {
              ~~~ ^
/tmp/t.cc:6:19: warning: the parameter 'v' is copied for each invocation but
only used as a const reference; consider making it a const reference
[performance-unnecessary-value-param]
clang-tidy:
.../llvm.307566/llvm/tools/clang/lib/Frontend/TextDiagnostic.cpp:1083:
std::string buildFixItInsertionLine(unsigned int, const
{anonymous}::SourceColumnMap&, llvm::ArrayRef<clang::FixItHint>, const
clang::SourceManager&, const clang::DiagnosticOptions*): Assertion
`HintByteOffset < static_cast<unsigned>(map.bytes())+1' failed.
Aborted (core dumped)


============================================================
## Expected output:

.../llvm.FID/build/bin/clang-tidy 
-checks=*,-anal*,-cppcoreguide*,-llvm*,-hicpp* -header-filter=.* /tmp/t.cc --
2 warnings generated.
/tmp/t.cc:3:19: warning: the parameter 'v' is copied for each invocation but
only used as a const reference; consider making it a const reference
[performance-unnecessary-value-param]
int f1(int n, ABC v) {
              ~~~ ^
              const &
/tmp/t.cc:6:19: warning: the parameter 'v' is copied for each invocation but
only used as a const reference; consider making it a const reference
[performance-unnecessary-value-param]
int f2(int n, ABC v) {
              ~~~ ^
              const &</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>