Author: Yanzuo Liu Date: 2024-07-26T08:39:46-04:00 New Revision: 9d220956320a36fd127ee14ed41f0ecdcc0fb5b0
URL: https://github.com/llvm/llvm-project/commit/9d220956320a36fd127ee14ed41f0ecdcc0fb5b0 DIFF: https://github.com/llvm/llvm-project/commit/9d220956320a36fd127ee14ed41f0ecdcc0fb5b0.diff LOG: [Clang] Remove `IDNS_Ordinary` flag in `IndirectFieldDecl::IdentifierNamespace` (#100525) There is a `IDNS_Ordinary` flag in `IndirectFieldDecl::IdentifierNamespace` so that members in nested anonymous struct/union can be found as ordinary identifiers. ```c struct S { struct { int x; }; // Previous behaviour: `x` in previous line is found // Expected: nothing is found int arr[sizeof(x)]; }; ``` This PR fixes this issue. Fixes #31295. Added: clang/test/Parser/namelookup-anonymous-struct.c Modified: clang/docs/ReleaseNotes.rst clang/lib/AST/DeclBase.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index b165f6e65636d..286f319d41a23 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -166,6 +166,9 @@ Miscellaneous Bug Fixes Miscellaneous Clang Crashes Fixed ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +- Fixed a crash in C due to incorrect lookup that members in nested anonymous struct/union + can be found as ordinary identifiers in struct/union definition. (#GH31295) + OpenACC Specific Changes ------------------------ diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index bc5a9206c0db2..a1f70546bde42 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -879,8 +879,6 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) { return IDNS_Ordinary; case Label: return IDNS_Label; - case IndirectField: - return IDNS_Ordinary | IDNS_Member; case Binding: case NonTypeTemplateParm: @@ -918,6 +916,7 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) { return IDNS_ObjCProtocol; case Field: + case IndirectField: case ObjCAtDefsField: case ObjCIvar: return IDNS_Member; diff --git a/clang/test/Parser/namelookup-anonymous-struct.c b/clang/test/Parser/namelookup-anonymous-struct.c new file mode 100644 index 0000000000000..cb691c22f97ff --- /dev/null +++ b/clang/test/Parser/namelookup-anonymous-struct.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -std=c11 -verify %s + +struct GH31295 { + struct { int x; }; + int arr[sizeof(x)]; // expected-error{{use of undeclared identifier 'x'}} +}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits