r186270 - If an unimported submodule of an imported module contains a declaration of a

Richard Smith richard-llvm at metafoo.co.uk
Sat Jul 13 19:01:48 PDT 2013


Author: rsmith
Date: Sat Jul 13 21:01:48 2013
New Revision: 186270

URL: http://llvm.org/viewvc/llvm-project?rev=186270&view=rev
Log:
If an unimported submodule of an imported module contains a declaration of a
global allocation or deallocation function, that should not cause that global
allocation or deallocation function to become unavailable.

Added:
    cfe/trunk/test/Modules/Inputs/cxx-decls-imported.h
    cfe/trunk/test/Modules/Inputs/cxx-decls-unimported.h
    cfe/trunk/test/Modules/cxx-decls.cpp
Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/Modules/Inputs/module.map

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=186270&r1=186269&r2=186270&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Sat Jul 13 21:01:48 2013
@@ -189,10 +189,13 @@ public:
 
   using Decl::isModulePrivate;
   using Decl::setModulePrivate;
-  
+
   /// \brief Determine whether this declaration is hidden from name lookup.
   bool isHidden() const { return Hidden; }
-  
+
+  /// \brief Set whether this declaration is hidden from name lookup.
+  void setHidden(bool Hide) { Hidden = Hide; }
+
   /// \brief Determine whether this declaration is a C++ class member.
   bool isCXXClassMember() const {
     const DeclContext *DC = getDeclContext();

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=186270&r1=186269&r2=186270&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sat Jul 13 21:01:48 2013
@@ -1949,8 +1949,12 @@ void Sema::DeclareGlobalAllocationFuncti
             Func->getParamDecl(0)->getType().getUnqualifiedType());
         // FIXME: Do we need to check for default arguments here?
         if (Func->getNumParams() == 1 && InitialParamType == Argument) {
-          if(AddMallocAttr && !Func->hasAttr<MallocAttr>())
+          if (AddMallocAttr && !Func->hasAttr<MallocAttr>())
             Func->addAttr(::new (Context) MallocAttr(SourceLocation(), Context));
+          // Make the function visible to name lookup, even if we found it in an
+          // unimported module. It either is an implicitly-declared global
+          // allocation function, or is suppressing that function.
+          Func->setHidden(false);
           return;
         }
       }

Added: cfe/trunk/test/Modules/Inputs/cxx-decls-imported.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/cxx-decls-imported.h?rev=186270&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Modules/Inputs/cxx-decls-unimported.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/cxx-decls-unimported.h?rev=186270&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/cxx-decls-unimported.h (added)
+++ cfe/trunk/test/Modules/Inputs/cxx-decls-unimported.h Sat Jul 13 21:01:48 2013
@@ -0,0 +1 @@
+void operator delete(void*);

Modified: cfe/trunk/test/Modules/Inputs/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/module.map?rev=186270&r1=186269&r2=186270&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/module.map (original)
+++ cfe/trunk/test/Modules/Inputs/module.map Sat Jul 13 21:01:48 2013
@@ -200,6 +200,15 @@ module cxx_templates_b {
   header "cxx-templates-b.h"
 }
 
+module cxx_decls {
+  module unimported {
+    header "cxx-decls-unimported.h"
+  }
+  module imported {
+    header "cxx-decls-imported.h"
+  }
+}
+
 module config {
   header "config.h"
   config_macros [exhaustive] WANT_FOO, WANT_BAR

Added: cfe/trunk/test/Modules/cxx-decls.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/cxx-decls.cpp?rev=186270&view=auto
==============================================================================
--- cfe/trunk/test/Modules/cxx-decls.cpp (added)
+++ cfe/trunk/test/Modules/cxx-decls.cpp Sat Jul 13 21:01:48 2013
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -verify -std=c++11
+
+// expected-no-diagnostics
+
+ at import cxx_decls.imported;
+
+void test_delete(int *p) {
+  // We can call the normal global deallocation function even though it has only
+  // ever been explicitly declared in an unimported submodule.
+  delete p;
+}





More information about the cfe-commits mailing list