Index: include/clang/Basic/DiagnosticCommonKinds.td =================================================================== --- include/clang/Basic/DiagnosticCommonKinds.td +++ include/clang/Basic/DiagnosticCommonKinds.td @@ -188,6 +188,7 @@ def err_target_unknown_triple : Error< "unknown target triple '%0', please use -triple or -arch">; def err_target_unknown_cpu : Error<"unknown target CPU '%0'">; +def note_valid_options : Note<"valid target CPU values are: %0">; def err_target_unsupported_cpu_for_micromips : Error< "micromips is not supported for target CPU '%0'">; def err_target_unknown_abi : Error<"unknown target ABI '%0'">; Index: include/clang/Basic/TargetInfo.h =================================================================== --- include/clang/Basic/TargetInfo.h +++ include/clang/Basic/TargetInfo.h @@ -867,6 +867,9 @@ return false; } + /// Fill a SmallVectorImpl with the valid values to setCPU. + virtual void fillValidCPUList(SmallVectorImpl &Values) const {} + /// brief Determine whether this TargetInfo supports the given CPU name. virtual bool isValidCPUName(StringRef Name) const { return true; Index: lib/Basic/Targets.cpp =================================================================== --- lib/Basic/Targets.cpp +++ lib/Basic/Targets.cpp @@ -38,6 +38,7 @@ #include "Targets/X86.h" #include "Targets/XCore.h" #include "clang/Basic/Diagnostic.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Triple.h" using namespace clang; @@ -607,6 +608,10 @@ // Set the target CPU if specified. if (!Opts->CPU.empty() && !Target->setCPU(Opts->CPU)) { Diags.Report(diag::err_target_unknown_cpu) << Opts->CPU; + SmallVector ValidList; + Target->fillValidCPUList(ValidList); + if (!ValidList.empty()) + Diags.Report(diag::note_valid_options) << llvm::join(ValidList, ", "); return nullptr; } Index: lib/Basic/Targets/AArch64.h =================================================================== --- lib/Basic/Targets/AArch64.h +++ lib/Basic/Targets/AArch64.h @@ -46,6 +46,7 @@ bool setABI(const std::string &Name) override; bool isValidCPUName(StringRef Name) const override; + void fillValidCPUList(SmallVectorImpl &Values) const override; bool setCPU(const std::string &Name) override; bool useFP16ConversionIntrinsics() const override { Index: lib/Basic/Targets/AArch64.cpp =================================================================== --- lib/Basic/Targets/AArch64.cpp +++ lib/Basic/Targets/AArch64.cpp @@ -101,6 +101,11 @@ return isValidCPUName(Name); } +void AArch64TargetInfo::fillValidCPUList( + SmallVectorImpl &Values) const { + llvm::AArch64::fillValidCPUArchList(Values); +} + void AArch64TargetInfo::getTargetDefinesARMV81A(const LangOptions &Opts, MacroBuilder &Builder) const { Builder.defineMacro("__ARM_FEATURE_QRDMX", "1"); Index: lib/Basic/Targets/ARM.h =================================================================== --- lib/Basic/Targets/ARM.h +++ lib/Basic/Targets/ARM.h @@ -122,6 +122,8 @@ bool hasFeature(StringRef Feature) const override; bool isValidCPUName(StringRef Name) const override; + void fillValidCPUList(SmallVectorImpl &Values) const override; + bool setCPU(const std::string &Name) override; bool setFPMath(StringRef Name) override; Index: lib/Basic/Targets/ARM.cpp =================================================================== --- lib/Basic/Targets/ARM.cpp +++ lib/Basic/Targets/ARM.cpp @@ -478,6 +478,10 @@ llvm::ARM::parseCPUArch(Name) != llvm::ARM::ArchKind::INVALID; } +void ARMTargetInfo::fillValidCPUList(SmallVectorImpl &Values) const { + llvm::ARM::fillValidCPUArchList(Values); +} + bool ARMTargetInfo::setCPU(const std::string &Name) { if (Name != "generic") setArchInfo(llvm::ARM::parseCPUArch(Name)); Index: test/Misc/target-invalid-cpu-note.c =================================================================== --- /dev/null +++ test/Misc/target-invalid-cpu-note.c @@ -0,0 +1,8 @@ +// RUN: not %clang_cc1 -triple armv5--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix ARM +// ARM: error: unknown target CPU 'not-a-cpu' +// ARM: note: valid target CPU values are: arm2, arm3, arm6, arm7m, arm8, arm810, strongarm, strongarm110, strongarm1100, strongarm1110, arm7tdmi, arm7tdmi-s, arm710t, arm720t, arm9, arm9tdmi, arm920, arm920t, arm922t, arm9312, arm940t, ep9312, arm10tdmi, arm1020t, arm9e, arm946e-s, arm966e-s, arm968e-s, arm10e, arm1020e, arm1022e, arm926ej-s, arm1136j-s, arm1136jf-s, arm1136jz-s, arm1176j-s, arm1176jz-s, mpcore, mpcorenovfp, arm1176jzf-s, arm1156t2-s, arm1156t2f-s, cortex-m0, cortex-m0plus, cortex-m1, sc000, cortex-a5, cortex-a7, cortex-a8, cortex-a9, cortex-a12, cortex-a15, cortex-a17, krait, cortex-r4, cortex-r4f, cortex-r5, cortex-r7, cortex-r8, cortex-r52, sc300, cortex-m3, cortex-m4, cortex-m7, cortex-m23, cortex-m33, cortex-a32, cortex-a35, cortex-a53, cortex-a55, cortex-a57, cortex-a72, cortex-a73, cortex-a75, cyclone, exynos-m1, exynos-m2, exynos-m3, kryo, iwmmxt, xscale, swift + +// RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix AARCH64 +// AARCH64: error: unknown target CPU 'not-a-cpu' +// AARCH64: note: valid target CPU values are: cortex-a35, cortex-a53, cortex-a55, cortex-a57, cortex-a72, cortex-a73, cortex-a75, cyclone, exynos-m1, exynos-m2, exynos-m3, falkor, saphira, kryo, thunderx2t99, thunderx, thunderxt88, thunderxt81, thunderxt83 +