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

    <tr>
        <th>Summary</th>
        <td>
            fno-semantic-interposition breaks code relying on address uniqueness of a function
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          aelovikov-intel
      </td>
    </tr>
</table>

<pre>
    ```
// a.cpp
#include <functional>
#include <cassert>
int foo(int x) { return x + 42; }

bool bar(std::function<int(int)> F) {
  auto f = F.target<int(*)(int)>();
  return f && *f == foo;
}
```
```
// b.cpp
#include <functional>
int foo(int x);

bool bar(std::function<int(int)> F);

int main() {
  return bar(foo);
}
```
```
$ /usr/bin/clang++ -std=c++17 -fPIC -fno-semantic-interposition a.cpp -shared -o liba.so
$ /usr/bin/clang++ -std=c++17 b.cpp -L. -la
$ LD_LIBRARY_PATH=. ./a.out ; echo $?
0
$ /usr/bin/clang++ -std=c++17 -fPIC a.cpp -shared -o liba.so
$ LD_LIBRARY_PATH=. ./a.out ; echo $?
1
```

GCC is consistent with/without the option.

I'm not sure if that is a bug or desired behavior, but https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100483#c2 suggests that the case above doesn't use *semantic* interposition and so should work with the option. I'm not unlikely to misread/misunderstand it though.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylVU1v2zgQ_TXSZWDBoixZPujg2KvdADkURS89BRQ1lrihSS8_nLa_vkPJjoM02EWzACFRJOfNe49DqjP99yaplpe23CfLbcJaasAzcTpdRwqphQo9QlLsDkELL43mKin-eG-B4M6h9S-zUns4GJOwOva-JWwDyfoOLPpgNXyDhN3BiiXFHQ3vL4DTszNGQcctRTrfJ8WW2jU75SG0GZMQKRm0F-Q5GIAHb-BAjPbQZp7bAf1LVMK2MepV-DRInZfwCz8CYBU1em0nsIgX5VxX3ki_8fFdW7vfsPVX425JP2rQG4QIfORSz-pfu3eRP6NPLDa_L3lFrrXBEUTbxSStUFwPtOFxzxcT572YP_M1LA6f7nf01Gbh8Mi1l2JBBNGejJNR01yUFDhyiz0sDCjZ8cyZj-XrZrSHDBaK3yAe9o8P93eft5-_Pn7afvmLQjLICItnJniIdYpiNJRplRTtHPa_BP-3qA8wyt_fken5524H0oEw2knnkUrgWfqR8OIrIvoRwZyi49nruPuErY-gjQcXLII80ELuIxSHLgxgLPToZFTR4cjP0pAPO5ryMHp_crFAp1MwCJENOmTGDtGoMPyQinaAtW40z4_0nYlBkhQZ7cqXy1Vd0GERjPIOAzrv5sSRJl02CLwzZ4TeoCPL1x4CjdFxvRYRdeFNHekenAFKF1QPz8Y-TRa8Fg43tUEr-YTqO9B9cpTOIu-JK_WC7tE6H9FkpGPCMGYpNnlVleWyLMsi7Zui3xQbnnrpFTb_Utsd4T7FXaH7wFI2qclRotr3Fp0jEvKfgDp2zYEMv57zNFjVvLGXpAQqbnOkD6XO19fiZM3fKOg6aKVzAR11ypptynRs8pUoyr46bIqc1VXBsEBR0WRVYy-qTZ0q3qFyTVJS7TKNzzBBUD8p96ls2JKxfJnnecVIdoZlXxR1Xouq3tR5t05WS1ItVRZ5xH1PbTNRos12NKmoEN1tkv4gctCIUzrCp6t8NLbhqMxZPpnzZJ1KJwrNJOEnOw4ACA">