[PATCH] D101338: [MS] Fix crash when calling __cpuid with /EHsc and -mavx2

Pengfei Wang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 26 19:51:16 PDT 2021


pengfei created this revision.
pengfei added reviewers: rnk, craig.topper, hans.
pengfei requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a workaround for PR50133.

When we do frame lowering for some complex scenarios, we may use RBX/EBX
register as frame pointer register, which may happen to be clobbered by
inline asm, e.g. __cpuid. Stopping to inline them is a workaround for
these cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101338

Files:
  clang/lib/Headers/intrin.h
  clang/test/CodeGen/ms-intrinsics-cpuid.c


Index: clang/test/CodeGen/ms-intrinsics-cpuid.c
===================================================================
--- clang/test/CodeGen/ms-intrinsics-cpuid.c
+++ clang/test/CodeGen/ms-intrinsics-cpuid.c
@@ -9,10 +9,12 @@
 
 #include <intrin.h>
 
-void test__cpuid(int *info, int level) {
-  __cpuid(info, level);
-}
-// CHECK-LABEL: define {{.*}} @test__cpuid(i32* %{{.*}}, i32 %{{.*}})
+// CHECK-LABEL: define {{.*}} @__cpuid(i32* %{{.*}}, i32 %{{.*}})
 // CHECK: call { i32, i32, i32, i32 } asm "cpuid",
 // CHECK-SAME:   "={ax},={bx},={cx},={dx},{ax},{cx},~{dirflag},~{fpsr},~{flags}"
 // CHECK-SAME:   (i32 %{{.*}}, i32 0)
+
+// CHECK-LABEL: define {{.*}} @__cpuidex(i32* %{{.*}}, i32 %{{.*}}, i32 %{{.*}})
+// CHECK: call { i32, i32, i32, i32 } asm "cpuid",
+// CHECK-SAME:   "={ax},={bx},={cx},={dx},{ax},{cx},~{dirflag},~{fpsr},~{flags}"
+// CHECK-SAME:   (i32 %{{.*}}, i32 %{{.*}})
Index: clang/lib/Headers/intrin.h
===================================================================
--- clang/lib/Headers/intrin.h
+++ clang/lib/Headers/intrin.h
@@ -507,12 +507,12 @@
 |* Misc
 \*----------------------------------------------------------------------------*/
 #if defined(__i386__) || defined(__x86_64__)
-static __inline__ void __DEFAULT_FN_ATTRS __cpuid(int __info[4], int __level) {
+static void __attribute__((noinline, __nodebug__)) __cpuid(int __info[4], int __level) {
   __asm__("cpuid"
           : "=a"(__info[0]), "=b"(__info[1]), "=c"(__info[2]), "=d"(__info[3])
           : "a"(__level), "c"(0));
 }
-static __inline__ void __DEFAULT_FN_ATTRS __cpuidex(int __info[4], int __level,
+static void __attribute__((noinline, __nodebug__)) __cpuidex(int __info[4], int __level,
                                                     int __ecx) {
   __asm__("cpuid"
           : "=a"(__info[0]), "=b"(__info[1]), "=c"(__info[2]), "=d"(__info[3])


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101338.340714.patch
Type: text/x-patch
Size: 1861 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210427/9f0a1269/attachment.bin>


More information about the cfe-commits mailing list