[clang] [Clang] Remove `IDNS_Ordinary` flag in `IndirectField::IdentifierNamespace` (PR #100525)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 25 00:12:57 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Yanzuo Liu (zwuis)
<details>
<summary>Changes</summary>
There is a `IDNS_Ordinary` flag in `IndirectField::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.
---
Full diff: https://github.com/llvm/llvm-project/pull/100525.diff
3 Files Affected:
- (modified) clang/docs/ReleaseNotes.rst (+3)
- (modified) clang/lib/AST/DeclBase.cpp (+1-2)
- (added) clang/test/Parser/namelookup-anonymous-struct.c (+6)
``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 83fd5dc31547e..24be9e26a9adf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -137,6 +137,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'}}
+};
``````````
</details>
https://github.com/llvm/llvm-project/pull/100525
More information about the cfe-commits
mailing list