diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp index 1844470f9adbd..ae6e55167360a 100644 --- a/lib/IRGen/IRGenModule.cpp +++ b/lib/IRGen/IRGenModule.cpp @@ -1001,42 +1001,22 @@ void IRGenModule::setHasFramePointer(llvm::Function *F, /// Construct initial function attributes from options. void IRGenModule::constructInitialFnAttributes(llvm::AttrBuilder &Attrs, OptimizationMode FuncOptMode) { + // Add the default attributes for the Clang configuration. + clang::CodeGen::addDefaultFunctionDefinitionAttributes(getClangCGM(), Attrs); + // Add frame pointer attributes. + // FIXME: why are we doing this? setHasFramePointer(Attrs, IRGen.Opts.DisableFPElim); - // Add target-cpu and target-features if they are non-null. - auto *Clang = static_cast(Context.getClangModuleLoader()); - clang::TargetOptions &ClangOpts = Clang->getTargetInfo().getTargetOpts(); - - std::string &CPU = ClangOpts.CPU; - if (CPU != "") - Attrs.addAttribute("target-cpu", CPU); - - std::vector Features; - for (auto &F : ClangOpts.Features) - if (!shouldRemoveTargetFeature(F)) - Features.push_back(F); - - if (!Features.empty()) { - SmallString<64> allFeatures; - // Sort so that the target features string is canonical. - std::sort(Features.begin(), Features.end()); - llvm::interleave(Features, [&](const std::string &s) { - allFeatures.append(s); - }, [&]{ - allFeatures.push_back(','); - }); - Attrs.addAttribute("target-features", allFeatures); - } + // Add/remove MinSize based on the appropriate setting. if (FuncOptMode == OptimizationMode::NotSet) FuncOptMode = IRGen.Opts.OptMode; - if (FuncOptMode == OptimizationMode::ForSize) + if (FuncOptMode == OptimizationMode::ForSize) { + Attrs.addAttribute(llvm::Attribute::OptimizeForSize); Attrs.addAttribute(llvm::Attribute::MinSize); - - auto triple = llvm::Triple(ClangOpts.Triple); - if (triple.getArchName() == "arm64e") { - Attrs.addAttribute("ptrauth-returns"); - Attrs.addAttribute("ptrauth-calls"); + } else { + Attrs.removeAttribute(llvm::Attribute::MinSize); + Attrs.removeAttribute(llvm::Attribute::OptimizeForSize); } } diff --git a/test/IRGen/c_globals.swift b/test/IRGen/c_globals.swift index 20cdca7519981..0f55f9bb4d173 100644 --- a/test/IRGen/c_globals.swift +++ b/test/IRGen/c_globals.swift @@ -32,4 +32,4 @@ public func testCaptureGlobal() { } // CHECK-DAG: attributes [[CLANG_FUNC_ATTR]] = { noinline nounwind {{.*}}"frame-pointer"="all"{{.*}} -// CHECK-DAG: attributes [[SWIFT_FUNC_ATTR]] = { "frame-pointer"="all" {{.*}}"target-cpu" +// CHECK-DAG: attributes [[SWIFT_FUNC_ATTR]] = { {{.*}}"frame-pointer"="all" {{.*}}"target-cpu" diff --git a/test/IRGen/generic_metatypes.swift b/test/IRGen/generic_metatypes.swift index 2bc67e77b6321..c6033e3680034 100644 --- a/test/IRGen/generic_metatypes.swift +++ b/test/IRGen/generic_metatypes.swift @@ -146,4 +146,4 @@ func makeGenericMetatypes() { // CHECK: ret %swift.metadata_response // CHECK-DAG: attributes [[NOUNWIND_READNONE]] = { nounwind readnone } -// CHECK-DAG: attributes [[NOUNWIND_OPT]] = { noinline nounwind "frame-pointer"="none" "target-cpu" +// CHECK-DAG: attributes [[NOUNWIND_OPT]] = { noinline nounwind " diff --git a/test/IRGen/generic_metatypes_future.swift b/test/IRGen/generic_metatypes_future.swift index 4cfaab336ad8a..3e9fb48513d35 100644 --- a/test/IRGen/generic_metatypes_future.swift +++ b/test/IRGen/generic_metatypes_future.swift @@ -176,4 +176,4 @@ func makeGenericMetatypes() { // CHECK: ret %swift.metadata_response // CHECK-DAG: attributes [[NOUNWIND_READNONE]] = { nounwind readnone } -// CHECK-DAG: attributes [[NOUNWIND_OPT]] = { noinline nounwind "frame-pointer"="none" "target-cpu" +// CHECK-DAG: attributes [[NOUNWIND_OPT]] = { noinline nounwind " diff --git a/test/IRGen/ptrauth-functions.sil b/test/IRGen/ptrauth-functions.sil index 9606671228345..80f9e43227584 100644 --- a/test/IRGen/ptrauth-functions.sil +++ b/test/IRGen/ptrauth-functions.sil @@ -87,4 +87,4 @@ bb0(%0 : $T): sil_vtable F { } -// CHECK: #[[ATTRS]] = {{{.*}} "ptrauth-calls" "ptrauth-returns" +// CHECK: #[[ATTRS]] = {{{.*}} "ptrauth-auth-traps" "ptrauth-calls" "ptrauth-indirect-gotos" "ptrauth-returns" diff --git a/test/SILOptimizer/opt_mode.swift b/test/SILOptimizer/opt_mode.swift index cfe34c25aea42..35a6f8f8bcbe0 100644 --- a/test/SILOptimizer/opt_mode.swift +++ b/test/SILOptimizer/opt_mode.swift @@ -47,5 +47,5 @@ func test_ospeed(_ a: A) -> Int { } -// CHECK-IR: attributes [[SIZE_ATTR]] = { minsize " +// CHECK-IR: attributes [[SIZE_ATTR]] = { minsize optsize " // CHECK-IR: attributes [[NOSIZE_ATTR]] = { "