r346265 - [MS] Zero out ECX in __cpuid in intrin.h
Reid Kleckner via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 6 12:45:26 PST 2018
Author: rnk
Date: Tue Nov 6 12:45:26 2018
New Revision: 346265
URL: http://llvm.org/viewvc/llvm-project?rev=346265&view=rev
Log:
[MS] Zero out ECX in __cpuid in intrin.h
Summary:
Some CPUID leafs depend on the value of ECX as well as EAX, but we left
it uninitialized.
Originally reported as https://crbug.com/901547
Reviewers: craig.topper, hans
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D54171
Added:
cfe/trunk/test/CodeGen/ms-intrinsics-cpuid.c
Modified:
cfe/trunk/lib/Headers/intrin.h
Modified: cfe/trunk/lib/Headers/intrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/intrin.h?rev=346265&r1=346264&r2=346265&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/intrin.h (original)
+++ cfe/trunk/lib/Headers/intrin.h Tue Nov 6 12:45:26 2018
@@ -535,7 +535,7 @@ __stosq(unsigned __int64 *__dst, unsigne
static __inline__ void __DEFAULT_FN_ATTRS
__cpuid(int __info[4], int __level) {
__asm__ ("cpuid" : "=a"(__info[0]), "=b" (__info[1]), "=c"(__info[2]), "=d"(__info[3])
- : "a"(__level));
+ : "a"(__level), "c"(0));
}
static __inline__ void __DEFAULT_FN_ATTRS
__cpuidex(int __info[4], int __level, int __ecx) {
Added: cfe/trunk/test/CodeGen/ms-intrinsics-cpuid.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms-intrinsics-cpuid.c?rev=346265&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/ms-intrinsics-cpuid.c (added)
+++ cfe/trunk/test/CodeGen/ms-intrinsics-cpuid.c Tue Nov 6 12:45:26 2018
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \
+// RUN: -triple i686-windows-msvc -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \
+// RUN: -triple x86_64-windows-msvc -emit-llvm %s -o - | FileCheck %s
+
+// intrin.h needs size_t, but -ffreestanding prevents us from getting it from
+// stddef.h. Work around it with this typedef.
+typedef __SIZE_TYPE__ size_t;
+
+#include <intrin.h>
+
+void test__cpuid(int *info, int level) {
+ __cpuid(info, level);
+}
+// CHECK-LABEL: define {{.*}} @test__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)
More information about the cfe-commits
mailing list