[cfe-commits] r146980 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td include/clang/Sema/Lookup.h include/clang/Sema/Sema.h lib/Sema/SemaDecl.cpp lib/Sema/SemaLookup.cpp lib/Sema/SemaTemplate.cpp test/Modules/Inputs/module.map test/Modules/Inputs/module_private_left.h test/Modules/Inputs/module_private_right.h test/Modules/Inputs/redecl-merge-left.h test/Modules/Inputs/redecl-merge-right.h test/Modules/Inputs/redecl-merge-top-explicit.h test/Modules/module-private.cpp test/Modules/redecl-merge.m
Douglas Gregor
dgregor at apple.com
Tue Dec 20 10:11:52 PST 2011
Author: dgregor
Date: Tue Dec 20 12:11:52 2011
New Revision: 146980
URL: http://llvm.org/viewvc/llvm-project?rev=146980&view=rev
Log:
When performing name lookup for a redeclaration, ignore module
visibility restrictions. This ensures that all declarations of the
same entity end up in the same redeclaration chain, even if some of
those declarations aren't visible. While this may seem unfortunate to
some---why can't two C modules have different functions named
'f'?---it's an acknowedgment that a module does not introduce a new
"namespace" of names.
As part of this, stop merging the 'module-private' bit from previous
declarations to later declarations, because we want each declaration
in a module to stand on its own because this can effect, for example,
submodule visibility.
Note that this notion of names that are invisible to normal name
lookup but are available for redeclaration lookups is how we should
implement friend declarations and extern declarations within local
function scopes. I'm not tackling that problem now.
Added:
cfe/trunk/test/Modules/Inputs/redecl-merge-top-explicit.h (with props)
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Lookup.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/Modules/Inputs/module.map
cfe/trunk/test/Modules/Inputs/module_private_left.h
cfe/trunk/test/Modules/Inputs/module_private_right.h
cfe/trunk/test/Modules/Inputs/redecl-merge-left.h
cfe/trunk/test/Modules/Inputs/redecl-merge-right.h
cfe/trunk/test/Modules/module-private.cpp
cfe/trunk/test/Modules/redecl-merge.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=146980&r1=146979&r2=146980&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Dec 20 12:11:52 2011
@@ -5154,8 +5154,6 @@
}
let CategoryName = "Modules Issue" in {
-def err_module_private_follows_public : Error<
- "__module_private__ declaration of %0 follows public declaration">;
def err_module_private_specialization : Error<
"%select{template|partial|member}0 specialization cannot be "
"declared __module_private__">;
Modified: cfe/trunk/include/clang/Sema/Lookup.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Lookup.h?rev=146980&r1=146979&r2=146980&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Lookup.h (original)
+++ cfe/trunk/include/clang/Sema/Lookup.h Tue Dec 20 12:11:52 2011
@@ -286,7 +286,7 @@
if (!D->isInIdentifierNamespace(IDNS))
return 0;
- if (isVisible(D))
+ if (Redecl == Sema::ForRedeclaration || isVisible(D))
return D;
return getAcceptableDeclSlow(D);
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=146980&r1=146979&r2=146980&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue Dec 20 12:11:52 2011
@@ -1119,12 +1119,6 @@
/// \param Path The module access path.
DeclResult ActOnModuleImport(SourceLocation ImportLoc, ModuleIdPath Path);
- /// \brief Diagnose that \p New is a module-private redeclaration of
- /// \p Old.
- void diagnoseModulePrivateRedeclaration(NamedDecl *New, NamedDecl *Old,
- SourceLocation ModulePrivateKeyword
- = SourceLocation());
-
/// \brief Retrieve a suitable printing policy.
PrintingPolicy getPrintingPolicy() const;
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=146980&r1=146979&r2=146980&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Dec 20 12:11:52 2011
@@ -1456,12 +1456,6 @@
if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Old))
New->setPreviousDeclaration(Typedef);
- // __module_private__ is propagated to later declarations.
- if (Old->isModulePrivate())
- New->setModulePrivate();
- else if (New->isModulePrivate())
- diagnoseModulePrivateRedeclaration(New, Old);
-
if (getLangOptions().MicrosoftExt)
return;
@@ -2047,12 +2041,6 @@
if (Old->isPure())
New->setPure();
- // __module_private__ is propagated to later declarations.
- if (Old->isModulePrivate())
- New->setModulePrivate();
- else if (New->isModulePrivate())
- diagnoseModulePrivateRedeclaration(New, Old);
-
// Merge attributes from the parameters. These can mismatch with K&R
// declarations.
if (New->getNumParams() == Old->getNumParams())
@@ -2237,12 +2225,6 @@
return New->setInvalidDecl();
}
- // __module_private__ is propagated to later declarations.
- if (Old->isModulePrivate())
- New->setModulePrivate();
- else if (New->isModulePrivate())
- diagnoseModulePrivateRedeclaration(New, Old);
-
// Variables with external linkage are analyzed in FinalizeDeclaratorGroup.
// FIXME: The test for external storage here seems wrong? We still
@@ -5627,9 +5609,6 @@
assert(OldTemplateDecl->isMemberSpecialization());
}
- if (OldTemplateDecl->isModulePrivate())
- NewTemplateDecl->setModulePrivate();
-
} else {
if (isa<CXXMethodDecl>(NewFD)) // Set access for out-of-line definitions
NewFD->setAccess(OldDecl->getAccess());
@@ -8212,19 +8191,14 @@
AddMsStructLayoutForRecord(RD);
}
- if (PrevDecl && PrevDecl->isModulePrivate())
- New->setModulePrivate();
- else if (ModulePrivateLoc.isValid()) {
+ if (ModulePrivateLoc.isValid()) {
if (isExplicitSpecialization)
Diag(New->getLocation(), diag::err_module_private_specialization)
<< 2
<< FixItHint::CreateRemoval(ModulePrivateLoc);
- else if (PrevDecl && !PrevDecl->isModulePrivate())
- diagnoseModulePrivateRedeclaration(New, PrevDecl, ModulePrivateLoc);
// __module_private__ does not apply to local classes. However, we only
// diagnose this as an error when the declaration specifiers are
// freestanding. Here, we just ignore the __module_private__.
- // foobar
else if (!SearchDC->isFunctionOrMethod())
New->setModulePrivate();
}
@@ -9969,20 +9943,6 @@
return Import;
}
-void
-Sema::diagnoseModulePrivateRedeclaration(NamedDecl *New, NamedDecl *Old,
- SourceLocation ModulePrivateKeyword) {
- assert(!Old->isModulePrivate() && "Old is module-private!");
-
- Diag(New->getLocation(), diag::err_module_private_follows_public)
- << New->getDeclName() << SourceRange(ModulePrivateKeyword);
- Diag(Old->getLocation(), diag::note_previous_declaration)
- << Old->getDeclName();
-
- // Drop the __module_private__ from the new declaration, since it's invalid.
- New->setModulePrivate(false);
-}
-
void Sema::ActOnPragmaWeakID(IdentifierInfo* Name,
SourceLocation PragmaLoc,
SourceLocation NameLoc) {
Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=146980&r1=146979&r2=146980&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Dec 20 12:11:52 2011
@@ -1169,7 +1169,7 @@
// If this declaration is module-private and it came from an AST
// file, we can't see it.
- NamedDecl *D = getVisibleDecl(*I);
+ NamedDecl *D = R.isForRedeclaration()? *I : getVisibleDecl(*I);
if (!D)
continue;
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=146980&r1=146979&r2=146980&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Tue Dec 20 12:11:52 2011
@@ -1013,15 +1013,8 @@
NewClass, PrevClassTemplate);
NewClass->setDescribedClassTemplate(NewTemplate);
- if (PrevClassTemplate && PrevClassTemplate->isModulePrivate()) {
+ if (ModulePrivateLoc.isValid())
NewTemplate->setModulePrivate();
- } else if (ModulePrivateLoc.isValid()) {
- if (PrevClassTemplate && !PrevClassTemplate->isModulePrivate())
- diagnoseModulePrivateRedeclaration(NewTemplate, PrevClassTemplate,
- ModulePrivateLoc);
- else
- NewTemplate->setModulePrivate();
- }
// Build the type for the class template declaration now.
QualType T = NewTemplate->getInjectedClassNameSpecialization();
Modified: cfe/trunk/test/Modules/Inputs/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/module.map?rev=146980&r1=146979&r2=146980&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/module.map (original)
+++ cfe/trunk/test/Modules/Inputs/module.map Tue Dec 20 12:11:52 2011
@@ -44,7 +44,8 @@
}
module redecl_merge_top {
- header "redecl-merge-top.h"
+ header "redecl-merge-top.h"
+ explicit module Explicit { header "redecl-merge-top-explicit.h" }
}
module redecl_merge_left {
header "redecl-merge-left.h"
Modified: cfe/trunk/test/Modules/Inputs/module_private_left.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/module_private_left.h?rev=146980&r1=146979&r2=146980&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/module_private_left.h (original)
+++ cfe/trunk/test/Modules/Inputs/module_private_left.h Tue Dec 20 12:11:52 2011
@@ -1,6 +1,6 @@
__module_private__ struct HiddenStruct;
-struct HiddenStruct {
+__module_private__ struct HiddenStruct {
};
@@ -10,17 +10,17 @@
__module_private__ void f1(T*);
template<typename T>
-void f1(T*);
+__module_private__ void f1(T*);
template<typename T>
__module_private__ class vector;
template<typename T>
-class vector {
+__module_private__ class vector {
};
vector<float> vec_float;
typedef __module_private__ int Integer;
-typedef int Integer;
+typedef __module_private__ int Integer;
Modified: cfe/trunk/test/Modules/Inputs/module_private_right.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/module_private_right.h?rev=146980&r1=146979&r2=146980&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/module_private_right.h (original)
+++ cfe/trunk/test/Modules/Inputs/module_private_right.h Tue Dec 20 12:11:52 2011
@@ -1,5 +1,5 @@
__module_private__ double &f0(double);
-double &f0(double);
+__module_private__ double &f0(double);
__module_private__ int hidden_var;
Modified: cfe/trunk/test/Modules/Inputs/redecl-merge-left.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/redecl-merge-left.h?rev=146980&r1=146979&r2=146980&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/redecl-merge-left.h (original)
+++ cfe/trunk/test/Modules/Inputs/redecl-merge-left.h Tue Dec 20 12:11:52 2011
@@ -10,6 +10,12 @@
@class A;
+ at class Explicit;
+
+int *explicit_func(void);
+
+struct explicit_struct;
+
#ifdef __cplusplus
template<typename T> class Vector;
Modified: cfe/trunk/test/Modules/Inputs/redecl-merge-right.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/redecl-merge-right.h?rev=146980&r1=146979&r2=146980&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/redecl-merge-right.h (original)
+++ cfe/trunk/test/Modules/Inputs/redecl-merge-right.h Tue Dec 20 12:11:52 2011
@@ -9,6 +9,12 @@
@class B;
+ at class Explicit;
+
+int *explicit_func(void);
+
+struct explicit_struct;
+
#ifdef __cplusplus
template<typename T> class Vector {
public:
Added: cfe/trunk/test/Modules/Inputs/redecl-merge-top-explicit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/redecl-merge-top-explicit.h?rev=146980&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/redecl-merge-top-explicit.h (added)
+++ cfe/trunk/test/Modules/Inputs/redecl-merge-top-explicit.h Tue Dec 20 12:11:52 2011
@@ -0,0 +1,5 @@
+ at class Explicit;
+
+int *explicit_func(void);
+
+struct explicit_struct { int member; };
Propchange: cfe/trunk/test/Modules/Inputs/redecl-merge-top-explicit.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/Modules/Inputs/redecl-merge-top-explicit.h
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cfe/trunk/test/Modules/Inputs/redecl-merge-top-explicit.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: cfe/trunk/test/Modules/module-private.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/module-private.cpp?rev=146980&r1=146979&r2=146980&view=diff
==============================================================================
--- cfe/trunk/test/Modules/module-private.cpp (original)
+++ cfe/trunk/test/Modules/module-private.cpp Tue Dec 20 12:11:52 2011
@@ -31,28 +31,28 @@
// Check for private redeclarations of public entities.
template<typename T>
-class public_class_template; // expected-note{{previous declaration is here}}
+class public_class_template;
template<typename T>
-__module_private__ class public_class_template; // expected-error{{__module_private__ declaration of 'public_class_template' follows public declaration}}
+__module_private__ class public_class_template;
-typedef int public_typedef; // expected-note{{previous declaration is here}}
-typedef __module_private__ int public_typedef; // expected-error{{__module_private__ declaration of 'public_typedef' follows public declaration}}
+typedef int public_typedef;
+typedef __module_private__ int public_typedef;
-extern int public_var; // expected-note{{previous declaration is here}}
-extern __module_private__ int public_var; // expected-error{{__module_private__ declaration of 'public_var' follows public declaration}}
+extern int public_var;
+extern __module_private__ int public_var;
-void public_func(); // expected-note{{previous declaration is here}}
-__module_private__ void public_func(); // expected-error{{__module_private__ declaration of 'public_func' follows public declaration}}
+void public_func();
+__module_private__ void public_func();
template<typename T>
-void public_func_template(); // expected-note{{previous declaration is here}}
+void public_func_template();
template<typename T>
-__module_private__ void public_func_template(); // expected-error{{__module_private__ declaration of 'public_func_template' follows public declaration}}
+__module_private__ void public_func_template();
-struct public_struct; // expected-note{{previous declaration is here}}
-__module_private__ struct public_struct; // expected-error{{__module_private__ declaration of 'public_struct' follows public declaration}}
+struct public_struct;
+__module_private__ struct public_struct;
// Check for attempts to make specializations private
template<> __module_private__ void public_func_template<int>(); // expected-error{{template specialization cannot be declared __module_private__}}
Modified: cfe/trunk/test/Modules/redecl-merge.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/redecl-merge.m?rev=146980&r1=146979&r2=146980&view=diff
==============================================================================
--- cfe/trunk/test/Modules/redecl-merge.m (original)
+++ cfe/trunk/test/Modules/redecl-merge.m Tue Dec 20 12:11:52 2011
@@ -20,6 +20,18 @@
@class B;
+// Test redeclarations of entities in explicit submodules, to make
+// sure we're maintaining the declaration chains even when normal name
+// lookup can't see what we're looking for.
+void testExplicit() {
+ Explicit *e;
+ int *(*fp)(void) = &explicit_func;
+ int *ip = explicit_func();
+
+ // FIXME: Should complain about definition not having been imported.
+ struct explicit_struct es = { 0 };
+}
+
__import_module__ redecl_merge_bottom;
@implementation B
More information about the cfe-commits
mailing list