diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp index b936bf123ec..83e72c05908 100644 --- a/lib/IRGen/IRGenModule.cpp +++ b/lib/IRGen/IRGenModule.cpp @@ -817,6 +817,8 @@ llvm::AttributeSet IRGenModule::constructInitialAttributes() { std::vector &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); }, [&]{ diff --git a/test/IRGen/ordering_x86.sil b/test/IRGen/ordering_x86.sil index ddae69d4a0f..c83e803db77 100644 --- a/test/IRGen/ordering_x86.sil +++ b/test/IRGen/ordering_x86.sil @@ -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"