[PATCH] D114833: [modules] Fix ambiguous name lookup for enum constants from hidden submodules.
Volodymyr Sapsai via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 1 19:30:03 PST 2021
vsapsai updated this revision to Diff 391189.
vsapsai added a comment.
Attempt to restore a previous commit.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D114833/new/
https://reviews.llvm.org/D114833
Files:
clang/lib/Sema/SemaDecl.cpp
clang/test/Modules/ambiguous-anonymous-enum-lookup.cpp
clang/test/Modules/redefinition-c-tagtypes.m
Index: clang/test/Modules/redefinition-c-tagtypes.m
===================================================================
--- clang/test/Modules/redefinition-c-tagtypes.m
+++ clang/test/Modules/redefinition-c-tagtypes.m
@@ -32,6 +32,10 @@
TRD = 55
};
+int testReferencingNSEConstant() {
+ return FST;
+}
+
#define NS_ENUM(_type, _name) \
enum _name : _type _name; \
enum _name : _type
@@ -42,7 +46,11 @@
MinXOther = MinX,
#else
MinXOther = TRD, // expected-note {{enumerator 'MinXOther' with value 55 here}}
- // expected-error at redefinition-c-tagtypes.m:39 {{type 'enum NSMyEnum' has incompatible definitions}}
+ // expected-error at redefinition-c-tagtypes.m:43 {{type 'enum NSMyEnum' has incompatible definitions}}
// expected-note at Inputs/F.framework/PrivateHeaders/NS.h:18 {{enumerator 'MinXOther' with value 11 here}}
#endif
};
+
+int testReferencingNSMyEnumConstant() {
+ return MinX;
+}
Index: clang/test/Modules/ambiguous-anonymous-enum-lookup.cpp
===================================================================
--- /dev/null
+++ clang/test/Modules/ambiguous-anonymous-enum-lookup.cpp
@@ -0,0 +1,41 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache -I %t/include %t/test.cpp -verify
+
+//--- include/textual.h
+#ifndef TEXTUAL_H
+#define TEXTUAL_H
+
+enum {
+ kAnonymousEnumValue = 0,
+};
+
+#endif
+
+//--- include/empty.h
+// empty
+
+//--- include/initially_hidden.h
+#include <textual.h>
+
+//--- include/module.modulemap
+module Piecewise {
+ module Empty {
+ header "empty.h"
+ export *
+ }
+ module InitiallyHidden {
+ header "initially_hidden.h"
+ export *
+ }
+}
+
+//--- test.cpp
+#include <empty.h>
+#include <textual.h>
+#include <initially_hidden.h>
+
+// expected-no-diagnostics
+int testReferencingAnonymousEnumConstant() {
+ return kAnonymousEnumValue;
+}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16598,6 +16598,19 @@
// Make the previous decl visible.
makeMergedDefinitionVisible(SkipBody.Previous);
+ // For the ignored `EnumDecl` definition remove its `EnumConstantDecl` from
+ // global name lookup to avoid future ambiguous lookups. Doing this for ObjC/C
+ // to mimic early return in `Sema::ActOnTag` that avoids calling
+ // `PushOnScopeChains` for duplicate `TagDecl` definitions. Doing it only for
+ // `EnumDecl` among all `TagDecl` because enum constants have global name
+ // lookup while record field lookup is limited to a record.
+ if (!getLangOpts().CPlusPlus) {
+ if (const auto *ED = dyn_cast<EnumDecl>(SkipBody.New))
+ for (EnumDecl::enumerator_iterator EC = ED->enumerator_begin(),
+ End = ED->enumerator_end();
+ EC != End; ++EC)
+ IdResolver.RemoveDecl(*EC);
+ }
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114833.391189.patch
Type: text/x-patch
Size: 2991 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211202/fad24425/attachment-0001.bin>
More information about the cfe-commits
mailing list