From 04caadc61fa221002018d32174f945d2904c2fae Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Sun, 19 Nov 2023 03:00:05 -0500 Subject: [PATCH] [Driver] Enable __float128 support on X86 on FreeBSD / NetBSD (#72788) (cherry picked from commit 23c47eba879769a29772c999be2991201c2fe399) --- clang/lib/Basic/Targets/OSTargets.h | 16 +++++++++++++++- clang/test/CodeGenCXX/float128-declarations.cpp | 12 ++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index 8f4331b02f3b73..cf8cc8e61c498a 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -217,6 +217,8 @@ class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public OSTargetInfo { Builder.defineMacro("__FreeBSD_cc_version", Twine(CCVersion)); Builder.defineMacro("__KPRINTF_ATTRIBUTE__"); DefineStd(Builder, "unix", Opts); + if (this->HasFloat128) + Builder.defineMacro("__FLOAT128__"); // On FreeBSD, wchar_t contains the number of the code point as // used by the character set of the locale. These character sets are @@ -234,9 +236,11 @@ class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public OSTargetInfo { FreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : OSTargetInfo(Triple, Opts) { switch (Triple.getArch()) { - default: case llvm::Triple::x86: case llvm::Triple::x86_64: + this->HasFloat128 = true; + [[fallthrough]]; + default: this->MCountName = ".mcount"; break; case llvm::Triple::mips: @@ -425,12 +429,22 @@ class LLVM_LIBRARY_VISIBILITY NetBSDTargetInfo : public OSTargetInfo { Builder.defineMacro("__unix__"); if (Opts.POSIXThreads) Builder.defineMacro("_REENTRANT"); + if (this->HasFloat128) + Builder.defineMacro("__FLOAT128__"); } public: NetBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : OSTargetInfo(Triple, Opts) { this->MCountName = "__mcount"; + switch (Triple.getArch()) { + default: + break; + case llvm::Triple::x86: + case llvm::Triple::x86_64: + this->HasFloat128 = true; + break; + } } }; diff --git a/clang/test/CodeGenCXX/float128-declarations.cpp b/clang/test/CodeGenCXX/float128-declarations.cpp index ddfe9dce109c81..84b8f7f33036b5 100644 --- a/clang/test/CodeGenCXX/float128-declarations.cpp +++ b/clang/test/CodeGenCXX/float128-declarations.cpp @@ -6,9 +6,17 @@ // RUN: %s -o - | FileCheck %s -check-prefix=CHECK-X86 // RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-linux-gnu -std=c++11 \ // RUN: %s -o - | FileCheck %s -check-prefix=CHECK-X86 -// RUN: %clang_cc1 -emit-llvm -triple i686-pc-openbsd -std=c++11 \ +// RUN: %clang_cc1 -emit-llvm -triple i386-unknown-freebsd -std=c++11 \ // RUN: %s -o - | FileCheck %s -check-prefix=CHECK-X86 -// RUN: %clang_cc1 -emit-llvm -triple amd64-pc-openbsd -std=c++11 \ +// RUN: %clang_cc1 -emit-llvm -triple amd64-unknown-freebsd -std=c++11 \ +// RUN: %s -o - | FileCheck %s -check-prefix=CHECK-X86 +// RUN: %clang_cc1 -emit-llvm -triple i386-unknown-netbsd -std=c++11 \ +// RUN: %s -o - | FileCheck %s -check-prefix=CHECK-X86 +// RUN: %clang_cc1 -emit-llvm -triple amd64-unknown-netbsd -std=c++11 \ +// RUN: %s -o - | FileCheck %s -check-prefix=CHECK-X86 +// RUN: %clang_cc1 -emit-llvm -triple i386-unknown-openbsd -std=c++11 \ +// RUN: %s -o - | FileCheck %s -check-prefix=CHECK-X86 +// RUN: %clang_cc1 -emit-llvm -triple amd64-unknown-openbsd -std=c++11 \ // RUN: %s -o - | FileCheck %s -check-prefix=CHECK-X86 // RUN: %clang_cc1 -emit-llvm -triple i386-pc-solaris2.11 -std=c++11 \ // RUN: %s -o - | FileCheck %s -check-prefix=CHECK-X86