Skip to content

Commit ca5fa9a

Browse files
committed
[nfc] Clang format changes.
1 parent 9d1d031 commit ca5fa9a

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
@@ -5942,16 +5942,13 @@ CxxRecordSemantics::evaluate(Evaluator &evaluator,
59425942
if (!hasRequiredValueTypeOperations(decl)) {
59435943
if (hasUnsafeAPIAttr(decl))
59445944
desc.ctx.Diags.diagnose({}, diag::api_pattern_attr_ignored,
5945-
"import_unsafe",
5946-
decl->getNameAsString());
5945+
"import_unsafe", decl->getNameAsString());
59475946
if (hasOwnedValueAttr(decl))
59485947
desc.ctx.Diags.diagnose({}, diag::api_pattern_attr_ignored,
5949-
"import_owned",
5950-
decl->getNameAsString());
5948+
"import_owned", decl->getNameAsString());
59515949
if (hasIteratorAPIAttr(decl))
59525950
desc.ctx.Diags.diagnose({}, diag::api_pattern_attr_ignored,
5953-
"import_iterator",
5954-
decl->getNameAsString());
5951+
"import_iterator", decl->getNameAsString());
59555952

59565953
return CxxRecordSemanticsKind::MissingLifetimeOperation;
59575954
}
@@ -5990,8 +5987,7 @@ bool IsSafeUseOfCxxDecl::evaluate(Evaluator &evaluator,
59905987
if (hasUnsafeAPIAttr(method))
59915988
return true;
59925989

5993-
if (method->isOverloadedOperator() ||
5994-
method->isStatic() ||
5990+
if (method->isOverloadedOperator() || method->isStatic() ||
59955991
isa<clang::CXXConstructorDecl>(decl))
59965992
return true;
59975993

@@ -6004,8 +6000,7 @@ bool IsSafeUseOfCxxDecl::evaluate(Evaluator &evaluator,
60046000
if (auto cxxRecordReturnType =
60056001
dyn_cast<clang::CXXRecordDecl>(returnType->getDecl())) {
60066002
auto semanticsKind = evaluateOrDefault(
6007-
evaluator,
6008-
CxxRecordSemantics({cxxRecordReturnType, desc.ctx}), {});
6003+
evaluator, CxxRecordSemantics({cxxRecordReturnType, desc.ctx}), {});
60096004

60106005
if (semanticsKind == CxxRecordSemanticsKind::UnsafePointerMember ||
60116006
// Pretend all methods that return iterators are unsafe so protocol
@@ -6023,9 +6018,8 @@ bool IsSafeUseOfCxxDecl::evaluate(Evaluator &evaluator,
60236018
llvm_unreachable("decl must be a C++ method or C++ record.");
60246019
}
60256020

6026-
auto semanticsKind =
6027-
evaluateOrDefault(evaluator,
6028-
CxxRecordSemantics({recordDecl, desc.ctx}), {});
6021+
auto semanticsKind = evaluateOrDefault(
6022+
evaluator, CxxRecordSemantics({recordDecl, desc.ctx}), {});
60296023

60306024
// Always unsafe.
60316025
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

@@ -2431,8 +2431,10 @@ namespace {
24312431
return VisitRecordDecl(decl);
24322432

24332433
if (!decl->getDefinition()) {
2434-
Impl.addImportDiagnostic(decl, Diagnostic(diag::incomplete_record,
2435-
Impl.SwiftContext.AllocateCopy(decl->getNameAsString())));
2434+
Impl.addImportDiagnostic(
2435+
decl,
2436+
Diagnostic(diag::incomplete_record, Impl.SwiftContext.AllocateCopy(
2437+
decl->getNameAsString())));
24362438
}
24372439

24382440
decl = decl->getDefinition();
@@ -2485,22 +2487,24 @@ namespace {
24852487

24862488
// It is import that we bail on an unimportable record *before* we import
24872489
// any of its members or cache the decl.
2488-
auto semanticsKind = evaluateOrDefault(
2489-
Impl.SwiftContext.evaluator,
2490-
CxxRecordSemantics({decl, Impl.SwiftContext}), {});
2490+
auto semanticsKind =
2491+
evaluateOrDefault(Impl.SwiftContext.evaluator,
2492+
CxxRecordSemantics({decl, Impl.SwiftContext}), {});
24912493
if (semanticsKind == CxxRecordSemanticsKind::MissingLifetimeOperation) {
24922494
Impl.addImportDiagnostic(
24932495
decl,
24942496
Diagnostic(diag::record_not_automatically_importable,
24952497
Impl.SwiftContext.AllocateCopy(decl->getNameAsString()),
24962498
"does not have a copy constructor or destructor"));
24972499
return nullptr;
2498-
} else if (semanticsKind == CxxRecordSemanticsKind::UnsafeLifetimeOperation) {
2500+
} else if (semanticsKind ==
2501+
CxxRecordSemanticsKind::UnsafeLifetimeOperation) {
24992502
Impl.addImportDiagnostic(
25002503
decl,
25012504
Diagnostic(diag::record_not_automatically_importable,
25022505
Impl.SwiftContext.AllocateCopy(decl->getNameAsString()),
2503-
"has custom, potentially unsafe copy constructor or destructor"));
2506+
"has custom, potentially unsafe copy constructor or "
2507+
"destructor"));
25042508
return nullptr;
25052509
}
25062510

@@ -2767,7 +2771,8 @@ namespace {
27672771
Impl.addImportDiagnostic(
27682772
decl,
27692773
Diagnostic(diag::reference_passed_by_value,
2770-
Impl.SwiftContext.AllocateCopy(recordType->getDecl()->getNameAsString()),
2774+
Impl.SwiftContext.AllocateCopy(
2775+
recordType->getDecl()->getNameAsString()),
27712776
"a parameter"));
27722777
return true;
27732778
}
@@ -2781,10 +2786,10 @@ namespace {
27812786
if (auto recordType = dyn_cast<clang::RecordType>(
27822787
decl->getReturnType().getCanonicalType())) {
27832788
Impl.addImportDiagnostic(
2784-
decl,
2785-
Diagnostic(diag::reference_passed_by_value,
2786-
Impl.SwiftContext.AllocateCopy(recordType->getDecl()->getNameAsString()),
2787-
"the return"));
2789+
decl, Diagnostic(diag::reference_passed_by_value,
2790+
Impl.SwiftContext.AllocateCopy(
2791+
recordType->getDecl()->getNameAsString()),
2792+
"the return"));
27882793
return recordHasReferenceSemantics(recordType->getDecl());
27892794
}
27902795

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"
@@ -3655,33 +3655,44 @@ bool SubscriptMisuseFailure::diagnoseAsNote() {
36553655
return false;
36563656
}
36573657

3658-
static void diagnoseUnsafeCxxMethod(SourceLoc loc,
3659-
Type baseType,
3658+
static void diagnoseUnsafeCxxMethod(SourceLoc loc, Type baseType,
36603659
DeclName name) {
36613660
auto &ctx = baseType->getASTContext();
36623661

36633662
if (baseType->getAnyNominal() == nullptr ||
36643663
// Don't waist time on non-cxx-methods.
3665-
!isa_and_nonnull<clang::CXXRecordDecl>(baseType->getAnyNominal()->getClangDecl()))
3664+
!isa_and_nonnull<clang::CXXRecordDecl>(
3665+
baseType->getAnyNominal()->getClangDecl()))
36663666
return;
36673667

3668-
auto unsafeId = ctx.getIdentifier("__" + name.getBaseIdentifier().str().str() + "Unsafe");
3669-
for (auto found : baseType->getAnyNominal()->lookupDirect(DeclBaseName(unsafeId))) {
3670-
auto cxxMethod = dyn_cast_or_null<clang::CXXMethodDecl>(found->getClangDecl());
3668+
auto unsafeId =
3669+
ctx.getIdentifier("__" + name.getBaseIdentifier().str().str() + "Unsafe");
3670+
for (auto found :
3671+
baseType->getAnyNominal()->lookupDirect(DeclBaseName(unsafeId))) {
3672+
auto cxxMethod =
3673+
dyn_cast_or_null<clang::CXXMethodDecl>(found->getClangDecl());
36713674
if (!cxxMethod)
36723675
continue;
36733676

36743677
if (name.getBaseIdentifier().str() == "begin" ||
36753678
name.getBaseIdentifier().str() == "end") {
3676-
ctx.Diags.diagnose(loc, diag::dont_use_iterator_api, name.getBaseIdentifier().str());
3679+
ctx.Diags.diagnose(loc, diag::dont_use_iterator_api,
3680+
name.getBaseIdentifier().str());
36773681
} else if (cxxMethod->getReturnType()->isPointerType())
3678-
ctx.Diags.diagnose(loc, diag::projection_not_imported, name.getBaseIdentifier().str(), "pointer");
3682+
ctx.Diags.diagnose(loc, diag::projection_not_imported,
3683+
name.getBaseIdentifier().str(), "pointer");
36793684
else if (cxxMethod->getReturnType()->isReferenceType())
3680-
ctx.Diags.diagnose(loc, diag::projection_not_imported, name.getBaseIdentifier().str(), "reference");
3685+
ctx.Diags.diagnose(loc, diag::projection_not_imported,
3686+
name.getBaseIdentifier().str(), "reference");
36813687
else if (cxxMethod->getReturnType()->isRecordType()) {
3682-
if (auto cxxRecord = dyn_cast<clang::CXXRecordDecl>(cxxMethod->getReturnType()->getAsRecordDecl())) {
3683-
assert(evaluateOrDefault(ctx.evaluator, CxxRecordSemantics({cxxRecord, ctx}), {}) == CxxRecordSemanticsKind::UnsafePointerMember);
3684-
ctx.Diags.diagnose(loc, diag::projection_not_imported, name.getBaseIdentifier().str(), cxxRecord->getNameAsString());
3688+
if (auto cxxRecord = dyn_cast<clang::CXXRecordDecl>(
3689+
cxxMethod->getReturnType()->getAsRecordDecl())) {
3690+
assert(evaluateOrDefault(ctx.evaluator,
3691+
CxxRecordSemantics({cxxRecord, ctx}), {}) ==
3692+
CxxRecordSemanticsKind::UnsafePointerMember);
3693+
ctx.Diags.diagnose(loc, diag::projection_not_imported,
3694+
name.getBaseIdentifier().str(),
3695+
cxxRecord->getNameAsString());
36853696
}
36863697
}
36873698
}

0 commit comments

Comments
 (0)