Author: Nathan Chancellor Date: 2023-08-08T13:41:21-07:00 New Revision: a22d385f9656c95f5ce4155ea705aab6f8ef6d82
URL: https://github.com/llvm/llvm-project/commit/a22d385f9656c95f5ce4155ea705aab6f8ef6d82 DIFF: https://github.com/llvm/llvm-project/commit/a22d385f9656c95f5ce4155ea705aab6f8ef6d82.diff LOG: [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: https://github.com/llvm/llvm-project/issues/64509 Link: https://lore.kernel.org/202308081050.szew4cq5-...@intel.com/ Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110947 Reviewed By: aaron.ballman, nickdesaulniers Differential Revision: https://reviews.llvm.org/D157435 Added: clang/test/Sema/warn-missing-variable-declarations-register.c Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaDecl.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index d3757c833ef83a..92abb65546caa3 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -123,6 +123,8 @@ Improvements to Clang's diagnostics 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 ------------------------- diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 390d09547f2a58..d250b4382753bb 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -14144,6 +14144,7 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) { 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, diff --git a/clang/test/Sema/warn-missing-variable-declarations-register.c b/clang/test/Sema/warn-missing-variable-declarations-register.c new file mode 100644 index 00000000000000..d26a0df12e23dc --- /dev/null +++ b/clang/test/Sema/warn-missing-variable-declarations-register.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -Wmissing-variable-declarations -fsyntax-only -verify %s +// expected-no-diagnostics + +register unsigned long current_stack_pointer asm("rsp"); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits