summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVassil Vassilev <v.g.vassilev@gmail.com>2016-09-08 20:34:41 +0000
committerVassil Vassilev <v.g.vassilev@gmail.com>2016-09-08 20:34:41 +0000
commit714b81c40adff7cb46df6adacb2a41dd282ca93b (patch)
tree65801a8c74c7af4913bbe322ee9d49539cf39fb8
parent2b68ada188d0e850875a0ebf6939276fd21a71b4 (diff)
downloadbcm5719-llvm-714b81c40adff7cb46df6adacb2a41dd282ca93b.tar.gz
bcm5719-llvm-714b81c40adff7cb46df6adacb2a41dd282ca93b.zip
[modules] Apply ODR merging for function scoped tags only in C++ mode.
In C mode, if we have a visible declaration but not a visible definition, a tag defined in the declaration should be have a visible definition. In C++ we rely on the ODR merging, whereas in C we cannot because each declaration of a function gets its own set of declarations in its prototype scope. Patch developed in collaboration with Richard Smith! llvm-svn: 280984
-rw-r--r--clang/lib/Sema/SemaLookup.cpp7
-rw-r--r--clang/test/Modules/Inputs/merge-fn-prototype-tags/a.h2
-rw-r--r--clang/test/Modules/Inputs/merge-fn-prototype-tags/b.h1
-rw-r--r--clang/test/Modules/Inputs/merge-fn-prototype-tags/c.h4
-rw-r--r--clang/test/Modules/Inputs/merge-fn-prototype-tags/module.modulemap5
-rw-r--r--clang/test/Modules/merge-fn-prototype-tags.c8
6 files changed, 26 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 19df1e30423..40ad686321b 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -1543,7 +1543,12 @@ bool LookupResult::isVisibleSlow(Sema &SemaRef, NamedDecl *D) {
// For a parameter, check whether our current template declaration's
// lexical context is visible, not whether there's some other visible
// definition of it, because parameters aren't "within" the definition.
- if ((D->isTemplateParameter() || isa<ParmVarDecl>(D))
+ //
+ // In C++ we need to check for a visible definition due to ODR merging,
+ // and in C we must not because each declaration of a function gets its own
+ // set of declarations for tags in prototype scope.
+ if ((D->isTemplateParameter() || isa<ParmVarDecl>(D)
+ || (isa<FunctionDecl>(DC) && !SemaRef.getLangOpts().CPlusPlus))
? isVisible(SemaRef, cast<NamedDecl>(DC))
: SemaRef.hasVisibleDefinition(cast<NamedDecl>(DC))) {
if (SemaRef.ActiveTemplateInstantiations.empty() &&
diff --git a/clang/test/Modules/Inputs/merge-fn-prototype-tags/a.h b/clang/test/Modules/Inputs/merge-fn-prototype-tags/a.h
new file mode 100644
index 00000000000..8dd717cba62
--- /dev/null
+++ b/clang/test/Modules/Inputs/merge-fn-prototype-tags/a.h
@@ -0,0 +1,2 @@
+#include "c.h"
+void ftw(struct stat);
diff --git a/clang/test/Modules/Inputs/merge-fn-prototype-tags/b.h b/clang/test/Modules/Inputs/merge-fn-prototype-tags/b.h
new file mode 100644
index 00000000000..566381f2edf
--- /dev/null
+++ b/clang/test/Modules/Inputs/merge-fn-prototype-tags/b.h
@@ -0,0 +1 @@
+struct stat;
diff --git a/clang/test/Modules/Inputs/merge-fn-prototype-tags/c.h b/clang/test/Modules/Inputs/merge-fn-prototype-tags/c.h
new file mode 100644
index 00000000000..cb526241743
--- /dev/null
+++ b/clang/test/Modules/Inputs/merge-fn-prototype-tags/c.h
@@ -0,0 +1,4 @@
+#ifndef _STAT_H_
+#define _STAT_H_
+struct stat {};
+#endif
diff --git a/clang/test/Modules/Inputs/merge-fn-prototype-tags/module.modulemap b/clang/test/Modules/Inputs/merge-fn-prototype-tags/module.modulemap
new file mode 100644
index 00000000000..b324f05abf1
--- /dev/null
+++ b/clang/test/Modules/Inputs/merge-fn-prototype-tags/module.modulemap
@@ -0,0 +1,5 @@
+module M {
+ header "a.h"
+ module mod_c { header "c.h" }
+ header "b.h"
+}
diff --git a/clang/test/Modules/merge-fn-prototype-tags.c b/clang/test/Modules/merge-fn-prototype-tags.c
new file mode 100644
index 00000000000..f43f1dc49d9
--- /dev/null
+++ b/clang/test/Modules/merge-fn-prototype-tags.c
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -x c -I%S/Inputs/merge-fn-prototype-tags -verify %s
+// RUN: %clang_cc1 -fmodules -fmodule-map-file=%S/Inputs/merge-fn-prototype-tags/module.modulemap -fmodules-cache-path=%t -x c -I%S/Inputs/merge-fn-prototype-tags -verify %s
+
+#include "c.h"
+void mmalloc_attach() { struct stat sbuf; }
+
+// expected-no-diagnostics
OpenPOWER on IntegriCloud