<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 - Type deduction loses alignment"
   href="https://bugs.llvm.org/show_bug.cgi?id=51282">51282</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Type deduction loses alignment
          </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>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>erich.keane@intel.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>Example: 
<a href="https://godbolt.org/z/q7W5csMnc">https://godbolt.org/z/q7W5csMnc</a>

typedef signed char int8x8_t __attribute__ ((aligned(16)));                     

int8x8_t foo();            
void baz(const int8x8_t &a);                                                    

void bar()                                                                      
{                                                                               
  const int8x8_t a = foo();                                                     
  baz(a);
  alignas(16) const auto b = foo();  
  baz(b);
}    


The warning is:
<source>:11:7: warning: passing 1-byte aligned argument to 16-byte aligned
parameter 1 of 'baz' may result in an unaligned pointer access
[-Walign-mismatch]
  baz(b);

I debugged this down to the beginning of
SemaTemplateDeduction.cpp::DeduceTemplateArgumentsByTypeMatch.  The
S.Context.getCanonicalType(ArgIn) line loses the typedef (which seems
intentional, based on the comment above it).

However, this also loses the alignment attached to the typedef.

Note that the 'alignas' is also lost, but is not necessarily part of this
example.  With/without it, we still get the warning because 'b' doesn't pick up
the alignment.

I would think about just fixing up the alignment in
DeduceTemplateArgumentsByTypeMismatch, but I suspect there needs to be a bigger
holistic approach to this.</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>