Skip to content

Commit 46b6756

Browse files
authored
[AMDGPU] Diagnose unaligned atomic (#80322)
AMDGPU does not support unaligned atomics, therefore make the warning an error. This patch is transferred from https://reviews.llvm.org/D99201
1 parent fbf9356 commit 46b6756

File tree

7 files changed

+34
-0
lines changed

7 files changed

+34
-0
lines changed

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,12 @@ void AMDGPUToolChain::addClangTargetOptions(
829829
}
830830
}
831831

832+
void AMDGPUToolChain::addClangWarningOptions(ArgStringList &CC1Args) const {
833+
// AMDGPU does not support atomic lib call. Treat atomic alignment
834+
// warnings as errors.
835+
CC1Args.push_back("-Werror=atomic-alignment");
836+
}
837+
832838
StringRef
833839
AMDGPUToolChain::getGPUArch(const llvm::opt::ArgList &DriverArgs) const {
834840
return getProcessorFromTargetID(

clang/lib/Driver/ToolChains/AMDGPU.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
121121
/// Get GPU arch from -mcpu without checking.
122122
StringRef getGPUArch(const llvm::opt::ArgList &DriverArgs) const;
123123

124+
/// Common warning options shared by AMDGPU HIP, OpenCL and OpenMP toolchains.
125+
/// Language specific warning options should go to derived classes.
126+
void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override;
124127
};
125128

126129
class LLVM_LIBRARY_VISIBILITY ROCMToolChain : public AMDGPUToolChain {

clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ llvm::opt::DerivedArgList *AMDGPUOpenMPToolChain::TranslateArgs(
118118

119119
void AMDGPUOpenMPToolChain::addClangWarningOptions(
120120
ArgStringList &CC1Args) const {
121+
AMDGPUToolChain::addClangWarningOptions(CC1Args);
121122
HostTC.addClangWarningOptions(CC1Args);
122123
}
123124

clang/lib/Driver/ToolChains/HIPAMD.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ Tool *HIPAMDToolChain::buildLinker() const {
308308
}
309309

310310
void HIPAMDToolChain::addClangWarningOptions(ArgStringList &CC1Args) const {
311+
AMDGPUToolChain::addClangWarningOptions(CC1Args);
311312
HostTC.addClangWarningOptions(CC1Args);
312313
}
313314

clang/test/Driver/amdgpu-openmp-toolchain.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,7 @@
7474
// RUN: %clang -### -target x86_64-pc-linux-gnu -fopenmp --offload-arch=gfx90a \
7575
// RUN: -O3 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-OPT
7676
// CHECK-OPT: clang-linker-wrapper{{.*}}"--opt-level=O3"
77+
78+
// 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
79+
// CHECK-WARN-ATOMIC-NOT: "-cc1" "-triple" "x86_64-unknown-linux-gnu"{{.*}}"-Werror=atomic-alignment"
80+
// CHECK-WARN-ATOMIC: "-cc1" "-triple" "amdgcn-amd-amdhsa"{{.*}}"-Werror=atomic-alignment"

clang/test/Driver/amdgpu-toolchain-opencl.cl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@
3232
// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -Wl,--unresolved-symbols=ignore-all -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK_UR %s
3333
// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -Xlinker --unresolved-symbols=ignore-all -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK_UR %s
3434
// CHK-LINK_UR: ld.lld{{.*}} "--no-undefined"{{.*}} "--unresolved-symbols=ignore-all"
35+
36+
// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHECK-WARN-ATOMIC %s
37+
// CHECK-WARN-ATOMIC: "-cc1"{{.*}} "-Werror=atomic-alignment"

clang/test/Driver/hip-options.hip

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,19 @@
229229

230230
// RUN: %clang -fdriver-only -c -Werror --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib -fno-offload-uniform-block \
231231
// RUN: -foffload-uniform-block --cuda-gpu-arch=gfx906 %s 2>&1 | count 0
232+
233+
// Check -Werror=atomic-alignment is passed for amdpu by default.
234+
235+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
236+
// RUN: --cuda-gpu-arch=gfx906 %s 2>&1 | FileCheck -check-prefix=WARN-ATOMIC %s
237+
// WARN-ATOMIC: clang{{.*}} "-triple" "amdgcn-amd-amdhsa" {{.*}} "-Werror=atomic-alignment"
238+
// WARN-ATOMIC-NOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-Werror=atomic-alignment"
239+
240+
// Check the default -Werror=atomic-alignment can be overridden.
241+
242+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
243+
// RUN: --cuda-gpu-arch=gfx906 -Xarch_device -Wno-error=atomic-alignment %s \
244+
// RUN: 2>&1 | FileCheck -check-prefix=NO-WARN-ATOMIC %s
245+
// NO-WARN-ATOMIC: clang{{.*}} "-triple" "amdgcn-amd-amdhsa" {{.*}} "-Werror=atomic-alignment" {{.*}} "-Wno-error=atomic-alignment"
246+
// NO-WARN-ATOMIC-NOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-Werror=atomic-alignment"
247+
// NO-WARN-ATOMIC-NOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-Wno-error=atomic-alignment"

0 commit comments

Comments
 (0)