Skip to content

Commit 74841a5

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. (cherry picked from commit f7bbbbe)
1 parent ff60ee5 commit 74841a5

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
@@ -3205,6 +3215,15 @@ static void printCompatibilityCheckIf(ASTPrinter &printer, bool isElseIf,
32053215
}
32063216
printer << "$" << getFeatureName(feature);
32073217
}
3218+
3219+
#ifndef NDEBUG
3220+
if (NumberSuppressionChecks) {
3221+
static unsigned totalSuppressionChecks = 0;
3222+
printer << " // Suppression Count: " << totalSuppressionChecks;
3223+
++totalSuppressionChecks;
3224+
}
3225+
#endif
3226+
32083227
printer.printNewline();
32093228
}
32103229

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)