<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 - Wrong alignment of __declspec(align)ed structs"
   href="https://bugs.llvm.org/show_bug.cgi?id=48776">48776</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Wrong alignment of __declspec(align)ed structs
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>11.0
          </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>ju.orth@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>Consider

__declspec(align(2)) struct X {
        int a;
};

#pragma pack(1)

struct Y {
        struct X x;
};

int f(void) {
    return _Alignof(struct Y);
}

msvc returns 2, clang returns 4 on the x86_64-pc-windows-msvc target.
Presumably because of [1]. If a struct has _any_ alignment attribute, the
branch is taken and the overall alignment of the struct is considered required.
I do not know the actual behavior of msvc, but I figure that the fix is to
exclude RecordType fields from this branch because their required alignment is
already handled in [2]. This bug seems to have been introduced in [3].


[1]
<a href="https://github.com/llvm-mirror/clang/blob/aa231e4be75ac4759c236b755c57876f76e3cf05/lib/AST/RecordLayoutBuilder.cpp#L2447-L2449">https://github.com/llvm-mirror/clang/blob/aa231e4be75ac4759c236b755c57876f76e3cf05/lib/AST/RecordLayoutBuilder.cpp#L2447-L2449</a>
[2]
<a href="https://github.com/llvm-mirror/clang/blob/aa231e4be75ac4759c236b755c57876f76e3cf05/lib/AST/RecordLayoutBuilder.cpp#L2456-L2462">https://github.com/llvm-mirror/clang/blob/aa231e4be75ac4759c236b755c57876f76e3cf05/lib/AST/RecordLayoutBuilder.cpp#L2456-L2462</a>
[3] <a href="https://reviews.llvm.org/D4714">https://reviews.llvm.org/D4714</a></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>