IRGen: Sort the target-features string

Function merging will not identify two otherwise equivalent if the order of the target-features list differs.

rdar://33057710
This commit is contained in:
Arnold Schwaighofer
2017-06-30 10:25:53 -07:00
parent 1803c04bf9
commit 1e794cdebf
2 changed files with 10 additions and 0 deletions

View File

@@ -817,6 +817,8 @@ llvm::AttributeSet IRGenModule::constructInitialAttributes() {
std::vector<std::string> &Features = ClangOpts.Features;
if (!Features.empty()) {
SmallString<64> allFeatures;
// Sort so that the target features string is canonical.
std::sort(Features.begin(), Features.end());
interleave(Features, [&](const std::string &s) {
allFeatures.append(s);
}, [&]{

View File

@@ -2,6 +2,7 @@
// RUN: %swift -target i386-apple-ios7.1 %s -module-name main -emit-ir -o - | %FileCheck %s
// RUN: %swift -target x86_64-apple-ios7.1 %s -module-name main -emit-ir -o - | %FileCheck %s
// RUN: %swift -target x86_64-unknown-linux-gnu -disable-objc-interop %s -module-name main -emit-ir -o - | %FileCheck %s
// RUN: %swift -target x86_64-apple-macosx10.9 -module-name main %s -emit-ir -o - | %FileCheck %s --check-prefix=X86_64
// REQUIRES: CODEGENERATOR=X86
@@ -34,3 +35,10 @@ bb0:
// CHECK: define{{( protected)?}} swiftcc void @foo
// CHECK: define{{( protected)?}} swiftcc void @bar
// CHECK: define{{( protected)?}} swiftcc void @baz
// Make sure that the target features are ordered. We care because function
// merging does not identify two otherwise identical functions as the same if
// the order of features differs.
// X86_64: define{{( protected)?}} swiftcc void @baz{{.*}}#0
// X86_64: #0 = {{.*}}"target-features"="+cx16,+fxsr,+mmx,+sse,+sse2,+sse3,+ssse3,+x87"