<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/54606>54606</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [JITLink][MachO] crash on x86_64 due to possible C-string literal misalignment
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ilian8
      </td>
    </tr>
</table>

<pre>
    Please consider the following LLVM IR (also attached as a [text file](https://github.com/llvm/llvm-project/files/8367667/cstring_bug.ll.txt))

```
@.str = private unnamed_addr constant [18 x i8] c"The result is %s\0A\00", align 1
@.str.1 = private unnamed_addr constant [17 x i8] c"abcdefghijklmnop\00", align 16

define dso_local i32 @main() local_unnamed_addr #0 {
  %1 = tail call noalias align 16 dereferenceable_or_null(17) i8* @malloc(i64 17) #5
  tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* noundef nonnull align 16 dereferenceable(17) %1, i8* noundef nonnull align 16 dereferenceable(17) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i64 17, i1 false) #5
  %2 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %1)
  tail call void @free(i8* %1) #5
  ret i32 0
}

declare dso_local noalias noundef align 16 i8* @malloc(i64 noundef) local_unnamed_addr #1

declare dso_local noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #2

declare dso_local void @free(i8* nocapture noundef) local_unnamed_addr #3

declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg) #4

attributes #0 = { mustprogress norecurse nounwind uwtable "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+avx,+avx2,+cx8,+fxsr,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave" "tune-cpu"="generic" }
attributes #1 = { inaccessiblememonly mustprogress nofree nounwind willreturn "frame-pointer"="none" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+avx,+avx2,+cx8,+fxsr,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave" "tune-cpu"="generic" }
attributes #2 = { nofree nounwind "frame-pointer"="none" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+avx,+avx2,+cx8,+fxsr,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave" "tune-cpu"="generic" }
attributes #3 = { inaccessiblemem_or_argmemonly mustprogress nounwind willreturn "frame-pointer"="none" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+avx,+avx2,+cx8,+fxsr,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave" "tune-cpu"="generic" }
attributes #4 = { argmemonly nofree nounwind willreturn }
attributes #5 = { nounwind }
attributes #5 = { nounwind }
```
This works fine on macOS
```
> llc -filetype=obj cstring_bug.ll
> clang -o cstring_bug cstring_bug.o
> ./cstring_bug
The result is abcdefghijklmnop
```
however executing via `llvm-jitlink` crashes
```
> llvm-jitlink cstring_bug.o
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
```
with a stack trace similar to
```
(lldb) run
Process 12435 launched: '/Users/iliang/bin/llvm-jitlink' (x86_64)
Process 12435 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
    frame #0: 0x000000010060300e
->  0x10060300e: vmovaps 0xffc(%rip), %xmm0
    0x100603016: vmovaps %xmm0, (%rax)
    0x10060301a: movb   $0x0, 0x10(%rax)
    0x10060301e: leaq   0xfdb(%rip), %rdi
```
where the alignment of the `vmovaps` operand is incorrect.

Possibly related to commit f9649d123db64e38bce7bcb4cc5791239820f3e2 (cc: @lhames).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztWEuT4jYQ_jVwUdllbAPmwGGeqU3N1m5lJqncKFmWQTOy5JVkYPLr0y0_gBnYRyqVXHaKAWG1-vV1S_rIdfG6_Cw5tZwwrawouCFuw0mppdQ7odbk4eGPj-TDb2QUZ1RaTahzlG14QagllIym147vHSmF5KPpLQhtnKvtKLkaxffwWgu3afKQ6Qq-SLntP4La6GfOHHzFpRY-s2Q2n83mMGLWGTC9ypt1KGXo9iC2wFd0O4quuvdZ1L3ar2kUwioySm5JbcSWOk4apWjFixUtCuOjc1Q59HiSkT0RGfhL2CiOnyBew20jHREW4pza0fQGVMJbBNOj-IZQKdaKTE5shZPvtDY_sUZzVvByvRHPL7JSuj5jZnYcKAgLxUlh9UpqRiURSUzAhYoKBemGtBD_fHXiwChOIjKaX7c6CEbVuuuokATEJVEazCGInVEC2PMS_hXjNJd8pc1KNVKCkckczUAM8VVrGooDYsnELCXtHNib9rYOJrZaFLgAEQ8rXrH6NawjkbVvsBp1eK1KNwoihU-FNi86NTiDAWHK_uHyNXdc8oorV0PVCJWjAgQ_O0EMLbx54DPQ4u_tQwqio8GiH6MdGE1ICW3D3-YI3I_f4OFx7fKBS8Mw9KvSCEpMufIoV22QZ2L7dmjZ29CyM6FdDqwtAZ_7xWW8S8P54G4nfRK-4c7H23fv_Pa05Jmk5rjm-1rtcR7wPV-Tndjl3ph8y1xrpmu1d_lntHYNrOjlDKeFVvL1CLbzduOv2z2bv3fmLqtPzqn_kSbss9xb3BnheB_ZJaHj6L06X_aiqqhZd8Cnx47BCWJE3jhuu20K2gC2KlI11sGxsIa9GNUbzhpj26jhJCpIs3NY57AoLg3EHdQacOEGN88EyjeGxoC0YRfFlVCB5Gsqgy2cMtoEO1G4zSAZdWJKB87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