Skip to content

Commit 74e5a3b

Browse files
authored
[clang] Remove "unknown" from availability diags (#138610)
Previously, diagnostics like `error: 'fNew' is unavailable: introduced in macOS 11 unknown` were getting emitted when the active target triple didn't have an environment tied to it. Instead, add a guard against this to avoid the `unknown`.
1 parent 823b1a5 commit 74e5a3b

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

clang/lib/AST/DeclBase.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -695,27 +695,31 @@ static AvailabilityResult CheckAvailability(ASTContext &Context,
695695
if (!A->getIntroduced().empty() &&
696696
EnclosingVersion < A->getIntroduced()) {
697697
IdentifierInfo *IIEnv = A->getEnvironment();
698-
StringRef TargetEnv =
699-
Context.getTargetInfo().getTriple().getEnvironmentName();
700-
StringRef EnvName = llvm::Triple::getEnvironmentTypeName(
701-
Context.getTargetInfo().getTriple().getEnvironment());
702-
// Matching environment or no environment on attribute
703-
if (!IIEnv || (!TargetEnv.empty() && IIEnv->getName() == TargetEnv)) {
698+
auto &Triple = Context.getTargetInfo().getTriple();
699+
StringRef TargetEnv = Triple.getEnvironmentName();
700+
StringRef EnvName =
701+
llvm::Triple::getEnvironmentTypeName(Triple.getEnvironment());
702+
// Matching environment or no environment on attribute.
703+
if (!IIEnv || (Triple.hasEnvironment() && IIEnv->getName() == TargetEnv)) {
704704
if (Message) {
705705
Message->clear();
706706
llvm::raw_string_ostream Out(*Message);
707707
VersionTuple VTI(A->getIntroduced());
708-
Out << "introduced in " << PrettyPlatformName << " " << VTI << " "
709-
<< EnvName << HintMessage;
708+
Out << "introduced in " << PrettyPlatformName << " " << VTI;
709+
if (Triple.hasEnvironment())
710+
Out << " " << EnvName;
711+
Out << HintMessage;
710712
}
711713
}
712-
// Non-matching environment or no environment on target
714+
// Non-matching environment or no environment on target.
713715
else {
714716
if (Message) {
715717
Message->clear();
716718
llvm::raw_string_ostream Out(*Message);
717-
Out << "not available on " << PrettyPlatformName << " " << EnvName
718-
<< HintMessage;
719+
Out << "not available on " << PrettyPlatformName;
720+
if (Triple.hasEnvironment())
721+
Out << " " << EnvName;
722+
Out << HintMessage;
719723
}
720724
}
721725

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: not %clang -target x86_64-apple-darwin9 -fsyntax-only %s 2>&1 | FileCheck %s
2+
3+
// CHECK: error:
4+
// CHECK-SAME: 'f0' is unavailable: introduced in macOS 11
5+
// CHECK-NOT: unknown
6+
7+
void f0(void) __attribute__((availability(macosx,strict,introduced=11)));
8+
9+
void client(void) {
10+
f0(); }

0 commit comments

Comments
 (0)