[PATCH] D46805: If some platforms do not support an attribute, we should exclude the platform

Li Jia He via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun May 13 07:25:12 PDT 2018


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 <stdio.h>
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 <stdio.h>
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<string> 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<list<string> 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<TargetDarwinNegative> {
   let Spellings = [GCC<"alias">];
   let Args = [StringArgument<"Aliasee">];
   let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag>;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46805.146512.patch
Type: text/x-patch
Size: 2096 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180513/5944ece8/attachment.bin>


More information about the cfe-commits mailing list