Skip to content

Commit

Permalink
[clang] Introduce a new UEFI target predefine. (#111719)
Browse files Browse the repository at this point in the history
Add a `__UEFI__` predefine for UEFI target.

Co-authored-by: RossComputerGuy
  • Loading branch information
Prabhuk authored Dec 23, 2024
1 parent 5db5dd7 commit ac586fd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion clang/lib/Basic/Targets/OSTargets.h
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,9 @@ template <typename Target>
class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo<Target> {
protected:
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
MacroBuilder &Builder) const override {}
MacroBuilder &Builder) const override {
Builder.defineMacro("__UEFI__");
}

public:
UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Expand Down
6 changes: 6 additions & 0 deletions clang/test/Driver/uefi-defines.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: %clang -target x86_64-unknown-uefi %s -emit-llvm -S -c -o - | FileCheck %s

// CHECK: __UEFI__defined
#ifdef __UEFI__
void __UEFI__defined() {}
#endif
4 changes: 4 additions & 0 deletions clang/test/Preprocessor/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -2742,3 +2742,7 @@
// RISCV64-LINUX: #define __unix__ 1
// RISCV64-LINUX: #define linux 1
// RISCV64-LINUX: #define unix 1

// RUN: %clang_cc1 -dM -triple=x86_64-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s

// UEFI: #define __UEFI__ 1

0 comments on commit ac586fd

Please sign in to comment.