Skip to content

Commit f7bbbbe

Browse files
committed
[ast] Add an asserts only option that causes the AST printer to print out an increasing ID for all suppressed statements.
I am using this to better test out suppression statements. I am finding that FileCheck runs into issues with some of the '#if' lines I am trying to match. I am able to use this option with my asserts only test to uniquely identify a '#if ...' statement and thus have the pattern matching work. I needed this to get the test in the next commit to pass testing.
1 parent 11f86a5 commit f7bbbbe

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include "clang/Lex/MacroInfo.h"
6363
#include "llvm/ADT/STLExtras.h"
6464
#include "llvm/ADT/StringSwitch.h"
65+
#include "llvm/Support/CommandLine.h"
6566
#include "llvm/Support/Compiler.h"
6667
#include "llvm/Support/ConvertUTF.h"
6768
#include "llvm/Support/SaveAndRestore.h"
@@ -71,6 +72,15 @@
7172

7273
using namespace swift;
7374

75+
#ifndef NDEBUG
76+
static llvm::cl::opt<bool> NumberSuppressionChecks(
77+
"swift-ast-printer-number-suppression-checks",
78+
llvm::cl::desc("Used to number suppression checks in swift interface files "
79+
"to make it easier to FileCheck them. Only available with "
80+
"asserts enabled and intended for compiler tests."),
81+
llvm::cl::init(false), llvm::cl::Hidden);
82+
#endif
83+
7484
// Defined here to avoid repeatedly paying the price of template instantiation.
7585
const std::function<bool(const ExtensionDecl *)>
7686
PrintOptions::defaultPrintExtensionContentAsMembers
@@ -3199,6 +3209,15 @@ static void printCompatibilityCheckIf(ASTPrinter &printer, bool isElseIf,
31993209
}
32003210
printer << "$" << getFeatureName(feature);
32013211
}
3212+
3213+
#ifndef NDEBUG
3214+
if (NumberSuppressionChecks) {
3215+
static unsigned totalSuppressionChecks = 0;
3216+
printer << " // Suppression Count: " << totalSuppressionChecks;
3217+
++totalSuppressionChecks;
3218+
}
3219+
#endif
3220+
32023221
printer.printNewline();
32033222
}
32043223

test/Concurrency/sending_conditional_suppression.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %empty-directory(%t)
22

3-
// RUN: %target-swift-frontend -enable-upcoming-feature SendingArgsAndResults -swift-version 5 -enable-library-evolution -module-name test -emit-module -o %t/test.swiftmodule -emit-module-interface-path - %s | %FileCheck %s
3+
// RUN: %target-swift-frontend -enable-upcoming-feature SendingArgsAndResults -swift-version 5 -enable-library-evolution -module-name test -emit-module -o %t/test.swiftmodule -emit-module-interface-path - -disable-availability-checking -swift-ast-printer-number-suppression-checks %s | %FileCheck %s
4+
5+
// REQUIRES: asserts
46

57
public class NonSendableKlass {}
68

0 commit comments

Comments
 (0)