Index: lib/CodeGen/CodeGenModule.cpp =================================================================== --- lib/CodeGen/CodeGenModule.cpp +++ lib/CodeGen/CodeGenModule.cpp @@ -3836,6 +3836,10 @@ /// to such functions with an unmangled name from inline assembly within the /// same translation unit. void CodeGenModule::EmitStaticExternCAliases() { + // Don't do anything if we're generating CUDA device code -- the NVPTX + // assembly target doesn't support aliases. + if (Context.getTargetInfo().getTriple().isNVPTX()) + return; for (auto &I : StaticExternCValues) { IdentifierInfo *Name = I.first; llvm::GlobalValue *Val = I.second; Index: test/CodeGenCUDA/alias.cu =================================================================== --- /dev/null +++ test/CodeGenCUDA/alias.cu @@ -0,0 +1,17 @@ +// REQUIRES: x86-registered-target +// REQUIRES: nvptx-registered-target + +// RUN: %clang_cc1 -fcuda-is-device -triple nvptx-nvidia-cuda -emit-llvm \ +// RUN: -o - %s | FileCheck %s + +#include "Inputs/cuda.h" + +// Check that we don't generate an alias from "foo" to the mangled name for +// ns::foo() -- nvptx doesn't support aliases. + +namespace ns { +extern "C" { +// CHECK-NOT: @foo = internal alias +__device__ __attribute__((used)) static int foo() { return 0; } +} +}