summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>2017-07-01 00:06:47 +0000
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>2017-07-01 00:06:47 +0000
commitdf0ee34bc2523f11b907311670c776cb3de108c1 (patch)
tree1426e07d6db57ced9bfe03e6e1fe9b4f00e298c8 /clang/test
parent057c82cf25a0c8bd4150eb715310b1d74a538aac (diff)
downloadbcm5719-llvm-df0ee34bc2523f11b907311670c776cb3de108c1.tar.gz
bcm5719-llvm-df0ee34bc2523f11b907311670c776cb3de108c1.zip
[Modules] Implement ODR-like semantics for tag types in C/ObjC
Allow ODR for ObjC/C in the sense that we won't keep more that one definition around (merge them). However, ensure the decl pass the structural compatibility check in C11 6.2.7/1, for that, reuse the structural equivalence checks used by the ASTImporter. Few other considerations: - Create error diagnostics for tag types mismatches and thread them into the structural equivalence checks. - Note that by doing this we only support redefinition between types that are considered "compatible types" by C. This is mixed approach of the suggestions discussed in http://lists.llvm.org/pipermail/cfe-dev/2017-March/053257.html Differential Revision: https://reviews.llvm.org/D31778 rdar://problem/31909368 llvm-svn: 306918
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Modules/Inputs/F.framework/Headers/F.h1
-rw-r--r--clang/test/Modules/Inputs/F.framework/Modules/module.modulemap7
-rw-r--r--clang/test/Modules/Inputs/F.framework/Modules/module.private.modulemap7
-rw-r--r--clang/test/Modules/Inputs/F.framework/PrivateHeaders/NS.h19
-rw-r--r--clang/test/Modules/elaborated-type-specifier-from-hidden-module.m7
-rw-r--r--clang/test/Modules/redefinition-c-tagtypes.m48
-rw-r--r--clang/test/Modules/redefinition-same-header.m10
7 files changed, 86 insertions, 13 deletions
diff --git a/clang/test/Modules/Inputs/F.framework/Headers/F.h b/clang/test/Modules/Inputs/F.framework/Headers/F.h
new file mode 100644
index 00000000000..4f705f00e1a
--- /dev/null
+++ b/clang/test/Modules/Inputs/F.framework/Headers/F.h
@@ -0,0 +1 @@
+// F.h
diff --git a/clang/test/Modules/Inputs/F.framework/Modules/module.modulemap b/clang/test/Modules/Inputs/F.framework/Modules/module.modulemap
new file mode 100644
index 00000000000..e414776c536
--- /dev/null
+++ b/clang/test/Modules/Inputs/F.framework/Modules/module.modulemap
@@ -0,0 +1,7 @@
+framework module F [extern_c] [system] {
+ umbrella header "F.h"
+ module * {
+ export *
+ }
+ export *
+}
diff --git a/clang/test/Modules/Inputs/F.framework/Modules/module.private.modulemap b/clang/test/Modules/Inputs/F.framework/Modules/module.private.modulemap
new file mode 100644
index 00000000000..69486a2a641
--- /dev/null
+++ b/clang/test/Modules/Inputs/F.framework/Modules/module.private.modulemap
@@ -0,0 +1,7 @@
+module F.Private [system] {
+ explicit module NS {
+ header "NS.h"
+ export *
+ }
+ export *
+}
diff --git a/clang/test/Modules/Inputs/F.framework/PrivateHeaders/NS.h b/clang/test/Modules/Inputs/F.framework/PrivateHeaders/NS.h
new file mode 100644
index 00000000000..5e947ba9051
--- /dev/null
+++ b/clang/test/Modules/Inputs/F.framework/PrivateHeaders/NS.h
@@ -0,0 +1,19 @@
+struct NS {
+ int a;
+ int b;
+};
+
+enum NSE {
+ FST = 22,
+ SND = 43,
+ TRD = 55
+};
+
+#define NS_ENUM(_type, _name) \
+ enum _name : _type _name; \
+ enum _name : _type
+
+typedef NS_ENUM(int, NSMyEnum) {
+ MinX = 11,
+ MinXOther = MinX,
+};
diff --git a/clang/test/Modules/elaborated-type-specifier-from-hidden-module.m b/clang/test/Modules/elaborated-type-specifier-from-hidden-module.m
index 0ca1c24bba0..571ccb9d95c 100644
--- a/clang/test/Modules/elaborated-type-specifier-from-hidden-module.m
+++ b/clang/test/Modules/elaborated-type-specifier-from-hidden-module.m
@@ -4,12 +4,11 @@
@import ElaboratedTypeStructs.Empty; // The structs are now hidden.
struct S1 *x;
struct S2 *y;
-// FIXME: compatible definition should not be an error.
-struct S2 { int x; }; // expected-error {{redefinition}}
+struct S2 { int x; };
struct S3 *z;
// Incompatible definition.
-struct S3 { float y; }; // expected-error {{redefinition}}
-// expected-note@elaborated-type-structs.h:* 2 {{previous definition is here}}
+struct S3 { float y; }; // expected-error {{has incompatible definitions}} // expected-note {{field has name}}
+// expected-note@Inputs/elaborated-type-structs.h:3 {{field has name}}
@import ElaboratedTypeStructs.Structs;
diff --git a/clang/test/Modules/redefinition-c-tagtypes.m b/clang/test/Modules/redefinition-c-tagtypes.m
new file mode 100644
index 00000000000..a01f11bd74c
--- /dev/null
+++ b/clang/test/Modules/redefinition-c-tagtypes.m
@@ -0,0 +1,48 @@
+// RUN: rm -rf %t.cache
+// RUN: %clang_cc1 -fsyntax-only %s -fmodules -fmodules-cache-path=%t.cache \
+// RUN: -fimplicit-module-maps -F%S/Inputs -verify
+// RUN: %clang_cc1 -fsyntax-only %s -fmodules -fmodules-cache-path=%t.cache \
+// RUN: -fimplicit-module-maps -F%S/Inputs -DCHANGE_TAGS -verify
+#include "F/F.h"
+
+#ifndef CHANGE_TAGS
+// expected-no-diagnostics
+#endif
+
+struct NS {
+ int a;
+#ifndef CHANGE_TAGS
+ int b;
+#else
+ int c; // expected-note {{field has name 'c' here}}
+ // expected-error@redefinition-c-tagtypes.m:12 {{type 'struct NS' has incompatible definitions}}
+ // expected-note@Inputs/F.framework/PrivateHeaders/NS.h:3 {{field has name 'b' here}}
+#endif
+};
+
+enum NSE {
+ FST = 22,
+#ifndef CHANGE_TAGS
+ SND = 43,
+#else
+ SND = 44, // expected-note {{enumerator 'SND' with value 44 here}}
+ // expected-error@redefinition-c-tagtypes.m:23 {{type 'enum NSE' has incompatible definitions}}
+ // expected-note@Inputs/F.framework/PrivateHeaders/NS.h:8 {{enumerator 'SND' with value 43 here}}
+#endif
+ TRD = 55
+};
+
+#define NS_ENUM(_type, _name) \
+ enum _name : _type _name; \
+ enum _name : _type
+
+typedef NS_ENUM(int, NSMyEnum) {
+ MinX = 11,
+#ifndef CHANGE_TAGS
+ MinXOther = MinX,
+#else
+ MinXOther = TRD, // expected-note {{enumerator 'MinXOther' with value 55 here}}
+ // expected-error@redefinition-c-tagtypes.m:39 {{type 'enum NSMyEnum' has incompatible definitions}}
+ // expected-note@Inputs/F.framework/PrivateHeaders/NS.h:18 {{enumerator 'MinXOther' with value 11 here}}
+#endif
+};
diff --git a/clang/test/Modules/redefinition-same-header.m b/clang/test/Modules/redefinition-same-header.m
index f1c6cbbcaa2..8c180f64322 100644
--- a/clang/test/Modules/redefinition-same-header.m
+++ b/clang/test/Modules/redefinition-same-header.m
@@ -6,15 +6,7 @@
// expected-note-re@Inputs/SameHeader/B.h:3 {{'{{.*}}C.h' included multiple times, additional include site in header from module 'X.B'}}
// expected-note@Inputs/SameHeader/module.modulemap:6 {{X.B defined here}}
// expected-note-re@redefinition-same-header.m:20 {{'{{.*}}C.h' included multiple times, additional include site here}}
+// expected-warning@Inputs/SameHeader/C.h:9 {{typedef requires a name}}
-// expected-error@Inputs/SameHeader/C.h:5 {{redefinition of 'aaa'}}
-// expected-note-re@Inputs/SameHeader/B.h:3 {{'{{.*}}C.h' included multiple times, additional include site in header from module 'X.B'}}
-// expected-note@Inputs/SameHeader/module.modulemap:6 {{X.B defined here}}
-// expected-note-re@redefinition-same-header.m:20 {{'{{.*}}C.h' included multiple times, additional include site here}}
-
-// expected-error@Inputs/SameHeader/C.h:9 {{redefinition of 'fd_set'}}
-// expected-note-re@Inputs/SameHeader/B.h:3 {{'{{.*}}C.h' included multiple times, additional include site in header from module 'X.B'}}
-// expected-note@Inputs/SameHeader/module.modulemap:6 {{X.B defined here}}
-// expected-note-re@redefinition-same-header.m:20 {{'{{.*}}C.h' included multiple times, additional include site here}}
#include "A.h" // maps to a modular
#include "C.h" // textual include
OpenPOWER on IntegriCloud