[llvm-bugs] [Bug 51282] New: Type deduction loses alignment

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jul 30 07:31:27 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51282

            Bug ID: 51282
           Summary: Type deduction loses alignment
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: erich.keane at intel.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Example: 
https://godbolt.org/z/q7W5csMnc

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210730/7725c476/attachment.html>


More information about the llvm-bugs mailing list