Skip to content

Commit 6e07ee8

Browse files
committed
Fix a couple of build warning
Fixes a couple of compiler warnings that occur frequently when building the compiler: - Copy the nullability annotation definitions from `Visibility.h` to `BridgedSwiftObject.h` and wrap all code that contains nullability annotations in `SWIFT_BEGIN_NULLABILITY_ANNOTATIONS` and `SWIFT_END_NULLABILITY_ANNOTATIONS` (supressing the warning `type nullability specifier '_Nullable' is a Clang extension [-Wnullability-extension]`) - Suppress warnings about using `$` (mangling prefix) as an identifier using pragmas (supressing the warning `'$' in identifier [-Wdollar-in-identifier-extension]`) - Change the macro condition of `SWIFT_NODISCARD` from `__cplusplus >= 201402l` (which checked for >= C++14) to `__cplusplus > 201402l`. This appears to have been a copy-paste error from `LLVM_NODISCARD` (supressing the warning `use of the 'nodiscard' attribute is a C++17 extension [-Wc++17-extensions]`)
1 parent 1202d90 commit 6e07ee8

File tree

7 files changed

+39
-3
lines changed

7 files changed

+39
-3
lines changed

include/swift/Demangling/ManglingMacros.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
#define MANGLE_AS_STRING(M) STRINGIFY_MANGLING(M)
1818

1919
/// The mangling prefix for the new mangling.
20+
_Pragma("clang diagnostic push")
21+
_Pragma("clang diagnostic ignored \"-Wdollar-in-identifier-extension\"")
2022
#define MANGLING_PREFIX $s
23+
_Pragma("clang diagnostic pop")
2124

2225
#define MANGLING_PREFIX_STR MANGLE_AS_STRING(MANGLING_PREFIX)
2326

include/swift/SIL/BridgedSwiftObject.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,30 @@
2020

2121
#include <stdint.h>
2222

23-
#if !__has_feature(nullability)
23+
// TODO: These macro definitions are duplicated in Visibility.h. Move
24+
// them to a single file if we find a location that both Visibility.h and
25+
// BridgedSwiftObject.h can import.
26+
#if __has_feature(nullability)
27+
// Provide macros to temporarily suppress warning about the use of
28+
// _Nullable and _Nonnull.
29+
# define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS \
30+
_Pragma("clang diagnostic push") \
31+
_Pragma("clang diagnostic ignored \"-Wnullability-extension\"")
32+
# define SWIFT_END_NULLABILITY_ANNOTATIONS \
33+
_Pragma("clang diagnostic pop")
34+
35+
#else
36+
// #define _Nullable and _Nonnull to nothing if we're not being built
37+
// with a compiler that supports them.
2438
# define _Nullable
2539
# define _Nonnull
2640
# define _Null_unspecified
41+
# define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
42+
# define SWIFT_END_NULLABILITY_ANNOTATIONS
2743
#endif
2844

45+
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
46+
2947
typedef const void * _Nonnull SwiftMetatype;
3048

3149
/// The header of a Swift object.
@@ -40,4 +58,6 @@ struct BridgedSwiftObject {
4058
typedef struct BridgedSwiftObject * _Nonnull SwiftObject;
4159
typedef struct BridgedSwiftObject * _Nullable OptionalSwiftObject;
4260

61+
SWIFT_END_NULLABILITY_ANNOTATIONS
62+
4363
#endif

include/swift/SIL/SILBridging.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <stddef.h>
1818
#include <string>
1919

20+
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
21+
2022
typedef struct {
2123
const unsigned char * _Nullable data;
2224
size_t length;
@@ -235,4 +237,6 @@ BridgedInstruction SILBuilder_createBuiltinBinaryFunction(
235237
BridgedInstruction SILBuilder_createCondFail(BridgedInstruction insertionPoint,
236238
BridgedLocation loc, BridgedValue condition, BridgedStringRef messge);
237239

240+
SWIFT_END_NULLABILITY_ANNOTATIONS
241+
238242
#endif

include/swift/SILOptimizer/OptimizerBridging.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include "../SIL/SILBridging.h"
1717

18+
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
19+
1820
#ifdef __cplusplus
1921
extern "C" {
2022
#endif
@@ -72,4 +74,6 @@ BridgedFunction BridgedFunctionArray_get(BridgedCalleeList callees,
7274
} // extern "C"
7375
#endif
7476

77+
SWIFT_END_NULLABILITY_ANNOTATIONS
78+
7579
#endif

lib/IDE/CodeCompletion.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6623,7 +6623,6 @@ static void deliverCompletionResults(CodeCompletionContext &CompletionContext,
66236623
// ModuleFilename can be empty if something strange happened during
66246624
// module loading, for example, the module file is corrupted.
66256625
if (!ModuleFilename.empty()) {
6626-
auto &Ctx = TheModule->getASTContext();
66276626
CodeCompletionCache::Key K{
66286627
ModuleFilename.str(),
66296628
std::string(TheModule->getName()),

lib/SILOptimizer/Utils/OnonePrespecializations.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
_Pragma("clang diagnostic push")
2+
_Pragma("clang diagnostic ignored \"-Wdollar-in-identifier-extension\"")
13
PRESPEC_SYMBOL($sS2ayxGycfCSJ_Tg5)
24
PRESPEC_SYMBOL($sS2ayxGycfCSS_Tg5)
35
PRESPEC_SYMBOL($sS2ayxGycfCSd_Tg5)
@@ -1196,3 +1198,4 @@ PRESPEC_SYMBOL($ss22_ContiguousArrayBufferVAByxGycfCs6UInt64V_Tg5)
11961198
PRESPEC_SYMBOL($ss22_ContiguousArrayBufferVAByxGycfCs7UnicodeO6ScalarV_Tg5)
11971199
PRESPEC_SYMBOL($ss27_allocateUninitializedArrayySayxG_BptBwlFyp_Tg5)
11981200

1201+
_Pragma("clang diagnostic pop")

stdlib/public/SwiftShims/Visibility.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
#define __has_cpp_attribute(attribute) 0
3535
#endif
3636

37+
// TODO: These macro definitions are duplicated in BridgedSwiftObject.h. Move
38+
// them to a single file if we find a location that both Visibility.h and
39+
// BridgedSwiftObject.h can import.
3740
#if __has_feature(nullability)
3841
// Provide macros to temporarily suppress warning about the use of
3942
// _Nullable and _Nonnull.
@@ -219,7 +222,7 @@
219222
#define SWIFT_FALLTHROUGH
220223
#endif
221224

222-
#if __cplusplus >= 201402l && __has_cpp_attribute(nodiscard)
225+
#if __cplusplus > 201402l && __has_cpp_attribute(nodiscard)
223226
#define SWIFT_NODISCARD [[nodiscard]]
224227
#elif __has_cpp_attribute(clang::warn_unused_result)
225228
#define SWIFT_NODISCARD [[clang::warn_unused_result]]

0 commit comments

Comments
 (0)