<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 - [optimizer + ubsan] constructor call on address with insufficient space for an object of type"
   href="https://bugs.llvm.org/show_bug.cgi?id=51120">51120</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[optimizer + ubsan] constructor call on address with insufficient space for an object of type
          </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>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>matthewjbarichello@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Affected versions:
Note: The regression seems to have been introduced in 11.0.0 as versions <=
10.0.1 do not exhibit this issue.
 - trunk
 - 12.0.1
 - 12.0.0
 - 11.1.0
 - 11.0.0

Driver cmdline:
Note: This bug occurs with all optimizer levels > 0
 clang++ -std=c++20 -O1 -fsanitize=undefined

Code:
Note: Code was reduced from the initial ~20k line sample
 struct A {
  struct B {
   char _[0];
  } b;

  A(B b) : b{b} {}
 };

 int main() {
  A{{}};
 }

UBSAN trace:
 example-reduced.cpp:10:2: runtime error: constructor call on address
0x7fffcaf56e90 with insufficient space for an object of type 'A'
 0x7fffcaf56e90: note: pointer points here
  18 56 00 00  90 6f f5 ca ff 7f 00 00  00 42 f4 a4 41 d6 f1 ba  00 00 00 00 00
00 00 00  25 9b cf be
               ^ 
     #0 0x56188f444f5c in main example-reduced.cpp:10:2
     #1 0x7fcbbecf9b24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)
     #2 0x56188f36619d in _start (a.out+0x2019d)

 SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
example-reduced.cpp:10:2 in 

Notes:
 - This error does not occur when compiling with `-O0` which leads me to
believe that this is an optimizer regression
 - GCC does not seem to exhibit the issue at any optimization level</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>