Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang crashes on the aws-crt-python project #57888

Open
yurivict opened this issue Sep 21, 2022 · 3 comments
Open

clang crashes on the aws-crt-python project #57888

yurivict opened this issue Sep 21, 2022 · 3 comments
Labels
backend:X86 crash Prefer [crash-on-valid] or [crash-on-invalid] llvm:asmparser

Comments

@yurivict
Copy link

Project: https://github.com/awslabs/aws-crt-python
OS: FreeBSD 14-CURRENT

clang-crash.tgz

@MaskRay
Copy link
Member

MaskRay commented Sep 22, 2022

In aws_checksums_crc32c_hw, __asm__("loop_small_%=: CRC32B (%[in]), %[crc]" : "+c"(crc) : [ crc ] "c"(crc), [ in ] "r"(input));
causes TwoAddressInstructionPass.cpp:1493 to trigger an assertion failure.

DstIdx == 3 (killed %107:gr32(tied-def 3))
i == 5
MI->getOperand(3).getReg() == MI->getOperand(5).getReg() 

INLINEASM &"loop_small_${:uid}: CRC32B ($2), $1" [attdialect], $0:[regdef], implicit-def $ecx, $1:[reguse], killed $ecx, $2:[reguse:GR64], killed %106:gr64, $3:[reguse tiedto:$0], killed %107:gr32(tied-def 3), $4:[clobber], implicit-def dead early-clobber $df, $5:[clobber], implicit-def early-clobber $fpsw, $6:[clobber], implicit-def dead early-clobber $eflags, !8

Still investigating.


The : "+c"(crc) : [crc]"+c"(crc) pattern is suspicious. The following patch helps a bit, but Clang still crashes in one INLINEASM instruction.

@@ -6669 +6670 @@
-        : "+c"(crc)
+        : [crc]"+c"(crc)
@@ -6672 +6673 @@
-        : [ crc ] "c"(crc), [ in ] "d"(input)
+        : [ in ] "d"(input)
@@ -6755 +6756 @@
-        : "+c"(crc), "+d"(input)
+        : [crc]"+c"(crc), "+d"(input)
@@ -6759 +6760 @@
-        : [ crc ] "c"(crc), [ in ] "d"(input)
+        : [ in ] "d"(input)
@@ -6835 +6836 @@
-        : "+c"(crc), "+d"(input)
+        : [crc]"+c"(crc), "+d"(input)
@@ -6839 +6840 @@
-        : [ crc ] "c"(crc), [ in ] "d"(input)
+        : [ in ] "d"(input)
@@ -6871,0 +6873 @@
+      uint32_t crc1 = 0;
@@ -6873 +6875 @@
-            __asm__("loop_small_%=: CRC32B (%[in]), %[crc]" : "+c"(crc) : [ crc ] "c"(crc), [ in ] "r"(input));
+            __asm__("loop_small_%=: CRC32B (%[in]), %[crc]" : [crc] "+c"(crc) : [ in ] "r"(input));
@@ -6890 +6892 @@
-        __asm__("loop_leading_%=: CRC32B (%[in]), %[crc]" : "+c"(crc) : [ crc ] "c"(crc), [ in ] "r"(input));
+        __asm__("loop_leading_%=: CRC32B (%[in]), %[crc]" : [ crc ] "+c"(crc) : [ in ] "r"(input));
@@ -6920 +6922 @@
-        __asm__ __volatile__("loop_8_%=: CRC32Q (%[in]), %%rcx" : "+c"(crc) : [ crc ] "c"(crc), [ in ] "r"(input));
+        __asm__ __volatile__("loop_8_%=: CRC32Q (%[in]), %%rcx" : [crc]"+c"(crc) : [ in ] "r"(input));
@@ -6928,2 +6930 @@
-                             : "+c"(crc)
-                             : [ crc ] "c"(crc), [ in ] "r"(input));
+                             : [crc]"+c"(crc) : [ in ] "r"(input));

@DimitryAndric
Copy link
Collaborator

There are a lot of duplicates of this bug, and it's always some Amazon AWS code, e.g.:

I think AWS is using some common CRC inline assembly that causes either assertions or backend errors with clang. Probably some impossible register constraint, which instead of generating a normal diagnostic causes an assertion failure or backend failure...

@Endilll Endilll added backend:X86 llvm:asmparser crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Sep 29, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 29, 2023

@llvm/issue-subscribers-backend-x86

Project: https://github.com/awslabs/aws-crt-python OS: FreeBSD 14-CURRENT

clang-crash.tgz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 crash Prefer [crash-on-valid] or [crash-on-invalid] llvm:asmparser
Projects
None yet
Development

No branches or pull requests

5 participants