Skip to content

Commit d5005f8

Browse files
authored
Merge pull request #68742 from tshortli/multi-opt-forbidden-prefix
Sema: Support multiple -debug-forbid-typecheck-prefix arguments
2 parents 67b68d1 + 50fdfbf commit d5005f8

File tree

6 files changed

+26
-14
lines changed

6 files changed

+26
-14
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,10 +780,10 @@ namespace swift {
780780
/// Should be stored sorted.
781781
llvm::SmallVector<unsigned, 4> DebugConstraintSolverOnLines;
782782

783-
/// Triggers llvm fatal_error if typechecker tries to typecheck a decl or an
784-
/// identifier reference with the provided prefix name.
785-
/// This is for testing purposes.
786-
std::string DebugForbidTypecheckPrefix;
783+
/// Triggers llvm fatal error if the typechecker tries to typecheck a decl
784+
/// or an identifier reference with any of the provided prefix names. This
785+
/// is for testing purposes.
786+
std::vector<std::string> DebugForbidTypecheckPrefixes;
787787

788788
/// The upper bound, in bytes, of temporary data that can be
789789
/// allocated by the constraint solver.

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,8 +1452,8 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
14521452
}
14531453
llvm::sort(Opts.DebugConstraintSolverOnLines);
14541454

1455-
if (const Arg *A = Args.getLastArg(OPT_debug_forbid_typecheck_prefix)) {
1456-
Opts.DebugForbidTypecheckPrefix = A->getValue();
1455+
for (auto A : Args.getAllArgValues(OPT_debug_forbid_typecheck_prefix)) {
1456+
Opts.DebugForbidTypecheckPrefixes.push_back(A);
14571457
}
14581458

14591459
if (Args.getLastArg(OPT_solver_disable_shrink))

lib/Sema/TypeChecker.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,16 +541,18 @@ Expr *swift::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *Contex
541541
}
542542

543543
void TypeChecker::checkForForbiddenPrefix(ASTContext &C, DeclBaseName Name) {
544-
if (C.TypeCheckerOpts.DebugForbidTypecheckPrefix.empty())
544+
if (C.TypeCheckerOpts.DebugForbidTypecheckPrefixes.empty())
545545
return;
546546

547547
// Don't touch special names or empty names.
548548
if (Name.isSpecial() || Name.empty())
549549
return;
550550

551551
StringRef Str = Name.getIdentifier().str();
552-
if (Str.startswith(C.TypeCheckerOpts.DebugForbidTypecheckPrefix)) {
553-
llvm::report_fatal_error(Twine("forbidden typecheck occurred: ") + Str);
552+
for (auto forbiddenPrefix : C.TypeCheckerOpts.DebugForbidTypecheckPrefixes) {
553+
if (Str.startswith(forbiddenPrefix)) {
554+
llvm::report_fatal_error(Twine("forbidden typecheck occurred: ") + Str);
555+
}
554556
}
555557
}
556558

lib/Sema/TypeChecker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,8 +1163,8 @@ bool diagnoseIfDeprecated(SourceLoc loc,
11631163
const ExportContext &where);
11641164
/// @}
11651165

1166-
/// If LangOptions::DebugForbidTypecheckPrefix is set and the given decl
1167-
/// name starts with that prefix, an llvm fatal_error is triggered.
1166+
/// If `LangOptions::DebugForbidTypecheckPrefixes` is set and the given decl
1167+
/// name starts with any of those prefixes, an llvm fatal error is triggered.
11681168
/// This is for testing purposes.
11691169
void checkForForbiddenPrefix(ASTContext &C, DeclBaseName Name);
11701170

test/Misc/opt-debug-forbid-typecheck-prefix.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,11 @@ class C {
6363
var member = FORBID_ref
6464
}
6565
#endif
66+
67+
// Verify that multiple -debug-forbid-typecheck-prefix arguments may be specified.
68+
// RUN: not --crash %target-swift-frontend -typecheck %s -D TRY9 -debug-forbid-typecheck-prefix FORBID_ -debug-forbid-typecheck-prefix FORBID2_ 2> %t.txt
69+
// RUN: %FileCheck -check-prefix=CHECK9 -input-file %t.txt %s
70+
#if TRY9
71+
// CHECK9: note: forbidden typecheck occurred: FORBID2_global
72+
var FORBID2_global = 0
73+
#endif

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ PrintStats("print-stats",
438438
llvm::cl::cat(Category),
439439
llvm::cl::init(false));
440440

441-
static llvm::cl::opt<std::string>
441+
static llvm::cl::list<std::string>
442442
DebugForbidTypecheckPrefix("debug-forbid-typecheck-prefix",
443443
llvm::cl::desc("Triggers llvm fatal_error if typechecker tries to typecheck "
444444
"a decl with the provided prefix name"),
@@ -4485,8 +4485,10 @@ int main(int argc, char *argv[]) {
44854485
}
44864486
InitInvok.getLangOptions().EnableObjCAttrRequiresFoundation =
44874487
!options::DisableObjCAttrRequiresFoundationModule;
4488-
InitInvok.getTypeCheckerOptions().DebugForbidTypecheckPrefix =
4489-
options::DebugForbidTypecheckPrefix;
4488+
for (auto prefix : options::DebugForbidTypecheckPrefix) {
4489+
InitInvok.getTypeCheckerOptions().DebugForbidTypecheckPrefixes.push_back(
4490+
prefix);
4491+
}
44904492
InitInvok.getTypeCheckerOptions().DebugConstraintSolver =
44914493
options::DebugConstraintSolver;
44924494

0 commit comments

Comments
 (0)