llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Gábor Horváth (Xazax-hun) <details> <summary>Changes</summary> We checked if a declaration has a LinkageSpecDecl ancestor and assumed that it would be a declaration in global/namespace scope. This prevented us from applying APINotes to methods or fields of a class that was declared in a LinkageSpecDecl. This PR changes the logic to only check whether the parent DeclContext is a LinkageSpecDecl instead of checking for all the ancestors. --- Full diff: https://github.com/llvm/llvm-project/pull/176792.diff 4 Files Affected: - (modified) clang/lib/Sema/SemaAPINotes.cpp (+2-2) - (modified) clang/test/APINotes/Inputs/Headers/Methods.apinotes (+5) - (modified) clang/test/APINotes/Inputs/Headers/Methods.h (+8) - (modified) clang/test/APINotes/methods.cpp (+5) ``````````diff diff --git a/clang/lib/Sema/SemaAPINotes.cpp b/clang/lib/Sema/SemaAPINotes.cpp index 0d8d0faa59abd..d041d0f1f0a30 100644 --- a/clang/lib/Sema/SemaAPINotes.cpp +++ b/clang/lib/Sema/SemaAPINotes.cpp @@ -987,8 +987,8 @@ void Sema::ProcessAPINotes(Decl *D) { auto *DC = D->getDeclContext(); // Globals. - if (DC->isFileContext() || DC->isNamespace() || DC->isExternCContext() || - DC->isExternCXXContext()) { + if (DC->isFileContext() || DC->isNamespace() || + DC->getDeclKind() == Decl::LinkageSpec) { std::optional<api_notes::Context> APINotesContext = UnwindNamespaceContext(DC, APINotes); // Global variables. diff --git a/clang/test/APINotes/Inputs/Headers/Methods.apinotes b/clang/test/APINotes/Inputs/Headers/Methods.apinotes index 618c2cb14b47f..397d34a1836fc 100644 --- a/clang/test/APINotes/Inputs/Headers/Methods.apinotes +++ b/clang/test/APINotes/Inputs/Headers/Methods.apinotes @@ -9,6 +9,11 @@ Tags: - Name: getDecremented Availability: none AvailabilityMsg: "this should have no effect" +- Name: IntWrapper2 + Methods: + - Name: getIncremented + Availability: none + AvailabilityMsg: "oh no" - Name: Outer Tags: - Name: Inner diff --git a/clang/test/APINotes/Inputs/Headers/Methods.h b/clang/test/APINotes/Inputs/Headers/Methods.h index cbb57ccd0afbd..d4a90e398c8ae 100644 --- a/clang/test/APINotes/Inputs/Headers/Methods.h +++ b/clang/test/APINotes/Inputs/Headers/Methods.h @@ -6,6 +6,14 @@ struct IntWrapper { IntWrapper operator+(const IntWrapper& RHS) const { return {value + RHS.value}; } }; +extern "C++" { +struct IntWrapper2 { + int value; + + IntWrapper2 getIncremented() const { return {value + 1}; } +}; +} + struct Outer { struct Inner { int value; diff --git a/clang/test/APINotes/methods.cpp b/clang/test/APINotes/methods.cpp index 910565745bea2..c215505ea5b72 100644 --- a/clang/test/APINotes/methods.cpp +++ b/clang/test/APINotes/methods.cpp @@ -1,6 +1,7 @@ // RUN: rm -rf %t && mkdir -p %t // RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Methods -fdisable-module-hash -fapinotes-modules -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -x c++ // RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Methods -fdisable-module-hash -fapinotes-modules -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -ast-dump -ast-dump-filter IntWrapper::getIncremented -x c++ | FileCheck --check-prefix=CHECK-METHOD %s +// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Methods -fdisable-module-hash -fapinotes-modules -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -ast-dump -ast-dump-filter IntWrapper2::getIncremented -x c++ | FileCheck --check-prefix=CHECK-METHOD-2 %s // RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Methods -fdisable-module-hash -fapinotes-modules -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -ast-dump -ast-dump-filter Outer::Inner::getDecremented -x c++ | FileCheck --check-prefix=CHECK-DEEP-METHOD %s #include "Methods.h" @@ -9,6 +10,10 @@ // CHECK-METHOD-NEXT: CXXMethodDecl {{.+}} getIncremented // CHECK-METHOD: UnavailableAttr {{.+}} <<invalid sloc>> "oh no" +// CHECK-METHOD-2: Dumping IntWrapper2::getIncremented: +// CHECK-METHOD-2-NEXT: CXXMethodDecl {{.+}} getIncremented +// CHECK-METHOD-2: UnavailableAttr {{.+}} <<invalid sloc>> "oh no" + // CHECK-DEEP-METHOD: Dumping Outer::Inner::getDecremented: // CHECK-DEEP-METHOD-NEXT: CXXMethodDecl {{.+}} getDecremented // CHECK-DEEP-METHOD: UnavailableAttr {{.+}} <<invalid sloc>> "nope" `````````` </details> https://github.com/llvm/llvm-project/pull/176792 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
