Index: clang/lib/Driver/ToolChains/AMDGPU.h =================================================================== --- clang/lib/Driver/ToolChains/AMDGPU.h +++ clang/lib/Driver/ToolChains/AMDGPU.h @@ -121,6 +121,9 @@ /// Get GPU arch from -mcpu without checking. StringRef getGPUArch(const llvm::opt::ArgList &DriverArgs) const; + /// Common warning options shared by AMDGPU HIP, OpenCL and OpenMP toolchains. + /// Language specific warning options should go to derived classes. + void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override; }; class LLVM_LIBRARY_VISIBILITY ROCMToolChain : public AMDGPUToolChain { Index: clang/lib/Driver/ToolChains/AMDGPU.cpp =================================================================== --- clang/lib/Driver/ToolChains/AMDGPU.cpp +++ clang/lib/Driver/ToolChains/AMDGPU.cpp @@ -721,6 +721,12 @@ } } +void AMDGPUToolChain::addClangWarningOptions(ArgStringList &CC1Args) const { + // AMDGPU does not support atomic lib call. Treat atomic alignment + // warnings as errors. + CC1Args.push_back("-Werror=atomic-alignment"); +} + StringRef AMDGPUToolChain::getGPUArch(const llvm::opt::ArgList &DriverArgs) const { return getProcessorFromTargetID( Index: clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp =================================================================== --- clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp +++ clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp @@ -118,6 +118,7 @@ void AMDGPUOpenMPToolChain::addClangWarningOptions( ArgStringList &CC1Args) const { + AMDGPUToolChain::addClangWarningOptions(CC1Args); HostTC.addClangWarningOptions(CC1Args); } Index: clang/lib/Driver/ToolChains/HIPAMD.cpp =================================================================== --- clang/lib/Driver/ToolChains/HIPAMD.cpp +++ clang/lib/Driver/ToolChains/HIPAMD.cpp @@ -291,6 +291,7 @@ } void HIPAMDToolChain::addClangWarningOptions(ArgStringList &CC1Args) const { + AMDGPUToolChain::addClangWarningOptions(CC1Args); HostTC.addClangWarningOptions(CC1Args); } Index: clang/test/Driver/amdgpu-openmp-toolchain.c =================================================================== --- clang/test/Driver/amdgpu-openmp-toolchain.c +++ clang/test/Driver/amdgpu-openmp-toolchain.c @@ -62,3 +62,7 @@ // RUN: --rocm-device-lib-path=%S/Inputs/rocm/amdgcn/bitcode -fopenmp-new-driver %s 2>&1 | \ // RUN: FileCheck %s --check-prefix=CHECK-LIB-DEVICE-NOGPULIB // CHECK-LIB-DEVICE-NOGPULIB-NOT: "-cc1" {{.*}}ocml.bc"{{.*}}ockl.bc"{{.*}}oclc_daz_opt_on.bc"{{.*}}oclc_unsafe_math_off.bc"{{.*}}oclc_finite_only_off.bc"{{.*}}oclc_correctly_rounded_sqrt_on.bc"{{.*}}oclc_wavefrontsize64_on.bc"{{.*}}oclc_isa_version_803.bc" + +// RUN: %clang -### --target=x86_64-unknown-linux-gnu -emit-llvm -S -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx803 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-WARN-ATOMIC +// CHECK-WARN-ATOMIC-NOT: "-cc1" "-triple" "x86_64-unknown-linux-gnu"{{.*}}"-Werror=atomic-alignment" +// CHECK-WARN-ATOMIC: "-cc1" "-triple" "amdgcn-amd-amdhsa"{{.*}}"-Werror=atomic-alignment" Index: clang/test/Driver/amdgpu-toolchain-opencl.cl =================================================================== --- clang/test/Driver/amdgpu-toolchain-opencl.cl +++ clang/test/Driver/amdgpu-toolchain-opencl.cl @@ -28,3 +28,6 @@ // RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -emit-llvm -mcpu=fiji %s 2>&1 | FileCheck -check-prefix=CHK-LINK %s // CHK-LINK: ld.lld{{.*}} "--no-undefined" "-shared" + +// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji %s 2>&1 | FileCheck -check-prefix=CHECK-WARN-ATOMIC %s +// CHECK-WARN-ATOMIC: "-cc1"{{.*}} "-Werror=atomic-alignment" Index: clang/test/Driver/hip-options.hip =================================================================== --- clang/test/Driver/hip-options.hip +++ clang/test/Driver/hip-options.hip @@ -138,3 +138,10 @@ // RUN: %clang -### -nogpuinc -nogpulib -mamdgpu-ieee -mno-amdgpu-ieee -ffast-math \ // RUN: --cuda-gpu-arch=gfx906 %s 2>&1 | FileCheck -check-prefixes=IEEE-OFF-NEG %s // IEEE-OFF-NEG-NOT: clang{{.*}} "-triple" "amdgcn-amd-amdhsa" {{.*}} "-mamdgpu-ieee" + +// Check -Werror=atomic-alignment is passed for amdpu by default. + +// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib \ +// RUN: --cuda-gpu-arch=gfx906 %s 2>&1 | FileCheck -check-prefix=WARN-ATOMIC %s +// WARN-ATOMIC: clang{{.*}} "-triple" "amdgcn-amd-amdhsa" {{.*}} "-Werror=atomic-alignment" +// WARN-ATOMIC-NOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-Werror=atomic-alignment"