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

    <tr>
        <th>Summary</th>
        <td>
            Address of empty function is not unique
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    Consider following snippet (https://godbolt.org/z/beGsh8zoj) compiled at least with `-O1`:

~~~~
#include <iostream>

void foo() { __builtin_unreachable(); }
void bar() {}

int main() {
 auto ap = size_t(&foo);
 auto bp = size_t(&bar);

 std::cout 
 << ap << "\n"
 << bp << "\n"
 << ap-bp << "\n"
 << (ap == bp ? "true\n" : "false\n");
}
~~~~

the output of this programs look like 

~~~~
95027430187360
95027430187360
0
false
~~~~


clang manages to creates two equal numbers (the difference is `0`), that are not equal



I believe this issue is related to https://github.com/llvm/llvm-project/issues/60588 (the oldest one I could find), which was (IMHO wrongly) rejected.

`void foo() { __builtin_unreachable(); }` does not have undefined behavior as long as it is not called, and taking the address of `foo` should thus not trigger undefined behavior.

The argument "The problematic code doesn't need to be executed for UB to take effect" is strangely worded.
The function `int baz(int i){return 1/i;}` also has UB when called as `baz(0)`, but as long as no one calls `baz` with the parameter `0`, there is no UB.

Contrary to most linked bug reports linked to https://github.com/llvm/llvm-project/issues/60588, the problematic function is not called.

As to why one would write something like `foo`; an example would be to write code for a compiler that does not support `__builtin_unreachable`; for example

~~~~
#ifdef PLATFORM_WITH_BUILTIN_UNREACHABLE
void foo() { __builtin_unreachable(); }
#else
void foo() { abort(); }
#endif

// some code that uses foo instead of 
// __builtin_unreachable directly to ensure portability
// with different compilers
~~~~

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVk1v2zgT_jX0ZdCApmxZPvhgu_XbAP14USTYY0CJI4kNRar8iJsc8tsXQ9lxuw12gRZIIH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