Skip to content

Commit 9d22095

Browse files
authored
[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.
1 parent 22bc9db commit 9d22095

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ Miscellaneous Bug Fixes
166166
Miscellaneous Clang Crashes Fixed
167167
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
168168

169+
- Fixed a crash in C due to incorrect lookup that members in nested anonymous struct/union
170+
can be found as ordinary identifiers in struct/union definition. (#GH31295)
171+
169172
OpenACC Specific Changes
170173
------------------------
171174

clang/lib/AST/DeclBase.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,8 +879,6 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {
879879
return IDNS_Ordinary;
880880
case Label:
881881
return IDNS_Label;
882-
case IndirectField:
883-
return IDNS_Ordinary | IDNS_Member;
884882

885883
case Binding:
886884
case NonTypeTemplateParm:
@@ -918,6 +916,7 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {
918916
return IDNS_ObjCProtocol;
919917

920918
case Field:
919+
case IndirectField:
921920
case ObjCAtDefsField:
922921
case ObjCIvar:
923922
return IDNS_Member;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %clang_cc1 -std=c11 -verify %s
2+
3+
struct GH31295 {
4+
struct { int x; };
5+
int arr[sizeof(x)]; // expected-error{{use of undeclared identifier 'x'}}
6+
};

0 commit comments

Comments
 (0)