Skip to content

[DO NOT MERGE] Default error diagnostics #41162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions include/swift/AST/DiagnosticsClangImporter.def
Original file line number Diff line number Diff line change
Expand Up @@ -100,30 +100,30 @@ WARNING(import_multiple_mainactor_attr,none,

ERROR(module_map_not_found, none, "module map file '%0' not found", (StringRef))

NOTE(macro_not_imported_unsupported_operator, none, "operator not supported in macro arithmetic", ())
NOTE(macro_not_imported_unsupported_named_operator, none, "operator '%0' not supported in macro arithmetic", (StringRef))
NOTE(macro_not_imported_invalid_string_literal, none, "invalid string literal", ())
NOTE(macro_not_imported_invalid_numeric_literal, none, "invalid numeric literal", ())
NOTE(macro_not_imported_unsupported_literal, none, "only numeric and string macro literals supported", ())
NOTE(macro_not_imported_nested_cast, none, "non-null nested casts not supported", ())

NOTE(macro_not_imported_function_like, none, "macro '%0' not imported: function like macros not supported", (StringRef))
NOTE(macro_not_imported_unsupported_structure, none, "macro '%0' not imported: structure not supported", (StringRef))
NOTE(macro_not_imported, none, "macro '%0' not imported", (StringRef))

NOTE(return_type_not_imported, none, "return type not imported", ())
NOTE(parameter_type_not_imported, none, "parameter %0 not imported", (const clang::NamedDecl*))
NOTE(incomplete_interface, none, "interface %0 is incomplete", (const clang::NamedDecl*))
NOTE(incomplete_protocol, none, "protocol %0 is incomplete", (const clang::NamedDecl*))
NOTE(unsupported_builtin_type, none, "built-in type '%0' not supported", (StringRef))

NOTE(record_field_not_imported, none, "field %0 not imported", (const clang::NamedDecl*))
NOTE(invoked_func_not_imported, none, "function %0 not imported", (const clang::NamedDecl*))
NOTE(record_method_not_imported, none, "method %0 not imported", (const clang::NamedDecl*))
NOTE(objc_property_not_imported, none, "property %0 not imported", (const clang::NamedDecl*))

NOTE(forward_declared_interface_label, none, "interface %0 forward declared here", (const clang::NamedDecl*))
NOTE(forward_declared_protocol_label, none, "protocol %0 forward declared here", (const clang::NamedDecl*))
ERROR(macro_not_imported_unsupported_operator, none, "operator not supported in macro arithmetic", ())
ERROR(macro_not_imported_unsupported_named_operator, none, "operator '%0' not supported in macro arithmetic", (StringRef))
ERROR(macro_not_imported_invalid_string_literal, none, "invalid string literal", ())
ERROR(macro_not_imported_invalid_numeric_literal, none, "invalid numeric literal", ())
ERROR(macro_not_imported_unsupported_literal, none, "only numeric and string macro literals supported", ())
ERROR(macro_not_imported_nested_cast, none, "non-null nested casts not supported", ())

ERROR(macro_not_imported_function_like, none, "macro '%0' not imported: function like macros not supported", (StringRef))
ERROR(macro_not_imported_unsupported_structure, none, "macro '%0' not imported: structure not supported", (StringRef))
ERROR(macro_not_imported, none, "macro '%0' not imported", (StringRef))

ERROR(return_type_not_imported, none, "return type not imported", ())
ERROR(parameter_type_not_imported, none, "parameter %0 not imported", (const clang::NamedDecl*))
ERROR(incomplete_interface, none, "interface %0 is incomplete", (const clang::NamedDecl*))
ERROR(incomplete_protocol, none, "protocol %0 is incomplete", (const clang::NamedDecl*))
ERROR(unsupported_builtin_type, none, "built-in type '%0' not supported", (StringRef))

ERROR(record_field_not_imported, none, "field %0 not imported", (const clang::NamedDecl*))
ERROR(invoked_func_not_imported, none, "function %0 not imported", (const clang::NamedDecl*))
ERROR(record_method_not_imported, none, "method %0 not imported", (const clang::NamedDecl*))
ERROR(objc_property_not_imported, none, "property %0 not imported", (const clang::NamedDecl*))

ERROR(forward_declared_interface_label, none, "interface %0 forward declared here", (const clang::NamedDecl*))
ERROR(forward_declared_protocol_label, none, "protocol %0 forward declared here", (const clang::NamedDecl*))

#define UNDEFINE_DIAGNOSTIC_MACROS
#include "DefineDiagnosticMacros.h"
4 changes: 2 additions & 2 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ namespace swift {
/// Enable experimental flow-sensitive concurrent captures.
bool EnableExperimentalFlowSensitiveConcurrentCaptures = false;

/// Enable experimental ClangImporter diagnostics.
bool EnableExperimentalClangImporterDiagnostics = false;
/// Disable experimental ClangImporter diagnostics.
bool DisableExperimentalClangImporterDiagnostics = false;

/// Enable experimental eager Clang module diagnostics.
bool EnableExperimentalEagerClangModuleDiagnostics = false;
Expand Down
6 changes: 3 additions & 3 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ def enable_experimental_flow_sensitive_concurrent_captures :
Flag<["-"], "enable-experimental-flow-sensitive-concurrent-captures">,
HelpText<"Enable flow-sensitive concurrent captures">;

def enable_experimental_clang_importer_diagnostics :
Flag<["-"], "enable-experimental-clang-importer-diagnostics">,
HelpText<"Enable experimental diagnostics when importing C, C++, and Objective-C libraries">;
def disable_experimental_clang_importer_diagnostics :
Flag<["-"], "disable-experimental-clang-importer-diagnostics">,
HelpText<"Disable experimental diagnostics when importing C, C++, and Objective-C libraries">;

def enable_experimental_eager_clang_module_diagnostics :
Flag<["-"], "enable-experimental-eager-clang-module-diagnostics">,
Expand Down
3 changes: 1 addition & 2 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2397,8 +2397,7 @@ void ClangImporter::Implementation::addImportDiagnostic(
ImportDiagnosticTarget target, Diagnostic &&diag,
const clang::SourceLocation &loc) {
ImportDiagnostic importDiag = ImportDiagnostic(target, diag, loc);
if (!(SwiftContext.LangOpts.EnableExperimentalClangImporterDiagnostics ||
SwiftContext.LangOpts.EnableExperimentalEagerClangModuleDiagnostics) ||
if (SwiftContext.LangOpts.DisableExperimentalClangImporterDiagnostics ||
CollectedDiagnostics.count(importDiag))
return;

Expand Down
5 changes: 3 additions & 2 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,11 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.EnableExperimentalFlowSensitiveConcurrentCaptures |=
Args.hasArg(OPT_enable_experimental_flow_sensitive_concurrent_captures);

Opts.EnableExperimentalClangImporterDiagnostics |=
Args.hasArg(OPT_enable_experimental_clang_importer_diagnostics);
Opts.DisableExperimentalClangImporterDiagnostics |=
Args.hasArg(OPT_disable_experimental_clang_importer_diagnostics);

Opts.EnableExperimentalEagerClangModuleDiagnostics |=
!Args.hasArg(OPT_disable_experimental_clang_importer_diagnostics) &&
Args.hasArg(OPT_enable_experimental_eager_clang_module_diagnostics);

Opts.DisableImplicitConcurrencyModuleImport |=
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/CSDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3627,7 +3627,7 @@ bool MissingMemberFailure::diagnoseAsError() {
.highlight(getSourceRange())
.highlight(nameLoc.getSourceRange());
const auto &ctx = getSolution().getDC()->getASTContext();
if (ctx.LangOpts.EnableExperimentalClangImporterDiagnostics) {
if (!ctx.LangOpts.DisableExperimentalClangImporterDiagnostics) {
ctx.getClangModuleLoader()->diagnoseMemberValue(getName().getFullName(),
baseType);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/PreCheckExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
.diagnose(Loc, diag::cannot_find_in_scope, Name,
Name.isOperator())
.highlight(UDRE->getSourceRange());
if (Context.LangOpts.EnableExperimentalClangImporterDiagnostics) {
if (!Context.LangOpts.DisableExperimentalClangImporterDiagnostics) {
Context.getClangModuleLoader()->diagnoseTopLevelValue(
Name.getFullName());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
// RUN: not %target-swift-frontend -enable-experimental-clang-importer-diagnostics -enable-objc-interop -import-objc-header %S/Inputs/experimental_clang_importer_diagnostics_bridging_header.h -typecheck %s 2>&1 | %FileCheck %s
// RUN: not %target-swift-frontend -enable-objc-interop -import-objc-header %S/Inputs/experimental_clang_importer_diagnostics_bridging_header.h -typecheck %s 2>&1 | %FileCheck %s

let s: PartialImport
s.c = 5
// CHECK: experimental_clang_importer_diagnostics_bridging_header.swift:{{[0-9]+}}:3: error: value of type 'PartialImport' has no member 'c'
// CHECK-NEXT: s.c = 5
// CHECK-NEXT: ~ ^
// CHECK-NEXT: experimental_clang_importer_diagnostics_bridging_header.h:{{[0-9]+}}:3: note: field 'c' not imported
// CHECK-NEXT: experimental_clang_importer_diagnostics_bridging_header.h:{{[0-9]+}}:3: error: field 'c' not imported
// CHECK-NEXT: int _Complex c;
// CHECK-NEXT: ^
// CHECK-NEXT: experimental_clang_importer_diagnostics_bridging_header.h:{{[0-9]+}}:3: note: built-in type 'Complex' not supported
// CHECK-NEXT: experimental_clang_importer_diagnostics_bridging_header.h:{{[0-9]+}}:3: error: built-in type 'Complex' not supported
// CHECK-NEXT: int _Complex c;
// CHECK-NEXT: ^

_ = CFunctionReturningAForwardDeclaredInterface()
// CHECK: experimental_clang_importer_diagnostics_bridging_header.swift:{{[0-9]+}}:5: error: cannot find 'CFunctionReturningAForwardDeclaredInterface' in scope
// CHECK-NEXT: _ = CFunctionReturningAForwardDeclaredInterface()
// CHECK-NEXT: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK-NEXT: experimental_clang_importer_diagnostics_bridging_header.h:{{[0-9]+}}:1: note: function 'CFunctionReturningAForwardDeclaredInterface' not imported
// CHECK-NEXT: experimental_clang_importer_diagnostics_bridging_header.h:{{[0-9]+}}:1: error: function 'CFunctionReturningAForwardDeclaredInterface' not imported
// CHECK-NEXT: ForwardDeclaredInterface* CFunctionReturningAForwardDeclaredInterface();
// CHECK-NEXT: ^
// CHECK-NEXT: experimental_clang_importer_diagnostics_bridging_header.h:{{[0-9]+}}:1: note: return type not imported
// CHECK-NEXT: experimental_clang_importer_diagnostics_bridging_header.h:{{[0-9]+}}:1: error: return type not imported
// CHECK-NEXT: ForwardDeclaredInterface* CFunctionReturningAForwardDeclaredInterface();
// CHECK-NEXT: ^
// CHECK-NEXT: experimental_clang_importer_diagnostics_bridging_header.h:{{[0-9]+}}:1: note: interface 'ForwardDeclaredInterface' is incomplete
// CHECK-NEXT: experimental_clang_importer_diagnostics_bridging_header.h:{{[0-9]+}}:1: error: interface 'ForwardDeclaredInterface' is incomplete
// CHECK-NEXT: ForwardDeclaredInterface* CFunctionReturningAForwardDeclaredInterface();
// CHECK-NEXT: ^
// CHECK-NEXT: experimental_clang_importer_diagnostics_bridging_header.h:{{[0-9]+}}:1: note: interface 'ForwardDeclaredInterface' forward declared here
// CHECK-NEXT: experimental_clang_importer_diagnostics_bridging_header.h:{{[0-9]+}}:1: error: interface 'ForwardDeclaredInterface' forward declared here
// CHECK-NEXT: @class ForwardDeclaredInterface;
// CHECK-NEXT: ^

_ = FUNC_LIKE_MACRO()
// CHECK: experimental_clang_importer_diagnostics_bridging_header.swift:{{[0-9]+}}:{{[0-9]+}}: error: cannot find 'FUNC_LIKE_MACRO' in scope
// CHECK-NEXT: _ = FUNC_LIKE_MACRO()
// CHECK-NEXT: ^~~~~~~~~~~~~~~
// CHECK-NEXT: experimental_clang_importer_diagnostics_bridging_header.h:{{[0-9]+}}:9: note: macro 'FUNC_LIKE_MACRO' not imported: function like macros not supported
// CHECK-NEXT: experimental_clang_importer_diagnostics_bridging_header.h:{{[0-9]+}}:9: error: macro 'FUNC_LIKE_MACRO' not imported: function like macros not supported
// CHECK-NEXT: #define FUNC_LIKE_MACRO() 0
// CHECK-NEXT: {{^}} ^

unsupported_return_type()
// CHECK: experimental_clang_importer_diagnostics_bridging_header.swift:{{[0-9]+}}:{{[0-9]+}}: error: cannot find 'unsupported_return_type' in scope
// CHECK-NEXT: unsupported_return_type()
// CHECK-NEXT: ^~~~~~~~~~~~~~~~~~~~~~~
// CHECK-NEXT: experimental_clang_importer_diagnostics_bridging_header.h:{{[0-9]+}}:1: note: function 'unsupported_return_type' not imported
// CHECK-NEXT: experimental_clang_importer_diagnostics_bridging_header.h:{{[0-9]+}}:1: error: function 'unsupported_return_type' not imported
// CHECK-NEXT: _Complex int unsupported_return_type();
// CHECK-NEXT: {{^}}^
// CHECK-NEXT: experimental_clang_importer_diagnostics_bridging_header.h:{{[0-9]+}}:1: note: return type not imported
// CHECK-NEXT: experimental_clang_importer_diagnostics_bridging_header.h:{{[0-9]+}}:1: error: return type not imported
// CHECK-NEXT: _Complex int unsupported_return_type();
// CHECK-NEXT: {{^}}^
// CHECK-NEXT: experimental_clang_importer_diagnostics_bridging_header.h:{{[0-9]+}}:1: note: built-in type 'Complex' not supported
// CHECK-NEXT: experimental_clang_importer_diagnostics_bridging_header.h:{{[0-9]+}}:1: error: built-in type 'Complex' not supported
// CHECK-NEXT: _Complex int unsupported_return_type();
// CHECK-NEXT: {{^}}^
26 changes: 13 additions & 13 deletions test/ClangImporter/experimental_diagnostics_cfuncs.swift
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-experimental-clang-importer-diagnostics -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %s 2>&1 | %FileCheck %s --strict-whitespace

import cfuncs

unsupported_parameter_type(1,2)
// CHECK: experimental_diagnostics_cfuncs.swift:5:1: error: cannot find 'unsupported_parameter_type' in scope
// CHECK-NEXT: unsupported_parameter_type(1,2)
// CHECK-NEXT: ^~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:1: note: function 'unsupported_parameter_type' not imported
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:1: error: function 'unsupported_parameter_type' not imported
// CHECK-NEXT: int unsupported_parameter_type(int param1, _Complex int param2);
// CHECK-NEXT: {{^}}^
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:44: note: parameter 'param2' not imported
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:44: error: parameter 'param2' not imported
// CHECK-NEXT: int unsupported_parameter_type(int param1, _Complex int param2);
// CHECK-NEXT: {{^}} ^
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:44: note: built-in type 'Complex' not supported
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:44: error: built-in type 'Complex' not supported
// CHECK-NEXT: int unsupported_parameter_type(int param1, _Complex int param2);
// CHECK-NEXT: {{^}} ^

unsupported_return_type()
// CHECK: experimental_diagnostics_cfuncs.swift:19:1: error: cannot find 'unsupported_return_type' in scope
// CHECK-NEXT: unsupported_return_type()
// CHECK-NEXT: ^~~~~~~~~~~~~~~~~~~~~~~
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:1: note: function 'unsupported_return_type' not imported
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:1: error: function 'unsupported_return_type' not imported
// CHECK-NEXT: _Complex int unsupported_return_type();
// CHECK-NEXT: {{^}}^
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:1: note: return type not imported
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:1: error: return type not imported
// CHECK-NEXT: _Complex int unsupported_return_type();
// CHECK-NEXT: {{^}}^
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:1: note: built-in type 'Complex' not supported
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:1: error: built-in type 'Complex' not supported
// CHECK-NEXT: _Complex int unsupported_return_type();
// CHECK-NEXT: {{^}}^

unsupported_parameter_type(1,2)
// CHECK: experimental_diagnostics_cfuncs.swift:33:1: error: cannot find 'unsupported_parameter_type' in scope
// CHECK-NEXT: unsupported_parameter_type(1,2)
// CHECK-NEXT: ^~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:1: note: function 'unsupported_parameter_type' not imported
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:1: error: function 'unsupported_parameter_type' not imported
// CHECK-NEXT: int unsupported_parameter_type(int param1, _Complex int param2);
// CHECK-NEXT: {{^}}^
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:44: note: parameter 'param2' not imported
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:44: error: parameter 'param2' not imported
// CHECK-NEXT: int unsupported_parameter_type(int param1, _Complex int param2);
// CHECK-NEXT: {{^}} ^
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:44: note: built-in type 'Complex' not supported
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:44: error: built-in type 'Complex' not supported
// CHECK-NEXT: int unsupported_parameter_type(int param1, _Complex int param2);
// CHECK-NEXT: {{^}} ^

unsupported_return_type()
// CHECK: experimental_diagnostics_cfuncs.swift:47:1: error: cannot find 'unsupported_return_type' in scope
// CHECK-NEXT: unsupported_return_type()
// CHECK-NEXT: ^~~~~~~~~~~~~~~~~~~~~~~
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:1: note: function 'unsupported_return_type' not imported
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:1: error: function 'unsupported_return_type' not imported
// CHECK-NEXT: _Complex int unsupported_return_type();
// CHECK-NEXT: {{^}}^
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:1: note: return type not imported
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:1: error: return type not imported
// CHECK-NEXT: _Complex int unsupported_return_type();
// CHECK-NEXT: {{^}}^
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:1: note: built-in type 'Complex' not supported
// CHECK-NEXT: cfuncs.h:{{[0-9]+}}:1: error: built-in type 'Complex' not supported
// CHECK-NEXT: _Complex int unsupported_return_type();
// CHECK-NEXT: {{^}}^
Loading