https://github.com/mylai-mtk updated https://github.com/llvm/llvm-project/pull/109600
>From 2eda754ee96aa416063ff65bddfc5e856b626454 Mon Sep 17 00:00:00 2001 From: Ming-Yi Lai <ming-yi....@mediatek.com> Date: Wed, 4 Sep 2024 18:40:48 +0800 Subject: [PATCH 1/4] [clang][RISCV] Introduce command line options for Zicfilp-backed forward-edge CFI This patch enables the following command line flags for RISC-V targets: + `-fcf-protection=branch` turns on forward-edge control-flow integrity conditioning on RISC-V targets with Zicfilp extension + `-mcf-branch-label-scheme=unlabeled|func-sig` selects the label scheme used in the forward-edge CFI conditioning --- .../clang/Basic/CFProtectionOptions.def | 15 +++++ .../include/clang/Basic/CFProtectionOptions.h | 38 ++++++++++++ clang/include/clang/Basic/CodeGenOptions.def | 2 + clang/include/clang/Basic/CodeGenOptions.h | 1 + clang/include/clang/Basic/LangOptions.def | 2 + clang/include/clang/Basic/LangOptions.h | 2 + clang/include/clang/Basic/TargetInfo.h | 7 +++ clang/include/clang/Driver/Options.td | 4 ++ clang/lib/Basic/TargetInfo.cpp | 10 ++++ clang/lib/Basic/Targets/RISCV.h | 22 +++++++ clang/lib/Driver/ToolChains/Clang.cpp | 4 ++ clang/lib/Frontend/CompilerInvocation.cpp | 40 +++++++++++++ .../test/CodeGen/RISCV/riscv-cf-protection.c | 58 +++++++++++++++++++ 13 files changed, 205 insertions(+) create mode 100644 clang/include/clang/Basic/CFProtectionOptions.def create mode 100644 clang/include/clang/Basic/CFProtectionOptions.h create mode 100644 clang/test/CodeGen/RISCV/riscv-cf-protection.c diff --git a/clang/include/clang/Basic/CFProtectionOptions.def b/clang/include/clang/Basic/CFProtectionOptions.def new file mode 100644 index 00000000000000..b9df2de7f7eba0 --- /dev/null +++ b/clang/include/clang/Basic/CFProtectionOptions.def @@ -0,0 +1,15 @@ +//===-- CFProtectionOptions.def - cf-protection options ---------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + + +#ifdef CF_BRANCH_LABEL_SCHEME +CF_BRANCH_LABEL_SCHEME(Unlabeled, unlabeled) +CF_BRANCH_LABEL_SCHEME(FuncSig, func-sig) + +#undef CF_BRANCH_LABEL_SCHEME +#endif // #ifdef CF_BRANCH_LABEL_SCHEME diff --git a/clang/include/clang/Basic/CFProtectionOptions.h b/clang/include/clang/Basic/CFProtectionOptions.h new file mode 100644 index 00000000000000..13f46d4c13e7e7 --- /dev/null +++ b/clang/include/clang/Basic/CFProtectionOptions.h @@ -0,0 +1,38 @@ +//===--- CFProtectionOptions.h ----------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines constants for -fcf-protection and other related flags. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H +#define LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H + +#include "llvm/Support/ErrorHandling.h" + +namespace clang { + +enum class CFBranchLabelSchemeKind { + Default, +#define CF_BRANCH_LABEL_SCHEME(Kind, FlagVal) Kind, +#include "clang/Basic/CFProtectionOptions.def" +}; + +static inline const char * +getCFBranchLabelSchemeFlagVal(const CFBranchLabelSchemeKind Scheme) { +#define CF_BRANCH_LABEL_SCHEME(Kind, FlagVal) \ + if (Scheme == CFBranchLabelSchemeKind::Kind) \ + return #FlagVal; +#include "clang/Basic/CFProtectionOptions.def" + + llvm::report_fatal_error("invalid scheme"); +} + +} // namespace clang + +#endif // #ifndef LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index b600198998d85b..de7ae73f8a603b 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -110,6 +110,8 @@ CODEGENOPT(CFProtectionReturn , 1, 0) ///< if -fcf-protection is ///< set to full or return. CODEGENOPT(CFProtectionBranch , 1, 0) ///< if -fcf-protection is ///< set to full or branch. +ENUM_CODEGENOPT(CFBranchLabelScheme, CFBranchLabelSchemeKind, 2, + CFBranchLabelSchemeKind::Default) ///< if -mcf-branch-label-scheme is set. CODEGENOPT(FunctionReturnThunks, 1, 0) ///< -mfunction-return={keep|thunk-extern} CODEGENOPT(IndirectBranchCSPrefix, 1, 0) ///< if -mindirect-branch-cs-prefix ///< is set. diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h index f2a707a8ba8d76..a6953c17a447ef 100644 --- a/clang/include/clang/Basic/CodeGenOptions.h +++ b/clang/include/clang/Basic/CodeGenOptions.h @@ -13,6 +13,7 @@ #ifndef LLVM_CLANG_BASIC_CODEGENOPTIONS_H #define LLVM_CLANG_BASIC_CODEGENOPTIONS_H +#include "clang/Basic/CFProtectionOptions.h" #include "clang/Basic/PointerAuthOptions.h" #include "clang/Basic/Sanitizers.h" #include "clang/Basic/XRayInstr.h" diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index fd3346d29f26a3..68db400c22e6c1 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -364,6 +364,8 @@ BENIGN_LANGOPT(CompatibilityQualifiedIdBlockParamTypeChecking, 1, 0, LANGOPT(ObjCDisableDirectMethodsForTesting, 1, 0, "Disable recognition of objc_direct methods") LANGOPT(CFProtectionBranch , 1, 0, "Control-Flow Branch Protection enabled") +ENUM_LANGOPT(CFBranchLabelScheme, CFBranchLabelSchemeKind, 2, CFBranchLabelSchemeKind::Default, + "Control-Flow Branch Protection Label Scheme") LANGOPT(FakeAddressSpaceMap , 1, 0, "OpenCL fake address space map") ENUM_LANGOPT(AddressSpaceMapMangling , AddrSpaceMapMangling, 2, ASMM_Target, "OpenCL address space map mangling mode") LANGOPT(IncludeDefaultHeader, 1, 0, "Include default header file for OpenCL") diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index 6c186c410e158d..c3d53ca92d450c 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -14,6 +14,7 @@ #ifndef LLVM_CLANG_BASIC_LANGOPTIONS_H #define LLVM_CLANG_BASIC_LANGOPTIONS_H +#include "clang/Basic/CFProtectionOptions.h" #include "clang/Basic/CommentOptions.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/LangStandard.h" @@ -73,6 +74,7 @@ class LangOptionsBase { public: using Visibility = clang::Visibility; using RoundingMode = llvm::RoundingMode; + using CFBranchLabelSchemeKind = clang::CFBranchLabelSchemeKind; enum GCMode { NonGC, GCOnly, HybridGC }; enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq }; diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index f31d88a354ea28..4388500ce1bb51 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -16,6 +16,7 @@ #include "clang/Basic/AddressSpaces.h" #include "clang/Basic/BitmaskEnum.h" +#include "clang/Basic/CFProtectionOptions.h" #include "clang/Basic/CodeGenOptions.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" @@ -1727,6 +1728,12 @@ class TargetInfo : public TransferrableTargetInfo, virtual bool checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const; + /// Get the target default CFBranchLabelScheme scheme + virtual CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const; + + virtual bool + checkCFBranchLabelSchemeSupported(const CFBranchLabelSchemeKind Scheme) const; + /// Check if the target supports CFProtection return. virtual bool checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const; diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 002f60350543d9..ccbe302e4937e1 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2841,6 +2841,10 @@ def fcf_protection : Flag<["-"], "fcf-protection">, Group<f_Group>, Visibility<[ClangOption, CLOption, CC1Option]>, Alias<fcf_protection_EQ>, AliasArgs<["full"]>, HelpText<"Enable cf-protection in 'full' mode">; +def mcf_branch_label_scheme_EQ : Joined<["-"], "mcf-branch-label-scheme=">, + Visibility<[ClangOption, CC1Option]>, Group<m_Group>, + HelpText<"Select label scheme for branch control-flow architecture protection">, + Values<"unlabeled,func-sig">; def mfunction_return_EQ : Joined<["-"], "mfunction-return=">, Group<m_Group>, Visibility<[ClangOption, CLOption, CC1Option]>, HelpText<"Replace returns with jumps to ``__x86_return_thunk`` (x86 only, error otherwise)">, diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp index 29f5cd14e46e11..589acdb0796530 100644 --- a/clang/lib/Basic/TargetInfo.cpp +++ b/clang/lib/Basic/TargetInfo.cpp @@ -198,6 +198,16 @@ TargetInfo::checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const { return false; } +CFBranchLabelSchemeKind TargetInfo::getDefaultCFBranchLabelScheme() const { + // if this hook is called, the target should override it + llvm::report_fatal_error("not implemented"); +} + +bool TargetInfo::checkCFBranchLabelSchemeSupported( + const CFBranchLabelSchemeKind) const { + return false; +} + bool TargetInfo::checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const { Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=return"; diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index 351ef21e197c4d..413eb42b2e1e2c 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -134,6 +134,28 @@ class RISCVTargetInfo : public TargetInfo { bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize, bool &HasSizeMismatch) const override; + + bool + checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const override { + if (ISAInfo->hasExtension("zicfilp")) + return true; + return TargetInfo::checkCFProtectionBranchSupported(Diags); + } + + CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override { + return CFBranchLabelSchemeKind::FuncSig; + } + + bool checkCFBranchLabelSchemeSupported( + const CFBranchLabelSchemeKind Scheme) const override { + switch (Scheme) { + case CFBranchLabelSchemeKind::Default: + case CFBranchLabelSchemeKind::Unlabeled: + case CFBranchLabelSchemeKind::FuncSig: + return true; + } + return false; + } }; class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo { public: diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 0bab48caf1a5e2..d3c5c3d9872ee4 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -7012,6 +7012,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) { CmdArgs.push_back( Args.MakeArgString(Twine("-fcf-protection=") + A->getValue())); + + if (Arg *SA = Args.getLastArg(options::OPT_mcf_branch_label_scheme_EQ)) + CmdArgs.push_back(Args.MakeArgString(Twine("-mcf-branch-label-scheme=") + + SA->getValue())); } if (Arg *A = Args.getLastArg(options::OPT_mfunction_return_EQ)) diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index efd852593468aa..6c09843a7146f4 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1688,6 +1688,18 @@ void CompilerInvocationBase::GenerateCodeGenArgs(const CodeGenOptions &Opts, else if (Opts.CFProtectionBranch) GenerateArg(Consumer, OPT_fcf_protection_EQ, "branch"); + if (Opts.CFProtectionBranch) { + switch (Opts.getCFBranchLabelScheme()) { + case CFBranchLabelSchemeKind::Default: + break; +#define CF_BRANCH_LABEL_SCHEME(Kind, FlagVal) \ + case CFBranchLabelSchemeKind::Kind: \ + GenerateArg(Consumer, OPT_mcf_branch_label_scheme_EQ, #FlagVal); \ + break; +#include "clang/Basic/CFProtectionOptions.def" + } + } + if (Opts.FunctionReturnThunks) GenerateArg(Consumer, OPT_mfunction_return_EQ, "thunk-extern"); @@ -2022,6 +2034,22 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; } + if (Opts.CFProtectionBranch && T.isRISCV()) { + if (const Arg *A = Args.getLastArg(OPT_mcf_branch_label_scheme_EQ)) { + const auto Scheme = + llvm::StringSwitch<CFBranchLabelSchemeKind>(A->getValue()) +#define CF_BRANCH_LABEL_SCHEME(Kind, FlagVal) \ + .Case(#FlagVal, CFBranchLabelSchemeKind::Kind) +#include "clang/Basic/CFProtectionOptions.def" + .Default(CFBranchLabelSchemeKind::Default); + if (Scheme != CFBranchLabelSchemeKind::Default) + Opts.setCFBranchLabelScheme(Scheme); + else + Diags.Report(diag::err_drv_invalid_value) + << A->getAsString(Args) << A->getValue(); + } + } + if (const Arg *A = Args.getLastArg(OPT_mfunction_return_EQ)) { auto Val = llvm::StringSwitch<llvm::FunctionReturnThunksKind>(A->getValue()) .Case("keep", llvm::FunctionReturnThunksKind::Keep) @@ -3952,6 +3980,18 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, } } + if (Opts.CFProtectionBranch) { + if (const Arg *A = Args.getLastArg(OPT_mcf_branch_label_scheme_EQ)) { + const auto Scheme = + llvm::StringSwitch<CFBranchLabelSchemeKind>(A->getValue()) +#define CF_BRANCH_LABEL_SCHEME(Kind, FlagVal) \ + .Case(#FlagVal, CFBranchLabelSchemeKind::Kind) +#include "clang/Basic/CFProtectionOptions.def" + .Default(CFBranchLabelSchemeKind::Default); + Opts.setCFBranchLabelScheme(Scheme); + } + } + if ((Args.hasArg(OPT_fsycl_is_device) || Args.hasArg(OPT_fsycl_is_host)) && !Args.hasArg(OPT_sycl_std_EQ)) { // If the user supplied -fsycl-is-device or -fsycl-is-host, but failed to diff --git a/clang/test/CodeGen/RISCV/riscv-cf-protection.c b/clang/test/CodeGen/RISCV/riscv-cf-protection.c new file mode 100644 index 00000000000000..02a22006b1638f --- /dev/null +++ b/clang/test/CodeGen/RISCV/riscv-cf-protection.c @@ -0,0 +1,58 @@ +// RUN: %clang --target=riscv32 -menable-experimental-extensions \ +// RUN: -march=rv32i_zicfilp1p0 -mcf-branch-label-scheme=unlabeled -c %s \ +// RUN: -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-UNLABELED-SCHEME-UNUSED %s + +// RUN: %clang --target=riscv32 -menable-experimental-extensions \ +// RUN: -march=rv32i_zicfilp1p0 -mcf-branch-label-scheme=func-sig -c %s \ +// RUN: -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FUNC-SIG-SCHEME-UNUSED %s + +// RUN: not %clang --target=riscv32 -fcf-protection=branch \ +// RUN: -mcf-branch-label-scheme=unlabeled -c %s -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-BRANCH-PROT-INVALID %s + +// RUN: not %clang --target=riscv32 -fcf-protection=branch \ +// RUN: -mcf-branch-label-scheme=func-sig -c %s -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-BRANCH-PROT-INVALID %s + +// RUN: %clang --target=riscv32 -mcf-branch-label-scheme=unlabeled -c %s \ +// RUN: -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-UNLABELED-SCHEME-UNUSED %s + +// RUN: %clang --target=riscv32 -mcf-branch-label-scheme=func-sig -c %s \ +// RUN: -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FUNC-SIG-SCHEME-UNUSED %s + +// RUN: %clang --target=riscv64 -menable-experimental-extensions \ +// RUN: -march=rv64i_zicfilp1p0 -mcf-branch-label-scheme=unlabeled -c %s \ +// RUN: -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-UNLABELED-SCHEME-UNUSED %s + +// RUN: %clang --target=riscv64 -menable-experimental-extensions \ +// RUN: -march=rv64i_zicfilp1p0 -mcf-branch-label-scheme=func-sig -c %s \ +// RUN: -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FUNC-SIG-SCHEME-UNUSED %s + +// RUN: not %clang --target=riscv64 -fcf-protection=branch \ +// RUN: -mcf-branch-label-scheme=unlabeled -c %s -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-BRANCH-PROT-INVALID %s + +// RUN: not %clang --target=riscv64 -fcf-protection=branch \ +// RUN: -mcf-branch-label-scheme=func-sig -c %s -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-BRANCH-PROT-INVALID %s + +// RUN: %clang --target=riscv64 -mcf-branch-label-scheme=unlabeled -c %s \ +// RUN: -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-UNLABELED-SCHEME-UNUSED %s + +// RUN: %clang --target=riscv64 -mcf-branch-label-scheme=func-sig -c %s \ +// RUN: -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FUNC-SIG-SCHEME-UNUSED %s + +// CHECK-BRANCH-PROT-INVALID: error: option 'cf-protection=branch' cannot be +// CHECK-BRANCH-PROT-INVALID-SAME: specified on this target +// CHECK-UNLABELED-SCHEME-UNUSED: warning: argument unused during compilation: +// CHECK-UNLABELED-SCHEME-UNUSED-SAME: '-mcf-branch-label-scheme=unlabeled' +// CHECK-FUNC-SIG-SCHEME-UNUSED: warning: argument unused during compilation: +// CHECK-FUNC-SIG-SCHEME-UNUSED-SAME: '-mcf-branch-label-scheme=func-sig' >From f13e462407b4e2e41ca9d62ec8fff54099833ad5 Mon Sep 17 00:00:00 2001 From: Ming-Yi Lai <ming-yi....@mediatek.com> Date: Wed, 25 Sep 2024 11:05:40 +0800 Subject: [PATCH 2/4] [clang] Don't force diagnosing when checking if -fcf-protection=branch is supported This turns the target hook that checks if `-fcf-protection=branch` is supported into a pure check function that is suitable to be used in more places. --- clang/include/clang/Basic/TargetInfo.h | 3 +-- clang/lib/Basic/TargetInfo.cpp | 6 +----- clang/lib/Basic/Targets/RISCV.h | 7 ++----- clang/lib/Basic/Targets/X86.h | 7 ++----- clang/lib/CodeGen/CodeGenModule.cpp | 12 +++++++----- 5 files changed, 13 insertions(+), 22 deletions(-) diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index 4388500ce1bb51..4032d7840528dc 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -1725,8 +1725,7 @@ class TargetInfo : public TransferrableTargetInfo, } /// Check if the target supports CFProtection branch. - virtual bool - checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const; + virtual bool checkCFProtectionBranchSupported() const; /// Get the target default CFBranchLabelScheme scheme virtual CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const; diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp index 589acdb0796530..4108eba1916578 100644 --- a/clang/lib/Basic/TargetInfo.cpp +++ b/clang/lib/Basic/TargetInfo.cpp @@ -192,11 +192,7 @@ void TargetInfo::resetDataLayout(StringRef DL, const char *ULP) { UserLabelPrefix = ULP; } -bool -TargetInfo::checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const { - Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=branch"; - return false; -} +bool TargetInfo::checkCFProtectionBranchSupported() const { return false; } CFBranchLabelSchemeKind TargetInfo::getDefaultCFBranchLabelScheme() const { // if this hook is called, the target should override it diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index 413eb42b2e1e2c..8a2ee2cbee52b3 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -135,11 +135,8 @@ class RISCVTargetInfo : public TargetInfo { bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize, bool &HasSizeMismatch) const override; - bool - checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const override { - if (ISAInfo->hasExtension("zicfilp")) - return true; - return TargetInfo::checkCFProtectionBranchSupported(Diags); + bool checkCFProtectionBranchSupported() const override { + return ISAInfo->hasExtension("zicfilp"); } CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override { diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index a99ae62984c7d5..58344a2ad3227a 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -266,11 +266,8 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public TargetInfo { return TargetInfo::checkCFProtectionReturnSupported(Diags); }; - bool - checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const override { - if (CPU == llvm::X86::CK_None || CPU >= llvm::X86::CK_PentiumPro) - return true; - return TargetInfo::checkCFProtectionBranchSupported(Diags); + bool checkCFProtectionBranchSupported() const override { + return CPU == llvm::X86::CK_None || CPU >= llvm::X86::CK_PentiumPro; }; virtual bool validateOperandSize(const llvm::StringMap<bool> &FeatureMap, diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index d53d47979f29fb..cbedd9ab930821 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1159,11 +1159,13 @@ void CodeGenModule::Release() { 1); } - if (CodeGenOpts.CFProtectionBranch && - Target.checkCFProtectionBranchSupported(getDiags())) { - // Indicate that we want to instrument branch control flow protection. - getModule().addModuleFlag(llvm::Module::Min, "cf-protection-branch", - 1); + if (CodeGenOpts.CFProtectionBranch) { + if (Target.checkCFProtectionBranchSupported()) + // Indicate that we want to instrument branch control flow protection. + getModule().addModuleFlag(llvm::Module::Min, "cf-protection-branch", 1); + else + getDiags().Report(diag::err_opt_not_valid_on_target) + << "cf-protection=branch"; } if (CodeGenOpts.FunctionReturnThunks) >From 60a6830059012f736cbec7d86f605e83c27d3d21 Mon Sep 17 00:00:00 2001 From: Ming-Yi Lai <ming-yi....@mediatek.com> Date: Wed, 25 Sep 2024 11:55:40 +0800 Subject: [PATCH 3/4] [clang] Support diagnosing in TargetInfo::getTargetDefines() This allows reporting target-specific diagnostics when checking conditions for predefined macros --- clang/include/clang/Basic/TargetInfo.h | 5 +-- clang/lib/Basic/Targets/AArch64.cpp | 27 +++++++----- clang/lib/Basic/Targets/AArch64.h | 21 +++++----- clang/lib/Basic/Targets/AMDGPU.cpp | 3 +- clang/lib/Basic/Targets/AMDGPU.h | 4 +- clang/lib/Basic/Targets/ARC.cpp | 3 +- clang/lib/Basic/Targets/ARC.h | 4 +- clang/lib/Basic/Targets/ARM.cpp | 42 +++++++++++-------- clang/lib/Basic/Targets/ARM.h | 32 +++++++------- clang/lib/Basic/Targets/AVR.cpp | 3 +- clang/lib/Basic/Targets/AVR.h | 4 +- clang/lib/Basic/Targets/BPF.cpp | 3 +- clang/lib/Basic/Targets/BPF.h | 4 +- clang/lib/Basic/Targets/CSKY.cpp | 3 +- clang/lib/Basic/Targets/CSKY.h | 4 +- clang/lib/Basic/Targets/DirectX.cpp | 3 +- clang/lib/Basic/Targets/DirectX.h | 4 +- clang/lib/Basic/Targets/Hexagon.cpp | 3 +- clang/lib/Basic/Targets/Hexagon.h | 4 +- clang/lib/Basic/Targets/Lanai.cpp | 3 +- clang/lib/Basic/Targets/Lanai.h | 4 +- clang/lib/Basic/Targets/LoongArch.cpp | 3 +- clang/lib/Basic/Targets/LoongArch.h | 4 +- clang/lib/Basic/Targets/M68k.cpp | 3 +- clang/lib/Basic/Targets/M68k.h | 4 +- clang/lib/Basic/Targets/MSP430.cpp | 3 +- clang/lib/Basic/Targets/MSP430.h | 4 +- clang/lib/Basic/Targets/Mips.cpp | 3 +- clang/lib/Basic/Targets/Mips.h | 4 +- clang/lib/Basic/Targets/NVPTX.cpp | 3 +- clang/lib/Basic/Targets/NVPTX.h | 4 +- clang/lib/Basic/Targets/OSTargets.h | 6 +-- clang/lib/Basic/Targets/PNaCl.h | 4 +- clang/lib/Basic/Targets/PPC.cpp | 3 +- clang/lib/Basic/Targets/PPC.h | 4 +- clang/lib/Basic/Targets/RISCV.cpp | 3 +- clang/lib/Basic/Targets/RISCV.h | 4 +- clang/lib/Basic/Targets/SPIR.cpp | 36 +++++++++------- clang/lib/Basic/Targets/SPIR.h | 32 +++++++------- clang/lib/Basic/Targets/Sparc.cpp | 13 +++--- clang/lib/Basic/Targets/Sparc.h | 12 +++--- clang/lib/Basic/Targets/SystemZ.cpp | 3 +- clang/lib/Basic/Targets/SystemZ.h | 4 +- clang/lib/Basic/Targets/TCE.cpp | 6 ++- clang/lib/Basic/Targets/TCE.h | 8 ++-- clang/lib/Basic/Targets/VE.cpp | 3 +- clang/lib/Basic/Targets/VE.h | 4 +- clang/lib/Basic/Targets/WebAssembly.cpp | 13 +++--- clang/lib/Basic/Targets/WebAssembly.h | 12 +++--- clang/lib/Basic/Targets/X86.cpp | 3 +- clang/lib/Basic/Targets/X86.h | 56 ++++++++++++------------- clang/lib/Basic/Targets/XCore.cpp | 3 +- clang/lib/Basic/Targets/XCore.h | 4 +- clang/lib/Frontend/InitPreprocessor.cpp | 11 +++-- 54 files changed, 258 insertions(+), 207 deletions(-) diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index 4032d7840528dc..197ce442fff833 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -1004,9 +1004,8 @@ class TargetInfo : public TransferrableTargetInfo, /// Appends the target-specific \#define values for this /// target set to the specified buffer. - virtual void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const = 0; - + virtual void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const = 0; /// Return information about target-specific builtins for /// the current primary target, and info about which builtins are non-portable diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 5f5dfcb722f9d4..41171758596c69 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -374,7 +374,8 @@ void AArch64TargetInfo::getTargetDefinesARMV95A(const LangOptions &Opts, } void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { // Target identification. if (getTriple().isWindowsArm64EC()) { // Define the same set of macros as would be defined on x86_64 to ensure that @@ -1530,9 +1531,10 @@ void AArch64leTargetInfo::setDataLayout() { } void AArch64leTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { Builder.defineMacro("__AARCH64EL__"); - AArch64TargetInfo::getTargetDefines(Opts, Builder); + AArch64TargetInfo::getTargetDefines(Opts, Builder, Diags); } AArch64beTargetInfo::AArch64beTargetInfo(const llvm::Triple &Triple, @@ -1540,11 +1542,12 @@ AArch64beTargetInfo::AArch64beTargetInfo(const llvm::Triple &Triple, : AArch64TargetInfo(Triple, Opts) {} void AArch64beTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { Builder.defineMacro("__AARCH64EB__"); Builder.defineMacro("__AARCH_BIG_ENDIAN"); Builder.defineMacro("__ARM_BIG_ENDIAN"); - AArch64TargetInfo::getTargetDefines(Opts, Builder); + AArch64TargetInfo::getTargetDefines(Opts, Builder, Diags); } void AArch64beTargetInfo::setDataLayout() { @@ -1613,9 +1616,10 @@ MicrosoftARM64TargetInfo::MicrosoftARM64TargetInfo(const llvm::Triple &Triple, TheCXXABI.set(TargetCXXABI::Microsoft); } -void MicrosoftARM64TargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { - WindowsARM64TargetInfo::getTargetDefines(Opts, Builder); +void MicrosoftARM64TargetInfo::getTargetDefines( + const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { + WindowsARM64TargetInfo::getTargetDefines(Opts, Builder, Diags); if (getTriple().isWindowsArm64EC()) { Builder.defineMacro("_M_X64", "100"); Builder.defineMacro("_M_AMD64", "100"); @@ -1713,8 +1717,9 @@ RenderScript64TargetInfo::RenderScript64TargetInfo(const llvm::Triple &Triple, IsRenderScriptTarget = true; } -void RenderScript64TargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { +void RenderScript64TargetInfo::getTargetDefines( + const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { Builder.defineMacro("__RENDERSCRIPT__"); - AArch64leTargetInfo::getTargetDefines(Opts, Builder); + AArch64leTargetInfo::getTargetDefines(Opts, Builder, Diags); } diff --git a/clang/lib/Basic/Targets/AArch64.h b/clang/lib/Basic/Targets/AArch64.h index 526f7f30a38618..636db80a66cd75 100644 --- a/clang/lib/Basic/Targets/AArch64.h +++ b/clang/lib/Basic/Targets/AArch64.h @@ -148,8 +148,8 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo { MacroBuilder &Builder) const; void getTargetDefinesARMV95A(const LangOptions &Opts, MacroBuilder &Builder) const; - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; ArrayRef<Builtin::Info> getTargetBuiltins() const override; @@ -211,8 +211,9 @@ class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo { public: AArch64leTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; + private: void setDataLayout() override; }; @@ -239,8 +240,8 @@ class LLVM_LIBRARY_VISIBILITY MicrosoftARM64TargetInfo MicrosoftARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; TargetInfo::CallingConvKind getCallingConvKind(bool ClangABICompat4) const override; @@ -258,8 +259,8 @@ class LLVM_LIBRARY_VISIBILITY MinGWARM64TargetInfo class LLVM_LIBRARY_VISIBILITY AArch64beTargetInfo : public AArch64TargetInfo { public: AArch64beTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; private: void setDataLayout() override; @@ -284,8 +285,8 @@ class LLVM_LIBRARY_VISIBILITY RenderScript64TargetInfo RenderScript64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; }; } // namespace targets diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp b/clang/lib/Basic/Targets/AMDGPU.cpp index 3b748d0249d57b..673262d3e57227 100644 --- a/clang/lib/Basic/Targets/AMDGPU.cpp +++ b/clang/lib/Basic/Targets/AMDGPU.cpp @@ -272,7 +272,8 @@ ArrayRef<Builtin::Info> AMDGPUTargetInfo::getTargetBuiltins() const { } void AMDGPUTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { Builder.defineMacro("__AMD__"); Builder.defineMacro("__AMDGPU__"); diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h index 94d9ba93ed226f..a0fc2eeb7685c8 100644 --- a/clang/lib/Basic/Targets/AMDGPU.h +++ b/clang/lib/Basic/Targets/AMDGPU.h @@ -248,8 +248,8 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo { bool useFP16ConversionIntrinsics() const override { return false; } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; BuiltinVaListKind getBuiltinVaListKind() const override { return TargetInfo::CharPtrBuiltinVaList; diff --git a/clang/lib/Basic/Targets/ARC.cpp b/clang/lib/Basic/Targets/ARC.cpp index 5cc13e2cf72866..82005f311c81dd 100644 --- a/clang/lib/Basic/Targets/ARC.cpp +++ b/clang/lib/Basic/Targets/ARC.cpp @@ -19,6 +19,7 @@ using namespace clang; using namespace clang::targets; void ARCTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { Builder.defineMacro("__arc__"); } diff --git a/clang/lib/Basic/Targets/ARC.h b/clang/lib/Basic/Targets/ARC.h index fcbfdd6eec5862..29767b2166cf82 100644 --- a/clang/lib/Basic/Targets/ARC.h +++ b/clang/lib/Basic/Targets/ARC.h @@ -37,8 +37,8 @@ class LLVM_LIBRARY_VISIBILITY ARCTargetInfo : public TargetInfo { "i32:32:32-f32:32:32-i64:32-f64:32-a:0:32-n32"); } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; ArrayRef<Builtin::Info> getTargetBuiltins() const override { return std::nullopt; diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp index 7423626d7c3cbf..1efb96ae97a8ad 100644 --- a/clang/lib/Basic/Targets/ARM.cpp +++ b/clang/lib/Basic/Targets/ARM.cpp @@ -712,7 +712,8 @@ void ARMTargetInfo::getTargetDefinesARMV83A(const LangOptions &Opts, } void ARMTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { // Target identification. Builder.defineMacro("__arm"); Builder.defineMacro("__arm__"); @@ -1349,9 +1350,10 @@ ARMleTargetInfo::ARMleTargetInfo(const llvm::Triple &Triple, : ARMTargetInfo(Triple, Opts) {} void ARMleTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { Builder.defineMacro("__ARMEL__"); - ARMTargetInfo::getTargetDefines(Opts, Builder); + ARMTargetInfo::getTargetDefines(Opts, Builder, Diags); } ARMbeTargetInfo::ARMbeTargetInfo(const llvm::Triple &Triple, @@ -1359,10 +1361,11 @@ ARMbeTargetInfo::ARMbeTargetInfo(const llvm::Triple &Triple, : ARMTargetInfo(Triple, Opts) {} void ARMbeTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { Builder.defineMacro("__ARMEB__"); Builder.defineMacro("__ARM_BIG_ENDIAN"); - ARMTargetInfo::getTargetDefines(Opts, Builder); + ARMTargetInfo::getTargetDefines(Opts, Builder, Diags); } WindowsARMTargetInfo::WindowsARMTargetInfo(const llvm::Triple &Triple, @@ -1421,8 +1424,9 @@ ItaniumWindowsARMleTargetInfo::ItaniumWindowsARMleTargetInfo( } void ItaniumWindowsARMleTargetInfo::getTargetDefines( - const LangOptions &Opts, MacroBuilder &Builder) const { - WindowsARMTargetInfo::getTargetDefines(Opts, Builder); + const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { + WindowsARMTargetInfo::getTargetDefines(Opts, Builder, Diags); if (Opts.MSVCCompat) WindowsARMTargetInfo::getVisualStudioDefines(Opts, Builder); @@ -1435,9 +1439,10 @@ MicrosoftARMleTargetInfo::MicrosoftARMleTargetInfo(const llvm::Triple &Triple, TheCXXABI.set(TargetCXXABI::Microsoft); } -void MicrosoftARMleTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { - WindowsARMTargetInfo::getTargetDefines(Opts, Builder); +void MicrosoftARMleTargetInfo::getTargetDefines( + const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { + WindowsARMTargetInfo::getTargetDefines(Opts, Builder, Diags); WindowsARMTargetInfo::getVisualStudioDefines(Opts, Builder); } @@ -1448,8 +1453,9 @@ MinGWARMTargetInfo::MinGWARMTargetInfo(const llvm::Triple &Triple, } void MinGWARMTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { - WindowsARMTargetInfo::getTargetDefines(Opts, Builder); + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { + WindowsARMTargetInfo::getTargetDefines(Opts, Builder, Diags); Builder.defineMacro("_ARM_"); } @@ -1463,8 +1469,9 @@ CygwinARMTargetInfo::CygwinARMTargetInfo(const llvm::Triple &Triple, } void CygwinARMTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { - ARMleTargetInfo::getTargetDefines(Opts, Builder); + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { + ARMleTargetInfo::getTargetDefines(Opts, Builder, Diags); Builder.defineMacro("_ARM_"); Builder.defineMacro("__CYGWIN__"); Builder.defineMacro("__CYGWIN32__"); @@ -1503,8 +1510,9 @@ RenderScript32TargetInfo::RenderScript32TargetInfo(const llvm::Triple &Triple, LongWidth = LongAlign = 64; } -void RenderScript32TargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { +void RenderScript32TargetInfo::getTargetDefines( + const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { Builder.defineMacro("__RENDERSCRIPT__"); - ARMleTargetInfo::getTargetDefines(Opts, Builder); + ARMleTargetInfo::getTargetDefines(Opts, Builder, Diags); } diff --git a/clang/lib/Basic/Targets/ARM.h b/clang/lib/Basic/Targets/ARM.h index df9855a52e61c0..bd9b1a85a23756 100644 --- a/clang/lib/Basic/Targets/ARM.h +++ b/clang/lib/Basic/Targets/ARM.h @@ -193,8 +193,8 @@ class LLVM_LIBRARY_VISIBILITY ARMTargetInfo : public TargetInfo { MacroBuilder &Builder) const; void getTargetDefinesARMV83A(const LangOptions &Opts, MacroBuilder &Builder) const; - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; ArrayRef<Builtin::Info> getTargetBuiltins() const override; @@ -234,15 +234,15 @@ class LLVM_LIBRARY_VISIBILITY ARMTargetInfo : public TargetInfo { class LLVM_LIBRARY_VISIBILITY ARMleTargetInfo : public ARMTargetInfo { public: ARMleTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; }; class LLVM_LIBRARY_VISIBILITY ARMbeTargetInfo : public ARMTargetInfo { public: ARMbeTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; }; class LLVM_LIBRARY_VISIBILITY WindowsARMTargetInfo @@ -267,8 +267,8 @@ class LLVM_LIBRARY_VISIBILITY ItaniumWindowsARMleTargetInfo ItaniumWindowsARMleTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; }; // Windows ARM, MS (C++) ABI @@ -278,8 +278,8 @@ class LLVM_LIBRARY_VISIBILITY MicrosoftARMleTargetInfo MicrosoftARMleTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; }; // ARM MinGW target @@ -287,8 +287,8 @@ class LLVM_LIBRARY_VISIBILITY MinGWARMTargetInfo : public WindowsARMTargetInfo { public: MinGWARMTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; }; // ARM Cygwin target @@ -296,8 +296,8 @@ class LLVM_LIBRARY_VISIBILITY CygwinARMTargetInfo : public ARMleTargetInfo { public: CygwinARMTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; }; class LLVM_LIBRARY_VISIBILITY DarwinARMTargetInfo @@ -317,8 +317,8 @@ class LLVM_LIBRARY_VISIBILITY RenderScript32TargetInfo RenderScript32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; }; } // namespace targets diff --git a/clang/lib/Basic/Targets/AVR.cpp b/clang/lib/Basic/Targets/AVR.cpp index 85ca4bc30c4612..5e09c1d92c8fe4 100644 --- a/clang/lib/Basic/Targets/AVR.cpp +++ b/clang/lib/Basic/Targets/AVR.cpp @@ -446,7 +446,8 @@ AVRTargetInfo::handleAsmEscapedChar(char EscChar) const { } void AVRTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { Builder.defineMacro("AVR"); Builder.defineMacro("__AVR"); Builder.defineMacro("__AVR__"); diff --git a/clang/lib/Basic/Targets/AVR.h b/clang/lib/Basic/Targets/AVR.h index feeb04f37eeba7..b6e35213f27b76 100644 --- a/clang/lib/Basic/Targets/AVR.h +++ b/clang/lib/Basic/Targets/AVR.h @@ -58,8 +58,8 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public TargetInfo { resetDataLayout("e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8"); } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; ArrayRef<Builtin::Info> getTargetBuiltins() const override { return std::nullopt; diff --git a/clang/lib/Basic/Targets/BPF.cpp b/clang/lib/Basic/Targets/BPF.cpp index 931f407ecb0d7e..61ff7a5e7f87a4 100644 --- a/clang/lib/Basic/Targets/BPF.cpp +++ b/clang/lib/Basic/Targets/BPF.cpp @@ -26,7 +26,8 @@ static constexpr Builtin::Info BuiltinInfo[] = { }; void BPFTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { Builder.defineMacro("__bpf__"); Builder.defineMacro("__BPF__"); diff --git a/clang/lib/Basic/Targets/BPF.h b/clang/lib/Basic/Targets/BPF.h index d19b37dd4df7a7..5f1147ff02eb7a 100644 --- a/clang/lib/Basic/Targets/BPF.h +++ b/clang/lib/Basic/Targets/BPF.h @@ -44,8 +44,8 @@ class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo { TLSSupported = false; } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; bool hasFeature(StringRef Feature) const override { return Feature == "bpf" || Feature == "alu32" || Feature == "dwarfris"; diff --git a/clang/lib/Basic/Targets/CSKY.cpp b/clang/lib/Basic/Targets/CSKY.cpp index c8bf8b9234d243..0dbd0171bfdf87 100644 --- a/clang/lib/Basic/Targets/CSKY.cpp +++ b/clang/lib/Basic/Targets/CSKY.cpp @@ -32,7 +32,8 @@ bool CSKYTargetInfo::setCPU(const std::string &Name) { } void CSKYTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { Builder.defineMacro("__csky__", "2"); Builder.defineMacro("__CSKY__", "2"); Builder.defineMacro("__ckcore__", "2"); diff --git a/clang/lib/Basic/Targets/CSKY.h b/clang/lib/Basic/Targets/CSKY.h index 94d4eeb9a1fff4..c31c8bd6664e48 100644 --- a/clang/lib/Basic/Targets/CSKY.h +++ b/clang/lib/Basic/Targets/CSKY.h @@ -84,8 +84,8 @@ class LLVM_LIBRARY_VISIBILITY CSKYTargetInfo : public TargetInfo { std::string_view getClobbers() const override { return ""; } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; bool hasFeature(StringRef Feature) const override; bool handleTargetFeatures(std::vector<std::string> &Features, DiagnosticsEngine &Diags) override; diff --git a/clang/lib/Basic/Targets/DirectX.cpp b/clang/lib/Basic/Targets/DirectX.cpp index 0dd27e6e93b33b..5d216b17ccf934 100644 --- a/clang/lib/Basic/Targets/DirectX.cpp +++ b/clang/lib/Basic/Targets/DirectX.cpp @@ -17,6 +17,7 @@ using namespace clang; using namespace clang::targets; void DirectXTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { DefineStd(Builder, "DIRECTX", Opts); } diff --git a/clang/lib/Basic/Targets/DirectX.h b/clang/lib/Basic/Targets/DirectX.h index cf7ea5e83503dc..836c6ed6d9c874 100644 --- a/clang/lib/Basic/Targets/DirectX.h +++ b/clang/lib/Basic/Targets/DirectX.h @@ -65,8 +65,8 @@ class LLVM_LIBRARY_VISIBILITY DirectXTargetInfo : public TargetInfo { TheCXXABI.set(TargetCXXABI::Microsoft); } bool useFP16ConversionIntrinsics() const override { return false; } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; bool hasFeature(StringRef Feature) const override { return Feature == "directx"; diff --git a/clang/lib/Basic/Targets/Hexagon.cpp b/clang/lib/Basic/Targets/Hexagon.cpp index 0282ac812c306f..7022cf093af23d 100644 --- a/clang/lib/Basic/Targets/Hexagon.cpp +++ b/clang/lib/Basic/Targets/Hexagon.cpp @@ -20,7 +20,8 @@ using namespace clang; using namespace clang::targets; void HexagonTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { Builder.defineMacro("__qdsp6__", "1"); Builder.defineMacro("__hexagon__", "1"); diff --git a/clang/lib/Basic/Targets/Hexagon.h b/clang/lib/Basic/Targets/Hexagon.h index 7f053ab7e48886..dd4e1f443f9db8 100644 --- a/clang/lib/Basic/Targets/Hexagon.h +++ b/clang/lib/Basic/Targets/Hexagon.h @@ -88,8 +88,8 @@ class LLVM_LIBRARY_VISIBILITY HexagonTargetInfo : public TargetInfo { return false; } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; bool isCLZForZeroUndef() const override { return false; } diff --git a/clang/lib/Basic/Targets/Lanai.cpp b/clang/lib/Basic/Targets/Lanai.cpp index 8722a369ed87ff..80904d6677ca9e 100644 --- a/clang/lib/Basic/Targets/Lanai.cpp +++ b/clang/lib/Basic/Targets/Lanai.cpp @@ -55,7 +55,8 @@ bool LanaiTargetInfo::hasFeature(StringRef Feature) const { } void LanaiTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { // Define __lanai__ when building for target lanai. Builder.defineMacro("__lanai__"); diff --git a/clang/lib/Basic/Targets/Lanai.h b/clang/lib/Basic/Targets/Lanai.h index 144cbc7de98931..341dd1994738df 100644 --- a/clang/lib/Basic/Targets/Lanai.h +++ b/clang/lib/Basic/Targets/Lanai.h @@ -59,8 +59,8 @@ class LLVM_LIBRARY_VISIBILITY LanaiTargetInfo : public TargetInfo { MinGlobalAlign = 32; } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; bool isValidCPUName(StringRef Name) const override; diff --git a/clang/lib/Basic/Targets/LoongArch.cpp b/clang/lib/Basic/Targets/LoongArch.cpp index cb3fd12c48ddb6..af0d42d2e6156f 100644 --- a/clang/lib/Basic/Targets/LoongArch.cpp +++ b/clang/lib/Basic/Targets/LoongArch.cpp @@ -184,7 +184,8 @@ LoongArchTargetInfo::convertConstraint(const char *&Constraint) const { } void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { Builder.defineMacro("__loongarch__"); unsigned GRLen = getRegisterWidth(); Builder.defineMacro("__loongarch_grlen", Twine(GRLen)); diff --git a/clang/lib/Basic/Targets/LoongArch.h b/clang/lib/Basic/Targets/LoongArch.h index c668ca7eca047a..f7b428adf9969c 100644 --- a/clang/lib/Basic/Targets/LoongArch.h +++ b/clang/lib/Basic/Targets/LoongArch.h @@ -59,8 +59,8 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo { StringRef getABI() const override { return ABI; } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; ArrayRef<Builtin::Info> getTargetBuiltins() const override; diff --git a/clang/lib/Basic/Targets/M68k.cpp b/clang/lib/Basic/Targets/M68k.cpp index 8b8bf97d6f99a1..1300467b46ca9f 100644 --- a/clang/lib/Basic/Targets/M68k.cpp +++ b/clang/lib/Basic/Targets/M68k.cpp @@ -75,7 +75,8 @@ bool M68kTargetInfo::setCPU(const std::string &Name) { } void M68kTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { using llvm::Twine; Builder.defineMacro("__m68k__"); diff --git a/clang/lib/Basic/Targets/M68k.h b/clang/lib/Basic/Targets/M68k.h index b732add77e0340..c5e16e263bd55a 100644 --- a/clang/lib/Basic/Targets/M68k.h +++ b/clang/lib/Basic/Targets/M68k.h @@ -42,8 +42,8 @@ class LLVM_LIBRARY_VISIBILITY M68kTargetInfo : public TargetInfo { public: M68kTargetInfo(const llvm::Triple &Triple, const TargetOptions &); - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; ArrayRef<Builtin::Info> getTargetBuiltins() const override; bool hasFeature(StringRef Feature) const override; ArrayRef<const char *> getGCCRegNames() const override; diff --git a/clang/lib/Basic/Targets/MSP430.cpp b/clang/lib/Basic/Targets/MSP430.cpp index 844f5d3af70379..f7c236c4f708a3 100644 --- a/clang/lib/Basic/Targets/MSP430.cpp +++ b/clang/lib/Basic/Targets/MSP430.cpp @@ -26,7 +26,8 @@ ArrayRef<const char *> MSP430TargetInfo::getGCCRegNames() const { } void MSP430TargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { Builder.defineMacro("MSP430"); Builder.defineMacro("__MSP430__"); // FIXME: defines for different 'flavours' of MCU diff --git a/clang/lib/Basic/Targets/MSP430.h b/clang/lib/Basic/Targets/MSP430.h index 25639b8c1e0ad9..9da737dedd00c4 100644 --- a/clang/lib/Basic/Targets/MSP430.h +++ b/clang/lib/Basic/Targets/MSP430.h @@ -47,8 +47,8 @@ class LLVM_LIBRARY_VISIBILITY MSP430TargetInfo : public TargetInfo { SigAtomicType = SignedLong; resetDataLayout("e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16"); } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; ArrayRef<Builtin::Info> getTargetBuiltins() const override { // FIXME: Implement. diff --git a/clang/lib/Basic/Targets/Mips.cpp b/clang/lib/Basic/Targets/Mips.cpp index 174bc9d2ab9967..acdec64c36243e 100644 --- a/clang/lib/Basic/Targets/Mips.cpp +++ b/clang/lib/Basic/Targets/Mips.cpp @@ -69,7 +69,8 @@ unsigned MipsTargetInfo::getISARev() const { } void MipsTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { if (BigEndian) { DefineStd(Builder, "MIPSEB", Opts); Builder.defineMacro("_MIPSEB"); diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h index 45425db3ac27ad..b68febb51d6b65 100644 --- a/clang/lib/Basic/Targets/Mips.h +++ b/clang/lib/Basic/Targets/Mips.h @@ -194,8 +194,8 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo { unsigned getISARev() const; - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; ArrayRef<Builtin::Info> getTargetBuiltins() const override; diff --git a/clang/lib/Basic/Targets/NVPTX.cpp b/clang/lib/Basic/Targets/NVPTX.cpp index 43b653dc52ce0d..d6b3c0b3abc265 100644 --- a/clang/lib/Basic/Targets/NVPTX.cpp +++ b/clang/lib/Basic/Targets/NVPTX.cpp @@ -170,7 +170,8 @@ bool NVPTXTargetInfo::hasFeature(StringRef Feature) const { } void NVPTXTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { Builder.defineMacro("__PTX__"); Builder.defineMacro("__NVPTX__"); diff --git a/clang/lib/Basic/Targets/NVPTX.h b/clang/lib/Basic/Targets/NVPTX.h index 1ef20ce733917d..b10207f74561e2 100644 --- a/clang/lib/Basic/Targets/NVPTX.h +++ b/clang/lib/Basic/Targets/NVPTX.h @@ -70,8 +70,8 @@ class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo : public TargetInfo { NVPTXTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts, unsigned TargetPointerWidth); - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; ArrayRef<Builtin::Info> getTargetBuiltins() const override; diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index a83d6464e789d6..e003859c6bf91d 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -27,9 +27,9 @@ class LLVM_LIBRARY_VISIBILITY OSTargetInfo : public TgtInfo { OSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : TgtInfo(Triple, Opts) {} - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override { - TgtInfo::getTargetDefines(Opts, Builder); + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override { + TgtInfo::getTargetDefines(Opts, Builder, Diags); getOSDefines(Opts, TgtInfo::getTriple(), Builder); } }; diff --git a/clang/lib/Basic/Targets/PNaCl.h b/clang/lib/Basic/Targets/PNaCl.h index 595c4d83b1d1c3..281b902da4e760 100644 --- a/clang/lib/Basic/Targets/PNaCl.h +++ b/clang/lib/Basic/Targets/PNaCl.h @@ -43,8 +43,8 @@ class LLVM_LIBRARY_VISIBILITY PNaClTargetInfo : public TargetInfo { void getArchDefines(const LangOptions &Opts, MacroBuilder &Builder) const; - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override { + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override { getArchDefines(Opts, Builder); } diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp index 1448069173b5f4..7b1ec8697e38e0 100644 --- a/clang/lib/Basic/Targets/PPC.cpp +++ b/clang/lib/Basic/Targets/PPC.cpp @@ -288,7 +288,8 @@ static void defineXLCompatMacros(MacroBuilder &Builder) { /// PPCTargetInfo::getTargetDefines - Return a set of the PowerPC-specific /// #defines that are not tied to a specific subtarget. void PPCTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { // We define the XLC compatibility macros only on AIX and Linux since XLC // was never available on any other platforms. diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h index b0833d30550af4..66b0b49a6c7be0 100644 --- a/clang/lib/Basic/Targets/PPC.h +++ b/clang/lib/Basic/Targets/PPC.h @@ -191,8 +191,8 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo { bool isCLZForZeroUndef() const override { return false; } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; bool initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, diff --git a/clang/lib/Basic/Targets/RISCV.cpp b/clang/lib/Basic/Targets/RISCV.cpp index b6ea4440507ea1..d6f09ce70cbec6 100644 --- a/clang/lib/Basic/Targets/RISCV.cpp +++ b/clang/lib/Basic/Targets/RISCV.cpp @@ -130,7 +130,8 @@ static unsigned getVersionValue(unsigned MajorVersion, unsigned MinorVersion) { } void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { Builder.defineMacro("__riscv"); bool Is64Bit = getTriple().isRISCV64(); Builder.defineMacro("__riscv_xlen", Is64Bit ? "64" : "32"); diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index 8a2ee2cbee52b3..fc19c6ee9f286f 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -59,8 +59,8 @@ class RISCVTargetInfo : public TargetInfo { } StringRef getABI() const override { return ABI; } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; ArrayRef<Builtin::Info> getTargetBuiltins() const override; diff --git a/clang/lib/Basic/Targets/SPIR.cpp b/clang/lib/Basic/Targets/SPIR.cpp index 040303983594f8..a53ff119fd9495 100644 --- a/clang/lib/Basic/Targets/SPIR.cpp +++ b/clang/lib/Basic/Targets/SPIR.cpp @@ -19,41 +19,48 @@ using namespace clang; using namespace clang::targets; void SPIRTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { DefineStd(Builder, "SPIR", Opts); } void SPIR32TargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { - SPIRTargetInfo::getTargetDefines(Opts, Builder); + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { + SPIRTargetInfo::getTargetDefines(Opts, Builder, Diags); DefineStd(Builder, "SPIR32", Opts); } void SPIR64TargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { - SPIRTargetInfo::getTargetDefines(Opts, Builder); + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { + SPIRTargetInfo::getTargetDefines(Opts, Builder, Diags); DefineStd(Builder, "SPIR64", Opts); } void BaseSPIRVTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { DefineStd(Builder, "SPIRV", Opts); } void SPIRVTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { - BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder); + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { + BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder, Diags); } void SPIRV32TargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { - BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder); + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { + BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder, Diags); DefineStd(Builder, "SPIRV32", Opts); } void SPIRV64TargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { - BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder); + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { + BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder, Diags); DefineStd(Builder, "SPIRV64", Opts); } @@ -86,8 +93,9 @@ ArrayRef<Builtin::Info> SPIRV64AMDGCNTargetInfo::getTargetBuiltins() const { } void SPIRV64AMDGCNTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { - BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder); + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { + BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder, Diags); DefineStd(Builder, "SPIRV64", Opts); Builder.defineMacro("__AMD__"); diff --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h index 37cf9d7921bac5..572d5b024d626a 100644 --- a/clang/lib/Basic/Targets/SPIR.h +++ b/clang/lib/Basic/Targets/SPIR.h @@ -239,8 +239,8 @@ class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public BaseSPIRTargetInfo { "SPIR target must use unknown environment type"); } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; bool hasFeature(StringRef Feature) const override { return Feature == "spir"; @@ -262,8 +262,8 @@ class LLVM_LIBRARY_VISIBILITY SPIR32TargetInfo : public SPIRTargetInfo { "v96:128-v192:256-v256:256-v512:512-v1024:1024-G1"); } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; }; class LLVM_LIBRARY_VISIBILITY SPIR64TargetInfo : public SPIRTargetInfo { @@ -279,8 +279,8 @@ class LLVM_LIBRARY_VISIBILITY SPIR64TargetInfo : public SPIRTargetInfo { "v96:128-v192:256-v256:256-v512:512-v1024:1024-G1"); } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; }; class LLVM_LIBRARY_VISIBILITY BaseSPIRVTargetInfo : public BaseSPIRTargetInfo { @@ -294,8 +294,8 @@ class LLVM_LIBRARY_VISIBILITY BaseSPIRVTargetInfo : public BaseSPIRTargetInfo { return Feature == "spirv"; } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; }; class LLVM_LIBRARY_VISIBILITY SPIRVTargetInfo : public BaseSPIRVTargetInfo { @@ -318,8 +318,8 @@ class LLVM_LIBRARY_VISIBILITY SPIRVTargetInfo : public BaseSPIRVTargetInfo { "v96:128-v192:256-v256:256-v512:512-v1024:1024-G1"); } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; }; class LLVM_LIBRARY_VISIBILITY SPIRV32TargetInfo : public BaseSPIRVTargetInfo { @@ -339,8 +339,8 @@ class LLVM_LIBRARY_VISIBILITY SPIRV32TargetInfo : public BaseSPIRVTargetInfo { "v96:128-v192:256-v256:256-v512:512-v1024:1024-G1"); } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; }; class LLVM_LIBRARY_VISIBILITY SPIRV64TargetInfo : public BaseSPIRVTargetInfo { @@ -360,8 +360,8 @@ class LLVM_LIBRARY_VISIBILITY SPIRV64TargetInfo : public BaseSPIRVTargetInfo { "v96:128-v192:256-v256:256-v512:512-v1024:1024-G1"); } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; }; class LLVM_LIBRARY_VISIBILITY SPIRV64AMDGCNTargetInfo final @@ -407,8 +407,8 @@ class LLVM_LIBRARY_VISIBILITY SPIRV64AMDGCNTargetInfo final ArrayRef<Builtin::Info> getTargetBuiltins() const override; - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; void setAuxTarget(const TargetInfo *Aux) override; diff --git a/clang/lib/Basic/Targets/Sparc.cpp b/clang/lib/Basic/Targets/Sparc.cpp index d1a891092b0f5c..2410bf6a02238f 100644 --- a/clang/lib/Basic/Targets/Sparc.cpp +++ b/clang/lib/Basic/Targets/Sparc.cpp @@ -130,7 +130,8 @@ void SparcTargetInfo::fillValidCPUList( } void SparcTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { DefineStd(Builder, "sparc", Opts); Builder.defineMacro("__REGISTER_PREFIX__", ""); @@ -139,8 +140,9 @@ void SparcTargetInfo::getTargetDefines(const LangOptions &Opts, } void SparcV8TargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { - SparcTargetInfo::getTargetDefines(Opts, Builder); + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { + SparcTargetInfo::getTargetDefines(Opts, Builder, Diags); if (getTriple().isOSSolaris()) Builder.defineMacro("__sparcv8"); else { @@ -163,8 +165,9 @@ void SparcV8TargetInfo::getTargetDefines(const LangOptions &Opts, } void SparcV9TargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { - SparcTargetInfo::getTargetDefines(Opts, Builder); + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { + SparcTargetInfo::getTargetDefines(Opts, Builder, Diags); Builder.defineMacro("__sparcv9"); Builder.defineMacro("__arch64__"); // Solaris doesn't need these variants, but the BSDs do. diff --git a/clang/lib/Basic/Targets/Sparc.h b/clang/lib/Basic/Targets/Sparc.h index 3357bee33e1ac7..30c8671149d388 100644 --- a/clang/lib/Basic/Targets/Sparc.h +++ b/clang/lib/Basic/Targets/Sparc.h @@ -43,8 +43,8 @@ class LLVM_LIBRARY_VISIBILITY SparcTargetInfo : public TargetInfo { SoftFloat = true; return true; } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; bool hasFeature(StringRef Feature) const override; @@ -177,8 +177,8 @@ class LLVM_LIBRARY_VISIBILITY SparcV8TargetInfo : public SparcTargetInfo { MaxAtomicInlineWidth = 32; } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; bool hasBitIntType() const override { return true; } }; @@ -218,8 +218,8 @@ class LLVM_LIBRARY_VISIBILITY SparcV9TargetInfo : public SparcTargetInfo { MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64; } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; bool isValidCPUName(StringRef Name) const override { return getCPUGeneration(SparcTargetInfo::getCPUKind(Name)) == CG_V9; diff --git a/clang/lib/Basic/Targets/SystemZ.cpp b/clang/lib/Basic/Targets/SystemZ.cpp index 06f08db2eadd47..2092de17b3333c 100644 --- a/clang/lib/Basic/Targets/SystemZ.cpp +++ b/clang/lib/Basic/Targets/SystemZ.cpp @@ -149,7 +149,8 @@ unsigned SystemZTargetInfo::getMinGlobalAlign(uint64_t Size, } void SystemZTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { Builder.defineMacro("__s390__"); Builder.defineMacro("__s390x__"); Builder.defineMacro("__zarch__"); diff --git a/clang/lib/Basic/Targets/SystemZ.h b/clang/lib/Basic/Targets/SystemZ.h index f05ea473017bec..928a2aeada29ad 100644 --- a/clang/lib/Basic/Targets/SystemZ.h +++ b/clang/lib/Basic/Targets/SystemZ.h @@ -96,8 +96,8 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo { unsigned getMinGlobalAlign(uint64_t Size, bool HasNonWeakDef) const override; - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; ArrayRef<Builtin::Info> getTargetBuiltins() const override; diff --git a/clang/lib/Basic/Targets/TCE.cpp b/clang/lib/Basic/Targets/TCE.cpp index 91194b568a09f8..352ff0e842ecf8 100644 --- a/clang/lib/Basic/Targets/TCE.cpp +++ b/clang/lib/Basic/Targets/TCE.cpp @@ -18,14 +18,16 @@ using namespace clang; using namespace clang::targets; void TCETargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { DefineStd(Builder, "tce", Opts); Builder.defineMacro("__TCE__"); Builder.defineMacro("__TCE_V1__"); } void TCELETargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { DefineStd(Builder, "tcele", Opts); Builder.defineMacro("__TCE__"); Builder.defineMacro("__TCE_V1__"); diff --git a/clang/lib/Basic/Targets/TCE.h b/clang/lib/Basic/Targets/TCE.h index dcf684fe6dbc01..aea022884d5e59 100644 --- a/clang/lib/Basic/Targets/TCE.h +++ b/clang/lib/Basic/Targets/TCE.h @@ -90,8 +90,8 @@ class LLVM_LIBRARY_VISIBILITY TCETargetInfo : public TargetInfo { UseAddrSpaceMapMangling = true; } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; bool hasFeature(StringRef Feature) const override { return Feature == "tce"; } @@ -132,8 +132,8 @@ class LLVM_LIBRARY_VISIBILITY TCELETargetInfo : public TCETargetInfo { "v1024:32:32-a0:0:32-n32"); } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; }; } // namespace targets } // namespace clang diff --git a/clang/lib/Basic/Targets/VE.cpp b/clang/lib/Basic/Targets/VE.cpp index 67cae8faf60522..cdbf3a780ecca6 100644 --- a/clang/lib/Basic/Targets/VE.cpp +++ b/clang/lib/Basic/Targets/VE.cpp @@ -25,7 +25,8 @@ static constexpr Builtin::Info BuiltinInfo[] = { }; void VETargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { Builder.defineMacro("__ve", "1"); Builder.defineMacro("__ve__", "1"); Builder.defineMacro("__NEC__", "1"); diff --git a/clang/lib/Basic/Targets/VE.h b/clang/lib/Basic/Targets/VE.h index 7e8fdf6096ef23..b88d33855cee91 100644 --- a/clang/lib/Basic/Targets/VE.h +++ b/clang/lib/Basic/Targets/VE.h @@ -50,8 +50,8 @@ class LLVM_LIBRARY_VISIBILITY VETargetInfo : public TargetInfo { "v1024:64:64-v2048:64:64-v4096:64:64-v8192:64:64-v16384:64:64"); } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; bool hasSjLjLowering() const override { return true; } diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp b/clang/lib/Basic/Targets/WebAssembly.cpp index 5ac9421663adea..7eaaf87335068b 100644 --- a/clang/lib/Basic/Targets/WebAssembly.cpp +++ b/clang/lib/Basic/Targets/WebAssembly.cpp @@ -72,7 +72,8 @@ void WebAssemblyTargetInfo::fillValidCPUList( } void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { defineCPUMacros(Builder, "wasm", /*Tuning=*/false); if (HasAtomics) Builder.defineMacro("__wasm_atomics__"); @@ -320,13 +321,15 @@ void WebAssemblyTargetInfo::adjust(DiagnosticsEngine &Diags, } void WebAssembly32TargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { - WebAssemblyTargetInfo::getTargetDefines(Opts, Builder); + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { + WebAssemblyTargetInfo::getTargetDefines(Opts, Builder, Diags); defineCPUMacros(Builder, "wasm32", /*Tuning=*/false); } void WebAssembly64TargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { - WebAssemblyTargetInfo::getTargetDefines(Opts, Builder); + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { + WebAssemblyTargetInfo::getTargetDefines(Opts, Builder, Diags); defineCPUMacros(Builder, "wasm64", /*Tuning=*/false); } diff --git a/clang/lib/Basic/Targets/WebAssembly.h b/clang/lib/Basic/Targets/WebAssembly.h index 213ec42ca84bb7..fb1e7583af1b08 100644 --- a/clang/lib/Basic/Targets/WebAssembly.h +++ b/clang/lib/Basic/Targets/WebAssembly.h @@ -93,8 +93,8 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo { bool useFP16ConversionIntrinsics() const override { return !HasFP16; } protected: - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; private: static void setSIMDLevel(llvm::StringMap<bool> &Features, SIMDEnum Level, @@ -187,8 +187,8 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo } protected: - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; }; class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo @@ -211,8 +211,8 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo } protected: - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; }; } // namespace targets } // namespace clang diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp index 5448bd841959f4..fa2fe682ac57dc 100644 --- a/clang/lib/Basic/Targets/X86.cpp +++ b/clang/lib/Basic/Targets/X86.cpp @@ -522,7 +522,8 @@ bool X86TargetInfo::handleTargetFeatures(std::vector<std::string> &Features, /// X86TargetInfo::getTargetDefines - Return the set of the X86-specific macro /// definitions for this particular subtarget. void X86TargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { // Inline assembly supports X86 flag outputs. Builder.defineMacro("__GCC_ASM_FLAG_OUTPUTS__"); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 58344a2ad3227a..3af20f6427b2fb 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -319,8 +319,8 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public TargetInfo { return false; } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name, bool Enabled) const final; @@ -587,9 +587,9 @@ class LLVM_LIBRARY_VISIBILITY MicrosoftX86_32TargetInfo LongDoubleFormat = &llvm::APFloat::IEEEdouble(); } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override { - WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder); + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override { + WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder, Diags); // The value of the following reflects processor type. // 300=386, 400=486, 500=Pentium, 600=Blend (default) // We lost the original triple, so we use the default. @@ -606,9 +606,9 @@ class LLVM_LIBRARY_VISIBILITY MinGWX86_32TargetInfo HasFloat128 = true; } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override { - WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder); + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override { + WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder, Diags); Builder.defineMacro("_X86_"); } }; @@ -625,9 +625,9 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_32TargetInfo : public X86_32TargetInfo { "_"); } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override { - X86_32TargetInfo::getTargetDefines(Opts, Builder); + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override { + X86_32TargetInfo::getTargetDefines(Opts, Builder, Diags); Builder.defineMacro("_X86_"); Builder.defineMacro("__CYGWIN__"); Builder.defineMacro("__CYGWIN32__"); @@ -645,9 +645,9 @@ class LLVM_LIBRARY_VISIBILITY HaikuX86_32TargetInfo HaikuX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : HaikuTargetInfo<X86_32TargetInfo>(Triple, Opts) {} - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override { - HaikuTargetInfo<X86_32TargetInfo>::getTargetDefines(Opts, Builder); + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override { + HaikuTargetInfo<X86_32TargetInfo>::getTargetDefines(Opts, Builder, Diags); Builder.defineMacro("__INTEL__"); } }; @@ -670,9 +670,9 @@ class LLVM_LIBRARY_VISIBILITY MCUX86_32TargetInfo : public X86_32TargetInfo { return CC == CC_C ? CCCR_OK : CCCR_Warning; } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override { - X86_32TargetInfo::getTargetDefines(Opts, Builder); + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override { + X86_32TargetInfo::getTargetDefines(Opts, Builder, Diags); Builder.defineMacro("__iamcu"); Builder.defineMacro("__iamcu__"); } @@ -690,9 +690,9 @@ class LLVM_LIBRARY_VISIBILITY RTEMSX86_32TargetInfo : public X86_32TargetInfo { PtrDiffType = SignedLong; } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override { - X86_32TargetInfo::getTargetDefines(Opts, Builder); + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override { + X86_32TargetInfo::getTargetDefines(Opts, Builder, Diags); Builder.defineMacro("__INTEL__"); Builder.defineMacro("__rtems__"); } @@ -823,8 +823,8 @@ class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo "i64:64-i128:128-f80:128-n8:16:32:64-S128"); } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override { + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override { getOSDefines(Opts, X86TargetInfo::getTriple(), Builder); } @@ -902,9 +902,9 @@ class LLVM_LIBRARY_VISIBILITY MicrosoftX86_64TargetInfo LongDoubleFormat = &llvm::APFloat::IEEEdouble(); } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override { - WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder); + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override { + WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder, Diags); Builder.defineMacro("_M_X64", "100"); Builder.defineMacro("_M_AMD64", "100"); } @@ -938,9 +938,9 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_64TargetInfo : public X86_64TargetInfo { TLSSupported = false; } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override { - X86_64TargetInfo::getTargetDefines(Opts, Builder); + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override { + X86_64TargetInfo::getTargetDefines(Opts, Builder, Diags); Builder.defineMacro("__x86_64__"); Builder.defineMacro("__CYGWIN__"); Builder.defineMacro("__CYGWIN64__"); diff --git a/clang/lib/Basic/Targets/XCore.cpp b/clang/lib/Basic/Targets/XCore.cpp index fd377bbfb90e16..887367e033520a 100644 --- a/clang/lib/Basic/Targets/XCore.cpp +++ b/clang/lib/Basic/Targets/XCore.cpp @@ -27,7 +27,8 @@ static constexpr Builtin::Info BuiltinInfo[] = { }; void XCoreTargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) const { Builder.defineMacro("__xcore__"); Builder.defineMacro("__XS1B__"); } diff --git a/clang/lib/Basic/Targets/XCore.h b/clang/lib/Basic/Targets/XCore.h index a58d3e8acf4791..9def027dd1dac6 100644 --- a/clang/lib/Basic/Targets/XCore.h +++ b/clang/lib/Basic/Targets/XCore.h @@ -40,8 +40,8 @@ class LLVM_LIBRARY_VISIBILITY XCoreTargetInfo : public TargetInfo { "-f64:32-a:0:32-n32"); } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder, + DiagnosticsEngine &Diags) const override; ArrayRef<Builtin::Info> getTargetBuiltins() const override; diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 9a0fdb175ff29e..8e1ae06d204814 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -852,7 +852,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI, const LangOptions &LangOpts, const FrontendOptions &FEOpts, const PreprocessorOptions &PPOpts, - MacroBuilder &Builder) { + MacroBuilder &Builder, + DiagnosticsEngine &Diags) { // Compiler version introspection macros. Builder.defineMacro("__llvm__"); // LLVM Backend Builder.defineMacro("__clang__"); // Clang Frontend @@ -1509,7 +1510,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI, } // Get other target #defines. - TI.getTargetDefines(LangOpts, Builder); + TI.getTargetDefines(LangOpts, Builder, Diags); } static void InitializePGOProfileMacros(const CodeGenOptions &CodeGenOpts, @@ -1547,10 +1548,12 @@ void clang::InitializePreprocessor(Preprocessor &PP, LangOpts.SYCLIsDevice) && PP.getAuxTargetInfo()) InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts, - PP.getPreprocessorOpts(), Builder); + PP.getPreprocessorOpts(), Builder, + PP.getDiagnostics()); InitializePredefinedMacros(PP.getTargetInfo(), LangOpts, FEOpts, - PP.getPreprocessorOpts(), Builder); + PP.getPreprocessorOpts(), Builder, + PP.getDiagnostics()); // Install definitions to make Objective-C++ ARC work well with various // C++ Standard Library implementations. >From 9addd946958d072ff5f21044461fde27fa626770 Mon Sep 17 00:00:00 2001 From: Ming-Yi Lai <ming-yi....@mediatek.com> Date: Fri, 10 May 2024 14:16:59 +0800 Subject: [PATCH 4/4] [clang][RISCV] Add Zicfilp CFI scheme preprocessor macros These macros allow assembly files to know which CFI label to use when the target has Zicfilp enabled. --- clang/lib/Basic/Targets/RISCV.cpp | 28 ++++++ .../test/CodeGen/RISCV/riscv-cf-protection.c | 99 +++++++++++++------ 2 files changed, 95 insertions(+), 32 deletions(-) diff --git a/clang/lib/Basic/Targets/RISCV.cpp b/clang/lib/Basic/Targets/RISCV.cpp index d6f09ce70cbec6..32fb2e003a4a71 100644 --- a/clang/lib/Basic/Targets/RISCV.cpp +++ b/clang/lib/Basic/Targets/RISCV.cpp @@ -225,6 +225,34 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts, else Builder.defineMacro("__riscv_32e"); } + + if (Opts.CFProtectionBranch) { + if (checkCFProtectionBranchSupported()) { + auto Scheme = Opts.getCFBranchLabelScheme(); + if (checkCFBranchLabelSchemeSupported(Scheme)) { + if (Scheme == CFBranchLabelSchemeKind::Default) + Scheme = getDefaultCFBranchLabelScheme(); + + Builder.defineMacro("__riscv_landing_pad", "1"); + switch (Scheme) { + case CFBranchLabelSchemeKind::Unlabeled: + Builder.defineMacro("__riscv_landing_pad_unlabeled", "1"); + break; + case CFBranchLabelSchemeKind::FuncSig: + Builder.defineMacro("__riscv_landing_pad_func_sig", "1"); + break; + case CFBranchLabelSchemeKind::Default: + llvm_unreachable("default cf-branch-label scheme should already be " + "transformed to other scheme"); + } + } else + Diags.Report(diag::err_opt_not_valid_on_target) + << (Twine("-mcf-branch-label-scheme=") + + getCFBranchLabelSchemeFlagVal(Scheme)) + .str(); + } else + Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=branch"; + } } static constexpr Builtin::Info BuiltinInfo[] = { diff --git a/clang/test/CodeGen/RISCV/riscv-cf-protection.c b/clang/test/CodeGen/RISCV/riscv-cf-protection.c index 02a22006b1638f..4de45e0c4ef416 100644 --- a/clang/test/CodeGen/RISCV/riscv-cf-protection.c +++ b/clang/test/CodeGen/RISCV/riscv-cf-protection.c @@ -1,55 +1,90 @@ +// Default cf-branch-label-scheme is func-sig // RUN: %clang --target=riscv32 -menable-experimental-extensions \ -// RUN: -march=rv32i_zicfilp1p0 -mcf-branch-label-scheme=unlabeled -c %s \ -// RUN: -o /dev/null 2>&1 \ -// RUN: | FileCheck --check-prefix=CHECK-UNLABELED-SCHEME-UNUSED %s +// RUN: -march=rv32i_zicfilp1p0 -fcf-protection=branch -E -dM %s -o - \ +// RUN: | FileCheck --check-prefix=CHECK-ZICFILP-FUNC-SIG %s +// RUN: %clang --target=riscv64 -menable-experimental-extensions \ +// RUN: -march=rv64i_zicfilp1p0 -fcf-protection=branch -E -dM %s -o - \ +// RUN: | FileCheck --check-prefix=CHECK-ZICFILP-FUNC-SIG %s + +// RUN: %clang --target=riscv32 -menable-experimental-extensions \ +// RUN: -march=rv32i_zicfilp1p0 -fcf-protection=branch \ +// RUN: -mcf-branch-label-scheme=unlabeled -E -dM %s -o - \ +// RUN: | FileCheck --check-prefix=CHECK-ZICFILP-UNLABELED %s // RUN: %clang --target=riscv32 -menable-experimental-extensions \ -// RUN: -march=rv32i_zicfilp1p0 -mcf-branch-label-scheme=func-sig -c %s \ -// RUN: -o /dev/null 2>&1 \ -// RUN: | FileCheck --check-prefix=CHECK-FUNC-SIG-SCHEME-UNUSED %s +// RUN: -march=rv32i_zicfilp1p0 -fcf-protection=branch \ +// RUN: -mcf-branch-label-scheme=func-sig -E -dM %s -o - \ +// RUN: | FileCheck --check-prefix=CHECK-ZICFILP-FUNC-SIG %s + +// RUN: %clang --target=riscv32 -menable-experimental-extensions \ +// RUN: -march=rv32i_zicfilp1p0 -mcf-branch-label-scheme=unlabeled -E -dM %s \ +// RUN: -o - 2>&1 | FileCheck \ +// RUN: --check-prefixes=CHECK-NO-MACRO,CHECK-UNLABELED-SCHEME-UNUSED %s + +// RUN: %clang --target=riscv32 -menable-experimental-extensions \ +// RUN: -march=rv32i_zicfilp1p0 -mcf-branch-label-scheme=func-sig -E -dM %s \ +// RUN: -o - 2>&1 | FileCheck \ +// RUN: --check-prefixes=CHECK-NO-MACRO,CHECK-FUNC-SIG-SCHEME-UNUSED %s // RUN: not %clang --target=riscv32 -fcf-protection=branch \ -// RUN: -mcf-branch-label-scheme=unlabeled -c %s -o /dev/null 2>&1 \ -// RUN: | FileCheck --check-prefix=CHECK-BRANCH-PROT-INVALID %s +// RUN: -mcf-branch-label-scheme=unlabeled -E -dM %s -o - 2>&1 | FileCheck \ +// RUN: --check-prefixes=CHECK-NO-MACRO,CHECK-BRANCH-PROT-INVALID %s // RUN: not %clang --target=riscv32 -fcf-protection=branch \ -// RUN: -mcf-branch-label-scheme=func-sig -c %s -o /dev/null 2>&1 \ -// RUN: | FileCheck --check-prefix=CHECK-BRANCH-PROT-INVALID %s +// RUN: -mcf-branch-label-scheme=func-sig -E -dM %s -o - 2>&1 | FileCheck \ +// RUN: --check-prefixes=CHECK-NO-MACRO,CHECK-BRANCH-PROT-INVALID %s + +// RUN: %clang --target=riscv32 -mcf-branch-label-scheme=unlabeled -E -dM %s \ +// RUN: -o - 2>&1 | FileCheck \ +// RUN: --check-prefixes=CHECK-NO-MACRO,CHECK-UNLABELED-SCHEME-UNUSED %s -// RUN: %clang --target=riscv32 -mcf-branch-label-scheme=unlabeled -c %s \ -// RUN: -o /dev/null 2>&1 \ -// RUN: | FileCheck --check-prefix=CHECK-UNLABELED-SCHEME-UNUSED %s +// RUN: %clang --target=riscv32 -mcf-branch-label-scheme=func-sig -E -dM %s \ +// RUN: -o - 2>&1 | FileCheck \ +// RUN: --check-prefixes=CHECK-NO-MACRO,CHECK-FUNC-SIG-SCHEME-UNUSED %s -// RUN: %clang --target=riscv32 -mcf-branch-label-scheme=func-sig -c %s \ -// RUN: -o /dev/null 2>&1 \ -// RUN: | FileCheck --check-prefix=CHECK-FUNC-SIG-SCHEME-UNUSED %s +// RUN: %clang --target=riscv64 -menable-experimental-extensions \ +// RUN: -march=rv64i_zicfilp1p0 -fcf-protection=branch \ +// RUN: -mcf-branch-label-scheme=unlabeled -E -dM %s -o - \ +// RUN: | FileCheck --check-prefix=CHECK-ZICFILP-UNLABELED %s + +// RUN: %clang --target=riscv64 -menable-experimental-extensions \ +// RUN: -march=rv64i_zicfilp1p0 -fcf-protection=branch \ +// RUN: -mcf-branch-label-scheme=func-sig -E -dM %s -o - \ +// RUN: | FileCheck --check-prefix=CHECK-ZICFILP-FUNC-SIG %s // RUN: %clang --target=riscv64 -menable-experimental-extensions \ -// RUN: -march=rv64i_zicfilp1p0 -mcf-branch-label-scheme=unlabeled -c %s \ -// RUN: -o /dev/null 2>&1 \ -// RUN: | FileCheck --check-prefix=CHECK-UNLABELED-SCHEME-UNUSED %s +// RUN: -march=rv64i_zicfilp1p0 -mcf-branch-label-scheme=unlabeled -E -dM %s \ +// RUN: -o - 2>&1 | FileCheck \ +// RUN: --check-prefixes=CHECK-NO-MACRO,CHECK-UNLABELED-SCHEME-UNUSED %s // RUN: %clang --target=riscv64 -menable-experimental-extensions \ -// RUN: -march=rv64i_zicfilp1p0 -mcf-branch-label-scheme=func-sig -c %s \ -// RUN: -o /dev/null 2>&1 \ -// RUN: | FileCheck --check-prefix=CHECK-FUNC-SIG-SCHEME-UNUSED %s +// RUN: -march=rv64i_zicfilp1p0 -mcf-branch-label-scheme=func-sig -E -dM %s \ +// RUN: -o - 2>&1 | FileCheck \ +// RUN: --check-prefixes=CHECK-NO-MACRO,CHECK-FUNC-SIG-SCHEME-UNUSED %s // RUN: not %clang --target=riscv64 -fcf-protection=branch \ -// RUN: -mcf-branch-label-scheme=unlabeled -c %s -o /dev/null 2>&1 \ -// RUN: | FileCheck --check-prefix=CHECK-BRANCH-PROT-INVALID %s +// RUN: -mcf-branch-label-scheme=unlabeled -E -dM %s -o - 2>&1 | FileCheck \ +// RUN: --check-prefixes=CHECK-NO-MACRO,CHECK-BRANCH-PROT-INVALID %s // RUN: not %clang --target=riscv64 -fcf-protection=branch \ -// RUN: -mcf-branch-label-scheme=func-sig -c %s -o /dev/null 2>&1 \ -// RUN: | FileCheck --check-prefix=CHECK-BRANCH-PROT-INVALID %s +// RUN: -mcf-branch-label-scheme=func-sig -E -dM %s -o - 2>&1 | FileCheck \ +// RUN: --check-prefixes=CHECK-NO-MACRO,CHECK-BRANCH-PROT-INVALID %s -// RUN: %clang --target=riscv64 -mcf-branch-label-scheme=unlabeled -c %s \ -// RUN: -o /dev/null 2>&1 \ -// RUN: | FileCheck --check-prefix=CHECK-UNLABELED-SCHEME-UNUSED %s +// RUN: %clang --target=riscv64 -mcf-branch-label-scheme=unlabeled -E -dM %s \ +// RUN: -o - 2>&1 | FileCheck \ +// RUN: --check-prefixes=CHECK-NO-MACRO,CHECK-UNLABELED-SCHEME-UNUSED %s -// RUN: %clang --target=riscv64 -mcf-branch-label-scheme=func-sig -c %s \ -// RUN: -o /dev/null 2>&1 \ -// RUN: | FileCheck --check-prefix=CHECK-FUNC-SIG-SCHEME-UNUSED %s +// RUN: %clang --target=riscv64 -mcf-branch-label-scheme=func-sig -E -dM %s \ +// RUN: -o - 2>&1 | FileCheck \ +// RUN: --check-prefixes=CHECK-NO-MACRO,CHECK-FUNC-SIG-SCHEME-UNUSED %s +// CHECK-ZICFILP-UNLABELED: __riscv_landing_pad 1{{$}} +// CHECK-ZICFILP-UNLABELED: __riscv_landing_pad_unlabeled 1{{$}} +// CHECK-ZICFILP-FUNC-SIG: __riscv_landing_pad 1{{$}} +// CHECK-ZICFILP-FUNC-SIG: __riscv_landing_pad_func_sig 1{{$}} +// CHECK-NO-MACRO-NOT: __riscv_landing_pad +// CHECK-NO-MACRO-NOT: __riscv_landing_pad_unlabeled +// CHECK-NO-MACRO-NOT: __riscv_landing_pad_func_sig // CHECK-BRANCH-PROT-INVALID: error: option 'cf-protection=branch' cannot be // CHECK-BRANCH-PROT-INVALID-SAME: specified on this target // CHECK-UNLABELED-SCHEME-UNUSED: warning: argument unused during compilation: _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits