From 1d2a84e04f6c7953e9c6a0b9680e1235410e5d1e Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Tue, 19 Jan 2016 22:54:26 +0000 Subject: [PATCH] Allow __attribute__((mode)) to appertain to field declarations again. Corrects compile issues with LibreOffice. Patch by Stephan Bergmann git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@258213 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/Attr.td | 4 ++-- include/clang/Basic/DiagnosticSemaKinds.td | 3 ++- include/clang/Sema/AttributeList.h | 3 ++- lib/Sema/SemaDeclAttr.cpp | 4 ++-- test/Sema/attr-mode.c | 8 ++++++-- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td index 06228f2059..dbb83e28b2 100644 --- a/include/clang/Basic/Attr.td +++ b/include/clang/Basic/Attr.td @@ -879,8 +879,8 @@ def MipsInterrupt : InheritableAttr, TargetSpecificAttr { def Mode : Attr { let Spellings = [GCC<"mode">]; - let Subjects = SubjectList<[Var, TypedefName], ErrorDiag, - "ExpectedVariableOrTypedef">; + let Subjects = SubjectList<[Var, TypedefName, Field], ErrorDiag, + "ExpectedVariableFieldOrTypedef">; let Args = [IdentifierArgument<"Mode">]; let Documentation = [Undocumented]; } diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index ade42225eb..d031b53bef 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -2441,7 +2441,8 @@ def warn_attribute_wrong_decl_type : Warning< "Objective-C instance methods|init methods of interface or class extension declarations|" "variables, functions and classes|Objective-C protocols|" "functions and global variables|structs, unions, and typedefs|structs and typedefs|" - "interface or protocol declarations|kernel functions|non-K&R-style functions}1">, + "interface or protocol declarations|kernel functions|non-K&R-style functions|" + "variables, fields and typedefs}1">, InGroup; def err_attribute_wrong_decl_type : Error; def warn_type_attribute_wrong_type : Warning< diff --git a/include/clang/Sema/AttributeList.h b/include/clang/Sema/AttributeList.h index e32781d35f..1a53a2c3d4 100644 --- a/include/clang/Sema/AttributeList.h +++ b/include/clang/Sema/AttributeList.h @@ -855,7 +855,8 @@ enum AttributeDeclKind { ExpectedStructOrTypedef, ExpectedObjectiveCInterfaceOrProtocol, ExpectedKernelFunction, - ExpectedFunctionWithProtoType + ExpectedFunctionWithProtoType, + ExpectedVariableFieldOrTypedef }; } // end namespace clang diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index f670b52d0d..31741be618 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -3392,7 +3392,7 @@ static void handleModeAttr(Sema &S, Decl *D, const AttributeList &Attr) { if (TypedefNameDecl *TD = dyn_cast(D)) OldTy = TD->getUnderlyingType(); else - OldTy = cast(D)->getType(); + OldTy = cast(D)->getType(); // Base type can also be a vector type (see PR17453). // Distinguish between base type and base element type. @@ -3465,7 +3465,7 @@ static void handleModeAttr(Sema &S, Decl *D, const AttributeList &Attr) { if (TypedefNameDecl *TD = dyn_cast(D)) TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy); else - cast(D)->setType(NewTy); + cast(D)->setType(NewTy); D->addAttr(::new (S.Context) ModeAttr(Attr.getRange(), S.Context, Name, diff --git a/test/Sema/attr-mode.c b/test/Sema/attr-mode.c index 77bd2f737a..179b1819b1 100644 --- a/test/Sema/attr-mode.c +++ b/test/Sema/attr-mode.c @@ -24,8 +24,8 @@ typedef unsigned unwind_word __attribute((mode(unwind_word))); int **__attribute((mode(QI)))* i32; // expected-error{{mode attribute}} -__attribute__((mode(QI))) int invalid_func() { return 1; } // expected-error{{'mode' attribute only applies to variables and typedefs}} -enum invalid_enum { A1 __attribute__((mode(QI))) }; // expected-error{{'mode' attribute only applies to variables and typedefs}} +__attribute__((mode(QI))) int invalid_func() { return 1; } // expected-error{{'mode' attribute only applies to variables, fields and typedefs}} +enum invalid_enum { A1 __attribute__((mode(QI))) }; // expected-error{{'mode' attribute only applies to variables, fields and typedefs}} typedef _Complex double c32 __attribute((mode(SC))); int c32_test[sizeof(c32) == 8 ? 1 : -1]; @@ -76,3 +76,7 @@ void test_TCtype(c128ibm *a) { f_ft128_complex_arg (a); } #else #error Unknown test architecture. #endif + +struct S { + int n __attribute((mode(HI))); +}; -- 2.50.1