[PATCH] D46805: If some platforms do not support an attribute, we should exclude the platform
HLJ2009 created this revision. HLJ2009 added a reviewer: aaron.ballman. Herald added a subscriber: cfe-commits. I tested the alias attribute on my own Apple laptop (Target: x86_64-apple-darwin17.5.0). First, I use __has_attribute to test that the alias is usable or not. The test code is as follows: #include void print() { #if __has_attribute(alias) printf("has attribute"); #else printf("has not attribute"); #endif } int main() { print(); return 0; } Compiled using clang, the output result is has attribute, but when i use the following code to verify #include int oldname = 1; extern int newname __attribute__((alias("oldname"))); // declaration void foo(void) { printf("newname = %d\n", newname); // prints 1 } int main() { foo(); return 0; } It told me alias.c:3:35: error: aliases are not supported on darwin.so we should exclude the platform. Repository: rC Clang https://reviews.llvm.org/D46805 Files: include/clang/Basic/Attr.td utils/TableGen/ClangAttrEmitter.cpp Index: utils/TableGen/ClangAttrEmitter.cpp === --- utils/TableGen/ClangAttrEmitter.cpp +++ utils/TableGen/ClangAttrEmitter.cpp @@ -2784,6 +2784,11 @@ GenerateTargetSpecificAttrCheck(R, Test, FnName, "OSes", "T.getOS()", "llvm::Triple::"); + // If the Negated is 1 in specific, it indicates that the attribute + // is not supported on this platform + if(R->getValueAsBit("Negated")) +Test = "!(" + Test + ")"; + // If one or more CXX ABIs are specified, check those as well. GenerateTargetSpecificAttrCheck(R, Test, FnName, "CXXABIs", "Target.getCXXABI().getKind()", Index: include/clang/Basic/Attr.td === --- include/clang/Basic/Attr.td +++ include/clang/Basic/Attr.td @@ -296,6 +296,9 @@ // Specifies Object Formats for which the target applies, based off the // ObjectFormatType enumeration in Triple.h list ObjectFormats; + // It indicates that a certain attribute is not supported on a specific + // platform, turn on support for this attribute by default + bit Negated = 0; } class TargetArch arches> : TargetSpec { @@ -318,6 +321,13 @@ let ObjectFormats = ["ELF"]; } +// We do not support the alias attribute on Apple platforms, +// so I define a platform other than the Apple platform. +def TargetDarwinNegative : TargetArch<["x86", "x86_64"]> { + let OSes = ["MacOSX"]; + let Negated = 1; +} + // Attribute subject match rules that are used for #pragma clang attribute. // // A instance of AttrSubjectMatcherRule represents an individual match rule. @@ -553,7 +563,8 @@ let Documentation = [Undocumented]; } -def Alias : Attr { +// We do not support alias attribute on Apple platform, so we exclude the platform. +def Alias : Attr, TargetSpecificAttr { let Spellings = [GCC<"alias">]; let Args = [StringArgument<"Aliasee">]; let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag>; Index: utils/TableGen/ClangAttrEmitter.cpp === --- utils/TableGen/ClangAttrEmitter.cpp +++ utils/TableGen/ClangAttrEmitter.cpp @@ -2784,6 +2784,11 @@ GenerateTargetSpecificAttrCheck(R, Test, FnName, "OSes", "T.getOS()", "llvm::Triple::"); + // If the Negated is 1 in specific, it indicates that the attribute + // is not supported on this platform + if(R->getValueAsBit("Negated")) +Test = "!(" + Test + ")"; + // If one or more CXX ABIs are specified, check those as well. GenerateTargetSpecificAttrCheck(R, Test, FnName, "CXXABIs", "Target.getCXXABI().getKind()", Index: include/clang/Basic/Attr.td === --- include/clang/Basic/Attr.td +++ include/clang/Basic/Attr.td @@ -296,6 +296,9 @@ // Specifies Object Formats for which the target applies, based off the // ObjectFormatType enumeration in Triple.h list ObjectFormats; + // It indicates that a certain attribute is not supported on a specific + // platform, turn on support for this attribute by default + bit Negated = 0; } class TargetArch arches> : TargetSpec { @@ -318,6 +321,13 @@ let ObjectFormats = ["ELF"]; } +// We do not support the alias attribute on Apple platforms, +// so I define a platform other than the Apple platform. +def TargetDarwinNegative : TargetArch<["x86", "x86_64"]> { + let OSes = ["MacOSX"]; + let Negated = 1; +} + // Attribute subject match rules that are used for #pragma clang attribute. // // A instance of AttrSubjectMatcherRule represents an individual match rule. @@ -553,7 +563,8 @@ let Documentation = [Undocumented]; } -def Alias : Attr { +// We do not support alias attribute on Apple platform, so we exclude the platform. +def Alias : Attr, TargetSpecificAttr { let Spellin
[PATCH] D46805: If some platforms do not support an attribute, we should exclude the platform
HLJ2009 marked 4 inline comments as done. HLJ2009 added inline comments. Comment at: include/clang/Basic/Attr.td:327 +def TargetDarwinNegative : TargetArch<["x86", "x86_64"]> { + let OSes = ["MacOSX"]; + let Negated = 1; aaron.ballman wrote: > I would expect the OS would be named "Darwin" and not "MacOSX" given the name > of the target. Which flavor should be used, or should both be used? hi,Aaron First, I set OSType to Darwin,but it does not work on my own machine. so I set OSType to MacOSX,and it is ok.Yes, I thought about adding two at the same time, but this needs to modify list OSes to list OSes[]. Repository: rC Clang https://reviews.llvm.org/D46805 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46805: If some platforms do not support an attribute, we should exclude the platform
HLJ2009 added inline comments. Comment at: include/clang/Basic/Attr.td:566-567 -def Alias : Attr { +// We do not support alias attribute on Apple platform, so we exclude the platform. +def Alias : Attr, TargetSpecificAttr { let Spellings = [GCC<"alias">]; rsmith wrote: > Is this really specific to Darwin? I would expect it instead to be specific > to the `ObjectFormat`. And I think listing the object formats that *do* > support aliases seems reasonable (as there's only three of them to list -- > assuming that WAsm actually supports aliases, which I don't know -- and we'd > probably want future object file formats to opt in rather than opting out). Hi, If using this program, we need to define a support alias platform, is not it? This platform needs to include the ArchType in the Triple.h file for the most part, and we need to set the ObjectFormatType to COFF, ELF, and Wasm. But we only want to exclude the few unsupported platforms. If my understanding is not right, please told me. Repository: rC Clang https://reviews.llvm.org/D46805 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46805: If some platforms do not support an attribute, we should exclude the platform
HLJ2009 updated this revision to Diff 147773. HLJ2009 added a comment. Herald added a subscriber: aheejin. listing the object formats that *do* support aliases seems reasonable Repository: rC Clang https://reviews.llvm.org/D46805 Files: include/clang/Basic/Attr.td test/Sema/attr-alias-has.c Index: test/Sema/attr-alias-has.c === --- /dev/null +++ test/Sema/attr-alias-has.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple wasm64-unknown-unknown -fsyntax-only -verify %s + +#if __has_attribute(alias) + +void g() {} + +void f() __attribute__((alias("g"))); //expected-no-diagnostics + +#else + +//expected-no-diagnostics + +#endif Index: include/clang/Basic/Attr.td === --- include/clang/Basic/Attr.td +++ include/clang/Basic/Attr.td @@ -318,6 +318,9 @@ def TargetELF : TargetSpec { let ObjectFormats = ["ELF"]; } +def TargetSupportsAlias : TargetSpec { + let ObjectFormats = ["COFF", "ELF", "Wasm"]; +} // Attribute subject match rules that are used for #pragma clang attribute. // @@ -554,7 +557,7 @@ let Documentation = [Undocumented]; } -def Alias : Attr { +def Alias : Attr, TargetSpecificAttr { let Spellings = [GCC<"alias">]; let Args = [StringArgument<"Aliasee">]; let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag>; Index: test/Sema/attr-alias-has.c === --- /dev/null +++ test/Sema/attr-alias-has.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple wasm64-unknown-unknown -fsyntax-only -verify %s + +#if __has_attribute(alias) + +void g() {} + +void f() __attribute__((alias("g"))); //expected-no-diagnostics + +#else + +//expected-no-diagnostics + +#endif Index: include/clang/Basic/Attr.td === --- include/clang/Basic/Attr.td +++ include/clang/Basic/Attr.td @@ -318,6 +318,9 @@ def TargetELF : TargetSpec { let ObjectFormats = ["ELF"]; } +def TargetSupportsAlias : TargetSpec { + let ObjectFormats = ["COFF", "ELF", "Wasm"]; +} // Attribute subject match rules that are used for #pragma clang attribute. // @@ -554,7 +557,7 @@ let Documentation = [Undocumented]; } -def Alias : Attr { +def Alias : Attr, TargetSpecificAttr { let Spellings = [GCC<"alias">]; let Args = [StringArgument<"Aliasee">]; let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag>; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46805: If some platforms do not support an attribute, we should exclude the platform
HLJ2009 added a comment. In https://reviews.llvm.org/D46805#1117091, @sunfish wrote: > In https://reviews.llvm.org/D46805#1115681, @rsmith wrote: > > > In https://reviews.llvm.org/D46805#1113358, @aaron.ballman wrote: > > > > > @rsmith -- do the object file formats listed look correct to you? > > > > > > They look at least plausible. We should be able to test whether LLVM can > > actually emit aliases on each of these targets easily enough... > > > > However, I get this error for any WAsm compilation I try: > > > > fatal error: error in backend: section size does not fit in a uint32_t > > > > ... so I have no idea if aliases are/will be supported there. Perhaps > > @sunfish can tell us :) > > > Yes, they are intended to be supported. It sounds like you found a bug, > though I've not been able to reproduce it in simple tests. Comment at: include/clang/Basic/Attr.td:322 +def TargetSupportsAlias : TargetSpec { + let ObjectFormats = ["COFF", "ELF", "Wasm"]; +} aaron.ballman wrote: > Did you verify that Wasm supports the alias attribute? If it is supported, it > might be nice to add a test to `CodeGen/alias.c` to demonstrate it. Similar > for COFF. Yes, I used the following command line to test my test file. clang -cc1 -triple wasm32-unknown-unknown -fsyntax-only -verify attr-alias-has.c clang -cc1 -triple wasm64-unknown-unknown -fsyntax-only -verify attr-alias-has.c The test result is ok. ok, I will update it. Comment at: test/Sema/attr-alias-has.c:5 +// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple wasm64-unknown-unknown -fsyntax-only -verify %s + aaron.ballman wrote: > I'd like to see a test that the "attribute not supported on target" > diagnostic is being generated. I'd recommend something along these lines: > ``` > void g() {} > void f() __attribute__((alias("g"))); > #if !__has_attribute(alias) > // expected-error@-2{{expected diagnostic text}} > #else > // expected-no-diagnostics > #endif > ``` ok, I will update it. Repository: rC Clang https://reviews.llvm.org/D46805 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46805: If some platforms do not support an attribute, we should exclude the platform
HLJ2009 updated this revision to Diff 149665. HLJ2009 added a comment. update test case. Repository: rC Clang https://reviews.llvm.org/D46805 Files: include/clang/Basic/Attr.td test/Sema/attr-alias-has.c test/Sema/attr-alias.c Index: test/Sema/attr-alias.c === --- test/Sema/attr-alias.c +++ test/Sema/attr-alias.c @@ -2,4 +2,4 @@ void g() {} -void f() __attribute__((alias("g"))); //expected-error {{aliases are not supported on darwin}} +void f() __attribute__((alias("g"))); //expected-warning {{unknown attribute 'alias' ignored}} Index: test/Sema/attr-alias-has.c === --- /dev/null +++ test/Sema/attr-alias-has.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple wasm64-unknown-unknown -fsyntax-only -verify %s + +void g() {} +#if !__has_attribute(alias) +void f() __attribute__((alias("g"))); // expected-warning {{unknown attribute 'alias' ignored}} +#else +void f() __attribute__((alias("g"))); // expected-no-diagnostics +#endif \ No newline at end of file Index: include/clang/Basic/Attr.td === --- include/clang/Basic/Attr.td +++ include/clang/Basic/Attr.td @@ -318,6 +318,9 @@ def TargetELF : TargetSpec { let ObjectFormats = ["ELF"]; } +def TargetSupportsAlias : TargetSpec { + let ObjectFormats = ["COFF", "ELF", "Wasm"]; +} // Attribute subject match rules that are used for #pragma clang attribute. // @@ -554,7 +557,7 @@ let Documentation = [Undocumented]; } -def Alias : Attr { +def Alias : Attr, TargetSpecificAttr { let Spellings = [GCC<"alias">]; let Args = [StringArgument<"Aliasee">]; let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag>; Index: test/Sema/attr-alias.c === --- test/Sema/attr-alias.c +++ test/Sema/attr-alias.c @@ -2,4 +2,4 @@ void g() {} -void f() __attribute__((alias("g"))); //expected-error {{aliases are not supported on darwin}} +void f() __attribute__((alias("g"))); //expected-warning {{unknown attribute 'alias' ignored}} Index: test/Sema/attr-alias-has.c === --- /dev/null +++ test/Sema/attr-alias-has.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple wasm64-unknown-unknown -fsyntax-only -verify %s + +void g() {} +#if !__has_attribute(alias) +void f() __attribute__((alias("g"))); // expected-warning {{unknown attribute 'alias' ignored}} +#else +void f() __attribute__((alias("g"))); // expected-no-diagnostics +#endif \ No newline at end of file Index: include/clang/Basic/Attr.td === --- include/clang/Basic/Attr.td +++ include/clang/Basic/Attr.td @@ -318,6 +318,9 @@ def TargetELF : TargetSpec { let ObjectFormats = ["ELF"]; } +def TargetSupportsAlias : TargetSpec { + let ObjectFormats = ["COFF", "ELF", "Wasm"]; +} // Attribute subject match rules that are used for #pragma clang attribute. // @@ -554,7 +557,7 @@ let Documentation = [Undocumented]; } -def Alias : Attr { +def Alias : Attr, TargetSpecificAttr { let Spellings = [GCC<"alias">]; let Args = [StringArgument<"Aliasee">]; let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag>; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits