[PATCH] D139632: [clang-cl] Ignore #pragma managed / #pragma unmanaged
Sylvain Audi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 8 07:49:18 PST 2022
saudi created this revision.
saudi added reviewers: thakis, rnk, thieta.
saudi added a project: clang.
Herald added a project: All.
saudi requested review of this revision.
Herald added a subscriber: cfe-commits.
Those 2 pragmas are ignored by MSVC when not compiling with `/CLR`, which clang doesn't support.
Ignore them in clang `-fms-extensions`, to avoid `-Wunknown-pragma` warnings.
See https://learn.microsoft.com/en-us/cpp/preprocessor/managed-unmanaged?view=msvc-170
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D139632
Files:
clang/lib/Lex/Pragma.cpp
clang/test/Preprocessor/pragma_microsoft.c
Index: clang/test/Preprocessor/pragma_microsoft.c
===================================================================
--- clang/test/Preprocessor/pragma_microsoft.c
+++ clang/test/Preprocessor/pragma_microsoft.c
@@ -235,6 +235,12 @@
#pragma optimize("", on) // expected-error {{'#pragma optimize' can only appear at file scope}}
}
+#pragma managed // no-warning
+#pragma unmanaged // no-warning
+#pragma managed(push, on) // no-warning
+#pragma managed(pop) // no-warning
+#pragma managed2 // expected-warning{{unknown pragma ignored}}
+
#pragma execution_character_set // expected-warning {{expected '('}}
#pragma execution_character_set( // expected-warning {{expected 'push' or 'pop'}}
#pragma execution_character_set() // expected-warning {{expected 'push' or 'pop'}}
Index: clang/lib/Lex/Pragma.cpp
===================================================================
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1957,6 +1957,15 @@
}
};
+/// "\#pragma managed"
+/// "\#pragma managed(...)"
+/// "\#pragma unmanaged"
+/// MSVC ignores this pragma when not compiling using /clr, which clang doesn't
+/// support. We parse it and ignore it to avoid -Wunknown-pragma warnings.
+struct PragmaManagedHandler : public EmptyPragmaHandler {
+ PragmaManagedHandler(const char *pragma) : EmptyPragmaHandler(pragma) {}
+};
+
/// This handles parsing pragmas that take a macro name and optional message
static IdentifierInfo *HandleMacroAnnotationPragma(Preprocessor &PP, Token &Tok,
const char *Pragma,
@@ -2129,6 +2138,8 @@
AddPragmaHandler(new PragmaIncludeAliasHandler());
AddPragmaHandler(new PragmaHdrstopHandler());
AddPragmaHandler(new PragmaSystemHeaderHandler());
+ AddPragmaHandler(new PragmaManagedHandler("managed"));
+ AddPragmaHandler(new PragmaManagedHandler("unmanaged"));
}
// Pragmas added by plugins
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139632.481275.patch
Type: text/x-patch
Size: 2007 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221208/9794ee26/attachment.bin>
More information about the cfe-commits
mailing list