Skip to content

Commit 955687f

Browse files
committed
[nfc] Clang format changes.
1 parent 1d1f445 commit 955687f

File tree

5 files changed

+65
-57
lines changed

5 files changed

+65
-57
lines changed

include/swift/ClangImporter/ClangImporterRequests.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,7 @@ struct SafeUseOfCxxDeclDescriptor final {
248248
const clang::Decl *decl;
249249
ASTContext &ctx;
250250

251-
SafeUseOfCxxDeclDescriptor(const clang::Decl *decl,
252-
ASTContext &ctx)
251+
SafeUseOfCxxDeclDescriptor(const clang::Decl *decl, ASTContext &ctx)
253252
: decl(decl), ctx(ctx) {}
254253

255254
friend llvm::hash_code hash_value(const SafeUseOfCxxDeclDescriptor &desc) {

lib/ClangImporter/ClangImporter.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6003,16 +6003,13 @@ CxxRecordSemantics::evaluate(Evaluator &evaluator,
60036003
if (!hasRequiredValueTypeOperations(decl)) {
60046004
if (hasUnsafeAPIAttr(decl))
60056005
desc.ctx.Diags.diagnose({}, diag::api_pattern_attr_ignored,
6006-
"import_unsafe",
6007-
decl->getNameAsString());
6006+
"import_unsafe", decl->getNameAsString());
60086007
if (hasOwnedValueAttr(decl))
60096008
desc.ctx.Diags.diagnose({}, diag::api_pattern_attr_ignored,
6010-
"import_owned",
6011-
decl->getNameAsString());
6009+
"import_owned", decl->getNameAsString());
60126010
if (hasIteratorAPIAttr(decl))
60136011
desc.ctx.Diags.diagnose({}, diag::api_pattern_attr_ignored,
6014-
"import_iterator",
6015-
decl->getNameAsString());
6012+
"import_iterator", decl->getNameAsString());
60166013

60176014
return CxxRecordSemanticsKind::MissingLifetimeOperation;
60186015
}
@@ -6051,8 +6048,7 @@ bool IsSafeUseOfCxxDecl::evaluate(Evaluator &evaluator,
60516048
if (hasUnsafeAPIAttr(method))
60526049
return true;
60536050

6054-
if (method->isOverloadedOperator() ||
6055-
method->isStatic() ||
6051+
if (method->isOverloadedOperator() || method->isStatic() ||
60566052
isa<clang::CXXConstructorDecl>(decl))
60576053
return true;
60586054

@@ -6065,8 +6061,7 @@ bool IsSafeUseOfCxxDecl::evaluate(Evaluator &evaluator,
60656061
if (auto cxxRecordReturnType =
60666062
dyn_cast<clang::CXXRecordDecl>(returnType->getDecl())) {
60676063
auto semanticsKind = evaluateOrDefault(
6068-
evaluator,
6069-
CxxRecordSemantics({cxxRecordReturnType, desc.ctx}), {});
6064+
evaluator, CxxRecordSemantics({cxxRecordReturnType, desc.ctx}), {});
60706065

60716066
if (semanticsKind == CxxRecordSemanticsKind::UnsafePointerMember ||
60726067
// Pretend all methods that return iterators are unsafe so protocol
@@ -6084,9 +6079,8 @@ bool IsSafeUseOfCxxDecl::evaluate(Evaluator &evaluator,
60846079
llvm_unreachable("decl must be a C++ method or C++ record.");
60856080
}
60866081

6087-
auto semanticsKind =
6088-
evaluateOrDefault(evaluator,
6089-
CxxRecordSemantics({recordDecl, desc.ctx}), {});
6082+
auto semanticsKind = evaluateOrDefault(
6083+
evaluator, CxxRecordSemantics({recordDecl, desc.ctx}), {});
60906084

60916085
// Always unsafe.
60926086
if (semanticsKind == CxxRecordSemanticsKind::MissingLifetimeOperation ||

lib/ClangImporter/ImportDecl.cpp

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,8 +1986,8 @@ namespace {
19861986
if (!decl->getDefinition()) {
19871987
Impl.addImportDiagnostic(
19881988
decl,
1989-
Diagnostic(diag::incomplete_record,
1990-
Impl.SwiftContext.AllocateCopy(decl->getNameAsString())));
1989+
Diagnostic(diag::incomplete_record, Impl.SwiftContext.AllocateCopy(
1990+
decl->getNameAsString())));
19911991
}
19921992

19931993
// FIXME: Figure out how to deal with incomplete types, since that
@@ -2001,18 +2001,18 @@ namespace {
20012001
// TODO(SR-13809): fix this once we support dependent types.
20022002
if (decl->getTypeForDecl()->isDependentType()) {
20032003
Impl.addImportDiagnostic(
2004-
decl,
2005-
Diagnostic(diag::record_is_dependent,
2006-
Impl.SwiftContext.AllocateCopy(decl->getNameAsString())));
2004+
decl, Diagnostic(
2005+
diag::record_is_dependent,
2006+
Impl.SwiftContext.AllocateCopy(decl->getNameAsString())));
20072007
return nullptr;
20082008
}
20092009

20102010
// Don't import nominal types that are over-aligned.
20112011
if (Impl.isOverAligned(decl)) {
20122012
Impl.addImportDiagnostic(
2013-
decl,
2014-
Diagnostic(diag::record_over_aligned,
2015-
Impl.SwiftContext.AllocateCopy(decl->getNameAsString())));
2013+
decl, Diagnostic(
2014+
diag::record_over_aligned,
2015+
Impl.SwiftContext.AllocateCopy(decl->getNameAsString())));
20162016
return nullptr;
20172017
}
20182018

@@ -2031,9 +2031,9 @@ namespace {
20312031
// referencing the name, which would sidestep our availability
20322032
// diagnostics.
20332033
Impl.addImportDiagnostic(
2034-
decl,
2035-
Diagnostic(diag::record_non_trivial_copy_destroy,
2036-
Impl.SwiftContext.AllocateCopy(decl->getNameAsString())));
2034+
decl, Diagnostic(
2035+
diag::record_non_trivial_copy_destroy,
2036+
Impl.SwiftContext.AllocateCopy(decl->getNameAsString())));
20372037
return nullptr;
20382038
}
20392039

@@ -2054,9 +2054,9 @@ namespace {
20542054
Impl.importDeclContextOf(decl, importedName.getEffectiveContext());
20552055
if (!dc) {
20562056
Impl.addImportDiagnostic(
2057-
decl,
2058-
Diagnostic(diag::record_parent_unimportable,
2059-
Impl.SwiftContext.AllocateCopy(decl->getNameAsString())));
2057+
decl, Diagnostic(
2058+
diag::record_parent_unimportable,
2059+
Impl.SwiftContext.AllocateCopy(decl->getNameAsString())));
20602060
return nullptr;
20612061
}
20622062

@@ -2428,8 +2428,10 @@ namespace {
24282428
return VisitRecordDecl(decl);
24292429

24302430
if (!decl->getDefinition()) {
2431-
Impl.addImportDiagnostic(decl, Diagnostic(diag::incomplete_record,
2432-
Impl.SwiftContext.AllocateCopy(decl->getNameAsString())));
2431+
Impl.addImportDiagnostic(
2432+
decl,
2433+
Diagnostic(diag::incomplete_record, Impl.SwiftContext.AllocateCopy(
2434+
decl->getNameAsString())));
24332435
}
24342436

24352437
decl = decl->getDefinition();
@@ -2482,22 +2484,24 @@ namespace {
24822484

24832485
// It is import that we bail on an unimportable record *before* we import
24842486
// any of its members or cache the decl.
2485-
auto semanticsKind = evaluateOrDefault(
2486-
Impl.SwiftContext.evaluator,
2487-
CxxRecordSemantics({decl, Impl.SwiftContext}), {});
2487+
auto semanticsKind =
2488+
evaluateOrDefault(Impl.SwiftContext.evaluator,
2489+
CxxRecordSemantics({decl, Impl.SwiftContext}), {});
24882490
if (semanticsKind == CxxRecordSemanticsKind::MissingLifetimeOperation) {
24892491
Impl.addImportDiagnostic(
24902492
decl,
24912493
Diagnostic(diag::record_not_automatically_importable,
24922494
Impl.SwiftContext.AllocateCopy(decl->getNameAsString()),
24932495
"does not have a copy constructor or destructor"));
24942496
return nullptr;
2495-
} else if (semanticsKind == CxxRecordSemanticsKind::UnsafeLifetimeOperation) {
2497+
} else if (semanticsKind ==
2498+
CxxRecordSemanticsKind::UnsafeLifetimeOperation) {
24962499
Impl.addImportDiagnostic(
24972500
decl,
24982501
Diagnostic(diag::record_not_automatically_importable,
24992502
Impl.SwiftContext.AllocateCopy(decl->getNameAsString()),
2500-
"has custom, potentially unsafe copy constructor or destructor"));
2503+
"has custom, potentially unsafe copy constructor or "
2504+
"destructor"));
25012505
return nullptr;
25022506
}
25032507

@@ -2764,7 +2768,8 @@ namespace {
27642768
Impl.addImportDiagnostic(
27652769
decl,
27662770
Diagnostic(diag::reference_passed_by_value,
2767-
Impl.SwiftContext.AllocateCopy(recordType->getDecl()->getNameAsString()),
2771+
Impl.SwiftContext.AllocateCopy(
2772+
recordType->getDecl()->getNameAsString()),
27682773
"a parameter"));
27692774
return true;
27702775
}
@@ -2778,10 +2783,10 @@ namespace {
27782783
if (auto recordType = dyn_cast<clang::RecordType>(
27792784
decl->getReturnType().getCanonicalType())) {
27802785
Impl.addImportDiagnostic(
2781-
decl,
2782-
Diagnostic(diag::reference_passed_by_value,
2783-
Impl.SwiftContext.AllocateCopy(recordType->getDecl()->getNameAsString()),
2784-
"the return"));
2786+
decl, Diagnostic(diag::reference_passed_by_value,
2787+
Impl.SwiftContext.AllocateCopy(
2788+
recordType->getDecl()->getNameAsString()),
2789+
"the return"));
27852790
return recordHasReferenceSemantics(recordType->getDecl());
27862791
}
27872792

lib/ClangImporter/ImportName.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,8 +1482,7 @@ static StringRef renameUnsafeMethod(ASTContext &ctx,
14821482
const clang::NamedDecl *decl,
14831483
StringRef name) {
14841484
if (isa<clang::CXXMethodDecl>(decl) &&
1485-
!evaluateOrDefault(ctx.evaluator,
1486-
IsSafeUseOfCxxDecl({decl, ctx}), {})) {
1485+
!evaluateOrDefault(ctx.evaluator, IsSafeUseOfCxxDecl({decl, ctx}), {})) {
14871486
return ctx.getIdentifier(("__" + name + "Unsafe").str()).str();
14881487
}
14891488

lib/Sema/CSDiagnostics.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@
1818
#include "MiscDiagnostics.h"
1919
#include "TypeCheckProtocol.h"
2020
#include "TypoCorrection.h"
21-
#include "swift/Sema/IDETypeChecking.h"
2221
#include "swift/AST/ASTContext.h"
2322
#include "swift/AST/ASTPrinter.h"
2423
#include "swift/AST/Decl.h"
2524
#include "swift/AST/DiagnosticsClangImporter.h"
2625
#include "swift/AST/ExistentialLayout.h"
2726
#include "swift/AST/Expr.h"
2827
#include "swift/AST/GenericSignature.h"
29-
#include "swift/AST/Initializer.h"
3028
#include "swift/AST/ImportCache.h"
29+
#include "swift/AST/Initializer.h"
3130
#include "swift/AST/ParameterList.h"
3231
#include "swift/AST/Pattern.h"
3332
#include "swift/AST/ProtocolConformance.h"
@@ -38,6 +37,7 @@
3837
#include "swift/Basic/SourceLoc.h"
3938
#include "swift/ClangImporter/ClangImporterRequests.h"
4039
#include "swift/Parse/Lexer.h"
40+
#include "swift/Sema/IDETypeChecking.h"
4141
#include "llvm/ADT/ArrayRef.h"
4242
#include "llvm/ADT/PointerUnion.h"
4343
#include "llvm/ADT/SmallString.h"
@@ -3639,33 +3639,44 @@ bool SubscriptMisuseFailure::diagnoseAsNote() {
36393639
return false;
36403640
}
36413641

3642-
static void diagnoseUnsafeCxxMethod(SourceLoc loc,
3643-
Type baseType,
3642+
static void diagnoseUnsafeCxxMethod(SourceLoc loc, Type baseType,
36443643
DeclName name) {
36453644
auto &ctx = baseType->getASTContext();
36463645

36473646
if (baseType->getAnyNominal() == nullptr ||
36483647
// Don't waist time on non-cxx-methods.
3649-
!isa_and_nonnull<clang::CXXRecordDecl>(baseType->getAnyNominal()->getClangDecl()))
3648+
!isa_and_nonnull<clang::CXXRecordDecl>(
3649+
baseType->getAnyNominal()->getClangDecl()))
36503650
return;
36513651

3652-
auto unsafeId = ctx.getIdentifier("__" + name.getBaseIdentifier().str().str() + "Unsafe");
3653-
for (auto found : baseType->getAnyNominal()->lookupDirect(DeclBaseName(unsafeId))) {
3654-
auto cxxMethod = dyn_cast_or_null<clang::CXXMethodDecl>(found->getClangDecl());
3652+
auto unsafeId =
3653+
ctx.getIdentifier("__" + name.getBaseIdentifier().str().str() + "Unsafe");
3654+
for (auto found :
3655+
baseType->getAnyNominal()->lookupDirect(DeclBaseName(unsafeId))) {
3656+
auto cxxMethod =
3657+
dyn_cast_or_null<clang::CXXMethodDecl>(found->getClangDecl());
36553658
if (!cxxMethod)
36563659
continue;
36573660

36583661
if (name.getBaseIdentifier().str() == "begin" ||
36593662
name.getBaseIdentifier().str() == "end") {
3660-
ctx.Diags.diagnose(loc, diag::dont_use_iterator_api, name.getBaseIdentifier().str());
3663+
ctx.Diags.diagnose(loc, diag::dont_use_iterator_api,
3664+
name.getBaseIdentifier().str());
36613665
} else if (cxxMethod->getReturnType()->isPointerType())
3662-
ctx.Diags.diagnose(loc, diag::projection_not_imported, name.getBaseIdentifier().str(), "pointer");
3666+
ctx.Diags.diagnose(loc, diag::projection_not_imported,
3667+
name.getBaseIdentifier().str(), "pointer");
36633668
else if (cxxMethod->getReturnType()->isReferenceType())
3664-
ctx.Diags.diagnose(loc, diag::projection_not_imported, name.getBaseIdentifier().str(), "reference");
3669+
ctx.Diags.diagnose(loc, diag::projection_not_imported,
3670+
name.getBaseIdentifier().str(), "reference");
36653671
else if (cxxMethod->getReturnType()->isRecordType()) {
3666-
if (auto cxxRecord = dyn_cast<clang::CXXRecordDecl>(cxxMethod->getReturnType()->getAsRecordDecl())) {
3667-
assert(evaluateOrDefault(ctx.evaluator, CxxRecordSemantics({cxxRecord, ctx}), {}) == CxxRecordSemanticsKind::UnsafePointerMember);
3668-
ctx.Diags.diagnose(loc, diag::projection_not_imported, name.getBaseIdentifier().str(), cxxRecord->getNameAsString());
3672+
if (auto cxxRecord = dyn_cast<clang::CXXRecordDecl>(
3673+
cxxMethod->getReturnType()->getAsRecordDecl())) {
3674+
assert(evaluateOrDefault(ctx.evaluator,
3675+
CxxRecordSemantics({cxxRecord, ctx}), {}) ==
3676+
CxxRecordSemanticsKind::UnsafePointerMember);
3677+
ctx.Diags.diagnose(loc, diag::projection_not_imported,
3678+
name.getBaseIdentifier().str(),
3679+
cxxRecord->getNameAsString());
36693680
}
36703681
}
36713682
}

0 commit comments

Comments
 (0)