mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Sema: Support multiple -debug-forbid-typecheck-prefix arguments.
An existing test (Frontend/skip-function-bodies.swift) was designed under the assumption that multiple `-debug-forbid-typecheck-prefix` arguments were already supported, and as a result the test was not actually asserting what it was written to assert.
This commit is contained in:
@@ -780,10 +780,10 @@ namespace swift {
|
||||
/// Should be stored sorted.
|
||||
llvm::SmallVector<unsigned, 4> DebugConstraintSolverOnLines;
|
||||
|
||||
/// Triggers llvm fatal_error if typechecker tries to typecheck a decl or an
|
||||
/// identifier reference with the provided prefix name.
|
||||
/// This is for testing purposes.
|
||||
std::string DebugForbidTypecheckPrefix;
|
||||
/// Triggers llvm fatal error if the typechecker tries to typecheck a decl
|
||||
/// or an identifier reference with any of the provided prefix names. This
|
||||
/// is for testing purposes.
|
||||
std::vector<std::string> DebugForbidTypecheckPrefixes;
|
||||
|
||||
/// The upper bound, in bytes, of temporary data that can be
|
||||
/// allocated by the constraint solver.
|
||||
|
||||
@@ -1452,8 +1452,8 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
|
||||
}
|
||||
llvm::sort(Opts.DebugConstraintSolverOnLines);
|
||||
|
||||
if (const Arg *A = Args.getLastArg(OPT_debug_forbid_typecheck_prefix)) {
|
||||
Opts.DebugForbidTypecheckPrefix = A->getValue();
|
||||
for (auto A : Args.getAllArgValues(OPT_debug_forbid_typecheck_prefix)) {
|
||||
Opts.DebugForbidTypecheckPrefixes.push_back(A);
|
||||
}
|
||||
|
||||
if (Args.getLastArg(OPT_solver_disable_shrink))
|
||||
|
||||
@@ -541,7 +541,7 @@ Expr *swift::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *Contex
|
||||
}
|
||||
|
||||
void TypeChecker::checkForForbiddenPrefix(ASTContext &C, DeclBaseName Name) {
|
||||
if (C.TypeCheckerOpts.DebugForbidTypecheckPrefix.empty())
|
||||
if (C.TypeCheckerOpts.DebugForbidTypecheckPrefixes.empty())
|
||||
return;
|
||||
|
||||
// Don't touch special names or empty names.
|
||||
@@ -549,8 +549,10 @@ void TypeChecker::checkForForbiddenPrefix(ASTContext &C, DeclBaseName Name) {
|
||||
return;
|
||||
|
||||
StringRef Str = Name.getIdentifier().str();
|
||||
if (Str.startswith(C.TypeCheckerOpts.DebugForbidTypecheckPrefix)) {
|
||||
llvm::report_fatal_error(Twine("forbidden typecheck occurred: ") + Str);
|
||||
for (auto forbiddenPrefix : C.TypeCheckerOpts.DebugForbidTypecheckPrefixes) {
|
||||
if (Str.startswith(forbiddenPrefix)) {
|
||||
llvm::report_fatal_error(Twine("forbidden typecheck occurred: ") + Str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1163,8 +1163,8 @@ bool diagnoseIfDeprecated(SourceLoc loc,
|
||||
const ExportContext &where);
|
||||
/// @}
|
||||
|
||||
/// If LangOptions::DebugForbidTypecheckPrefix is set and the given decl
|
||||
/// name starts with that prefix, an llvm fatal_error is triggered.
|
||||
/// If `LangOptions::DebugForbidTypecheckPrefixes` is set and the given decl
|
||||
/// name starts with any of those prefixes, an llvm fatal error is triggered.
|
||||
/// This is for testing purposes.
|
||||
void checkForForbiddenPrefix(ASTContext &C, DeclBaseName Name);
|
||||
|
||||
|
||||
@@ -63,3 +63,11 @@ class C {
|
||||
var member = FORBID_ref
|
||||
}
|
||||
#endif
|
||||
|
||||
// Verify that multiple -debug-forbid-typecheck-prefix arguments may be specified.
|
||||
// RUN: not --crash %target-swift-frontend -typecheck %s -D TRY9 -debug-forbid-typecheck-prefix FORBID_ -debug-forbid-typecheck-prefix FORBID2_ 2> %t.txt
|
||||
// RUN: %FileCheck -check-prefix=CHECK9 -input-file %t.txt %s
|
||||
#if TRY9
|
||||
// CHECK9: note: forbidden typecheck occurred: FORBID2_global
|
||||
var FORBID2_global = 0
|
||||
#endif
|
||||
|
||||
@@ -438,7 +438,7 @@ PrintStats("print-stats",
|
||||
llvm::cl::cat(Category),
|
||||
llvm::cl::init(false));
|
||||
|
||||
static llvm::cl::opt<std::string>
|
||||
static llvm::cl::list<std::string>
|
||||
DebugForbidTypecheckPrefix("debug-forbid-typecheck-prefix",
|
||||
llvm::cl::desc("Triggers llvm fatal_error if typechecker tries to typecheck "
|
||||
"a decl with the provided prefix name"),
|
||||
@@ -4485,8 +4485,10 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
InitInvok.getLangOptions().EnableObjCAttrRequiresFoundation =
|
||||
!options::DisableObjCAttrRequiresFoundationModule;
|
||||
InitInvok.getTypeCheckerOptions().DebugForbidTypecheckPrefix =
|
||||
options::DebugForbidTypecheckPrefix;
|
||||
for (auto prefix : options::DebugForbidTypecheckPrefix) {
|
||||
InitInvok.getTypeCheckerOptions().DebugForbidTypecheckPrefixes.push_back(
|
||||
prefix);
|
||||
}
|
||||
InitInvok.getTypeCheckerOptions().DebugConstraintSolver =
|
||||
options::DebugConstraintSolver;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user