summarylogtreecommitdiffstats
path: root/0002-Fix-handling-of-abi_tag-attribute-on-namespaces.patch
diff options
context:
space:
mode:
Diffstat (limited to '0002-Fix-handling-of-abi_tag-attribute-on-namespaces.patch')
-rw-r--r--0002-Fix-handling-of-abi_tag-attribute-on-namespaces.patch128
1 files changed, 128 insertions, 0 deletions
diff --git a/0002-Fix-handling-of-abi_tag-attribute-on-namespaces.patch b/0002-Fix-handling-of-abi_tag-attribute-on-namespaces.patch
new file mode 100644
index 000000000000..1e5a3b6ade6e
--- /dev/null
+++ b/0002-Fix-handling-of-abi_tag-attribute-on-namespaces.patch
@@ -0,0 +1,128 @@
+>From 092a55679cf2a27b286118c8e425248a0c52dc90 Mon Sep 17 00:00:00 2001
+From: Stephan Bergmann <sbergman@redhat.com>
+Date: Wed, 9 Dec 2015 11:33:35 +0100
+Subject: [PATCH 2/2] Fix handling of abi_tag attribute on namespaces
+
+...to match GCC behavior:
+
+* Forbid the attribute on unnamed namespaces. (GCC merely produces a warning
+ instead of an error for unnamed or non-inline namespaces, though.)
+
+* When no tags are given for a (named, inline) namespace, use the namespace's
+ name as tag.
+---
+ include/clang/Basic/DiagnosticSemaKinds.td | 2 ++
+ lib/Sema/SemaDeclAttr.cpp | 24 ++++++++++++++++--------
+ test/SemaCXX/attr-abi-tag-syntax.cpp | 20 ++++++++++++++++++++
+ test/SemaCXX/attr-abi-tag.cpp | 13 +++++++++++++
+ 4 files changed, 51 insertions(+), 8 deletions(-)
+ create mode 100644 test/SemaCXX/attr-abi-tag-syntax.cpp
+ create mode 100644 test/SemaCXX/attr-abi-tag.cpp
+
+diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
+index c1931f6..2bda8c0 100644
+--- a/include/clang/Basic/DiagnosticSemaKinds.td
++++ b/include/clang/Basic/DiagnosticSemaKinds.td
+@@ -4137,6 +4137,8 @@ def err_redefinition_extern_inline : Error<
+ "%select{C99 mode|C++}1">;
+ def err_attr_abi_tag_only_on_inline_namespace :
+ Error<"abi_tag attribute only allowed on inline namespaces">;
++def err_attr_abi_tag_only_on_named_namespace :
++ Error<"abi_tag attribute only allowed on named namespaces">;
+ def err_abi_tag_on_redeclaration :
+ Error<"cannot add abi_tag attribute in redeclaration">;
+ def err_new_abi_tag_on_redeclaration :
+diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
+index e3bc97b..0fc1384 100644
+--- a/lib/Sema/SemaDeclAttr.cpp
++++ b/lib/Sema/SemaDeclAttr.cpp
+@@ -4423,7 +4423,9 @@ static void handleDeclspecThreadAttr(Sema &S, Decl *D,
+
+ static void handleAbiTagAttr(Sema &S, Decl *D,
+ const AttributeList &Attr) {
+- if (!checkAttributeAtLeastNumArgs(S, Attr, 1))
++ const auto *NS = dyn_cast<NamespaceDecl>(D);
++
++ if (!checkAttributeAtLeastNumArgs(S, Attr, NS ? 0 : 1))
+ return;
+
+ SmallVector<std::string, 4> Tags;
+@@ -4436,17 +4438,23 @@ static void handleAbiTagAttr(Sema &S, Decl *D,
+
+ Tags.push_back(Tag);
+ }
++
++ if (NS && !NS->isInline()) {
++ S.Diag(Attr.getLoc(), diag::err_attr_abi_tag_only_on_inline_namespace);
++ return;
++ }
++ if (NS && NS->isAnonymousNamespace()) {
++ S.Diag(Attr.getLoc(), diag::err_attr_abi_tag_only_on_named_namespace);
++ return;
++ }
++ if (NS && Attr.getNumArgs() == 0) {
++ Tags.push_back(NS->getName());
++ }
++
+ // store tags sorted and without duplicates
+ std::sort(Tags.begin(), Tags.end());
+ Tags.erase(std::unique(Tags.begin(), Tags.end()), Tags.end());
+
+- if (const auto *NS = dyn_cast<NamespaceDecl>(D)) {
+- if (!NS->isInline()) {
+- S.Diag(Attr.getLoc(), diag::err_attr_abi_tag_only_on_inline_namespace);
+- return;
+- }
+- }
+-
+ const auto *CD = D->getCanonicalDecl();
+ if (CD != D) {
+ // redeclarations must not add new abi tags, or abi tags in the first place
+diff --git a/test/SemaCXX/attr-abi-tag-syntax.cpp b/test/SemaCXX/attr-abi-tag-syntax.cpp
+new file mode 100644
+index 0000000..31d900d
+--- /dev/null
++++ b/test/SemaCXX/attr-abi-tag-syntax.cpp
+@@ -0,0 +1,20 @@
++// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
++
++namespace N1 {
++
++namespace __attribute__((__abi_tag__)) {} // \
++ // expected-error {{abi_tag attribute only allowed on inline namespaces}}
++
++namespace N __attribute__((__abi_tag__)) {} // \
++ // expected-error {{abi_tag attribute only allowed on inline namespaces}}
++
++}
++
++namespace N2 {
++
++inline namespace __attribute__((__abi_tag__)) {} // \
++ // expected-error {{abi_tag attribute only allowed on named namespaces}}
++
++inline namespace N __attribute__((__abi_tag__)) {}
++
++}
+diff --git a/test/SemaCXX/attr-abi-tag.cpp b/test/SemaCXX/attr-abi-tag.cpp
+new file mode 100644
+index 0000000..098ce86
+--- /dev/null
++++ b/test/SemaCXX/attr-abi-tag.cpp
+@@ -0,0 +1,13 @@
++// RUN: %clang_cc1 -x c++ -std=c++11 -triple x86_64-unknown-linux -emit-llvm < %s | FileCheck %s
++
++// CHECK: @_Z5Func1B6Names1v()
++inline namespace Names1 __attribute__((__abi_tag__)) {
++ class C1 {};
++}
++C1 Func1() { return C1(); }
++
++// CHECK: @_Z5Func2B4Tag1B4Tag2v()
++inline namespace Names2 __attribute__((__abi_tag__("Tag1", "Tag2"))) {
++ class C2 {};
++}
++C2 Func2() { return C2(); }
+--
+2.5.0
+