diff --git a/clang/include/clang/Basic/TargetOSMacros.def b/clang/include/clang/Basic/TargetOSMacros.def index 58dce330f9c8f..f4f3276ad1c25 100644 --- a/clang/include/clang/Basic/TargetOSMacros.def +++ b/clang/include/clang/Basic/TargetOSMacros.def @@ -53,4 +53,7 @@ TARGET_OS(TARGET_OS_NANO, Triple.isWatchOS()) TARGET_OS(TARGET_IPHONE_SIMULATOR, Triple.isSimulatorEnvironment()) TARGET_OS(TARGET_OS_UIKITFORMAC, Triple.isMacCatalystEnvironment()) +// UEFI target. +TARGET_OS(TARGET_OS_UEFI, Triple.isUEFI()) + #undef TARGET_OS diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 205edcab9ccb3..fd38ae98fdfaf 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -835,8 +835,23 @@ class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo public: UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : UEFITargetInfo(Triple, Opts) { + // The UEFI spec does not mandate specific C++ ABI, integer widths, or + // alignment. We are setting these defaults to match the Windows target as + // it is the only way to build EFI applications with Clang/LLVM today. We + // intend to offer flexibility by supporting choices that are not default in + // Windows target in the future. this->TheCXXABI.set(TargetCXXABI::Microsoft); - this->MaxTLSAlign = 8192u * this->getCharWidth(); + LongWidth = LongAlign = 32; + DoubleAlign = LongLongAlign = 64; + LongDoubleWidth = LongDoubleAlign = 64; + LongDoubleFormat = &llvm::APFloat::IEEEdouble(); + IntMaxType = SignedLongLong; + Int64Type = SignedLongLong; + SizeType = UnsignedLongLong; + PtrDiffType = SignedLongLong; + IntPtrType = SignedLongLong; + WCharType = UnsignedShort; + WIntType = UnsignedShort; this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-" "i64:64-i128:128-f80:128-n8:16:32:64-S128"); } diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index f88d6202ad381..44e16ba4b4742 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -267,6 +267,7 @@ createTargetCodeGenInfo(CodeGenModule &CGM) { : X86AVXABILevel::None); switch (Triple.getOS()) { + case llvm::Triple::UEFI: case llvm::Triple::Win32: return createWinX86_64TargetCodeGenInfo(CGM, AVXLevel); default: diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index fe172d923ac07..2bc1cecb53c38 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5959,7 +5959,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // We turn strict aliasing off by default if we're Windows MSVC since MSVC // doesn't do any TBAA. if (!Args.hasFlag(options::OPT_fstrict_aliasing, StrictAliasingAliasOption, - options::OPT_fno_strict_aliasing, !IsWindowsMSVC)) + options::OPT_fno_strict_aliasing, + !IsWindowsMSVC && !IsUEFI)) CmdArgs.push_back("-relaxed-aliasing"); if (Args.hasFlag(options::OPT_fno_pointer_tbaa, options::OPT_fpointer_tbaa, false)) diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 1ac325d444662..4c8d519c2b664 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -2835,6 +2835,7 @@ // RISCV64-LINUX: #define unix 1 // RUN: %clang_cc1 -dM -triple=x86_64-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s +// RUN: %clang_cc1 -dM -triple=x86_64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s // UEFI: #define __UEFI__ 1