Skip to content

Commit d642c83

Browse files
committed
[clang] Remove "unknown" from availability diags
Previously, diagnostics like `error: 'fNew' is unavailable: introduced in macOS 11 unknown` were getting emitted when the active target triple didn't have a enviornment tied to it. Instead, add a guard against this to avoid the `unknown`.
1 parent b2e2ae8 commit d642c83

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

clang/lib/AST/DeclBase.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -695,11 +695,13 @@ 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
698+
auto &Triple = Context.getTargetInfo().getTriple();
699+
StringRef TargetEnv = Triple.getEnvironmentName();
700+
StringRef EnvName =
701+
Triple.hasEnvironment()
702+
? llvm::Triple::getEnvironmentTypeName(Triple.getEnvironment())
703+
: "";
704+
// Matching environment or no environment on attribute.
703705
if (!IIEnv || (!TargetEnv.empty() && IIEnv->getName() == TargetEnv)) {
704706
if (Message) {
705707
Message->clear();
@@ -709,7 +711,7 @@ static AvailabilityResult CheckAvailability(ASTContext &Context,
709711
<< EnvName << 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();

0 commit comments

Comments
 (0)