Skip to content

Conversation

cyndyishida
Copy link
Member

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.

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`.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels May 5, 2025
@llvmbot
Copy link
Member

llvmbot commented May 5, 2025

@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Cyndy Ishida (cyndyishida)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/138610.diff

1 Files Affected:

  • (modified) clang/lib/AST/DeclBase.cpp (+8-6)
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();

@cor3ntin
Copy link
Contributor

cor3ntin commented May 6, 2025

The change looks reasonable but can you add a test? thanks!

@llvmbot llvmbot added the clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' label May 8, 2025
@cyndyishida
Copy link
Member Author

The change looks reasonable but can you add a test? thanks!

Open to other suggestions @cor3ntin, but I didn't figure out a way to ensure part of a diagnostic was omitted with cc1's -verify so its a driver test that uses FIleCheck

Copy link
Collaborator

@cachemeifyoucan cachemeifyoucan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. LGTM.

@cyndyishida cyndyishida merged commit 74e5a3b into llvm:main May 9, 2025
11 checks passed
cyndyishida added a commit to cyndyishida/llvm-project that referenced this pull request May 12, 2025
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`.
cyndyishida added a commit to swiftlang/llvm-project that referenced this pull request May 13, 2025
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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants