Skip to content

NFC: Fix warnings #67575

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

Merged
merged 3 commits into from
Jul 27, 2023
Merged
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
3 changes: 2 additions & 1 deletion include/swift/AST/ASTBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
#ifndef SWIFT_AST_ASTBRIDGING_H
#define SWIFT_AST_ASTBRIDGING_H

#include "swift/AST/DiagnosticEngine.h"
#include "swift/Basic/BasicBridging.h"
#include "swift/Basic/Compiler.h"
#include "swift/AST/DiagnosticEngine.h"
#include "swift/Basic/Nullability.h"
#include <stdbool.h>
#include <stddef.h>

Expand Down
24 changes: 4 additions & 20 deletions include/swift/AST/CASTBridging.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===--- ASTBridging.h - header for the swift SILBridging module ----------===//
//===--- CASTBridging.h - header for the swift SILBridging module ---------===//
//
// This source file is part of the Swift.org open source project
//
Expand All @@ -15,29 +15,15 @@

#include "swift/Basic/CBasicBridging.h"
#include "swift/Basic/Compiler.h"
#include "swift/Basic/Nullability.h"

// NOTE: DO NOT #include any stdlib headers here. e.g. <stdint.h>. Those are
// part of "Darwin"/"Glibc" module, so when a Swift file imports this header,
// it causes importing the "Darwin"/"Glibc" overlay module. That violates
// layering. i.e. Darwin overlay is created by Swift compiler.

#if __clang__
// Provide macros to temporarily suppress warning about the use of
// _Nullable and _Nonnull.
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wnullability-extension\"") \
_Pragma("clang assume_nonnull begin")

#define SWIFT_END_NULLABILITY_ANNOTATIONS \
_Pragma("clang diagnostic pop") _Pragma("clang assume_nonnull end")
#else
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
#define SWIFT_END_NULLABILITY_ANNOTATIONS
#define _Nullable
#endif

SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
SWIFT_BEGIN_ASSUME_NONNULL

typedef long SwiftInt;
typedef unsigned long SwiftUInt;
Expand Down Expand Up @@ -486,9 +472,7 @@ _Bool Plugin_waitForNextMessage(PluginHandle handle, BridgedData *data);
}
#endif

SWIFT_END_ASSUME_NONNULL
SWIFT_END_NULLABILITY_ANNOTATIONS

#undef SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
#undef SWIFT_END_NULLABILITY_ANNOTATIONS

#endif // SWIFT_C_AST_ASTBRIDGING_H
1 change: 1 addition & 0 deletions include/swift/Basic/BasicBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "llvm/CAS/CASReference.h"

#include "swift/Basic/BridgedSwiftObject.h"
#include "swift/Basic/Nullability.h"
#include "swift/Basic/SourceLoc.h"
#include <stddef.h>

Expand Down
24 changes: 2 additions & 22 deletions include/swift/Basic/BridgedSwiftObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef SWIFT_BASIC_BRIDGEDSWIFTOBJECT_H
#define SWIFT_BASIC_BRIDGEDSWIFTOBJECT_H

#include "swift/Basic/Nullability.h"

#if defined(__OpenBSD__)
#include <sys/stdint.h>
#else
Expand All @@ -28,28 +30,6 @@
#define __has_feature(feature) 0
#endif

// TODO: These macro definitions are duplicated in Visibility.h. Move
// them to a single file if we find a location that both Visibility.h and
// BridgedSwiftObject.h can import.
#if __has_feature(nullability)
// Provide macros to temporarily suppress warning about the use of
// _Nullable and _Nonnull.
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wnullability-extension\"")
#define SWIFT_END_NULLABILITY_ANNOTATIONS \
_Pragma("clang diagnostic pop")

#else
// #define _Nullable and _Nonnull to nothing if we're not being built
// with a compiler that supports them.
#define _Nullable
#define _Nonnull
#define _Null_unspecified
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
#define SWIFT_END_NULLABILITY_ANNOTATIONS
#endif

SWIFT_BEGIN_NULLABILITY_ANNOTATIONS

typedef const void * _Nonnull SwiftMetatype;
Expand Down
23 changes: 3 additions & 20 deletions include/swift/Basic/CBasicBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,15 @@
#define SWIFT_C_BASIC_BASICBRIDGING_H

#include "swift/Basic/Compiler.h"
#include "swift/Basic/Nullability.h"

// NOTE: DO NOT #include any stdlib headers here. e.g. <stdint.h>. Those are
// part of "Darwin"/"Glibc" module, so when a Swift file imports this header,
// it causes importing the "Darwin"/"Glibc" overlay module. That violates
// layering. i.e. Darwin overlay is created by Swift compiler.

#if __clang__
// Provide macros to temporarily suppress warning about the use of
// _Nullable and _Nonnull.
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wnullability-extension\"") \
_Pragma("clang assume_nonnull begin")

#define SWIFT_END_NULLABILITY_ANNOTATIONS \
_Pragma("clang diagnostic pop") _Pragma("clang assume_nonnull end")
#else
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
#define SWIFT_END_NULLABILITY_ANNOTATIONS
#define _Nullable
#define _Nonnull
#endif

SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
SWIFT_BEGIN_ASSUME_NONNULL

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -119,9 +104,7 @@ void *JSON_array_pushNewValue(void *arrayPtr);
}
#endif

SWIFT_END_ASSUME_NONNULL
SWIFT_END_NULLABILITY_ANNOTATIONS

#undef SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
#undef SWIFT_END_NULLABILITY_ANNOTATIONS

#endif // SWIFT_C_BASIC_BASICBRIDGING_H
41 changes: 41 additions & 0 deletions include/swift/Basic/Nullability.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//===--- Nullability.h ----------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#ifndef SWIFT_BASIC_NULLABILITY_H
#define SWIFT_BASIC_NULLABILITY_H

// TODO: These macro definitions are duplicated in Visibility.h. Move
// them to a single file if we find a location that both Visibility.h and
// BridgedSwiftObject.h can import.
#if __has_feature(nullability)
// Provide macros to temporarily suppress warning about the use of
// _Nullable and _Nonnull.
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wnullability-extension\"")
#define SWIFT_END_NULLABILITY_ANNOTATIONS _Pragma("clang diagnostic pop")

#define SWIFT_BEGIN_ASSUME_NONNULL _Pragma("clang assume_nonnull begin")
#define SWIFT_END_ASSUME_NONNULL _Pragma("clang assume_nonnull end")
#else
// #define _Nullable and _Nonnull to nothing if we're not being built
// with a compiler that supports them.
#define _Nullable
#define _Nonnull
#define _Null_unspecified
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
#define SWIFT_END_NULLABILITY_ANNOTATIONS
#define SWIFT_BEGIN_ASSUME_NONNULL
#define SWIFT_END_ASSUME_NONNULL
#endif

#endif
9 changes: 8 additions & 1 deletion include/swift/Demangling/Errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#define SWIFT_DEMANGLING_ERRORS_H

#include "swift/Demangling/NamespaceMacros.h"
#include "swift/shims/Visibility.h"
#include <inttypes.h>
#include <stdarg.h>

Expand All @@ -44,6 +43,14 @@
#endif
#endif

#ifndef SWIFT_NORETURN
#if __has_attribute(noreturn)
#define SWIFT_NORETURN __attribute__((__noreturn__))
#else
#define SWIFT_NORETURN
#endif
#endif

namespace swift {
namespace Demangle {
SWIFT_BEGIN_INLINE_NAMESPACE
Expand Down
1 change: 1 addition & 0 deletions include/swift/Parse/RegexParserBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define REGEX_PARSER_BRIDGING

#include "swift/AST/ASTBridging.h"
#include "swift/Basic/Nullability.h"
#include <stdbool.h>

/// Attempt to lex a regex literal string. Takes the following arguments:
Expand Down
13 changes: 7 additions & 6 deletions include/swift/SIL/SILBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@
#ifndef SWIFT_SIL_SILBRIDGING_H
#define SWIFT_SIL_SILBRIDGING_H

#include "swift/Basic/BasicBridging.h"
#include "swift/Basic/BridgedSwiftObject.h"
#include "swift/AST/Builtins.h"
#include "swift/AST/Decl.h"
#include "swift/AST/SubstitutionMap.h"
#include "swift/SIL/SILInstruction.h"
#include "swift/Basic/BasicBridging.h"
#include "swift/Basic/BridgedSwiftObject.h"
#include "swift/Basic/Nullability.h"
#include "swift/SIL/ApplySite.h"
#include "swift/SIL/SILBuilder.h"
#include "swift/SIL/SILLocation.h"
#include "swift/SIL/SILDefaultWitnessTable.h"
#include "swift/SIL/SILFunctionConventions.h"
#include "swift/SIL/SILInstruction.h"
#include "swift/SIL/SILLocation.h"
#include "swift/SIL/SILModule.h"
#include "swift/SIL/SILWitnessTable.h"
#include "swift/SIL/SILDefaultWitnessTable.h"
#include "swift/SIL/SILVTable.h"
#include "swift/SIL/SILWitnessTable.h"
#include <stdbool.h>
#include <stddef.h>
#include <string>
Expand Down
3 changes: 2 additions & 1 deletion include/swift/SILOptimizer/OptimizerBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
#ifndef SWIFT_SILOPTIMIZER_OPTIMIZERBRIDGING_H
#define SWIFT_SILOPTIMIZER_OPTIMIZERBRIDGING_H

#include "swift/Basic/Nullability.h"
#include "swift/SIL/SILBridging.h"
#include "swift/SILOptimizer/PassManager/PassManager.h"
#include "swift/SILOptimizer/Analysis/AliasAnalysis.h"
#include "swift/SILOptimizer/Analysis/BasicCalleeAnalysis.h"
#include "swift/SILOptimizer/Analysis/DeadEndBlocksAnalysis.h"
#include "swift/SILOptimizer/Analysis/DominanceAnalysis.h"
#include "swift/SILOptimizer/PassManager/PassManager.h"
#include "swift/SILOptimizer/Utils/InstOptUtils.h"

SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
Expand Down
8 changes: 4 additions & 4 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3663,7 +3663,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
return makeParserSuccess();
}

SourceLoc LParenLoc = consumeToken(tok::l_paren);
consumeToken(tok::l_paren);

if (!Tok.canBeArgumentLabel()) {
diagnose(Loc, diag::attr_rawlayout_expected_label, "'size', 'like', or 'likeArrayOf'");
Expand All @@ -3672,7 +3672,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
}

Identifier firstLabel;
SourceLoc firstLabelLoc = consumeArgumentLabel(firstLabel, true);
consumeArgumentLabel(firstLabel, true);
if (!consumeIf(tok::colon)) {
diagnose(Loc, diag::attr_expected_colon_after_label, firstLabel.str());
return makeParserSuccess();
Expand Down Expand Up @@ -3700,7 +3700,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
}

Identifier alignLabel;
SourceLoc alignLabelLoc = consumeArgumentLabel(alignLabel, true);
consumeArgumentLabel(alignLabel, true);
if (!consumeIf(tok::colon)) {
diagnose(Loc, diag::attr_expected_colon_after_label, "alignment");
return makeParserSuccess();
Expand Down Expand Up @@ -3759,7 +3759,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
}

Identifier countLabel;
SourceLoc countLabelLoc = consumeArgumentLabel(countLabel, true);
consumeArgumentLabel(countLabel, true);
if (!consumeIf(tok::colon)) {
diagnose(Loc, diag::attr_expected_colon_after_label, "count");
return makeParserSuccess();
Expand Down
5 changes: 3 additions & 2 deletions lib/Parse/ParseType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
//
//===----------------------------------------------------------------------===//

#include "swift/Parse/Parser.h"
#include "swift/AST/ASTWalker.h"
#include "swift/AST/Attr.h"
#include "swift/AST/GenericParamList.h"
#include "swift/AST/SourceFile.h" // only for isMacroSignatureFile
#include "swift/AST/TypeRepr.h"
#include "swift/Parse/Lexer.h"
#include "swift/Basic/Nullability.h"
#include "swift/Parse/IDEInspectionCallbacks.h"
#include "swift/Parse/Lexer.h"
#include "swift/Parse/Parser.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Twine.h"
Expand Down
2 changes: 1 addition & 1 deletion lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3210,7 +3210,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
} else if (auto likeArrayTypeAndCount = attr->getResolvedArrayLikeTypeAndCount()) {
typeID = S.addTypeRef(likeArrayTypeAndCount->first);
rawSize = likeArrayTypeAndCount->second;
rawAlign = ~0u;
rawAlign = static_cast<uint8_t>(~0u);
} else {
llvm_unreachable("unhandled raw layout attribute, or trying to serialize unresolved attr!");
}
Expand Down