nathanchance created this revision.
nathanchance added reviewers: aaron.ballman, nickdesaulniers.
Herald added a subscriber: pengfei.
Herald added a project: All.
nathanchance requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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: https://github.com/llvm/llvm-project/issues/64509
Link: https://lore.kernel.org/202308081050.szew4cq5-...@intel.com/


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157435

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/warn-missing-variable-declarations-register.c


Index: clang/test/Sema/warn-missing-variable-declarations-register.c
===================================================================
--- /dev/null
+++ clang/test/Sema/warn-missing-variable-declarations-register.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -Wmissing-variable-declarations 
-fsyntax-only -verify %s
+// REQUIRES: x86-registered-target
+// expected-no-diagnostics
+
+register unsigned long current_stack_pointer asm("rsp");
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -14144,6 +14144,7 @@
       var->getDeclContext()->getRedeclContext()->isFileContext() &&
       var->isExternallyVisible() && var->hasLinkage() &&
       !var->isInline() && !var->getDescribedVarTemplate() &&
+      var->getStorageClass() != SC_Register &&
       !isa<VarTemplatePartialSpecializationDecl>(var) &&
       !isTemplateInstantiation(var->getTemplateSpecializationKind()) &&
       !getDiagnostics().isIgnored(diag::warn_missing_variable_declarations,
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -123,6 +123,8 @@
   template-specialization function calls.
 - Clang contexpr evaluator now displays notes as well as an error when a 
constructor
   of a base class is not called in the constructor of its derived class.
+- Clang no longer emits `-Wmissing-variable-declarations` for variables 
declared
+  with the `register` storage class.
 
 Bug Fixes in This Version
 -------------------------


Index: clang/test/Sema/warn-missing-variable-declarations-register.c
===================================================================
--- /dev/null
+++ clang/test/Sema/warn-missing-variable-declarations-register.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -Wmissing-variable-declarations -fsyntax-only -verify %s
+// REQUIRES: x86-registered-target
+// expected-no-diagnostics
+
+register unsigned long current_stack_pointer asm("rsp");
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -14144,6 +14144,7 @@
       var->getDeclContext()->getRedeclContext()->isFileContext() &&
       var->isExternallyVisible() && var->hasLinkage() &&
       !var->isInline() && !var->getDescribedVarTemplate() &&
+      var->getStorageClass() != SC_Register &&
       !isa<VarTemplatePartialSpecializationDecl>(var) &&
       !isTemplateInstantiation(var->getTemplateSpecializationKind()) &&
       !getDiagnostics().isIgnored(diag::warn_missing_variable_declarations,
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -123,6 +123,8 @@
   template-specialization function calls.
 - Clang contexpr evaluator now displays notes as well as an error when a constructor
   of a base class is not called in the constructor of its derived class.
+- Clang no longer emits `-Wmissing-variable-declarations` for variables declared
+  with the `register` storage class.
 
 Bug Fixes in This Version
 -------------------------
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to