Skip to content

Commit 1381d9a

Browse files
authored
Merge pull request #67575 from tshortli/fix-warnings
NFC: Fix warnings
2 parents 7c93887 + f9a93a5 commit 1381d9a

File tree

13 files changed

+79
-78
lines changed

13 files changed

+79
-78
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
#ifndef SWIFT_AST_ASTBRIDGING_H
1414
#define SWIFT_AST_ASTBRIDGING_H
1515

16+
#include "swift/AST/DiagnosticEngine.h"
1617
#include "swift/Basic/BasicBridging.h"
1718
#include "swift/Basic/Compiler.h"
18-
#include "swift/AST/DiagnosticEngine.h"
19+
#include "swift/Basic/Nullability.h"
1920
#include <stdbool.h>
2021
#include <stddef.h>
2122

include/swift/AST/CASTBridging.h

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- ASTBridging.h - header for the swift SILBridging module ----------===//
1+
//===--- CASTBridging.h - header for the swift SILBridging module ---------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -15,29 +15,15 @@
1515

1616
#include "swift/Basic/CBasicBridging.h"
1717
#include "swift/Basic/Compiler.h"
18+
#include "swift/Basic/Nullability.h"
1819

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

24-
#if __clang__
25-
// Provide macros to temporarily suppress warning about the use of
26-
// _Nullable and _Nonnull.
27-
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS \
28-
_Pragma("clang diagnostic push") \
29-
_Pragma("clang diagnostic ignored \"-Wnullability-extension\"") \
30-
_Pragma("clang assume_nonnull begin")
31-
32-
#define SWIFT_END_NULLABILITY_ANNOTATIONS \
33-
_Pragma("clang diagnostic pop") _Pragma("clang assume_nonnull end")
34-
#else
35-
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
36-
#define SWIFT_END_NULLABILITY_ANNOTATIONS
37-
#define _Nullable
38-
#endif
39-
4025
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
26+
SWIFT_BEGIN_ASSUME_NONNULL
4127

4228
typedef long SwiftInt;
4329
typedef unsigned long SwiftUInt;
@@ -486,9 +472,7 @@ _Bool Plugin_waitForNextMessage(PluginHandle handle, BridgedData *data);
486472
}
487473
#endif
488474

475+
SWIFT_END_ASSUME_NONNULL
489476
SWIFT_END_NULLABILITY_ANNOTATIONS
490477

491-
#undef SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
492-
#undef SWIFT_END_NULLABILITY_ANNOTATIONS
493-
494478
#endif // SWIFT_C_AST_ASTBRIDGING_H

include/swift/Basic/BasicBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/CAS/CASReference.h"
2020

2121
#include "swift/Basic/BridgedSwiftObject.h"
22+
#include "swift/Basic/Nullability.h"
2223
#include "swift/Basic/SourceLoc.h"
2324
#include <stddef.h>
2425

include/swift/Basic/BridgedSwiftObject.h

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#ifndef SWIFT_BASIC_BRIDGEDSWIFTOBJECT_H
1919
#define SWIFT_BASIC_BRIDGEDSWIFTOBJECT_H
2020

21+
#include "swift/Basic/Nullability.h"
22+
2123
#if defined(__OpenBSD__)
2224
#include <sys/stdint.h>
2325
#else
@@ -28,28 +30,6 @@
2830
#define __has_feature(feature) 0
2931
#endif
3032

31-
// TODO: These macro definitions are duplicated in Visibility.h. Move
32-
// them to a single file if we find a location that both Visibility.h and
33-
// BridgedSwiftObject.h can import.
34-
#if __has_feature(nullability)
35-
// Provide macros to temporarily suppress warning about the use of
36-
// _Nullable and _Nonnull.
37-
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS \
38-
_Pragma("clang diagnostic push") \
39-
_Pragma("clang diagnostic ignored \"-Wnullability-extension\"")
40-
#define SWIFT_END_NULLABILITY_ANNOTATIONS \
41-
_Pragma("clang diagnostic pop")
42-
43-
#else
44-
// #define _Nullable and _Nonnull to nothing if we're not being built
45-
// with a compiler that supports them.
46-
#define _Nullable
47-
#define _Nonnull
48-
#define _Null_unspecified
49-
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
50-
#define SWIFT_END_NULLABILITY_ANNOTATIONS
51-
#endif
52-
5333
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
5434

5535
typedef const void * _Nonnull SwiftMetatype;

include/swift/Basic/CBasicBridging.h

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,15 @@
1414
#define SWIFT_C_BASIC_BASICBRIDGING_H
1515

1616
#include "swift/Basic/Compiler.h"
17+
#include "swift/Basic/Nullability.h"
1718

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

23-
#if __clang__
24-
// Provide macros to temporarily suppress warning about the use of
25-
// _Nullable and _Nonnull.
26-
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS \
27-
_Pragma("clang diagnostic push") \
28-
_Pragma("clang diagnostic ignored \"-Wnullability-extension\"") \
29-
_Pragma("clang assume_nonnull begin")
30-
31-
#define SWIFT_END_NULLABILITY_ANNOTATIONS \
32-
_Pragma("clang diagnostic pop") _Pragma("clang assume_nonnull end")
33-
#else
34-
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
35-
#define SWIFT_END_NULLABILITY_ANNOTATIONS
36-
#define _Nullable
37-
#define _Nonnull
38-
#endif
39-
4024
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
25+
SWIFT_BEGIN_ASSUME_NONNULL
4126

4227
#ifdef __cplusplus
4328
extern "C" {
@@ -119,9 +104,7 @@ void *JSON_array_pushNewValue(void *arrayPtr);
119104
}
120105
#endif
121106

107+
SWIFT_END_ASSUME_NONNULL
122108
SWIFT_END_NULLABILITY_ANNOTATIONS
123109

124-
#undef SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
125-
#undef SWIFT_END_NULLABILITY_ANNOTATIONS
126-
127110
#endif // SWIFT_C_BASIC_BASICBRIDGING_H

include/swift/Basic/Nullability.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//===--- Nullability.h ----------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_BASIC_NULLABILITY_H
14+
#define SWIFT_BASIC_NULLABILITY_H
15+
16+
// TODO: These macro definitions are duplicated in Visibility.h. Move
17+
// them to a single file if we find a location that both Visibility.h and
18+
// BridgedSwiftObject.h can import.
19+
#if __has_feature(nullability)
20+
// Provide macros to temporarily suppress warning about the use of
21+
// _Nullable and _Nonnull.
22+
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS \
23+
_Pragma("clang diagnostic push") \
24+
_Pragma("clang diagnostic ignored \"-Wnullability-extension\"")
25+
#define SWIFT_END_NULLABILITY_ANNOTATIONS _Pragma("clang diagnostic pop")
26+
27+
#define SWIFT_BEGIN_ASSUME_NONNULL _Pragma("clang assume_nonnull begin")
28+
#define SWIFT_END_ASSUME_NONNULL _Pragma("clang assume_nonnull end")
29+
#else
30+
// #define _Nullable and _Nonnull to nothing if we're not being built
31+
// with a compiler that supports them.
32+
#define _Nullable
33+
#define _Nonnull
34+
#define _Null_unspecified
35+
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
36+
#define SWIFT_END_NULLABILITY_ANNOTATIONS
37+
#define SWIFT_BEGIN_ASSUME_NONNULL
38+
#define SWIFT_END_ASSUME_NONNULL
39+
#endif
40+
41+
#endif

include/swift/Demangling/Errors.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#define SWIFT_DEMANGLING_ERRORS_H
2121

2222
#include "swift/Demangling/NamespaceMacros.h"
23-
#include "swift/shims/Visibility.h"
2423
#include <inttypes.h>
2524
#include <stdarg.h>
2625

@@ -44,6 +43,14 @@
4443
#endif
4544
#endif
4645

46+
#ifndef SWIFT_NORETURN
47+
#if __has_attribute(noreturn)
48+
#define SWIFT_NORETURN __attribute__((__noreturn__))
49+
#else
50+
#define SWIFT_NORETURN
51+
#endif
52+
#endif
53+
4754
namespace swift {
4855
namespace Demangle {
4956
SWIFT_BEGIN_INLINE_NAMESPACE

include/swift/Parse/RegexParserBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define REGEX_PARSER_BRIDGING
1616

1717
#include "swift/AST/ASTBridging.h"
18+
#include "swift/Basic/Nullability.h"
1819
#include <stdbool.h>
1920

2021
/// Attempt to lex a regex literal string. Takes the following arguments:

include/swift/SIL/SILBridging.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@
1313
#ifndef SWIFT_SIL_SILBRIDGING_H
1414
#define SWIFT_SIL_SILBRIDGING_H
1515

16-
#include "swift/Basic/BasicBridging.h"
17-
#include "swift/Basic/BridgedSwiftObject.h"
1816
#include "swift/AST/Builtins.h"
1917
#include "swift/AST/Decl.h"
2018
#include "swift/AST/SubstitutionMap.h"
21-
#include "swift/SIL/SILInstruction.h"
19+
#include "swift/Basic/BasicBridging.h"
20+
#include "swift/Basic/BridgedSwiftObject.h"
21+
#include "swift/Basic/Nullability.h"
2222
#include "swift/SIL/ApplySite.h"
2323
#include "swift/SIL/SILBuilder.h"
24-
#include "swift/SIL/SILLocation.h"
24+
#include "swift/SIL/SILDefaultWitnessTable.h"
2525
#include "swift/SIL/SILFunctionConventions.h"
26+
#include "swift/SIL/SILInstruction.h"
27+
#include "swift/SIL/SILLocation.h"
2628
#include "swift/SIL/SILModule.h"
27-
#include "swift/SIL/SILWitnessTable.h"
28-
#include "swift/SIL/SILDefaultWitnessTable.h"
2929
#include "swift/SIL/SILVTable.h"
30+
#include "swift/SIL/SILWitnessTable.h"
3031
#include <stdbool.h>
3132
#include <stddef.h>
3233
#include <string>

include/swift/SILOptimizer/OptimizerBridging.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
#ifndef SWIFT_SILOPTIMIZER_OPTIMIZERBRIDGING_H
1414
#define SWIFT_SILOPTIMIZER_OPTIMIZERBRIDGING_H
1515

16+
#include "swift/Basic/Nullability.h"
1617
#include "swift/SIL/SILBridging.h"
17-
#include "swift/SILOptimizer/PassManager/PassManager.h"
1818
#include "swift/SILOptimizer/Analysis/AliasAnalysis.h"
1919
#include "swift/SILOptimizer/Analysis/BasicCalleeAnalysis.h"
2020
#include "swift/SILOptimizer/Analysis/DeadEndBlocksAnalysis.h"
2121
#include "swift/SILOptimizer/Analysis/DominanceAnalysis.h"
22+
#include "swift/SILOptimizer/PassManager/PassManager.h"
2223
#include "swift/SILOptimizer/Utils/InstOptUtils.h"
2324

2425
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS

lib/Parse/ParseDecl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3663,7 +3663,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
36633663
return makeParserSuccess();
36643664
}
36653665

3666-
SourceLoc LParenLoc = consumeToken(tok::l_paren);
3666+
consumeToken(tok::l_paren);
36673667

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

36743674
Identifier firstLabel;
3675-
SourceLoc firstLabelLoc = consumeArgumentLabel(firstLabel, true);
3675+
consumeArgumentLabel(firstLabel, true);
36763676
if (!consumeIf(tok::colon)) {
36773677
diagnose(Loc, diag::attr_expected_colon_after_label, firstLabel.str());
36783678
return makeParserSuccess();
@@ -3700,7 +3700,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
37003700
}
37013701

37023702
Identifier alignLabel;
3703-
SourceLoc alignLabelLoc = consumeArgumentLabel(alignLabel, true);
3703+
consumeArgumentLabel(alignLabel, true);
37043704
if (!consumeIf(tok::colon)) {
37053705
diagnose(Loc, diag::attr_expected_colon_after_label, "alignment");
37063706
return makeParserSuccess();
@@ -3759,7 +3759,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
37593759
}
37603760

37613761
Identifier countLabel;
3762-
SourceLoc countLabelLoc = consumeArgumentLabel(countLabel, true);
3762+
consumeArgumentLabel(countLabel, true);
37633763
if (!consumeIf(tok::colon)) {
37643764
diagnose(Loc, diag::attr_expected_colon_after_label, "count");
37653765
return makeParserSuccess();

lib/Parse/ParseType.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17-
#include "swift/Parse/Parser.h"
1817
#include "swift/AST/ASTWalker.h"
1918
#include "swift/AST/Attr.h"
2019
#include "swift/AST/GenericParamList.h"
2120
#include "swift/AST/SourceFile.h" // only for isMacroSignatureFile
2221
#include "swift/AST/TypeRepr.h"
23-
#include "swift/Parse/Lexer.h"
22+
#include "swift/Basic/Nullability.h"
2423
#include "swift/Parse/IDEInspectionCallbacks.h"
24+
#include "swift/Parse/Lexer.h"
25+
#include "swift/Parse/Parser.h"
2526
#include "llvm/ADT/APInt.h"
2627
#include "llvm/ADT/SmallString.h"
2728
#include "llvm/ADT/Twine.h"

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3210,7 +3210,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
32103210
} else if (auto likeArrayTypeAndCount = attr->getResolvedArrayLikeTypeAndCount()) {
32113211
typeID = S.addTypeRef(likeArrayTypeAndCount->first);
32123212
rawSize = likeArrayTypeAndCount->second;
3213-
rawAlign = ~0u;
3213+
rawAlign = static_cast<uint8_t>(~0u);
32143214
} else {
32153215
llvm_unreachable("unhandled raw layout attribute, or trying to serialize unresolved attr!");
32163216
}

0 commit comments

Comments
 (0)