<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/60759>60759</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            UBSan `function` check error message should state return type of the actual function called
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          seanm
      </td>
    </tr>
</table>

<pre>
    Consider this C++14:

```c++
#include <cstdio>

static float* foo (short* a)
{
        printf("%p\n", a);
        return nullptr;
}

int main (void)
{
        // Bad cast. Correct parameters, but mismatched return types.
        long*(*mypointer)(short*) = (long*(*)(short*))foo;

        mypointer(nullptr);

        return 0;
}
```

Then build with UBSan:

```
clang++ -std=c++14 -fsanitize=undefined test.cxx
```

Then run:

```
test.cxx:14:2: runtime error: call to function foo(short*) through pointer to incorrect function type 'long *(*)(short *)'
(a.out:x86_64+0x100003f10): note: foo(short*) defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior test.cxx:14:2 in
0x0
```

UBSan is correct to warn here.  But the error message is missing information.

It tells us:

1. the *incorrect* function pointer type: `long *(*)(short *)`
2. the *partial* signature of the function: `foo(short*)`

Note the return type (`float*`) of `foo` is *not* stated. This omission makes it harder to see that there is a mismatch ('they both take `short*`, what's the problem?)

(Of course this is a toy/reduced example, but in a large codebase I'm seeing an analogous UBSan warning where the parameters clearly match, and the return values seem to, but it would sure help if UBSan stated the return type it's expecting.)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVU9v47YT_TT0ZRBBpmzJPvjgPz8De9hfge7uoaeCEkcWuxQpkMPE7qcvSEmOk2wbIIgskfPmzXvDofBeXQzijq0PbH1aiECddTuPwvSL2srb7miNVxIdUKc8HBk_MH5YrlixZ_mJ5fP_Mh__mnHD9JUXyjQ6SARWHBtPUllW_O8x0JMg1UCrrSDG99BaC4xvfGddeheM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