Skip to content

Commit a22d385

Browse files
committed
[Sema] Do not emit -Wmissing-variable-declarations for register variables
When building the Linux kernel with -Wmissing-variable-declarations, there are several instances of warnings around variables declared with register storage: arch/x86/include/asm/asm.h:208:24: warning: no previous extern declaration for non-static variable 'current_stack_pointer' [-Wmissing-variable-declarations] register unsigned long current_stack_pointer asm(_ASM_SP); ^ arch/x86/include/asm/asm.h:208:10: note: declare 'static' if the variable is not intended to be used outside of this translation unit register unsigned long current_stack_pointer asm(_ASM_SP); ^ 1 warning generated. The suggestion is invalid, as the variable cannot have both static and register storage. Do not emit -Wmissing-variable-declarations for register variables. Closes: #64509 Link: https://lore.kernel.org/[email protected]/ Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110947 Reviewed By: aaron.ballman, nickdesaulniers Differential Revision: https://reviews.llvm.org/D157435
1 parent d0ca66a commit a22d385

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ Improvements to Clang's diagnostics
123123
template-specialization function calls.
124124
- Clang contexpr evaluator now displays notes as well as an error when a constructor
125125
of a base class is not called in the constructor of its derived class.
126+
- Clang no longer emits ``-Wmissing-variable-declarations`` for variables declared
127+
with the ``register`` storage class.
126128

127129
Bug Fixes in This Version
128130
-------------------------

clang/lib/Sema/SemaDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14144,6 +14144,7 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
1414414144
var->getDeclContext()->getRedeclContext()->isFileContext() &&
1414514145
var->isExternallyVisible() && var->hasLinkage() &&
1414614146
!var->isInline() && !var->getDescribedVarTemplate() &&
14147+
var->getStorageClass() != SC_Register &&
1414714148
!isa<VarTemplatePartialSpecializationDecl>(var) &&
1414814149
!isTemplateInstantiation(var->getTemplateSpecializationKind()) &&
1414914150
!getDiagnostics().isIgnored(diag::warn_missing_variable_declarations,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -Wmissing-variable-declarations -fsyntax-only -verify %s
2+
// expected-no-diagnostics
3+
4+
register unsigned long current_stack_pointer asm("rsp");

0 commit comments

Comments
 (0)