diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 6a5f0b3b51b1f..74009cfd11463 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5747,6 +5747,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) { StringRef CM = A->getValue(); bool Ok = false; + bool Skip = false; if (Triple.isOSAIX() && CM == "medium") CM = "large"; if (Triple.isAArch64(64)) { @@ -5777,12 +5778,23 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, } else if (Triple.getArch() == llvm::Triple::x86_64) { Ok = llvm::is_contained({"small", "kernel", "medium", "large", "tiny"}, CM); - } else if (Triple.isNVPTX() || Triple.isAMDGPU()) { - // NVPTX/AMDGPU does not care about the code model and will accept + } else if (Triple.isNVPTX()) { + // NVPTX does not care about the code model and will accept // whatever works for the host. Ok = true; + } else if (Triple.isAMDGPU()) { + // AMDGPU does not care about the code model. + Ok = true; + // AMDGPU target ignores CM tiny and kernel. + if (CM == "tiny" || CM == "kernel") { + Skip = true; + D.Diag(diag::warn_ignored_clang_option) + << A->getSpelling() << CM << TripleStr; + } } - if (Ok) { + if (Skip) { + // CM option is not propogated further. + } else if (Ok) { CmdArgs.push_back(Args.MakeArgString("-mcmodel=" + CM)); } else { D.Diag(diag::err_drv_unsupported_option_argument_for_target) diff --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c index 1eb6ae16ff472..cff3b0c2d683c 100644 --- a/clang/test/Driver/mcmodel.c +++ b/clang/test/Driver/mcmodel.c @@ -15,6 +15,11 @@ // RUN: not %clang -### -c --target=aarch64 -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=ERR-MEDIUM %s // RUN: not %clang -### -c --target=aarch64 -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=ERR-KERNEL %s // RUN: not %clang --target=aarch64_32-linux -### -S -mcmodel=small %s 2>&1 | FileCheck --check-prefix=ERR-AARCH64_32 %s +// RUN: %clang --offload-arch=gfx906 -nogpulib -### -c -x hip -mcmodel=tiny %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-TINY-WARNING %s +// RUN: %clang --offload-arch=gfx906 -nogpulib -### -c -x hip -mcmodel=small %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-SMALL %s +// RUN: %clang --offload-arch=gfx906 -nogpulib -### -S -x hip -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-KERNEL-WARNING %s +// RUN: %clang --offload-arch=gfx906 -nogpulib -### -c -x hip -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-MEDIUM %s +// RUN: %clang --offload-arch=gfx906 -nogpulib -### -S -x hip -mcmodel=large %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-LARGE %s // RUN: %clang --target=loongarch64 -### -S -mcmodel=normal %s 2>&1 | FileCheck --check-prefix=SMALL %s // RUN: %clang --target=loongarch64 -### -S -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=MEDIUM %s // RUN: %clang --target=loongarch64 -### -S -mcmodel=extreme %s 2>&1 | FileCheck --check-prefix=LARGE %s @@ -41,6 +46,11 @@ // AARCH64-PIC-LARGE: error: invalid argument '-mcmodel=large' only allowed with '-fno-pic' // ERR-AARCH64_32: error: unsupported argument 'small' to option '-mcmodel=' for target 'aarch64_32-unknown-linux' +// AMDGPU-MCMODEL-TINY-WARNING: warning: the flag '-mcmodel=' has been deprecated and will be ignored +// AMDGPU-MCMODEL-SMALL: "-mcmodel=small" +// AMDGPU-MCMODEL-KERNEL-WARNING: warning: the flag '-mcmodel=' has been deprecated and will be ignored +// AMDGPU-MCMODEL-MEDIUM: "-mcmodel=medium" +// AMDGPU-MCMODEL-LARGE: "-mcmodel=large" // ERR-LOONGARCH64-PLT-LARGE: error: invalid argument '-mcmodel=large' not allowed with '-fplt' // ERR-LOONGARCH64-PLT-EXTREME: error: invalid argument '-mcmodel=extreme' not allowed with '-fplt'