diff options
| author | Reid Kleckner <rnk@google.com> | 2018-11-06 20:45:26 +0000 |
|---|---|---|
| committer | Reid Kleckner <rnk@google.com> | 2018-11-06 20:45:26 +0000 |
| commit | 902fa411888e5c23c2a9ff7038947e5c5ee98c4e (patch) | |
| tree | d185b9518d9bc56d29b151b094c48cf54698516a | |
| parent | b23fded9017b3527642f60a1473f78a5098a2dce (diff) | |
| download | bcm5719-llvm-902fa411888e5c23c2a9ff7038947e5c5ee98c4e.tar.gz bcm5719-llvm-902fa411888e5c23c2a9ff7038947e5c5ee98c4e.zip | |
[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
llvm-svn: 346265
| -rw-r--r-- | clang/lib/Headers/intrin.h | 2 | ||||
| -rw-r--r-- | clang/test/CodeGen/ms-intrinsics-cpuid.c | 18 |
2 files changed, 19 insertions, 1 deletions
diff --git a/clang/lib/Headers/intrin.h b/clang/lib/Headers/intrin.h index c2517e03b8b..e872ef10a9c 100644 --- a/clang/lib/Headers/intrin.h +++ b/clang/lib/Headers/intrin.h @@ -535,7 +535,7 @@ __stosq(unsigned __int64 *__dst, unsigned __int64 __x, size_t __n) { 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) { diff --git a/clang/test/CodeGen/ms-intrinsics-cpuid.c b/clang/test/CodeGen/ms-intrinsics-cpuid.c new file mode 100644 index 00000000000..e6666c86e68 --- /dev/null +++ b/clang/test/CodeGen/ms-intrinsics-cpuid.c @@ -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) |

