Clang error: unknown target CPU 'A' (err_target_unknown_cpu)

From emmtrix Wiki
Jump to navigation Jump to search
Text error: unknown target CPU 'A'
Type Error
Category None
Internal Id err_target_unknown_cpu
Internal Message unknown target CPU '%0'
Regular Expression (?:error|fatal error)\: unknown target CPU '(.*?)'
First Commit 2009-12-18 acde99ea522d ARM: Fix predefines (__ARM_ARCH_..., __REGISTER_PREFIX).

Description

The error is issued by the Clang compiler when it encounters a specified target CPU that is unrecognized or unsupported. This can occur in scenarios where the compiler is instructed to compile code for a specific processor architecture using the target CPU option, but the name provided does not match any of the CPUs known to Clang. It is usually triggered by a mistake in specifying the CPU name or targeting a CPU that Clang does not support.

In the context of cross-compilation or when optimizing code for a specific processor, specifying the correct target CPU is critical for generating optimized machine code that takes advantage of the specific features and instruction sets of the processor. If the target CPU is misspelled, incorrectly identified, or not supported by the current version of Clang being used, Clang will not be able to proceed with the generation of optimized code for that target and will halt compilation with this error.

This error serves as a notification to the developer that the compiler lacks the necessary information or capability to generate code optimized for the specified CPU and invites the developer to correct the target CPU specification. It might also encourage verifying that the compiler version in use supports the intended target processor.

 
AI Generated

Example

In the following example, the Clang compiler issues an error message because an attempt is made to compile code for the ARMv8-A architecture with the specific +nosve modifier, indicating a request to utilize the Scalable Vector Extension (SVE) feature. However, the specified target CPU 'armv8-a+nosve' is unrecognized or unsupported by the compiler. This leads to an error indicating that the CPU target is unknown. The compiler also provides a note listing valid target CPU values, which are recognized and supported configurations. This list aims to help identify the correct or alternative CPU specifications that could be used. The example demonstrates the importance of specifying valid and supported target CPUs when compiling code to ensure that the compiler can generate the appropriate machine code.  
AI Generated


Flags -xc -march=armv8-a+nosve

[Try out in Compiler Explorer]

Source
void f(__SVInt8_t v) {} // Used an SVE data type but the target CPU doesn't support SVE
Compiler Output
error: unknown target CPU 'armv8-a+nosve'
note: valid target CPU values are: nocona, core2, penryn, bonnell, atom, silvermont, slm, goldmont, goldmont-plus, tremont, nehalem, corei7, westmere, sandybridge, corei7-avx, ivybridge, core-avx-i, haswell, core-avx2, broadwell, skylake, skylake-avx512, skx, cascadelake, cooperlake, cannonlake, icelake-client, rocketlake, icelake-server, tigerlake, sapphirerapids, alderlake, raptorlake, meteorlake, sierraforest, grandridge, graniterapids, graniterapids-d, emeraldrapids, knl, knm, k8, athlon64, athlon-fx, opteron, k8-sse3, athlon64-sse3, opteron-sse3, amdfam10, barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, znver2, znver3, znver4, x86-64, x86-64-v2, x86-64-v3, x86-64-v4


Clang Internals (17.0.6)

Git Commit Message

ARM: Fix predefines (__ARM_ARCH_..., __REGISTER_PREFIX).
 - This should be done leveraging the backend, but I'm a little refactored
   out. I'll fix it one day, I promise.

llvm-svn: 91700

Used in Clang Sources

This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.

clang/lib/Basic/Targets.cpp (line 787)

/// CreateTargetInfo - Return the target info object for the specified target
/// options.
TargetInfo *TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags, const std::shared_ptr<TargetOptions> &Opts) {
  // ...
  // Set the target CPU if specified.
  if (!Opts->CPU.empty() && !Target->setCPU(Opts->CPU)) {
    Diags.Report(diag::err_target_unknown_cpu) << Opts->CPU;

clang/lib/Basic/Targets.cpp (line 798)

/// CreateTargetInfo - Return the target info object for the specified target
/// options.
TargetInfo *TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags, const std::shared_ptr<TargetOptions> &Opts) {
  // ...
  // Check the TuneCPU name if specified.
  if (!Opts->TuneCPU.empty() && !Target->isValidTuneCPUName(Opts->TuneCPU)) {
    Diags.Report(diag::err_target_unknown_cpu) << Opts->TuneCPU;

Triggered in Clang Tests

This section lists all internal Clang test cases that trigger the diagnostic.

clang/test/Preprocessor/predefined-arch-macros.c

  • error: unknown target CPU 'amdgcn'