diff options
| author | Luca Barbato <lu_zero@gentoo.org> | 2017-07-28 02:03:23 +0000 |
|---|---|---|
| committer | Luca Barbato <lu_zero@gentoo.org> | 2017-07-28 14:30:06 +0000 |
| commit | c4710203c098b68b5f80b1507e889ad894855729 (patch) | |
| tree | 71052bd4843b612179d9dde9c167e7c1c59a01c9 | |
| parent | cbce0aa341c8be3f4b9253c93ed641ed454fc0a0 (diff) | |
| download | rust-c4710203c098b68b5f80b1507e889ad894855729.tar.gz rust-c4710203c098b68b5f80b1507e889ad894855729.zip | |
Make LLVMRustHasFeature more robust
The function should accept feature strings that old LLVM might not support. Simplify the code using the same approach used by LLVMRustPrintTargetFeatures. Dummify the function for non 4.0 LLVM and update the tests accordingly.
| -rw-r--r-- | src/rustllvm/PassWrapper.cpp | 20 | ||||
| -rw-r--r-- | src/test/run-make/print-cfg/Makefile | 2 | ||||
| -rw-r--r-- | src/test/run-pass/sse2.rs | 1 |
3 files changed, 9 insertions, 14 deletions
diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp index 7fb1eafb30d..57e90be2774 100644 --- a/src/rustllvm/PassWrapper.cpp +++ b/src/rustllvm/PassWrapper.cpp @@ -181,20 +181,14 @@ extern "C" bool LLVMRustHasFeature(LLVMTargetMachineRef TM, TargetMachine *Target = unwrap(TM); const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo(); const FeatureBitset &Bits = MCInfo->getFeatureBits(); - const llvm::SubtargetFeatureKV *FeatureEntry; - -#define SUBTARGET(x) \ - if (MCInfo->isCPUStringValid(x##SubTypeKV[0].Key)) { \ - FeatureEntry = x##FeatureKV; \ - } else - - GEN_SUBTARGETS { return false; } -#undef SUBTARGET - - while (strcmp(Feature, FeatureEntry->Key) != 0) - FeatureEntry++; +#if LLVM_VERSION_GE(4, 0) + const ArrayRef<SubtargetFeatureKV> FeatTable = MCInfo->getFeatureTable(); - return (Bits & FeatureEntry->Value) == FeatureEntry->Value; + for (auto &FeatureEntry : FeatTable) + if (!strcmp(FeatureEntry.Key, Feature)) + return (Bits & FeatureEntry.Value) == FeatureEntry.Value; +#endif + return false; } enum class LLVMRustCodeModel { diff --git a/src/test/run-make/print-cfg/Makefile b/src/test/run-make/print-cfg/Makefile index a820a463f4a..82fa3f6a3c5 100644 --- a/src/test/run-make/print-cfg/Makefile +++ b/src/test/run-make/print-cfg/Makefile @@ -5,7 +5,7 @@ all: default $(RUSTC) --target x86_64-pc-windows-gnu --print cfg | grep x86_64 $(RUSTC) --target i686-pc-windows-msvc --print cfg | grep msvc $(RUSTC) --target i686-apple-darwin --print cfg | grep macos - $(RUSTC) --target i686-unknown-linux-gnu --print cfg | grep sse2 + $(RUSTC) --target i686-unknown-linux-gnu --print cfg | grep gnu ifdef IS_WINDOWS default: diff --git a/src/test/run-pass/sse2.rs b/src/test/run-pass/sse2.rs index 8d88c17af79..c27f83011cb 100644 --- a/src/test/run-pass/sse2.rs +++ b/src/test/run-pass/sse2.rs @@ -7,6 +7,7 @@ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. +// min-llvm-version 4.0 #![feature(cfg_target_feature)] |
