Skip to content

Commit d759b75

Browse files
committed
PrintAsClang: Ignore non-null attributes in C output mode
In C mode we may still print _Nonnull attributes. Don't let clang warn on them and ignore the attribute if the C compiler doesn't know it.
1 parent e65a1fb commit d759b75

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/PrintAsClang/PrintAsClang.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ static void writePrologue(raw_ostream &out, ASTContext &ctx,
207207

208208
static_assert(SWIFT_MAX_IMPORTED_SIMD_ELEMENTS == 4,
209209
"need to add SIMD typedefs here if max elements is increased");
210+
211+
// Ignore nullability attributes for C clients.
212+
out << "#if !defined(__OBJC__) && !defined(__cplusplus)\n"
213+
"# if __has_feature(nullability)\n"
214+
"# pragma clang diagnostic ignored \"-Wnullability-extension\"\n"
215+
"# else\n"
216+
"# define _Nonnull\n"
217+
"# endif\n";
218+
"#endif\n";
210219
}
211220

212221
static int compareImportModulesByName(const ImportModuleTy *left,

0 commit comments

Comments
 (0)