From d86db9b1f7f83fc95844a8724aa66e4c434953b0 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Wed, 25 Apr 2018 19:14:05 +0000 Subject: [PATCH] [TargetInfo] Sort target features before passing them to the backend Passing the features in random order will lead to unpredictable results when some of the features are related (like the architecture-version features on ARM). It might be possible to fix this particular case in the ARM target code, to avoid adding overlapping target features. But we should probably be sorting in any case: the behavior shouldn't depend on StringMap's hashing algorithm. Differential Revision: https://reviews.llvm.org/D46030 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@330861 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets.cpp | 3 +++ test/CodeGen/arm-build-attributes.c | 4 ++++ 2 files changed, 7 insertions(+) create mode 100644 test/CodeGen/arm-build-attributes.c diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index e325403a1f..2e4b722b85 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -638,6 +638,9 @@ TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags, Opts->Features.clear(); for (const auto &F : Features) Opts->Features.push_back((F.getValue() ? "+" : "-") + F.getKey().str()); + // Sort here, so we handle the features in a predictable order. (This matters + // when we're dealing with features that overlap.) + llvm::sort(Opts->Features.begin(), Opts->Features.end()); if (!Target->handleTargetFeatures(Opts->Features, Diags)) return nullptr; diff --git a/test/CodeGen/arm-build-attributes.c b/test/CodeGen/arm-build-attributes.c new file mode 100644 index 0000000000..ceb97d153f --- /dev/null +++ b/test/CodeGen/arm-build-attributes.c @@ -0,0 +1,4 @@ +// RUN: %clang --target=arm-none-eabi -x c - -o - -S < %s -mcpu=cortex-a5 -mfpu=vfpv4-d16 | FileCheck %s +// REQUIRES: arm-registered-target +// CHECK: .fpu vfpv4-d16 +void foo() {} -- 2.49.0