Skip to content

Commit 051aa17

Browse files
MaskRaytru
authored andcommitted
[Driver] Adjust -fsanitize=function & -mexecute-only interop after D158614
clangDriver depends on clangBasic, so clangBasic should not depend on clangDriver, even just its header. Also remove clangBasic's dependency on LLVMOption. The issue can be seen through the bazel commit d26dd68 which is reverted now. Add hasFlagNoClaim and use it as we don't want to suppress -Wunused-command-line-argument for -mexecute-only just because -fsanitize= is specified.
1 parent c138c8a commit 051aa17

File tree

6 files changed

+18
-19
lines changed

6 files changed

+18
-19
lines changed

clang/include/clang/Basic/Sanitizers.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,6 @@ StringRef AsanDetectStackUseAfterReturnModeToString(
209209
llvm::AsanDetectStackUseAfterReturnMode
210210
AsanDetectStackUseAfterReturnModeFromString(StringRef modeStr);
211211

212-
/// Return true if an execute-only target disallows data access to code
213-
/// sections.
214-
bool isExecuteOnlyTarget(const llvm::Triple &Triple,
215-
const llvm::opt::ArgList &Args);
216-
217212
} // namespace clang
218213

219214
#endif // LLVM_CLANG_BASIC_SANITIZERS_H

clang/lib/Basic/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
set(LLVM_LINK_COMPONENTS
2-
Option
32
Support
43
TargetParser
54
)

clang/lib/Basic/Sanitizers.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "clang/Basic/Sanitizers.h"
14-
#include "clang/Driver/Options.h"
1514
#include "llvm/ADT/Hashing.h"
1615
#include "llvm/ADT/SmallVector.h"
1716
#include "llvm/ADT/StringSwitch.h"
18-
#include "llvm/Option/ArgList.h"
1917
#include "llvm/Support/MathExtras.h"
20-
#include "llvm/TargetParser/Triple.h"
2118

2219
using namespace clang;
2320

@@ -115,14 +112,4 @@ AsanDetectStackUseAfterReturnModeFromString(StringRef modeStr) {
115112
.Default(llvm::AsanDetectStackUseAfterReturnMode::Invalid);
116113
}
117114

118-
bool isExecuteOnlyTarget(const llvm::Triple &Triple,
119-
const llvm::opt::ArgList &Args) {
120-
if (Triple.isPS5())
121-
return true;
122-
123-
// On Arm, the clang `-mexecute-only` option is used to generate the
124-
// execute-only output (no data access to code sections).
125-
return Args.hasFlag(clang::driver::options::OPT_mexecute_only,
126-
clang::driver::options::OPT_mno_execute_only, false);
127-
}
128115
} // namespace clang

clang/lib/Driver/SanitizerArgs.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ static std::string describeSanitizeArg(const llvm::opt::Arg *A,
143143
/// Sanitizers set.
144144
static std::string toString(const clang::SanitizerSet &Sanitizers);
145145

146+
/// Return true if an execute-only target disallows data access to code
147+
/// sections.
148+
static bool isExecuteOnlyTarget(const llvm::Triple &Triple,
149+
const llvm::opt::ArgList &Args) {
150+
if (Triple.isPS5())
151+
return true;
152+
return Args.hasFlagNoClaim(options::OPT_mexecute_only,
153+
options::OPT_mno_execute_only, false);
154+
}
155+
146156
static void validateSpecialCaseListFormat(const Driver &D,
147157
std::vector<std::string> &SCLFiles,
148158
unsigned MalformedSCLErrorDiagID,

llvm/include/llvm/Option/ArgList.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ class ArgList {
299299
/// \p Default if neither option is given. If both the option and its
300300
/// negation are present, the last one wins.
301301
bool hasFlag(OptSpecifier Pos, OptSpecifier Neg, bool Default) const;
302+
bool hasFlagNoClaim(OptSpecifier Pos, OptSpecifier Neg, bool Default) const;
302303

303304
/// hasFlag - Given an option \p Pos, an alias \p PosAlias and its negative
304305
/// form \p Neg, return true if the option or its alias is present, false if

llvm/lib/Option/ArgList.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ bool ArgList::hasFlag(OptSpecifier Pos, OptSpecifier Neg, bool Default) const {
7575
return Default;
7676
}
7777

78+
bool ArgList::hasFlagNoClaim(OptSpecifier Pos, OptSpecifier Neg,
79+
bool Default) const {
80+
if (Arg *A = getLastArgNoClaim(Pos, Neg))
81+
return A->getOption().matches(Pos);
82+
return Default;
83+
}
84+
7885
bool ArgList::hasFlag(OptSpecifier Pos, OptSpecifier PosAlias, OptSpecifier Neg,
7986
bool Default) const {
8087
if (Arg *A = getLastArg(Pos, PosAlias, Neg))

0 commit comments

Comments
 (0)