Skip to content

Commit 9c5c14d

Browse files
committed
[clang] Remove "unknown" from availability diags (llvm#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 e14e6a6 commit 9c5c14d

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
@@ -689,27 +689,31 @@ static AvailabilityResult CheckAvailability(ASTContext &Context,
689689
if (!A->getIntroduced().empty() &&
690690
EnclosingVersion < A->getIntroduced()) {
691691
IdentifierInfo *IIEnv = A->getEnvironment();
692-
StringRef TargetEnv =
693-
Context.getTargetInfo().getTriple().getEnvironmentName();
694-
StringRef EnvName = llvm::Triple::getEnvironmentTypeName(
695-
Context.getTargetInfo().getTriple().getEnvironment());
696-
// Matching environment or no environment on attribute
697-
if (!IIEnv || (!TargetEnv.empty() && IIEnv->getName() == TargetEnv)) {
692+
auto &Triple = Context.getTargetInfo().getTriple();
693+
StringRef TargetEnv = Triple.getEnvironmentName();
694+
StringRef EnvName =
695+
llvm::Triple::getEnvironmentTypeName(Triple.getEnvironment());
696+
// Matching environment or no environment on attribute.
697+
if (!IIEnv || (Triple.hasEnvironment() && IIEnv->getName() == TargetEnv)) {
698698
if (Message) {
699699
Message->clear();
700700
llvm::raw_string_ostream Out(*Message);
701701
VersionTuple VTI(A->getIntroduced());
702-
Out << "introduced in " << PrettyPlatformName << " " << VTI << " "
703-
<< EnvName << HintMessage;
702+
Out << "introduced in " << PrettyPlatformName << " " << VTI;
703+
if (Triple.hasEnvironment())
704+
Out << " " << EnvName;
705+
Out << HintMessage;
704706
}
705707
}
706-
// Non-matching environment or no environment on target
708+
// Non-matching environment or no environment on target.
707709
else {
708710
if (Message) {
709711
Message->clear();
710712
llvm::raw_string_ostream Out(*Message);
711-
Out << "not available on " << PrettyPlatformName << " " << EnvName
712-
<< HintMessage;
713+
Out << "not available on " << PrettyPlatformName;
714+
if (Triple.hasEnvironment())
715+
Out << " " << EnvName;
716+
Out << HintMessage;
713717
}
714718
}
715719

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)