r325520 - Add several more attributes to be parsed in C with [[]] when -fdouble-square-bracket-attributes is specified.

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 19 09:32:07 PST 2018


Author: aaronballman
Date: Mon Feb 19 09:32:07 2018
New Revision: 325520

URL: http://llvm.org/viewvc/llvm-project?rev=325520&view=rev
Log:
Add several more attributes to be parsed in C with [[]] when -fdouble-square-bracket-attributes is specified.

Also flags a few attributes that should not be available with the C spelling as they only matter in C++.

Added:
    cfe/trunk/test/Sema/attr-cx2.c
Modified:
    cfe/trunk/include/clang/Basic/Attr.td

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=325520&r1=325519&r2=325520&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Mon Feb 19 09:32:07 2018
@@ -534,7 +534,7 @@ def AbiTag : Attr {
 }
 
 def AddressSpace : TypeAttr {
-  let Spellings = [Clang<"address_space">];
+  let Spellings = [Clang<"address_space", 1>];
   let Args = [IntArgument<"AddressSpace">];
   let Documentation = [Undocumented];
 }
@@ -598,18 +598,18 @@ def Artificial : InheritableAttr {
 }
 
 def XRayInstrument : InheritableAttr {
-  let Spellings = [Clang<"xray_always_instrument">,
-                   Clang<"xray_never_instrument">];
+  let Spellings = [Clang<"xray_always_instrument", 1>,
+                   Clang<"xray_never_instrument", 1>];
   let Subjects = SubjectList<[Function, ObjCMethod]>;
   let Accessors = [Accessor<"alwaysXRayInstrument",
-                     [Clang<"xray_always_instrument">]>,
+                     [Clang<"xray_always_instrument", 1>]>,
                    Accessor<"neverXRayInstrument",
-                     [Clang<"xray_never_instrument">]>];
+                     [Clang<"xray_never_instrument", 1>]>];
   let Documentation = [XRayDocs];
 }
 
 def XRayLogArgs : InheritableAttr {
-  let Spellings = [Clang<"xray_log_args">];
+  let Spellings = [Clang<"xray_log_args", 1>];
   let Subjects = SubjectList<[Function, ObjCMethod]>;
   let Args = [UnsignedArgument<"ArgumentCount">];
   let Documentation = [XRayDocs];
@@ -735,7 +735,7 @@ def ExternalSourceSymbol : InheritableAt
 }
 
 def Blocks : InheritableAttr {
-  let Spellings = [Clang<"blocks">];
+  let Spellings = [Clang<"blocks", 1>];
   let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
   let Documentation = [Undocumented];
 }
@@ -1072,19 +1072,19 @@ def Final : InheritableAttr {
 }
 
 def MinSize : InheritableAttr {
-  let Spellings = [Clang<"minsize">];
+  let Spellings = [Clang<"minsize", 1>];
   let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;
   let Documentation = [Undocumented];
 }
 
 def FlagEnum : InheritableAttr {
-  let Spellings = [Clang<"flag_enum">];
+  let Spellings = [Clang<"flag_enum", 1>];
   let Subjects = SubjectList<[Enum]>;
   let Documentation = [FlagEnumDocs];
 }
 
 def EnumExtensibility : InheritableAttr {
-  let Spellings = [Clang<"enum_extensibility">];
+  let Spellings = [Clang<"enum_extensibility", 1>];
   let Subjects = SubjectList<[Enum]>;
   let Args = [EnumArgument<"Extensibility", "Kind",
               ["closed", "open"], ["Closed", "Open"]>];
@@ -1169,6 +1169,8 @@ def LayoutVersion : InheritableAttr, Tar
 }
 
 def TrivialABI : InheritableAttr {
+  // This attribute does not have a C [[]] spelling because it requires the
+  // CPlusPlus language option.
   let Spellings = [Clang<"trivial_abi">];
   let Subjects = SubjectList<[CXXRecord]>;
   let Documentation = [TrivialABIDocs];
@@ -1259,13 +1261,13 @@ def Naked : InheritableAttr {
 }
 
 def NeonPolyVectorType : TypeAttr {
-  let Spellings = [Clang<"neon_polyvector_type">];
+  let Spellings = [Clang<"neon_polyvector_type", 1>];
   let Args = [IntArgument<"NumElements">];
   let Documentation = [Undocumented];
 }
 
 def NeonVectorType : TypeAttr {
-  let Spellings = [Clang<"neon_vector_type">];
+  let Spellings = [Clang<"neon_vector_type", 1>];
   let Args = [IntArgument<"NumElements">];
   let Documentation = [Undocumented];
 }
@@ -1277,7 +1279,7 @@ def ReturnsTwice : InheritableAttr {
 }
 
 def DisableTailCalls : InheritableAttr {
-  let Spellings = [Clang<"disable_tail_calls">];
+  let Spellings = [Clang<"disable_tail_calls", 1>];
   let Subjects = SubjectList<[Function, ObjCMethod]>;
   let Documentation = [DisableTailCallsDocs];
 }
@@ -1301,13 +1303,13 @@ def NoDebug : InheritableAttr {
 }
 
 def NoDuplicate : InheritableAttr {
-  let Spellings = [Clang<"noduplicate">];
+  let Spellings = [Clang<"noduplicate", 1>];
   let Subjects = SubjectList<[Function]>;
   let Documentation = [NoDuplicateDocs];
 }
 
 def Convergent : InheritableAttr {
-  let Spellings = [Clang<"convergent">];
+  let Spellings = [Clang<"convergent", 1>];
   let Subjects = SubjectList<[Function]>;
   let Documentation = [ConvergentDocs];
 }
@@ -1409,7 +1411,7 @@ def ReturnsNonNull : InheritableAttr {
 // pass_object_size(N) indicates that the parameter should have
 // __builtin_object_size with Type=N evaluated on the parameter at the callsite.
 def PassObjectSize : InheritableParamAttr {
-  let Spellings = [Clang<"pass_object_size">];
+  let Spellings = [Clang<"pass_object_size", 1>];
   let Args = [IntArgument<"Type">];
   let Subjects = SubjectList<[ParmVar]>;
   let Documentation = [PassObjectSizeDocs];
@@ -1469,7 +1471,7 @@ def NoInstrumentFunction : InheritableAt
 }
 
 def NotTailCalled : InheritableAttr {
-  let Spellings = [Clang<"not_tail_called">];
+  let Spellings = [Clang<"not_tail_called", 1>];
   let Subjects = SubjectList<[Function]>;
   let Documentation = [NotTailCalledDocs];
 }
@@ -1632,13 +1634,13 @@ def ObjCBoxable : Attr {
 }
 
 def OptimizeNone : InheritableAttr {
-  let Spellings = [Clang<"optnone">];
+  let Spellings = [Clang<"optnone", 1>];
   let Subjects = SubjectList<[Function, ObjCMethod]>;
   let Documentation = [OptnoneDocs];
 }
 
 def Overloadable : Attr {
-  let Spellings = [Clang<"overloadable">];
+  let Spellings = [Clang<"overloadable", 1>];
   let Subjects = SubjectList<[Function], ErrorDiag>;
   let Documentation = [OverloadableDocs];
 }
@@ -1650,11 +1652,11 @@ def Override : InheritableAttr {
 }
 
 def Ownership : InheritableAttr {
-  let Spellings = [Clang<"ownership_holds">, Clang<"ownership_returns">,
-                   Clang<"ownership_takes">];
-  let Accessors = [Accessor<"isHolds", [Clang<"ownership_holds">]>,
-                   Accessor<"isReturns", [Clang<"ownership_returns">]>,
-                   Accessor<"isTakes", [Clang<"ownership_takes">]>];
+  let Spellings = [Clang<"ownership_holds", 1>, Clang<"ownership_returns", 1>,
+                   Clang<"ownership_takes", 1>];
+  let Accessors = [Accessor<"isHolds", [Clang<"ownership_holds", 1>]>,
+                   Accessor<"isReturns", [Clang<"ownership_returns", 1>]>,
+                   Accessor<"isTakes", [Clang<"ownership_takes", 1>]>];
   let AdditionalMembers = [{
     enum OwnershipKind { Holds, Returns, Takes };
     OwnershipKind getOwnKind() const {
@@ -1710,6 +1712,8 @@ def ReqdWorkGroupSize : InheritableAttr
 }
 
 def RequireConstantInit : InheritableAttr {
+  // This attribute does not have a C [[]] spelling because it requires the
+  // CPlusPlus language option.
   let Spellings = [Clang<"require_constant_initialization">];
   let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
   let Documentation = [RequireConstantInitDocs];
@@ -1788,23 +1792,23 @@ def StdCall : InheritableAttr {
 }
 
 def SwiftCall : InheritableAttr {
-  let Spellings = [Clang<"swiftcall">];
+  let Spellings = [Clang<"swiftcall", 1>];
 //  let Subjects = SubjectList<[Function]>;
   let Documentation = [SwiftCallDocs];
 }
 
 def SwiftContext : ParameterABIAttr {
-  let Spellings = [Clang<"swift_context">];
+  let Spellings = [Clang<"swift_context", 1>];
   let Documentation = [SwiftContextDocs];
 }
 
 def SwiftErrorResult : ParameterABIAttr {
-  let Spellings = [Clang<"swift_error_result">];
+  let Spellings = [Clang<"swift_error_result", 1>];
   let Documentation = [SwiftErrorResultDocs];
 }
 
 def SwiftIndirectResult : ParameterABIAttr {
-  let Spellings = [Clang<"swift_indirect_result">];
+  let Spellings = [Clang<"swift_indirect_result", 1>];
   let Documentation = [SwiftIndirectResultDocs];
 }
 
@@ -1828,25 +1832,25 @@ def ThisCall : InheritableAttr {
 }
 
 def VectorCall : InheritableAttr {
-  let Spellings = [Clang<"vectorcall">, Keyword<"__vectorcall">,
+  let Spellings = [Clang<"vectorcall", 1>, Keyword<"__vectorcall">,
                    Keyword<"_vectorcall">];
 //  let Subjects = [Function, ObjCMethod];
   let Documentation = [VectorCallDocs];
 }
 
 def Pascal : InheritableAttr {
-  let Spellings = [Clang<"pascal">, Keyword<"__pascal">, Keyword<"_pascal">];
+  let Spellings = [Clang<"pascal", 1>, Keyword<"__pascal">, Keyword<"_pascal">];
 //  let Subjects = [Function, ObjCMethod];
   let Documentation = [Undocumented];
 }
 
 def PreserveMost : InheritableAttr {
-  let Spellings = [Clang<"preserve_most">];
+  let Spellings = [Clang<"preserve_most", 1>];
   let Documentation = [PreserveMostDocs];
 }
 
 def PreserveAll : InheritableAttr {
-  let Spellings = [Clang<"preserve_all">];
+  let Spellings = [Clang<"preserve_all", 1>];
   let Documentation = [PreserveAllDocs];
 }
 
@@ -1922,7 +1926,7 @@ def TransparentUnion : InheritableAttr {
 }
 
 def Unavailable : InheritableAttr {
-  let Spellings = [Clang<"unavailable">];
+  let Spellings = [Clang<"unavailable", 1>];
   let Args = [StringArgument<"Message", 1>,
               EnumArgument<"ImplicitReason", "ImplicitReason",
                 ["", "", "", ""],
@@ -2032,7 +2036,7 @@ def Visibility : InheritableAttr {
 
 def TypeVisibility : InheritableAttr {
   let Clone = 0;
-  let Spellings = [Clang<"type_visibility">];
+  let Spellings = [Clang<"type_visibility", 1>];
   let Args = [EnumArgument<"Visibility", "VisibilityType",
                            ["default", "hidden", "internal", "protected"],
                            ["Default", "Hidden", "Hidden", "Protected"]>];
@@ -2041,6 +2045,9 @@ def TypeVisibility : InheritableAttr {
 }
 
 def VecReturn : InheritableAttr {
+  // This attribute does not have a C [[]] spelling because it only appertains
+  // to C++ struct/class/union.
+  // FIXME: should this attribute have a CPlusPlus language option?
   let Spellings = [Clang<"vecreturn">];
   let Subjects = SubjectList<[CXXRecord], ErrorDiag>;
   let Documentation = [Undocumented];
@@ -2067,7 +2074,7 @@ def Weak : InheritableAttr {
 }
 
 def WeakImport : InheritableAttr {
-  let Spellings = [Clang<"weak_import">];
+  let Spellings = [Clang<"weak_import", 1>];
   let Documentation = [Undocumented];
 }
 
@@ -2080,7 +2087,7 @@ def WeakRef : InheritableAttr {
 }
 
 def LTOVisibilityPublic : InheritableAttr {
-  let Spellings = [Clang<"lto_visibility_public">];
+  let Spellings = [Clang<"lto_visibility_public", 1>];
   let Subjects = SubjectList<[Record]>;
   let Documentation = [LTOVisibilityDocs];
 }
@@ -2110,7 +2117,7 @@ def X86ForceAlignArgPointer : Inheritabl
 }
 
 def NoSanitize : InheritableAttr {
-  let Spellings = [Clang<"no_sanitize">];
+  let Spellings = [Clang<"no_sanitize", 1>];
   let Args = [VariadicStringArgument<"Sanitizers">];
   let Subjects = SubjectList<[Function, ObjCMethod, GlobalVar], ErrorDiag>;
   let Documentation = [NoSanitizeDocs];
@@ -2133,7 +2140,7 @@ def NoSanitizeSpecific : InheritableAttr
   let Spellings = [GCC<"no_address_safety_analysis">,
                    GCC<"no_sanitize_address">,
                    GCC<"no_sanitize_thread">,
-                   Clang<"no_sanitize_memory">];
+                   Clang<"no_sanitize_memory", 1>];
   let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag>;
   let Documentation = [NoSanitizeAddressDocs, NoSanitizeThreadDocs,
                        NoSanitizeMemoryDocs];
@@ -2266,7 +2273,7 @@ def RequiresCapability : InheritableAttr
 }
 
 def NoThreadSafetyAnalysis : InheritableAttr {
-  let Spellings = [Clang<"no_thread_safety_analysis">];
+  let Spellings = [Clang<"no_thread_safety_analysis", 1>];
   let Subjects = SubjectList<[Function]>;
   let Documentation = [Undocumented];
 }

Added: cfe/trunk/test/Sema/attr-cx2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-cx2.c?rev=325520&view=auto
==============================================================================
--- cfe/trunk/test/Sema/attr-cx2.c (added)
+++ cfe/trunk/test/Sema/attr-cx2.c Mon Feb 19 09:32:07 2018
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -fdouble-square-bracket-attributes %s
+
+struct S {};
+struct S * [[clang::address_space(1)]] Foo;
+
+enum [[clang::enum_extensibility(open)]] EnumOpen {
+  C0 = 1, C1 = 10
+};
+
+enum [[clang::flag_enum]] EnumFlag {
+  D0 = 1, D1 = 8
+};
+
+void foo(void *c) [[clang::overloadable]];
+void foo(char *c) [[clang::overloadable]];
+
+void context_okay(void *context [[clang::swift_context]]) [[clang::swiftcall]];
+void context_okay2(void *context [[clang::swift_context]], void *selfType, char **selfWitnessTable) [[clang::swiftcall]];
+
+void *f1(void) [[clang::ownership_returns(foo)]];
+void *f2() [[clang::ownership_returns(foo)]]; // expected-warning {{'ownership_returns' attribute only applies to non-K&R-style functions}}
+
+void foo2(void) [[clang::unavailable("not available - replaced")]]; // expected-note {{'foo2' has been explicitly marked unavailable here}}
+void bar(void) {
+  foo2(); // expected-error {{'foo2' is unavailable: not available - replaced}}
+}




More information about the cfe-commits mailing list