leonardchan updated this revision to Diff 368423.
leonardchan edited the summary of this revision.
Herald added subscribers: dexonsmith, dang.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D108592/new/
https://reviews.llvm.org/D108592
Files:
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/OSTargets.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Frontend/attr-availability-fuchsia.c
clang/test/Sema/attr-availability-fuchsia.c
Index: clang/test/Sema/attr-availability-fuchsia.c
===================================================================
--- /dev/null
+++ clang/test/Sema/attr-availability-fuchsia.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 "-triple" "x86_64-unknown-fuchsia" -mfuchsia-version=16 -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "x86_64-unknown-fuchsia" -fsyntax-only %s |& \
+// RUN: FileCheck %s
+
+// If the version is not specified, we should not get any errors since there
+// is no checking (the major version number is zero).
+// CHECK-NOT: error:
+
+void f0(int) __attribute__((availability(fuchsia, introduced = 14, deprecated = 19)));
+void f1(int) __attribute__((availability(fuchsia, introduced = 16)));
+void f2(int) __attribute__((availability(fuchsia, introduced = 14, deprecated = 16))); // expected-note {{'f2' has been explicitly marked deprecated here}}
+void f3(int) __attribute__((availability(fuchsia, introduced = 19)));
+void f4(int) __attribute__((availability(fuchsia, introduced = 9, deprecated = 11, obsoleted = 16), availability(ios, introduced = 2.0, deprecated = 3.0))); // expected-note{{explicitly marked unavailable}}
+void f5(int) __attribute__((availability(ios, introduced = 3.2), availability(fuchsia, unavailable))); // expected-note{{'f5' has been explicitly marked unavailable here}}
+void f6(int) __attribute__((availability(fuchsia, introduced = 16.0))); // expected-warning {{Fuchsia versions only support 'major', not '.minor[.subminor]}}
+void f7(int) __attribute__((availability(fuchsia, introduced = 16.1))); // expected-warning {{Fuchsia versions only support 'major', not '.minor[.subminor]}}
+
+void test() {
+ f0(0);
+ f1(0);
+ f2(0); // expected-warning{{'f2' is deprecated: first deprecated in Fuchsia 16}}
+ f3(0);
+ f4(0); // expected-error{{f4' is unavailable: obsoleted in Fuchsia 16}}
+ f5(0); // expected-error{{'f5' is unavailable: not available on Fuchsia}}
+}
Index: clang/test/Frontend/attr-availability-fuchsia.c
===================================================================
--- /dev/null
+++ clang/test/Frontend/attr-availability-fuchsia.c
@@ -0,0 +1,10 @@
+// Test that `-mfuchsia-version` is propagated to cc1.
+// RUN: %clang -target x86_64-unknown-fuchsia -mfuchsia-version=16 -c %s -### |& FileCheck %s
+//
+// It should also be exposed to non-fuchsia platforms. This is desireable when
+// using common Fuchsia headers for building host libraries that also depend on
+// the Fuchsia version (such as using a compatible host-side FIDL library that
+// talks with a Fuchsia FIDL library of the same version).
+// RUN: %clang -target x86_64-unknown-linux-gnu -mfuchsia-version=16 -c %s -### |& FileCheck %s
+//
+// CHECK: "-mfuchsia-version=16"
Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -2488,6 +2488,15 @@
}
}
+ if (II->isStr("fuchsia")) {
+ Optional<unsigned> Min, Sub;
+ if ((Min = Introduced.Version.getMinor()) ||
+ (Sub = Introduced.Version.getSubminor())) {
+ S.Diag(AL.getLoc(), diag::warn_availability_fuchsia_unavailable_minor);
+ return;
+ }
+ }
+
int PriorityModifier = AL.isPragmaClangAttribute()
? Sema::AP_PragmaClangAttribute
: Sema::AP_Explicit;
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5462,6 +5462,9 @@
Args.AddLastArg(CmdArgs, options::OPT_fexperimental_relative_cxx_abi_vtables,
options::OPT_fno_experimental_relative_cxx_abi_vtables);
+ if (Arg *A = Args.getLastArg(options::OPT_mfuchsia_version_EQ))
+ A->render(Args, CmdArgs);
+
// Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi}
// (-ansi is equivalent to -std=c89 or -std=c++98).
//
Index: clang/lib/Basic/Targets/OSTargets.h
===================================================================
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -885,6 +885,9 @@
// Required by the libc++ locale support.
if (Opts.CPlusPlus)
Builder.defineMacro("_GNU_SOURCE");
+
+ this->PlatformName = "fuchsia";
+ this->PlatformMinVersion = VersionTuple(Opts.FuchsiaVersion);
}
public:
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3136,6 +3136,9 @@
def mllvm : Separate<["-"], "mllvm">, Flags<[CC1Option,CC1AsOption,CoreOption]>,
HelpText<"Additional arguments to forward to LLVM's option processing">,
MarshallingInfoStringVector<FrontendOpts<"LLVMArgs">>;
+def mfuchsia_version_EQ : Joined<["-"], "mfuchsia-version=">,
+ Group<m_Group>, Flags<[CC1Option]>, HelpText<"Set Fuchsia version target">,
+ MarshallingInfoInt<LangOpts<"FuchsiaVersion">>;
def mmacosx_version_min_EQ : Joined<["-"], "mmacosx-version-min=">,
Group<m_Group>, HelpText<"Set Mac OS X deployment target">;
def mmacos_version_min_EQ : Joined<["-"], "mmacos-version-min=">,
Index: clang/include/clang/Basic/LangOptions.def
===================================================================
--- clang/include/clang/Basic/LangOptions.def
+++ clang/include/clang/Basic/LangOptions.def
@@ -428,6 +428,8 @@
"Controls how scalar integer arguments are extended in calls "
"to unprototyped and varargs functions")
+VALUE_LANGOPT(FuchsiaVersion, 32, 0, "Fuchsia Version")
+
#undef LANGOPT
#undef COMPATIBLE_LANGOPT
#undef BENIGN_LANGOPT
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3543,6 +3543,9 @@
InGroup<Availability>;
def note_protocol_method : Note<
"protocol method is here">;
+def warn_availability_fuchsia_unavailable_minor : Warning<
+ "Fuchsia versions only support 'major', not '.minor[.subminor]'">,
+ InGroup<Availability>;
def warn_unguarded_availability :
Warning<"%0 is only available on %1 %2 or newer">,
Index: clang/include/clang/Basic/Attr.td
===================================================================
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -848,6 +848,7 @@
[{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
return llvm::StringSwitch<llvm::StringRef>(Platform)
.Case("android", "Android")
+ .Case("fuchsia", "Fuchsia")
.Case("ios", "iOS")
.Case("macos", "macOS")
.Case("tvos", "tvOS")
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits