Skip to contentSkip to conversation

KVM: x86: fix clang build

PATCH In review Radim Krčmář 2 participants 2 messages Sep 13, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: x86: fix clang build

Clang resolves __builtin_constant_p() to false even if the expression is constant in the end. The only purpose of that expression was to differentiate a case where the following expression couldn't be checked at compile-time, so we can just remove the check.

Clang handles the following two correctly. Turn it into BUG_ON if there are any more problems with this.

Fixes d6321d493319 ("KVM: x86: generalize guest_cpuid_has_ helpers")
---
 arch/x86/kvm/cpuid.h | 1 -
 1 file changed, 1 deletion(-)
arch/x86/kvm/cpuid.h +0 -1
index 1ea3c0e1e3a9..0bc5c1315708 100644
@@ -59,7 +59,6 @@ static __always_inline struct cpuid_reg x86_feature_cpuid(unsigned x86_feature)
 {
 	unsigned x86_leaf = x86_feature / 32;
 
-	BUILD_BUG_ON(!__builtin_constant_p(x86_leaf));
 	BUILD_BUG_ON(x86_leaf >= ARRAY_SIZE(reverse_cpuid));
 	BUILD_BUG_ON(reverse_cpuid[x86_leaf].function == 0);
 
Signature · 1 line
2.14.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · Radim Krčmář

Clang resolves __builtin_constant_p() to false even if the expression is constant in the end. The only purpose of that expression was to differentiate a case where the following expression couldn't be checked at compile-time, so we can just remove the check.

Clang handles the following two correctly. Turn it into BUG_ON if there are any more problems with this.

Fixes d6321d493319 ("KVM: x86: generalize guest_cpuid_has_ helpers")
---
 arch/x86/kvm/cpuid.h | 1 -
 1 file changed, 1 deletion(-)
arch/x86/kvm/cpuid.h +0 -0
index 1ea3c0e1e3a9..0bc5c1315708 100644

arch/x86/kvm/cpuid.h static __always_inline struct cpuid_reg x86_feature_cpuid(unsigned x86_feature) · line 64

Quoted 7 lines
arch/x86/kvm/cpuid.h +0 -1
@@ -59,7 +59,6 @@ static __always_inline struct cpuid_reg x86_feature_cpuid(unsigned x86_feature)
 {
 	unsigned x86_leaf = x86_feature / 32;
 
-	BUILD_BUG_ON(!__builtin_constant_p(x86_leaf));
 	BUILD_BUG_ON(x86_leaf >= ARRAY_SIZE(reverse_cpuid));
 	BUILD_BUG_ON(reverse_cpuid[x86_leaf].function == 0);
 
Signature · 3 lines
Thanks,

David