diff --git a/clang/lib/Driver/XRayArgs.cpp b/clang/lib/Driver/XRayArgs.cpp index e25259ca6d64..873693354d18 100644 --- a/clang/lib/Driver/XRayArgs.cpp +++ b/clang/lib/Driver/XRayArgs.cpp @@ -146,21 +146,16 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) { llvm::copy(XRaySupportedModes, std::back_inserter(Modes)); else for (const auto &Arg : SpecifiedModes) { - if (Arg == "none") { - Modes.clear(); - break; - } - if (Arg == "all") { - Modes.clear(); - llvm::copy(XRaySupportedModes, std::back_inserter(Modes)); - break; - } - // Parse CSV values for -fxray-modes=... llvm::SmallVector ModeParts; llvm::SplitString(Arg, ModeParts, ","); for (const auto &M : ModeParts) - Modes.push_back(M); + if (M == "none") + Modes.clear(); + else if (M == "all") + llvm::copy(XRaySupportedModes, std::back_inserter(Modes)); + else + Modes.push_back(M); } // Then we want to sort and unique the modes we've collected. @@ -205,4 +200,10 @@ void XRayArgs::addArgs(const ToolChain &TC, const ArgList &Args, ExtraDepOpt += Dep; CmdArgs.push_back(Args.MakeArgString(ExtraDepOpt)); } + + for (const auto &Mode : Modes) { + SmallString<64> ModeOpt("-fxray-modes="); + ModeOpt += Mode; + CmdArgs.push_back(Args.MakeArgString(ModeOpt)); + } } diff --git a/clang/test/Driver/XRay/xray-mode-flags.cpp b/clang/test/Driver/XRay/xray-mode-flags.cpp index 9c87b8e55e3d..0a040881d332 100644 --- a/clang/test/Driver/XRay/xray-mode-flags.cpp +++ b/clang/test/Driver/XRay/xray-mode-flags.cpp @@ -14,6 +14,18 @@ // RUN: 2>&1 | FileCheck --check-prefixes FDR,BASIC %s // RUN: %clang -v -o /dev/null -fxray-instrument -fxray-modes=none -### %s \ // RUN: 2>&1 | FileCheck --check-prefixes NONE %s +// +// We also should support overriding the modes in an additive manner. +// +// RUN: %clang -v -o /dev/null -fxray-instrument -fxray-modes=none,xray-fdr \ +// RUN: -### %s \ +// RUN: 2>&1 | FileCheck --check-prefixes FDR %s +// RUN: %clang -v -o /dev/null -fxray-instrument -fxray-modes=xray-fdr,none \ +// RUN: -### %s \ +// RUN: 2>&1 | FileCheck --check-prefixes NONE %s +// RUN: %clang -v -o /dev/null -fxray-instrument -fxray-modes=none,all \ +// RUN: -### %s \ +// RUN: 2>&1 | FileCheck --check-prefixes FDR,BASIC %s // BASIC: libclang_rt.xray-basic // FDR: libclang_rt.xray-fdr