Skip to content

Commit c471020

Browse files
committed
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.
1 parent cbce0aa commit c471020

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

src/rustllvm/PassWrapper.cpp

+7-13
Original file line numberDiff line numberDiff line change
@@ -181,20 +181,14 @@ extern "C" bool LLVMRustHasFeature(LLVMTargetMachineRef TM,
181181
TargetMachine *Target = unwrap(TM);
182182
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
183183
const FeatureBitset &Bits = MCInfo->getFeatureBits();
184-
const llvm::SubtargetFeatureKV *FeatureEntry;
185-
186-
#define SUBTARGET(x) \
187-
if (MCInfo->isCPUStringValid(x##SubTypeKV[0].Key)) { \
188-
FeatureEntry = x##FeatureKV; \
189-
} else
190-
191-
GEN_SUBTARGETS { return false; }
192-
#undef SUBTARGET
193-
194-
while (strcmp(Feature, FeatureEntry->Key) != 0)
195-
FeatureEntry++;
184+
#if LLVM_VERSION_GE(4, 0)
185+
const ArrayRef<SubtargetFeatureKV> FeatTable = MCInfo->getFeatureTable();
196186

197-
return (Bits & FeatureEntry->Value) == FeatureEntry->Value;
187+
for (auto &FeatureEntry : FeatTable)
188+
if (!strcmp(FeatureEntry.Key, Feature))
189+
return (Bits & FeatureEntry.Value) == FeatureEntry.Value;
190+
#endif
191+
return false;
198192
}
199193

200194
enum class LLVMRustCodeModel {

src/test/run-make/print-cfg/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ all: default
55
$(RUSTC) --target x86_64-pc-windows-gnu --print cfg | grep x86_64
66
$(RUSTC) --target i686-pc-windows-msvc --print cfg | grep msvc
77
$(RUSTC) --target i686-apple-darwin --print cfg | grep macos
8-
$(RUSTC) --target i686-unknown-linux-gnu --print cfg | grep sse2
8+
$(RUSTC) --target i686-unknown-linux-gnu --print cfg | grep gnu
99

1010
ifdef IS_WINDOWS
1111
default:

src/test/run-pass/sse2.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
10+
// min-llvm-version 4.0
1011

1112
#![feature(cfg_target_feature)]
1213

0 commit comments

Comments
 (0)