Skip to content

Commit

Permalink
[CUDA] "Support" ASAN arguments in CudaToolChain
Browse files Browse the repository at this point in the history
This fixes a bug that was introduced in rL287285. The bug made it
illegal to pass -fsanitize=address during CUDA compilation because the
CudaToolChain class was switched from deriving from the Linux toolchain
class to deriving directly from the ToolChain toolchain class. When
CudaToolChain derived from Linux, it used Linux's getSupportedSanitizers
method, and that method allowed ASAN, but when it switched to deriving
directly from ToolChain, it inherited a getSupportedSanitizers method
that didn't allow for ASAN.

This patch fixes that bug by creating a getSupportedSanitizers method
for CudaToolChain that supports ASAN.

This patch also fixes the test that checks that -fsanitize=address is
passed correctly for CUDA builds. That test didn't used to notice if an
error message was emitted, and that's why it didn't catch this bug when
it was first introduced. With the fix from this patch, that test will
now catch any similar bug in the future.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288448 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
henline committed Dec 2, 2016
1 parent 070f9f1 commit ad22c75
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4973,6 +4973,15 @@ void CudaToolChain::AddIAMCUIncludeArgs(const ArgList &Args,
HostTC.AddIAMCUIncludeArgs(Args, CC1Args);
}

SanitizerMask CudaToolChain::getSupportedSanitizers() const {
// The CudaToolChain only supports address sanitization in the sense that it
// allows ASAN arguments on the command line. It must not error out on these
// command line arguments because the host code compilation supports them.
// However, it doesn't actually do any address sanitization for device code;
// instead, it just ignores any ASAN command line arguments it sees.
return SanitizerKind::Address;
}

/// XCore tool chain
XCoreToolChain::XCoreToolChain(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
Expand Down
2 changes: 2 additions & 0 deletions lib/Driver/ToolChains.h
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,8 @@ class LLVM_LIBRARY_VISIBILITY CudaToolChain : public ToolChain {
void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;

SanitizerMask getSupportedSanitizers() const override;

const ToolChain &HostTC;
CudaInstallationDetector CudaInstallation;

Expand Down
1 change: 1 addition & 0 deletions test/Driver/cuda-no-sanitizers.cu
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 -fsanitize=address %s 2>&1 | \
// RUN: FileCheck %s

// CHECK-NOT: error:
// CHECK-DAG: "-fcuda-is-device"
// CHECK-NOT: "-fsanitize=address"
// CHECK-DAG: "-triple" "x86_64--linux-gnu"
Expand Down

0 comments on commit ad22c75

Please sign in to comment.