Index: lib/AST/ASTContext.cpp =================================================================== --- lib/AST/ASTContext.cpp +++ lib/AST/ASTContext.cpp @@ -7874,6 +7874,9 @@ if (const VarDecl *VD = dyn_cast(D)) { if (!VD->isFileVarDecl()) return false; + // Global named register variables (GNU extension) are never emitted. + if (VD->getStorageClass() == SC_Register && !VD->isLocalVarDecl()) + return false; } else if (const FunctionDecl *FD = dyn_cast(D)) { // We never need to emit an uninstantiated function template. if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate) Index: test/CodeGen/named_reg_global.c =================================================================== --- test/CodeGen/named_reg_global.c +++ test/CodeGen/named_reg_global.c @@ -3,6 +3,7 @@ // RUN: %clang_cc1 -triple arm64-linux-gnu -S -emit-llvm %s -o - | FileCheck %s // RUN: %clang_cc1 -triple armv7-linux-gnu -S -emit-llvm %s -o - | FileCheck %s +// CHECK-NOT: @sp = common global register unsigned long current_stack_pointer asm("sp"); // CHECK: define{{.*}} i[[bits:[0-9]+]] @get_stack_pointer_addr()