This is an archive of the discontinued LLVM Phabricator instance.

Add support for #pragma system_header with -fms-extensions
ClosedPublic

Authored by hans on Jun 23 2021, 2:17 AM.

Details

Summary

Clang already supports the pragma prefixed by "GCC" or "clang".

MSVC has more recently added support for the pragma, but without any prefix; see https://devblogs.microsoft.com/cppblog/broken-warnings-theory/#external-headers

Diff Detail

Event Timeline

hans requested review of this revision.Jun 23 2021, 2:17 AM
hans created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJun 23 2021, 2:17 AM
hans added inline comments.Jun 23 2021, 2:20 AM
clang/test/Lexer/pragma-operators.cpp
22

I had to change the pragma here, because now we will warn about system_header being ignored in a non-header file which would break this test.

clang/test/Preprocessor/pragma_sysheader.c
0–1

Adding -std=c99 is necessary, because in newer language modes (which are now the default), Clang doesn't warn about repeated typedef declarations, so the test wasn't actually testing the system_header pragma anymore.

5–7

Moving the .h file to Inputs/ is just a cleanup.

aaron.ballman accepted this revision.Jun 23 2021, 4:01 AM
aaron.ballman added a subscriber: aaron.ballman.

LGTM, though you could add a test that #pragma system_header gives a diagnostic outside of -fms-extensions mode if you think that's valuable.

This revision is now accepted and ready to land.Jun 23 2021, 4:01 AM
hans added a comment.Jun 23 2021, 4:30 AM

LGTM, though you could add a test that #pragma system_header gives a diagnostic outside of -fms-extensions mode if you think that's valuable.

Thanks! Yes, I'll do that, and I'll also add a test to see that it actually warns when no system_header is used.

This revision was landed with ongoing or failed builds.Jun 23 2021, 4:31 AM
This revision was automatically updated to reflect the committed changes.
clang/test/Lexer/pragma-operators.cpp