diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 8479aa5d4037d..eee242d566d1c 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -689,27 +689,31 @@ 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 - if (!IIEnv || (!TargetEnv.empty() && IIEnv->getName() == TargetEnv)) { + auto &Triple = Context.getTargetInfo().getTriple(); + StringRef TargetEnv = Triple.getEnvironmentName(); + StringRef EnvName = + llvm::Triple::getEnvironmentTypeName(Triple.getEnvironment()); + // Matching environment or no environment on attribute. + if (!IIEnv || (Triple.hasEnvironment() && IIEnv->getName() == TargetEnv)) { if (Message) { Message->clear(); llvm::raw_string_ostream Out(*Message); VersionTuple VTI(A->getIntroduced()); - Out << "introduced in " << PrettyPlatformName << " " << VTI << " " - << EnvName << HintMessage; + Out << "introduced in " << PrettyPlatformName << " " << VTI; + if (Triple.hasEnvironment()) + Out << " " << EnvName; + Out << HintMessage; } } - // Non-matching environment or no environment on target + // Non-matching environment or no environment on target. else { if (Message) { Message->clear(); llvm::raw_string_ostream Out(*Message); - Out << "not available on " << PrettyPlatformName << " " << EnvName - << HintMessage; + Out << "not available on " << PrettyPlatformName; + if (Triple.hasEnvironment()) + Out << " " << EnvName; + Out << HintMessage; } } diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp index 578bcea7f0389..c2547ea96c474 100644 --- a/clang/lib/Serialization/ModuleManager.cpp +++ b/clang/lib/Serialization/ModuleManager.cpp @@ -134,7 +134,9 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type, // Note: ExpectedSize and ExpectedModTime will be 0 for MK_ImplicitModule // when using an ASTFileSignature. if (lookupModuleFile(FileName, ExpectedSize, ExpectedModTime, Entry)) { - ErrorStr = "module file out of date"; + ErrorStr = IgnoreModTime + ? "module file has a different size than expected" + : "module file has a different size or mtime than expected"; return OutOfDate; } diff --git a/clang/test/Driver/attr-availability-erroneous-diags.c b/clang/test/Driver/attr-availability-erroneous-diags.c new file mode 100644 index 0000000000000..5e67a461f3e19 --- /dev/null +++ b/clang/test/Driver/attr-availability-erroneous-diags.c @@ -0,0 +1,10 @@ +// RUN: not %clang -target x86_64-apple-darwin9 -fsyntax-only %s 2>&1 | FileCheck %s + +// CHECK: error: +// CHECK-SAME: 'f0' is unavailable: introduced in macOS 11 +// CHECK-NOT: unknown + +void f0(void) __attribute__((availability(macosx,strict,introduced=11))); + +void client(void) { +f0(); } diff --git a/clang/test/Driver/xros-driver.c b/clang/test/Driver/xros-driver.c index dd2c55ed4e70c..a79b76d5fe0ba 100644 --- a/clang/test/Driver/xros-driver.c +++ b/clang/test/Driver/xros-driver.c @@ -30,8 +30,8 @@ // LINK: "-platform_version" "xros" "1.0.0" "1.0.0" // LINK-SIM: "-platform_version" "xros-simulator" "1.0.0" "1.0.0" -// OBJC-RUNTIME: "-fobjc-runtime=ios-17.0.0.0" -// OBJC-RUNTIME2: "-fobjc-runtime=ios-18.0.0.0" +// OBJC-RUNTIME: "-fobjc-runtime=ios-17.0.0" +// OBJC-RUNTIME2: "-fobjc-runtime=ios-18.0.0" // ARC-NOT: error: // SSP_ON: "-stack-protector" "1" diff --git a/clang/test/Modules/explicit-build.cpp b/clang/test/Modules/explicit-build.cpp index d8834ec304f64..97e50f3769eed 100644 --- a/clang/test/Modules/explicit-build.cpp +++ b/clang/test/Modules/explicit-build.cpp @@ -199,6 +199,6 @@ // RUN: -fmodule-file=%t/c.pcm \ // RUN: %s -DHAVE_A -DHAVE_B -DHAVE_C 2>&1 | FileCheck --check-prefix=CHECK-MISMATCHED-B %s // -// CHECK-MISMATCHED-B: fatal error: module file '{{.*}}b.pcm' is out of date and needs to be rebuilt: module file out of date +// CHECK-MISMATCHED-B: fatal error: module file '{{.*}}b.pcm' is out of date and needs to be rebuilt: module file has a different size than expected // CHECK-MISMATCHED-B-NEXT: note: imported by module 'c' // CHECK-MISMATCHED-B-NOT: note: diff --git a/llvm/include/llvm/Support/VersionTuple.h b/llvm/include/llvm/Support/VersionTuple.h index ff43e00b73aed..f236d8f778aa8 100644 --- a/llvm/include/llvm/Support/VersionTuple.h +++ b/llvm/include/llvm/Support/VersionTuple.h @@ -103,9 +103,7 @@ class VersionTuple { /// Return a version tuple that contains a different major version but /// everything else is the same. - VersionTuple withMajorReplaced(unsigned NewMajor) const { - return VersionTuple(NewMajor, Minor, Subminor, Build); - } + VersionTuple withMajorReplaced(unsigned NewMajor) const; /// Return a version tuple that contains only components that are non-zero. VersionTuple normalize() const { diff --git a/llvm/lib/Support/VersionTuple.cpp b/llvm/lib/Support/VersionTuple.cpp index a4224f23b2f94..c6e20f1bd3ef4 100644 --- a/llvm/lib/Support/VersionTuple.cpp +++ b/llvm/lib/Support/VersionTuple.cpp @@ -108,3 +108,13 @@ bool VersionTuple::tryParse(StringRef input) { *this = VersionTuple(major, minor, micro, build); return false; } + +VersionTuple VersionTuple::withMajorReplaced(unsigned NewMajor) const { + if (HasBuild) + return VersionTuple(NewMajor, Minor, Subminor, Build); + if (HasSubminor) + return VersionTuple(NewMajor, Minor, Subminor); + if (HasMinor) + return VersionTuple(NewMajor, Minor); + return VersionTuple(NewMajor); +} diff --git a/llvm/unittests/Support/VersionTupleTest.cpp b/llvm/unittests/Support/VersionTupleTest.cpp index af6c0a7febad5..d498d670fb710 100644 --- a/llvm/unittests/Support/VersionTupleTest.cpp +++ b/llvm/unittests/Support/VersionTupleTest.cpp @@ -47,3 +47,33 @@ TEST(VersionTuple, tryParse) { EXPECT_TRUE(VT.tryParse("1 ")); EXPECT_TRUE(VT.tryParse(".")); } + +TEST(VersionTuple, withMajorReplaced) { + VersionTuple VT(2); + VersionTuple ReplacedVersion = VT.withMajorReplaced(7); + EXPECT_FALSE(ReplacedVersion.getMinor().has_value()); + EXPECT_FALSE(ReplacedVersion.getSubminor().has_value()); + EXPECT_FALSE(ReplacedVersion.getBuild().has_value()); + EXPECT_EQ(VersionTuple(7), ReplacedVersion); + + VT = VersionTuple(100, 1); + ReplacedVersion = VT.withMajorReplaced(7); + EXPECT_TRUE(ReplacedVersion.getMinor().has_value()); + EXPECT_FALSE(ReplacedVersion.getSubminor().has_value()); + EXPECT_FALSE(ReplacedVersion.getBuild().has_value()); + EXPECT_EQ(VersionTuple(7, 1), ReplacedVersion); + + VT = VersionTuple(101, 11, 12); + ReplacedVersion = VT.withMajorReplaced(7); + EXPECT_TRUE(ReplacedVersion.getMinor().has_value()); + EXPECT_TRUE(ReplacedVersion.getSubminor().has_value()); + EXPECT_FALSE(ReplacedVersion.getBuild().has_value()); + EXPECT_EQ(VersionTuple(7, 11, 12), ReplacedVersion); + + VT = VersionTuple(101, 11, 12, 2); + ReplacedVersion = VT.withMajorReplaced(7); + EXPECT_TRUE(ReplacedVersion.getMinor().has_value()); + EXPECT_TRUE(ReplacedVersion.getSubminor().has_value()); + EXPECT_TRUE(ReplacedVersion.getBuild().has_value()); + EXPECT_EQ(VersionTuple(7, 11, 12, 2), ReplacedVersion); +}