<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - UBSan: constant operand required for __builtin_address()" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24256&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=bPJX3fM4CAkdRTYWQS87FeONvbKF3ejxNRZTQTrKAC4&s=2912eHjHurTHSP2MMrNAG-as2q0UpEC6aTptZYtojMQ&e=">24256</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>UBSan: constant operand required for __builtin_address()
          </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>LLVM Codegen
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>Wolfgang_Pieb@playstation.sony.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>//========================
void *gGetCallStack() { return __builtin_frame_address(0 + 0); }
//========================

Compiled with the undefined behavior sanitizer enabled:

clang -fsanitize=undefined -c t.cpp

produces an assertion:
clang-3.7: /home/user/src/llvm/trunk/llvm/include/llvm/Support/Casting.h:237:
typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X =
llvm::ConstantInt; Y = llvm::Value; typename llvm::cast_retty<X, Y*>::ret_type
= llvm::ConstantInt*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of
incompatible type!"' failed.

This is caused by clang not folding 0 + 0 but instead generating code
for it. The lowering of the LLVM builtin llvm.frameaddress is not prepared
for this and expects a constant.

This appears to be similar to <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed" title="RESOLVED FIXED - Constant builtin operands should be emitted as constants, even with UBSan" href="show_bug.cgi?id=23517">bug 23517</a> for ARM builtins.</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>