aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Gouly <joey.gouly@arm.com>2013-03-14 09:54:43 +0000
committerJoey Gouly <joey.gouly@arm.com>2013-03-14 09:54:43 +0000
commit96cead513761d287c88a4f05c712aee3b26b9d6f (patch)
tree24c61d7927c36601c108c6ee72ff46262b1989b4
parent8ef19a22956defa392df46c79e2d499ab7b16647 (diff)
Add support for the 'endian' attribute for OpenCL.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177035 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/Attr.td5
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td2
-rw-r--r--lib/Sema/SemaDeclAttr.cpp13
-rw-r--r--test/SemaOpenCL/endian-attr.cl9
4 files changed, 29 insertions, 0 deletions
diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td
index 53f83e1acf..88cf0f9644 100644
--- a/include/clang/Basic/Attr.td
+++ b/include/clang/Basic/Attr.td
@@ -632,6 +632,11 @@ def ReqdWorkGroupSize : InheritableAttr {
UnsignedArgument<"ZDim">];
}
+def Endian : InheritableAttr {
+ let Spellings = [GNU<"endian">];
+ let Args = [IdentifierArgument<"platform">];
+}
+
def WorkGroupSizeHint : InheritableAttr {
let Spellings = [GNU<"work_group_size_hint">];
let Args = [UnsignedArgument<"XDim">,
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 87f95aca4b..bd3d1b4e10 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2150,6 +2150,8 @@ def warn_attribute_protected_visibility :
Warning<"target does not support 'protected' visibility; using 'default'">,
InGroup<DiagGroup<"unsupported-visibility">>;
def err_mismatched_visibility: Error<"visibility does not match previous declaration">;
+def warn_attribute_unknown_endian : Warning<"unknown endian '%0'">,
+ InGroup<IgnoredAttributes>;
def note_previous_attribute : Note<"previous attribute is here">;
def err_unknown_machine_mode : Error<"unknown machine mode %0">;
def err_unsupported_machine_mode : Error<"unsupported machine mode %0">;
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index c9ccf80191..c6e28c3e61 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -2799,6 +2799,15 @@ static void handleVecTypeHint(Sema &S, Decl *D, const AttributeList &Attr) {
ParmType, Attr.getLoc()));
}
+static void handleEndianAttr(Sema &S, Decl *D, const AttributeList &Attr) {
+ if (!dyn_cast<VarDecl>(D))
+ S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type) << "endian"
+ << 9;
+ StringRef EndianType = Attr.getParameterName()->getName();
+ if (EndianType != "host" && EndianType != "device")
+ S.Diag(Attr.getLoc(), diag::warn_attribute_unknown_endian) << EndianType;
+}
+
SectionAttr *Sema::mergeSectionAttr(Decl *D, SourceRange Range,
StringRef Name,
unsigned AttrSpellingListIndex) {
@@ -4783,6 +4792,10 @@ static void ProcessInheritableDeclAttr(Sema &S, Scope *scope, Decl *D,
case AttributeList::AT_VecTypeHint:
handleVecTypeHint(S, D, Attr); break;
+ case AttributeList::AT_Endian:
+ handleEndianAttr(S, D, Attr);
+ break;
+
case AttributeList::AT_InitPriority:
handleInitPriorityAttr(S, D, Attr); break;
diff --git a/test/SemaOpenCL/endian-attr.cl b/test/SemaOpenCL/endian-attr.cl
new file mode 100644
index 0000000000..e851cdf90b
--- /dev/null
+++ b/test/SemaOpenCL/endian-attr.cl
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify %s
+
+constant long a __attribute__((endian(host))) = 100;
+
+constant long b __attribute__((endian(device))) = 100;
+
+constant long c __attribute__((endian(none))) = 100; // expected-warning {{unknown endian 'none'}}
+
+void func() __attribute__((endian(host))); // expected-warning {{endian attribute only applies to variables}}