[clang] [clang] Remove "unknown" from availability diags (PR #138610)
Cyndy Ishida via cfe-commits
cfe-commits at lists.llvm.org
Mon May 5 16:20:17 PDT 2025
https://github.com/cyndyishida created https://github.com/llvm/llvm-project/pull/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`.
>From d642c83835743409395a2b7a091eac8bf5c948c4 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida <cyndy_ishida at apple.com>
Date: Mon, 5 May 2025 16:09:00 -0700
Subject: [PATCH] [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`.
---
clang/lib/AST/DeclBase.cpp | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index fead99c5f28a9..47857e7fd523b 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -695,11 +695,13 @@ static AvailabilityResult CheckAvailability(ASTContext &Context,
if (!A->getIntroduced().empty() &&
EnclosingVersion < A->getIntroduced()) {
IdentifierInfo *IIEnv = A->getEnvironment();
- StringRef TargetEnv =
- Context.getTargetInfo().getTriple().getEnvironmentName();
- StringRef EnvName = llvm::Triple::getEnvironmentTypeName(
- Context.getTargetInfo().getTriple().getEnvironment());
- // Matching environment or no environment on attribute
+ auto &Triple = Context.getTargetInfo().getTriple();
+ StringRef TargetEnv = Triple.getEnvironmentName();
+ StringRef EnvName =
+ Triple.hasEnvironment()
+ ? llvm::Triple::getEnvironmentTypeName(Triple.getEnvironment())
+ : "";
+ // Matching environment or no environment on attribute.
if (!IIEnv || (!TargetEnv.empty() && IIEnv->getName() == TargetEnv)) {
if (Message) {
Message->clear();
@@ -709,7 +711,7 @@ static AvailabilityResult CheckAvailability(ASTContext &Context,
<< EnvName << HintMessage;
}
}
- // Non-matching environment or no environment on target
+ // Non-matching environment or no environment on target.
else {
if (Message) {
Message->clear();
More information about the cfe-commits
mailing list