[DiagnosticVerifier] ensure expansion ancestors are populated

Simply GSI->ancestors is not enough if the ancestors list has not been
populated yet. Ensure this is done by calling getAncestors.
This commit is contained in:
Henrik G. Olsson
2025-11-14 20:02:20 -08:00
parent 62ba94ef12
commit 69f6f477cd
4 changed files with 12 additions and 3 deletions

View File

@@ -20,6 +20,7 @@
#include "swift/Basic/ColorUtils.h"
#include "swift/Basic/SourceManager.h"
#include "swift/Parse/Lexer.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FormatVariadic.h"
@@ -1426,9 +1427,9 @@ DiagnosticVerifier::Result DiagnosticVerifier::verifyFile(unsigned BufferID) {
// Diagnostics attached to generated sources originating in this
// buffer also count as part of this buffer for this purpose.
const GeneratedSourceInfo *GSI =
SM.getGeneratedSourceInfo(CapturedDiagIter->SourceBufferID.value());
if (!GSI || llvm::find(GSI->ancestors, BufferID) == GSI->ancestors.end()) {
unsigned scratch;
llvm::ArrayRef<unsigned> ancestors = SM.getAncestors(CapturedDiagIter->SourceBufferID.value(), scratch);
if (llvm::find(ancestors, BufferID) == ancestors.end()) {
++CapturedDiagIter;
continue;
}

View File

@@ -233,6 +233,9 @@ MAIN_ACTOR MAIN_ACTOR __attribute__((__swift_attr__("@MainActor"))) @protocol Tr
SENDABLE @interface SendableClass : NSObject @end
// expected-expansion@+3:13{{
// expected-note@1 5{{conformance of 'NonSendableClass' to 'Sendable' has been explicitly marked unavailable here}}
// }}
NONSENDABLE @interface NonSendableClass : NSObject @end // expected-note {{class 'NonSendableClass' does not conform to the 'Sendable' protocol}}
ASSUME_NONSENDABLE_BEGIN

View File

@@ -102,6 +102,7 @@ struct MyBrokenStruct {
/*
expected-expansion@-2:25{{
expected-error@1:1{{variable already has a getter}}
expected-error@5:1{{variable already has a setter}}
}}
*/
// CHECK-DIAGS: variable already has a getter

View File

@@ -11,6 +11,10 @@ macro HangingMacro() = #externalMacro(module: "MacroDefinition", type: "HangingM
class Foo {
init() {}
// expected-expansion@+5:32{{
// expected-error@1{{unexpected token '}' in expanded member list}}
// expected-error@2{{expected declaration}}
// }}
// expected-note@+1 2{{in expansion of macro 'HangingMacro' on property 'result' here}}
@HangingMacro var result: Int // This comment makes it hang.
}