]> granicus.if.org Git - clang/commitdiff
If an unimported submodule of an imported module contains a declaration of a
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 14 Jul 2013 02:01:48 +0000 (02:01 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 14 Jul 2013 02:01:48 +0000 (02:01 +0000)
global allocation or deallocation function, that should not cause that global
allocation or deallocation function to become unavailable.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186270 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Decl.h
lib/Sema/SemaExprCXX.cpp
test/Modules/Inputs/cxx-decls-imported.h [new file with mode: 0644]
test/Modules/Inputs/cxx-decls-unimported.h [new file with mode: 0644]
test/Modules/Inputs/module.map
test/Modules/cxx-decls.cpp [new file with mode: 0644]

index c849b5417b6901fb0d31934b550ff78acb84d053..bc588ac4542b26fe06f97becb14943f287c608bb 100644 (file)
@@ -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();
index a6b6e36bb7d2e9e7c43f0d54b7446147cf829fa3..39c4211892229823fcafd3fbed7e059c87c3aaeb 100644 (file)
@@ -1949,8 +1949,12 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name,
             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;
         }
       }
diff --git a/test/Modules/Inputs/cxx-decls-imported.h b/test/Modules/Inputs/cxx-decls-imported.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Modules/Inputs/cxx-decls-unimported.h b/test/Modules/Inputs/cxx-decls-unimported.h
new file mode 100644 (file)
index 0000000..0431e32
--- /dev/null
@@ -0,0 +1 @@
+void operator delete(void*);
index a4ac5b14de34d1424ae284d83b7574bc7bdeaed8..0a84f88b0af8e1a978747c3dddf6408468de1d7e 100644 (file)
@@ -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
diff --git a/test/Modules/cxx-decls.cpp b/test/Modules/cxx-decls.cpp
new file mode 100644 (file)
index 0000000..733e3f9
--- /dev/null
@@ -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
+
+@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;
+}